Main MRPT website > C++ reference for MRPT 1.3.2
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-2015, 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  inline TTriangle(const mrpt::math::TPolygon3D &p) {
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  */
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  */
106  void insertTriangles(const CSetOfTrianglesPtr &p);
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 
118  virtual CRenderizable& setColor_u8(const mrpt::utils::TColor &c);
119  virtual CRenderizable& setColorR_u8(const uint8_t r);
120  virtual CRenderizable& setColorG_u8(const uint8_t g);
121  virtual CRenderizable& setColorB_u8(const uint8_t b);
122  virtual CRenderizable& setColorA_u8(const uint8_t a);
123 
124  /** Render
125  */
126  void render_dl() const;
127 
128  /** Ray tracing
129  */
130  virtual bool traceRay(const mrpt::poses::CPose3D &o,double &dist) const;
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  */
163  inline const_reverse_iterator rbegin() const {
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  */
169  inline const_reverse_iterator rend() const {
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. */
174  virtual void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const;
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  */
200  template<> inline CSetOfTrianglesPtr &operator<<(CSetOfTrianglesPtr &s,const CSetOfTriangles::TTriangle &t) {
201  s->insertTriangle(t);
202  return s;
203  }
204 
205  } // end namespace
206 
207 } // End of namespace
208 
209 
210 #endif
const_reverse_iterator rbegin() const
Gets the reverse beginning iterator to this object, which points to the last triangle.
OPENGL_IMPEXP mrpt::utils::CStream & operator<<(mrpt::utils::CStream &out, const mrpt::opengl::CLight &o)
EIGEN_STRONG_INLINE iterator end()
Definition: eigen_plugins.h:27
EIGEN_STRONG_INLINE const AdjointReturnType t() const
Transpose.
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) ...
const Scalar * const_iterator
Definition: eigen_plugins.h:24
TTriangle(const mrpt::math::TPolygon3D &p)
const_iterator begin() const
Gets the beginning iterator to this object.
A renderizable object suitable for rendering with OpenGL'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.
void insertTriangle(const TTriangle &t)
Inserts a triangle into the set.
const_iterator end() const
Gets the ending iterator to this object.
A RGB color - 8bit.
Definition: TColor.h:25
void getTriangle(size_t idx, TTriangle &t) const
Gets the triangle in a given position.
CSetOfTriangles(bool enableTransparency=false)
Constructor.
std::vector< TTriangle > m_triangles
List of triangles.
void enableTransparency(bool v)
Enables or disables transparency.
bool BASE_IMPEXP traceRay(const vector< TPolygonWithPlane > &vec, const mrpt::poses::CPose3D &pose, double &dist)
Fast ray tracing method using polygons' properties.
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...
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:72
#define ASSERT_(f)
void reserve(size_t t)
Reserves memory for certain number of triangles, avoiding multiple memory allocation calls...
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.
Lightweight 3D point.
const_reverse_iterator rend() const
Gets the reverse ending iterator to this object, which points to the beginning of the actual set...
size_t getTrianglesCount() const
Get triangle count.
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
void insertTriangles(const CONTAINER &c)
Inserts a set of triangles, given in a container of either TTriangle's or TPolygon3D.
bool polygonsUpToDate
Mutable variable used to check whether polygons need to be recalculated.
bool m_enableTransparency
Transparency enabling.
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



Page generated by Doxygen 1.8.9.1 for MRPT 1.3.2 SVN:Unversioned directory at Tue Dec 8 09:49:21 UTC 2015