Main MRPT website > C++ reference for MRPT 1.9.9
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-2018, 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 /** A set of colored triangles.
20  * This class can be used to draw any solid, arbitrarily complex object
21  * (without textures).
22  * \sa opengl::COpenGLScene, CSetOfTexturedTriangles
23  * \ingroup mrpt_opengl_grp
24  */
26 {
28  public:
29  /**
30  * Triangle definition. Each vertex has three spatial coordinates and four
31  * color values.
32  */
33  struct TTriangle
34  {
35  inline TTriangle()
36  {
37  for (size_t i = 0; i < 3; i++)
38  {
39  r[i] = g[i] = b[i] = a[i] = 1.0f;
40  }
41  }
43  {
44  ASSERT_(p.size() == 3);
45  for (size_t i = 0; i < 3; i++)
46  {
47  x[i] = p[i].x;
48  y[i] = p[i].y;
49  z[i] = p[i].z;
50  r[i] = g[i] = b[i] = a[i] = 1.0f;
51  }
52  }
53  float x[3], y[3], z[3];
54  float r[3], g[3], b[3], a[3];
55  };
58  std::vector<TTriangle>::const_reverse_iterator;
59 
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 
79  public:
80  /**
81  * Polygon cache updating.
82  */
83  void updatePolygons() const;
84  /**
85  * Clear this object.
86  */
87  inline void clearTriangles()
88  {
89  m_triangles.clear();
90  polygonsUpToDate = false;
92  }
93  /**
94  * Get triangle count.
95  */
96  inline size_t getTrianglesCount() const { return m_triangles.size(); }
97  /**
98  * Gets the triangle in a given position.
99  */
100  inline void getTriangle(size_t idx, TTriangle& t) const
101  {
102  ASSERT_(idx < m_triangles.size());
103  t = m_triangles[idx];
104  }
105  /**
106  * Inserts a triangle into the set.
107  */
108  inline void insertTriangle(const TTriangle& t)
109  {
110  m_triangles.push_back(t);
111  polygonsUpToDate = false;
113  }
114  /**
115  * Inserts a set of triangles, bounded by iterators, into this set.
116  * \sa insertTriangle
117  */
118  template <class InputIterator>
119  inline void insertTriangles(
120  const InputIterator& begin, const InputIterator& end)
121  {
122  m_triangles.insert(m_triangles.end(), begin, end);
123  polygonsUpToDate = false;
125  }
126  /**
127  * Inserts an existing CSetOfTriangles into this one.
128  */
130  /**
131  * Reserves memory for certain number of triangles, avoiding multiple
132  * memory allocation calls.
133  */
134  inline void reserve(size_t t)
135  {
136  m_triangles.reserve(t);
138  }
139 
140  /** Enables or disables transparency. */
141  inline void enableTransparency(bool v)
142  {
145  }
146 
147  CRenderizable& setColor_u8(const mrpt::img::TColor& c) override;
148  CRenderizable& setColorR_u8(const uint8_t r) override;
149  CRenderizable& setColorG_u8(const uint8_t g) override;
150  CRenderizable& setColorB_u8(const uint8_t b) override;
151  CRenderizable& setColorA_u8(const uint8_t a) override;
152 
153  /** Render
154  */
155  void render_dl() const override;
156 
157  /** Ray tracing
158  */
159  bool traceRay(const mrpt::poses::CPose3D& o, double& dist) const override;
160 
161  /**
162  * Gets the polygon cache.
163  * \sa insertTriangles
164  */
165  void getPolygons(std::vector<mrpt::math::TPolygon3D>& polys) const;
166 
167  /**
168  * Inserts a set of triangles, given in a container of either TTriangle's
169  * or TPolygon3D
170  * \sa insertTriangle
171  */
172  template <class CONTAINER>
173  inline void insertTriangles(const CONTAINER& c)
174  {
175  this->insertTriangles(c.begin(), c.end());
177  }
178 
179  /**
180  * Gets the beginning iterator to this object.
181  */
182  inline const_iterator begin() const { return m_triangles.begin(); }
183  /**
184  * Gets the ending iterator to this object.
185  */
186  inline const_iterator end() const { return m_triangles.end(); }
187  /**
188  * Gets the reverse beginning iterator to this object, which points to the
189  * last triangle.
190  */
192  {
193  return m_triangles.rbegin();
194  }
195  /**
196  * Gets the reverse ending iterator to this object, which points to the
197  * beginning of the actual set.
198  */
199  inline const_reverse_iterator rend() const { return m_triangles.rend(); }
200  /** Evaluates the bounding box of this object (including possible children)
201  * in the coordinate frame of the object parent. */
202  void getBoundingBox(
203  mrpt::math::TPoint3D& bb_min,
204  mrpt::math::TPoint3D& bb_max) const override;
205 
206  /** Constructor
207  */
209  : m_triangles(),
211  polygonsUpToDate(false)
212  {
213  }
214 
215  /** Private, virtual destructor: only can be deleted from smart pointers */
216  virtual ~CSetOfTriangles() {}
217 };
218 /** Inserts a set of triangles into the list; note that this method allows to
219  * pass another CSetOfTriangles as argument. Allows call chaining.
220  * \sa mrpt::opengl::CSetOfTriangles::insertTriangle
221  */
222 template <class T>
224 {
225  s->insertTriangles(t.begin(), t.end());
226  return s;
227 }
228 /** Inserts a triangle into the list. Allows call chaining.
229  * \sa mrpt::opengl::CSetOfTriangles::insertTriangle
230  */
231 template <>
234 {
235  s->insertTriangle(t);
236  return s;
237 }
238 
239 } // namespace opengl
240 
241 } // namespace mrpt
242 
243 #endif
void getTriangle(size_t idx, TTriangle &t) const
Gets the triangle in a given position.
const_reverse_iterator rend() const
Gets the reverse ending iterator to this object, which points to the beginning of the actual set...
GLdouble GLdouble t
Definition: glext.h:3689
GLdouble GLdouble z
Definition: glext.h:3872
CRenderizable & setColorG_u8(const uint8_t g) override
Color components in the range [0,255].
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Ray tracing.
void getPolygons(std::vector< mrpt::math::TPolygon3D > &polys) const
Gets the polygon cache.
mrpt::serialization::CArchive & operator<<(mrpt::serialization::CArchive &out, const mrpt::opengl::CLight &o)
Definition: CLight.cpp:130
const_iterator end() const
Gets the ending iterator to this object.
The base class of 3D objects that can be directly rendered through OpenGL.
Definition: CRenderizable.h:43
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) ...
CRenderizable & setColor_u8(const mrpt::img::TColor &c) override
Changes the default object color.
size_t getTrianglesCount() const
Get triangle count.
GLdouble s
Definition: glext.h:3676
const_iterator begin() const
Gets the beginning iterator to this object.
CRenderizable & setColorR_u8(const uint8_t r) override
Color components in the range [0,255].
TTriangle(const mrpt::math::TPolygon3D &p)
unsigned char uint8_t
Definition: rptypes.h:41
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:113
const GLubyte * c
Definition: glext.h:6313
void insertTriangle(const TTriangle &t)
Inserts a triangle into the set.
GLuint GLuint end
Definition: glext.h:3528
void render_dl() const override
Render.
GLubyte g
Definition: glext.h:6279
GLubyte GLubyte b
Definition: glext.h:6279
CSetOfTriangles(bool enableTransparency=false)
Constructor.
void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const override
Evaluates the bounding box of this object (including possible children) in the coordinate frame of th...
std::vector< TTriangle > m_triangles
List of triangles.
void enableTransparency(bool v)
Enables or disables transparency.
void updatePolygons() const
Polygon cache updating.
const GLdouble * v
Definition: glext.h:3678
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
std::vector< TTriangle >::const_iterator const_iterator
const_reverse_iterator rbegin() const
Gets the reverse beginning iterator to this object, which points to the last triangle.
GLdouble GLdouble GLdouble r
Definition: glext.h:3705
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
void reserve(size_t t)
Reserves memory for certain number of triangles, avoiding multiple memory allocation calls...
GLenum GLint GLint y
Definition: glext.h:3538
virtual ~CSetOfTriangles()
Private, virtual destructor: only can be deleted from smart pointers.
A set of colored triangles.
void clearTriangles()
Clear this object.
std::vector< TTriangle >::const_reverse_iterator const_reverse_iterator
A RGB color - 8bit.
Definition: TColor.h:22
GLenum GLint x
Definition: glext.h:3538
Lightweight 3D point.
void insertTriangles(const CONTAINER &c)
Inserts a set of triangles, given in a container of either TTriangle&#39;s or TPolygon3D.
bool polygonsUpToDate
Mutable variable used to check whether polygons need to be recalculated.
CRenderizable & setColorB_u8(const uint8_t b) override
Color components in the range [0,255].
GLubyte GLubyte GLubyte a
Definition: glext.h:6279
bool m_enableTransparency
Transparency enabling.
GLfloat GLfloat p
Definition: glext.h:6305
CRenderizable & setColorA_u8(const uint8_t a) override
Color components in the range [0,255].
void insertTriangles(const InputIterator &begin, const InputIterator &end)
Inserts a set of triangles, bounded by iterators, into this set.
const Scalar * const_iterator
Definition: eigen_plugins.h:27
3D polygon, inheriting from std::vector<TPoint3D>



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019