MRPT  2.0.4
CPolyhedron.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
11 #include <mrpt/math/geometry.h>
14 
15 namespace mrpt
16 {
17 namespace opengl
18 {
19 class CPolyhedron;
20 
21 /**
22  * This class represents arbitrary polyhedra. The class includes a set of
23  * static methods to create common polyhedrons. The class includes many methods
24  * to create standard polyhedra, not intended to be fast but to be simple. For
25  * example, the dodecahedron is not created efficiently: first, an icosahedron
26  * is created, and a duality operator is applied to it, which yields the
27  * dodecahedron. This way, code is much smaller, although much slower. This is
28  * not a big problem, since polyhedron creation does not usually take a
29  * significant amount of time (they are created once and rendered many times).
30  * Polyhedra information and models have been gotten from the Wikipedia,
31  * http://wikipedia.org
32  * \sa opengl::COpenGLScene
33  *
34  * <div align="center">
35  * <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px;
36  * border-style: solid;">
37  * <tr> <td> mrpt::opengl::CPolyhedron </td> <td> \image html
38  * preview_CPolyhedron.png </td> </tr>
39  * </table>
40  * </div>
41  *
42  * \ingroup mrpt_opengl_grp
43  */
46 {
48  public:
49  /** @name Renderizable shader API virtual methods
50  * @{ */
51  void render(const RenderContext& rc) const override;
52  void renderUpdateBuffers() const override;
53  void freeOpenGLResources() override
54  {
57  }
58 
59  virtual shader_list_t requiredShaders() const override
60  {
61  // May use up to two shaders (triangles and lines):
63  }
64  void onUpdateBuffers_Wireframe() override;
65  void onUpdateBuffers_Triangles() override;
66  /** @} */
67 
68  /**
69  * Struct used to store a polyhedron edge. The struct consists only of two
70  * vertex indices, used to access the polyhedron vertex list.
71  */
73  {
74  /**
75  * Vertices.
76  */
77  uint32_t v1 = 0, v2 = 0;
78  /**
79  * Default constructor. Initializes to garbage.
80  */
81  TPolyhedronEdge() = default;
82  /**
83  * Comparison agains another edge. Simmetry is taken into account.
84  */
85  bool operator==(const TPolyhedronEdge& e) const
86  {
87  if (e.v1 == v1 && e.v2 == v2)
88  return true;
89  else
90  return e.v1 == v2 && e.v2 == v1;
91  }
92  /**
93  * Given a set of vertices, computes the length of the vertex.
94  */
95  double length(const std::vector<mrpt::math::TPoint3D>& vs) const;
96  /**
97  * Destructor.
98  */
99  ~TPolyhedronEdge() = default;
100  };
101  /**
102  * Struct used to store a polyhedron face. Consists on a set of vertex
103  * indices and a normal vector.
104  */
106  {
107  /** Vector of indices to the vertex list. */
108  std::vector<uint32_t> vertices;
109  /** Normal vector. */
111  /** Fast default constructor. Initializes to garbage. */
113  /** Destructor. */
114  ~TPolyhedronFace() = default;
115  /** Given a set of vertices, computes the area of this face. */
116  double area(const std::vector<mrpt::math::TPoint3D>& vertices) const;
117  /** Given a set of vertices, get this face's center. */
118  void getCenter(
119  const std::vector<mrpt::math::TPoint3D>& vertices,
120  mrpt::math::TPoint3D& p) const;
121  };
122 
123  protected:
124  /**
125  * List of vertices presents in the polyhedron.
126  */
127  std::vector<mrpt::math::TPoint3D> m_Vertices;
128  /**
129  * List of polyhedron's edges.
130  */
131  std::vector<TPolyhedronEdge> m_Edges;
132  /**
133  * List of polyhedron's faces.
134  */
135  std::vector<TPolyhedronFace> m_Faces;
136  /**
137  * This flag determines whether the polyhedron will be displayed as a solid
138  * object or as a set of edges.
139  */
140  bool m_Wireframe{false};
141  /**
142  * Mutable list of actual polygons, maintained for speed.
143  */
144  mutable std::vector<mrpt::math::TPolygonWithPlane> tempPolygons;
145  /**
146  * Whether the set of actual polygons is up to date or not.
147  */
148  mutable bool polygonsUpToDate{false};
149 
150  public:
151  /** Evaluates the bounding box of this object (including possible children)
152  * in the coordinate frame of the object parent. */
153  void getBoundingBox(
155  mrpt::math::TPoint3D& bb_max) const override;
156 
157  // Static methods to create frequent polyhedra. More bizarre polyhedra are
158  // intended to be added in a near future.
159 
160  /** @name Platonic solids.
161  @{
162  */
163  /**
164  * Creates a regular tetrahedron (see
165  http://en.wikipedia.org/wiki/Tetrahedron). The tetrahedron is created as a
166  triangular pyramid whose edges and vertices are transitive.
167  * The tetrahedron is the dual to itself.
168  <p align="center"><img src="Tetrahedron.gif"></p>
169  * \sa
170  CreatePyramid,CreateJohnsonSolidWithConstantBase,CreateTruncatedTetrahedron
171  */
172  static CPolyhedron::Ptr CreateTetrahedron(double radius);
173  /**
174  * Creates a regular cube, also called hexahedron (see
175  http://en.wikipedia.org/wiki/Hexahedron). The hexahedron is created as a
176  cubic prism which transitive edges. Another ways to create it include:
177  <ul><li>Dual to an octahedron.</li><li>Parallelepiped with three
178  orthogonal, equally-lengthed vectors.</li><li>Triangular trapezohedron
179  with proper height.</li></ul>
180  <p align="center"><img src="Hexahedron.gif"></p>
181  * \sa
182  CreateOctahedron,getDual,CreateParallelepiped,CreateTrapezohedron,CreateTruncatedHexahedron,CreateTruncatedOctahedron,CreateCuboctahedron,CreateRhombicuboctahedron
183  */
184  static CPolyhedron::Ptr CreateHexahedron(double radius);
185  /**
186  * Creates a regular octahedron (see
187  http://en.wikipedia.org/wiki/Octahedron). The octahedron is created as a
188  square bipyramid whit transitive edges and vertices. Another ways to
189  create an octahedron are:
190  <ul><li>Dual to an hexahedron</li><li>Triangular antiprism with transitive
191  vertices.</li><li>Conveniently truncated tetrahedron.</li></ul>
192  <p align="center"><img src="Octahedron.gif"></p>
193  * \sa
194  CreateHexahedron,getDual,CreateArchimedeanAntiprism,CreateTetrahedron,truncate,CreateTruncatedOctahedron,CreateTruncatedHexahedron,CreateCuboctahedron,CreateRhombicuboctahedron
195  */
196  static CPolyhedron::Ptr CreateOctahedron(double radius);
197  /**
198  * Creates a regular dodecahedron (see
199  http://en.wikipedia.org/wiki/Dodecahedron). The dodecahedron is created as
200  the dual to an icosahedron.
201  <p align="center"><img src="Dodecahedron.gif"></p>
202  * \sa
203  CreateIcosahedron,getDual,CreateTruncatedDodecahedron,CreateTruncatedIcosahedron,CreateIcosidodecahedron,CreateRhombicosidodecahedron
204  */
205  static CPolyhedron::Ptr CreateDodecahedron(double radius);
206  /**
207  * Creates a regular icosahedron (see
208  http://en.wikipedia.org/wiki/Icosahedron). The icosahedron is created as a
209  gyroelongated pentagonal bipyramid with transitive edges, and it's the
210  dual to a dodecahedron.
211  <p align="center"><img src="Icosahedron.gif"></p>
212  * \sa
213  CreateJohnsonSolidWithConstantBase,CreateDodecahedron,getDual,CreateTruncatedIcosahedron,CreateTruncatedDodecahedron,CreateIcosidodecahedron,CreateRhombicosidodecahedron
214  */
215  static CPolyhedron::Ptr CreateIcosahedron(double radius);
216  /** @}
217  */
218 
219  /** @name Archimedean solids.
220  @{
221  */
222  /**
223  * Creates a truncated tetrahedron, consisting of four triangular faces and
224  for hexagonal ones (see
225  http://en.wikipedia.org/wiki/Truncated_tetrahedron). Its dual is the
226  triakis tetrahedron.
227  <p align="center"><img src="Truncatedtetrahedron.gif"></p>
228  * \sa CreateTetrahedron,CreateTriakisTetrahedron
229  */
230  static CPolyhedron::Ptr CreateTruncatedTetrahedron(double radius);
231  /**
232  * Creates a cuboctahedron, consisting of six square faces and eight
233  triangular ones (see http://en.wikipedia.org/wiki/Cuboctahedron). There
234  are several ways to create a cuboctahedron:
235  <ul><li>Hexahedron truncated to a certain extent.</li><li>Octahedron
236  truncated to a certain extent.</li><li>Cantellated
237  tetrahedron</li><li>Dual to a rhombic dodecahedron.</li></ul>
238  <p align="center"><img src="Cuboctahedron.gif"></p>
239  * \sa
240  CreateHexahedron,CreateOctahedron,truncate,CreateTetrahedron,cantellate,CreateRhombicuboctahedron,CreateRhombicDodecahedron,
241  */
242  static CPolyhedron::Ptr CreateCuboctahedron(double radius);
243  /**
244  * Creates a truncated hexahedron, with six octogonal faces and eight
245  triangular ones (see http://en.wikipedia.org/wiki/Truncated_hexahedron).
246  The truncated octahedron is dual to the triakis octahedron.
247  <p align="center"><img src="Truncatedhexahedron.gif"></p>
248  * \sa CreateHexahedron,CreateTriakisOctahedron
249  */
250  static CPolyhedron::Ptr CreateTruncatedHexahedron(double radius);
251  /**
252  * Creates a truncated octahedron, with eight hexagons and eight squares
253  (see http://en.wikipedia.org/wiki/Truncated_octahedron). It's the dual to
254  the tetrakis hexahedron.
255  <p align="center"><img src="Truncatedoctahedron.gif"></p>
256  * \sa CreateOctahedron,CreateTetrakisHexahedron
257  */
258  static CPolyhedron::Ptr CreateTruncatedOctahedron(double radius);
259  /**
260  * Creates a rhombicuboctahedron, with 18 squares and 8 triangles (see
261  http://en.wikipedia.org/wiki/Rhombicuboctahedron), calculated as an
262  elongated square bicupola. It can also be calculated as a cantellated
263  hexahedron or octahedron, and its dual is the deltoidal icositetrahedron.
264  * If the second argument is set to false, the lower cupola is rotated, so
265  that the objet created is an elongated square gyrobicupola (see
266  http://en.wikipedia.org/wiki/Elongated_square_gyrobicupola). This is not
267  an archimedean solid, but a Johnson one, since it hasn't got vertex
268  transitivity.
269  <p align="center"><img src="Rhombicuboctahedron.gif"></p>
270  * \sa
271  CreateJohnsonSolidWithConstantBase,CreateHexahedron,CreateOctahedron,cantellate,CreateCuboctahedron,CreateDeltoidalIcositetrahedron
272  */
274  double radius, bool type = true);
275  /**
276  * Creates an icosidodecahedron, with 12 pentagons and 20 triangles (see
277  http://en.wikipedia.org/wiki/Icosidodecahedron). Certain truncations of
278  either a dodecahedron or an icosahedron yield an icosidodecahedron.
279  * The dual of the icosidodecahedron is the rhombic triacontahedron.
280  * If the second argument is set to false, the lower rotunda is rotated. In
281  this case, the object created is a pentagonal orthobirotunda (see
282  http://en.wikipedia.org/wiki/Pentagonal_orthobirotunda). This object
283  presents symmetry against the XY plane and is not vertex transitive, so
284  it's a Johnson's solid.
285  <p align="center"><img src="Icosidodecahedron.gif"></p>
286  * \sa
287  CreateDodecahedron,CreateIcosahedron,truncate,CreateRhombicosidodecahedron,CreateRhombicTriacontahedron
288  */
290  double radius, bool type = true);
291  /**
292  * Creates a truncated dodecahedron, consisting of 12 dodecagons and 20
293  triangles (see http://en.wikipedia.org/wiki/Truncated_dodecahedron). The
294  truncated dodecahedron is the dual to the triakis icosahedron.
295  <p align="center"><img src="Truncateddodecahedron.gif"></p>
296  * \sa CreateDodecahedron,CreateTriakisIcosahedron
297  */
298  static CPolyhedron::Ptr CreateTruncatedDodecahedron(double radius);
299  /**
300  * Creates a truncated icosahedron, consisting of 20 hexagons and 12
301  pentagons. This object resembles a typical soccer ball (see
302  http://en.wikipedia.org/wiki/Truncated_icosahedron). The pentakis
303  dodecahedron is the dual to the truncated icosahedron.
304  <p align="center"><img src="Truncatedicosahedron.gif"></p>
305  * \sa CreateIcosahedron,CreatePentakisDodecahedron
306  */
307  static CPolyhedron::Ptr CreateTruncatedIcosahedron(double radius);
308  /**
309  * Creates a rhombicosidodecahedron, consisting of 30 squares, 12 pentagons
310  and 20 triangles (see
311  http://en.wikipedia.org/wiki/Rhombicosidodecahedron). This object can be
312  obtained as the cantellation of either a dodecahedron or an icosahedron.
313  The dual of the rhombicosidodecahedron is the deltoidal hexecontahedron.
314  <p align="center"><img src="Rhombicosidodecahedron.gif"></p>
315  * \sa
316  CreateDodecahedron,CreateIcosahedron,CreateIcosidodecahedron,CreateDeltoidalHexecontahedron
317  */
318  static CPolyhedron::Ptr CreateRhombicosidodecahedron(double radius);
319  /** @}
320  */
321 
322  /** @name Other Johnson solids.
323  @{
324  */
325  /**
326  * Creates a pentagonal rotunda (half an icosidodecahedron), consisting of
327  * six pentagons, ten triangles and a decagon (see
328  * http://en.wikipedia.org/wiki/Pentagonal_rotunda).
329  * \sa CreateIcosidodecahedron,CreateJohnsonSolidWithConstantBase
330  */
331  static CPolyhedron::Ptr CreatePentagonalRotunda(double radius);
332  /** @}
333  */
334 
335  /** @name Catalan solids.
336  @{
337  */
338  /**
339  * Creates a triakis tetrahedron, dual to the truncated tetrahedron. This
340  body consists of 12 isosceles triangles (see
341  http://en.wikipedia.org/wiki/Triakis_tetrahedron).
342  <p align="center"><img src="Triakistetrahedron.gif"></p>
343  * \sa CreateTruncatedTetrahedron
344  */
345  static CPolyhedron::Ptr CreateTriakisTetrahedron(double radius);
346 
347  /**
348  * Creates a rhombic dodecahedron, dual to the cuboctahedron. This body
349  consists of 12 rhombi (see
350  http://en.wikipedia.org/wiki/Rhombic_dodecahedron).
351  <p align="center"><img src="Rhombicdodecahedron.gif"></p>
352  * \sa CreateCuboctahedron
353  */
354  static CPolyhedron::Ptr CreateRhombicDodecahedron(double radius);
355 
356  /**
357  * Creates a triakis octahedron, dual to the truncated hexahedron. This
358  body consists of 24 isosceles triangles (see
359  http://en.wikipedia.org/wiki/Triakis_octahedron).
360  <p align="center"><img src="Triakisoctahedron.gif"></p>
361  * \sa CreateTruncatedHexahedron
362  */
363  static CPolyhedron::Ptr CreateTriakisOctahedron(double radius);
364 
365  /**
366  * Creates a tetrakis hexahedron, dual to the truncated octahedron. This
367  body consists of 24 isosceles triangles (see
368  http://en.wikipedia.org/wiki/Tetrakis_hexahedron).
369  <p align="center"><img src="Tetrakishexahedron.gif"></p>
370  * \sa CreateTruncatedOctahedron
371  */
372  static CPolyhedron::Ptr CreateTetrakisHexahedron(double radius);
373 
374  /**
375  * Creates a deltoidal icositetrahedron, dual to the rhombicuboctahedron.
376  This body consists of 24 kites (see
377  http://en.wikipedia.org/wiki/Deltoidal_icositetrahedron).
378  <p align="center"><img src="Deltoidalicositetrahedron.gif"></p>
379  * \sa CreateRhombicuboctahedron
380  */
382 
383  /**
384  * Creates a rhombic triacontahedron, dual to the icosidodecahedron. This
385  body consists of 30 rhombi (see
386  http://en.wikipedia.org/wiki/Rhombic_triacontahedron).
387  <p align="center"><img src="Rhombictriacontahedron.gif"></p>
388  * \sa CreateIcosidodecahedron
389  */
390  static CPolyhedron::Ptr CreateRhombicTriacontahedron(double radius);
391 
392  /**
393  * Creates a triakis icosahedron, dual to the truncated dodecahedron. This
394  body consists of 60 isosceles triangles
395  http://en.wikipedia.org/wiki/Triakis_icosahedron).
396  <p align="center"><img src="Triakisicosahedron.gif"></p>
397  * \sa CreateTruncatedDodecahedron
398  */
399  static CPolyhedron::Ptr CreateTriakisIcosahedron(double radius);
400 
401  /**
402  * Creates a pentakis dodecahedron, dual to the truncated icosahedron. This
403  body consists of 60 isosceles triangles (see
404  http://en.wikipedia.org/wiki/Pentakis_dodecahedron).
405  <p align="center"><img src="Pentakisdodecahedron.gif"></p>
406  * \sa CreateTruncatedIcosahedron
407  */
408  static CPolyhedron::Ptr CreatePentakisDodecahedron(double radius);
409 
410  /**
411  * Creates a deltoidal hexecontahedron, dual to the rhombicosidodecahedron.
412  This body consists of 60 kites (see
413  http://en.wikipedia.org/wiki/Deltoidal_hexecontahedron).
414  <p align="center"><img src="Deltoidalhexecontahedron.gif"></p>
415  * \sa CreateRhombicosidodecahedron
416  */
417  static CPolyhedron::Ptr CreateDeltoidalHexecontahedron(double radius);
418  /** @}
419  */
420 
421  /** @name Customizable polyhedra
422  @{
423  */
424  /**
425  * Creates a cubic prism, given the coordinates of two opposite vertices.
426  * Each edge will be parallel to one of the coordinate axes, although the
427  * orientation may change by assigning a pose to the object.
428  * \sa CreateCubicPrism(const mrpt::math::TPoint3D &,const
429  * mrpt::math::TPoint3D
430  * &),CreateParallelepiped,CreateCustomPrism,CreateRegularPrism,CreateArchimedeanRegularPrism
431  */
433  double x1, double x2, double y1, double y2, double z1, double z2);
434  /**
435  * Creates a cubic prism, given two opposite vertices.
436  * \sa
437  * CreateCubicPrism(double,double,double,double,double,double),CreateParallelepiped,CreateCustomPrism,CreateRegularPrism,CreateArchimedeanRegularPrism
438  */
440  const mrpt::math::TPoint3D& p1, const mrpt::math::TPoint3D& p2);
441  /**
442  * Creates a custom pyramid, using a set of 2D vertices which will lie on
443  * the XY plane.
444  * \sa
445  * CreateDoublePyramid,CreateFrustum,CreateBifrustum,CreateRegularPyramid
446  */
448  const std::vector<mrpt::math::TPoint2D>& baseVertices, double height);
449  /**
450  * Creates a double pyramid, using a set of 2D vertices which will lie on
451  * the XY plane. The second height is used with the downwards pointing
452  * pyramid, so that it will effectively point downwards if it's positive.
453  * \sa CreatePyramid,CreateBifrustum,CreateRegularDoublePyramid
454  */
456  const std::vector<mrpt::math::TPoint2D>& baseVertices, double height1,
457  double height2);
458  /**
459  * Creates a truncated pyramid, using a set of vertices which will lie on
460  * the XY plane.
461  * Do not try to use with a ratio equal to zero; use CreatePyramid instead.
462  * When using a ratio of 1, it will create a Prism.
463  * \sa CreatePyramid,CreateBifrustum
464  */
466  const std::vector<mrpt::math::TPoint2D>& baseVertices, double height,
467  double ratio);
468  /**
469  * This is a synonym for CreateTruncatedPyramid.
470  * \sa CreateTruncatedPyramid
471  */
473  const std::vector<mrpt::math::TPoint2D>& baseVertices, double height,
474  double ratio);
475  /**
476  * Creates a custom prism with vertical edges, given any base which will
477  * lie on the XY plane.
478  * \sa
479  * CreateCubicPrism,CreateCustomAntiprism,CreateRegularPrism,CreateArchimedeanRegularPrism
480  */
482  const std::vector<mrpt::math::TPoint2D>& baseVertices, double height);
483  /**
484  * Creates a custom antiprism, using two custom bases. For better results,
485  * the top base should be slightly rotated with respect to the bottom one.
486  * \sa
487  * CreateCustomPrism,CreateRegularAntiprism,CreateArchimedeanRegularAntiprism
488  */
490  const std::vector<mrpt::math::TPoint2D>& bottomBase,
491  const std::vector<mrpt::math::TPoint2D>& topBase, double height);
492  /**
493  * Creates a parallelepiped, given a base point and three vectors
494  * represented as points.
495  * \sa CreateCubicPrism
496  */
498  const mrpt::math::TPoint3D& base, const mrpt::math::TPoint3D& v1,
499  const mrpt::math::TPoint3D& v2, const mrpt::math::TPoint3D& v3);
500  /**
501  * Creates a bifrustum, or double truncated pyramid, given a base which
502  * will lie on the XY plane.
503  * \sa CreateFrustum,CreateDoublePyramid
504  */
506  const std::vector<mrpt::math::TPoint2D>& baseVertices, double height1,
507  double ratio1, double height2, double ratio2);
508  /**
509  * Creates a trapezohedron, consisting of 2*N kites, where N is the number
510  * of edges in the base. The base radius controls the polyhedron height,
511  * whilst the distance between bases affects the height.
512  * When the number of edges equals 3, the polyhedron is actually a
513  * parallelepiped, and it can even be a cube.
514  */
516  uint32_t numBaseEdges, double baseRadius, double basesDistance);
517  /**
518  * Creates an antiprism whose base is a regular polygon. The upper base is
519  * rotated \f$\frac\pi N\f$ with respect to the lower one, where N is the
520  * number of vertices in the base, and thus the lateral triangles are
521  * isosceles.
522  * \sa CreateCustomAntiprism,CreateArchimedeanRegularAntiprism
523  */
525  uint32_t numBaseEdges, double baseRadius, double height);
526  /**
527  * Creates a regular prism whose base is a regular polygon and whose edges
528  * are either parallel or perpendicular to the XY plane.
529  * \sa CreateCubicPrism,CreateCustomPrism,CreateArchimedeanRegularAntiprism
530  */
532  uint32_t numBaseEdges, double baseRadius, double height);
533  /**
534  * Creates a regular pyramid whose base is a regular polygon.
535  * \sa CreatePyramid
536  */
538  uint32_t numBaseEdges, double baseRadius, double height);
539  /**
540  * Creates a regular double pyramid whose base is a regular polygon.
541  * \sa CreateDoublePyramid
542  */
544  uint32_t numBaseEdges, double baseRadius, double height1,
545  double height2);
546  /**
547  * Creates a regular prism whose lateral area is comprised of squares, and
548  * so each face of its is a regular polygon. Due to vertex transitivity, the
549  * resulting object is always archimedean.
550  * \sa CreateRegularPrism,CreateCustomPrism
551  */
553  uint32_t numBaseEdges, double baseRadius);
554  /**
555  * Creates a regular antiprism whose lateral polygons are equilateral
556  * triangles, and so each face of its is a regular polygon. Due to vertex
557  * transitivity, the resulting object is always archimedean.
558  * \sa CreateRegularAntiprism,CreateCustomAntiprism
559  */
561  uint32_t numBaseEdges, double baseRadius);
562  /**
563  * Creates a regular truncated pyramid whose base is a regular polygon.
564  * \sa CreateTruncatedPyramid
565  */
567  uint32_t numBaseEdges, double baseRadius, double height, double ratio);
568  /**
569  * This is a synonym for CreateRegularTruncatedPyramid.
570  * \sa CreateRegularTruncatedPyramid
571  */
573  uint32_t numBaseEdges, double baseRadius, double height, double ratio);
574  /**
575  * Creates a bifrustum (double truncated pyramid) whose base is a regular
576  * polygon lying in the XY plane.
577  * \sa CreateBifrustum
578  */
580  uint32_t numBaseEdges, double baseRadius, double height1, double ratio1,
581  double height2, double ratio2);
582  /**
583  * Creates a cupola.
584  * \throw std::logic_error if the number of edges is odd or less than four.
585  */
587  uint32_t numBaseEdges, double edgeLength);
588  /**
589  * Creates a trapezohedron whose dual is exactly an archimedean antiprism.
590  * Creates a cube if numBaseEdges is equal to 3.
591  * \todo Actually resulting height is significantly higher than that passed
592  * to the algorithm.
593  * \sa CreateTrapezohedron,CreateArchimedeanRegularAntiprism,getDual
594  */
596  uint32_t numBaseEdges, double height);
597  /**
598  * Creates a double pyramid whose dual is exactly an archimedean prism.
599  * Creates an octahedron if numBaseEdges is equal to 4.
600  * \todo Actually resulting height is significantly higher than that passed
601  * to the algorithm.
602  * \sa CreateDoublePyramid,CreateArchimedeanRegularPrism,getDual
603  */
605  uint32_t numBaseEdges, double height);
606  /**
607  * Creates a series of concatenated solids (most of which are prismatoids)
608  whose base is a regular polygon with a given number of edges. Every face
609  of the resulting body will be a regular polygon, so it is a Johnson solid;
610  in special cases, it may be archimedean or even platonic.
611  * The shape of the body is defined by the string argument, which can
612  include one or more of the following:
613  <center><table>
614  <tr><td><b>String</b></td><td><b>Body</b></td><td><b>Restrictions</b></td></tr>
615  <tr><td>P+</td><td>Upward pointing pyramid</td><td>Must be the last
616  object, vertex number cannot surpass 5</td></tr>
617  <tr><td>P-</td><td>Downward pointing pyramid</td><td>Must be the first
618  object, vertex number cannot surpass 5</td></tr>
619  <tr><td>C+</td><td>Upward pointing cupola</td><td>Must be the last object,
620  vertex number must be an even number in the range 4-10.</td></tr>
621  <tr><td>C-</td><td>Downward pointing cupola</td><td>Must be the first
622  object, vertex number must be an even number in the range 4-10.</td></tr>
623  <tr><td>GC+</td><td>Upward pointing cupola, rotated</td><td>Must be the
624  last object, vertex number must be an even number in the range
625  4-10.</td></tr>
626  <tr><td>GC-</td><td>Downward pointing cupola, rotated</td><td>Must be the
627  first object, vertex number must be an even number in the range
628  4-10.</td></tr>
629  <tr><td>PR</td><td>Archimedean prism</td><td>Cannot abut other
630  prism</td></tr>
631  <tr><td>A</td><td>Archimedean antiprism</td><td>None</td></tr>
632  <tr><td>R+</td><td>Upward pointing rotunda</td><td>Must be the last
633  object, vertex number must be exactly 10</td></tr>
634  <tr><td>R-</td><td>Downward pointing rotunda</td><td>Must be the first
635  object, vertex number must be exactly 10</td></tr>
636  <tr><td>GR+</td><td>Upward pointing rotunda, rotated</td><td>Must be the
637  last object, vertex number must be exactly 10</td></tr>
638  <tr><td>GR-</td><td>Downward pointing rotunda</td><td>Must be the first
639  object, vertex number must be exactly 10</td></tr>
640  </table></center>
641  * Some examples of bodies are:
642  <center><table>
643  <tr><td><b>String</b></td><td><b>Vertices</b></td><td><b>Resulting
644  body</b></td></tr>
645  <tr><td>P+</td><td align="center">3</td><td>Tetrahedron</td></tr>
646  <tr><td>PR</td><td align="center">4</td><td>Hexahedron</td></tr>
647  <tr><td>P-P+</td><td align="center">4</td><td>Octahedron</td></tr>
648  <tr><td>A</td><td align="center">3</td><td>Octahedron</td></tr>
649  <tr><td>C+PRC-</td><td
650  align="center">8</td><td>Rhombicuboctahedron</td></tr>
651  <tr><td>P-AP+</td><td align="center">5</td><td>Icosahedron</td></tr>
652  <tr><td>R-R+</td><td align="center">10</td><td>Icosidodecahedron</td></tr>
653  </table></center>
654  */
656  uint32_t numBaseEdges, double baseRadius, const std::string& components,
657  size_t shifts = 0);
658  /** @}
659  */
660 
661  bool traceRay(const mrpt::poses::CPose3D& o, double& dist) const override;
662 
663  /**
664  * Gets a list with the polyhedron's vertices.
665  */
666  inline void getVertices(std::vector<mrpt::math::TPoint3D>& vertices) const
667  {
668  vertices = m_Vertices;
669  }
670  /**
671  * Gets a list with the polyhedron's edges.
672  */
673  inline void getEdges(std::vector<TPolyhedronEdge>& edges) const
674  {
675  edges = m_Edges;
676  }
677  /**
678  * Gets a list with the polyhedron's faces.
679  */
680  inline void getFaces(std::vector<TPolyhedronFace>& faces) const
681  {
682  faces = m_Faces;
683  }
684  /**
685  * Gets the amount of vertices.
686  */
687  inline uint32_t getNumberOfVertices() const { return m_Vertices.size(); }
688  /**
689  * Gets the amount of edges.
690  */
691  inline uint32_t getNumberOfEdges() const { return m_Edges.size(); }
692  /**
693  * Gets the amount of faces.
694  */
695  inline uint32_t getNumberOfFaces() const { return m_Faces.size(); }
696  /**
697  * Gets a vector with each edge's length.
698  */
699  void getEdgesLength(std::vector<double>& lengths) const;
700  /**
701  * Gets a vector with each face's area. Won't work properly if the polygons
702  * are not convex.
703  */
704  void getFacesArea(std::vector<double>& areas) const;
705  /**
706  * Gets the polyhedron volume. Won't work properly if the polyhedron is not
707  * convex.
708  */
709  double getVolume() const;
710  /**
711  * Returns whether the polyhedron will be rendered as a wireframe object.
712  */
713  inline bool isWireframe() const { return m_Wireframe; }
714  /**
715  * Sets whether the polyhedron will be rendered as a wireframe object.
716  */
717  inline void setWireframe(bool enabled = true)
718  {
719  m_Wireframe = enabled;
721  }
722  /**
723  * Gets the polyhedron as a set of polygons.
724  * \sa mrpt::math::TPolygon3D
725  */
726  void getSetOfPolygons(std::vector<math::TPolygon3D>& vec) const;
727  /**
728  * Gets the polyhedron as a set of polygons, with the pose transformation
729  * already applied.
730  * \sa mrpt::math::TPolygon3D,mrpt::poses::CPose3D
731  */
732  void getSetOfPolygonsAbsolute(std::vector<math::TPolygon3D>& vec) const;
733  /** Gets the intersection of two polyhedra, either as a set or as a matrix
734  * of intersections. Each intersection is represented by a TObject3D.
735  * \sa mrpt::math::TObject3D
736  */
737  template <class T>
738  inline static size_t getIntersection(
739  const CPolyhedron::Ptr& p1, const CPolyhedron::Ptr& p2, T& container);
740  /**
741  * Returns true if the polygon is a completely closed object.
742  */
743  inline bool isClosed() const
744  {
745  for (size_t i = 0; i < m_Vertices.size(); i++)
746  if (edgesInVertex(i) != facesInVertex(i)) return false;
747  return true;
748  }
749  /**
750  * Recomputes polygons, if necessary, so that each one is convex.
751  */
752  void makeConvexPolygons();
753  /**
754  * Gets the center of the polyhedron.
755  */
756  void getCenter(mrpt::math::TPoint3D& center) const;
757  /**
758  * Creates a random polyhedron from the static methods.
759  */
760  static CPolyhedron::Ptr CreateRandomPolyhedron(double radius);
761 
762  /** @name Polyhedron special operations.
763  @{
764  */
765  /**
766  * Given a polyhedron, creates its dual.
767  * \sa truncate,cantellate,augment
768  * \throw std::logic_error Can't get the dual to this polyhedron.
769  */
770  CPolyhedron::Ptr getDual() const;
771  /**
772  * Truncates a polyhedron to a given factor.
773  * \sa getDual,cantellate,augment
774  * \throw std::logic_error Polyhedron truncation results in skew polygons
775  * and thus it's impossible to perform.
776  */
777  CPolyhedron::Ptr truncate(double factor) const;
778  /**
779  * Cantellates a polyhedron to a given factor.
780  * \sa getDual,truncate,augment
781  */
782  CPolyhedron::Ptr cantellate(double factor) const;
783  /**
784  * Augments a polyhedron to a given height. This operation is roughly dual
785  * to the truncation: given a body P, the operation dtdP and aP yield
786  * resembling results.
787  * \sa getDual,truncate,cantellate
788  */
789  CPolyhedron::Ptr augment(double height) const;
790  /**
791  * Augments a polyhedron to a given height. This method only affects to
792  * faces with certain number of vertices.
793  * \sa augment(double) const
794  */
795  CPolyhedron::Ptr augment(double height, size_t numVertices) const;
796  /**
797  * Augments a polyhedron, so that the resulting triangles are equilateral.
798  * If the argument is true, triangles are "cut" from the polyhedron, instead
799  * of being added.
800  * \throw std::logic_error a non-regular face has been found.
801  * \sa augment(double) const
802  */
803  CPolyhedron::Ptr augment(bool direction = false) const;
804  /**
805  * Augments a polyhedron, so that the resulting triangles are equilateral;
806  * affects only faces with certain number of faces. If the second argument
807  * is true, triangles are "cut" from the polyhedron.
808  * \throw std::logic_error a non-regular face has been found.
809  * \sa augment(double) const
810  */
811  CPolyhedron::Ptr augment(size_t numVertices, bool direction = false) const;
812  /**
813  * Rotates a polyhedron around the Z axis a given amount of radians. In
814  *some cases, this operation may be necessary to view the symmetry between
815  *related objects.
816  * \sa scale
817  */
818  CPolyhedron::Ptr rotate(double angle) const;
819  /**
820  * Scales a polyhedron to a given factor.
821  * \throw std::logic_error factor is not a strictly positive number.
822  * \sa rotate
823  */
824  CPolyhedron::Ptr scale(double factor) const;
825  /** @}
826  */
827  /**
828  * Updates the mutable list of polygons used in rendering and ray tracing.
829  */
830  void updatePolygons() const;
831 
832  private:
833  /**
834  * Generates a list of 2D vertices constituting a regular polygon.
835  */
836  static std::vector<mrpt::math::TPoint2D> generateBase(
837  uint32_t numBaseEdges, double baseRadius);
838  /**
839  * Generates a list of 2D vertices constituting a regular polygon, with an
840  * angle shift which makes it suitable for antiprisms.
841  */
842  static std::vector<mrpt::math::TPoint2D> generateShiftedBase(
843  uint32_t numBaseEdges, double baseRadius);
844  /**
845  * Generates a list of 3D vertices constituting a regular polygon,
846  * appending it to an existing vector.
847  */
848  static void generateBase(
849  uint32_t numBaseEdges, double baseRadius, double height,
850  std::vector<mrpt::math::TPoint3D>& vec);
851  /**
852  * Generates a list of 3D vertices constituting a regular polygon
853  * conveniently shifted, appending it to an existing vector.
854  */
855  static void generateShiftedBase(
856  uint32_t numBaseEdges, double baseRadius, double height, double shift,
857  std::vector<mrpt::math::TPoint3D>& vec);
858  /**
859  * Calculates the normal vector to a face.
860  */
861  bool setNormal(TPolyhedronFace& f, bool doCheck = true);
862  /**
863  * Adds, to the existing list of edges, each edge in a given face.
864  */
865  void addEdges(const TPolyhedronFace& e);
866  /**
867  * Checks whether a set of faces is suitable for a set of vertices.
868  */
869  static bool checkConsistence(
870  const std::vector<mrpt::math::TPoint3D>& vertices,
871  const std::vector<TPolyhedronFace>& faces);
872  /**
873  * Returns how many edges converge in a given vertex.
874  */
875  size_t edgesInVertex(size_t vertex) const;
876  /**
877  * Returns how many faces converge in a given vertex.
878  */
879  size_t facesInVertex(size_t vertex) const;
880 
881  public:
882  /**
883  * Basic empty constructor.
884  */
885  inline CPolyhedron() : m_Vertices(), m_Edges(), m_Faces() {}
886  /**
887  * Basic constructor with a list of vertices and another of faces, checking
888  * for correctness.
889  */
890  inline CPolyhedron(
891  const std::vector<mrpt::math::TPoint3D>& vertices,
892  const std::vector<TPolyhedronFace>& faces, bool doCheck = true)
893  : m_Vertices(vertices),
894  m_Edges(),
895  m_Faces(faces),
896  m_Wireframe(false),
897  polygonsUpToDate(false)
898  {
899  InitFromVertAndFaces(vertices, faces, doCheck);
900  }
901  inline void InitFromVertAndFaces(
902  const std::vector<mrpt::math::TPoint3D>& vertices,
903  const std::vector<TPolyhedronFace>& faces, bool doCheck = true)
904  {
905  if (doCheck && !checkConsistence(vertices, faces))
906  throw std::logic_error("Face list accesses a vertex out of range");
907  for (auto& mFace : m_Faces)
908  {
909  if (!setNormal(mFace, doCheck))
910  throw std::logic_error("Bad face specification");
911  addEdges(mFace);
912  }
913  }
914 
915  CPolyhedron(const std::vector<math::TPolygon3D>& polys);
916 
917  CPolyhedron(
918  const std::vector<mrpt::math::TPoint3D>& vertices,
919  const std::vector<std::vector<uint32_t>>& faces);
920 
921  /** Creates a polyhedron without checking its correctness. */
923  const std::vector<mrpt::math::TPoint3D>& vertices,
924  const std::vector<TPolyhedronFace>& faces);
925  /** Creates an empty Polyhedron. */
926  static CPolyhedron::Ptr CreateEmpty();
927  /** Destructor. */
928  ~CPolyhedron() override = default;
929 };
930 
931 // Implemented after the definition of Smart::Ptrs in the _POST() macro above.
932 template <class T>
934  const CPolyhedron::Ptr& p1, const CPolyhedron::Ptr& p2, T& container)
935 {
936  std::vector<mrpt::math::TPolygon3D> polys1, polys2;
937  p1->getSetOfPolygonsAbsolute(polys1);
938  p2->getSetOfPolygonsAbsolute(polys2);
939  return mrpt::math::intersect(polys1, polys2, container);
940 }
941 
942 /**
943  * Reads a polyhedron edge from a binary stream.
944  */
947 /**
948  * Writes a polyhedron edge to a binary stream.
949  */
952 /**
953  * Reads a polyhedron face from a binary stream.
954  */
957 /**
958  * Writes a polyhedron face to a binary stream.
959  */
962 } // namespace opengl
963 namespace typemeta
964 {
965 // Specialization must occur in the same namespace
966 MRPT_DECLARE_TTYPENAME_NAMESPACE(CPolyhedron::TPolyhedronEdge, mrpt::opengl)
967 MRPT_DECLARE_TTYPENAME_NAMESPACE(CPolyhedron::TPolyhedronFace, mrpt::opengl)
968 } // namespace typemeta
969 } // namespace mrpt
static CPolyhedron::Ptr CreateEmpty()
Creates an empty Polyhedron.
static CPolyhedron::Ptr CreateRhombicuboctahedron(double radius, bool type=true)
Creates a rhombicuboctahedron, with 18 squares and 8 triangles (see http://en.wikipedia.org/wiki/Rhombicuboctahedron), calculated as an elongated square bicupola.
static CPolyhedron::Ptr CreateBifrustum(const std::vector< mrpt::math::TPoint2D > &baseVertices, double height1, double ratio1, double height2, double ratio2)
Creates a bifrustum, or double truncated pyramid, given a base which will lie on the XY plane...
static CPolyhedron::Ptr CreateTrapezohedron(uint32_t numBaseEdges, double baseRadius, double basesDistance)
Creates a trapezohedron, consisting of 2*N kites, where N is the number of edges in the base...
#define MRPT_DECLARE_TTYPENAME_NAMESPACE(_TYPE, __NS)
Declares a typename to be "namespace::type".
Definition: TTypeName.h:119
static CPolyhedron::Ptr CreateRhombicTriacontahedron(double radius)
Creates a rhombic triacontahedron, dual to the icosidodecahedron.
static CPolyhedron::Ptr CreateIcosidodecahedron(double radius, bool type=true)
Creates an icosidodecahedron, with 12 pentagons and 20 triangles (see http://en.wikipedia.org/wiki/Icosidodecahedron).
void addEdges(const TPolyhedronFace &e)
Adds, to the existing list of edges, each edge in a given face.
~CPolyhedron() override=default
Destructor.
void render(const RenderContext &rc) const override
Implements the rendering of 3D objects in each class derived from CRenderizable.
size_t facesInVertex(size_t vertex) const
Returns how many faces converge in a given vertex.
virtual shader_list_t requiredShaders() const override
Returns the ID of the OpenGL shader program required to render this class.
Definition: CPolyhedron.h:59
mrpt::serialization::CArchive & operator>>(mrpt::serialization::CArchive &in, CPolyhedron::TPolyhedronEdge &o)
Reads a polyhedron edge from a binary stream.
uint32_t getNumberOfVertices() const
Gets the amount of vertices.
Definition: CPolyhedron.h:682
TPolyhedronEdge()=default
Default constructor.
size_t edgesInVertex(size_t vertex) const
Returns how many edges converge in a given vertex.
double getVolume() const
Gets the polyhedron volume.
static std::vector< mrpt::math::TPoint2D > generateShiftedBase(uint32_t numBaseEdges, double baseRadius)
Generates a list of 2D vertices constituting a regular polygon, with an angle shift which makes it su...
void freeOpenGLResources() override
Free opengl buffers.
void onUpdateBuffers_Triangles() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
void InitFromVertAndFaces(const std::vector< mrpt::math::TPoint3D > &vertices, const std::vector< TPolyhedronFace > &faces, bool doCheck=true)
Definition: CPolyhedron.h:895
void notifyChange() const
Call to enable calling renderUpdateBuffers() before the next render() rendering iteration.
static CPolyhedron::Ptr CreateCuboctahedron(double radius)
Creates a cuboctahedron, consisting of six square faces and eight triangular ones (see http://en...
void makeConvexPolygons()
Recomputes polygons, if necessary, so that each one is convex.
void getFaces(std::vector< TPolyhedronFace > &faces) const
Gets a list with the polyhedron&#39;s faces.
Definition: CPolyhedron.h:675
static CPolyhedron::Ptr CreateTriakisIcosahedron(double radius)
Creates a triakis icosahedron, dual to the truncated dodecahedron.
COpenGLScene::Ptr & operator<<(COpenGLScene::Ptr &s, const CRenderizable::Ptr &r)
Inserts an openGL object into a scene.
Definition: COpenGLScene.h:252
CPolyhedron::Ptr getDual() const
Given a polyhedron, creates its dual.
static CPolyhedron::Ptr CreateCatalanDoublePyramid(uint32_t numBaseEdges, double height)
Creates a double pyramid whose dual is exactly an archimedean prism.
bool m_Wireframe
This flag determines whether the polyhedron will be displayed as a solid object or as a set of edges...
Definition: CPolyhedron.h:140
mrpt::math::TVector3D normal
Normal vector.
Definition: CPolyhedron.h:110
CPolyhedron::Ptr rotate(double angle) const
Rotates a polyhedron around the Z axis a given amount of radians.
static CPolyhedron::Ptr CreateTetrakisHexahedron(double radius)
Creates a tetrakis hexahedron, dual to the truncated octahedron.
static CPolyhedron::Ptr CreateIcosahedron(double radius)
Creates a regular icosahedron (see http://en.wikipedia.org/wiki/Icosahedron).
static CPolyhedron::Ptr CreateRegularPrism(uint32_t numBaseEdges, double baseRadius, double height)
Creates a regular prism whose base is a regular polygon and whose edges are either parallel or perpen...
static CPolyhedron::Ptr CreateArchimedeanRegularAntiprism(uint32_t numBaseEdges, double baseRadius)
Creates a regular antiprism whose lateral polygons are equilateral triangles, and so each face of its...
Renderizable generic renderer for objects using the triangles shader.
std::vector< TPolyhedronFace > m_Faces
List of polyhedron&#39;s faces.
Definition: CPolyhedron.h:135
static CPolyhedron::Ptr CreateCubicPrism(double x1, double x2, double y1, double y2, double z1, double z2)
Creates a cubic prism, given the coordinates of two opposite vertices.
std::vector< TPolyhedronEdge > m_Edges
List of polyhedron&#39;s edges.
Definition: CPolyhedron.h:131
std::vector< shader_id_t > shader_list_t
A list of shader IDs.
Definition: Shader.h:26
static CPolyhedron::Ptr CreateCupola(uint32_t numBaseEdges, double edgeLength)
Creates a cupola.
This class represents arbitrary polyhedra.
Definition: CPolyhedron.h:44
static CPolyhedron::Ptr CreateTriakisTetrahedron(double radius)
Creates a triakis tetrahedron, dual to the truncated tetrahedron.
Context for calls to render()
static CPolyhedron::Ptr CreateJohnsonSolidWithConstantBase(uint32_t numBaseEdges, double baseRadius, const std::string &components, size_t shifts=0)
Creates a series of concatenated solids (most of which are prismatoids) whose base is a regular polyg...
CPolyhedron::Ptr cantellate(double factor) const
Cantellates a polyhedron to a given factor.
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Simulation of ray-trace, given a pose.
static CPolyhedron::Ptr CreateTetrahedron(double radius)
Creates a regular tetrahedron (see http://en.wikipedia.org/wiki/Tetrahedron).
static CPolyhedron::Ptr CreateCatalanTrapezohedron(uint32_t numBaseEdges, double height)
Creates a trapezohedron whose dual is exactly an archimedean antiprism.
static CPolyhedron::Ptr CreateTruncatedPyramid(const std::vector< mrpt::math::TPoint2D > &baseVertices, double height, double ratio)
Creates a truncated pyramid, using a set of vertices which will lie on the XY plane.
static CPolyhedron::Ptr CreateTruncatedDodecahedron(double radius)
Creates a truncated dodecahedron, consisting of 12 dodecagons and 20 triangles (see http://en...
std::vector< uint32_t > vertices
Vector of indices to the vertex list.
Definition: CPolyhedron.h:108
std::vector< mrpt::math::TPolygonWithPlane > tempPolygons
Mutable list of actual polygons, maintained for speed.
Definition: CPolyhedron.h:144
static CPolyhedron::Ptr CreateRandomPolyhedron(double radius)
Creates a random polyhedron from the static methods.
uint32_t getNumberOfEdges() const
Gets the amount of edges.
Definition: CPolyhedron.h:686
static CPolyhedron::Ptr CreateFrustum(const std::vector< mrpt::math::TPoint2D > &baseVertices, double height, double ratio)
This is a synonym for CreateTruncatedPyramid.
static CPolyhedron::Ptr CreateRhombicosidodecahedron(double radius)
Creates a rhombicosidodecahedron, consisting of 30 squares, 12 pentagons and 20 triangles (see http:/...
static CPolyhedron::Ptr CreatePentagonalRotunda(double radius)
Creates a pentagonal rotunda (half an icosidodecahedron), consisting of six pentagons, ten triangles and a decagon (see http://en.wikipedia.org/wiki/Pentagonal_rotunda).
Struct used to store a polyhedron face.
Definition: CPolyhedron.h:105
void getSetOfPolygons(std::vector< math::TPolygon3D > &vec) const
Gets the polyhedron as a set of polygons.
static CPolyhedron::Ptr CreateTruncatedOctahedron(double radius)
Creates a truncated octahedron, with eight hexagons and eight squares (see http://en.wikipedia.org/wiki/Truncated_octahedron).
static constexpr shader_id_t WIREFRAME
static CPolyhedron::Ptr CreatePyramid(const std::vector< mrpt::math::TPoint2D > &baseVertices, double height)
Creates a custom pyramid, using a set of 2D vertices which will lie on the XY plane.
static CPolyhedron::Ptr CreateRegularPyramid(uint32_t numBaseEdges, double baseRadius, double height)
Creates a regular pyramid whose base is a regular polygon.
void getCenter(const std::vector< mrpt::math::TPoint3D > &vertices, mrpt::math::TPoint3D &p) const
Given a set of vertices, get this face&#39;s center.
double area(const std::vector< mrpt::math::TPoint3D > &vertices) const
Given a set of vertices, computes the area of this face.
CPolyhedron()
Basic empty constructor.
Definition: CPolyhedron.h:879
bool isWireframe() const
Returns whether the polyhedron will be rendered as a wireframe object.
Definition: CPolyhedron.h:708
Struct used to store a polyhedron edge.
Definition: CPolyhedron.h:72
bool operator==(const TPolyhedronEdge &e) const
Comparison agains another edge.
Definition: CPolyhedron.h:85
static CPolyhedron::Ptr CreateTriakisOctahedron(double radius)
Creates a triakis octahedron, dual to the truncated hexahedron.
static CPolyhedron::Ptr CreateOctahedron(double radius)
Creates a regular octahedron (see http://en.wikipedia.org/wiki/Octahedron).
void setWireframe(bool enabled=true)
Sets whether the polyhedron will be rendered as a wireframe object.
Definition: CPolyhedron.h:712
static std::vector< mrpt::math::TPoint2D > generateBase(uint32_t numBaseEdges, double baseRadius)
Generates a list of 2D vertices constituting a regular polygon.
TPolyhedronFace()
Fast default constructor.
Definition: CPolyhedron.h:112
static CPolyhedron::Ptr CreateParallelepiped(const mrpt::math::TPoint3D &base, const mrpt::math::TPoint3D &v1, const mrpt::math::TPoint3D &v2, const mrpt::math::TPoint3D &v3)
Creates a parallelepiped, given a base point and three vectors represented as points.
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 onUpdateBuffers_Wireframe() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
CPolyhedron::Ptr scale(double factor) const
Scales a polyhedron to a given factor.
static constexpr shader_id_t TRIANGLES
static CPolyhedron::Ptr CreateCustomAntiprism(const std::vector< mrpt::math::TPoint2D > &bottomBase, const std::vector< mrpt::math::TPoint2D > &topBase, double height)
Creates a custom antiprism, using two custom bases.
static CPolyhedron::Ptr CreateTruncatedTetrahedron(double radius)
Creates a truncated tetrahedron, consisting of four triangular faces and for hexagonal ones (see http...
void freeOpenGLResources() override
Free opengl buffers.
Definition: CPolyhedron.h:53
static CPolyhedron::Ptr CreateRegularAntiprism(uint32_t numBaseEdges, double baseRadius, double height)
Creates an antiprism whose base is a regular polygon.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
std::shared_ptr< mrpt::opengl ::CPolyhedron > Ptr
Definition: CPolyhedron.h:47
bool polygonsUpToDate
Whether the set of actual polygons is up to date or not.
Definition: CPolyhedron.h:148
bool setNormal(TPolyhedronFace &f, bool doCheck=true)
Calculates the normal vector to a face.
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:54
void updatePolygons() const
Updates the mutable list of polygons used in rendering and ray tracing.
static CPolyhedron::Ptr CreateRhombicDodecahedron(double radius)
Creates a rhombic dodecahedron, dual to the cuboctahedron.
static CPolyhedron::Ptr CreateRegularDoublePyramid(uint32_t numBaseEdges, double baseRadius, double height1, double height2)
Creates a regular double pyramid whose base is a regular polygon.
uint32_t getNumberOfFaces() const
Gets the amount of faces.
Definition: CPolyhedron.h:690
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:85
mrpt::vision::TStereoCalibResults out
static CPolyhedron::Ptr CreateRegularBifrustum(uint32_t numBaseEdges, double baseRadius, double height1, double ratio1, double height2, double ratio2)
Creates a bifrustum (double truncated pyramid) whose base is a regular polygon lying in the XY plane...
static size_t getIntersection(const CPolyhedron::Ptr &p1, const CPolyhedron::Ptr &p2, T &container)
Gets the intersection of two polyhedra, either as a set or as a matrix of intersections.
Definition: CPolyhedron.h:933
double length(const std::vector< mrpt::math::TPoint3D > &vs) const
Given a set of vertices, computes the length of the vertex.
static CPolyhedron::Ptr CreateNoCheck(const std::vector< mrpt::math::TPoint3D > &vertices, const std::vector< TPolyhedronFace > &faces)
Creates a polyhedron without checking its correctness.
Renderizable generic renderer for objects using the wireframe shader.
static CPolyhedron::Ptr CreateTruncatedIcosahedron(double radius)
Creates a truncated icosahedron, consisting of 20 hexagons and 12 pentagons.
static CPolyhedron::Ptr CreateDodecahedron(double radius)
Creates a regular dodecahedron (see http://en.wikipedia.org/wiki/Dodecahedron).
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
bool isClosed() const
Returns true if the polygon is a completely closed object.
Definition: CPolyhedron.h:738
static CPolyhedron::Ptr CreateRegularTruncatedPyramid(uint32_t numBaseEdges, double baseRadius, double height, double ratio)
Creates a regular truncated pyramid whose base is a regular polygon.
const auto bb_max
CPolyhedron::Ptr truncate(double factor) const
Truncates a polyhedron to a given factor.
static CPolyhedron::Ptr CreateArchimedeanRegularPrism(uint32_t numBaseEdges, double baseRadius)
Creates a regular prism whose lateral area is comprised of squares, and so each face of its is a regu...
void renderUpdateBuffers() const override
Called whenever m_outdatedBuffers is true: used to re-generate OpenGL vertex buffers, etc.
static CPolyhedron::Ptr CreateDeltoidalHexecontahedron(double radius)
Creates a deltoidal hexecontahedron, dual to the rhombicosidodecahedron.
static CPolyhedron::Ptr CreateHexahedron(double radius)
Creates a regular cube, also called hexahedron (see http://en.wikipedia.org/wiki/Hexahedron).
#define DEFINE_SERIALIZABLE(class_name, NS)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
void getEdgesLength(std::vector< double > &lengths) const
Gets a vector with each edge&#39;s length.
static CPolyhedron::Ptr CreateRegularFrustum(uint32_t numBaseEdges, double baseRadius, double height, double ratio)
This is a synonym for CreateRegularTruncatedPyramid.
const auto bb_min
static bool checkConsistence(const std::vector< mrpt::math::TPoint3D > &vertices, const std::vector< TPolyhedronFace > &faces)
Checks whether a set of faces is suitable for a set of vertices.
void getCenter(mrpt::math::TPoint3D &center) const
Gets the center of the polyhedron.
void getFacesArea(std::vector< double > &areas) const
Gets a vector with each face&#39;s area.
std::vector< mrpt::math::TPoint3D > m_Vertices
List of vertices presents in the polyhedron.
Definition: CPolyhedron.h:127
void freeOpenGLResources() override
Free opengl buffers.
static CPolyhedron::Ptr CreatePentakisDodecahedron(double radius)
Creates a pentakis dodecahedron, dual to the truncated icosahedron.
void getVertices(std::vector< mrpt::math::TPoint3D > &vertices) const
Gets a list with the polyhedron&#39;s vertices.
Definition: CPolyhedron.h:661
void getEdges(std::vector< TPolyhedronEdge > &edges) const
Gets a list with the polyhedron&#39;s edges.
Definition: CPolyhedron.h:668
bool intersect(const TSegment3D &s1, const TSegment3D &s2, TObject3D &obj)
Gets the intersection between two 3D segments.
Definition: geometry.cpp:617
static CPolyhedron::Ptr CreateDeltoidalIcositetrahedron(double radius)
Creates a deltoidal icositetrahedron, dual to the rhombicuboctahedron.
static CPolyhedron::Ptr CreateCustomPrism(const std::vector< mrpt::math::TPoint2D > &baseVertices, double height)
Creates a custom prism with vertical edges, given any base which will lie on the XY plane...
static CPolyhedron::Ptr CreateDoublePyramid(const std::vector< mrpt::math::TPoint2D > &baseVertices, double height1, double height2)
Creates a double pyramid, using a set of 2D vertices which will lie on the XY plane.
CPolyhedron::Ptr augment(double height) const
Augments a polyhedron to a given height.
static CPolyhedron::Ptr CreateTruncatedHexahedron(double radius)
Creates a truncated hexahedron, with six octogonal faces and eight triangular ones (see http://en...
void getSetOfPolygonsAbsolute(std::vector< math::TPolygon3D > &vec) const
Gets the polyhedron as a set of polygons, with the pose transformation already applied.



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020