Skip to content

Commit

Permalink
update map to use both stream and index
Browse files Browse the repository at this point in the history
  • Loading branch information
AviaAv committed Dec 4, 2024
1 parent 0033401 commit 146fb9b
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
11 changes: 6 additions & 5 deletions tools/convert/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ void rs2::tools::converter::metadata_to_txtfile(const rs2::frame& frm, const std
file.close();
}

bool converter_base::frames_map_get_and_set(rs2_stream streamType, frame_number_t frameNumber)
bool converter_base::frames_map_get_and_set(rs2_stream streamType, int index, frame_number_t frameNumber)
{
if (_framesMap.find(streamType) == _framesMap.end()) {
_framesMap.emplace(streamType, std::unordered_set<frame_number_t>());
auto stream_with_index = std::pair<rs2_stream, int>(streamType, index);
if (_framesMap.find(stream_with_index) == _framesMap.end()) {
_framesMap.emplace(stream_with_index, std::unordered_set<frame_number_t>());
}

auto& set = _framesMap[streamType];
auto& set = _framesMap[stream_with_index];
bool result = (set.find(frameNumber) != set.end());

if (!result) {
Expand Down Expand Up @@ -67,7 +68,7 @@ std::string converter_base::get_statistics()
for (auto& i : _framesMap) {
result << '\t'
<< i.second.size() << ' '
<< (static_cast<rs2_stream>(i.first) != rs2_stream::RS2_STREAM_ANY ? rs2_stream_to_string(static_cast<rs2_stream>(i.first)) : "")
<< (i.first.first != rs2_stream::RS2_STREAM_ANY ? rs2_stream_to_string(i.first.first) : "")
<< " frame(s) processed"
<< '\n';
}
Expand Down
6 changes: 3 additions & 3 deletions tools/convert/converter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#ifndef __RS_CONVERTER_CONVERTER_H
#define __RS_CONVERTER_CONVERTER_H

#include <unordered_map>
#include <map>
#include <unordered_set>
#include <thread>
#include <string>
Expand All @@ -26,10 +26,10 @@ namespace rs2 {
protected:
std::thread _worker;
std::vector<std::thread> _subWorkers;
std::unordered_map<int, std::unordered_set<frame_number_t>> _framesMap;
std::map<std::pair<rs2_stream, int>, std::unordered_set<frame_number_t>> _framesMap;

protected:
bool frames_map_get_and_set(rs2_stream streamType, frame_number_t frameNumber);
bool frames_map_get_and_set(rs2_stream streamType, int index, frame_number_t frameNumber);
void wait_sub_workers();

template <typename F> void start_worker(const F& f)
Expand Down
2 changes: 1 addition & 1 deletion tools/convert/converters/converter-bin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ namespace rs2 {
return;
}

if (frames_map_get_and_set(depthframe.get_profile().stream_type(), depthframe.get_frame_number())) {
if (frames_map_get_and_set(depthframe.get_profile().stream_type(), depthframe.get_profile().stream_index(), depthframe.get_frame_number())) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions tools/convert/converters/converter-csv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ converter_csv::converter_csv(const std::string& filePath, rs2_stream streamType)

void converter_csv::convert_depth(rs2::depth_frame& depthframe)
{
if (frames_map_get_and_set(depthframe.get_profile().stream_type(), depthframe.get_frame_number())) {
if (frames_map_get_and_set(depthframe.get_profile().stream_type(), depthframe.get_profile().stream_index(), depthframe.get_frame_number())) {
return;
}

Expand Down Expand Up @@ -146,7 +146,7 @@ void converter_csv::save_motion_pose_data_to_file()

void converter_csv::convert_motion_pose(rs2::frame& f)
{
if (frames_map_get_and_set(f.get_profile().stream_type(), f.get_frame_number())) {
if (frames_map_get_and_set(f.get_profile().stream_type(), f.get_profile().stream_index(), f.get_frame_number())) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion tools/convert/converters/converter-ply.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace rs2 {
auto frameColor = frameset.get_color_frame();

if (frameDepth && frameColor) {
if (frames_map_get_and_set(rs2_stream::RS2_STREAM_ANY, frameDepth.get_frame_number())) {
if (frames_map_get_and_set(rs2_stream::RS2_STREAM_ANY, frameDepth.get_profile().stream_index(), frameDepth.get_frame_number())) {
return;
}

Expand Down
3 changes: 1 addition & 2 deletions tools/convert/converters/converter-png.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ namespace rs2 {
return;
}

if (frames_map_get_and_set(videoframe.get_profile().stream_type(),
static_cast<rs2::tools::converter::frame_number_t>(videoframe.get_timestamp()))) {
if (frames_map_get_and_set(videoframe.get_profile().stream_type(), videoframe.get_profile().stream_index(), videoframe.get_frame_number())) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion tools/convert/converters/converter-raw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace rs2 {
return;
}

if (frames_map_get_and_set(videoframe.get_profile().stream_type(), videoframe.get_frame_number())) {
if (frames_map_get_and_set(videoframe.get_profile().stream_type(), videoframe.get_profile().stream_index(), videoframe.get_frame_number())) {
return;
}

Expand Down

0 comments on commit 146fb9b

Please sign in to comment.