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
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 class OPENGL_IMPEXP CPointCloudColoured :
00063 public CRenderizable,
00064 public COctreePointRenderer<CPointCloudColoured>
00065 {
00066 DEFINE_SERIALIZABLE( CPointCloudColoured )
00067
00068 public:
00069 struct TPointColour
00070 {
00071 inline TPointColour() { }
00072 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) { }
00073 float x,y,z,R,G,B;
00074 };
00075
00076 private:
00077 typedef std::vector<TPointColour> TListPointColour;
00078 TListPointColour m_points;
00079
00080 typedef TListPointColour::iterator iterator;
00081 typedef TListPointColour::const_iterator const_iterator;
00082 inline iterator begin() { return m_points.begin(); }
00083 inline const_iterator begin() const { return m_points.begin(); }
00084 inline iterator end() { return m_points.end(); }
00085 inline const_iterator end() const { return m_points.end(); }
00086
00087
00088 float m_pointSize;
00089 bool m_pointSmooth;
00090 mutable volatile size_t m_last_rendered_count, m_last_rendered_count_ongoing;
00091
00092
00093
00094 CPointCloudColoured( ) :
00095 m_points(),
00096 m_pointSize(1),
00097 m_pointSmooth(false),
00098 m_last_rendered_count(0),
00099 m_last_rendered_count_ongoing(0)
00100 {
00101 }
00102
00103 virtual ~CPointCloudColoured() { }
00104
00105 void markAllPointsAsNew();
00106
00107 public:
00108
00109
00110
00111
00112
00113 void push_back(float x,float y,float z, float R, float G, float B);
00114
00115
00116 inline void resize(size_t N) { m_points.resize(N); }
00117
00118
00119 inline void reserve(size_t N) { m_points.reserve(N); }
00120
00121
00122 inline const TPointColour &operator [](size_t i) const {
00123 #ifdef _DEBUG
00124 ASSERT_BELOW_(i,size())
00125 #endif
00126 return m_points[i];
00127 }
00128
00129
00130 inline const TPointColour &getPoint(size_t i) const {
00131 #ifdef _DEBUG
00132 ASSERT_BELOW_(i,size())
00133 #endif
00134 return m_points[i];
00135 }
00136
00137
00138 inline mrpt::math::TPoint3Df getPointf(size_t i) const {
00139 #ifdef _DEBUG
00140 ASSERT_BELOW_(i,size())
00141 #endif
00142 return mrpt::math::TPoint3Df(m_points[i].x,m_points[i].y,m_points[i].z);
00143 }
00144
00145
00146 void setPoint(size_t i, const TPointColour &p );
00147
00148 inline size_t size() const { return m_points.size(); }
00149
00150 inline void clear() { m_points.clear(); markAllPointsAsNew(); }
00151
00152
00153
00154
00155
00156
00157 template <class POINTSMAP>
00158 void loadFromPointsMap( const POINTSMAP *m)
00159 {
00160 if (m->hasColorPoints())
00161 {
00162 size_t N = m->size();
00163 m_points.resize(N);
00164 for (size_t i=0;i<N;i++)
00165 {
00166 m->getPoint(i,
00167 m_points[i].x,
00168 m_points[i].y,
00169 m_points[i].z,
00170 m_points[i].R,
00171 m_points[i].G,
00172 m_points[i].B );
00173 }
00174 }
00175 else
00176 {
00177
00178 vector_float xs,ys,zs;
00179 m->getAllPoints(xs,ys,zs);
00180
00181 size_t N = xs.size();
00182 m_points.resize(N);
00183 for (size_t i=0;i<N;i++)
00184 {
00185 m_points[i].x = xs[i];
00186 m_points[i].y = ys[i];
00187 m_points[i].z = zs[i];
00188 m_points[i].R = m_color_R;
00189 m_points[i].G = m_color_G;
00190 m_points[i].B = m_color_B;
00191 }
00192 }
00193 markAllPointsAsNew();
00194 }
00195
00196
00197 size_t getActuallyRendered() const { return m_last_rendered_count; }
00198
00199
00200
00201
00202
00203
00204
00205 inline void setPointSize(float pointSize) { m_pointSize = pointSize; }
00206 inline float getPointSize() const { return m_pointSize; }
00207
00208 inline void enablePointSmooth(bool enable=true) { m_pointSmooth=enable; }
00209 inline void disablePointSmooth() { m_pointSmooth=false; }
00210 inline bool isPointSmoothEnabled() const { return m_pointSmooth; }
00211
00212
00213
00214
00215
00216 void render() const;
00217
00218
00219 void render_subset(const bool all, const std::vector<size_t>& idxs, const float render_area_sqpixels ) const;
00220
00221 };
00222
00223 OPENGL_IMPEXP mrpt::utils::CStream& operator>>(mrpt::utils::CStream& in, CPointCloudColoured::TPointColour &o);
00224 OPENGL_IMPEXP mrpt::utils::CStream& operator<<(mrpt::utils::CStream& out, const CPointCloudColoured::TPointColour &o);
00225
00226 }
00227
00228 namespace utils
00229 {
00230 using namespace mrpt::opengl;
00231
00232
00233 MRPT_DECLARE_TTYPENAME(CPointCloudColoured::TPointColour)
00234 }
00235
00236 }
00237
00238
00239 #endif