9 #ifndef opengl_CPolyhedron_H
10 #define opengl_CPolyhedron_H
57 if (e.
v1==v1&&e.
v2==v2)
return true;
58 else return e.
v1==v2&&e.
v2==v1;
63 double length(
const std::vector<mrpt::math::TPoint3D> &vs)
const;
79 double area(
const std::vector<mrpt::math::TPoint3D> &vertices)
const;
116 static CPolyhedronPtr
Create(
const std::vector<mrpt::math::TPoint3D> &vertices,
const std::vector<std::vector<uint32_t> > &faces);
121 static CPolyhedronPtr
Create(
const std::vector<mrpt::math::TPoint3D> &vertices,
const std::vector<TPolyhedronFace> &faces);
126 static CPolyhedronPtr
Create(
const std::vector<mrpt::math::TPolygon3D> &polys);
322 static CPolyhedronPtr
CreateCubicPrism(
double x1,
double x2,
double y1,
double y2,
double z1,
double z2);
332 static CPolyhedronPtr
CreatePyramid(
const std::vector<mrpt::math::TPoint2D> &baseVertices,
double height);
337 static CPolyhedronPtr
CreateDoublePyramid(
const std::vector<mrpt::math::TPoint2D> &baseVertices,
double height1,
double height2);
343 static CPolyhedronPtr
CreateTruncatedPyramid(
const std::vector<mrpt::math::TPoint2D> &baseVertices,
double height,
double ratio);
348 static CPolyhedronPtr
CreateFrustum(
const std::vector<mrpt::math::TPoint2D> &baseVertices,
double height,
double ratio);
353 static CPolyhedronPtr
CreateCustomPrism(
const std::vector<mrpt::math::TPoint2D> &baseVertices,
double height);
358 static CPolyhedronPtr
CreateCustomAntiprism(
const std::vector<mrpt::math::TPoint2D> &bottomBase,
const std::vector<mrpt::math::TPoint2D> &topBase,
double height);
368 static CPolyhedronPtr
CreateBifrustum(
const std::vector<mrpt::math::TPoint2D> &baseVertices,
double height1,
double ratio1,
double height2,
double ratio2);
413 static CPolyhedronPtr
CreateRegularFrustum(uint32_t numBaseEdges,
double baseRadius,
double height,
double ratio);
418 static CPolyhedronPtr
CreateRegularBifrustum(uint32_t numBaseEdges,
double baseRadius,
double height1,
double ratio1,
double height2,
double ratio2);
423 static CPolyhedronPtr
CreateCupola(uint32_t numBaseEdges,
double edgeLength);
483 inline
void getVertices(std::vector<
mrpt::math::TPoint3D> &vertices)
const {
489 inline void getEdges(std::vector<TPolyhedronEdge> &edges)
const {
495 inline void getFaces(std::vector<TPolyhedronFace> &faces)
const {
502 return mVertices.size();
508 return mEdges.size();
514 return mFaces.size();
551 mLineWidth=lineWidth;
567 template<
class T>
inline static size_t getIntersection(
const CPolyhedronPtr &p1,
const CPolyhedronPtr &p2,T &container);
572 for (
size_t i=0;i<mVertices.size();i++)
if (edgesInVertex(i)!=facesInVertex(i))
return false;
617 CPolyhedronPtr
augment(
double height,
size_t numVertices)
const;
623 CPolyhedronPtr
augment(
bool direction=
false)
const;
629 CPolyhedronPtr
augment(
size_t numVertices,
bool direction=
false)
const;
634 CPolyhedronPtr
rotate(
double angle)
const;
640 CPolyhedronPtr
scale(
double factor)
const;
651 static std::vector<mrpt::math::TPoint2D>
generateBase(uint32_t numBaseEdges,
double baseRadius);
659 static void generateBase(uint32_t numBaseEdges,
double baseRadius,
double height,std::vector<mrpt::math::TPoint3D> &vec);
663 static void generateShiftedBase(uint32_t numBaseEdges,
double baseRadius,
double height,
double shift,std::vector<mrpt::math::TPoint3D> &vec);
675 static bool checkConsistence(
const std::vector<mrpt::math::TPoint3D> &vertices,
const std::vector<TPolyhedronFace> &faces);
687 inline CPolyhedron():mVertices(),mEdges(),mFaces(),mWireframe(false),mLineWidth(1),polygonsUpToDate(false) {}
691 inline CPolyhedron(
const std::vector<mrpt::math::TPoint3D> &vertices,
const std::vector<TPolyhedronFace> &faces,
bool doCheck=
true):mVertices(vertices),mEdges(),mFaces(faces),mWireframe(false),mLineWidth(1),polygonsUpToDate(false) {
692 if (doCheck)
if (!checkConsistence(vertices,faces))
throw std::logic_error(
"Face list accesses a vertex out of range");
694 if (!setNormal(*it,doCheck))
throw std::logic_error(
"Bad face specification");
699 static CPolyhedronPtr
CreateNoCheck(
const std::vector<mrpt::math::TPoint3D> &vertices,
const std::vector<TPolyhedronFace> &faces);
710 std::vector<mrpt::math::TPolygon3D> polys1,polys2;
711 p1->getSetOfPolygonsAbsolute(polys1);
712 p2->getSetOfPolygonsAbsolute(polys2);
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
#define MRPT_DECLARE_TTYPENAME_NAMESPACE(_TYPE, __NS)
This class represents arbitrary polyhedra.
static CPolyhedronPtr CreateTriakisTetrahedron(double radius)
Creates a triakis tetrahedron, dual to the truncated tetrahedron.
std::vector< TPolyhedronEdge > mEdges
List of polyhedron's edges.
bool polygonsUpToDate
Whether the set of actual polygons is up to date or not.
bool setNormal(TPolyhedronFace &f, bool doCheck=true)
Calculates the normal vector to a face.
CPolyhedronPtr rotate(double angle) const
Rotates a polyhedron around the Z axis a given amount of radians.
static CPolyhedronPtr 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...
static CPolyhedronPtr CreateTruncatedHexahedron(double radius)
Creates a truncated hexahedron, with six octogonal faces and eight triangular ones (see http://en....
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...
CPolyhedronPtr truncate(double factor) const
Truncates a polyhedron to a given factor.
static size_t getIntersection(const CPolyhedronPtr &p1, const CPolyhedronPtr &p2, T &container)
Gets the intersection of two polyhedra, either as a set or as a matrix of intersections.
static CPolyhedronPtr CreateFrustum(const std::vector< mrpt::math::TPoint2D > &baseVertices, double height, double ratio)
This is a synonym for CreateTruncatedPyramid.
CPolyhedronPtr augment(double height) const
Augments a polyhedron to a given height.
static CPolyhedronPtr CreateCuboctahedron(double radius)
Creates a cuboctahedron, consisting of six square faces and eight triangular ones (see http://en....
static CPolyhedronPtr CreateCatalanDoublePyramid(uint32_t numBaseEdges, double height)
Creates a double pyramid whose dual is exactly an archimedean prism.
static CPolyhedronPtr CreateRegularAntiprism(uint32_t numBaseEdges, double baseRadius, double height)
Creates an antiprism whose base is a regular polygon.
static CPolyhedronPtr CreateRandomPolyhedron(double radius)
Creates a random polyhedron from the static methods.
static CPolyhedronPtr CreateRhombicDodecahedron(double radius)
Creates a rhombic dodecahedron, dual to the cuboctahedron.
static CPolyhedronPtr 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 CPolyhedronPtr CreateArchimedeanRegularAntiprism(uint32_t numBaseEdges, double baseRadius)
Creates a regular antiprism whose lateral polygons are equilateral triangles, and so each face of its...
CPolyhedronPtr augment(double height, size_t numVertices) const
Augments a polyhedron to a given height.
static CPolyhedronPtr CreateRhombicTriacontahedron(double radius)
Creates a rhombic triacontahedron, dual to the icosidodecahedron.
void updatePolygons() const
Updates the mutable list of polygons used in rendering and ray tracing.
static CPolyhedronPtr CreateRegularDoublePyramid(uint32_t numBaseEdges, double baseRadius, double height1, double height2)
Creates a regular double pyramid whose base is a regular polygon.
static CPolyhedronPtr CreateDodecahedron(double radius)
Creates a regular dodecahedron (see http://en.wikipedia.org/wiki/Dodecahedron).
static CPolyhedronPtr 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.
double getLineWidth() const
Gets the wireframe lines width.
static CPolyhedronPtr 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...
std::vector< mrpt::math::TPoint3D > mVertices
List of vertices presents in the polyhedron.
size_t facesInVertex(size_t vertex) const
Returns how many faces converge in a given vertex.
uint32_t getNumberOfEdges() const
Gets the amount of edges.
bool isClosed() const
Returns true if the polygon is a completely closed object.
static CPolyhedronPtr Create(const std::vector< mrpt::math::TPoint3D > &vertices, const std::vector< TPolyhedronFace > &faces)
Creation of a polyhedron from its vertices and faces.
static CPolyhedronPtr CreateTruncatedOctahedron(double radius)
Creates a truncated octahedron, with eight hexagons and eight squares (see http://en....
static CPolyhedronPtr 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.
CPolyhedronPtr augment(bool direction=false) const
Augments a polyhedron, so that the resulting triangles are equilateral.
static CPolyhedronPtr 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 CPolyhedronPtr 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.
static CPolyhedronPtr 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.
std::vector< TPolyhedronFace > mFaces
List of polyhedron's faces.
static CPolyhedronPtr CreateCatalanTrapezohedron(uint32_t numBaseEdges, double height)
Creates a trapezohedron whose dual is exactly an archimedean antiprism.
void getEdges(std::vector< TPolyhedronEdge > &edges) const
Gets a list with the polyhedron's edges.
static CPolyhedronPtr CreateTetrakisHexahedron(double radius)
Creates a tetrakis hexahedron, dual to the truncated octahedron.
static CPolyhedronPtr CreateTetrahedron(double radius)
Creates a regular tetrahedron (see http://en.wikipedia.org/wiki/Tetrahedron).
CPolyhedronPtr augment(size_t numVertices, bool direction=false) const
Augments a polyhedron, so that the resulting triangles are equilateral; affects only faces with certa...
uint32_t getNumberOfFaces() const
Gets the amount of faces.
uint32_t getNumberOfVertices() const
Gets the amount of vertices.
void getEdgesLength(std::vector< double > &lengths) const
Gets a vector with each edge's length.
void getSetOfPolygonsAbsolute(std::vector< math::TPolygon3D > &vec) const
Gets the polyhedron as a set of polygons, with the pose transformation already applied.
void getCenter(mrpt::math::TPoint3D ¢er) const
Gets the center of the polyhedron.
static CPolyhedronPtr 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.
static CPolyhedronPtr CreateHexahedron(double radius)
Creates a regular cube, also called hexahedron (see http://en.wikipedia.org/wiki/Hexahedron).
bool isWireframe() const
Returns whether the polyhedron will be rendered as a wireframe object.
std::vector< mrpt::math::TPolygonWithPlane > tempPolygons
Mutable list of actual polygons, maintained for speed.
static CPolyhedronPtr CreateRegularFrustum(uint32_t numBaseEdges, double baseRadius, double height, double ratio)
This is a synonym for CreateRegularTruncatedPyramid.
static CPolyhedronPtr Create(const std::vector< mrpt::math::TPoint3D > &vertices, const std::vector< std::vector< uint32_t > > &faces)
Creation of a polyhedron from its vertices and faces.
static CPolyhedronPtr 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.
static CPolyhedronPtr CreatePentagonalRotunda(double radius)
Creates a pentagonal rotunda (half an icosidodecahedron), consisting of six pentagons,...
static CPolyhedronPtr 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.
void getFacesArea(std::vector< double > &areas) const
Gets a vector with each face's area.
static CPolyhedronPtr CreateRegularTruncatedPyramid(uint32_t numBaseEdges, double baseRadius, double height, double ratio)
Creates a regular truncated pyramid whose base is a regular polygon.
static CPolyhedronPtr CreateDeltoidalIcositetrahedron(double radius)
Creates a deltoidal icositetrahedron, dual to the rhombicuboctahedron.
void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const MRPT_OVERRIDE
Evaluates the bounding box of this object (including possible children) in the coordinate frame of th...
static CPolyhedronPtr CreateIcosidodecahedron(double radius, bool type=true)
Creates an icosidodecahedron, with 12 pentagons and 20 triangles (see http://en.wikipedia....
static CPolyhedronPtr CreateRhombicosidodecahedron(double radius)
Creates a rhombicosidodecahedron, consisting of 30 squares, 12 pentagons and 20 triangles (see http:/...
static CPolyhedronPtr 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.
void render_dl() const MRPT_OVERRIDE
Render.
static CPolyhedronPtr CreateOctahedron(double radius)
Creates a regular octahedron (see http://en.wikipedia.org/wiki/Octahedron).
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.
static CPolyhedronPtr CreateRegularPyramid(uint32_t numBaseEdges, double baseRadius, double height)
Creates a regular pyramid whose base is a regular polygon.
static CPolyhedronPtr CreateTruncatedTetrahedron(double radius)
Creates a truncated tetrahedron, consisting of four triangular faces and for hexagonal ones (see http...
static CPolyhedronPtr Create(const std::vector< mrpt::math::TPolygon3D > &polys)
Creation from a set of polygons.
static CPolyhedronPtr CreateRhombicuboctahedron(double radius, bool type=true)
Creates a rhombicuboctahedron, with 18 squares and 8 triangles (see http://en.wikipedia....
void getSetOfPolygons(std::vector< math::TPolygon3D > &vec) const
Gets the polyhedron as a set of polygons.
static CPolyhedronPtr CreateNoCheck(const std::vector< mrpt::math::TPoint3D > &vertices, const std::vector< TPolyhedronFace > &faces)
Creates a polyhedron without checking its correctness.
double mLineWidth
When displaying as wireframe object, this variable stores the width of the edges.
CPolyhedronPtr getDual() const
Given a polyhedron, creates its dual.
static void generateBase(uint32_t numBaseEdges, double baseRadius, double height, std::vector< mrpt::math::TPoint3D > &vec)
Generates a list of 3D vertices constituting a regular polygon, appending it to an existing vector.
CPolyhedron(const std::vector< mrpt::math::TPoint3D > &vertices, const std::vector< TPolyhedronFace > &faces, bool doCheck=true)
Basic constructor with a list of vertices and another of faces, checking for correctness.
void getFaces(std::vector< TPolyhedronFace > &faces) const
Gets a list with the polyhedron's faces.
static CPolyhedronPtr CreateTriakisOctahedron(double radius)
Creates a triakis octahedron, dual to the truncated hexahedron.
static CPolyhedronPtr CreateIcosahedron(double radius)
Creates a regular icosahedron (see http://en.wikipedia.org/wiki/Icosahedron).
static std::vector< mrpt::math::TPoint2D > generateBase(uint32_t numBaseEdges, double baseRadius)
Generates a list of 2D vertices constituting a regular polygon.
CPolyhedron()
Basic empty constructor.
static CPolyhedronPtr CreateTruncatedDodecahedron(double radius)
Creates a truncated dodecahedron, consisting of 12 dodecagons and 20 triangles (see http://en....
static void generateShiftedBase(uint32_t numBaseEdges, double baseRadius, double height, double shift, std::vector< mrpt::math::TPoint3D > &vec)
Generates a list of 3D vertices constituting a regular polygon conveniently shifted,...
static CPolyhedronPtr CreateTruncatedIcosahedron(double radius)
Creates a truncated icosahedron, consisting of 20 hexagons and 12 pentagons.
void makeConvexPolygons()
Recomputes polygons, if necessary, so that each one is convex.
CPolyhedronPtr cantellate(double factor) const
Cantellates a polyhedron to a given factor.
static CPolyhedronPtr CreateDeltoidalHexecontahedron(double radius)
Creates a deltoidal hexecontahedron, dual to the rhombicosidodecahedron.
static CPolyhedronPtr 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 CPolyhedronPtr CreateEmpty()
Creates an empty Polyhedron.
void setWireframe(bool enabled=true)
Sets whether the polyhedron will be rendered as a wireframe object.
virtual ~CPolyhedron()
Destructor.
CPolyhedronPtr scale(double factor) const
Scales a polyhedron to a given factor.
size_t edgesInVertex(size_t vertex) const
Returns how many edges converge in a given vertex.
void addEdges(const TPolyhedronFace &e)
Adds, to the existing list of edges, each edge in a given face.
double getVolume() const
Gets the polyhedron volume.
static CPolyhedronPtr CreateCupola(uint32_t numBaseEdges, double edgeLength)
Creates a cupola.
static CPolyhedronPtr CreateTriakisIcosahedron(double radius)
Creates a triakis icosahedron, dual to the truncated dodecahedron.
bool mWireframe
This flag determines whether the polyhedron will be displayed as a solid object or as a set of edges.
static CPolyhedronPtr CreateCubicPrism(const mrpt::math::TPoint3D &p1, const mrpt::math::TPoint3D &p2)
Creates a cubic prism, given two opposite vertices.
void setLineWidth(double lineWidth)
Sets the width used to render lines, when wireframe rendering is activated.
static CPolyhedronPtr CreatePentakisDodecahedron(double radius)
Creates a pentakis dodecahedron, dual to the truncated icosahedron.
A renderizable object suitable for rendering with OpenGL's display lists.
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated)
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
bool BASE_IMPEXP intersect(const TSegment3D &s1, const TSegment3D &s2, TObject3D &obj)
Gets the intersection between two 3D segments.
bool BASE_IMPEXP traceRay(const vector< TPolygonWithPlane > &vec, const mrpt::poses::CPose3D &pose, double &dist)
Fast ray tracing method using polygons' properties.
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
The namespace for 3D scene representation and rendering.
::mrpt::utils::CStream & operator>>(mrpt::utils::CStream &in, CAngularObservationMeshPtr &pObj)
class OPENGL_IMPEXP CPolyhedron
OPENGL_IMPEXP mrpt::utils::CStream & operator<<(mrpt::utils::CStream &out, const mrpt::opengl::CLight &o)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Struct used to store a polyhedron edge.
~TPolyhedronEdge()
Destructor.
uint32_t v2
Second vertex.
TPolyhedronEdge()
Default constructor.
bool operator==(const TPolyhedronEdge &e) const
Comparison agains another edge.
double length(const std::vector< mrpt::math::TPoint3D > &vs) const
Given a set of vertices, computes the length of the vertex.
Struct used to store a polyhedron face.
std::vector< uint32_t > vertices
Vector of indices to the vertex list.
TPolyhedronFace()
Fast default constructor.
~TPolyhedronFace()
Destructor.
double area(const std::vector< mrpt::math::TPoint3D > &vertices) const
Given a set of vertices, computes the area of this face.
void getCenter(const std::vector< mrpt::math::TPoint3D > &vertices, mrpt::math::TPoint3D &p) const
Given a set of vertices, get this face's center.