-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix pointcloud map_to #2371
fix pointcloud map_to #2371
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,7 +72,6 @@ namespace librealsense | |
_depth_intrinsics = optional_value<rs2_intrinsics>(); | ||
_depth_units = optional_value<float>(); | ||
_extrinsics = optional_value<rs2_extrinsics>(); | ||
_other_stream = nullptr; | ||
} | ||
|
||
bool found_depth_intrinsics = false; | ||
|
@@ -115,13 +114,19 @@ namespace librealsense | |
|
||
void pointcloud::inspect_other_frame(const rs2::frame& other) | ||
{ | ||
if (_other_stream != nullptr && other.get_profile().as<rs2::video_stream_profile>() == *_other_stream.get()) | ||
if (_stream_filter != _prev_stream_filter) | ||
_other_stream = nullptr; | ||
_prev_stream_filter = _stream_filter; | ||
|
||
if (_extrinsics.has_value() && _other_stream != nullptr && other.get_profile().as<rs2::video_stream_profile>() == *_other_stream.get()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using "(!_extrinsics.has_value() || .." would be more readable, i.e. maintainable |
||
return; | ||
|
||
_other_stream = nullptr; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The "if" in the next line is redundant now, and should be removed to make it straight-forward: i.e: |
||
|
||
if (!_other_stream.get()) | ||
{ | ||
auto osp = other.get_profile().as<rs2::video_stream_profile>(); | ||
_other_stream = std::make_shared<rs2::video_stream_profile>(osp.clone(osp.stream_type(), osp.stream_index(), osp.format())); | ||
auto osp = other.get_profile().get(); | ||
_other_stream = std::make_shared<rs2::video_stream_profile>(rs2::stream_profile(osp).as<rs2::video_stream_profile>()); | ||
_other_intrinsics = optional_value<rs2_intrinsics>(); | ||
_extrinsics = optional_value<rs2_extrinsics>(); | ||
} | ||
|
@@ -464,8 +469,6 @@ namespace librealsense | |
pointcloud::pointcloud() : | ||
_other_stream(nullptr) | ||
{ | ||
_stream_filter = RS2_STREAM_ANY; | ||
|
||
_occlusion_filter = std::make_shared<occlusion_filter>(); | ||
|
||
auto occlusion_invalidation = std::make_shared<ptr_option<uint8_t>>( | ||
|
@@ -500,10 +503,10 @@ namespace librealsense | |
if (set) | ||
{ | ||
//process composite frame only if it contains both a depth frame and the requested texture frame | ||
if (_stream_filter == RS2_STREAM_ANY) | ||
if (_stream_filter.stream == RS2_STREAM_ANY) | ||
return false; | ||
|
||
auto tex = set.first_or_default(_stream_filter, _stream_format_filter); | ||
auto tex = set.first_or_default(_stream_filter.stream, _stream_filter.format); | ||
if (!tex) | ||
return false; | ||
auto depth = set.first_or_default(RS2_STREAM_DEPTH, RS2_FORMAT_Z16); | ||
|
@@ -516,7 +519,7 @@ namespace librealsense | |
return true; | ||
|
||
auto p = frame.get_profile(); | ||
if (p.stream_type() == _stream_filter && p.format() == _stream_format_filter && p.stream_index() == _stream_index_filter) | ||
if (p.stream_type() == _stream_filter.stream && p.format() == _stream_filter.format && p.stream_index() == _stream_filter.index) | ||
return true; | ||
return false; | ||
|
||
|
@@ -540,7 +543,7 @@ namespace librealsense | |
inspect_depth_frame(depth); | ||
rv = process_depth_frame(source, depth); | ||
|
||
auto texture = composite.first(_stream_filter); | ||
auto texture = composite.first(_stream_filter.stream); | ||
inspect_other_frame(texture); | ||
} | ||
else | ||
|
@@ -551,7 +554,7 @@ namespace librealsense | |
inspect_depth_frame(f); | ||
rv = process_depth_frame(source, f); | ||
} | ||
if (f.get_profile().stream_type() == _stream_filter && f.get_profile().format() == _stream_format_filter) | ||
if (f.get_profile().stream_type() == _stream_filter.stream && f.get_profile().format() == _stream_filter.format) | ||
{ | ||
inspect_other_frame(f); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,8 +61,8 @@ namespace librealsense | |
_holes_filling_mode(holes_fill_def), | ||
_holes_filling_radius(0) | ||
{ | ||
_stream_filter = RS2_STREAM_DEPTH; | ||
_stream_format_filter = RS2_FORMAT_Z16; | ||
_stream_filter.stream = RS2_STREAM_DEPTH; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better to be move to initialization list, so if one day one other class member become dependent on this struct, the initialization order will be preserved, or at least compiler warning will be generated |
||
_stream_filter.format = RS2_FORMAT_Z16; | ||
|
||
auto spatial_filter_alpha = std::make_shared<ptr_option<float>>( | ||
alpha_min_val, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,15 +118,12 @@ namespace librealsense | |
return source.allocate_composite_frame(results); | ||
} | ||
|
||
stream_filter_processing_block::stream_filter_processing_block() : | ||
_stream_filter(RS2_STREAM_ANY), | ||
_stream_format_filter(RS2_FORMAT_ANY), | ||
_stream_index_filter(-1) | ||
stream_filter_processing_block::stream_filter_processing_block() | ||
{ | ||
register_option(RS2_OPTION_FRAMES_QUEUE_SIZE, _source.get_published_size_option()); | ||
_source.init(std::shared_ptr<metadata_parser_map>()); | ||
|
||
auto stream_selector = std::make_shared<ptr_option<int>>(RS2_STREAM_ANY, RS2_STREAM_FISHEYE, 1, RS2_STREAM_ANY, (int*)&_stream_filter, "Stream type"); | ||
auto stream_selector = std::make_shared<ptr_option<int>>(RS2_STREAM_ANY, RS2_STREAM_FISHEYE, 1, RS2_STREAM_ANY, (int*)&_stream_filter.stream, "Stream type"); | ||
for (int s = RS2_STREAM_ANY; s < RS2_STREAM_COUNT; s++) | ||
{ | ||
stream_selector->set_description(s, "Process - " + std::string (rs2_stream_to_string((rs2_stream)s))); | ||
|
@@ -139,10 +136,10 @@ namespace librealsense | |
throw invalid_value_exception(to_string() | ||
<< "Unsupported stream filter, " << val << " is out of range."); | ||
|
||
_stream_filter = static_cast<rs2_stream>((int)val); | ||
_stream_filter.stream = static_cast<rs2_stream>((int)val); | ||
}); | ||
|
||
auto format_selector = std::make_shared<ptr_option<int>>(RS2_FORMAT_ANY, RS2_FORMAT_DISPARITY32, 1, RS2_FORMAT_ANY, (int*)&_stream_format_filter, "Stream format"); | ||
auto format_selector = std::make_shared<ptr_option<int>>(RS2_FORMAT_ANY, RS2_FORMAT_DISPARITY32, 1, RS2_FORMAT_ANY, (int*)&_stream_filter.format, "Stream format"); | ||
for (int f = RS2_FORMAT_ANY; f < RS2_FORMAT_COUNT; f++) | ||
{ | ||
format_selector->set_description(f, "Process - " + std::string(rs2_format_to_string((rs2_format)f))); | ||
|
@@ -155,10 +152,10 @@ namespace librealsense | |
throw invalid_value_exception(to_string() | ||
<< "Unsupported stream format filter, " << val << " is out of range."); | ||
|
||
_stream_format_filter = static_cast<rs2_format>((int)val); | ||
_stream_filter.format = static_cast<rs2_format>((int)val); | ||
}); | ||
|
||
auto index_selector = std::make_shared<ptr_option<int>>(0, std::numeric_limits<int>::max(), 1, -1, &_stream_index_filter, "Stream index"); | ||
auto index_selector = std::make_shared<ptr_option<int>>(0, std::numeric_limits<int>::max(), 1, -1, &_stream_filter.index, "Stream index"); | ||
index_selector->on_set([this, index_selector](float val) | ||
{ | ||
std::lock_guard<std::mutex> lock(_mutex); | ||
|
@@ -167,7 +164,7 @@ namespace librealsense | |
throw invalid_value_exception(to_string() | ||
<< "Unsupported stream index filter, " << val << " is out of range."); | ||
|
||
_stream_index_filter = (int)val; | ||
_stream_filter.index = (int)val; | ||
}); | ||
|
||
register_option(RS2_OPTION_STREAM_FILTER, stream_selector); | ||
|
@@ -191,20 +188,20 @@ namespace librealsense | |
rs2_format format = profile.format(); | ||
int index = profile.stream_index(); | ||
|
||
if (_stream_filter != RS2_STREAM_ANY && _stream_filter != stream) | ||
if (_stream_filter.stream != RS2_STREAM_ANY && _stream_filter.stream != stream) | ||
return false; | ||
if (is_z_or_disparity(_stream_format_filter)) | ||
if (is_z_or_disparity(_stream_filter.format)) | ||
{ | ||
if (_stream_format_filter != RS2_FORMAT_ANY && !is_z_or_disparity(format)) | ||
if (_stream_filter.format != RS2_FORMAT_ANY && !is_z_or_disparity(format)) | ||
return false; | ||
} | ||
else | ||
{ | ||
if (_stream_format_filter != RS2_FORMAT_ANY && _stream_format_filter != format) | ||
if (_stream_filter.format != RS2_FORMAT_ANY && _stream_filter.format != format) | ||
return false; | ||
} | ||
|
||
if (_stream_index_filter != -1 && _stream_index_filter != index) | ||
if (_stream_filter.index != -1 && _stream_filter.index != index) | ||
return false; | ||
return true; | ||
} | ||
|
@@ -217,16 +214,7 @@ namespace librealsense | |
rs2_stream stream = profile.stream_type(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those three lines seem to be redundant after refactoring |
||
rs2_format format = profile.format(); | ||
int index = profile.stream_index(); | ||
|
||
if (_stream_filter != RS2_STREAM_ANY && _stream_filter != stream) | ||
return false; | ||
|
||
if (_stream_format_filter != RS2_FORMAT_ANY && _stream_format_filter != format) | ||
return false; | ||
|
||
if (_stream_index_filter != -1 && _stream_index_filter != index) | ||
return false; | ||
return true; | ||
return _stream_filter.match(frame); | ||
} | ||
|
||
void synthetic_source::frame_ready(frame_holder result) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,16 +71,64 @@ namespace librealsense | |
virtual rs2::frame process_frame(const rs2::frame_source& source, const rs2::frame& f) = 0; | ||
}; | ||
|
||
struct stream_filter | ||
{ | ||
rs2_stream stream; | ||
rs2_format format; | ||
int index; | ||
|
||
stream_filter() : stream(RS2_STREAM_ANY), format(RS2_FORMAT_ANY), index(-1) {} | ||
stream_filter(rs2_stream s, rs2_format f, int i) : stream(s), format(f), index(i) {} | ||
|
||
bool match(const rs2::frame& frame) | ||
{ | ||
stream_filter filter(frame.get_profile().stream_type(), frame.get_profile().format(), frame.get_profile().stream_index()); | ||
return match(filter); | ||
} | ||
|
||
bool match(const stream_filter& other) | ||
{ | ||
if (stream != RS2_STREAM_ANY && stream != other.stream) | ||
return false; | ||
if (format != RS2_FORMAT_ANY && format != other.format) | ||
return false; | ||
if (index != -1 && index != other.index) | ||
return false; | ||
return true; | ||
} | ||
|
||
bool operator!=(const stream_filter& other) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can the == and ~= operator be swapped, i.e to implement != by terms of == ? |
||
{ | ||
if (stream != other.stream) | ||
return true; | ||
if (format != other.format) | ||
return true; | ||
if (index != other.index) | ||
return true; | ||
return false; | ||
} | ||
|
||
bool operator==(const stream_filter& other) | ||
{ | ||
return !(*this != other); | ||
} | ||
|
||
void operator=(const stream_filter& other) | ||
{ | ||
stream = other.stream; | ||
format = other.format; | ||
index = other.index; | ||
} | ||
}; | ||
|
||
class stream_filter_processing_block : public generic_processing_block | ||
{ | ||
public: | ||
stream_filter_processing_block(); | ||
virtual ~stream_filter_processing_block() { _source.flush(); } | ||
|
||
protected: | ||
rs2_stream _stream_filter; | ||
rs2_format _stream_format_filter; | ||
int _stream_index_filter; | ||
stream_filter _stream_filter; | ||
|
||
bool should_process(const rs2::frame& frame) override; | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be encapsulated with the previous line under the "if.." statement