Main MRPT website > C++ reference
MRPT logo
CSetOfTexturedTriangles.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_CSetOfTexturedTriangles_H
00029 #define opengl_CSetOfTexturedTriangles_H
00030 
00031 #include <mrpt/opengl/CTexturedObject.h>
00032 
00033 namespace mrpt
00034 {
00035         namespace utils { class CStream; }
00036 
00037         namespace opengl
00038         {
00039                 using mrpt::utils::CStream;
00040 
00041                 class OPENGL_IMPEXP CSetOfTexturedTriangles;
00042 
00043                 // This must be added to any CSerializable derived class:
00044                 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CSetOfTexturedTriangles, CTexturedObject, OPENGL_IMPEXP )
00045 
00046                 /** A set of textured triangles.
00047                   *  This class can be used to draw any solid, arbitrarily complex object with textures.
00048                   *  \sa opengl::COpenGLScene
00049                   * \ingroup mrpt_opengl_grp
00050                   */
00051                 class OPENGL_IMPEXP CSetOfTexturedTriangles : public CTexturedObject
00052                 {
00053                         DEFINE_SERIALIZABLE( CSetOfTexturedTriangles )
00054 
00055                 public:
00056                         /** Triangle vertex. This structure encapsulates the vertex coordinates and the image pixels.
00057                           */
00058                         struct OPENGL_IMPEXP TVertex
00059                         {
00060                                 /** Default constructor. */
00061                                 TVertex( ) :
00062                                         m_x(0.0), m_y(0.0), m_z(0.0), m_u(0), m_v(0) { }
00063                                 /** Constructor. */
00064                                 TVertex(float x, float y, float z, uint32_t u, uint32_t v) :
00065                                         m_x(x), m_y(y), m_z(z), m_u(u), m_v(v) { }
00066                                 /** 3D vertex coordinates.  */
00067                                 float                   m_x, m_y, m_z;
00068                                 /** 2D texture coordinates. Notice that the texture coordinates are 2D pixels!!! */
00069                                 uint32_t        m_u, m_v;
00070 
00071                                 void writeToStream(CStream &out) const { out << m_x << m_y << m_z  << m_u << m_v; }
00072                                 void readFromStream(CStream &in) { in >> m_x >> m_y >> m_z >> m_u >> m_v; }
00073                         };
00074 
00075                         /** Triangle. This structure encapsulates the triangle vertices.
00076                           */
00077                         struct OPENGL_IMPEXP TTriangle
00078                         {
00079                         /** Default constructor.  */
00080                                 TTriangle( ) :
00081                                         m_v1(), m_v2(), m_v3() { }
00082                         /** Constructor. */
00083                                 TTriangle(TVertex v1, TVertex v2, TVertex v3) :
00084                                         m_v1(v1), m_v2(v2), m_v3(v3) { }
00085                         /** Vertices.  */
00086                                 TVertex m_v1, m_v2, m_v3;
00087 
00088                                 void writeToStream(CStream &out) const {  m_v1.writeToStream(out); m_v2.writeToStream(out); m_v3.writeToStream(out); }
00089                                 void readFromStream(CStream &in) { m_v1.readFromStream(in); m_v2.readFromStream(in);  m_v3.readFromStream(in); }
00090                         };
00091 
00092                 protected:
00093                         /** Triangle array. */
00094                         std::vector<TTriangle>  m_triangles;
00095 
00096                         /** Render */
00097                         void  render_texturedobj( ) const;
00098 
00099                 public:
00100                         void clearTriangles( ) { m_triangles.clear(); CRenderizableDisplayList::notifyChange(); }
00101                         size_t getTrianglesCount( ) const { return m_triangles.size(); }
00102                         const TTriangle & getTriangle( size_t idx) const { ASSERT_(idx<m_triangles.size()); return m_triangles[idx];  }
00103                         void getTriangle( size_t idx, TTriangle &t ) const { ASSERT_(idx<m_triangles.size()); t = m_triangles[idx]; CRenderizableDisplayList::notifyChange(); }
00104                         void insertTriangle( const TTriangle &t ) { m_triangles.push_back(t); CRenderizableDisplayList::notifyChange(); }
00105 
00106 
00107                         /** Ray Trace
00108                           */
00109                         virtual bool traceRay( const mrpt::poses::CPose3D &o,double &dist ) const;
00110 
00111                 private:
00112                         /** Constructor
00113                           */
00114                         CSetOfTexturedTriangles( ) : m_triangles()
00115                         { }
00116 
00117                         /** Private, virtual destructor: only can be deleted from smart pointers */
00118                         virtual ~CSetOfTexturedTriangles();
00119                 };
00120 
00121         } // end namespace
00122 
00123 } // End of namespace
00124 
00125 #endif



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