disparity-transform.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2017 Intel Corporation. All Rights Reserved.
3 
4 #include "../include/librealsense2/hpp/rs_sensor.hpp"
5 #include "../include/librealsense2/hpp/rs_processing.hpp"
6 
7 #include "option.h"
8 #include "context.h"
9 #include "ds5/ds5-private.h"
10 #include "core/video.h"
11 #include "proc/synthetic-stream.h"
13 #include "software-device.h"
14 #include "environment.h"
15 
16 namespace librealsense
17 {
18  disparity_transform::disparity_transform(bool transform_to_disparity):
19  generic_processing_block(transform_to_disparity ? "Depth to Disparity" : "Disparity to Depth"),
20  _transform_to_disparity(transform_to_disparity),
21  _update_target(false),
22  _width(0), _height(0), _bpp(0)
23  {
24  auto transform_opt = std::make_shared<ptr_option<bool>>(
25  false,true,true,true,
27  "Stereoscopic Transformation Mode");
28  transform_opt->set_description(false, "Disparity to Depth");
29  transform_opt->set_description(true, "Depth to Disparity");
30  transform_opt->on_set([this, transform_opt](float val)
31  {
32  std::lock_guard<std::mutex> lock(_mutex);
33  if (!transform_opt->is_valid(val))
34  throw invalid_value_exception(to_string() << "Unsupported transformation mode" << (int)val << " is out of range.");
35 
36  on_set_mode(static_cast<bool>(!!int(val)));
37  });
38 
40 
41  on_set_mode(_transform_to_disparity);
42  }
43 
45  {
46  if (!frame)
47  return false;
48 
49  if (frame.is<rs2::frameset>())
50  return false;
51 
53  return false;
54 
57  return false;
58 
60  return false;
61 
62  return true;
63  }
64 
66  {
67  rs2::frame tgt;
68 
70 
71  if (_stereoscopic_depth && (tgt = prepare_target_frame(f, source)))
72  {
73  auto src = f.as<rs2::video_frame>();
74 
76  convert<uint16_t, float>(src.get_data(), const_cast<void*>(tgt.get_data()));
77  else
78  convert<float, uint16_t>(src.get_data(), const_cast<void*>(tgt.get_data()));
79  }
80 
81  return tgt;
82  }
83 
84  void disparity_transform::on_set_mode(bool to_disparity)
85  {
86  _transform_to_disparity = to_disparity;
87  _bpp = _transform_to_disparity ? sizeof(float) : sizeof(uint16_t);
88  _update_target = true;
89  }
90 
92  {
94  {
96 
98  _stereoscopic_depth = info.stereoscopic_depth;
99  _depth_units = info.depth_units;
100  _d2d_convert_factor = info.d2d_convert_factor;
101 
103  _width = vp.width();
104  _height = vp.height();
105  _update_target = true;
106  }
107 
108  // Adjust the target profile
109  if (_update_target)
110  {
113  auto src_vspi = dynamic_cast<video_stream_profile_interface*>(_source_stream_profile.get()->profile);
114  auto tgt_vspi = dynamic_cast<video_stream_profile_interface*>(_target_stream_profile.get()->profile);
115  rs2_intrinsics src_intrin = src_vspi->get_intrinsics();
116 
117  tgt_vspi->set_intrinsics([src_intrin]() { return src_intrin; });
118  tgt_vspi->set_dims(src_intrin.width, src_intrin.height);
119 
120  _update_target = false;
121  }
122  }
123 
125  {
126  return source.allocate_video_frame(_target_stream_profile, f, int(_bpp), int(_width), int(_height), int(_width*_bpp),
128  }
129 }
static const textual_icon lock
Definition: model-views.h:218
disparity_transform(bool transform_to_disparity)
void update_transformation_profile(const rs2::frame &f)
stream_profile get_profile() const
Definition: rs_frame.hpp:557
const void * get_data() const
Definition: rs_frame.hpp:545
unsigned short uint16_t
Definition: stdint.h:79
rs2::stream_profile _target_stream_profile
GLenum src
Definition: glext.h:1751
bool should_process(const rs2::frame &frame) override
void unregister_option(rs2_option id)
Definition: options.h:92
rs2::stream_profile _source_stream_profile
frame allocate_video_frame(const stream_profile &profile, const frame &original, int new_bpp=0, int new_width=0, int new_height=0, int new_stride=0, rs2_extension frame_type=RS2_EXTENSION_VIDEO_FRAME) const
GLuint GLfloat * val
static info update_info_from_frame(const rs2::frame &f)
def info(name, value, persistent=False)
Definition: test.py:301
GLdouble f
bool is() const
Definition: rs_frame.hpp:570
rs2::frame process_frame(const rs2::frame_source &source, const rs2::frame &f) override
rs2::frame prepare_target_frame(const rs2::frame &f, const rs2::frame_source &source)
librealsense::stream_profile_interface * profile
Definition: context.h:34
rs2_format format() const
Definition: rs_frame.hpp:44
const rs2_stream_profile * get() const
Definition: rs_frame.hpp:137
Video stream intrinsics.
Definition: rs_types.h:58
GLsizei GLsizei GLchar * source
rs2_stream stream_type() const
Definition: rs_frame.hpp:39
stream_profile clone(rs2_stream type, int index, rs2_format format) const
Definition: rs_frame.hpp:63
T as() const
Definition: rs_frame.hpp:580
std::string to_string(T value)


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:12