9 #ifndef opengl_CPolyhedron_H
10 #define opengl_CPolyhedron_H
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);
142 static CPolyhedronPtr CreateTetrahedron(
double radius);
149 static CPolyhedronPtr CreateHexahedron(
double radius);
156 static CPolyhedronPtr CreateOctahedron(
double radius);
162 static CPolyhedronPtr CreateDodecahedron(
double radius);
168 static CPolyhedronPtr CreateIcosahedron(
double radius);
180 static CPolyhedronPtr CreateTruncatedTetrahedron(
double radius);
187 static CPolyhedronPtr CreateCuboctahedron(
double radius);
193 static CPolyhedronPtr CreateTruncatedHexahedron(
double radius);
199 static CPolyhedronPtr CreateTruncatedOctahedron(
double radius);
206 static CPolyhedronPtr CreateRhombicuboctahedron(
double radius,
bool type=
true);
214 static CPolyhedronPtr CreateIcosidodecahedron(
double radius,
bool type=
true);
220 static CPolyhedronPtr CreateTruncatedDodecahedron(
double radius);
226 static CPolyhedronPtr CreateTruncatedIcosahedron(
double radius);
232 static CPolyhedronPtr CreateRhombicosidodecahedron(
double radius);
243 static CPolyhedronPtr CreatePentagonalRotunda(
double radius);
255 static CPolyhedronPtr CreateTriakisTetrahedron(
double radius);
262 static CPolyhedronPtr CreateRhombicDodecahedron(
double radius);
269 static CPolyhedronPtr CreateTriakisOctahedron(
double radius);
276 static CPolyhedronPtr CreateTetrakisHexahedron(
double radius);
283 static CPolyhedronPtr CreateDeltoidalIcositetrahedron(
double radius);
290 static CPolyhedronPtr CreateRhombicTriacontahedron(
double radius);
297 static CPolyhedronPtr CreateTriakisIcosahedron(
double radius);
304 static CPolyhedronPtr CreatePentakisDodecahedron(
double radius);
311 static CPolyhedronPtr CreateDeltoidalHexecontahedron(
double radius);
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);
373 static CPolyhedronPtr CreateTrapezohedron(
uint32_t numBaseEdges,
double baseRadius,
double basesDistance);
378 static CPolyhedronPtr CreateRegularAntiprism(
uint32_t numBaseEdges,
double baseRadius,
double height);
383 static CPolyhedronPtr CreateRegularPrism(
uint32_t numBaseEdges,
double baseRadius,
double height);
388 static CPolyhedronPtr CreateRegularPyramid(
uint32_t numBaseEdges,
double baseRadius,
double height);
393 static CPolyhedronPtr CreateRegularDoublePyramid(
uint32_t numBaseEdges,
double baseRadius,
double height1,
double height2);
398 static CPolyhedronPtr CreateArchimedeanRegularPrism(
uint32_t numBaseEdges,
double baseRadius);
403 static CPolyhedronPtr CreateArchimedeanRegularAntiprism(
uint32_t numBaseEdges,
double baseRadius);
408 static CPolyhedronPtr CreateRegularTruncatedPyramid(
uint32_t numBaseEdges,
double baseRadius,
double height,
double ratio);
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);
429 static CPolyhedronPtr CreateCatalanTrapezohedron(
uint32_t numBaseEdges,
double height);
435 static CPolyhedronPtr CreateCatalanDoublePyramid(
uint32_t numBaseEdges,
double height);
466 static CPolyhedronPtr CreateJohnsonSolidWithConstantBase(
uint32_t numBaseEdges,
double baseRadius,
const std::string &
components,
size_t shifts=0);
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();
519 void getEdgesLength(std::vector<double> &lengths)
const;
523 void getFacesArea(std::vector<double> &areas)
const;
527 double getVolume()
const;
551 mLineWidth=lineWidth;
558 void getSetOfPolygons(std::vector<math::TPolygon3D> &vec)
const;
563 void getSetOfPolygonsAbsolute(std::vector<math::TPolygon3D> &vec)
const;
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;
578 void makeConvexPolygons();
586 static CPolyhedronPtr CreateRandomPolyhedron(
double radius);
596 CPolyhedronPtr getDual()
const;
602 CPolyhedronPtr truncate(
double factor)
const;
607 CPolyhedronPtr cantellate(
double factor)
const;
612 CPolyhedronPtr augment(
double height)
const;
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;
646 void updatePolygons()
const;
651 static std::vector<mrpt::math::TPoint2D> generateBase(
uint32_t numBaseEdges,
double baseRadius);
655 static std::vector<mrpt::math::TPoint2D> generateShiftedBase(
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);
667 bool setNormal(TPolyhedronFace &f,
bool doCheck=
true);
671 void addEdges(
const TPolyhedronFace &e);
675 static bool checkConsistence(
const std::vector<mrpt::math::TPoint3D> &vertices,
const std::vector<TPolyhedronFace> &faces);
679 size_t edgesInVertex(
size_t vertex)
const;
683 size_t facesInVertex(
size_t vertex)
const;
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);
701 static CPolyhedronPtr CreateEmpty();
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.
std::vector< TPolyhedronEdge > mEdges
List of polyhedron's edges.
bool polygonsUpToDate
Whether the set of actual polygons is up to date or not.
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.
double getLineWidth() const
Gets the wireframe lines width.
std::vector< mrpt::math::TPoint3D > mVertices
List of vertices presents in the polyhedron.
uint32_t getNumberOfEdges() const
Gets the amount of edges.
bool isClosed() const
Returns true if the polygon is a completely closed object.
std::vector< TPolyhedronFace > mFaces
List of polyhedron's faces.
void getEdges(std::vector< TPolyhedronEdge > &edges) const
Gets a list with the polyhedron's edges.
uint32_t getNumberOfFaces() const
Gets the amount of faces.
uint32_t getNumberOfVertices() const
Gets the amount of vertices.
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.
double mLineWidth
When displaying as wireframe object, this variable stores the width of the edges.
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.
CPolyhedron()
Basic empty constructor.
void setWireframe(bool enabled=true)
Sets whether the polyhedron will be rendered as a wireframe object.
virtual ~CPolyhedron()
Destructor.
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.
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...
GLenum GLenum GLenum GLenum GLenum scale
GLuint GLsizei GLsizei * length
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 BASE_IMPEXP traceRay(const std::vector< TPolygonWithPlane > &vec, const mrpt::poses::CPose3D &pose, double &dist)
Fast ray tracing method using polygons' properties.
bool BASE_IMPEXP intersect(const TSegment3D &s1, const TSegment3D &s2, TObject3D &obj)
Gets the intersection between two 3D segments.
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
The namespace for 3D scene representation and rendering.
OPENGL_IMPEXP mrpt::utils::CStream & operator<<(mrpt::utils::CStream &out, const mrpt::opengl::CLight &o)
::mrpt::utils::CStream & operator>>(mrpt::utils::CStream &in, CAngularObservationMeshPtr &pObj)
class OPENGL_IMPEXP CPolyhedron
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.
bool operator==(const TPolyhedronEdge &e) const
Comparison agains another edge.
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.