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{
10CVB_BEGIN_INLINE_NS
11
13
24#pragma pack(push, 4)
25class SensorSettings final
26{
27public:
28
30 SensorSettings() noexcept
31 : size_(sizeof(CExports::CVC3DSensorSettings))
32 , rangeScale_(1.0)
33 , pixelPosition_(SensorPixelPosition::Absolute)
34 , pixelsMirrored_(SensorPixelsMirrored::None)
35 , offsetLeft_(0)
36 , offsetTop_(0)
37 , width_(0)
38 , height_(0)
39 , resolutionReductionX_(1.0)
40 , resolutionReductionY_(1.0)
41 {
42 }
43
45
63 SensorSettings(double rangeScale, SensorPixelPosition pixelPosition, SensorPixelsMirrored pixelsMirrored, Rect<int> sensorRoi, Point2D<double> resolutionReduction)
64 : size_(sizeof(CExports::CVC3DSensorSettings))
65 , rangeScale_(rangeScale)
66 , pixelPosition_(pixelPosition)
67 , pixelsMirrored_(pixelsMirrored)
68 , offsetLeft_(sensorRoi.Left())
69 , offsetTop_(sensorRoi.Top())
70 , width_(sensorRoi.Width())
71 , height_(sensorRoi.Height())
72 , resolutionReductionX_(resolutionReduction.X())
73 , resolutionReductionY_(resolutionReduction.Y())
74{
75 static_assert(sizeof(SensorSettings) == sizeof(CExports::CVC3DSensorSettings),
76 "size of class SensorSettings and CExports::CVC3DSensorSettings must be equal");
77
78 if (sensorRoi.Left() == 0 && sensorRoi.Top() == 0 && sensorRoi.Width() == 0 && sensorRoi.Height() == 0)
79 {
80 if (MirrorX() || MirrorY())
81 throw std::invalid_argument("Sensor ROI is not valid");
82 }
83
84 if (!MirrorX() && sensorRoi.Width() < 0)
85 throw std::invalid_argument("reverse_x = false and sensorRoi.Width < 0 are contradictory. Please set reverse_x to TRUE.");
86
87 if (!MirrorY() && sensorRoi.Height() < 0)
88 throw std::invalid_argument("reverse_y = false and sensorRoi.Height < 0 are contradictory. Please set reverse_y to TRUE.");
89
90 if (sensorRoi.Left() < 0 || sensorRoi.Top() < 0)
91 throw std::invalid_argument("Sensor ROI is not valid. Offset must be positive.");
92
93 if (pixelPosition_ == SensorPixelPosition::Absolute && sensorRoi.Top() != 0)
94 throw std::invalid_argument("Sensor ROI is not valid: sensorRoi.Top must be zero as absolutePosition = true");
95 }
96
98
102 double RangeScale() const noexcept { return rangeScale_; }
103
105
109 SensorPixelPosition PixelPosition() const noexcept { return pixelPosition_; }
110
112
116 SensorPixelsMirrored PixelsMirrored() const noexcept { return pixelsMirrored_; }
117
119
123 Rect<int> SensorRoi() const noexcept
124 {
125 return Rect<int>{Point2D<int>{offsetLeft_, offsetTop_}, Size2D<int>{width_, height_}};
126 }
127
129
133 Point2D<double> ResolutionReduction() const noexcept { return { resolutionReductionX_, resolutionReductionY_ }; }
134
136
141 bool operator==(const SensorSettings& other) const noexcept
142 {
143 return size_ == other.size_
144 && rangeScale_ == other.rangeScale_
145 && pixelPosition_ == other.pixelPosition_
146 && pixelsMirrored_ == other.pixelsMirrored_
147 && SensorRoi() == other.SensorRoi()
148 && resolutionReductionX_ == other.resolutionReductionX_
149 && resolutionReductionY_ == other.resolutionReductionY_;
150 }
151
153
158 bool operator!=(const SensorSettings& other) const noexcept
159 {
160 return !(*this == other);
161 }
162
163private:
164
165 int size_;
166 double rangeScale_;
167 SensorPixelPosition pixelPosition_;
168 SensorPixelsMirrored pixelsMirrored_;
169
170 CExports::cvbdim_t offsetLeft_;
171 CExports::cvbdim_t offsetTop_;
172 CExports::cvbdim_t width_;
173 CExports::cvbdim_t height_;
174
175 // should be a Point2D as the packing shifts the start by 4 byte
176 double resolutionReductionX_;
177 double resolutionReductionY_;
178
179 // Convenient functions
180 bool MirrorX() const noexcept { return (pixelsMirrored_ == SensorPixelsMirrored::X || pixelsMirrored_ == SensorPixelsMirrored::XY); }
181 bool MirrorY() const noexcept { return (pixelsMirrored_ == SensorPixelsMirrored::Y || pixelsMirrored_ == SensorPixelsMirrored::XY); }
182};
183#pragma pack(pop)
184
185CVB_END_INLINE_NS
186
187}
T Height() const noexcept
Gets the height of the rectangle.
Definition: rect.hpp:191
T Top() const noexcept
Gets first row of the rectangle.
Definition: rect.hpp:111
T Left() const noexcept
Gets first column of the rectangle.
Definition: rect.hpp:91
T Width() const noexcept
Gets the width of the rectangle.
Definition: rect.hpp:171
Class to store camera sensor settings.
Definition: sensor_settings.hpp:26
SensorSettings() noexcept
Default ctor.
Definition: sensor_settings.hpp:30
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:102
bool operator==(const SensorSettings &other) const noexcept
Compares to other sensor settings.
Definition: sensor_settings.hpp:141
bool operator!=(const SensorSettings &other) const noexcept
Compares to other sensor settings.
Definition: sensor_settings.hpp:158
Point2D< double > ResolutionReduction() const noexcept
Gets horizontal (X) and vertical (Y) resolution reduction factors (due to binning).
Definition: sensor_settings.hpp:133
SensorPixelsMirrored PixelsMirrored() const noexcept
Gets information if sensor pixels are mirrored.
Definition: sensor_settings.hpp:116
SensorPixelPosition PixelPosition() const noexcept
Gets pixel position in y on sensor.
Definition: sensor_settings.hpp:109
Rect< int > SensorRoi() const noexcept
Gets sensor region of interest (ROI).
Definition: sensor_settings.hpp:123
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24
SensorPixelPosition
Indicates pixel position on sensor.
Definition: core_3d.hpp:246
@ Absolute
Scaled rangemap values represent absolute pixel position on sensor.
SensorPixelsMirrored
Indicates if sensor pixels are mirrored in rangemap.
Definition: core_3d.hpp:260
@ X
Sensor pixel values are mirrored in X (or denoted by u), so that the columns of the range map will be...
@ Y
Sensor pixel values are mirrored in Y (or denoted by v), so that the range map pixel values will be f...
@ XY
Sensor pixel values are mirrored in X and Y.