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_CPointCloud_H
00030 #define opengl_CPointCloud_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 CPointCloud;
00042
00043
00044 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CPointCloud, CRenderizable, OPENGL_IMPEXP )
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 class OPENGL_IMPEXP CPointCloud :
00066 public CRenderizable,
00067 public COctreePointRenderer<CPointCloud>,
00068 public mrpt::utils::PLY_Importer,
00069 public mrpt::utils::PLY_Exporter
00070 {
00071 DEFINE_SERIALIZABLE( CPointCloud )
00072 protected:
00073 enum Axis { None=0, Z, Y, X} m_colorFromDepth;
00074 std::vector<float> m_xs,m_ys,m_zs;
00075 float m_pointSize;
00076 bool m_pointSmooth;
00077
00078 mutable volatile size_t m_last_rendered_count, m_last_rendered_count_ongoing;
00079
00080 void markAllPointsAsNew();
00081
00082 protected:
00083
00084
00085
00086 virtual void PLY_import_set_vertex_count(const size_t N);
00087
00088
00089 virtual void PLY_import_set_face_count(const size_t N) { }
00090
00091
00092
00093
00094 virtual void PLY_import_set_vertex(const size_t idx, const mrpt::math::TPoint3Df &pt, const mrpt::utils::TColorf *pt_color = NULL);
00095
00096
00097
00098
00099
00100
00101 virtual size_t PLY_export_get_vertex_count() const;
00102
00103
00104 virtual size_t PLY_export_get_face_count() const { return 0; }
00105
00106
00107
00108
00109 virtual void PLY_export_get_vertex(
00110 const size_t idx,
00111 mrpt::math::TPoint3Df &pt,
00112 bool &pt_has_color,
00113 mrpt::utils::TColorf &pt_color) const;
00114
00115
00116
00117
00118 public:
00119
00120
00121
00122
00123 inline size_t size() const { return m_xs.size(); }
00124
00125
00126 inline void resize(size_t N) { m_xs.resize(N); m_ys.resize(N); m_zs.resize(N); m_minmax_valid = false; markAllPointsAsNew(); }
00127
00128
00129 inline void reserve(size_t N) { m_xs.reserve(N); m_ys.reserve(N); m_zs.reserve(N); }
00130
00131
00132 void setAllPoints(const std::vector<float> &x, const std::vector<float> &y, const std::vector<float> &z)
00133 {
00134 m_xs = x;
00135 m_ys = y;
00136 m_zs = z;
00137 m_minmax_valid = false;
00138 markAllPointsAsNew();
00139 }
00140
00141
00142 void setAllPointsFast(std::vector<float> &x, std::vector<float> &y, std::vector<float> &z)
00143 {
00144 this->clear();
00145 m_xs.swap(x);
00146 m_ys.swap(y);
00147 m_zs.swap(z);
00148 m_minmax_valid = false;
00149 markAllPointsAsNew();
00150 }
00151
00152 inline const std::vector<float> & getArrayX() const {return m_xs;}
00153 inline const std::vector<float> & getArrayY() const {return m_ys;}
00154 inline const std::vector<float> & getArrayZ() const {return m_zs;}
00155
00156 void clear();
00157
00158
00159 void insertPoint( float x,float y, float z );
00160
00161
00162 inline mrpt::math::TPoint3D operator [](size_t i) const {
00163 #ifdef _DEBUG
00164 ASSERT_BELOW_(i,size())
00165 #endif
00166 return mrpt::math::TPoint3D(m_xs[i],m_ys[i],m_zs[i]);
00167 }
00168
00169
00170 inline mrpt::math::TPoint3D getPoint(size_t i) const {
00171 #ifdef _DEBUG
00172 ASSERT_BELOW_(i,size())
00173 #endif
00174 return mrpt::math::TPoint3D(m_xs[i],m_ys[i],m_zs[i]);
00175 }
00176
00177
00178 inline mrpt::math::TPoint3Df getPointf(size_t i) const {
00179 #ifdef _DEBUG
00180 ASSERT_BELOW_(i,size())
00181 #endif
00182 return mrpt::math::TPoint3Df(m_xs[i],m_ys[i],m_zs[i]);
00183 }
00184
00185
00186 void setPoint(size_t i, const float x,const float y, const float z);
00187
00188
00189 inline void setPoint_fast(size_t i, const float x,const float y, const float z)
00190 {
00191 m_xs[i] = x;
00192 m_ys[i] = y;
00193 m_zs[i] = z;
00194 m_minmax_valid = false;
00195 markAllPointsAsNew();
00196 }
00197
00198
00199
00200 template <class POINTSMAP>
00201 void loadFromPointsMap( const POINTSMAP *themap);
00202
00203
00204
00205
00206 template<class LISTOFPOINTS> void loadFromPointsList( LISTOFPOINTS &pointsList)
00207 {
00208 MRPT_START
00209 const size_t N = pointsList.size();
00210
00211 m_xs.resize(N);
00212 m_ys.resize(N);
00213 m_zs.resize(N);
00214
00215 size_t idx;
00216 typename LISTOFPOINTS::const_iterator it;
00217 for ( idx=0,it=pointsList.begin() ; idx<N ; ++idx,++it)
00218 {
00219 m_xs[idx]=it->x;
00220 m_ys[idx]=it->y;
00221 m_zs[idx]=it->z;
00222 }
00223 markAllPointsAsNew();
00224 MRPT_END
00225 }
00226
00227
00228 size_t getActuallyRendered() const { return m_last_rendered_count; }
00229
00230
00231
00232
00233
00234
00235 inline void enableColorFromX(bool v=true) { m_colorFromDepth = v ? CPointCloud::X : CPointCloud::None; }
00236 inline void enableColorFromY(bool v=true) { m_colorFromDepth = v ? CPointCloud::Y : CPointCloud::None; }
00237 inline void enableColorFromZ(bool v=true) { m_colorFromDepth = v ? CPointCloud::Z : CPointCloud::None; }
00238
00239 inline void setPointSize(float p) { m_pointSize=p; }
00240 inline float getPointSize() const { return m_pointSize; }
00241
00242 inline void enablePointSmooth(bool enable=true) { m_pointSmooth=enable; }
00243 inline void disablePointSmooth() { m_pointSmooth=false; }
00244 inline bool isPointSmoothEnabled() const { return m_pointSmooth; }
00245
00246
00247 void setGradientColors( const mrpt::utils::TColorf &colorMin, const mrpt::utils::TColorf &colorMax );
00248
00249
00250
00251
00252 void render() const;
00253
00254
00255
00256 void render_subset(const bool all, const std::vector<size_t>& idxs, const float render_area_sqpixels ) const;
00257
00258 private:
00259
00260 CPointCloud();
00261
00262
00263 virtual ~CPointCloud() { }
00264
00265 mutable float m_min, m_max,m_max_m_min,m_max_m_min_inv;
00266 mutable mrpt::utils::TColorf m_col_slop,m_col_slop_inv;
00267 mutable bool m_minmax_valid;
00268
00269 mrpt::utils::TColorf m_colorFromDepth_min, m_colorFromDepth_max;
00270
00271 inline void internal_render_one_point(size_t i) const;
00272 };
00273
00274 }
00275
00276
00277 namespace utils
00278 {
00279
00280 template <>
00281 class PointCloudAdapter<mrpt::opengl::CPointCloud> : public detail::PointCloudAdapterHelperNoRGB<mrpt::opengl::CPointCloud,float>
00282 {
00283 private:
00284 mrpt::opengl::CPointCloud &m_obj;
00285 public:
00286 typedef float coords_t;
00287 static const int HAS_RGB = 0;
00288 static const int HAS_RGBf = 0;
00289 static const int HAS_RGBu8 = 0;
00290
00291
00292 inline PointCloudAdapter(const mrpt::opengl::CPointCloud &obj) : m_obj(*const_cast<mrpt::opengl::CPointCloud*>(&obj)) { }
00293
00294 inline size_t size() const { return m_obj.size(); }
00295
00296 inline void resize(const size_t N) { m_obj.resize(N); }
00297
00298
00299 template <typename T>
00300 inline void getPointXYZ(const size_t idx, T &x,T &y, T &z) const {
00301 x=m_obj.getArrayX()[idx];
00302 y=m_obj.getArrayY()[idx];
00303 z=m_obj.getArrayZ()[idx];
00304 }
00305
00306 inline void setPointXYZ(const size_t idx, const coords_t x,const coords_t y, const coords_t z) {
00307 m_obj.setPoint_fast(idx,x,y,z);
00308 }
00309
00310 };
00311 }
00312
00313 namespace opengl
00314 {
00315
00316 template <class POINTSMAP>
00317 void CPointCloud::loadFromPointsMap( const POINTSMAP *themap)
00318 {
00319 mrpt::utils::PointCloudAdapter<CPointCloud> pc_dst(*this);
00320 const mrpt::utils::PointCloudAdapter<POINTSMAP> pc_src(*themap);
00321 const size_t N=pc_src.size();
00322 pc_dst.resize(N);
00323 for (size_t i=0;i<N;i++)
00324 {
00325 float x,y,z;
00326 pc_src.getPointXYZ(i,x,y,z);
00327 pc_dst.setPointXYZ(i,x,y,z);
00328 }
00329 }
00330 }
00331
00332 }
00333
00334
00335 #endif