MRPT  2.0.4
CSetOfTriangles.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
11 #include <mrpt/math/geometry.h>
13 
14 namespace mrpt::opengl
15 {
16 /** A set of colored triangles, able to draw any solid, arbitrarily complex
17  * object without textures. For textures, see CSetOfTexturedTriangles
18  *
19  * \sa opengl::COpenGLScene, CSetOfTexturedTriangles
20  * \ingroup mrpt_opengl_grp
21  */
23 {
25  public:
26  /** @name Renderizable shader API virtual methods
27  * @{ */
28  void onUpdateBuffers_Triangles() override;
29  /** @} */
30 
31  using const_iterator = std::vector<TTriangle>::const_iterator;
33  std::vector<TTriangle>::const_reverse_iterator;
34 
35  /** Explicitly updates the internal polygon cache, with all triangles as
36  * polygons. \sa getPolygons() */
37  void updatePolygons() const;
38 
39  /** Clear this object, removing all triangles. */
41  {
42  m_triangles.clear();
43  polygonsUpToDate = false;
45  }
46 
47  /** Get triangle count */
48  size_t getTrianglesCount() const { return m_triangles.size(); }
49 
50  /** Gets the i-th triangle */
51  void getTriangle(size_t idx, TTriangle& t) const
52  {
53  ASSERT_BELOW_(idx, m_triangles.size());
54  t = m_triangles[idx];
55  }
56  /** Inserts a triangle into the set */
57  void insertTriangle(const TTriangle& t)
58  {
59  m_triangles.push_back(t);
60  polygonsUpToDate = false;
62  }
63 
64  /** Inserts a set of triangles, bounded by iterators, into this set.
65  * \sa insertTriangle
66  */
67  template <class InputIterator>
68  void insertTriangles(const InputIterator& begin, const InputIterator& end)
69  {
70  m_triangles.insert(m_triangles.end(), begin, end);
71  polygonsUpToDate = false;
73  }
74 
75  /** Inserts an existing CSetOfTriangles into this one */
77 
78  /**
79  * Reserves memory for certain number of triangles, avoiding multiple
80  * memory allocation calls.
81  */
82  inline void reserve(size_t t)
83  {
84  m_triangles.reserve(t);
86  }
87 
88  /** Overwrite all triangles colors with the one provided */
89  CRenderizable& setColor_u8(const mrpt::img::TColor& c) override;
90  /** Overwrite all triangles colors with the one provided */
91  CRenderizable& setColorR_u8(const uint8_t r) override;
92  /** Overwrite all triangles colors with the one provided */
93  CRenderizable& setColorG_u8(const uint8_t g) override;
94  /** Overwrite all triangles colors with the one provided */
95  CRenderizable& setColorB_u8(const uint8_t b) override;
96  /** Overwrite all triangles colors with the one provided */
97  CRenderizable& setColorA_u8(const uint8_t a) override;
98 
99  bool traceRay(const mrpt::poses::CPose3D& o, double& dist) const override;
100 
101  /**
102  * Gets the polygon cache.
103  * \sa insertTriangles
104  */
105  void getPolygons(std::vector<mrpt::math::TPolygon3D>& polys) const;
106 
107  /**
108  * Inserts a set of triangles, given in a container of either TTriangle's
109  * or TPolygon3D
110  * \sa insertTriangle
111  */
112  template <class CONTAINER>
113  inline void insertTriangles(const CONTAINER& c)
114  {
115  this->insertTriangles(c.begin(), c.end());
117  }
118 
119  /**
120  * Gets the beginning iterator to this object.
121  */
122  inline const_iterator begin() const { return m_triangles.begin(); }
123  /**
124  * Gets the ending iterator to this object.
125  */
126  inline const_iterator end() const { return m_triangles.end(); }
127  /**
128  * Gets the reverse beginning iterator to this object, which points to the
129  * last triangle.
130  */
132  {
133  return m_triangles.rbegin();
134  }
135  /**
136  * Gets the reverse ending iterator to this object, which points to the
137  * beginning of the actual set.
138  */
139  inline const_reverse_iterator rend() const { return m_triangles.rend(); }
140  /** Evaluates the bounding box of this object (including possible children)
141  * in the coordinate frame of the object parent. */
142  void getBoundingBox(
144  mrpt::math::TPoint3D& bb_max) const override;
145 
146  CSetOfTriangles() = default;
147  virtual ~CSetOfTriangles() override = default;
148 
149  protected:
150  /**
151  * Mutable variable used to check whether polygons need to be recalculated.
152  */
153  mutable bool polygonsUpToDate{false};
154 
155  /** Polygon cache, used for ray-tracing only */
156  mutable std::vector<mrpt::math::TPolygonWithPlane> m_polygons;
157 };
158 /** Inserts a set of triangles into the list; note that this method allows to
159  * pass another CSetOfTriangles as argument. Allows call chaining.
160  * \sa mrpt::opengl::CSetOfTriangles::insertTriangle
161  */
162 template <class T>
164 {
165  s->insertTriangles(t.begin(), t.end());
166  return s;
167 }
168 /** Inserts a triangle into the list. Allows call chaining.
169  * \sa mrpt::opengl::CSetOfTriangles::insertTriangle
170  */
171 template <>
174 {
175  s->insertTriangle(t);
176  return s;
177 }
178 } // namespace mrpt::opengl
void getTriangle(size_t idx, TTriangle &t) const
Gets the i-th triangle.
const_reverse_iterator rend() const
Gets the reverse ending iterator to this object, which points to the beginning of the actual set...
CRenderizable & setColorG_u8(const uint8_t g) override
Overwrite all triangles colors with the one provided.
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Simulation of ray-trace, given a pose.
void getPolygons(std::vector< mrpt::math::TPolygon3D > &polys) const
Gets the polygon cache.
#define ASSERT_BELOW_(__A, __B)
Definition: exceptions.h:149
void notifyChange() const
Call to enable calling renderUpdateBuffers() before the next render() rendering iteration.
A triangle (float coordinates) with RGBA colors (u8) and UV (texture coordinates) for each vertex...
Definition: TTriangle.h:35
const_iterator end() const
Gets the ending iterator to this object.
COpenGLScene::Ptr & operator<<(COpenGLScene::Ptr &s, const CRenderizable::Ptr &r)
Inserts an openGL object into a scene.
Definition: COpenGLScene.h:252
The base class of 3D objects that can be directly rendered through OpenGL.
Definition: CRenderizable.h:48
void onUpdateBuffers_Triangles() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
Renderizable generic renderer for objects using the triangles shader.
CRenderizable & setColor_u8(const mrpt::img::TColor &c) override
Overwrite all triangles colors with the one provided.
size_t getTrianglesCount() const
Get triangle count.
const_iterator begin() const
Gets the beginning iterator to this object.
CRenderizable & setColorR_u8(const uint8_t r) override
Overwrite all triangles colors with the one provided.
void insertTriangle(const TTriangle &t)
Inserts a triangle into the set.
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...
virtual ~CSetOfTriangles() override=default
void updatePolygons() const
Explicitly updates the internal polygon cache, with all triangles as polygons.
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.
std::vector< mrpt::opengl::TTriangle > m_triangles
List of triangles.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:85
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
const auto bb_max
void reserve(size_t t)
Reserves memory for certain number of triangles, avoiding multiple memory allocation calls...
#define DEFINE_SERIALIZABLE(class_name, NS)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
A set of colored triangles, able to draw any solid, arbitrarily complex object without textures...
const auto bb_min
void clearTriangles()
Clear this object, removing all triangles.
std::vector< TTriangle >::const_reverse_iterator const_reverse_iterator
A RGB color - 8bit.
Definition: TColor.h:25
std::vector< mrpt::math::TPolygonWithPlane > m_polygons
Polygon cache, used for ray-tracing only.
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
Overwrite all triangles colors with the one provided.
CRenderizable & setColorA_u8(const uint8_t a) override
Overwrite all triangles colors with the one provided.
void insertTriangles(const InputIterator &begin, const InputIterator &end)
Inserts a set of triangles, bounded by iterators, into this set.



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 7b5ddf9de Fri May 29 14:02:56 2020 +0200 at vie may 29 14:15:09 CEST 2020