Main MRPT website > C++ reference
MRPT logo

COpenGLStandardObject.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 #ifndef opengl_COpenGLStandardObject_H
00029 #define opengl_COpenGLStandardObject_H
00030 
00031 #include <mrpt/opengl/CRenderizableDisplayList.h>
00032 #include <mrpt/math/geometry.h>
00033 
00034 #include <mrpt/utils/stl_extensions.h>
00035 
00036 namespace mrpt  {
00037         namespace opengl        {
00038                 typedef uint32_t _GLENUM;
00039                 using namespace mrpt::utils;
00040                 using namespace mrpt::math;
00041                 class OPENGL_IMPEXP COpenGLStandardObject;
00042                 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE(COpenGLStandardObject,CRenderizableDisplayList, OPENGL_IMPEXP)
00043                 /**
00044                   * Objects of this class represent a generic openGL object without specific geometric properties.
00045                   */
00046                 class OPENGL_IMPEXP COpenGLStandardObject:public CRenderizableDisplayList       {
00047                         DEFINE_SERIALIZABLE(COpenGLStandardObject)
00048                 protected:
00049                         /**
00050                           * OpenGL identifier of the object type.
00051                           */
00052                         _GLENUM type;
00053                         /**
00054                           * Set of points in which consists this object.
00055                           */
00056                         std::vector<TPoint3D> vertices;
00057                         /**
00058                           * Granularity of the openGL elements. 3 for GL_TRIANGLES, 4 for GL_QUADS, and so on. Setting it to 0 will generate a single openGL object.
00059                           */
00060                         uint32_t chunkSize;
00061                         /**
00062                           * Set of openGL properties enabled in the rendering of this object.
00063                           */
00064                         std::vector<_GLENUM> enabled;
00065                         float normal[3];
00066                 public:
00067                         /**
00068                           * Render.
00069                           * \sa mrpt::opengl::CRenderizable
00070                           */
00071                         virtual void render_dl() const;
00072                         /**
00073                           * Ray Tracing. Will always return false, since objects of this class are not intended to have geometric properties.
00074                           * \sa mrpt::opengl::CRenderizable
00075                           */
00076                         virtual bool traceRay(const mrpt::poses::CPose3D &o,float &dist) const;
00077                         /**
00078                           * Creation of object from type, vertices, chunk size and a list of enabled openGL flags.
00079                           * \throw std::logic_error if the number of vertices is not an exact multiple of the chunk size.
00080                           */
00081                         static COpenGLStandardObjectPtr Create(_GLENUM t,const std::vector<TPoint3D> &v,uint32_t cs=0,const std::vector<_GLENUM> &en=std::vector<_GLENUM>())    {
00082                                 if (cs!=0&&v.size()%cs!=0) throw std::logic_error("Vertices vector does not match chunk size");
00083                                 return COpenGLStandardObjectPtr(new COpenGLStandardObject(t,v,cs,en));
00084                         }
00085                         /**
00086                           * Enable some openGL flag.
00087                           */
00088                         inline void enable(_GLENUM flag)        {
00089                                 if (find(enabled.begin(),enabled.end(),flag)==enabled.end()) enabled.push_back(flag);
00090                                 CRenderizableDisplayList::notifyChange();
00091                         }
00092                         /**
00093                           * Disable some openGL flag.
00094                           */
00095                         inline void disable(_GLENUM flag)       {
00096                                 std::remove(enabled.begin(),enabled.end(),flag);
00097                                 CRenderizableDisplayList::notifyChange();
00098                         }
00099                         /**
00100                           * Check whether an openGL will be enabled during the rendering of this object.
00101                           */
00102                         inline bool isEnabled(_GLENUM flag) const       {
00103                                 return find(enabled.begin(),enabled.end(),flag)!=enabled.end();
00104                         }
00105                         /**
00106                           * Get a list of all currently enabled openGL flags.
00107                           */
00108                         inline void getEnabledFlags(std::vector<_GLENUM> &v) const      {
00109                                 v=enabled;
00110                         }
00111                         /**
00112                           * Set the list of all openGL flags.
00113                           */
00114                         inline void setFlags(const std::vector<_GLENUM> &v)     {
00115                                 enabled=v;
00116                                 CRenderizableDisplayList::notifyChange();
00117                         }
00118                         /**
00119                           * Set the normal vector to this object.
00120                           */
00121                         inline void setNormal(const float (&n)[3])      {
00122                                 for (size_t i=0;i<3;i++) normal[i]=n[i];
00123                                 CRenderizableDisplayList::notifyChange();
00124                         }
00125                         /**
00126                           * Gets the normal vector to this object.
00127                           */
00128                         inline void getNormal(float (&n)[3]) const      {
00129                                 for (size_t i=0;i<3;i++) n[i]=normal[i];
00130                         }
00131                 private:
00132                         /**
00133                           * Constructor with all the information.
00134                           */
00135                         COpenGLStandardObject(_GLENUM t,const std::vector<TPoint3D> &v,uint32_t cs,const vector<_GLENUM> &en):type(t),vertices(v),chunkSize(cs),enabled(en)     {
00136                                 for (size_t i=0;i<3;i++) normal[i]=0.0;
00137                         }
00138                         /**
00139                           * Baic empty constructor, initializes to default.
00140                           */
00141                         COpenGLStandardObject():type(0),vertices(std::vector<TPoint3D>(0)),chunkSize(0),enabled(std::vector<_GLENUM>()) {
00142                                 for (size_t i=0;i<3;i++) normal[i]=0.0;
00143                         }
00144                         /**
00145                           * Destructor.
00146                           */
00147                         virtual ~COpenGLStandardObject()        {}
00148                 };
00149         } // end namespace
00150 } // End of namespace
00151 #endif



Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN:exported at Tue Jan 25 21:56:31 UTC 2011