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
00029 #ifndef opengl_CPointCloudColoured_H
00030 #define opengl_CPointCloudColoured_H
00031
00032 #include <mrpt/opengl/CRenderizable.h>
00033 #include <mrpt/opengl/COctreePointRenderer.h>
00034 #include <mrpt/utils/PLY_import_export.h>
00035 #include <mrpt/utils/adapters.h>
00036
00037 namespace mrpt
00038 {
00039 namespace opengl
00040 {
00041 class OPENGL_IMPEXP CPointCloudColoured;
00042
00043
00044 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CPointCloudColoured, CRenderizable, OPENGL_IMPEXP )
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 class OPENGL_IMPEXP CPointCloudColoured :
00065 public CRenderizable,
00066 public COctreePointRenderer<CPointCloudColoured>,
00067 public mrpt::utils::PLY_Importer,
00068 public mrpt::utils::PLY_Exporter
00069 {
00070 DEFINE_SERIALIZABLE( CPointCloudColoured )
00071
00072 public:
00073 struct TPointColour
00074 {
00075 inline TPointColour() { }
00076 inline TPointColour(float _x,float _y,float _z,float _R,float _G,float _B ) : x(_x),y(_y),z(_z),R(_R),G(_G),B(_B) { }
00077 float x,y,z,R,G,B;
00078 };
00079
00080 private:
00081 typedef std::vector<TPointColour> TListPointColour;
00082 TListPointColour m_points;
00083
00084 typedef TListPointColour::iterator iterator;
00085 typedef TListPointColour::const_iterator const_iterator;
00086 inline iterator begin() { return m_points.begin(); }
00087 inline const_iterator begin() const { return m_points.begin(); }
00088 inline iterator end() { return m_points.end(); }
00089 inline const_iterator end() const { return m_points.end(); }
00090
00091
00092 float m_pointSize;
00093 bool m_pointSmooth;
00094 mutable volatile size_t m_last_rendered_count, m_last_rendered_count_ongoing;
00095
00096
00097
00098 CPointCloudColoured( ) :
00099 m_points(),
00100 m_pointSize(1),
00101 m_pointSmooth(false),
00102 m_last_rendered_count(0),
00103 m_last_rendered_count_ongoing(0)
00104 {
00105 }
00106
00107 virtual ~CPointCloudColoured() { }
00108
00109 void markAllPointsAsNew();
00110
00111 public:
00112
00113
00114
00115
00116
00117 void push_back(float x,float y,float z, float R, float G, float B);
00118
00119
00120 inline void resize(size_t N) { m_points.resize(N); markAllPointsAsNew(); }
00121
00122
00123 inline void reserve(size_t N) { m_points.reserve(N); }
00124
00125
00126 inline const TPointColour &operator [](size_t i) const {
00127 #ifdef _DEBUG
00128 ASSERT_BELOW_(i,size())
00129 #endif
00130 return m_points[i];
00131 }
00132
00133
00134 inline const TPointColour &getPoint(size_t i) const {
00135 #ifdef _DEBUG
00136 ASSERT_BELOW_(i,size())
00137 #endif
00138 return m_points[i];
00139 }
00140
00141
00142 inline mrpt::math::TPoint3Df getPointf(size_t i) const {
00143 #ifdef _DEBUG
00144 ASSERT_BELOW_(i,size())
00145 #endif
00146 return mrpt::math::TPoint3Df(m_points[i].x,m_points[i].y,m_points[i].z);
00147 }
00148
00149
00150 void setPoint(size_t i, const TPointColour &p );
00151
00152
00153 inline void setPoint_fast(const size_t i, const TPointColour &p ) {
00154 m_points[i] = p;
00155 markAllPointsAsNew();
00156 }
00157
00158
00159 inline void setPoint_fast(const size_t i, const float x,const float y, const float z ) {
00160 TPointColour &p = m_points[i];
00161 p.x=x; p.y=y; p.z=z;
00162 markAllPointsAsNew();
00163 }
00164
00165
00166 inline void setPointColor_fast(size_t index,float R, float G, float B)
00167 {
00168 m_points[index].R=R;
00169 m_points[index].G=G;
00170 m_points[index].B=B;
00171 }
00172
00173 inline void getPointColor_fast( size_t index, float &R, float &G, float &B ) const
00174 {
00175 R = m_points[index].R;
00176 G = m_points[index].G;
00177 B = m_points[index].B;
00178 }
00179
00180 inline size_t size() const { return m_points.size(); }
00181
00182 inline void clear() { m_points.clear(); markAllPointsAsNew(); }
00183
00184
00185 template <class POINTSMAP>
00186 void loadFromPointsMap( const POINTSMAP *themap);
00187
00188
00189
00190 size_t getActuallyRendered() const { return m_last_rendered_count; }
00191
00192
00193
00194
00195
00196
00197
00198 inline void setPointSize(float pointSize) { m_pointSize = pointSize; }
00199 inline float getPointSize() const { return m_pointSize; }
00200
00201 inline void enablePointSmooth(bool enable=true) { m_pointSmooth=enable; }
00202 inline void disablePointSmooth() { m_pointSmooth=false; }
00203 inline bool isPointSmoothEnabled() const { return m_pointSmooth; }
00204
00205
00206
00207
00208
00209 void render() const;
00210
00211
00212 void render_subset(const bool all, const std::vector<size_t>& idxs, const float render_area_sqpixels ) const;
00213
00214 protected:
00215
00216
00217
00218 virtual void PLY_import_set_vertex_count(const size_t N);
00219
00220 virtual void PLY_import_set_face_count(const size_t N) { }
00221
00222
00223
00224 virtual void PLY_import_set_vertex(const size_t idx, const mrpt::math::TPoint3Df &pt, const mrpt::utils::TColorf *pt_color = NULL);
00225
00226
00227
00228
00229
00230
00231 virtual size_t PLY_export_get_vertex_count() const;
00232
00233
00234 virtual size_t PLY_export_get_face_count() const { return 0; }
00235
00236
00237
00238
00239 virtual void PLY_export_get_vertex(
00240 const size_t idx,
00241 mrpt::math::TPoint3Df &pt,
00242 bool &pt_has_color,
00243 mrpt::utils::TColorf &pt_color) const;
00244
00245
00246
00247
00248 };
00249
00250 OPENGL_IMPEXP mrpt::utils::CStream& operator>>(mrpt::utils::CStream& in, CPointCloudColoured::TPointColour &o);
00251 OPENGL_IMPEXP mrpt::utils::CStream& operator<<(mrpt::utils::CStream& out, const CPointCloudColoured::TPointColour &o);
00252
00253 }
00254
00255 namespace utils
00256 {
00257 using namespace mrpt::opengl;
00258
00259
00260 MRPT_DECLARE_TTYPENAME(CPointCloudColoured::TPointColour)
00261 }
00262
00263 namespace utils
00264 {
00265
00266 template <>
00267 class PointCloudAdapter<mrpt::opengl::CPointCloudColoured>
00268 {
00269 private:
00270 mrpt::opengl::CPointCloudColoured &m_obj;
00271 public:
00272 typedef float coords_t;
00273 static const int HAS_RGB = 1;
00274 static const int HAS_RGBf = 1;
00275 static const int HAS_RGBu8 = 0;
00276
00277
00278 inline PointCloudAdapter(const mrpt::opengl::CPointCloudColoured &obj) : m_obj(*const_cast<mrpt::opengl::CPointCloudColoured*>(&obj)) { }
00279
00280 inline size_t size() const { return m_obj.size(); }
00281
00282 inline void resize(const size_t N) { m_obj.resize(N); }
00283
00284
00285 template <typename T>
00286 inline void getPointXYZ(const size_t idx, T &x,T &y, T &z) const {
00287 const mrpt::opengl::CPointCloudColoured::TPointColour &pc = m_obj[idx];
00288 x=pc.x;
00289 y=pc.y;
00290 z=pc.z;
00291 }
00292
00293 inline void setPointXYZ(const size_t idx, const coords_t x,const coords_t y, const coords_t z) {
00294 m_obj.setPoint_fast(idx, x,y,z);
00295 }
00296
00297
00298 template <typename T>
00299 inline void getPointXYZ_RGBf(const size_t idx, T &x,T &y, T &z, float &r,float &g,float &b) const {
00300 const mrpt::opengl::CPointCloudColoured::TPointColour &pc = m_obj[idx];
00301 x=pc.x; y=pc.y; z=pc.z;
00302 r=pc.R; g=pc.G; b=pc.B;
00303 }
00304
00305 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) {
00306 m_obj.setPoint_fast(idx, mrpt::opengl::CPointCloudColoured::TPointColour(x,y,z,r,g,b) );
00307 }
00308
00309
00310 template <typename T>
00311 inline void getPointXYZ_RGBu8(const size_t idx, T &x,T &y, T &z, uint8_t &r,uint8_t &g,uint8_t &b) const {
00312 const mrpt::opengl::CPointCloudColoured::TPointColour &pc = m_obj[idx];
00313 x=pc.x; y=pc.y; z=pc.z;
00314 r=pc.R*255; g=pc.G*255; b=pc.B*255;
00315 }
00316
00317 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) {
00318 m_obj.setPoint_fast(idx, mrpt::opengl::CPointCloudColoured::TPointColour(x,y,z,r/255.f,g/255.f,b/255.f) );
00319 }
00320
00321
00322 inline void getPointRGBf(const size_t idx, float &r,float &g,float &b) const { m_obj.getPointColor_fast(idx,r,g,b); }
00323
00324 inline void setPointRGBf(const size_t idx, const float r,const float g,const float b) { m_obj.setPointColor_fast(idx,r,g,b); }
00325
00326
00327 inline void getPointRGBu8(const size_t idx, uint8_t &r,uint8_t &g,uint8_t &b) const {
00328 float R,G,B;
00329 m_obj.getPointColor_fast(idx,R,G,B);
00330 r=R*255; g=G*255; b=B*255;
00331 }
00332
00333 inline void setPointRGBu8(const size_t idx,const uint8_t r,const uint8_t g,const uint8_t b) {
00334 m_obj.setPointColor_fast(idx,r/255.f,g/255.f,b/255.f);
00335 }
00336
00337 };
00338
00339 }
00340
00341 namespace opengl
00342 {
00343
00344 template <class POINTSMAP>
00345 void CPointCloudColoured::loadFromPointsMap( const POINTSMAP *themap)
00346 {
00347 mrpt::utils::PointCloudAdapter<CPointCloudColoured> pc_dst(*this);
00348 const mrpt::utils::PointCloudAdapter<POINTSMAP> pc_src(*themap);
00349 const size_t N=pc_src.size();
00350 pc_dst.resize(N);
00351 for (size_t i=0;i<N;i++)
00352 {
00353 float x,y,z,r,g,b;
00354 pc_src.getPointXYZ_RGBf(i,x,y,z,r,g,b);
00355 pc_dst.setPointXYZ_RGBf(i,x,y,z,r,g,b);
00356 }
00357 }
00358 }
00359
00360 }
00361
00362
00363 #endif