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