9 #ifndef opengl_CAngularObservationMesh_H
10 #define opengl_CAngularObservationMesh_H
84 rangeData.mode0.initial=a;
85 rangeData.mode0.final=b;
86 rangeData.mode0.increment=c;
92 rangeData.mode1.initial=a;
93 rangeData.mode1.final=b;
94 rangeData.mode1.amount=c;
100 rangeData.mode2.aperture=a;
101 rangeData.mode2.amount=b;
102 rangeData.mode2.negToPos=c;
110 if (increment==0)
throw std::logic_error(
"Invalid increment value.");
111 return TDoubleRange(initial,
final,increment);
117 return TDoubleRange(initial,
final,amount);
123 return TDoubleRange(aperture,amount,negToPos);
131 case 0:
return (
sign(rangeData.mode0.increment)==
sign(rangeData.mode0.final-rangeData.mode0.initial))?fabs(rangeData.mode0.final-rangeData.mode0.initial):0;
132 case 1:
return rangeData.mode1.final-rangeData.mode1.initial;
133 case 2:
return rangeData.mode2.aperture;
134 default:
throw std::logic_error(
"Unknown range type.");
144 case 1:
return rangeData.mode0.initial;
145 case 2:
return rangeData.mode2.negToPos?-rangeData.mode2.aperture/2:rangeData.mode2.aperture/2;
146 default:
throw std::logic_error(
"Unknown range type.");
155 case 0:
return (
sign(rangeData.mode0.increment)==
sign(rangeData.mode0.final-rangeData.mode0.initial))?rangeData.mode0.final:rangeData.mode0.initial;
156 case 1:
return rangeData.mode1.final;
157 case 2:
return rangeData.mode2.negToPos?rangeData.mode2.aperture/2:-rangeData.mode2.aperture/2;
158 default:
throw std::logic_error(
"Unknown range type.");
167 case 0:
return rangeData.mode0.increment;
168 case 1:
return (rangeData.mode1.final-rangeData.mode1.initial)/
static_cast<double>(rangeData.mode1.amount-1);
169 case 2:
return rangeData.mode2.negToPos?rangeData.mode2.aperture/
static_cast<double>(rangeData.mode2.amount-1):-rangeData.mode2.aperture/static_cast<double>(rangeData.mode2.amount-1);
170 default:
throw std::logic_error(
"Unknown range type.");
179 case 0:
return (
sign(rangeData.mode0.increment)==
sign(rangeData.mode0.final-rangeData.mode0.initial))?1+
static_cast<size_t>(ceil((rangeData.mode0.final-rangeData.mode0.initial)/rangeData.mode0.increment)):1;
180 case 1:
return rangeData.mode1.amount;
181 case 2:
return rangeData.mode2.amount;
182 default:
throw std::logic_error(
"Unknown range type.");
189 void values(std::vector<double> &vals)
const;
196 case 0:
return sign(rangeData.mode0.increment)>0;
197 case 1:
return sign(rangeData.mode1.final-rangeData.mode1.initial)>0;
198 case 2:
return rangeData.mode2.negToPos;
199 default:
throw std::logic_error(
"Unknown range type.");
210 void updateMesh()
const;
218 mutable std::vector<CSetOfTriangles::TTriangle>
triangles;
254 CAngularObservationMesh():mWireframe(true),meshUpToDate(false),mEnableTransparency(true),actualMesh(0,0),validityMatrix(0,0),pitchBounds(),scanSet() {}
273 return mEnableTransparency;
279 mEnableTransparency=enabled;
286 virtual void render_dl()
const;
295 void setPitchBounds(
const double initial,
const double final);
299 void setPitchBounds(
const std::vector<double> bounds);
303 void getPitchBounds(
double &initial,
double &
final)
const;
307 void getPitchBounds(std::vector<double> &bounds)
const;
311 void getScanSet(std::vector<CObservation2DRangeScan> &scans)
const;
315 bool setScanSet(
const std::vector<CObservation2DRangeScan> &scans);
320 void generateSetOfTriangles(CSetOfTrianglesPtr &res)
const;
324 void generatePointCloud(
CPointsMap *out_map)
const;
329 void getTracedRays(CSetOfLinesPtr &res)
const;
334 void getUntracedRays(CSetOfLinesPtr &res,
double dist)
const;
339 void generateSetOfTriangles(std::vector<TPolygon3D> &res)
const;
344 if (!meshUpToDate) updateMesh();
346 validity=validityMatrix;
359 FTrace1D(
const T &s,
const CPose3D &p,std::vector<double> &v,std::vector<char> &v2):initial(p),e(s),values(v),valid(v2) {}
363 if (e->traceRay(pNew,dist)) {
364 values.push_back(dist);
379 CAngularObservationMeshPtr &
caom;
381 std::vector<CObservation2DRangeScan> &
vObs;
384 FTrace2D(
const T &s,
const CPose3D &p,CAngularObservationMeshPtr &om,
const CAngularObservationMesh::TDoubleRange &y,std::vector<CObservation2DRangeScan> &obs,
const CPose3D &b):e(s),initial(p),caom(om),yaws(y),vObs(obs),pBase(b) {}
386 std::vector<double> yValues;
390 std::vector<double> values;
391 std::vector<char> valid;
392 size_t nY=yValues.size();
395 for_each(yValues.begin(),yValues.end(),
FTrace1D<T>(e,pNew,values,valid));
401 o.
scan.resize(values.size());
402 for (
size_t i=0;i<values.size();i++) o.
scan[i]=values[i];
413 template<
class T>
static void trace2DSetOfRays(
const T &e,
const CPose3D &initial,CAngularObservationMeshPtr &caom,
const TDoubleRange &pitchs,
const TDoubleRange &yaws);
420 std::vector<double> yValues;
422 std::vector<double> scanValues;
423 std::vector<char> valid;
425 scanValues.reserve(nV);
427 for_each(yValues.begin(),yValues.end(),
FTrace1D<T>(e,initial,scanValues,valid));
441 std::vector<double> pValues;
442 pitchs.values(pValues);
443 std::vector<CObservation2DRangeScan> vObs;
444 vObs.reserve(pValues.size());
445 for_each(pValues.begin(),pValues.end(),
FTrace2D<T>(e,initial,caom,yaws,vObs,initial));
446 caom->mWireframe=
false;
447 caom->mEnableTransparency=
false;
448 caom->setPitchBounds(pValues);
449 caom->setScanSet(vObs);
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
bool meshUpToDate
Mutable variable which controls if the object has suffered any change since last time the mesh was up...
std::vector< CObservation2DRangeScan > & vObs
std::vector< char > & valid
A mesh built from a set of 2D laser scan observations.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
double initialValue() const
Returns the first value of the range.
CAngularObservationMeshPtr & caom
Internal functor class to trace a set of rays.
double increment() const
Returns the increment between two consecutive values of the range.
Internal functor class to trace a ray.
TDoubleRange(double a, size_t b, bool c)
Constructor from aperture, amount of samples and scan direction.
std::vector< char > validRange
It's false (=0) on no reflected rays, referenced to elements in "scan" (Added in the streamming versi...
virtual ~CAngularObservationMesh()
Empty destructor.
std::vector< float > scan
The range values of the scan, in meters.
double deltaPitch
If the laser gathers data by sweeping in the pitch/elevation angle, this holds the increment in "pitc...
char rangeType
Range type.
void values(std::vector< double > &vals) const
Gets a vector with every value in the range.
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
FTrace2D(const T &s, const CPose3D &p, CAngularObservationMeshPtr &om, const CAngularObservationMesh::TDoubleRange &y, std::vector< CObservation2DRangeScan > &obs, const CPose3D &b)
bool mEnableTransparency
Whether the object may present transparencies or not.
void setWireframe(bool enabled=true)
Sets the display mode for the object.
This namespace contains algorithms for SLAM, localization, map building, representation of robot's ac...
CAngularObservationMesh()
Basic constructor.
A renderizable object suitable for rendering with OpenGL's display lists.
void operator()(double pitch)
CPose3D sensorPose
The 6D pose of the sensor on the robot.
float aperture
The aperture of the range finder, in radians (typically M_PI = 180 degrees).
bool negToPos() const
Returns the direction of the scan.
double aperture() const
Returns the total aperture of the range.
mrpt::math::CMatrixB validityMatrix
Scan validity matrix.
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
void getActualMesh(mrpt::math::CMatrixTemplate< mrpt::math::TPoint3D > &pts, mrpt::math::CMatrixBool &validity) const
Retrieves the full mesh, along with the validity matrix.
bool isWireframe() const
Returns whether the object is configured as wireframe or solid.
static void trace1DSetOfRays(const T &e, const CPose3D &initial, CObservation2DRangeScan &obs, const TDoubleRange &yaws)
2D ray tracing (will generate a vectorial mesh inside a plane).
float maxRange
The maximum range allowed by the device, in meters (e.g.
double finalValue() const
Returns the last value of the range.
int sign(T x)
Returns the sign of X as "1" or "-1".
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
std::vector< CObservation2DRangeScan > scanSet
Actual scan set which is used to generate the mesh.
mrpt::math::CMatrixTemplate< TPoint3D > actualMesh
Mutable object with the mesh's points.
bool BASE_IMPEXP traceRay(const vector< TPolygonWithPlane > &vec, const mrpt::poses::CPose3D &pose, double &dist)
Fast ray tracing method using polygons' properties.
std::vector< double > & values
bool isTransparencyEnabled() const
Returns whether the object may be transparent or not.
This template class provides the basic functionality for a general 2D any-size, resizable container o...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
static TDoubleRange CreateFromIncrement(double initial, double final, double increment)
Creates a range of values from the initial value, the final value and the increment.
static TDoubleRange CreateFromAmount(double initial, double final, size_t amount)
Creates a range of values from the initial value, the final value and a desired amount of samples...
const CAngularObservationMesh::TDoubleRange & yaws
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
bool mWireframe
Whether the mesh will be displayed wireframe or solid.
bool rightToLeft
The scanning direction.
static TDoubleRange CreateFromAperture(double aperture, size_t amount, bool negToPos=true)
Creates a zero-centered range of values from an aperture, an amount of samples and a direction...
size_t amount() const
Returns the total amount of values in this range.
FTrace1D(const T &s, const CPose3D &p, std::vector< double > &v, std::vector< char > &v2)
Range specification type, with several uses.
TDoubleRange(double a, double b, size_t c)
Constructor from initial value, final value and amount of samples.
This class is a "CSerializable" wrapper for "CMatrixBool".
TDoubleRange(double a, double b, double c)
Constructor from initial value, final value and range.
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans or other sensors...
void enableTransparency(bool enabled=true)
Enables or disables transparencies.
Union type with the actual data.
void operator()(double yaw)
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
std::vector< CSetOfTriangles::TTriangle > triangles
Actual set of triangles to be displayed.
std::vector< double > pitchBounds
Observation pitch range.