Add initial AR playback support
This commit is contained in:
65
openVulkanoCpp/AR/Provider/Playback/ArPlaybackReader.hpp
Normal file
65
openVulkanoCpp/AR/Provider/Playback/ArPlaybackReader.hpp
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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 "IO/Archive/ArchiveReader.hpp"
|
||||
#include "IO/Files/Pfm.hpp"
|
||||
#include "IO/Files/Pnm.hpp"
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
|
||||
namespace openVulkanoCpp::AR::Playback
|
||||
{
|
||||
struct DepthImage
|
||||
{
|
||||
PfmImage depth;
|
||||
PnmImage confidence;
|
||||
};
|
||||
|
||||
struct ColorImg
|
||||
{
|
||||
std::shared_ptr<uint8_t> dataPtr;
|
||||
uint8_t* data;
|
||||
int cols, rows, channels;
|
||||
};
|
||||
|
||||
class ArPlaybackReader final
|
||||
{
|
||||
static constexpr std::string_view TAR_EXTENSIONS_REGEX = R"(\.(tar(\.gz|\.bz2)?|tgz|tbz|tb2|tbz2))";
|
||||
|
||||
ArchiveReader m_archiveMetadata, m_archiveColor, m_archiveDepth, m_archiveConfidence;
|
||||
public:
|
||||
ArPlaybackReader(const std::string& recDir)
|
||||
{
|
||||
std::string extensions = R"((_\d+|\.part\d+)?)" + std::string(TAR_EXTENSIONS_REGEX);
|
||||
m_archiveMetadata.Open(recDir, ".*meta(data)?" + extensions);
|
||||
m_archiveColor.Open(recDir, ".*(color|image)" + extensions);
|
||||
m_archiveDepth.Open(recDir, ".*depth" + extensions);
|
||||
m_archiveConfidence.Open(recDir, ".*conf(idence)?" + extensions);
|
||||
}
|
||||
|
||||
Array<char> ReadMetadata()
|
||||
{
|
||||
return std::move(m_archiveMetadata.GetNextFile()->second);
|
||||
}
|
||||
|
||||
ColorImg ReadColorImage();
|
||||
|
||||
DepthImage ReadDepthImage()
|
||||
{
|
||||
DepthImage img;
|
||||
m_archiveDepth.GetNextFileAsStream([&img](const FileDescription&, std::istream& stream) { img.depth.Read(stream); });
|
||||
m_archiveConfidence.GetNextFileAsStream([&img](const FileDescription&, std::istream& stream) { img.confidence.Read(stream); });
|
||||
return img;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool HasNext() const
|
||||
{
|
||||
return m_archiveMetadata.HasNext() && m_archiveDepth.HasNext() && m_archiveConfidence.HasNext() && m_archiveColor.HasNext();
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user