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



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