Main MRPT website > C++ reference for MRPT 1.5.6
CSetOfTriangles.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 #ifndef opengl_CSetOfTriangles_H
10 #define opengl_CSetOfTriangles_H
11 
13 #include <mrpt/math/geometry.h>
14 
15 namespace mrpt
16 {
17  namespace opengl
18  {
19 
20 
21  // This must be added to any CSerializable derived class:
22  DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CSetOfTriangles, CRenderizableDisplayList, OPENGL_IMPEXP )
23 
24  /** A set of colored triangles.
25  * This class can be used to draw any solid, arbitrarily complex object (without textures).
26  * \sa opengl::COpenGLScene, CSetOfTexturedTriangles
27  * \ingroup mrpt_opengl_grp
28  */
30  {
32  public:
33  /**
34  * Triangle definition. Each vertex has three spatial coordinates and four color values.
35  */
37  {
38  inline TTriangle() {
39  for (size_t i = 0; i<3; i++) {
40  r[i] = g[i] = b[i] = a[i] = 1.0f;
41  }
42  }
44  ASSERT_(p.size()==3)
45  for (size_t i=0;i<3;i++) {
46  x[i]=p[i].x; y[i]=p[i].y; z[i]=p[i].z; r[i]=g[i]=b[i]=a[i]=1.0f;
47  }
48  }
49  float x[3],y[3],z[3];
50  float r[3],g[3],b[3],a[3];
51  };
52  /**
53  * Const iterator type.
54  */
56  /**
57  * Const reverse iterator type.
58  */
59  typedef std::vector<TTriangle>::const_reverse_iterator const_reverse_iterator;
60  protected:
61  /**
62  * List of triangles.
63  * \sa TTriangle
64  */
65  std::vector<TTriangle> m_triangles;
66  /**
67  * Transparency enabling.
68  */
70  /**
71  * Mutable variable used to check whether polygons need to be recalculated.
72  */
73  mutable bool polygonsUpToDate;
74  /**
75  * Polygon cache.
76  */
77  mutable std::vector<mrpt::math::TPolygonWithPlane> tmpPolygons;
78  public:
79  /**
80  * Polygon cache updating.
81  */
82  void updatePolygons() const;
83  /**
84  * Clear this object.
85  */
86  inline void clearTriangles() { m_triangles.clear();polygonsUpToDate=false; CRenderizableDisplayList::notifyChange(); }
87  /**
88  * Get triangle count.
89  */
90  inline size_t getTrianglesCount() const { return m_triangles.size(); }
91  /**
92  * Gets the triangle in a given position.
93  */
94  inline void getTriangle(size_t idx, TTriangle &t) const { ASSERT_(idx<m_triangles.size()); t=m_triangles[idx]; }
95  /**
96  * Inserts a triangle into the set.
97  */
98  inline void insertTriangle( const TTriangle &t ) { m_triangles.push_back(t);polygonsUpToDate=false; CRenderizableDisplayList::notifyChange(); }
99  /**
100  * Inserts a set of triangles, bounded by iterators, into this set.
101  * \sa insertTriangle
102  */
103  template<class InputIterator> inline void insertTriangles(const InputIterator &begin,const InputIterator &end) {
104  m_triangles.insert(m_triangles.end(),begin,end);
105  polygonsUpToDate=false;
107  }
108  /**
109  * Inserts an existing CSetOfTriangles into this one.
110  */
111  void insertTriangles(const CSetOfTrianglesPtr &p);
112  /**
113  * Reserves memory for certain number of triangles, avoiding multiple memory allocation calls.
114  */
115  inline void reserve(size_t t) {
116  m_triangles.reserve(t);
118  }
119 
120  /** Enables or disables transparency. */
121  inline void enableTransparency( bool v ) { m_enableTransparency = v; CRenderizableDisplayList::notifyChange(); }
122 
123  CRenderizable& setColor_u8(const mrpt::utils::TColor &c) MRPT_OVERRIDE;
124  CRenderizable& setColorR_u8(const uint8_t r) MRPT_OVERRIDE;
125  CRenderizable& setColorG_u8(const uint8_t g) MRPT_OVERRIDE;
126  CRenderizable& setColorB_u8(const uint8_t b) MRPT_OVERRIDE;
127  CRenderizable& setColorA_u8(const uint8_t a) MRPT_OVERRIDE;
128 
129  /** Render
130  */
131  void render_dl() const MRPT_OVERRIDE;
132 
133  /** Ray tracing
134  */
135  bool traceRay(const mrpt::poses::CPose3D &o,double &dist) const MRPT_OVERRIDE;
136 
137  /**
138  * Gets the polygon cache.
139  * \sa insertTriangles
140  */
141  void getPolygons(std::vector<mrpt::math::TPolygon3D> &polys) const;
142 
143  /**
144  * Inserts a set of triangles, given in a container of either TTriangle's or TPolygon3D
145  * \sa insertTriangle
146  */
147  template<class CONTAINER>
148  inline void insertTriangles(const CONTAINER &c) {
149  this->insertTriangles(c.begin(),c.end());
151  }
152 
153  /**
154  * Gets the beginning iterator to this object.
155  */
156  inline const_iterator begin() const {
157  return m_triangles.begin();
158  }
159  /**
160  * Gets the ending iterator to this object.
161  */
162  inline const_iterator end() const {
163  return m_triangles.end();
164  }
165  /**
166  * Gets the reverse beginning iterator to this object, which points to the last triangle.
167  */
168  inline const_reverse_iterator rbegin() const {
169  return m_triangles.rbegin();
170  }
171  /**
172  * Gets the reverse ending iterator to this object, which points to the beginning of the actual set.
173  */
174  inline const_reverse_iterator rend() const {
175  return m_triangles.rend();
176  }
177 
178  /** Evaluates the bounding box of this object (including possible children) in the coordinate frame of the object parent. */
179  void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const MRPT_OVERRIDE;
180 
181  private:
182  /** Constructor
183  */
184  CSetOfTriangles( bool enableTransparency = false ) :
185  m_triangles(),
186  m_enableTransparency(enableTransparency),
187  polygonsUpToDate(false)
188  {
189  }
190 
191  /** Private, virtual destructor: only can be deleted from smart pointers */
192  virtual ~CSetOfTriangles() { }
193  };
194  DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE( CSetOfTriangles, CRenderizableDisplayList, OPENGL_IMPEXP )
195  /** Inserts a set of triangles into the list; note that this method allows to pass another CSetOfTriangles as argument. Allows call chaining.
196  * \sa mrpt::opengl::CSetOfTriangles::insertTriangle
197  */
198  template<class T> inline CSetOfTrianglesPtr &operator<<(CSetOfTrianglesPtr &s,const T &t) {
199  s->insertTriangles(t.begin(),t.end());
200  return s;
201  }
202  /** Inserts a triangle into the list. Allows call chaining.
203  * \sa mrpt::opengl::CSetOfTriangles::insertTriangle
204  */
205  template<> inline CSetOfTrianglesPtr &operator<<(CSetOfTrianglesPtr &s,const CSetOfTriangles::TTriangle &t) {
206  s->insertTriangle(t);
207  return s;
208  }
209 
210  } // end namespace
211 
212 } // End of namespace
213 
214 
215 #endif
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:5406
const GLdouble * v
Definition: glew.h:1296
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1166
const_reverse_iterator rbegin() const
Gets the reverse beginning iterator to this object, which points to the last triangle.
OPENGL_IMPEXP mrpt::utils::CStream & operator<<(mrpt::utils::CStream &out, const mrpt::opengl::CLight &o)
Definition: CLight.cpp:132
GLboolean GLboolean g
Definition: glew.h:5406
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
bool BASE_IMPEXP traceRay(const std::vector< TPolygonWithPlane > &vec, const mrpt::poses::CPose3D &pose, double &dist)
Fast ray tracing method using polygons' properties.
Definition: geometry.cpp:1996
const GLfloat * c
Definition: glew.h:10088
GLdouble GLdouble t
Definition: glew.h:1303
The base class of 3D objects that can be directly rendered through OpenGL.
Definition: CRenderizable.h:44
EIGEN_STRONG_INLINE iterator begin()
Definition: eigen_plugins.h:26
std::vector< mrpt::math::TPolygonWithPlane > tmpPolygons
Polygon cache.
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
const Scalar * const_iterator
Definition: eigen_plugins.h:24
TTriangle(const mrpt::math::TPolygon3D &p)
unsigned char uint8_t
Definition: rptypes.h:43
const_iterator begin() const
Gets the beginning iterator to this object.
A renderizable object suitable for rendering with OpenGL's display lists.
GLdouble s
Definition: glew.h:1295
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
GLuint GLuint end
Definition: glew.h:1167
std::vector< TTriangle >::const_iterator const_iterator
Const iterator type.
void insertTriangle(const TTriangle &t)
Inserts a triangle into the set.
const_iterator end() const
Gets the ending iterator to this object.
GLint GLint GLint GLint GLint x
Definition: glew.h:1166
A RGB color - 8bit.
Definition: TColor.h:26
void getTriangle(size_t idx, TTriangle &t) const
Gets the triangle in a given position.
class BASE_IMPEXP TPolygon3D
CSetOfTriangles(bool enableTransparency=false)
Constructor.
std::vector< TTriangle > m_triangles
List of triangles.
GLfloat GLfloat p
Definition: glew.h:10113
void enableTransparency(bool v)
Enables or disables transparency.
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
GLdouble GLdouble z
Definition: glew.h:1464
GLdouble GLdouble GLdouble r
Definition: glew.h:1311
#define ASSERT_(f)
void reserve(size_t t)
Reserves memory for certain number of triangles, avoiding multiple memory allocation calls...
std::vector< TTriangle >::const_reverse_iterator const_reverse_iterator
Const reverse iterator type.
virtual ~CSetOfTriangles()
Private, virtual destructor: only can be deleted from smart pointers.
A set of colored triangles.
void clearTriangles()
Clear this object.
GLdouble GLdouble GLdouble b
Definition: glew.h:5092
Lightweight 3D point.
const_reverse_iterator rend() const
Gets the reverse ending iterator to this object, which points to the beginning of the actual set...
size_t getTrianglesCount() const
Get triangle count.
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
bool polygonsUpToDate
Mutable variable used to check whether polygons need to be recalculated.
bool m_enableTransparency
Transparency enabling.
void insertTriangles(const InputIterator &begin, const InputIterator &end)
Inserts a set of triangles, bounded by iterators, into this set.
3D polygon, inheriting from std::vector<TPoint3D>



Page generated by Doxygen 1.8.6 for MRPT 1.5.6 Git: 4c65e84 Tue Apr 24 08:18:17 2018 +0200 at mar abr 24 08:26:17 CEST 2018