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-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 /** 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  };
56  /**
57  * Const iterator type.
58  */
60  /**
61  * Const reverse iterator type.
62  */
63  typedef std::vector<TTriangle>::const_reverse_iterator
65 
66  protected:
67  /**
68  * List of triangles.
69  * \sa TTriangle
70  */
71  std::vector<TTriangle> m_triangles;
72  /**
73  * Transparency enabling.
74  */
76  /**
77  * Mutable variable used to check whether polygons need to be recalculated.
78  */
79  mutable bool polygonsUpToDate;
80  /**
81  * Polygon cache.
82  */
83  mutable std::vector<mrpt::math::TPolygonWithPlane> tmpPolygons;
84 
85  public:
86  /**
87  * Polygon cache updating.
88  */
89  void updatePolygons() const;
90  /**
91  * Clear this object.
92  */
93  inline void clearTriangles()
94  {
95  m_triangles.clear();
96  polygonsUpToDate = false;
98  }
99  /**
100  * Get triangle count.
101  */
102  inline size_t getTrianglesCount() const { return m_triangles.size(); }
103  /**
104  * Gets the triangle in a given position.
105  */
106  inline void getTriangle(size_t idx, TTriangle& t) const
107  {
108  ASSERT_(idx < m_triangles.size());
109  t = m_triangles[idx];
110  }
111  /**
112  * Inserts a triangle into the set.
113  */
114  inline void insertTriangle(const TTriangle& t)
115  {
116  m_triangles.push_back(t);
117  polygonsUpToDate = false;
119  }
120  /**
121  * Inserts a set of triangles, bounded by iterators, into this set.
122  * \sa insertTriangle
123  */
124  template <class InputIterator>
125  inline void insertTriangles(
126  const InputIterator& begin, const InputIterator& end)
127  {
128  m_triangles.insert(m_triangles.end(), begin, end);
129  polygonsUpToDate = false;
131  }
132  /**
133  * Inserts an existing CSetOfTriangles into this one.
134  */
136  /**
137  * Reserves memory for certain number of triangles, avoiding multiple
138  * memory allocation calls.
139  */
140  inline void reserve(size_t t)
141  {
142  m_triangles.reserve(t);
144  }
145 
146  /** Enables or disables transparency. */
147  inline void enableTransparency(bool v)
148  {
151  }
152 
154  CRenderizable& setColorR_u8(const uint8_t r) override;
155  CRenderizable& setColorG_u8(const uint8_t g) override;
156  CRenderizable& setColorB_u8(const uint8_t b) override;
157  CRenderizable& setColorA_u8(const uint8_t a) override;
158 
159  /** Render
160  */
161  void render_dl() const override;
162 
163  /** Ray tracing
164  */
165  bool traceRay(const mrpt::poses::CPose3D& o, double& dist) const override;
166 
167  /**
168  * Gets the polygon cache.
169  * \sa insertTriangles
170  */
171  void getPolygons(std::vector<mrpt::math::TPolygon3D>& polys) const;
172 
173  /**
174  * Inserts a set of triangles, given in a container of either TTriangle's
175  * or TPolygon3D
176  * \sa insertTriangle
177  */
178  template <class CONTAINER>
179  inline void insertTriangles(const CONTAINER& c)
180  {
181  this->insertTriangles(c.begin(), c.end());
183  }
184 
185  /**
186  * Gets the beginning iterator to this object.
187  */
188  inline const_iterator begin() const { return m_triangles.begin(); }
189  /**
190  * Gets the ending iterator to this object.
191  */
192  inline const_iterator end() const { return m_triangles.end(); }
193  /**
194  * Gets the reverse beginning iterator to this object, which points to the
195  * last triangle.
196  */
198  {
199  return m_triangles.rbegin();
200  }
201  /**
202  * Gets the reverse ending iterator to this object, which points to the
203  * beginning of the actual set.
204  */
205  inline const_reverse_iterator rend() const { return m_triangles.rend(); }
206  /** Evaluates the bounding box of this object (including possible children)
207  * in the coordinate frame of the object parent. */
208  void getBoundingBox(
209  mrpt::math::TPoint3D& bb_min,
210  mrpt::math::TPoint3D& bb_max) const override;
211 
212  /** Constructor
213  */
215  : m_triangles(),
217  polygonsUpToDate(false)
218  {
219  }
220 
221  /** Private, virtual destructor: only can be deleted from smart pointers */
222  virtual ~CSetOfTriangles() {}
223 };
224 /** Inserts a set of triangles into the list; note that this method allows to
225  * pass another CSetOfTriangles as argument. Allows call chaining.
226  * \sa mrpt::opengl::CSetOfTriangles::insertTriangle
227  */
228 template <class T>
230 {
231  s->insertTriangles(t.begin(), t.end());
232  return s;
233 }
234 /** Inserts a triangle into the list. Allows call chaining.
235  * \sa mrpt::opengl::CSetOfTriangles::insertTriangle
236  */
237 template <>
240 {
241  s->insertTriangle(t);
242  return s;
243 }
244 
245 } // end namespace
246 
247 } // End of namespace
248 
249 #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
mrpt::utils::CStream & operator<<(mrpt::utils::CStream &out, const mrpt::opengl::CLight &o)
Definition: CLight.cpp:132
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.
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) ...
const Scalar * const_iterator
Definition: eigen_plugins.h:27
std::shared_ptr< CSetOfTriangles > Ptr
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.
std::vector< TTriangle >::const_iterator const_iterator
Const iterator type.
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.
CRenderizable & setColor_u8(const mrpt::utils::TColor &c) override
Changes the default object color.
GLubyte g
Definition: glext.h:6279
A RGB color - 8bit.
Definition: TColor.h:25
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...
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
#define ASSERT_(f)
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
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.
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.
3D polygon, inheriting from std::vector<TPoint3D>



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019