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-2018, Individual contributors, see AUTHORS file |
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  */
44  void calculateNormal();
45
46  public:
47  /**
49  */
51  /**
52  * Normal vector.
53  */
54  double normal;
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 = points;
63  vec = points;
64  vec = points;
65  vec = points;
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 = p1;
75  points = p2;
76  points = p3;
77  points = p4;
79  }
80  /**
81  * Construction from any array of four compatible objects.
82  */
83  template <class T>
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. */
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  */
174  {
175  a = axis;
176  }
177  /**
178  * Set the axis points.
179  */
180  inline void setAxis(const std::vector<mrpt::math::TPoint3D>& a)
181  {
182  generatePoses(a, axis);
183  meshUpToDate = false;
184  fullyVisible = true;
186  }
187  /**
188  * Get cylinder's profile.
189  */
190  inline void getGeneratrix(std::vector<mrpt::math::TPoint3D>& g) const
191  {
192  g = generatrix;
193  }
194  /**
195  * Set cylinder's profile.
196  */
197  inline void setGeneratrix(const std::vector<mrpt::math::TPoint3D>& g)
198  {
199  generatrix = g;
200  meshUpToDate = false;
202  }
203  /**
204  * Returns true if each section is a closed polygon.
205  */
206  inline bool isClosed() const { return closed; }
207  /**
208  * Set whether each section is a closed polygon or not.
209  */
210  inline void setClosed(bool c = true)
211  {
212  closed = c;
213  meshUpToDate = false;
215  }
216  /**
217  * Get a polyhedron containing the starting point of the cylinder (its
218  * "base").
219  * \sa getEnd,mrpt::opengl::CPolyhedron
220  */
221  void getOrigin(CPolyhedron::Ptr& poly) const;
222  /**
223  * Get a polyhedron containing the ending point of the cylinder (its
224  * "base").
225  * \sa getOrigin,mrpt::opengl::CPolyhedron
226  */
227  void getEnd(CPolyhedron::Ptr& poly) const;
228  /**
229  * Get the cylinder as a set of polygons in 3D.
230  * \sa mrpt::math::TPolygon3D
231  */
232  void generateSetOfPolygons(std::vector<mrpt::math::TPolygon3D>& res) const;
233  /**
234  * Get a polyhedron consisting of a set of closed sections of the cylinder.
235  * \sa mrpt::opengl::CPolyhedron
236  */
237  void getClosedSection(
238  size_t index1, size_t index2, CPolyhedron::Ptr& poly) const;
239  /**
240  * Get a polyhedron consisting of a single section of the cylinder.
241  * \sa mrpt::opengl::CPolyhedron
242  */
243  inline void getClosedSection(size_t index, CPolyhedron::Ptr& poly) const
244  {
245  getClosedSection(index, index, poly);
246  }
247  /**
248  * Get the number of sections in this cylinder.
249  */
250  inline size_t getNumberOfSections() const
251  {
252  return axis.size() ? (axis.size() - 1) : 0;
253  }
254  /**
255  * Get how many visible sections are in the cylinder.
256  */
257  inline size_t getVisibleSections() const
258  {
261  }
262  /**
263  * Gets the cylinder's visible sections.
264  */
265  void getVisibleSections(size_t& first, size_t& last) const
266  {
267  if (fullyVisible)
268  {
269  first = 0;
270  last = getNumberOfSections();
271  }
272  else
273  {
275  last = lastSection;
276  }
277  }
278  /**
279  * Sets all sections visible.
280  */
281  inline void setAllSectionsVisible()
282  {
283  fullyVisible = true;
285  }
286  /**
287  * Hides all sections.
288  */
289  inline void setAllSectionsInvisible(size_t pointer = 0)
290  {
291  fullyVisible = false;
295  }
296  /**
297  * Sets which sections are visible.
298  * \throw std::logic_error on wrongly defined bounds.
299  */
300  inline void setVisibleSections(size_t first, size_t last)
301  {
302  fullyVisible = false;
303  if (first > last || last > getNumberOfSections())
304  throw std::logic_error("Wrong bound definition");
306  lastSection = last;
308  }
309  /**
310  * Adds another visible section at the start of the cylinder. The cylinder
311  * must have an invisble section to display.
312  * \throw std::logic_error if there is no section to add to the displaying
313  * set.
314  * \sa
316  */
318  {
319  if (fullyVisible || firstSection == 0)
320  throw std::logic_error("No more sections");
321  firstSection--;
323  }
324  /**
325  * Adds another visible section at the end of the cylinder. The cylinder
326  * must have an invisible section to display.
327  * \throw std::logic_error if there is no section to add to the displaying
328  * set.
329  * \sa
331  */
333  {
335  throw std::logic_error("No more sections");
336  lastSection++;
338  }
339  /**
340  * Removes a visible section from the start of the currently visible set.
341  * \throw std::logic_error if there are no visible sections.
342  * \sa
344  */
346  /**
347  * Removes a visible section from the ending of the currently visible set.
348  * \throw std::logic_error when there is no such section.
349  * \sa
351  */
353  /**
354  * Gets the axis pose of the first section, returning false if there is no
355  * such pose.
356  */
358  /**
359  * Gets the axis pose of the last section, returning false if there is no
360  * such pose.
361  */
363  /**
364  * Gets the axis pose of the first visible section, returning false if
365  * there is no such pose.
366  */
368  /**
369  * Gets the axis pose of the last section, returning false if there is no
370  * such pose.
371  */
373  /**
374  * Updates the mutable set of polygons used in ray tracing.
375  */
376  void updatePolys() const;
377
378  /** Evaluates the bounding box of this object (including possible children)
379  * in the coordinate frame of the object parent. */
380  void getBoundingBox(
381  mrpt::math::TPoint3D& bb_min,
382  mrpt::math::TPoint3D& bb_max) const override;
383
384  private:
385  /**
386  * Updates the axis, transforming each point into a pose pointing to the
387  * next section.
388  */
389  void generatePoses(
390  const std::vector<mrpt::math::TPoint3D>& pIn,
392  /**
393  * Updates the mutable mesh.
394  */
395  void updateMesh() const;
396  /**
397  * Given a vector of polyhedrons, gets the starting and ending iterators to
398  * the section to be actually rendered.
399  */
400  void getMeshIterators(
404
405  public:
406  /**
407  * Basic constructor with default initialization.
408  */
410  : axis(),
411  generatrix(),
412  mesh(),
413  meshUpToDate(false),
414  polysUpToDate(false),
415  closed(false),
416  fullyVisible(true)
417  {
418  }
419  /**
420  * Constructor with axis and generatrix.
421  */
423  const std::vector<mrpt::math::TPoint3D>& a,
424  const std::vector<mrpt::math::TPoint3D>& g)
425  : generatrix(g),
426  mesh(),
427  meshUpToDate(false),
428  polysUpToDate(false),
429  closed(false),
430  fullyVisible(true)
431  {
432  generatePoses(a, axis);
433  }
434  /**
435  * Destructor.
436  */
438 };
439 } // namespace opengl
440 } // namespace mrpt
441 #endif
void generateSetOfPolygons(std::vector< mrpt::math::TPolygon3D > &res) const
Get the cylinder as a set of polygons in 3D.
void calculateNormal()
Automatically compute a vector normal to this quadrilateral.
void generatePoses(const std::vector< mrpt::math::TPoint3D > &pIn, mrpt::aligned_std_vector< mrpt::poses::CPose3D > &pOut)
Updates the axis, transforming each point into a pose pointing to the next section.
void setAllSectionsVisible()
Sets all sections visible.
void getOrigin(CPolyhedron::Ptr &poly) const
Get a polyhedron containing the starting point of the cylinder (its "base").
void getAsPolygonUnsafe(mrpt::math::TPolygon3D &vec) const
Given a polygon with 4 already positions allocated, this method fills it with the quadrilateral point...
GLsizei const GLvoid * pointer
Definition: glext.h:3825
void getEnd(CPolyhedron::Ptr &poly) const
Get a polyhedron containing the ending point of the cylinder (its "base").
bool getFirstSectionPose(mrpt::poses::CPose3D &p)
Gets the axis pose of the first section, returning false if there is no such pose.
void setClosed(bool c=true)
Set whether each section is a closed polygon or not.
GLint * first
Definition: glext.h:3827
size_t getNumberOfSections() const
Get the number of sections in this cylinder.
void removeVisibleSectionAtStart()
Removes a visible section from the start of the currently visible set.
bool fullyVisible
Flag to determine whether the object is fully visible or only some sections are.
static Ptr Create(Args &&... args)
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...
EIGEN_STRONG_INLINE iterator begin()
Definition: eigen_plugins.h:29
Adds another visible section at the start of the cylinder.
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
Mutable object with mesh information, used to avoid repeated computations.
bool meshUpToDate
Mutable flag which tells if recalculations are needed.
Given a vector of polyhedrons, gets the starting and ending iterators to the section to be actually r...
std::vector< T, mrpt::aligned_allocator_cpp11< T > > aligned_std_vector
bool getLastSectionPose(mrpt::poses::CPose3D &p)
Gets the axis pose of the last section, returning false if there is no such pose. ...
CGeneralizedCylinder(const std::vector< mrpt::math::TPoint3D > &a, const std::vector< mrpt::math::TPoint3D > &g)
Constructor with axis and generatrix.
void getClosedSection(size_t index, CPolyhedron::Ptr &poly) const
Get a polyhedron consisting of a single section of the cylinder.
void removeVisibleSectionAtEnd()
Removes a visible section from the ending of the currently visible set.
GLsizei const GLfloat * points
Definition: glext.h:5339
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
void render_dl() const override
Render.
bool closed
Boolean variable which determines if the profile is closed at each section.
void setVisibleSections(size_t first, size_t last)
Sets which sections are visible.
void getGeneratrix(std::vector< mrpt::math::TPoint3D > &g) const
Get cylinder&#39;s profile.
GLuint index
Definition: glext.h:4054
const GLubyte * c
Definition: glext.h:6313
void setGeneratrix(const std::vector< mrpt::math::TPoint3D > &g)
Set cylinder&#39;s profile.
GLuint GLuint end
Definition: glext.h:3528
GLubyte g
Definition: glext.h:6279
void setAllSectionsInvisible(size_t pointer=0)
Hides all sections.
void getVisibleSections(size_t &first, size_t &last) const
Gets the cylinder&#39;s visible sections.
bool getFirstVisibleSectionPose(mrpt::poses::CPose3D &p)
Gets the axis pose of the first visible section, returning false if there is no such pose...
mrpt::math::CMatrixTemplate< mrpt::math::TPoint3D > pointsMesh
Mutable object with the cylinder&#39;s points, used to avoid repeated computations.
std::vector< mrpt::math::TPolygonWithPlane > polys
Mutable set of data used in ray tracing.
bool polysUpToDate
Mutable flag telling whether ray tracing temporary data must be recalculated or not.
void setAxis(const std::vector< mrpt::math::TPoint3D > &a)
Set the axis points.
void getAxis(std::vector< mrpt::math::TPoint3D > &a) const
Get axis&#39;s spatial coordinates.
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...
size_t lastSection
Last visible section, if fullyVisible is set to false.
This object represents any figure obtained by extruding any profile along a given axis...
size_t getVisibleSections() const
Get how many visible sections are in the cylinder.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
void updateMesh() const
std::vector< mrpt::math::TPoint3D > generatrix
Object&#39;s generatrix, that is, profile which will be extruded.
mrpt::aligned_std_vector< mrpt::poses::CPose3D > axis
Cylinder&#39;s axis.
void updatePolys() const
Updates the mutable set of polygons used in ray tracing.
Construction from any array of four compatible objects.
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.
bool isClosed() const
Returns true if each section is a closed polygon.
CGeneralizedCylinder()
Basic constructor with default initialization.
void getAxis(mrpt::aligned_std_vector< mrpt::poses::CPose3D > &a) const
Get axis, including angular coordinates.
bool getLastVisibleSectionPose(mrpt::poses::CPose3D &p)
Gets the axis pose of the last section, returning false if there is no such pose. ...
GLuint res
Definition: glext.h:7268
Lightweight 3D point.
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.
Auxiliary struct holding any quadrilateral, represented by foour points.
Adds another visible section at the end of the cylinder.
GLubyte GLubyte GLubyte a
Definition: glext.h:6279
GLfloat GLfloat p
Definition: glext.h:6305
const Scalar * const_iterator
Definition: eigen_plugins.h:27
3D polygon, inheriting from std::vector<TPoint3D>
size_t firstSection
First visible section, if fullyVisible is set to false.
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Ray tracing.

 Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019 