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