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