sensor_settings.hpp
1 #pragma once
2 
3 #include <cvb/_cexports/c_img.h>
4 #include <cvb/core_3d.hpp>
5 #include <cvb/rect.hpp>
6 #include <cvb/point_2d.hpp>
7 
8 namespace Cvb
9 {
10 CVB_BEGIN_INLINE_NS
11 
13 
24 #pragma pack(push, 4)
25 class SensorSettings final
26 {
27 public:
28 
30  SensorSettings() noexcept
32  {
33  }
34 
36 
54  SensorSettings(double rangeScale, SensorPixelPosition pixelPosition, SensorPixelsMirrored pixelsMirrored, Rect<int> sensorRoi, Point2D<double> resolutionReduction)
55  {
56  size_ = sizeof(CExports::CVC3DSensorSettings);
57  rangeScale_ = rangeScale;
58  pixelPosition_ = pixelPosition;
59  pixelsMirrored_ = pixelsMirrored;
60  offsetLeft_ = sensorRoi.Left();
61  offsetTop_ = sensorRoi.Top();
62  width_ = sensorRoi.Width();
63  height_ = sensorRoi.Height();
64  resolutionReduction_ = resolutionReduction;
65 
66  static_assert(sizeof(SensorSettings) == sizeof(CExports::CVC3DSensorSettings),
67  "size of class SensorSettings and CExports::CVC3DSensorSettings must be equal");
68 
69  if (sensorRoi.Left() == 0 && sensorRoi.Top() == 0 && sensorRoi.Width() == 0 && sensorRoi.Height() == 0)
70  {
71  if (MirrorX() || MirrorY())
72  throw std::invalid_argument("Sensor ROI is not valid");
73  }
74 
75  if (!MirrorX() && sensorRoi.Width() < 0)
76  throw std::invalid_argument("reverse_x = false and sensorRoi.Width < 0 are contradictory. Please set reverse_x to TRUE.");
77 
78  if (!MirrorY() && sensorRoi.Height() < 0)
79  throw std::invalid_argument("reverse_y = false and sensorRoi.Height < 0 are contradictory. Please set reverse_y to TRUE.");
80 
81  if (sensorRoi.Left() < 0 || sensorRoi.Top() < 0)
82  throw std::invalid_argument("Sensor ROI is not valid. Offset must be positive.");
83 
84  if (pixelPosition_ == SensorPixelPosition::Absolute && sensorRoi.Top() != 0)
85  throw std::invalid_argument("Sensor ROI is not valid: sensorRoi.Top must be zero as absolutePosition = true");
86  }
87 
89 
93  double RangeScale() const noexcept { return rangeScale_; }
94 
96 
100  SensorPixelPosition PixelPosition() const noexcept { return pixelPosition_; }
101 
103 
107  SensorPixelsMirrored PixelsMirrored() const noexcept { return pixelsMirrored_; }
108 
110 
114  Rect<int> SensorRoi() const noexcept
115  {
116  return Rect<int>{Point2D<int>{offsetLeft_, offsetTop_}, Size2D<int>{width_, height_}};
117  }
118 
120 
124  Point2D<double> ResolutionReduction() const noexcept { return resolutionReduction_; }
125 
127 
132  bool operator==(const SensorSettings& other) const noexcept
133  {
134  if (size_ != other.size_)
135  return false;
136  else if (rangeScale_ != other.rangeScale_)
137  return false;
138  else if (pixelPosition_ != other.pixelPosition_)
139  return false;
140  else if (pixelsMirrored_ != other.pixelsMirrored_)
141  return false;
142  else if (SensorRoi()!= other.SensorRoi())
143  return false;
144  else if (resolutionReduction_ != other.resolutionReduction_)
145  return false;
146 
147  return true;
148  }
149 
151 
156  bool operator!=(const SensorSettings& other) const noexcept
157  {
158  return !(*this == other);
159  }
160 
161 private:
162  int size_;
163  double rangeScale_;
164  SensorPixelPosition pixelPosition_;
165  SensorPixelsMirrored pixelsMirrored_;
166 
167  CExports::cvbdim_t offsetLeft_;
168  CExports::cvbdim_t offsetTop_;
169  CExports::cvbdim_t width_;
170  CExports::cvbdim_t height_;
171 
172  Point2D<double> resolutionReduction_;
173 
174  // Convenient functions
175  bool MirrorX() const noexcept { return (pixelsMirrored_ == SensorPixelsMirrored::X || pixelsMirrored_ == SensorPixelsMirrored::XY); }
176  bool MirrorY() const noexcept { return (pixelsMirrored_ == SensorPixelsMirrored::Y || pixelsMirrored_ == SensorPixelsMirrored::XY); }
177 };
178 #pragma pack(pop)
179 
180 CVB_END_INLINE_NS
181 
182 }
T Width() const noexcept
Gets the width of the rectangle.
Definition: rect.hpp:171
double RangeScale() const noexcept
Gets range scale (z factor).
Definition: sensor_settings.hpp:93
T Top() const noexcept
Gets first row of the rectangle.
Definition: rect.hpp:111
No mirroring is applied.
bool operator==(const SensorSettings &other) const noexcept
Compares to other sensor settings.
Definition: sensor_settings.hpp:132
Point2D< double > ResolutionReduction() const noexcept
Gets horizontal (X) and vertical (Y) resolution reduction factors (due to binning).
Definition: sensor_settings.hpp:124
Rectangle object.
Definition: rect.hpp:25
Rect< int > SensorRoi() const noexcept
Gets sensor region of interest (ROI).
Definition: sensor_settings.hpp:114
SensorSettings() noexcept
Default ctor.
Definition: sensor_settings.hpp:30
SensorPixelsMirrored
Indicates if sensor pixels are mirrored in rangemap.
Definition: core_3d.hpp:259
T Left() const noexcept
Gets first column of the rectangle.
Definition: rect.hpp:91
Root namespace for the Image Manager interface.
Definition: version.hpp:11
Sensor pixel values are mirrored in X and Y.
Sensor pixel values are mirrored in Y (or denoted by v), so that the range map pixel values will be f...
Class to store camera sensor settings.
Definition: sensor_settings.hpp:25
SensorPixelsMirrored PixelsMirrored() const noexcept
Gets information if sensor pixels are mirrored.
Definition: sensor_settings.hpp:107
SensorPixelPosition
Indicates pixel position on sensor.
Definition: core_3d.hpp:245
Sensor pixel values are mirrored in X (or denoted by u), so that the columns of the range map will be...
Scaled rangemap values represent absolute pixel position on sensor.
T Height() const noexcept
Gets the height of the rectangle.
Definition: rect.hpp:191
SensorSettings(double rangeScale, SensorPixelPosition pixelPosition, SensorPixelsMirrored pixelsMirrored, Rect< int > sensorRoi, Point2D< double > resolutionReduction)
Ctor passing sensor settings.
Definition: sensor_settings.hpp:54
bool operator!=(const SensorSettings &other) const noexcept
Compares to other sensor settings.
Definition: sensor_settings.hpp:156
SensorPixelPosition PixelPosition() const noexcept
Gets pixel position in y on sensor.
Definition: sensor_settings.hpp:100