CVB++ 14.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 : SensorSettings(1.0, SensorPixelPosition::Absolute, SensorPixelsMirrored::None, Rect<int>{Point2D<int>{0, 0}, Size2D<int> {0, 0}}, Point2D<double>{1.0, 1.0})
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
161private:
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
180CVB_END_INLINE_NS
181
182}
Rectangle object.
Definition: rect.hpp:26
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:54
double RangeScale() const noexcept
Gets range scale (z factor).
Definition: sensor_settings.hpp:93
bool operator==(const SensorSettings &other) const noexcept
Compares to other sensor settings.
Definition: sensor_settings.hpp:132
bool operator!=(const SensorSettings &other) const noexcept
Compares to other sensor settings.
Definition: sensor_settings.hpp:156
Point2D< double > ResolutionReduction() const noexcept
Gets horizontal (X) and vertical (Y) resolution reduction factors (due to binning).
Definition: sensor_settings.hpp:124
SensorPixelsMirrored PixelsMirrored() const noexcept
Gets information if sensor pixels are mirrored.
Definition: sensor_settings.hpp:107
SensorPixelPosition PixelPosition() const noexcept
Gets pixel position in y on sensor.
Definition: sensor_settings.hpp:100
Rect< int > SensorRoi() const noexcept
Gets sensor region of interest (ROI).
Definition: sensor_settings.hpp:114
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.