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