Main MRPT website > C++ reference for MRPT 1.4.0
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-2016, 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
15namespace mrpt
16{
17 namespace opengl
18 {
19
20
21 // This must be added to any CSerializable derived class:
23
24 /** A set of colored triangles.
25 * This class can be used to draw any solid, arbitrarily complex object (without textures).
26 * \sa opengl::COpenGLScene, CSetOfTexturedTriangles
27 * \ingroup mrpt_opengl_grp
28 */
30 {
32 public:
33 /**
34 * Triangle definition. Each vertex has three spatial coordinates and four color values.
35 */
37 {
38 inline TTriangle() { }
40 ASSERT_(p.size()==3)
41 for (size_t i=0;i<3;i++) {
42 x[i]=p[i].x; y[i]=p[i].y; z[i]=p[i].z; r[i]=g[i]=b[i]=a[i]=1; }
43 }
44 float x[3],y[3],z[3];
45 float r[3],g[3],b[3],a[3];
46 };
47 /**
48 * Const iterator type.
49 */
50 typedef std::vector<TTriangle>::const_iterator const_iterator;
51 /**
52 * Const reverse iterator type.
53 */
54 typedef std::vector<TTriangle>::const_reverse_iterator const_reverse_iterator;
55 protected:
56 /**
57 * List of triangles.
58 * \sa TTriangle
59 */
60 std::vector<TTriangle> m_triangles;
61 /**
62 * Transparency enabling.
63 */
65 /**
66 * Mutable variable used to check whether polygons need to be recalculated.
67 */
68 mutable bool polygonsUpToDate;
69 /**
70 * Polygon cache.
71 */
72 mutable std::vector<mrpt::math::TPolygonWithPlane> tmpPolygons;
73 public:
74 /**
75 * Polygon cache updating.
76 */
77 void updatePolygons() const;
78 /**
79 * Clear this object.
80 */
81 inline void clearTriangles() { m_triangles.clear();polygonsUpToDate=false; CRenderizableDisplayList::notifyChange(); }
82 /**
83 * Get triangle count.
84 */
85 inline size_t getTrianglesCount() const { return m_triangles.size(); }
86 /**
87 * Gets the triangle in a given position.
88 */
89 inline void getTriangle(size_t idx, TTriangle &t) const { ASSERT_(idx<m_triangles.size()); t=m_triangles[idx]; }
90 /**
91 * Inserts a triangle into the set.
92 */
93 inline void insertTriangle( const TTriangle &t ) { m_triangles.push_back(t);polygonsUpToDate=false; CRenderizableDisplayList::notifyChange(); }
94 /**
95 * Inserts a set of triangles, bounded by iterators, into this set.
96 * \sa insertTriangle
97 */
98 template<class InputIterator> inline void insertTriangles(const InputIterator &begin,const InputIterator &end) {
99 m_triangles.insert(m_triangles.end(),begin,end);
100 polygonsUpToDate=false;
102 }
103 /**
104 * Inserts an existing CSetOfTriangles into this one.
105 */
107 /**
108 * Reserves memory for certain number of triangles, avoiding multiple memory allocation calls.
109 */
110 inline void reserve(size_t t) {
111 m_triangles.reserve(t);
113 }
114
115 /** Enables or disables transparency. */
116 inline void enableTransparency( bool v ) { m_enableTransparency = v; CRenderizableDisplayList::notifyChange(); }
117
123
124 /** Render
125 */
127
128 /** Ray tracing
129 */
130 bool traceRay(const mrpt::poses::CPose3D &o,double &dist) const MRPT_OVERRIDE;
131
132 /**
133 * Gets the polygon cache.
134 * \sa insertTriangles
135 */
136 void getPolygons(std::vector<mrpt::math::TPolygon3D> &polys) const;
137
138 /**
139 * Inserts a set of triangles, given in a container of either TTriangle's or TPolygon3D
140 * \sa insertTriangle
141 */
142 template<class CONTAINER>
143 inline void insertTriangles(const CONTAINER &c) {
144 this->insertTriangles(c.begin(),c.end());
146 }
147
148 /**
149 * Gets the beginning iterator to this object.
150 */
151 inline const_iterator begin() const {
152 return m_triangles.begin();
153 }
154 /**
155 * Gets the ending iterator to this object.
156 */
157 inline const_iterator end() const {
158 return m_triangles.end();
159 }
160 /**
161 * Gets the reverse beginning iterator to this object, which points to the last triangle.
162 */
164 return m_triangles.rbegin();
165 }
166 /**
167 * Gets the reverse ending iterator to this object, which points to the beginning of the actual set.
168 */
170 return m_triangles.rend();
171 }
172
173 /** Evaluates the bounding box of this object (including possible children) in the coordinate frame of the object parent. */
175
176 private:
177 /** Constructor
178 */
179 CSetOfTriangles( bool enableTransparency = false ) :
180 m_triangles(),
181 m_enableTransparency(enableTransparency),
182 polygonsUpToDate(false)
183 {
184 }
185
186 /** Private, virtual destructor: only can be deleted from smart pointers */
187 virtual ~CSetOfTriangles() { }
188 };
189 DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE( CSetOfTriangles, CRenderizableDisplayList, OPENGL_IMPEXP )
190 /** Inserts a set of triangles into the list; note that this method allows to pass another CSetOfTriangles as argument. Allows call chaining.
191 * \sa mrpt::opengl::CSetOfTriangles::insertTriangle
192 */
193 template<class T> inline CSetOfTrianglesPtr &operator<<(CSetOfTrianglesPtr &s,const T &t) {
194 s->insertTriangles(t.begin(),t.end());
195 return s;
196 }
197 /** Inserts a triangle into the list. Allows call chaining.
198 * \sa mrpt::opengl::CSetOfTriangles::insertTriangle
199 */
201 s->insertTriangle(t);
202 return s;
203 }
204
205 } // end namespace
206
207} // End of namespace
208
209
210#endif
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
This declaration must be inserted in all CSerializable classes definition, before 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:45
A set of colored triangles.
void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const MRPT_OVERRIDE
Evaluates the bounding box of this object (including possible children) in the coordinate frame of th...
size_t getTrianglesCount() const
Get triangle count.
CRenderizable & setColorA_u8(const uint8_t a) MRPT_OVERRIDE
Color components in the range [0,255].
bool polygonsUpToDate
Mutable variable used to check whether polygons need to be recalculated.
CRenderizable & setColorB_u8(const uint8_t b) MRPT_OVERRIDE
Color components in the range [0,255].
void insertTriangles(const CSetOfTrianglesPtr &p)
Inserts an existing CSetOfTriangles into this one.
void enableTransparency(bool v)
Enables or disables transparency.
bool m_enableTransparency
Transparency enabling.
const_iterator end() const
Gets the ending iterator to this object.
virtual ~CSetOfTriangles()
Private, virtual destructor: only can be deleted from smart pointers.
std::vector< TTriangle >::const_iterator const_iterator
Const iterator type.
void clearTriangles()
Clear this object.
CSetOfTriangles(bool enableTransparency=false)
Constructor.
CRenderizable & setColorR_u8(const uint8_t r) MRPT_OVERRIDE
Color components in the range [0,255].
const_iterator begin() const
Gets the beginning iterator to this object.
void render_dl() const MRPT_OVERRIDE
Render.
CRenderizable & setColorG_u8(const uint8_t g) MRPT_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.
void insertTriangle(const TTriangle &t)
Inserts a triangle into the set.
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 updatePolygons() const
Polygon cache updating.
CRenderizable & setColor_u8(const mrpt::utils::TColor &c) MRPT_OVERRIDE
Changes the default object color.
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
Const reverse iterator type.
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.
EIGEN_STRONG_INLINE const AdjointReturnType t() const
Transpose.
EIGEN_STRONG_INLINE iterator begin()
Definition: eigen_plugins.h:26
EIGEN_STRONG_INLINE iterator end()
Definition: eigen_plugins.h:27
#define ASSERT_(f)
Definition: mrpt_macros.h:261
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
Definition: mrpt_macros.h:28
struct OPENGL_IMPEXP CSetOfTrianglesPtr
OPENGL_IMPEXP mrpt::utils::CStream & operator<<(mrpt::utils::CStream &out, const mrpt::opengl::CLight &o)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
STL namespace.
unsigned char uint8_t
Definition: pstdint.h:143
Lightweight 3D point.
TTriangle(const mrpt::math::TPolygon3D &p)
A RGB color - 8bit.
Definition: TColor.h:26



Page generated by Doxygen 1.9.6 for MRPT 1.4.0 SVN: at Fri Jan 20 02:28:26 UTC 2023