9 #ifndef opengl_CPolyhedron_H
10 #define opengl_CPolyhedron_H
62 if (e.
v1==v1&&e.
v2==v2)
return true;
63 else return e.
v1==v2&&e.
v2==v1;
68 double length(
const vector<TPoint3D> &vs)
const;
97 double area(
const vector<TPoint3D> &vertices)
const;
101 void getCenter(
const vector<TPoint3D> &vertices,
TPoint3D &p)
const;
137 static CPolyhedronPtr Create(
const vector<TPoint3D> &vertices,
const vector<vector<uint32_t> > &faces);
142 static CPolyhedronPtr Create(
const vector<TPoint3D> &vertices,
const vector<TPolyhedronFace> &faces);
147 static CPolyhedronPtr Create(
const std::vector<math::TPolygon3D> &polys);
163 static CPolyhedronPtr CreateTetrahedron(
double radius);
170 static CPolyhedronPtr CreateHexahedron(
double radius);
177 static CPolyhedronPtr CreateOctahedron(
double radius);
183 static CPolyhedronPtr CreateDodecahedron(
double radius);
189 static CPolyhedronPtr CreateIcosahedron(
double radius);
201 static CPolyhedronPtr CreateTruncatedTetrahedron(
double radius);
208 static CPolyhedronPtr CreateCuboctahedron(
double radius);
214 static CPolyhedronPtr CreateTruncatedHexahedron(
double radius);
220 static CPolyhedronPtr CreateTruncatedOctahedron(
double radius);
227 static CPolyhedronPtr CreateRhombicuboctahedron(
double radius,
bool type=
true);
235 static CPolyhedronPtr CreateIcosidodecahedron(
double radius,
bool type=
true);
241 static CPolyhedronPtr CreateTruncatedDodecahedron(
double radius);
247 static CPolyhedronPtr CreateTruncatedIcosahedron(
double radius);
253 static CPolyhedronPtr CreateRhombicosidodecahedron(
double radius);
264 static CPolyhedronPtr CreatePentagonalRotunda(
double radius);
276 static CPolyhedronPtr CreateTriakisTetrahedron(
double radius);
283 static CPolyhedronPtr CreateRhombicDodecahedron(
double radius);
290 static CPolyhedronPtr CreateTriakisOctahedron(
double radius);
297 static CPolyhedronPtr CreateTetrakisHexahedron(
double radius);
304 static CPolyhedronPtr CreateDeltoidalIcositetrahedron(
double radius);
311 static CPolyhedronPtr CreateRhombicTriacontahedron(
double radius);
318 static CPolyhedronPtr CreateTriakisIcosahedron(
double radius);
325 static CPolyhedronPtr CreatePentakisDodecahedron(
double radius);
332 static CPolyhedronPtr CreateDeltoidalHexecontahedron(
double radius);
343 static CPolyhedronPtr CreateCubicPrism(
double x1,
double x2,
double y1,
double y2,
double z1,
double z2);
348 static CPolyhedronPtr CreateCubicPrism(
const TPoint3D &p1,
const TPoint3D &p2);
353 static CPolyhedronPtr CreatePyramid(
const vector<TPoint2D> &baseVertices,
double height);
358 static CPolyhedronPtr CreateDoublePyramid(
const vector<TPoint2D> &baseVertices,
double height1,
double height2);
364 static CPolyhedronPtr CreateTruncatedPyramid(
const vector<TPoint2D> &baseVertices,
double height,
double ratio);
369 static CPolyhedronPtr CreateFrustum(
const vector<TPoint2D> &baseVertices,
double height,
double ratio);
374 static CPolyhedronPtr CreateCustomPrism(
const vector<TPoint2D> &baseVertices,
double height);
379 static CPolyhedronPtr CreateCustomAntiprism(
const vector<TPoint2D> &bottomBase,
const vector<TPoint2D> &topBase,
double height);
389 static CPolyhedronPtr CreateBifrustum(
const vector<TPoint2D> &baseVertices,
double height1,
double ratio1,
double height2,
double ratio2);
394 static CPolyhedronPtr CreateTrapezohedron(uint32_t numBaseEdges,
double baseRadius,
double basesDistance);
399 static CPolyhedronPtr CreateRegularAntiprism(uint32_t numBaseEdges,
double baseRadius,
double height);
404 static CPolyhedronPtr CreateRegularPrism(uint32_t numBaseEdges,
double baseRadius,
double height);
409 static CPolyhedronPtr CreateRegularPyramid(uint32_t numBaseEdges,
double baseRadius,
double height);
414 static CPolyhedronPtr CreateRegularDoublePyramid(uint32_t numBaseEdges,
double baseRadius,
double height1,
double height2);
419 static CPolyhedronPtr CreateArchimedeanRegularPrism(uint32_t numBaseEdges,
double baseRadius);
424 static CPolyhedronPtr CreateArchimedeanRegularAntiprism(uint32_t numBaseEdges,
double baseRadius);
429 static CPolyhedronPtr CreateRegularTruncatedPyramid(uint32_t numBaseEdges,
double baseRadius,
double height,
double ratio);
434 static CPolyhedronPtr CreateRegularFrustum(uint32_t numBaseEdges,
double baseRadius,
double height,
double ratio);
439 static CPolyhedronPtr CreateRegularBifrustum(uint32_t numBaseEdges,
double baseRadius,
double height1,
double ratio1,
double height2,
double ratio2);
444 static CPolyhedronPtr CreateCupola(uint32_t numBaseEdges,
double edgeLength);
450 static CPolyhedronPtr CreateCatalanTrapezohedron(uint32_t numBaseEdges,
double height);
456 static CPolyhedronPtr CreateCatalanDoublePyramid(uint32_t numBaseEdges,
double height);
487 static CPolyhedronPtr CreateJohnsonSolidWithConstantBase(uint32_t numBaseEdges,
double baseRadius,
const std::string &components,
size_t shifts=0);
495 void render_dl()
const;
504 inline void getVertices(vector<TPoint3D> &vertices)
const {
510 inline void getEdges(vector<TPolyhedronEdge> &edges)
const {
516 inline void getFaces(vector<TPolyhedronFace> &faces)
const {
522 inline uint32_t getNumberOfVertices()
const {
523 return mVertices.size();
528 inline uint32_t getNumberOfEdges()
const {
529 return mEdges.size();
534 inline uint32_t getNumberOfFaces()
const {
535 return mFaces.size();
540 void getEdgesLength(vector<double> &lengths)
const;
544 void getFacesArea(vector<double> &areas)
const;
548 double getVolume()
const;
552 inline bool isWireframe()
const {
558 inline void setWireframe(
bool enabled=
true) {
565 inline double getLineWidth()
const {
571 inline void setLineWidth(
double lineWidth) {
572 mLineWidth=lineWidth;
579 void getSetOfPolygons(std::vector<math::TPolygon3D> &vec)
const;
584 void getSetOfPolygonsAbsolute(std::vector<math::TPolygon3D> &vec)
const;
588 template<
class T>
inline static size_t getIntersection(
const CPolyhedronPtr &p1,
const CPolyhedronPtr &p2,T &container);
592 inline bool isClosed()
const {
593 for (
size_t i=0;i<mVertices.size();i++)
if (edgesInVertex(i)!=facesInVertex(i))
return false;
599 void makeConvexPolygons();
603 void getCenter(
TPoint3D ¢er)
const;
607 static CPolyhedronPtr CreateRandomPolyhedron(
double radius);
617 CPolyhedronPtr getDual()
const;
623 CPolyhedronPtr truncate(
double factor)
const;
628 CPolyhedronPtr cantellate(
double factor)
const;
633 CPolyhedronPtr augment(
double height)
const;
638 CPolyhedronPtr augment(
double height,
size_t numVertices)
const;
644 CPolyhedronPtr augment(
bool direction=
false)
const;
650 CPolyhedronPtr augment(
size_t numVertices,
bool direction=
false)
const;
655 CPolyhedronPtr rotate(
double angle)
const;
661 CPolyhedronPtr scale(
double factor)
const;
667 void updatePolygons()
const;
672 static vector<TPoint2D> generateBase(uint32_t numBaseEdges,
double baseRadius);
676 static vector<TPoint2D> generateShiftedBase(uint32_t numBaseEdges,
double baseRadius);
680 static void generateBase(uint32_t numBaseEdges,
double baseRadius,
double height,vector<TPoint3D> &vec);
684 static void generateShiftedBase(uint32_t numBaseEdges,
double baseRadius,
double height,
double shift,vector<TPoint3D> &vec);
688 bool setNormal(TPolyhedronFace &f,
bool doCheck=
true);
692 void addEdges(
const TPolyhedronFace &e);
696 static bool checkConsistence(
const vector<TPoint3D> &vertices,
const vector<TPolyhedronFace> &faces);
700 size_t edgesInVertex(
size_t vertex)
const;
704 size_t facesInVertex(
size_t vertex)
const;
708 inline CPolyhedron():mVertices(),mEdges(),mFaces(),mWireframe(false),mLineWidth(1),polygonsUpToDate(false) {}
712 inline CPolyhedron(
const vector<TPoint3D> &vertices,
const vector<TPolyhedronFace> &faces,
bool doCheck=
true):mVertices(vertices),mEdges(),mFaces(faces),mWireframe(false),mLineWidth(1),polygonsUpToDate(false) {
713 if (doCheck)
if (!checkConsistence(vertices,faces))
throw std::logic_error(
"Face list accesses a vertex out of range");
715 if (!setNormal(*it,doCheck))
throw std::logic_error(
"Bad face specification");
720 static CPolyhedronPtr CreateNoCheck(
const vector<TPoint3D> &vertices,
const vector<TPolyhedronFace> &faces);
722 static CPolyhedronPtr CreateEmpty();
730 size_t CPolyhedron::getIntersection(const CPolyhedronPtr &p1,const CPolyhedronPtr &p2,T &container) {
731 std::vector<TPolygon3D> polys1,polys2;
733 p2->getSetOfPolygonsAbsolute(polys2);
bool mWireframe
This flag determines whether the polyhedron will be displayed as a solid object or as a set of edges...
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
bool operator==(const TPolyhedronEdge &e) const
Comparison agains another edge.
OPENGL_IMPEXP mrpt::utils::CStream & operator<<(mrpt::utils::CStream &out, const mrpt::opengl::CLight &o)
vector< TPolyhedronFace > mFaces
List of polyhedron's faces.
vector< uint32_t > vertices
Vector of indices to the vertex list.
::mrpt::utils::CStream & operator>>(mrpt::utils::CStream &in, CAngularObservationMeshPtr &pObj)
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
This class represents arbitrary polyhedra.
~TPolyhedronFace()
Destructor.
A renderizable object suitable for rendering with OpenGL's display lists.
vector< TPolyhedronEdge > mEdges
List of polyhedron's edges.
uint32_t v2
Second vertex.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
This base provides a set of functions for maths stuff.
#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.
TPolyhedronFace()
Fast default constructor.
~TPolyhedronEdge()
Destructor.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
bool BASE_IMPEXP traceRay(const vector< TPolygonWithPlane > &vec, const mrpt::poses::CPose3D &pose, double &dist)
Fast ray tracing method using polygons' properties.
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
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
TPolyhedronEdge()
Default constructor.
The namespace for 3D scene representation and rendering.
void getSetOfPolygonsAbsolute(std::vector< math::TPolygon3D > &vec) const
Gets the polyhedron as a set of polygons, with the pose transformation already applied.
bool BASE_IMPEXP intersect(const TSegment3D &s1, const TSegment3D &s2, TObject3D &obj)
Gets the intersection between two 3D segments.
double mLineWidth
When displaying as wireframe object, this variable stores the width of the edges. ...
std::vector< TPolygonWithPlane > tempPolygons
Mutable list of actual polygons, maintained for speed.
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
vector< TPoint3D > mVertices
List of vertices presents in the polyhedron.
#define MRPT_DECLARE_TTYPENAME(_TYPE)