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



Page generated by Doxygen 1.9.1 for MRPT 1.9.9 Git: 814d80880 Fri Aug 24 01:51:28 2018 +0200 at mar 26 may 2026 12:30:59 CEST