51 class CSimplePointsMap;
52 class CObservation2DRangeScan;
53 class CObservation3DRangeScan;
55 using namespace mrpt::poses;
56 using namespace mrpt::math;
80 public mrpt::utils::KDTreeCapable<CPointsMap>,
95 std::vector<unsigned int>
uVars;
124 virtual void reserve(
size_t newLength) = 0;
130 virtual void resize(
size_t newLength) = 0;
136 virtual void setSize(
size_t newLength) = 0;
139 virtual void setPointFast(
size_t index,
float x,
float y,
float z)=0;
142 virtual void insertPointFast(
float x,
float y,
float z = 0 ) = 0;
145 virtual void copyFrom(
const CPointsMap &obj) = 0;
151 virtual void getPointAllFieldsFast(
const size_t index, std::vector<float> & point_data )
const = 0;
157 virtual void setPointAllFieldsFast(
const size_t index,
const std::vector<float> & point_data ) = 0;
162 virtual void addFrom_classSpecific(
const CPointsMap &anotherMap,
const size_t nPreviousPoints) = 0;
172 virtual float squareDistanceToClosestCorrespondence(
177 return squareDistanceToClosestCorrespondence(static_cast<float>(p0.
x),static_cast<float>(p0.
y));
191 void dumpToTextStream(
CStream &out)
const;
217 void loadFromConfigFile(
219 const std::string §ion);
222 void dumpToTextStream(
CStream &out)
const;
224 void writeToStream(
CStream &out)
const;
225 void readFromStream(
CStream &in);
245 virtual void addFrom(
const CPointsMap &anotherMap);
250 this->addFrom(anotherMap);
258 void insertAnotherMap(
277 bool load2Dor3D_from_text_file(
const std::string &file,
const bool is_3D);
282 bool save2D_to_text_file(
const std::string &file)
const;
287 bool save3D_to_text_file(
const std::string &file)
const;
291 void saveMetricMapRepresentationToFile(
292 const std::string &filNamePrefix
295 std::string fil( filNamePrefix + std::string(
".txt") );
296 save3D_to_text_file( fil );
300 virtual bool savePCDFile(
const std::string &filename,
bool save_as_binary)
const;
307 inline size_t size()
const {
return x.size(); }
318 unsigned long getPoint(
size_t index,
float &x,
float &y,
float &z)
const;
320 unsigned long getPoint(
size_t index,
float &x,
float &y)
const;
322 unsigned long getPoint(
size_t index,
double &x,
double &y,
double &z)
const;
324 unsigned long getPoint(
size_t index,
double &x,
double &y)
const;
338 virtual void getPoint(
size_t index,
float &x,
float &y,
float &z,
float &R,
float &G,
float &B )
const
340 getPoint(index,x,y,z);
346 inline void getPointFast(
size_t index,
float &x,
float &y,
float &z)
const { x=this->x[index]; y=this->y[index]; z=this->z[index]; }
354 inline void setPoint(
size_t index,
float x,
float y,
float z) {
356 setPointFast(index,x,y,z);
366 virtual void setPoint(
size_t index,
float x,
float y,
float z,
float R,
float G,
float B) {
setPoint(index,x,y,z); }
376 void getPointsBuffer(
size_t &outPointsCount,
const float *&xs,
const float *&ys,
const float *&zs )
const;
390 template <
class VECTOR>
391 void getAllPoints( VECTOR &xs, VECTOR &ys, VECTOR &zs,
size_t decimation = 1 )
const
395 const size_t Nout = x.size() / decimation;
399 size_t idx_in, idx_out;
400 for (idx_in=0,idx_out=0;idx_out<Nout;idx_in+=decimation,++idx_out)
402 xs[idx_out]=x[idx_in];
403 ys[idx_out]=y[idx_in];
404 zs[idx_out]=z[idx_in];
409 inline void getAllPoints(std::vector<TPoint3D> &ps,
size_t decimation=1)
const {
410 std::vector<float> dmy1,dmy2,dmy3;
411 getAllPoints(dmy1,dmy2,dmy3,decimation);
412 ps.resize(dmy1.size());
413 for (
size_t i=0;i<dmy1.size();i++) {
414 ps[i].x=
static_cast<double>(dmy1[i]);
415 ps[i].y=
static_cast<double>(dmy2[i]);
416 ps[i].z=
static_cast<double>(dmy3[i]);
424 void getAllPoints( std::vector<float> &xs, std::vector<float> &ys,
size_t decimation = 1 )
const;
426 inline void getAllPoints(std::vector<TPoint2D> &ps,
size_t decimation=1)
const {
427 std::vector<float> dmy1,dmy2;
428 getAllPoints(dmy1,dmy2,decimation);
429 ps.resize(dmy1.size());
430 for (
size_t i=0;i<dmy1.size();i++) {
431 ps[i].x=
static_cast<double>(dmy1[i]);
432 ps[i].y=
static_cast<double>(dmy2[i]);
439 inline void insertPoint(
float x,
float y,
float z=0 ) { insertPointFast(x,y,z); mark_as_modified(); }
450 template <
typename VECTOR>
451 inline void setAllPointsTemplate(
const VECTOR &X,
const VECTOR &Y,
const VECTOR &Z = VECTOR())
453 const size_t N = X.size();
455 ASSERT_(Z.size()==0 || Z.size()==X.size())
457 const bool z_valid = !Z.empty();
458 if (z_valid)
for (
size_t i=0;i<N;i++) { this->setPointFast(i,X[i],Y[i],Z[i]); }
459 else for (
size_t i=0;i<N;i++) { this->setPointFast(i,X[i],Y[i],0); }
464 inline void setAllPoints(
const std::vector<float> &X,
const std::vector<float> &Y,
const std::vector<float> &Z) {
465 setAllPointsTemplate(X,Y,Z);
469 inline void setAllPoints(
const std::vector<float> &X,
const std::vector<float> &Y) {
470 setAllPointsTemplate(X,Y);
478 getPointAllFieldsFast(index,point_data);
487 setPointAllFieldsFast(index,point_data);
493 void clipOutOfRangeInZ(
float zMin,
float zMax);
497 void clipOutOfRange(
const CPoint2D &point,
float maxRange);
502 void applyDeletionMask(
const std::vector<bool> &mask );
523 void computeMatchingWith2D(
526 float maxDistForCorrespondence,
527 float maxAngularDistForCorrespondence,
528 const CPose2D &angularDistPivotPoint,
530 float &correspondencesRatio,
531 float *sumSqrDist = NULL,
532 bool onlyKeepTheClosest =
false,
533 bool onlyUniqueRobust =
false,
534 const size_t decimation_other_map_points = 1,
535 const size_t offset_other_map_points = 0 )
const;
554 void computeMatchingWith3D(
557 float maxDistForCorrespondence,
558 float maxAngularDistForCorrespondence,
559 const CPoint3D &angularDistPivotPoint,
561 float &correspondencesRatio,
562 float *sumSqrDist = NULL,
563 bool onlyKeepTheClosest =
true,
564 bool onlyUniqueRobust =
false,
565 const size_t decimation_other_map_points = 1,
566 const size_t offset_other_map_points = 0 )
const;
578 float compute3DMatchingRatio(
581 float minDistForCorr = 0.10f,
582 float minMahaDistForCorr = 2.0f
598 virtual void loadFromRangeScan(
600 const CPose3D *robotPose = NULL ) = 0;
611 virtual void loadFromRangeScan(
613 const CPose3D *robotPose = NULL ) = 0;
627 float minDistForFuse = 0.02f,
628 std::vector<bool> *notFusedPoints = NULL);
632 void changeCoordinatesReference(
const CPose2D &b);
636 void changeCoordinatesReference(
const CPose3D &b);
644 virtual bool isEmpty()
const;
647 inline bool empty()
const {
return isEmpty(); }
663 float getLargestDistanceFromOrigin()
const;
667 output_is_valid = m_largestDistanceFromOriginIsUpdated;
668 return m_largestDistanceFromOrigin;
674 void boundingBox(
float &min_x,
float &max_x,
float &min_y,
float &max_y,
float &min_z,
float &max_z )
const;
677 float dmy1,dmy2,dmy3,dmy4,dmy5,dmy6;
678 boundingBox(dmy1,dmy2,dmy3,dmy4,dmy5,dmy6);
687 void extractCylinder(
const CPoint2D ¢er,
const double radius,
const double zmin,
const double zmax,
CPointsMap *outMap );
698 inline void setHeightFilterLevels(
const double _z_min,
const double _z_max) { m_heightfilter_z_min=_z_min; m_heightfilter_z_max=_z_max; }
700 inline void getHeightFilterLevels(
double &_z_min,
double &_z_max)
const { _z_min=m_heightfilter_z_min; _z_max=m_heightfilter_z_max; }
718 virtual double computeObservationLikelihood(
const CObservation *obs,
const CPose3D &takenFrom );
733 template <
class POINTCLOUD>
734 void getPCLPointCloud(POINTCLOUD &cloud)
const
736 const size_t nThis = this->
size();
740 cloud.is_dense =
false;
741 cloud.points.resize(cloud.width * cloud.height);
742 for (
size_t i = 0; i < nThis; ++i) {
743 cloud.points[i].x =this->x[i];
744 cloud.points[i].y =this->y[i];
745 cloud.points[i].z =this->z[i];
759 if (dim==0)
return this->x[idx];
760 else if (dim==1)
return this->y[idx];
761 else if (dim==2)
return this->z[idx];
else return 0;
765 inline float kdtree_distance(
const float *p1,
const size_t idx_p2,
size_t size)
const
769 const float d0 = p1[0]-x[idx_p2];
770 const float d1 = p1[1]-y[idx_p2];
775 const float d0 = p1[0]-x[idx_p2];
776 const float d1 = p1[1]-y[idx_p2];
777 const float d2 = p1[2]-z[idx_p2];
778 return d0*d0+d1*d1+d2*d2;
785 template <
typename BBOX>
786 bool kdtree_get_bbox(BBOX &bb)
const
790 bb[0].low, bb[0].high,
791 bb[1].low, bb[1].high,
794 bb[2].low = min_z; bb[2].high = max_z;
803 std::vector<float> x,y,
z;
818 mutable float m_bb_min_x,m_bb_max_x, m_bb_min_y,m_bb_max_y,
m_bb_min_z,m_bb_max_z;
822 inline void mark_as_modified()
const
824 m_largestDistanceFromOriginIsUpdated=
false;
825 m_boundingBoxIsUpdated =
false;
826 kdtree_mark_as_outdated();
833 bool internal_insertObservation(
856 virtual size_t PLY_export_get_vertex_count()
const;
864 virtual void PLY_export_get_vertex(
882 template <
class Derived>
friend struct detail::loadFromRangeImpl;
883 template <
class Derived>
friend struct detail::pointmap_traits;
890 namespace global_settings
909 static const int HAS_RGB = 0;
910 static const int HAS_RGBf = 0;
911 static const int HAS_RGBu8 = 0;
916 inline size_t size()
const {
return m_obj.size(); }
918 inline void resize(
const size_t N) { m_obj.resize(N); }
921 template <
typename T>
922 inline void getPointXYZ(
const size_t idx, T &x,T &y, T &z)
const {
923 m_obj.getPointFast(idx,x,y,z);
927 m_obj.setPointFast(idx,x,y,z);