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 |
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
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:128
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:41
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
#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:86
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
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:20
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: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020