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



Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011