24 if (!cloud || !grid) {
41 maxPhiShifted = parameters.
maxPhi;
43 maxThetaShifted = parameters.
maxTheta;
48 std::vector<AngleAndSpan> angles;
49 std::vector<AngleAndSpan> anglesShifted;
53 const int* _indexGrid = grid->indexes.data();
54 for (
unsigned j = 0; j < grid->h; ++j) {
55 unsigned minIndex = grid->w;
56 unsigned maxIndex = 0;
57 for (
unsigned i = 0; i < grid->w; ++i) {
58 if (_indexGrid[i] >= 0) {
59 if (i < minIndex) minIndex = i;
60 if (i > maxIndex) maxIndex = i;
64 if (maxIndex > minIndex) {
66 maxPhiCurrentLine = 0;
68 maxPhiCurrentLineShifted = 0;
69 for (
unsigned k = minIndex; k <= maxIndex; ++k) {
70 int index = _indexGrid[k];
73 static_cast<unsigned>(index)));
74 if (cloudToSensorTrans)
75 cloudToSensorTrans->
apply(P);
82 (p < 0 ? p +
static_cast<
87 if (minPhiCurrentLine > p)
88 minPhiCurrentLine = p;
89 else if (maxPhiCurrentLine < p)
90 maxPhiCurrentLine = p;
92 if (minPhiCurrentLineShifted > pShifted)
93 minPhiCurrentLineShifted = pShifted;
94 else if (maxPhiCurrentLineShifted < pShifted)
95 maxPhiCurrentLineShifted = pShifted;
97 minPhiCurrentLine = maxPhiCurrentLine = p;
98 minPhiCurrentLineShifted =
99 maxPhiCurrentLineShifted = pShifted;
109 if (parameters.
minPhi > minPhiCurrentLine)
110 parameters.
minPhi = minPhiCurrentLine;
111 if (parameters.
maxPhi < maxPhiCurrentLine)
112 parameters.
maxPhi = maxPhiCurrentLine;
114 if (minPhiShifted > minPhiCurrentLineShifted)
115 minPhiShifted = minPhiCurrentLineShifted;
116 if (maxPhiShifted < maxPhiCurrentLineShifted)
117 maxPhiShifted = maxPhiCurrentLineShifted;
119 unsigned span = maxIndex - minIndex + 1;
120 ScalarType angle_rad =
static_cast<ScalarType
>(
121 (maxPhiCurrentLine - minPhiCurrentLine) / span);
122 angles.emplace_back(angle_rad, span);
124 ScalarType angleShifted_rad =
125 static_cast<ScalarType
>((maxPhiCurrentLineShifted -
126 minPhiCurrentLineShifted) /
128 anglesShifted.emplace_back(angleShifted_rad, span);
131 _indexGrid += grid->w;
134 if (!angles.empty()) {
139 if (spanShifted < 0.99 * span) {
141 angles = anglesShifted;
142 parameters.
minPhi = minPhiShifted;
143 parameters.
maxPhi = maxPhiShifted;
148 size_t maxSpanIndex = 0;
149 for (
size_t i = 1; i < angles.size(); ++i) {
150 if (angles[i].second > angles[maxSpanIndex].second ||
151 (angles[i].second == angles[maxSpanIndex].second &&
152 angles[i].first > angles[maxSpanIndex].first)) {
158 angles[maxSpanIndex].first);
160 CVLog::Print(QString(
"[Scan grid] Detected pitch step: %1 "
161 "degrees (span [%2 - %3])")
171 "[Scan grid] Not enough valid points to compute the "
172 "scan angular step (pitch)!");
179 std::vector<AngleAndSpan> angles;
180 std::vector<AngleAndSpan> anglesShifted;
184 for (
unsigned i = 0; i < grid->w; ++i) {
185 const int* _indexGrid = &(grid->indexes[i]);
187 unsigned minIndex = grid->h;
188 unsigned maxIndex = 0;
189 for (
unsigned j = 0; j < grid->h; ++j) {
190 if (_indexGrid[j * grid->w] >= 0) {
191 if (j < minIndex) minIndex = j;
192 if (j > maxIndex) maxIndex = j;
196 if (maxIndex > minIndex) {
198 maxThetaCurrentCol = 0;
200 maxThetaCurrentColShifted = 0;
201 for (
unsigned k = minIndex; k <= maxIndex; ++k) {
202 int index = _indexGrid[k * grid->w];
206 static_cast<unsigned>(index)));
207 if (cloudToSensorTrans)
208 cloudToSensorTrans->
apply(P);
212 (t < 0 ? t +
static_cast<
217 if (minThetaCurrentColShifted > tShifted)
218 minThetaCurrentColShifted = tShifted;
219 else if (maxThetaCurrentColShifted < tShifted)
220 maxThetaCurrentColShifted = tShifted;
222 if (minThetaCurrentCol > t)
223 minThetaCurrentCol = t;
224 else if (maxThetaCurrentCol < t)
225 maxThetaCurrentCol = t;
227 minThetaCurrentCol = maxThetaCurrentCol = t;
228 minThetaCurrentColShifted =
229 maxThetaCurrentColShifted = tShifted;
234 if (parameters.
minTheta > minThetaCurrentCol)
235 parameters.
minTheta = minThetaCurrentCol;
236 if (parameters.
maxTheta < maxThetaCurrentCol)
237 parameters.
maxTheta = maxThetaCurrentCol;
239 if (minThetaShifted > minThetaCurrentColShifted)
240 minThetaShifted = minThetaCurrentColShifted;
241 if (maxThetaShifted < maxThetaCurrentColShifted)
242 maxThetaShifted = maxThetaCurrentColShifted;
244 unsigned span = maxIndex - minIndex;
245 ScalarType angle_rad =
static_cast<ScalarType
>(
246 (maxThetaCurrentCol - minThetaCurrentCol) / span);
247 angles.emplace_back(angle_rad, span);
249 ScalarType angleShifted_rad =
static_cast<ScalarType
>(
250 (maxThetaCurrentColShifted -
251 minThetaCurrentColShifted) /
253 anglesShifted.emplace_back(angleShifted_rad, span);
257 if (!angles.empty()) {
260 maxThetaShifted - minThetaShifted;
263 if (spanShifted < 0.99 * span) {
265 angles = anglesShifted;
266 parameters.
minTheta = minThetaShifted;
267 parameters.
maxTheta = maxThetaShifted;
272 size_t maxSpanIndex = 0;
273 for (
size_t i = 1; i < angles.size(); ++i) {
274 if (angles[i].second > angles[maxSpanIndex].second ||
275 (angles[i].second == angles[maxSpanIndex].second &&
276 angles[i].first > angles[maxSpanIndex].first)) {
282 angles[maxSpanIndex].first);
284 CVLog::Print(QString(
"[Scan grid] Detected yaw step: %1 "
285 "degrees (span [%2 - %3])")
295 "[Scan grid] Not enough valid points to compute the "
296 "scan angular steps!");
300 }
catch (
const std::bad_alloc&) {
302 "[Scan grid] Not enough memory to compute the scan angular "
constexpr PointCoordinateType PC_ONE
'1' as a PointCoordinateType value
float PointCoordinateType
Type of the coordinates of a (N-D) point.
static bool Warning(const char *format,...)
Prints out a formatted warning message in console.
static bool Print(const char *format,...)
Prints out a formatted message in console.
Type norm() const
Returns vector norm.
virtual void setVisible(bool state)
Sets entity visibility.
Ground-based Laser sensor.
void setYawRange(PointCoordinateType minTheta, PointCoordinateType maxTheta)
Sets the yaw scanning limits.
void setPitchRange(PointCoordinateType minPhi, PointCoordinateType maxPhi)
Sets the pitch scanning limits.
void setSensorRange(PointCoordinateType range)
Sets the sensor max. range.
void setYawStep(PointCoordinateType dTheta)
Sets the yaw step.
void setPitchStep(PointCoordinateType dPhi)
Sets the pitch step.
void apply(float vec[3]) const
Applies transformation to a 3D vector (in place) - float version.
Float version of ccGLMatrixTpl.
virtual void setEnabled(bool state)
Sets the "enabled" property.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
void setGraphicScale(PointCoordinateType scale)
Sets the sensor graphic representation scale.
const CCVector3 * getPoint(unsigned index) const override
float RadiansToDegrees(int radians)
Convert radians to degrees.
QSharedPointer< Grid > Shared
Shared type.