32 intensity(m_intensity),
33 validRange(m_validRange)
39 uint8_t CObservation2DRangeScan::serializeGetVersion()
const {
return 7; }
40 void CObservation2DRangeScan::serializeTo(
44 out << aperture << rightToLeft << maxRange << sensorPose;
47 ASSERT_(validRange.size() == scan.size());
51 out.
WriteBuffer(&m_validRange[0],
sizeof(m_validRange[0]) * N);
61 out << hasIntensity();
65 void CObservation2DRangeScan::truncateByDistanceAndAngle(
66 float min_distance,
float max_angle,
float min_height,
float max_height,
72 unsigned int nPts = scan.
size();
75 auto itValid = m_validRange.begin();
76 for (
auto itScan = m_scan.begin(); itScan != m_scan.end(); itScan++, itValid++, k++)
78 float ang = fabs(k * aperture / nPts - aperture * 0.5);
79 float x = (*itScan) * cos(ang);
81 if (min_height != 0 || max_height != 0)
83 ASSERT_(max_height > min_height);
84 if (*itScan < min_distance || ang > max_angle ||
85 x > h - min_height ||
x < h - max_height)
88 else if (*itScan < min_distance || ang > max_angle)
93 void CObservation2DRangeScan::serializeFrom(
104 in >> aperture >> rightToLeft >> maxRange >> sensorPose >>
111 if (N)
in.ReadBufferFixEndianness(&m_scan[0], N);
117 &m_validRange[0],
sizeof(m_validRange[0]) * N);
122 for (i = 0; i < N; i++) m_validRange[i] = scan[i] < maxRange;
155 in >> aperture >> rightToLeft >> maxRange >> sensorPose;
164 in.ReadBufferFixEndianness(&m_scan[0], N);
165 in.ReadBuffer(&m_validRange[0],
sizeof(m_validRange[0]) * N);
168 in.ReadBufferFixEndianness(×tamp, 1);
185 setScanHasIntensity(hasIntensity);
186 if (hasIntensity && N)
188 in.ReadBufferFixEndianness(&m_intensity[0], N);
208 mxArray* CObservation2DRangeScan::writeToMatlab()
const 211 const char* fields[] = {
"class",
214 "scan",
"validRange",
219 "stdError",
"beamAperture",
223 mexplus::MxArray obs_struct(
224 mexplus::MxArray::Struct(
sizeof(fields) /
sizeof(fields[0]), fields));
226 obs_struct.set(
"class", this->GetRuntimeClass()->className);
228 obs_struct.set(
"ts", this->timestamp);
229 obs_struct.set(
"sensorLabel", this->sensorLabel);
231 obs_struct.set(
"scan", this->m_scan);
235 obs_struct.set(
"validRange", this->m_validRange);
236 obs_struct.set(
"intensity", this->m_intensity);
237 obs_struct.set(
"aperture", this->aperture);
238 obs_struct.set(
"rightToLeft", this->rightToLeft);
239 obs_struct.set(
"maxRange", this->maxRange);
240 obs_struct.set(
"stdError", this->stdError);
241 obs_struct.set(
"beamAperture", this->beamAperture);
242 obs_struct.set(
"deltaPitch", this->deltaPitch);
243 obs_struct.set(
"pose", this->sensorPose);
245 return obs_struct.release();
254 bool CObservation2DRangeScan::isPlanarScan(
const double tolerance)
const 256 return sensorPose.isHorizontal(tolerance);
259 bool CObservation2DRangeScan::hasIntensity()
const {
return m_has_intensity; }
260 void CObservation2DRangeScan::setScanHasIntensity(
bool setHasIntensityFlag)
262 m_has_intensity = setHasIntensityFlag;
268 void CObservation2DRangeScan::filterByExclusionAreas(
271 if (areas.empty())
return;
276 size_t sizeRangeScan = scan.size();
278 ASSERT_(scan.size() == validRange.size());
280 if (!sizeRangeScan)
return;
284 Ang = -0.5 * aperture;
285 dA = aperture / (sizeRangeScan - 1);
289 Ang = +0.5 * aperture;
290 dA = -aperture / (sizeRangeScan - 1);
293 auto valid_it = m_validRange.begin();
294 for (
auto scan_it = m_scan.begin(); scan_it != m_scan.end(); scan_it++, valid_it++)
303 const double Lx = *scan_it * cos(Ang);
304 const double Ly = *scan_it * sin(Ang);
309 this->sensorPose.composePoint(Lx, Ly, 0, Gx, Gy, Gz);
313 i != areas.end(); ++i)
315 if (i->first.PointIntoPolygon(Gx, Gy) &&
316 (Gz >= i->second.first && Gz <= i->second.second))
330 void CObservation2DRangeScan::filterByExclusionAreas(
331 const std::vector<mrpt::math::CPolygon>& areas)
333 if (areas.empty())
return;
336 for (
size_t i = 0; i < areas.size(); i++)
338 TListExclusionAreasWithRanges::value_type dat;
339 dat.first = areas[i];
340 dat.second.first = -std::numeric_limits<double>::max();
341 dat.second.second = std::numeric_limits<double>::max();
345 filterByExclusionAreas(lst);
351 void CObservation2DRangeScan::filterByExclusionAngles(
352 const std::vector<std::pair<double, double>>& angles)
354 if (angles.empty())
return;
359 const size_t sizeRangeScan = scan.size();
361 ASSERT_(scan.size() == validRange.size());
363 if (!sizeRangeScan)
return;
367 Ang = -0.5 * aperture;
368 dA = aperture / (sizeRangeScan - 1);
372 Ang = +0.5 * aperture;
373 dA = -aperture / (sizeRangeScan - 1);
377 for (vector<pair<double, double>>::
const_iterator itA = angles.begin();
378 itA != angles.end(); ++itA)
384 if (ap_idx_ini < 0) ap_idx_ini = 0;
385 if (ap_idx_end < 0) ap_idx_end = 0;
387 if (ap_idx_ini > (
int)sizeRangeScan) ap_idx_ini = sizeRangeScan - 1;
388 if (ap_idx_end > (
int)sizeRangeScan) ap_idx_end = sizeRangeScan - 1;
390 const size_t idx_ini = ap_idx_ini;
391 const size_t idx_end = ap_idx_end;
393 if (idx_end >= idx_ini)
395 for (
size_t i = idx_ini; i <= idx_end; i++) m_validRange[i] =
false;
399 for (
size_t i = 0; i < idx_end; i++) m_validRange[i] =
false;
401 for (
size_t i = idx_ini; i < sizeRangeScan; i++)
402 m_validRange[i] =
false;
429 void CObservation2DRangeScan::internal_buildAuxPointsMap(
430 const void* options)
const 433 throw std::runtime_error(
434 "[CObservation2DRangeScan::buildAuxPointsMap] ERROR: This function " 435 "needs linking against mrpt-maps.\n");
437 (*ptr_internal_build_points_map_from_scan2D)(*
this, m_cachedMap, options);
443 p.nRays = this->scan.size();
444 p.aperture = this->aperture;
445 p.rightToLeft = this->rightToLeft;
451 if (
a.nRays !=
b.nRays)
return a.nRays <
b.nRays;
452 if (
a.aperture !=
b.aperture)
return a.aperture <
b.aperture;
453 if (
a.rightToLeft !=
b.rightToLeft)
return a.rightToLeft;
457 void CObservation2DRangeScan::getDescriptionAsText(std::ostream& o)
const 459 CObservation::getDescriptionAsText(o);
460 o <<
"Homogeneous matrix for the sensor's 3D pose, relative to robot " 462 o << sensorPose.getHomogeneousMatrixVal<
CMatrixDouble44>() << sensorPose
466 "Samples direction: %s\n",
467 (rightToLeft) ?
"Right->Left" :
"Left->Right");
468 o <<
format(
"Points in the scan: %u\n", (
unsigned)scan.size());
469 o <<
format(
"Estimated sensor 'sigma': %f\n", stdError);
471 "Increment in pitch during the scan: %f deg\n",
RAD2DEG(deltaPitch));
474 for (i = 0; i < scan.size(); i++)
475 if (!validRange[i]) inval++;
476 o <<
format(
"Invalid points in the scan: %u\n", (
unsigned)inval);
478 o <<
format(
"Sensor maximum range: %.02f m\n", maxRange);
480 "Sensor field-of-view (\"aperture\"): %.01f deg\n",
RAD2DEG(aperture));
482 o <<
"Raw scan values: [";
483 for (i = 0; i < scan.size(); i++) o <<
format(
"%.03f ", scan[i]);
486 o <<
"Raw valid-scan values: [";
487 for (i = 0; i < validRange.size(); i++)
488 o <<
format(
"%u ", validRange[i] ? 1 : 0);
493 o <<
"Raw intensity values: [";
494 for (i = 0; i < m_intensity.size(); i++)
495 o <<
format(
"%d ", m_intensity[i]);
500 float CObservation2DRangeScan::getScanRange(
const size_t i)
const 506 void CObservation2DRangeScan::setScanRange(
const size_t i,
const float val)
512 int CObservation2DRangeScan::getScanIntensity(
const size_t i)
const 515 return m_intensity[i];
517 void CObservation2DRangeScan::setScanIntensity(
const size_t i,
const int val)
520 m_intensity[i] =
val;
523 bool CObservation2DRangeScan::getScanRangeValidity(
const size_t i)
const 526 return m_validRange[i] != 0;
528 void CObservation2DRangeScan::setScanRangeValidity(
529 const size_t i,
const bool val)
532 m_validRange[i] =
val ? 1 : 0;
535 void CObservation2DRangeScan::resizeScan(
const size_t len)
538 m_intensity.resize(
len);
539 m_validRange.resize(
len);
542 void CObservation2DRangeScan::resizeScanAndAssign(
543 const size_t len,
const float rangeVal,
const bool rangeValidity,
546 m_scan.assign(
len, rangeVal);
547 m_validRange.assign(
len, rangeValidity);
548 m_intensity.assign(
len, rangeIntensity);
551 size_t CObservation2DRangeScan::getScanSize()
const {
return m_scan.size(); }
552 void CObservation2DRangeScan::loadFromVectors(
553 size_t nRays,
const float* scanRanges,
const char* scanValidity)
558 for (
size_t i = 0; i < nRays; i++)
560 m_scan[i] = scanRanges[i];
561 m_validRange[i] = scanValidity[i];
#define THROW_EXCEPTION(msg)
scan2pts_functor ptr_internal_build_points_map_from_scan2D
#define ASSERT_BELOW_(__A, __B)
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
static constexpr size_type size()
void WriteBufferFixEndianness(const T *ptr, size_t ElementCount)
Writes a sequence of elemental datatypes, taking care of reordering their bytes from the running arch...
bool operator<(const T2DScanProperties &a, const T2DScanProperties &b)
Order operator, so T2DScanProperties can appear in associative STL containers.
void internal_set_build_points_map_from_scan2D(scan2pts_functor fn)
void WriteBuffer(const void *Buffer, size_t Count)
Writes a block of bytes to the stream from Buffer.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
#define ASSERT_(f)
Defines an assertion mechanism.
A numeric matrix of compile-time fixed size.
This base provides a set of functions for maths stuff.
Auxiliary struct that holds all the relevant geometry information about a 2D scan.
T wrapTo2Pi(T a)
Modifies the given angle to translate it into the [0,2pi[ range.
This namespace contains representation of robot actions and observations.
#define IMPLEMENTS_MEXPLUS_FROM(complete_type)
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
struct mxArray_tag mxArray
Forward declaration for mxArray (avoid #including as much as possible to speed up compiling) ...
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
Virtual base class for "archives": classes abstracting I/O streams.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Declares a class that represents any robot's observation.
std::vector< std::pair< mrpt::math::CPolygon, std::pair< double, double > >> TListExclusionAreasWithRanges
Used in filterByExclusionAreas.
void(*)(const mrpt::obs::CObservation2DRangeScan &obs, mrpt::maps::CMetricMap::Ptr &out_map, const void *insertOps) scan2pts_functor
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
GLenum GLsizei GLenum format
This class is a "CSerializable" wrapper for "CMatrixFloat".
unsigned __int32 uint32_t
GLubyte GLubyte GLubyte a
const Scalar * const_iterator