105 lines
3.4 KiB
C++
105 lines
3.4 KiB
C++
/*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#include "ArFramePlayback.hpp"
|
|
#include "ArSessionPlayback.hpp"
|
|
#include "Base/BlockProfiler.hpp"
|
|
|
|
namespace OpenVulkano::AR::Playback
|
|
{
|
|
ArFramePlayback::ArFramePlayback(const std::shared_ptr<ArSessionPlayback>& session, ArPlaybackReader& frameReader)
|
|
: ArFrame(session, frameReader.GetNextFrameId())
|
|
{
|
|
//BlockProfiler profile("Read_AR_Frame");
|
|
const Array<char> data = frameReader.ReadMetadata();
|
|
frameMetadata = ArFrameMetadata::FromContent(data.Data(), data.Size());
|
|
if (session->GetCapabilities().IsDepthSupported())
|
|
{
|
|
auto depth = frameReader.ReadDepthImage();
|
|
SetDepthImgInfo(depth);
|
|
}
|
|
if (session->IsLoadColorEnabled())
|
|
{
|
|
colorImgData = frameReader.ReadColorImage();
|
|
SetColorImgInfo();
|
|
}
|
|
SetSaved();
|
|
}
|
|
|
|
ArFramePlayback::ArFramePlayback(const std::shared_ptr<ArSessionPlayback>& session, const std::filesystem::path& imagePath)
|
|
: ArFrame(session, 99999) // TODO find better way to generate id
|
|
{
|
|
ArchiveReader reader(imagePath);
|
|
DepthImage dImage;
|
|
while(reader.HasNext())
|
|
{
|
|
reader.GetNextFileAsStream([this, &dImage](const FileDescription& desc, std::istream& data)
|
|
{
|
|
if (desc.path.find("depth") != std::string::npos)
|
|
{
|
|
dImage.depth.TryRead(data);
|
|
}
|
|
else if (desc.path.find("confidence") != std::string::npos)
|
|
{
|
|
dImage.confidence.TryRead(data);
|
|
}
|
|
else if (desc.path.find("metadata") != std::string::npos)
|
|
{
|
|
std::ostringstream buffer;
|
|
buffer << data.rdbuf();
|
|
std::string str = buffer.str();
|
|
frameMetadata = ArFrameMetadata::FromContent(str.data(), str.size());
|
|
}
|
|
});
|
|
}
|
|
colorImgData.channels = ColorImg::RGBA; // TODO test if defaulting to NV12
|
|
colorImgData.Decode(Utils::ReadFile(imagePath));
|
|
SetColorImgInfo();
|
|
SetDepthImgInfo(dImage);
|
|
SetSaved();
|
|
}
|
|
|
|
void ArFramePlayback::SetDepthImgInfo(DepthImage& depth)
|
|
{
|
|
confImgData = std::move(depth.confidence.image);
|
|
depthImgData = std::move(depth.depth.image);
|
|
depthImage.format = ArDepthFormat::METER_FP32; //TODO session->GetSessionMetadata().depthFormat;
|
|
depthImage.intrinsic = frameMetadata.intrinsic.GetForResolution({depth.depth.header.width, depth.depth.header.height});
|
|
depthImage.depth.data = depthImgData.get();
|
|
depthImage.depth.resolution = {depth.depth.header.width, depth.depth.header.height};
|
|
depthImage.confidence.data = confImgData.get();
|
|
depthImage.confidence.resolution = {depth.confidence.header.width, depth.confidence.header.height};
|
|
}
|
|
|
|
void ArFramePlayback::SetColorImgInfo()
|
|
{
|
|
colorImage.intrinsic = frameMetadata.intrinsic.GetForResolution({colorImgData.cols, colorImgData.rows});
|
|
colorImage.format = ArImagePlanar::Format::RGB;
|
|
colorImage.luminescenceOrColor = {colorImgData.data, {colorImgData.cols, colorImgData.rows}};
|
|
colorImage.luminescenceOrColor.numChannels = colorImgData.channels;
|
|
}
|
|
|
|
ArImagePlanar ArFramePlayback::GetCameraImage()
|
|
{
|
|
return colorImage;
|
|
}
|
|
|
|
ArDepthImage ArFramePlayback::GetDepthImage()
|
|
{
|
|
return depthImage;
|
|
}
|
|
|
|
Math::Matrix4f ArFramePlayback::GetCameraViewForCurrentDeviceOrientation()
|
|
{
|
|
return Math::Utils::inverse(GetCameraTransformation());
|
|
}
|
|
|
|
Math::Matrix4f ArFramePlayback::GetCameraProjection(Math::Vector2f viewportSize, float near, float far)
|
|
{
|
|
return GetFrameMetadata().projection; //TODO
|
|
}
|
|
}
|