CVB++ 15.0
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
8namespace Cvb
9{
10 CVB_BEGIN_INLINE_NS
11
13
24#pragma pack(push, 4)
25 class SensorSettings final
26 {
27 public:
29 SensorSettings() noexcept
30 : size_(sizeof(CExports::CVC3DSensorSettings))
31 , rangeScale_(1.0)
32 , pixelPosition_(SensorPixelPosition::Absolute)
33 , pixelsMirrored_(SensorPixelsMirrored::None)
34 , offsetLeft_(0)
35 , offsetTop_(0)
36 , width_(0)
37 , height_(0)
38 , resolutionReductionX_(1.0)
39 , resolutionReductionY_(1.0)
40 {
41 }
42
44
63 SensorSettings(double rangeScale, SensorPixelPosition pixelPosition, SensorPixelsMirrored pixelsMirrored,
64 Rect<int> sensorRoi, Point2D<double> resolutionReduction)
65 : size_(sizeof(CExports::CVC3DSensorSettings))
66 , rangeScale_(rangeScale)
67 , pixelPosition_(pixelPosition)
68 , pixelsMirrored_(pixelsMirrored)
69 , offsetLeft_(sensorRoi.Left())
70 , offsetTop_(sensorRoi.Top())
71 , width_(sensorRoi.Width())
72 , height_(sensorRoi.Height())
73 , resolutionReductionX_(resolutionReduction.X())
74 , resolutionReductionY_(resolutionReduction.Y())
75 {
76 static_assert(sizeof(SensorSettings) == sizeof(CExports::CVC3DSensorSettings),
77 "size of class SensorSettings and CExports::CVC3DSensorSettings must be equal");
78
79 if (sensorRoi.Left() == 0 && sensorRoi.Top() == 0 && sensorRoi.Width() == 0 && sensorRoi.Height() == 0)
80 {
81 if (MirrorX() || MirrorY())
82 throw std::invalid_argument("Sensor ROI is not valid");
83 }
84
85 if (!MirrorX() && sensorRoi.Width() < 0)
87 "reverse_x = false and sensorRoi.Width < 0 are contradictory. Please set reverse_x to TRUE.");
88
89 if (!MirrorY() && sensorRoi.Height() < 0)
91 "reverse_y = false and sensorRoi.Height < 0 are contradictory. Please set reverse_y to TRUE.");
92
93 if (sensorRoi.Left() < 0 || sensorRoi.Top() < 0)
94 throw std::invalid_argument("Sensor ROI is not valid. Offset must be positive.");
95
96 if (pixelPosition_ == SensorPixelPosition::Absolute && sensorRoi.Top() != 0)
97 throw std::invalid_argument("Sensor ROI is not valid: sensorRoi.Top must be zero as absolutePosition = true");
98 }
99
101
105 double RangeScale() const noexcept
106 {
107 return rangeScale_;
108 }
109
111
116 {
117 return pixelPosition_;
118 }
119
121
126 {
127 return pixelsMirrored_;
128 }
129
131
135 Rect<int> SensorRoi() const noexcept
136 {
137 return Rect<int>{Point2D<int>{offsetLeft_, offsetTop_}, Size2D<int>{width_, height_}};
138 }
139
141
146 {
147 return {resolutionReductionX_, resolutionReductionY_};
148 }
149
151
156 bool operator==(const SensorSettings &other) const noexcept
157 {
158 return size_ == other.size_ && rangeScale_ == other.rangeScale_ && pixelPosition_ == other.pixelPosition_
159 && pixelsMirrored_ == other.pixelsMirrored_ && SensorRoi() == other.SensorRoi()
160 && resolutionReductionX_ == other.resolutionReductionX_
161 && resolutionReductionY_ == other.resolutionReductionY_;
162 }
163
165
170 bool operator!=(const SensorSettings &other) const noexcept
171 {
172 return !(*this == other);
173 }
174
175 private:
176 int size_;
177 double rangeScale_;
178 SensorPixelPosition pixelPosition_;
179 SensorPixelsMirrored pixelsMirrored_;
180
181 CExports::cvbdim_t offsetLeft_;
182 CExports::cvbdim_t offsetTop_;
183 CExports::cvbdim_t width_;
184 CExports::cvbdim_t height_;
185
186 // should be a Point2D as the packing shifts the start by 4 byte
187 double resolutionReductionX_;
188 double resolutionReductionY_;
189
190 // Convenient functions
191 bool MirrorX() const noexcept
192 {
193 return (pixelsMirrored_ == SensorPixelsMirrored::X || pixelsMirrored_ == SensorPixelsMirrored::XY);
194 }
195 bool MirrorY() const noexcept
196 {
197 return (pixelsMirrored_ == SensorPixelsMirrored::Y || pixelsMirrored_ == SensorPixelsMirrored::XY);
198 }
199 };
200#pragma pack(pop)
201
202 CVB_END_INLINE_NS
203
204} // namespace Cvb
Multi-purpose 2D vector class.
Definition point_2d.hpp:20
Rectangle object.
Definition rect.hpp:24
T Height() const noexcept
Gets the height of the rectangle.
Definition rect.hpp:184
T Top() const noexcept
Gets first row of the rectangle.
Definition rect.hpp:104
T Left() const noexcept
Gets first column of the rectangle.
Definition rect.hpp:84
T Width() const noexcept
Gets the width of the rectangle.
Definition rect.hpp:164
SensorSettings() noexcept
Default ctor.
Definition sensor_settings.hpp:29
SensorSettings(double rangeScale, SensorPixelPosition pixelPosition, SensorPixelsMirrored pixelsMirrored, Rect< int > sensorRoi, Point2D< double > resolutionReduction)
Ctor passing sensor settings.
Definition sensor_settings.hpp:63
double RangeScale() const noexcept
Gets range scale (z factor).
Definition sensor_settings.hpp:105
bool operator==(const SensorSettings &other) const noexcept
Compares to other sensor settings.
Definition sensor_settings.hpp:156
bool operator!=(const SensorSettings &other) const noexcept
Compares to other sensor settings.
Definition sensor_settings.hpp:170
Point2D< double > ResolutionReduction() const noexcept
Gets horizontal (X) and vertical (Y) resolution reduction factors (due to binning).
Definition sensor_settings.hpp:145
SensorPixelsMirrored PixelsMirrored() const noexcept
Gets information if sensor pixels are mirrored.
Definition sensor_settings.hpp:125
SensorPixelPosition PixelPosition() const noexcept
Gets pixel position in y on sensor.
Definition sensor_settings.hpp:115
Rect< int > SensorRoi() const noexcept
Gets sensor region of interest (ROI).
Definition sensor_settings.hpp:135
Stores a pair of numbers that represents the width and the height of a subject, typically a rectangle...
Definition size_2d.hpp:20
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
SensorPixelPosition
Indicates pixel position on sensor.
Definition core_3d.hpp:248
@ Absolute
Scaled rangemap values represent absolute pixel position on sensor.
Definition core_3d.hpp:252
SensorPixelsMirrored
Indicates if sensor pixels are mirrored in rangemap.
Definition core_3d.hpp:262
@ X
Sensor pixel values are mirrored in X (or denoted by u), so that the columns of the range map will be...
Definition core_3d.hpp:272
@ Y
Sensor pixel values are mirrored in Y (or denoted by v), so that the range map pixel values will be f...
Definition core_3d.hpp:278
@ None
No mirroring is applied.
Definition core_3d.hpp:266
@ XY
Sensor pixel values are mirrored in X and Y.
Definition core_3d.hpp:283