Merge pull request 'Merge some bugfixes' (#126) from wip into master

Reviewed-on: https://git.madvoxel.net/OpenVulkano/OpenVulkano/pulls/126
This commit is contained in:
Georg Hagen
2024-09-27 12:28:24 +02:00
9 changed files with 81 additions and 30 deletions

View File

@@ -57,11 +57,11 @@ namespace OpenVulkano::AR
return { nullptr, ArCreateResult::FAILED_UNKNOWN, "Unknown exception while initializing AR system." };
}
ArCreateResult ArSession::CreatePlayback(const std::string& recordingPath, bool autoAdvance)
ArCreateResult ArSession::CreatePlayback(const std::string& recordingPath, bool autoAdvance, bool loadImages, bool loadDepth)
{
try
{
const auto session = std::make_shared<Playback::ArSessionPlayback>(recordingPath, autoAdvance);
const auto session = std::make_shared<Playback::ArSessionPlayback>(recordingPath, autoAdvance, loadImages, loadDepth);
sessions.push_back(session);
return { session, ArCreateResult::SUCCESS, "" };
}

View File

@@ -113,7 +113,7 @@ namespace OpenVulkano::AR
* @param autoAdvance If set to true the playback will advance based on the stored timestamps. If set to false it will only advance if a new frame is requested.
* @return ArCreateResult about the status of the AR session creation. The session pointer will always be nullptr unless the status is SUCCESS.
*/
[[nodiscard]] static ArCreateResult CreatePlayback(const std::string& recordingPath, bool autoAdvance = true);
[[nodiscard]] static ArCreateResult CreatePlayback(const std::string& recordingPath, bool autoAdvance = true, bool loadImages = true, bool loadDepth = true);
/**
* Creates a network streamed AR session. nullptr if failed to create session for given address. This will block till the connection with the remote host has been established.

View File

@@ -16,21 +16,26 @@ namespace OpenVulkano::AR::Playback
//BlockProfiler profile("Read_AR_Frame");
const auto data = frameReader.ReadMetadata();
frameMetadata = ArFrameMetadata::FromXML(data.Data(), data.Size());
colorImgData = frameReader.ReadColorImage();
auto depth = frameReader.ReadDepthImage();
confImgData = std::move(depth.confidence.image);
depthImgData = std::move(depth.depth.image);
depthImage.format = 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.depth.resolution = { depth.confidence.header.width, depth.confidence.header.height };
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;
if (session->GetCapabilities().IsDepthSupported())
{
auto depth = frameReader.ReadDepthImage();
confImgData = std::move(depth.confidence.image);
depthImgData = std::move(depth.depth.image);
depthImage.format = 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.depth.resolution = {depth.confidence.header.width, depth.confidence.header.height};
}
if (session->IsLoadColorEnabled())
{
colorImgData = frameReader.ReadColorImage();
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;
}
SetSaved();
}

View File

@@ -14,10 +14,11 @@ using namespace std::chrono_literals;
namespace OpenVulkano::AR::Playback
{
ArSessionPlayback::ArSessionPlayback(const std::string& recordingPath, bool autoAdvance)
: ArSession(ArSessionMetadata(recordingPath)), recordingPath(recordingPath), autoAdvance(autoAdvance), playbackReader(recordingPath)
ArSessionPlayback::ArSessionPlayback(const std::string& recordingPath, bool autoAdvance, bool loadImages, bool loadDepth)
: ArSession(ArSessionMetadata(recordingPath)), recordingPath(recordingPath), autoAdvance(autoAdvance)
, loadImages(loadImages), loadDepth(loadDepth), playbackReader(recordingPath)
{
capabilities = ArSessionCapabilities(metadata.type, ArSessionType::PLAYBACK, false, metadata.depthFormat != ArDepthFormat::UNAVAILABLE, false, false, false);
capabilities = ArSessionCapabilities(metadata.type, ArSessionType::PLAYBACK, false, metadata.depthFormat != ArDepthFormat::UNAVAILABLE && loadDepth, false, false, false);
constants = { Math::Matrix4f(1), metadata.confidenceRange };
m_playbackReaderThread = std::thread([this](){ReadWorker();});

View File

@@ -15,7 +15,7 @@ namespace OpenVulkano::AR::Playback
class ArSessionPlayback final : public ArSession, public std::enable_shared_from_this<ArSessionPlayback>
{
public:
ArSessionPlayback(const std::string& recordingPath, bool autoAdvance);
ArSessionPlayback(const std::string& recordingPath, bool autoAdvance, bool loadImages, bool loadDepth);
~ArSessionPlayback() override;
@@ -33,12 +33,15 @@ class ArSessionPlayback final : public ArSession, public std::enable_shared_from
[[nodiscard]] const std::string& GetPlaybackPath() const { return recordingPath; }
[[nodiscard]] bool IsLoadColorEnabled() const { return loadImages; }
[[nodiscard]] bool IsLoadDepthEnabled() const { return loadDepth; }
void SetRenderer(IRenderer* renderer) override;
Event<double> OnPlaybackProgress;
protected:
Scene::Texture * MakeTexture(OpenVulkano::AR::ArFrame *frame) override;
Scene::Texture* MakeTexture(OpenVulkano::AR::ArFrame* frame) override;
void ReturnTexture(Scene::Texture *texture) override;
@@ -48,7 +51,7 @@ class ArSessionPlayback final : public ArSession, public std::enable_shared_from
Math::Timestamp lastTimestamp;
const std::string recordingPath;
const bool autoAdvance;
const bool autoAdvance, loadImages, loadDepth;
ArPlaybackReader playbackReader;
ArTrackingState m_lastTrackingState = ArTrackingState::UNKNOWN;

View File

@@ -78,7 +78,7 @@ namespace OpenVulkano::Math
public:
constexpr explicit DenseVector3i(const Math::Vector3i& vec3) : DenseVector3i(vec3.x, vec3.y, vec3.z) {}
constexpr explicit DenseVector3i(const Math::Vector3i_SIMD& vec3) : DenseVector3i(vec3.x, vec3.y, vec3.z) {}
constexpr DenseVector3i(int x, int y, int z)
constexpr DenseVector3i(T x, T y, T z)
: data((x & BITMASK) | ((y & BITMASK) << (2 * BITS)) | ((z & BITMASK) << BITS))
{
AssertValue(x);
@@ -88,9 +88,9 @@ namespace OpenVulkano::Math
constexpr T Data() const { return data; }
[[nodiscard]] constexpr int X() const { int v = data & BITMASK; if (v > MAX_VALUE) v |= ~BITMASK; return reinterpret_cast<int&>(v); }
[[nodiscard]] constexpr int Y() const { int v = (data >> (2 * BITS)) & BITMASK; if (v > MAX_VALUE_Y) v |= ~BITMASK; return reinterpret_cast<int&>(v); }
[[nodiscard]] constexpr int Z() const { int v = (data >> BITS) & BITMASK; if (v > MAX_VALUE) v |= ~BITMASK; return reinterpret_cast<int&>(v); }
[[nodiscard]] constexpr int X() const { T v = data & BITMASK; if (v > MAX_VALUE) v |= ~BITMASK; return reinterpret_cast<int&>(v); }
[[nodiscard]] constexpr int Y() const { T v = (data >> (2 * BITS)) & BITMASK; if (v > MAX_VALUE_Y) v |= ~BITMASK; return reinterpret_cast<int&>(v); }
[[nodiscard]] constexpr int Z() const { T v = (data >> BITS) & BITMASK; if (v > MAX_VALUE) v |= ~BITMASK; return reinterpret_cast<int&>(v); }
void SetX(int x)
{
@@ -120,7 +120,7 @@ namespace OpenVulkano::Math
return fmt::format("{},{},{}", X(), Y(), Z());
}
[[nodiscard]] constexpr operator T() const { return data; }
//[[nodiscard]] constexpr operator T() const { return data; }
[[nodiscard]] constexpr bool operator <(DenseVec3 rhs) const
{

View File

@@ -0,0 +1,40 @@
/*
* 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/.
*/
#pragma once
#include "Math/Math.hpp"
namespace OpenVulkano::Math
{
class RGBA5551
{
uint16_t Make5(uint8_t val)
{
return val * 31.0f / 255.0f;
}
public:
union
{
uint16_t value;
struct
{
uint16_t b : 5;
uint16_t g : 5;
uint16_t r : 5;
uint16_t a : 1;
};
};
RGBA5551(Math::Vector4uc color = {0, 0, 0, 1})
: b(Make5(color.b))
, g(Make5(color.g))
, r(Make5(color.r))
, a(color.a > 128)
{}
};
}

View File

@@ -46,6 +46,8 @@ namespace OpenVulkano::Vulkan
return mapped || allocation->mapped;
}
[[nodiscard]] void* GetMappedMemory() const { return mapped; }
/**
* \brief Maps the buffer into the memory of the host.
* \tparam T The type of the buffers data.

View File

@@ -110,7 +110,7 @@ namespace OpenVulkano::Vulkan
break;
}
}
if(!alloc && createIfAllFull) alloc = CreateMemoryAllocation(64_MiB, type, true);
if(!alloc && createIfAllFull) alloc = CreateMemoryAllocation(128_MiB, type, true);
return alloc;
}