Main MRPT website > C++ reference for MRPT 1.5.7
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 
20 
21  // This must be added to any CSerializable derived class:
22  DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CSetOfTriangles, CRenderizableDisplayList, OPENGL_IMPEXP )
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() {
39  for (size_t i = 0; i<3; i++) {
40  r[i] = g[i] = b[i] = a[i] = 1.0f;
41  }
42  }
44  ASSERT_(p.size()==3)
45  for (size_t i=0;i<3;i++) {
46  x[i]=p[i].x; y[i]=p[i].y; z[i]=p[i].z; r[i]=g[i]=b[i]=a[i]=1.0f;
47  }
48  }
49  float x[3],y[3],z[3];
50  float r[3],g[3],b[3],a[3];
51  };
52  /**
53  * Const iterator type.
54  */
56  /**
57  * Const reverse iterator type.
58  */
59  typedef std::vector<TTriangle>::const_reverse_iterator const_reverse_iterator;
60  protected:
61  /**
62  * List of triangles.
63  * \sa TTriangle
64  */
65  std::vector<TTriangle> m_triangles;
66  /**
67  * Transparency enabling.
68  */
70  /**
71  * Mutable variable used to check whether polygons need to be recalculated.
72  */
73  mutable bool polygonsUpToDate;
74  /**
75  * Polygon cache.
76  */
77  mutable std::vector<mrpt::math::TPolygonWithPlane> tmpPolygons;
78  public:
79  /**
80  * Polygon cache updating.
81  */
82  void updatePolygons() const;
83  /**
84  * Clear this object.
85  */
86  inline void clearTriangles() { m_triangles.clear();polygonsUpToDate=false; CRenderizableDisplayList::notifyChange(); }
87  /**
88  * Get triangle count.
89  */
90  inline size_t getTrianglesCount() const { return m_triangles.size(); }
91  /**
92  * Gets the triangle in a given position.
93  */
94  inline void getTriangle(size_t idx, TTriangle &t) const { ASSERT_(idx<m_triangles.size()); t=m_triangles[idx]; }
95  /**
96  * Inserts a triangle into the set.
97  */
98  inline void insertTriangle( const TTriangle &t ) { m_triangles.push_back(t);polygonsUpToDate=false; CRenderizableDisplayList::notifyChange(); }
99  /**
100  * Inserts a set of triangles, bounded by iterators, into this set.
101  * \sa insertTriangle
102  */
103  template<class InputIterator> inline void insertTriangles(const InputIterator &begin,const InputIterator &end) {
104  m_triangles.insert(m_triangles.end(),begin,end);
105  polygonsUpToDate=false;
107  }
108  /**
109  * Inserts an existing CSetOfTriangles into this one.
110  */
111  void insertTriangles(const CSetOfTrianglesPtr &p);
112  /**
113  * Reserves memory for certain number of triangles, avoiding multiple memory allocation calls.
114  */
115  inline void reserve(size_t t) {
116  m_triangles.reserve(t);
118  }
119 
120  /** Enables or disables transparency. */
121  inline void enableTransparency( bool v ) { m_enableTransparency = v; CRenderizableDisplayList::notifyChange(); }
122 
123  CRenderizable& setColor_u8(const mrpt::utils::TColor &c) MRPT_OVERRIDE;
124  CRenderizable& setColorR_u8(const uint8_t r) MRPT_OVERRIDE;
125  CRenderizable& setColorG_u8(const uint8_t g) MRPT_OVERRIDE;
126  CRenderizable& setColorB_u8(const uint8_t b) MRPT_OVERRIDE;
127  CRenderizable& setColorA_u8(const uint8_t a) MRPT_OVERRIDE;
128 
129  /** Render
130  */
131  void render_dl() const MRPT_OVERRIDE;
132 
133  /** Ray tracing
134  */
135  bool traceRay(const mrpt::poses::CPose3D &o,double &dist) const MRPT_OVERRIDE;
136 
137  /**
138  * Gets the polygon cache.
139  * \sa insertTriangles
140  */
141  void getPolygons(std::vector<mrpt::math::TPolygon3D> &polys) const;
142 
143  /**
144  * Inserts a set of triangles, given in a container of either TTriangle's or TPolygon3D
145  * \sa insertTriangle
146  */
147  template<class CONTAINER>
148  inline void insertTriangles(const CONTAINER &c) {
149  this->insertTriangles(c.begin(),c.end());
151  }
152 
153  /**
154  * Gets the beginning iterator to this object.
155  */
156  inline const_iterator begin() const {
157  return m_triangles.begin();
158  }
159  /**
160  * Gets the ending iterator to this object.
161  */
162  inline const_iterator end() const {
163  return m_triangles.end();
164  }
165  /**
166  * Gets the reverse beginning iterator to this object, which points to the last triangle.
167  */
169  return m_triangles.rbegin();
170  }
171  /**
172  * Gets the reverse ending iterator to this object, which points to the beginning of the actual set.
173  */
174  inline const_reverse_iterator rend() const {
175  return m_triangles.rend();
176  }
177 
178  /** Evaluates the bounding box of this object (including possible children) in the coordinate frame of the object parent. */
179  void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const MRPT_OVERRIDE;
180 
181  private:
182  /** Constructor
183  */
184  CSetOfTriangles( bool enableTransparency = false ) :
185  m_triangles(),
186  m_enableTransparency(enableTransparency),
187  polygonsUpToDate(false)
188  {
189  }
190 
191  /** Private, virtual destructor: only can be deleted from smart pointers */
192  virtual ~CSetOfTriangles() { }
193  };
194  DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE( CSetOfTriangles, CRenderizableDisplayList, OPENGL_IMPEXP )
195  /** Inserts a set of triangles into the list; note that this method allows to pass another CSetOfTriangles as argument. Allows call chaining.
196  * \sa mrpt::opengl::CSetOfTriangles::insertTriangle
197  */
198  template<class T> inline CSetOfTrianglesPtr &operator<<(CSetOfTrianglesPtr &s,const T &t) {
199  s->insertTriangles(t.begin(),t.end());
200  return s;
201  }
202  /** Inserts a triangle into the list. Allows call chaining.
203  * \sa mrpt::opengl::CSetOfTriangles::insertTriangle
204  */
205  template<> inline CSetOfTrianglesPtr &operator<<(CSetOfTrianglesPtr &s,const CSetOfTriangles::TTriangle &t) {
206  s->insertTriangle(t);
207  return s;
208  }
209 
210  } // end namespace
211 
212 } // End of namespace
213 
214 
215 #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:3610
GLdouble GLdouble z
Definition: glext.h:3734
OPENGL_IMPEXP mrpt::utils::CStream & operator<<(mrpt::utils::CStream &out, const mrpt::opengl::CLight &o)
Definition: CLight.cpp:132
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
bool BASE_IMPEXP traceRay(const std::vector< TPolygonWithPlane > &vec, const mrpt::poses::CPose3D &pose, double &dist)
Fast ray tracing method using polygons&#39; properties.
Definition: geometry.cpp:1989
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:44
EIGEN_STRONG_INLINE iterator begin()
Definition: eigen_plugins.h:26
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) ...
STL namespace.
const Scalar * const_iterator
Definition: eigen_plugins.h:24
size_t getTrianglesCount() const
Get triangle count.
GLdouble s
Definition: glext.h:3602
const_iterator begin() const
Gets the beginning iterator to this object.
TTriangle(const mrpt::math::TPolygon3D &p)
unsigned char uint8_t
Definition: rptypes.h:43
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
#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...
std::vector< TTriangle >::const_iterator const_iterator
Const iterator type.
const GLubyte * c
Definition: glext.h:5590
void insertTriangle(const TTriangle &t)
Inserts a triangle into the set.
GLuint GLuint end
Definition: glext.h:3512
GLubyte g
Definition: glext.h:5575
A RGB color - 8bit.
Definition: TColor.h:26
GLubyte GLubyte b
Definition: glext.h:5575
class BASE_IMPEXP TPolygon3D
CSetOfTriangles(bool enableTransparency=false)
Constructor.
std::vector< TTriangle > m_triangles
List of triangles.
void enableTransparency(bool v)
Enables or disables transparency.
const GLdouble * v
Definition: glext.h:3603
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:3618
#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:3516
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:3516
Lightweight 3D point.
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
bool polygonsUpToDate
Mutable variable used to check whether polygons need to be recalculated.
GLubyte GLubyte GLubyte a
Definition: glext.h:5575
bool m_enableTransparency
Transparency enabling.
GLfloat GLfloat p
Definition: glext.h:5587
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.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019