Main MRPT website > C++ reference
MRPT logo
CSetOfTexturedTriangles.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef opengl_CSetOfTexturedTriangles_H
29 #define opengl_CSetOfTexturedTriangles_H
30 
32 
33 namespace mrpt
34 {
35  namespace utils { class CStream; }
36 
37  namespace opengl
38  {
40 
42 
43  // This must be added to any CSerializable derived class:
45 
46  /** A set of textured triangles.
47  * This class can be used to draw any solid, arbitrarily complex object with textures.
48  * \sa opengl::COpenGLScene
49  * \ingroup mrpt_opengl_grp
50  */
52  {
54 
55  public:
56  /** Triangle vertex. This structure encapsulates the vertex coordinates and the image pixels.
57  */
59  {
60  /** Default constructor. */
61  TVertex( ) :
62  m_x(0.0), m_y(0.0), m_z(0.0), m_u(0), m_v(0) { }
63  /** Constructor. */
64  TVertex(float x, float y, float z, uint32_t u, uint32_t v) :
65  m_x(x), m_y(y), m_z(z), m_u(u), m_v(v) { }
66  /** 3D vertex coordinates. */
67  float m_x, m_y, m_z;
68  /** 2D texture coordinates. Notice that the texture coordinates are 2D pixels!!! */
69  uint32_t m_u, m_v;
70 
71  void writeToStream(CStream &out) const { out << m_x << m_y << m_z << m_u << m_v; }
72  void readFromStream(CStream &in) { in >> m_x >> m_y >> m_z >> m_u >> m_v; }
73  };
74 
75  /** Triangle. This structure encapsulates the triangle vertices.
76  */
78  {
79  /** Default constructor. */
80  TTriangle( ) :
81  m_v1(), m_v2(), m_v3() { }
82  /** Constructor. */
84  m_v1(v1), m_v2(v2), m_v3(v3) { }
85  /** Vertices. */
86  TVertex m_v1, m_v2, m_v3;
87 
88  void writeToStream(CStream &out) const { m_v1.writeToStream(out); m_v2.writeToStream(out); m_v3.writeToStream(out); }
89  void readFromStream(CStream &in) { m_v1.readFromStream(in); m_v2.readFromStream(in); m_v3.readFromStream(in); }
90  };
91 
92  protected:
93  /** Triangle array. */
94  std::vector<TTriangle> m_triangles;
95 
96  /** Render */
97  void render_texturedobj( ) const;
98 
99  public:
100  void clearTriangles( ) { m_triangles.clear(); CRenderizableDisplayList::notifyChange(); }
101  size_t getTrianglesCount( ) const { return m_triangles.size(); }
102  const TTriangle & getTriangle( size_t idx) const { ASSERT_(idx<m_triangles.size()); return m_triangles[idx]; }
103  void getTriangle( size_t idx, TTriangle &t ) const { ASSERT_(idx<m_triangles.size()); t = m_triangles[idx]; CRenderizableDisplayList::notifyChange(); }
104  void insertTriangle( const TTriangle &t ) { m_triangles.push_back(t); CRenderizableDisplayList::notifyChange(); }
105 
106 
107  /** Ray Trace
108  */
109  virtual bool traceRay( const mrpt::poses::CPose3D &o,double &dist ) const;
110 
111  private:
112  /** Constructor
113  */
114  CSetOfTexturedTriangles( ) : m_triangles()
115  { }
116 
117  /** Private, virtual destructor: only can be deleted from smart pointers */
118  virtual ~CSetOfTexturedTriangles();
119  };
120 
121  } // end namespace
122 
123 } // End of namespace
124 
125 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013