00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef CColouredPointsMap_H
00029 #define CColouredPointsMap_H
00030
00031 #include <mrpt/slam/CPointsMap.h>
00032 #include <mrpt/slam/CObservation2DRangeScan.h>
00033 #include <mrpt/slam/CObservationImage.h>
00034 #include <mrpt/utils/CSerializable.h>
00035 #include <mrpt/math/CMatrix.h>
00036 #include <mrpt/utils/stl_extensions.h>
00037
00038 #include <mrpt/maps/link_pragmas.h>
00039
00040 namespace mrpt
00041 {
00042 namespace slam
00043 {
00044 class CObservation3DRangeScan;
00045
00046
00047 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CColouredPointsMap, CPointsMap,MAPS_IMPEXP )
00048
00049
00050
00051
00052
00053
00054
00055 class MAPS_IMPEXP CColouredPointsMap : public CPointsMap
00056 {
00057
00058 DEFINE_SERIALIZABLE( CColouredPointsMap )
00059
00060 public:
00061
00062
00063 virtual ~CColouredPointsMap();
00064
00065
00066
00067 CColouredPointsMap();
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 virtual void reserve(size_t newLength);
00078
00079
00080
00081
00082
00083 virtual void resize(size_t newLength);
00084
00085
00086
00087
00088
00089 virtual void setSize(size_t newLength);
00090
00091
00092 virtual void setPointFast(size_t index,float x, float y, float z)
00093 {
00094 this->x[index] = x;
00095 this->y[index] = y;
00096 this->z[index] = z;
00097 }
00098
00099
00100 virtual void insertPointFast( float x, float y, float z = 0 );
00101
00102
00103
00104 virtual void copyFrom(const CPointsMap &obj);
00105
00106
00107
00108
00109
00110 virtual void getPointAllFieldsFast( const size_t index, std::vector<float> & point_data ) const {
00111 point_data.resize(6);
00112 point_data[0] = x[index];
00113 point_data[1] = y[index];
00114 point_data[2] = z[index];
00115 point_data[3] = m_color_R[index];
00116 point_data[4] = m_color_G[index];
00117 point_data[5] = m_color_B[index];
00118 }
00119
00120
00121
00122
00123
00124 virtual void setPointAllFieldsFast( const size_t index, const std::vector<float> & point_data ) {
00125 ASSERTDEB_(point_data.size()==6)
00126 x[index] = point_data[0];
00127 y[index] = point_data[1];
00128 z[index] = point_data[2];
00129 m_color_R[index] = point_data[3];
00130 m_color_G[index] = point_data[4];
00131 m_color_B[index] = point_data[5];
00132 }
00133
00134
00135 virtual void loadFromRangeScan(
00136 const CObservation2DRangeScan &rangeScan,
00137 const CPose3D *robotPose = NULL );
00138
00139
00140 virtual void loadFromRangeScan(
00141 const CObservation3DRangeScan &rangeScan,
00142 const CPose3D *robotPose = NULL );
00143
00144 protected:
00145
00146
00147 virtual void addFrom_classSpecific(const CPointsMap &anotherMap, const size_t nPreviousPoints);
00148
00149
00150
00151 template <class Derived> friend struct detail::loadFromRangeImpl;
00152 template <class Derived> friend struct detail::pointmap_traits;
00153
00154 public:
00155
00156
00157
00158
00159
00160
00161
00162
00163 bool save3D_and_colour_to_text_file(const std::string &file) const;
00164
00165
00166
00167
00168 virtual void setPoint(size_t index,float x, float y, float z, float R, float G, float B);
00169
00170
00171
00172 inline void setPoint(size_t index,float x, float y, float z) {
00173 ASSERT_BELOW_(index,this->size())
00174 setPointFast(index,x,y,z);
00175 mark_as_modified();
00176 }
00177
00178 inline void setPoint(size_t index,CPoint2D &p) { setPoint(index,p.x(),p.y(),0); }
00179
00180 inline void setPoint(size_t index,CPoint3D &p) { setPoint(index,p.x(),p.y(),p.z()); }
00181
00182 inline void setPoint(size_t index,float x, float y) { setPoint(index,x,y,0); }
00183
00184
00185
00186 virtual void insertPoint( float x, float y, float z, float R, float G, float B );
00187
00188
00189 inline void insertPoint( const CPoint3D &p ) { insertPoint(p.x(),p.y(),p.z()); }
00190
00191 inline void insertPoint( const mrpt::math::TPoint3D &p ) { insertPoint(p.x,p.y,p.z); }
00192
00193 inline void insertPoint( float x, float y, float z) { insertPointFast(x,y,z); mark_as_modified(); }
00194
00195
00196
00197
00198 void setPointColor(size_t index,float R, float G, float B);
00199
00200
00201 inline void setPointColor_fast(size_t index,float R, float G, float B)
00202 {
00203 this->m_color_R[index]=R;
00204 this->m_color_G[index]=G;
00205 this->m_color_B[index]=B;
00206 }
00207
00208
00209
00210 virtual void getPoint( size_t index, float &x, float &y, float &z, float &R, float &G, float &B ) const;
00211
00212
00213 unsigned long getPoint( size_t index, float &x, float &y, float &z) const;
00214
00215
00216 void getPointColor( size_t index, float &R, float &G, float &B ) const;
00217
00218
00219 inline void getPointColor_fast( size_t index, float &R, float &G, float &B ) const
00220 {
00221 R = m_color_R[index];
00222 G = m_color_G[index];
00223 B = m_color_B[index];
00224 }
00225
00226
00227 virtual bool hasColorPoints() const { return true; }
00228
00229
00230
00231
00232 virtual void getAs3DObject ( mrpt::opengl::CSetOfObjectsPtr &outObj ) const;
00233
00234
00235
00236 bool colourFromObservation( const CObservationImage &obs, const CPose3D &robotPose );
00237
00238
00239
00240
00241
00242
00243 enum TColouringMethod
00244 {
00245 cmFromHeightRelativeToSensor = 0,
00246 cmFromHeightRelativeToSensorJet = 0,
00247 cmFromHeightRelativeToSensorGray = 1,
00248 cmFromIntensityImage = 2
00249 };
00250
00251
00252 struct MAPS_IMPEXP TColourOptions : public utils::CLoadableOptions
00253 {
00254
00255 TColourOptions( );
00256 virtual ~TColourOptions() {}
00257
00258
00259 void loadFromConfigFile(
00260 const mrpt::utils::CConfigFileBase &source,
00261 const std::string §ion);
00262
00263
00264
00265 void dumpToTextStream(CStream &out) const;
00266
00267 TColouringMethod scheme;
00268 float z_min,z_max;
00269 float d_max;
00270 };
00271
00272 TColourOptions colorScheme;
00273
00274 void resetPointsMinDist( float defValue = 2000.0f );
00275
00276
00277
00278
00279
00280 virtual bool savePCDFile(const std::string &filename, bool save_as_binary) const;
00281
00282
00283
00284
00285 protected:
00286
00287 std::vector<float> m_color_R,m_color_G,m_color_B;
00288
00289
00290
00291
00292
00293
00294 virtual void internal_clear();
00295
00296
00297
00298
00299
00300
00301 virtual void PLY_import_set_vertex(const size_t idx, const mrpt::math::TPoint3Df &pt, const mrpt::utils::TColorf *pt_color = NULL);
00302
00303
00304 virtual void PLY_import_set_vertex_count(const size_t N);
00305
00306
00307
00308
00309
00310
00311
00312 virtual void PLY_export_get_vertex(
00313 const size_t idx,
00314 mrpt::math::TPoint3Df &pt,
00315 bool &pt_has_color,
00316 mrpt::utils::TColorf &pt_color) const;
00317
00318
00319 };
00320
00321 }
00322
00323 #include <mrpt/utils/adapters.h>
00324 namespace utils
00325 {
00326
00327 template <>
00328 class PointCloudAdapter<mrpt::slam::CColouredPointsMap>
00329 {
00330 private:
00331 mrpt::slam::CColouredPointsMap &m_obj;
00332 public:
00333 typedef float coords_t;
00334 static const int HAS_RGB = 1;
00335 static const int HAS_RGBf = 1;
00336 static const int HAS_RGBu8 = 0;
00337
00338
00339 inline PointCloudAdapter(const mrpt::slam::CColouredPointsMap &obj) : m_obj(*const_cast<mrpt::slam::CColouredPointsMap*>(&obj)) { }
00340
00341 inline size_t size() const { return m_obj.size(); }
00342
00343 inline void resize(const size_t N) { m_obj.resize(N); }
00344
00345
00346 template <typename T>
00347 inline void getPointXYZ(const size_t idx, T &x,T &y, T &z) const {
00348 m_obj.getPointFast(idx,x,y,z);
00349 }
00350
00351 inline void setPointXYZ(const size_t idx, const coords_t x,const coords_t y, const coords_t z) {
00352 m_obj.setPointFast(idx,x,y,z);
00353 }
00354
00355
00356 template <typename T>
00357 inline void getPointXYZ_RGBf(const size_t idx, T &x,T &y, T &z, float &r,float &g,float &b) const {
00358 m_obj.getPoint(idx,x,y,z,r,g,b);
00359 }
00360
00361 inline void setPointXYZ_RGBf(const size_t idx, const coords_t x,const coords_t y, const coords_t z, const float r,const float g,const float b) {
00362 m_obj.setPoint(idx,x,y,z,r,g,b);
00363 }
00364
00365
00366 template <typename T>
00367 inline void getPointXYZ_RGBu8(const size_t idx, T &x,T &y, T &z, uint8_t &r,uint8_t &g,uint8_t &b) const {
00368 float Rf,Gf,Bf;
00369 m_obj.getPoint(idx,x,y,z,Rf,Gf,Bf);
00370 r=Rf*255; g=Gf*255; b=Bf*255;
00371 }
00372
00373 inline void setPointXYZ_RGBu8(const size_t idx, const coords_t x,const coords_t y, const coords_t z, const uint8_t r,const uint8_t g,const uint8_t b) {
00374 m_obj.setPoint(idx,x,y,z,r/255.f,g/255.f,b/255.f);
00375 }
00376
00377
00378 inline void getPointRGBf(const size_t idx, float &r,float &g,float &b) const { m_obj.getPointColor_fast(idx,r,g,b); }
00379
00380 inline void setPointRGBf(const size_t idx, const float r,const float g,const float b) { m_obj.setPointColor_fast(idx,r,g,b); }
00381
00382
00383 inline void getPointRGBu8(const size_t idx, uint8_t &r,uint8_t &g,uint8_t &b) const {
00384 float R,G,B;
00385 m_obj.getPointColor_fast(idx,R,G,B);
00386 r=R*255; g=G*255; b=B*255;
00387 }
00388
00389 inline void setPointRGBu8(const size_t idx,const uint8_t r,const uint8_t g,const uint8_t b) {
00390 m_obj.setPointColor_fast(idx,r/255.f,g/255.f,b/255.f);
00391 }
00392
00393 };
00394
00395 }
00396
00397 }
00398
00399 #endif