Main MRPT website > C++ reference
MRPT logo

CPointCloudColoured.h

Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                   http://mrpt.sourceforge.net/                            |
00005    |                                                                           |
00006    |   Copyright (C) 2005-2011  University of Malaga                           |
00007    |                                                                           |
00008    |    This software was written by the Machine Perception and Intelligent    |
00009    |      Robotics Lab, University of Malaga (Spain).                          |
00010    |    Contact: Jose-Luis Blanco  <jlblanco@ctima.uma.es>                     |
00011    |                                                                           |
00012    |  This file is part of the MRPT project.                                   |
00013    |                                                                           |
00014    |     MRPT is free software: you can redistribute it and/or modify          |
00015    |     it under the terms of the GNU General Public License as published by  |
00016    |     the Free Software Foundation, either version 3 of the License, or     |
00017    |     (at your option) any later version.                                   |
00018    |                                                                           |
00019    |   MRPT is distributed in the hope that it will be useful,                 |
00020    |     but WITHOUT ANY WARRANTY; without even the implied warranty of        |
00021    |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         |
00022    |     GNU General Public License for more details.                          |
00023    |                                                                           |
00024    |     You should have received a copy of the GNU General Public License     |
00025    |     along with MRPT.  If not, see <http://www.gnu.org/licenses/>.         |
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/stl_extensions.h>
00035 
00036 namespace mrpt
00037 {
00038         namespace opengl
00039         {
00040                 class OPENGL_IMPEXP CPointCloudColoured;
00041 
00042                 // This must be added to any CSerializable derived class:
00043                 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CPointCloudColoured, CRenderizable, OPENGL_IMPEXP )
00044 
00045 
00046                 /** A cloud of points, each one with an individual colour (R,G,B). The alpha component is shared by all the points and is stored in the base member m_color_A.
00047                   *
00048                   *  To load from a points-map, CPointCloudColoured::loadFromPointsMap().
00049                   *
00050                   *   This class uses smart optimizations while rendering to efficiently draw clouds of millions of points,
00051                   *   as described in this page: http://www.mrpt.org/Efficiently_rendering_point_clouds_of_millions_of_points
00052                   *
00053                   *  \sa opengl::COpenGLScene, opengl::CPointCloud
00054                   *
00055                   *  <div align="center">
00056                   *  <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px; border-style: solid;">
00057                   *   <tr> <td> mrpt::opengl::CPointCloudColoured </td> <td> \image html preview_CPointCloudColoured.png </td> </tr>
00058                   *  </table>
00059                   *  </div>
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;      // Float is precission enough for rendering
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; //!< By default is 1.0
00089                         bool                            m_pointSmooth; //!< Default: false
00090                         mutable volatile size_t m_last_rendered_count, m_last_rendered_count_ongoing;
00091 
00092                         /** Constructor
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                         /** Private, virtual destructor: only can be deleted from smart pointers */
00103                         virtual ~CPointCloudColoured() { }
00104 
00105                         void markAllPointsAsNew(); //!< Do needed internal work if all points are new (octree rebuilt,...)
00106 
00107                 public:
00108 
00109                         /** @name Read/Write of the list of points to render
00110                             @{ */
00111 
00112                         /** Inserts a new point into the point cloud. */
00113                         void push_back(float x,float y,float z, float R, float G, float B);
00114 
00115                         /** Set the number of points, with undefined contents */
00116                         inline void resize(size_t N) { m_points.resize(N); }
00117 
00118                         /** Like STL std::vector's reserve */
00119                         inline void reserve(size_t N) { m_points.reserve(N); }
00120 
00121                         /** Read access to each individual point (checks for "i" in the valid range only in Debug). */
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                         /** Read access to each individual point (checks for "i" in the valid range only in Debug). */
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                         /** Read access to each individual point (checks for "i" in the valid range only in Debug). */
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                         /** Write an individual point (checks for "i" in the valid range only in Debug). */
00146                         void setPoint(size_t i, const TPointColour &p );
00147 
00148                         inline size_t size() const { return m_points.size(); } //!< Return the number of points
00149 
00150                         inline void clear() { m_points.clear(); markAllPointsAsNew(); }  //!< Erase all the points
00151 
00152 
00153                         /** Load the points from a points map (passed as a pointer), depending on the type of point map passed: for the case of a mrpt::slam::CColouredPointMap the colours of individual points will be also copied.
00154                           *  The possible classes accepted as arguments are: mrpt::slam::CColouredPointsMap, or in general any mrpt::slam::CPointsMap.
00155                           * \note The method is a template since CPointsMap belongs to a different mrpt library.
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                                         // Default colors:
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                         /** Get the number of elements actually rendered in the last render event. */
00197                         size_t getActuallyRendered() const { return m_last_rendered_count; }
00198 
00199                         /** @} */
00200 
00201 
00202                         /** @name Modify the appearance of the rendered points
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                         /** Render */
00216                         void  render() const;
00217 
00218                         /** Render a subset of points (required by octree renderer) */
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         } // end namespace
00227 
00228         namespace utils
00229         {
00230                 using namespace mrpt::opengl;
00231 
00232                 // Specialization must occur in the same namespace
00233                 MRPT_DECLARE_TTYPENAME(CPointCloudColoured::TPointColour)
00234         }
00235 
00236 } // End of namespace
00237 
00238 
00239 #endif



Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN: at Sat Mar 26 06:16:28 UTC 2011