From 18fe7eb544c5fef0dceb550c4bc9107f9b1030ed Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Fri, 6 Dec 2024 16:08:51 +0100 Subject: [PATCH] Update ArSessionMetadata --- openVulkanoCpp/AR/ArSessionMetadata.cpp | 54 ++++++++++++++++++------- openVulkanoCpp/AR/ArSessionMetadata.hpp | 18 ++++++++- 2 files changed, 56 insertions(+), 16 deletions(-) diff --git a/openVulkanoCpp/AR/ArSessionMetadata.cpp b/openVulkanoCpp/AR/ArSessionMetadata.cpp index 2e60f43..5ccac67 100644 --- a/openVulkanoCpp/AR/ArSessionMetadata.cpp +++ b/openVulkanoCpp/AR/ArSessionMetadata.cpp @@ -14,8 +14,7 @@ namespace OpenVulkano::AR { ArSessionMetadata::ArSessionMetadata() - : ArSessionMetadata(ArType::UNKNOWN, ArDepthFormat::UNAVAILABLE, {0,0}, { 1920, 1440 }, 60, - SystemInfo::GetDeviceModelName(), SystemInfo::GetOsNameHumanReadable()) + : ArSessionMetadata(ArType::UNKNOWN, ArDepthFormat::UNAVAILABLE, {0,0}, { 1920, 1440 }, 60) {} ArSessionMetadata::ArSessionMetadata(ArType type, ArDepthFormat format, Math::Range confRange, Math::Vector2ui resolution, float frameRate) @@ -54,33 +53,48 @@ namespace OpenVulkano::AR { YAML::Node meta = YAML::LoadFile(filePath); - return { + ArSessionMetadata metadata = { ArType::GetFromName(meta["Type"].Scalar()), ArDepthFormat::GetFromName(meta["DepthType"].Scalar()).value_or(ArDepthFormat::UNAVAILABLE), Math::Range(meta["MinConfidence"].as(), meta["MaxConfidence"].as()), - meta["Resolution"].as(), - meta["FrameRate"].as(60), + meta["Resolution"].as(), meta["FrameRate"].as(60), meta["Device"].as("Unknown"), meta["OS"].as("Unknown"), - meta["Vesion"].as(2) + meta["Version"].as(2) }; + + auto recNode = meta["Recording"]; + if (recNode.IsMap()) + { + metadata.recDuration = recNode["Duration"].as(-1); + metadata.recFrameCount = recNode["FrameCount"].as(-1); + metadata.recSkippedFrames = recNode["SkippedFrames"].as(-1); + } + + return metadata; } - ArSessionMetadata::ArSessionMetadata(const std::string& dirPath) + bool ArSessionMetadata::DirHasMetadata(const std::filesystem::path& dirPath) + { + return std::filesystem::exists(dirPath / RECORDING_METADATA_FILENAME_INFO) || + std::filesystem::exists(dirPath / RECORDING_METADATA_FILENAME_XML) || + std::filesystem::exists(dirPath / RECORDING_METADATA_FILENAME); + } + + ArSessionMetadata::ArSessionMetadata(const std::filesystem::path& dirPath) { std::optional metaFromFile; - std::filesystem::path rPath(dirPath); - if (!is_directory(rPath)) throw std::runtime_error("Ar recording path must be a directory!"); - std::filesystem::path xmlInfoPath(dirPath + "/arType.info"); + if (!is_directory(dirPath)) throw std::runtime_error("Ar recording path must be a directory!"); + std::filesystem::path xmlInfoPath(dirPath / RECORDING_METADATA_FILENAME_INFO); if (std::filesystem::exists(xmlInfoPath)) { metaFromFile = FromXML(xmlInfoPath.string()); } - xmlInfoPath = { dirPath + "/ArRecording.xml" }; + xmlInfoPath = dirPath / RECORDING_METADATA_FILENAME_XML; if (std::filesystem::exists(xmlInfoPath)) { metaFromFile = FromXML(xmlInfoPath.string()); } - std::filesystem::path ymlInfoPath(dirPath + "/ArRecording.yml"); + std::filesystem::path ymlInfoPath = dirPath / RECORDING_METADATA_FILENAME; if (std::filesystem::exists(ymlInfoPath)) { metaFromFile = FromYaml(ymlInfoPath.string()); @@ -109,19 +123,31 @@ namespace OpenVulkano::AR depthFormat.GetAltName(), imageResolution.x, imageResolution.y, frameRate, device, os, version); } + std::string ArSessionMetadata::FinishedRecordingInfoToYaml() const + { + if (recFrameCount < 1 || recDuration < 1 || recSkippedFrames < 1) return ""; + return fmt::format(R"(Recording: + Duration: {} + FrameCount: {} + SkippedFrames: {} +)", + recDuration, recFrameCount, recSkippedFrames); + } + std::string ArSessionMetadata::ToYaml() const { return fmt::format(R"(Type: {} DepthType: {} MinConfidence: {} MaxConfidence: {} -Resolution: ({},{}) +Resolution: '({},{})' FrameRate: {} Device: {} OS: {} Version: {} +{} )", type.GetName(), depthFormat.GetName(), static_cast(confidenceRange.min), static_cast(confidenceRange.max), - imageResolution.x, imageResolution.y, frameRate, device, os, version); + imageResolution.x, imageResolution.y, frameRate, device, os, version, FinishedRecordingInfoToYaml()); } } \ No newline at end of file diff --git a/openVulkanoCpp/AR/ArSessionMetadata.hpp b/openVulkanoCpp/AR/ArSessionMetadata.hpp index 1332a71..2a9af1c 100644 --- a/openVulkanoCpp/AR/ArSessionMetadata.hpp +++ b/openVulkanoCpp/AR/ArSessionMetadata.hpp @@ -10,11 +10,16 @@ #include "AR/ArDepthFormat.hpp" #include "Math/Range.hpp" #include "Math/Math.hpp" +#include namespace OpenVulkano::AR { struct ArSessionMetadata { + static constexpr std::string_view RECORDING_METADATA_FILENAME = "ArRecording.yml"; + static constexpr std::string_view RECORDING_METADATA_FILENAME_XML = "ArRecording.xml"; + static constexpr std::string_view RECORDING_METADATA_FILENAME_INFO = "arType.info"; + ArType type; ArDepthFormat depthFormat; Math::Range confidenceRange; @@ -22,6 +27,9 @@ namespace OpenVulkano::AR float frameRate; uint32_t version; std::string device, os; + // Recording info + int64_t recFrameCount; + int32_t recDuration, recSkippedFrames; bool playback = false; @@ -30,22 +38,28 @@ namespace OpenVulkano::AR ArSessionMetadata(ArType type, ArDepthFormat format, Math::Range confRange, Math::Vector2ui resolution, float frameRate); ArSessionMetadata(ArType type, ArDepthFormat format, Math::Range confRange, Math::Vector2ui resolution, - float frameRate, const std::string& device, const std::string& os, uint32_t version = 2) + float frameRate, const std::string& device, const std::string& os, uint32_t version = 2, + int64_t frameCount = -1, int32_t duration = -1, int32_t skippedFrames = -1) : type(type), depthFormat(format), confidenceRange(confRange), imageResolution(resolution) , frameRate(frameRate), version(version), device(device), os(os) {} - ArSessionMetadata(const std::string& dirPath); + ArSessionMetadata(const std::filesystem::path& dirPath); + [[deprecated]] [[nodiscard]] std::string ToXML() const; [[nodiscard]] std::string ToYaml() const; + [[nodiscard]] std::string FinishedRecordingInfoToYaml() const; + [[nodiscard]] float GetConfidenceNormalisationFactor() const { return 1.0f / static_cast(confidenceRange.max); } + static bool DirHasMetadata(const std::filesystem::path& dirPath); + static ArSessionMetadata FromXML(const std::string& filePath); static ArSessionMetadata FromYaml(const std::string& filePath);