Main MRPT website > C++ reference for MRPT 1.9.9
CGeneralizedCylinder.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_CGeneralizedCylinder_H
10 #define opengl_CGeneralizedCylinder_H
11 
15 #include <mrpt/math/geometry.h>
18 
19 namespace mrpt
20 {
21 namespace opengl
22 {
23 class CGeneralizedCylinder;
24 /**
25  * This object represents any figure obtained by extruding any profile along a
26  * given axis. The profile should lie over a x=0 plane, and the axis must be
27  * roughly perpendicular to this plane. In particular, it should be almost
28  * perpendicular to the Z axis.
29  * \ingroup mrpt_opengl_grp
30  */
32 {
34  public:
35  /**
36  * Auxiliary struct holding any quadrilateral, represented by foour points.
37  */
39  {
40  private:
41  /**
42  * Automatically compute a vector normal to this quadrilateral.
43  */
45 
46  public:
47  /**
48  * Quadrilateral`'s points.
49  */
51  /**
52  * Normal vector.
53  */
54  double normal[3];
55  /**
56  * Given a polygon with 4 already positions allocated, this method
57  * fills it with the quadrilateral points.
58  * \sa mrpt::math::TPolygon3D
59  */
61  {
62  vec[0] = points[0];
63  vec[1] = points[1];
64  vec[2] = points[2];
65  vec[3] = points[3];
66  }
67  /**
68  * Constructor from 4 points.
69  */
71  const mrpt::math::TPoint3D& p1, const mrpt::math::TPoint3D& p2,
72  const mrpt::math::TPoint3D& p3, const mrpt::math::TPoint3D& p4)
73  {
74  points[0] = p1;
75  points[1] = p2;
76  points[2] = p3;
77  points[3] = p4;
79  }
80  /**
81  * Construction from any array of four compatible objects.
82  */
83  template <class T>
84  TQuadrilateral(const T (&p)[4])
85  {
86  for (int i = 0; i < 4; i++) points[i] = p[i];
88  }
89  /**
90  * Empty constructor. Initializes to garbage.
91  */
93  /**
94  * Destructor.
95  */
97  };
98 
99  protected:
100  /** Cylinder's axis. It's represented as a pose because it holds the angle
101  * to get to the next pose. */
103  /** Object's generatrix, that is, profile which will be extruded. */
104  std::vector<mrpt::math::TPoint3D> generatrix;
105  /** Mutable object with mesh information, used to avoid repeated
106  * computations. */
107  mutable std::vector<TQuadrilateral> mesh;
108  /** Mutable object with the cylinder's points, used to avoid repeated
109  * computations. */
111  /** Mutable flag which tells if recalculations are needed. */
112  mutable bool meshUpToDate;
113  /**
114  * Mutable set of data used in ray tracing.
115  * \sa mrpt::math::TPolygonWithPlane
116  */
117  mutable std::vector<mrpt::math::TPolygonWithPlane> polys;
118  /** Mutable flag telling whether ray tracing temporary data must be
119  * recalculated or not. */
120  mutable bool polysUpToDate;
121  /** Boolean variable which determines if the profile is closed at each
122  * section. */
123  bool closed;
124  /** Flag to determine whether the object is fully visible or only some
125  * sections are. */
127  /**
128  * First visible section, if fullyVisible is set to false.
129  * \sa fullyVisible,lastSection
130  */
131  size_t firstSection;
132  /**
133  * Last visible section, if fullyVisible is set to false.
134  * \sa fullyVisible,firstSection
135  */
136  size_t lastSection;
137 
138  public:
139  /**
140  * Creation of generalized cylinder from axis and generatrix
141  */
143  const std::vector<mrpt::math::TPoint3D>& axis,
144  const std::vector<mrpt::math::TPoint3D>& generatrix);
145  /**
146  * Render.
147  * \sa mrpt::opengl::CRenderizable
148  */
149  void render_dl() const override;
150  /**
151  * Ray tracing.
152  * \sa mrpt::opengl::CRenderizable.
153  */
154  bool traceRay(const mrpt::poses::CPose3D& o, double& dist) const override;
155  /**
156  * Get axis's spatial coordinates.
157  */
158  inline void getAxis(std::vector<mrpt::math::TPoint3D>& a) const
159  {
160  // a=axis;
161  size_t N = axis.size();
162  a.resize(N);
163  for (size_t i = 0; i < N; i++)
164  {
165  a[i].x = axis[i].x();
166  a[i].y = axis[i].y();
167  a[i].z = axis[i].z();
168  }
169  }
170  /**
171  * Get axis, including angular coordinates.
172  */
173  inline void getAxis(
175  {
176  a = axis;
177  }
178  /**
179  * Set the axis points.
180  */
181  inline void setAxis(const std::vector<mrpt::math::TPoint3D>& a)
182  {
183  generatePoses(a, axis);
184  meshUpToDate = false;
185  fullyVisible = true;
187  }
188  /**
189  * Get cylinder's profile.
190  */
191  inline void getGeneratrix(std::vector<mrpt::math::TPoint3D>& g) const
192  {
193  g = generatrix;
194  }
195  /**
196  * Set cylinder's profile.
197  */
198  inline void setGeneratrix(const std::vector<mrpt::math::TPoint3D>& g)
199  {
200  generatrix = g;
201  meshUpToDate = false;
203  }
204  /**
205  * Returns true if each section is a closed polygon.
206  */
207  inline bool isClosed() const { return closed; }
208  /**
209  * Set whether each section is a closed polygon or not.
210  */
211  inline void setClosed(bool c = true)
212  {
213  closed = c;
214  meshUpToDate = false;
216  }
217  /**
218  * Get a polyhedron containing the starting point of the cylinder (its
219  * "base").
220  * \sa getEnd,mrpt::opengl::CPolyhedron
221  */
222  void getOrigin(CPolyhedron::Ptr& poly) const;
223  /**
224  * Get a polyhedron containing the ending point of the cylinder (its
225  * "base").
226  * \sa getOrigin,mrpt::opengl::CPolyhedron
227  */
228  void getEnd(CPolyhedron::Ptr& poly) const;
229  /**
230  * Get the cylinder as a set of polygons in 3D.
231  * \sa mrpt::math::TPolygon3D
232  */
233  void generateSetOfPolygons(std::vector<mrpt::math::TPolygon3D>& res) const;
234  /**
235  * Get a polyhedron consisting of a set of closed sections of the cylinder.
236  * \sa mrpt::opengl::CPolyhedron
237  */
238  void getClosedSection(
239  size_t index1, size_t index2, CPolyhedron::Ptr& poly) const;
240  /**
241  * Get a polyhedron consisting of a single section of the cylinder.
242  * \sa mrpt::opengl::CPolyhedron
243  */
244  inline void getClosedSection(size_t index, CPolyhedron::Ptr& poly) const
245  {
246  getClosedSection(index, index, poly);
247  }
248  /**
249  * Get the number of sections in this cylinder.
250  */
251  inline size_t getNumberOfSections() const
252  {
253  return axis.size() ? (axis.size() - 1) : 0;
254  }
255  /**
256  * Get how many visible sections are in the cylinder.
257  */
258  inline size_t getVisibleSections() const
259  {
262  }
263  /**
264  * Gets the cylinder's visible sections.
265  */
266  void getVisibleSections(size_t& first, size_t& last) const
267  {
268  if (fullyVisible)
269  {
270  first = 0;
271  last = getNumberOfSections();
272  }
273  else
274  {
276  last = lastSection;
277  }
278  }
279  /**
280  * Sets all sections visible.
281  */
282  inline void setAllSectionsVisible()
283  {
284  fullyVisible = true;
286  }
287  /**
288  * Hides all sections.
289  */
290  inline void setAllSectionsInvisible(size_t pointer = 0)
291  {
292  fullyVisible = false;
296  }
297  /**
298  * Sets which sections are visible.
299  * \throw std::logic_error on wrongly defined bounds.
300  */
301  inline void setVisibleSections(size_t first, size_t last)
302  {
303  fullyVisible = false;
304  if (first > last || last > getNumberOfSections())
305  throw std::logic_error("Wrong bound definition");
307  lastSection = last;
309  }
310  /**
311  * Adds another visible section at the start of the cylinder. The cylinder
312  * must have an invisble section to display.
313  * \throw std::logic_error if there is no section to add to the displaying
314  * set.
315  * \sa
316  * addVisibleSectionAtEnd,removeVisibleSectionAtStart,removeVisibleSectionAtEnd
317  */
319  {
320  if (fullyVisible || firstSection == 0)
321  throw std::logic_error("No more sections");
322  firstSection--;
324  }
325  /**
326  * Adds another visible section at the end of the cylinder. The cylinder
327  * must have an invisible section to display.
328  * \throw std::logic_error if there is no section to add to the displaying
329  * set.
330  * \sa
331  * addVisibleSectionAtStart,removeVisibleSectionAtStart,removeVisibleSectionAtEnd
332  */
334  {
336  throw std::logic_error("No more sections");
337  lastSection++;
339  }
340  /**
341  * Removes a visible section from the start of the currently visible set.
342  * \throw std::logic_error if there are no visible sections.
343  * \sa
344  * addVisibleSectionAtStart,addVisibleSectionAtEnd,removeVisibleSectionAtEnd
345  */
347  /**
348  * Removes a visible section from the ending of the currently visible set.
349  * \throw std::logic_error when there is no such section.
350  * \sa
351  * addVisibleSectionAtStart,addVisibleSectionAtEnd,removeVisibleSectionAtStart
352  */
354  /**
355  * Gets the axis pose of the first section, returning false if there is no
356  * such pose.
357  */
359  /**
360  * Gets the axis pose of the last section, returning false if there is no
361  * such pose.
362  */
364  /**
365  * Gets the axis pose of the first visible section, returning false if
366  * there is no such pose.
367  */
369  /**
370  * Gets the axis pose of the last section, returning false if there is no
371  * such pose.
372  */
374  /**
375  * Updates the mutable set of polygons used in ray tracing.
376  */
377  void updatePolys() const;
378 
379  /** Evaluates the bounding box of this object (including possible children)
380  * in the coordinate frame of the object parent. */
381  void getBoundingBox(
382  mrpt::math::TPoint3D& bb_min,
383  mrpt::math::TPoint3D& bb_max) const override;
384 
385  private:
386  /**
387  * Updates the axis, transforming each point into a pose pointing to the
388  * next section.
389  */
390  void generatePoses(
391  const std::vector<mrpt::math::TPoint3D>& pIn,
393  /**
394  * Updates the mutable mesh.
395  */
396  void updateMesh() const;
397  /**
398  * Given a vector of polyhedrons, gets the starting and ending iterators to
399  * the section to be actually rendered.
400  */
401  void getMeshIterators(
402  const std::vector<TQuadrilateral>& m,
405 
406  public:
407  /**
408  * Basic constructor with default initialization.
409  */
411  : axis(),
412  generatrix(),
413  mesh(),
414  meshUpToDate(false),
415  polysUpToDate(false),
416  closed(false),
417  fullyVisible(true)
418  {
419  }
420  /**
421  * Constructor with axis and generatrix.
422  */
424  const std::vector<mrpt::math::TPoint3D>& a,
425  const std::vector<mrpt::math::TPoint3D>& g)
426  : generatrix(g),
427  mesh(),
428  meshUpToDate(false),
429  polysUpToDate(false),
430  closed(false),
431  fullyVisible(true)
432  {
433  generatePoses(a, axis);
434  }
435  /**
436  * Destructor.
437  */
439 };
440 }
441 }
442 #endif
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
3D polygon, inheriting from std::vector<TPoint3D>
This object represents any figure obtained by extruding any profile along a given axis.
void getClosedSection(size_t index, CPolyhedron::Ptr &poly) const
Get a polyhedron consisting of a single section of the cylinder.
std::vector< TQuadrilateral > mesh
Mutable object with mesh information, used to avoid repeated computations.
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...
void setGeneratrix(const std::vector< mrpt::math::TPoint3D > &g)
Set cylinder's profile.
bool getLastVisibleSectionPose(mrpt::poses::CPose3D &p)
Gets the axis pose of the last section, returning false if there is no such pose.
void setVisibleSections(size_t first, size_t last)
Sets which sections are visible.
std::vector< mrpt::math::TPoint3D > generatrix
Object's generatrix, that is, profile which will be extruded.
mrpt::math::CMatrixTemplate< mrpt::math::TPoint3D > pointsMesh
Mutable object with the cylinder's points, used to avoid repeated computations.
void getEnd(CPolyhedron::Ptr &poly) const
Get a polyhedron containing the ending point of the cylinder (its "base").
static CGeneralizedCylinder::Ptr Create(const std::vector< mrpt::math::TPoint3D > &axis, const std::vector< mrpt::math::TPoint3D > &generatrix)
Creation of generalized cylinder from axis and generatrix.
void setAllSectionsVisible()
Sets all sections visible.
void updatePolys() const
Updates the mutable set of polygons used in ray tracing.
void updateMesh() const
Updates the mutable mesh.
bool fullyVisible
Flag to determine whether the object is fully visible or only some sections are.
void getAxis(std::vector< mrpt::math::TPoint3D > &a) const
Get axis's spatial coordinates.
void generatePoses(const std::vector< mrpt::math::TPoint3D > &pIn, mrpt::aligned_containers< mrpt::poses::CPose3D >::vector_t &pOut)
Updates the axis, transforming each point into a pose pointing to the next section.
size_t lastSection
Last visible section, if fullyVisible is set to false.
void setAllSectionsInvisible(size_t pointer=0)
Hides all sections.
bool closed
Boolean variable which determines if the profile is closed at each section.
bool getFirstSectionPose(mrpt::poses::CPose3D &p)
Gets the axis pose of the first section, returning false if there is no such pose.
mrpt::aligned_containers< mrpt::poses::CPose3D >::vector_t axis
Cylinder's axis.
CGeneralizedCylinder()
Basic constructor with default initialization.
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Ray tracing.
void render_dl() const override
Render.
void generateSetOfPolygons(std::vector< mrpt::math::TPolygon3D > &res) const
Get the cylinder as a set of polygons in 3D.
bool getFirstVisibleSectionPose(mrpt::poses::CPose3D &p)
Gets the axis pose of the first visible section, returning false if there is no such pose.
bool polysUpToDate
Mutable flag telling whether ray tracing temporary data must be recalculated or not.
void getOrigin(CPolyhedron::Ptr &poly) const
Get a polyhedron containing the starting point of the cylinder (its "base").
void getVisibleSections(size_t &first, size_t &last) const
Gets the cylinder's visible sections.
void getClosedSection(size_t index1, size_t index2, CPolyhedron::Ptr &poly) const
Get a polyhedron consisting of a set of closed sections of the cylinder.
std::vector< mrpt::math::TPolygonWithPlane > polys
Mutable set of data used in ray tracing.
void removeVisibleSectionAtStart()
Removes a visible section from the start of the currently visible set.
void getMeshIterators(const std::vector< TQuadrilateral > &m, std::vector< TQuadrilateral >::const_iterator &begin, std::vector< TQuadrilateral >::const_iterator &end) const
Given a vector of polyhedrons, gets the starting and ending iterators to the section to be actually r...
bool meshUpToDate
Mutable flag which tells if recalculations are needed.
void setClosed(bool c=true)
Set whether each section is a closed polygon or not.
CGeneralizedCylinder(const std::vector< mrpt::math::TPoint3D > &a, const std::vector< mrpt::math::TPoint3D > &g)
Constructor with axis and generatrix.
void setAxis(const std::vector< mrpt::math::TPoint3D > &a)
Set the axis points.
void addVisibleSectionAtStart()
Adds another visible section at the start of the cylinder.
size_t firstSection
First visible section, if fullyVisible is set to false.
void removeVisibleSectionAtEnd()
Removes a visible section from the ending of the currently visible set.
size_t getNumberOfSections() const
Get the number of sections in this cylinder.
bool getLastSectionPose(mrpt::poses::CPose3D &p)
Gets the axis pose of the last section, returning false if there is no such pose.
size_t getVisibleSections() const
Get how many visible sections are in the cylinder.
void getAxis(mrpt::aligned_containers< mrpt::poses::CPose3D >::vector_t &a) const
Get axis, including angular coordinates.
bool isClosed() const
Returns true if each section is a closed polygon.
void getGeneratrix(std::vector< mrpt::math::TPoint3D > &g) const
Get cylinder's profile.
void addVisibleSectionAtEnd()
Adds another visible section at the end of the cylinder.
std::shared_ptr< CGeneralizedCylinder > Ptr
std::shared_ptr< CPolyhedron > Ptr
Definition: CPolyhedron.h:46
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)
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:89
const Scalar * const_iterator
Definition: eigen_plugins.h:27
EIGEN_STRONG_INLINE iterator begin()
Definition: eigen_plugins.h:29
GLuint res
Definition: glext.h:7268
const GLubyte * c
Definition: glext.h:6313
GLuint GLuint end
Definition: glext.h:3528
GLsizei const GLvoid * pointer
Definition: glext.h:3825
GLuint index
Definition: glext.h:4054
GLint * first
Definition: glext.h:3827
GLubyte g
Definition: glext.h:6279
GLfloat GLfloat p
Definition: glext.h:6305
GLubyte GLubyte GLubyte a
Definition: glext.h:6279
GLsizei const GLfloat * points
Definition: glext.h:5339
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
std::vector< TYPE1, Eigen::aligned_allocator< TYPE1 > > vector_t
Lightweight 3D point.
Auxiliary struct holding any quadrilateral, represented by foour points.
void getAsPolygonUnsafe(mrpt::math::TPolygon3D &vec) const
Given a polygon with 4 already positions allocated, this method fills it with the quadrilateral point...
TQuadrilateral(const T(&p)[4])
Construction from any array of four compatible objects.
TQuadrilateral(const mrpt::math::TPoint3D &p1, const mrpt::math::TPoint3D &p2, const mrpt::math::TPoint3D &p3, const mrpt::math::TPoint3D &p4)
Constructor from 4 points.
void calculateNormal()
Automatically compute a vector normal to this quadrilateral.



Page generated by Doxygen 1.9.1 for MRPT 1.9.9 Git: 63ea9d1f1 Thu Nov 23 00:06:53 2017 +0100 at mar 26 may 2026 12:19:29 CEST