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 {
501 inline uint32_t getNumberOfVertices()
const {
502 return mVertices.size();
507 inline uint32_t getNumberOfEdges()
const {
508 return mEdges.size();
513 inline uint32_t getNumberOfFaces()
const {
514 return mFaces.size();
519 void getEdgesLength(std::vector<double> &lengths)
const;
523 void getFacesArea(std::vector<double> &areas)
const;
527 double getVolume()
const;
531 inline bool isWireframe()
const {
537 inline void setWireframe(
bool enabled=
true) {
544 inline double getLineWidth()
const {
550 inline void setLineWidth(
double lineWidth) {
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);
571 inline bool isClosed()
const {
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 MRPT_DECLARE_TTYPENAME_NAMESPACE(_TYPE, __NS)
bool mWireframe
This flag determines whether the polyhedron will be displayed as a solid object or as a set of edges...
OPENGL_IMPEXP mrpt::utils::CStream & operator<<(mrpt::utils::CStream &out, const mrpt::opengl::CLight &o)
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
::mrpt::utils::CStream & operator>>(mrpt::utils::CStream &in, CAngularObservationMeshPtr &pObj)
bool BASE_IMPEXP traceRay(const std::vector< TPolygonWithPlane > &vec, const mrpt::poses::CPose3D &pose, double &dist)
Fast ray tracing method using polygons' properties.
GLenum GLenum GLenum GLenum GLenum scale
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
GLenum GLenum GLuint components
This class represents arbitrary polyhedra.
~TPolyhedronFace()
Destructor.
A renderizable object suitable for rendering with OpenGL's display lists.
uint32_t v2
Second vertex.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
std::vector< uint32_t > vertices
Vector of indices to the vertex list.
std::vector< mrpt::math::TPolygonWithPlane > tempPolygons
Mutable list of actual polygons, maintained for speed.
#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...
Struct used to store a polyhedron face.
Struct used to store a polyhedron edge.
bool operator==(const TPolyhedronEdge &e) const
Comparison agains another edge.
GLfloat GLfloat GLfloat GLfloat v3
TPolyhedronFace()
Fast default constructor.
GLsizei const GLchar ** string
std::vector< TPolyhedronEdge > mEdges
List of polyhedron's edges.
std::vector< mrpt::math::TPoint3D > mVertices
List of vertices presents in the polyhedron.
~TPolyhedronEdge()
Destructor.
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.
class OPENGL_IMPEXP CPolyhedron
TPolyhedronEdge()
Default constructor.
GLuint GLsizei GLsizei * length
The namespace for 3D scene representation and rendering.
double mLineWidth
When displaying as wireframe object, this variable stores the width of the edges. ...
GLfloat GLfloat GLfloat v2
std::vector< TPolyhedronFace > mFaces
List of polyhedron's faces.
GLenum GLsizei GLsizei height
unsigned __int32 uint32_t
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
bool BASE_IMPEXP intersect(const TSegment3D &s1, const TSegment3D &s2, TObject3D &obj)
Gets the intersection between two 3D segments.
GLuint GLuint GLsizei GLenum type
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.