Skip to content

Commit

Permalink
{Feature} VrsDataProvider - Support retrieval of the VRS file tags (#102
Browse files Browse the repository at this point in the history
)

Summary:
Pull Request resolved: #102

VRS file tags can be retrieved in VRS file reader classes. Modified `VrsDataProvider` to use this functionality through `RecordReaderInterface`. Added the Python binding for the new `VrsDataProvider::getFileTags` function in `VrsDataProviderPyBind.h`.

Reviewed By: SeaOtocinclus

Differential Revision: D58093298

fbshipit-source-id: b1f58d9740d5745281cef0c716c63b19d9904ee7
  • Loading branch information
selcuk-meta authored and facebook-github-bot committed Jun 4, 2024
1 parent 63c4272 commit 844149c
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core/data_provider/RecordReaderInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,17 @@ RecordReaderInterface::RecordReaderInterface(
streamIdToCondition_.emplace(streamId, std::make_unique<std::condition_variable>());
streamIdToLastReadRecord_.emplace(streamId, nullptr);
}
fileTags_ = reader_->getTags();
}

std::set<vrs::StreamId> RecordReaderInterface::getStreamIds() const {
return streamIds_;
}

std::map<std::string, std::string> RecordReaderInterface::getFileTags() const {
return fileTags_;
}

SensorDataType RecordReaderInterface::getSensorDataType(const vrs::StreamId& streamId) const {
auto it = streamIdToSensorDataType_.find(streamId);
if (it == streamIdToSensorDataType_.end()) {
Expand Down
2 changes: 2 additions & 0 deletions core/data_provider/RecordReaderInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class RecordReaderInterface {
const std::shared_ptr<TimeSyncMapper>& timeSyncMapper);

std::set<vrs::StreamId> getStreamIds() const;
[[nodiscard]] std::map<std::string, std::string> getFileTags() const;
SensorDataType getSensorDataType(const vrs::StreamId& streamId) const;

size_t getNumData(const vrs::StreamId& streamId) const;
Expand Down Expand Up @@ -78,6 +79,7 @@ class RecordReaderInterface {

std::set<vrs::StreamId> streamIds_;
std::map<vrs::StreamId, SensorDataType> streamIdToSensorDataType_;
std::map<std::string, std::string> fileTags_;

std::map<vrs::StreamId, std::shared_ptr<ImageSensorPlayer>> imagePlayers_;
std::map<vrs::StreamId, std::shared_ptr<MotionSensorPlayer>> motionPlayers_;
Expand Down
4 changes: 4 additions & 0 deletions core/data_provider/VrsDataProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ const std::set<vrs::StreamId> VrsDataProvider::getAllStreams() const {
return interface_->getStreamIds();
}

std::map<std::string, std::string> VrsDataProvider::getFileTags() const {
return interface_->getFileTags();
}

size_t VrsDataProvider::getNumData(const vrs::StreamId& streamId) const {
return interface_->getNumData(streamId);
}
Expand Down
6 changes: 6 additions & 0 deletions core/data_provider/VrsDataProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ class VrsDataProvider {
*/
const std::set<vrs::StreamId> getAllStreams() const;

/**
* @brief Get the tags map for all the underlying files. Does not include any stream tags.
* @return The tags map for all underlying files.
*/
std::map<std::string, std::string> getFileTags() const;

/**
* @brief Get SensorDataType from streamId.
* @param streamId The ID of a sensor's stream.
Expand Down
40 changes: 40 additions & 0 deletions core/data_provider/test/VrsDataProviderFileTagsTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <data_provider/VrsDataProvider.h>

#include <gtest/gtest.h>

using namespace projectaria::tools::data_provider;

#define STRING(x) #x
#define XSTRING(x) std::string(STRING(x)) + "aria_unit_test_sequence_calib.vrs"

static const std::string ariaTestDataPath = XSTRING(TEST_FOLDER);

#define DEFAULT_LOG_CHANNEL "TestLog"
#include <logging/Checks.h>
#include <logging/Log.h>

namespace {
constexpr const uint32_t kFileTagsNum = 25;
}

TEST(VrsDataProvider, getFileTags) {
auto provider = createVrsDataProvider(ariaTestDataPath);
auto fileTags = provider->getFileTags();
EXPECT_EQ(fileTags.size(), kFileTagsNum);
}
4 changes: 4 additions & 0 deletions core/python/VrsDataProviderPyBind.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ inline void declareVrsDataProvider(py::module& m) {
return std::vector<vrs::StreamId>{streams.begin(), streams.end()};
},
"Get all available streams from the vrs file.")
.def(
"get_file_tags",
[](const VrsDataProvider& self) { return self.getFileTags(); },
"Get the tags map from the vrs file.")
.def(
"get_sensor_data_type",
&VrsDataProvider::getSensorDataType,
Expand Down
5 changes: 5 additions & 0 deletions core/python/test/corePyBindTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,8 @@ def test_camera_calibration_rotation(self) -> None:
test_pixel=test_pixel, cam_calib=src_calib
)
)

def test_vrs_file_tags(self) -> None:
provider = data_provider.create_vrs_data_provider(vrs_filepath)
file_tags = provider.get_file_tags()
assert len(file_tags) == 25

0 comments on commit 844149c

Please sign in to comment.