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