9 #ifndef opengl_CPolyhedron_H
10 #define opengl_CPolyhedron_H
79 double length(
const std::vector<mrpt::math::TPoint3D>& vs)
const;
100 double area(
const std::vector<mrpt::math::TPoint3D>&
vertices)
const;
103 const std::vector<mrpt::math::TPoint3D>&
vertices,
263 double radius,
bool type =
true);
279 double radius,
bool type =
true);
422 double x1,
double x2,
double y1,
double y2,
double z1,
double z2);
437 const std::vector<mrpt::math::TPoint2D>& baseVertices,
double height);
445 const std::vector<mrpt::math::TPoint2D>& baseVertices,
double height1,
455 const std::vector<mrpt::math::TPoint2D>& baseVertices,
double height,
462 const std::vector<mrpt::math::TPoint2D>& baseVertices,
double height,
471 const std::vector<mrpt::math::TPoint2D>& baseVertices,
double height);
479 const std::vector<mrpt::math::TPoint2D>& bottomBase,
480 const std::vector<mrpt::math::TPoint2D>& topBase,
double height);
495 const std::vector<mrpt::math::TPoint2D>& baseVertices,
double height1,
496 double ratio1,
double height2,
double ratio2);
505 uint32_t numBaseEdges,
double baseRadius,
double basesDistance);
533 uint32_t numBaseEdges,
double baseRadius,
double height1,
542 uint32_t numBaseEdges,
double baseRadius);
550 uint32_t numBaseEdges,
double baseRadius);
556 uint32_t numBaseEdges,
double baseRadius,
double height,
double ratio);
562 uint32_t numBaseEdges,
double baseRadius,
double height,
double ratio);
569 uint32_t numBaseEdges,
double baseRadius,
double height1,
double ratio1,
570 double height2,
double ratio2);
576 uint32_t numBaseEdges,
double edgeLength);
663 inline void getVertices(std::vector<mrpt::math::TPoint3D>& vertices)
const
670 inline void getEdges(std::vector<TPolyhedronEdge>& edges)
const
677 inline void getFaces(std::vector<TPolyhedronFace>& faces)
const
755 for (
size_t i = 0; i <
mVertices.size(); i++)
847 uint32_t numBaseEdges,
double baseRadius);
853 uint32_t numBaseEdges,
double baseRadius);
860 std::vector<mrpt::math::TPoint3D>& vec);
866 uint32_t numBaseEdges,
double baseRadius,
double height,
double shift,
867 std::vector<mrpt::math::TPoint3D>& vec);
871 bool setNormal(TPolyhedronFace& f,
bool doCheck =
true);
875 void addEdges(
const TPolyhedronFace& e);
880 const std::vector<mrpt::math::TPoint3D>& vertices,
881 const std::vector<TPolyhedronFace>& faces);
909 const std::vector<mrpt::math::TPoint3D>& vertices,
910 const std::vector<TPolyhedronFace>& faces,
bool doCheck =
true)
921 const std::vector<mrpt::math::TPoint3D>& vertices,
922 const std::vector<TPolyhedronFace>& faces,
bool doCheck =
true)
925 throw std::logic_error(
"Face list accesses a vertex out of range");
930 throw std::logic_error(
"Bad face specification");
935 CPolyhedron(
const std::vector<math::TPolygon3D>& polys);
938 const std::vector<mrpt::math::TPoint3D>& vertices,
939 const std::vector<std::vector<uint32_t>>& faces);
943 const std::vector<mrpt::math::TPoint3D>& vertices,
944 const std::vector<TPolyhedronFace>& faces);
956 std::vector<mrpt::math::TPolygon3D> polys1, polys2;
957 p1->getSetOfPolygonsAbsolute(polys1);
958 p2->getSetOfPolygonsAbsolute(polys2);
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
#define MRPT_DECLARE_TTYPENAME_NAMESPACE(_TYPE, __NS)
This class represents arbitrary polyhedra.
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...
std::vector< TPolyhedronEdge > mEdges
List of polyhedron's edges.
CPolyhedron::Ptr scale(double factor) const
Scales a polyhedron to a given factor.
bool polygonsUpToDate
Whether the set of actual polygons is up to date or not.
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 CreateRegularTruncatedPyramid(uint32_t numBaseEdges, double baseRadius, double height, double ratio)
Creates a regular truncated pyramid whose base is a regular polygon.
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 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.
void getFacesArea(std::vector< double > &areas) const
Gets a vector with each face's area.
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.
static CPolyhedron::Ptr CreateRhombicTriacontahedron(double radius)
Creates a rhombic triacontahedron, dual to the icosidodecahedron.
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 CPolyhedron::Ptr CreateTriakisIcosahedron(double radius)
Creates a triakis icosahedron, dual to the truncated dodecahedron.
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 CreateDeltoidalHexecontahedron(double radius)
Creates a deltoidal hexecontahedron, dual to the rhombicosidodecahedron.
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.
static CPolyhedron::Ptr CreateRegularFrustum(uint32_t numBaseEdges, double baseRadius, double height, double ratio)
This is a synonym for CreateRegularTruncatedPyramid.
void getCenter(mrpt::math::TPoint3D ¢er) const
Gets the center of the polyhedron.
static CPolyhedron::Ptr CreateIcosidodecahedron(double radius, bool type=true)
Creates an icosidodecahedron, with 12 pentagons and 20 triangles (see http://en.wikipedia....
static CPolyhedron::Ptr CreateTriakisOctahedron(double radius)
Creates a triakis octahedron, dual to the truncated hexahedron.
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Ray trace.
double getLineWidth() const
Gets the wireframe lines width.
static CPolyhedron::Ptr CreateRhombicuboctahedron(double radius, bool type=true)
Creates a rhombicuboctahedron, with 18 squares and 8 triangles (see http://en.wikipedia....
void InitFromVertAndFaces(const std::vector< mrpt::math::TPoint3D > &vertices, const std::vector< TPolyhedronFace > &faces, bool doCheck=true)
std::vector< mrpt::math::TPoint3D > mVertices
List of vertices presents in the polyhedron.
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.
void getEdgesLength(std::vector< double > &lengths) const
Gets a vector with each edge's length.
CPolyhedron::Ptr truncate(double factor) const
Truncates a polyhedron to a given factor.
uint32_t getNumberOfEdges() const
Gets the amount of edges.
bool isClosed() const
Returns true if the polygon is a completely closed object.
void addEdges(const TPolyhedronFace &e)
Adds, to the existing list of edges, each edge in a given face.
std::shared_ptr< CPolyhedron > Ptr
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 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.
CPolyhedron::Ptr augment(double height) const
Augments a polyhedron to a given height.
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.
static CPolyhedron::Ptr CreateRhombicosidodecahedron(double radius)
Creates a rhombicosidodecahedron, consisting of 30 squares, 12 pentagons and 20 triangles (see http:/...
static CPolyhedron::Ptr CreateTruncatedHexahedron(double radius)
Creates a truncated hexahedron, with six octogonal faces and eight triangular ones (see http://en....
void updatePolygons() const
Updates the mutable list of polygons used in rendering and ray tracing.
std::vector< TPolyhedronFace > mFaces
List of polyhedron's faces.
static CPolyhedron::Ptr CreateCupola(uint32_t numBaseEdges, double edgeLength)
Creates a cupola.
CPolyhedron::Ptr cantellate(double factor) const
Cantellates a polyhedron to a given factor.
void getEdges(std::vector< TPolyhedronEdge > &edges) const
Gets a list with the polyhedron's edges.
static CPolyhedron::Ptr CreateTetrakisHexahedron(double radius)
Creates a tetrakis hexahedron, dual to the truncated octahedron.
static std::vector< mrpt::math::TPoint2D > generateBase(uint32_t numBaseEdges, double baseRadius)
Generates a list of 2D vertices constituting a regular polygon.
static CPolyhedron::Ptr CreateEmpty()
Creates an empty Polyhedron.
uint32_t getNumberOfFaces() const
Gets the amount of faces.
uint32_t getNumberOfVertices() const
Gets the amount of vertices.
static CPolyhedron::Ptr CreateIcosahedron(double radius)
Creates a regular icosahedron (see http://en.wikipedia.org/wiki/Icosahedron).
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 CreateDodecahedron(double radius)
Creates a regular dodecahedron (see http://en.wikipedia.org/wiki/Dodecahedron).
bool isWireframe() const
Returns whether the polyhedron will be rendered as a wireframe object.
static CPolyhedron::Ptr CreateHexahedron(double radius)
Creates a regular cube, also called hexahedron (see http://en.wikipedia.org/wiki/Hexahedron).
size_t facesInVertex(size_t vertex) const
Returns how many faces converge in a given vertex.
std::vector< mrpt::math::TPolygonWithPlane > tempPolygons
Mutable list of actual polygons, maintained for speed.
static CPolyhedron::Ptr CreateTruncatedDodecahedron(double radius)
Creates a truncated dodecahedron, consisting of 12 dodecagons and 20 triangles (see http://en....
CPolyhedron::Ptr rotate(double angle) const
Rotates a polyhedron around the Z axis a given amount of radians.
static CPolyhedron::Ptr CreateTruncatedIcosahedron(double radius)
Creates a truncated icosahedron, consisting of 20 hexagons and 12 pentagons.
static CPolyhedron::Ptr CreateTetrahedron(double radius)
Creates a regular tetrahedron (see http://en.wikipedia.org/wiki/Tetrahedron).
void render_dl() const override
Render.
void getVertices(std::vector< mrpt::math::TPoint3D > &vertices) const
Gets a list with the polyhedron's vertices.
void makeConvexPolygons()
Recomputes polygons, if necessary, so that each one is convex.
static CPolyhedron::Ptr CreateRhombicDodecahedron(double radius)
Creates a rhombic dodecahedron, dual to the cuboctahedron.
static CPolyhedron::Ptr CreateCuboctahedron(double radius)
Creates a cuboctahedron, consisting of six square faces and eight triangular ones (see http://en....
void getSetOfPolygons(std::vector< math::TPolygon3D > &vec) const
Gets the polyhedron as a set of polygons.
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.
static CPolyhedron::Ptr CreateTriakisTetrahedron(double radius)
Creates a triakis tetrahedron, dual to the truncated tetrahedron.
static CPolyhedron::Ptr CreateRegularPyramid(uint32_t numBaseEdges, double baseRadius, double height)
Creates a regular pyramid whose base is a regular polygon.
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 CreateTruncatedOctahedron(double radius)
Creates a truncated octahedron, with eight hexagons and eight squares (see http://en....
static CPolyhedron::Ptr CreateRandomPolyhedron(double radius)
Creates a random polyhedron from the static methods.
size_t edgesInVertex(size_t vertex) const
Returns how many edges converge in a given vertex.
bool setNormal(TPolyhedronFace &f, bool doCheck=true)
Calculates the normal vector to a face.
static CPolyhedron::Ptr CreateTruncatedTetrahedron(double radius)
Creates a truncated tetrahedron, consisting of four triangular faces and for hexagonal ones (see http...
double mLineWidth
When displaying as wireframe object, this variable stores the width of the edges.
static CPolyhedron::Ptr CreatePentagonalRotunda(double radius)
Creates a pentagonal rotunda (half an icosidodecahedron), consisting of six pentagons,...
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 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...
static CPolyhedron::Ptr CreateRegularDoublePyramid(uint32_t numBaseEdges, double baseRadius, double height1, double height2)
Creates a regular double pyramid whose base is a regular polygon.
static CPolyhedron::Ptr CreatePentakisDodecahedron(double radius)
Creates a pentakis dodecahedron, dual to the truncated icosahedron.
static CPolyhedron::Ptr CreateCatalanTrapezohedron(uint32_t numBaseEdges, double height)
Creates a trapezohedron whose dual is exactly an archimedean antiprism.
static CPolyhedron::Ptr CreateFrustum(const std::vector< mrpt::math::TPoint2D > &baseVertices, double height, double ratio)
This is a synonym for CreateTruncatedPyramid.
CPolyhedron()
Basic empty constructor.
static CPolyhedron::Ptr CreateCatalanDoublePyramid(uint32_t numBaseEdges, double height)
Creates a double pyramid whose dual is exactly an archimedean prism.
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...
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 CreateRegularAntiprism(uint32_t numBaseEdges, double baseRadius, double height)
Creates an antiprism whose base is a regular polygon.
void setWireframe(bool enabled=true)
Sets whether the polyhedron will be rendered as a wireframe object.
double getVolume() const
Gets the polyhedron volume.
virtual ~CPolyhedron()
Destructor.
CPolyhedron::Ptr getDual() const
Given a polyhedron, creates its dual.
void getSetOfPolygonsAbsolute(std::vector< math::TPolygon3D > &vec) const
Gets the polyhedron as a set of polygons, with the pose transformation already applied.
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...
static CPolyhedron::Ptr CreateOctahedron(double radius)
Creates a regular octahedron (see http://en.wikipedia.org/wiki/Octahedron).
bool mWireframe
This flag determines whether the polyhedron will be displayed as a solid object or as a set of edges.
void setLineWidth(double lineWidth)
Sets the width used to render lines, when wireframe rendering is activated.
static CPolyhedron::Ptr CreateDeltoidalIcositetrahedron(double radius)
Creates a deltoidal icositetrahedron, dual to the rhombicuboctahedron.
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)
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
GLenum GLenum GLuint components
GLuint GLuint GLsizei GLenum type
GLfloat GLfloat GLfloat v2
GLfloat GLfloat GLfloat GLfloat v3
GLenum GLsizei GLsizei height
GLsizei const GLchar ** string
bool intersect(const TSegment3D &s1, const TSegment3D &s2, TObject3D &obj)
Gets the intersection between two 3D segments.
The namespace for 3D scene representation and rendering.
mrpt::utils::CStream & operator<<(mrpt::utils::CStream &out, const mrpt::opengl::CLight &o)
mrpt::utils::CStream & operator>>(mrpt::utils::CStream &in, mrpt::opengl::CLight &o)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
unsigned __int32 uint32_t
Struct used to store a polyhedron edge.
~TPolyhedronEdge()
Destructor.
uint32_t v2
Second vertex.
TPolyhedronEdge()
Default constructor.
double length(const std::vector< mrpt::math::TPoint3D > &vs) const
Given a set of vertices, computes the length of the vertex.
bool operator==(const TPolyhedronEdge &e) const
Comparison agains another edge.
Struct used to store a polyhedron 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.
std::vector< uint32_t > vertices
Vector of indices to the vertex list.
TPolyhedronFace()
Fast default constructor.
double area(const std::vector< mrpt::math::TPoint3D > &vertices) const
Given a set of vertices, computes the area of this face.
~TPolyhedronFace()
Destructor.
double normal[3]
Normal vector.