#include <polyhedron.h>
Public Member Functions | |
Polyhedron () | |
Default constructor. | |
Polyhedron (const char *filename) | |
Constructor for Polyhedron class. | |
Polyhedron (const std::vector< Vertex * > &verts, const std::vector< std::vector< int > > &faces) | |
Constructor that takes an array of vertices and an array of faces. | |
Polyhedron * | refine () const |
Constructs a mode refined Polyhedron by adding one edge in the middle point of each edge, and connecting them in a number of interior faces. | |
~Polyhedron () | |
Destructor. | |
bool | load (const char *filename) |
Loads a mesh from a file. | |
bool | readPly (const char *filename) |
Loads a mesh from a PLY ASCII file. | |
bool | readOff (const char *filename) |
Loads a mesh from an OFF file. | |
bool | readTri (const char *filename) |
Loads a mesh from an TRI file. | |
bool | save (const char *filename) const |
Saves the mesh in a file. | |
bool | saveAsPly (const char *filename) const |
Saves the mesh in a PLY ASCII file. | |
bool | saveAsOff (const char *filename) const |
Saves the mesh in an OFF file. | |
bool | saveAsTri (const char *filename) const |
Saves the mesh in an TRI file. | |
void | clearData () |
Clears all the data in the mesh (vertices, faces. | |
Vertex * | addVertex (float x, float y, float z) |
Adds a new vertex to the Polyhedron. | |
Vertex * | addVertex (const Geometry::Vector3Df &v) |
Adds a new vertex to the Polyhedron. | |
Face * | addFace (const std::vector< int > &corners) |
Adds a new face to the Polyhedron. | |
Face * | addFace (int a, int b, int c) |
Adds a new triangular face to the Polyhedron. | |
void | loadVertices (const std::vector< float > &verts) |
Bulk-adding vertices. | |
void | loadFaces (const std::vector< std::vector< int > > &faces) |
Bulk-adding faces. | |
int | numVertices () const |
Tells the number of vertices in the Polyhedron. | |
int | numFaces () const |
Tells the number of faces in the Polyhedron. | |
int | numHalfEdges () const |
Tells the number of half-edges in the Polyhedron. | |
int | numHoles () const |
Tells the number of holes in the Polyhedron. | |
bool | adjacent (const Vertex *v1, const Vertex *v2) const |
Tells if two vertices are adjacent. | |
bool | adjacent (const Face *f1, const Face *f2) const |
Tells if two faces are adjacent. | |
filetype_e | type () const |
Tells the format of the mesh. | |
void | type (filetype_e ft) |
Sets the format of the mesh. | |
HalfEdge * | edge (int from, int to) const |
Finds the HalfEdge that connects two vertices. | |
HalfEdge * | edge (const Vertex *vFrom, const Vertex *vTo) const |
Vertex * | vertex (int v) |
Returns the indicated Vertex. | |
const Vertex * | vertex (int v) const |
Returns the indicated Vertex. | |
Face * | face (int f) |
Returns the indicated Face. | |
const Face * | face (int f) const |
Returns the indicated Face. | |
HalfEdge * | halfedge (int h) |
Returns the indicated HalfEdge. | |
const HalfEdge * | halfedge (int h) const |
Returns the indicated HalfEdge. | |
const std::vector < Vertex * > & | vertices () const |
Gets the array of vertices being used. | |
void | invertNormals () |
Inverts all the normals of the mesh, by swapping the direction of the HalfEdge objects. | |
void | packVertices () |
Eliminates all the vertices that do not have any adjacent HalfEdge, reindexing the rest. | |
void | scaleAndCenter (float side=10) |
Centers the mesh around the origin, and scales it to fit in a bounding box of the indicated size. | |
void | boundingBox (Geometry::Vector3Df &m, Geometry::Vector3Df &M) const |
Computes the (axis aligned) bounding box of the mesh. | |
void | finalize () |
Makes the _twin connections for all halfedges, and closes the holes. | |
face_iterator | fBegin () |
Iterator for the first Face of the Polyhedron. | |
face_iterator | fEnd () |
Iterator past the last Face of the Polyhedron. | |
const_face_iterator | fBegin () const |
Const Iterator for the first Face of the Polyhedron. | |
const_face_iterator | fEnd () const |
Const Iterator past the last Face of the Polyhedron. | |
edge_iterator | eBegin () |
Iterator for the first HalfEdge of the Polyhedron. | |
edge_iterator | eEnd () |
Iterator past the last HalfEdge of the Polyhedron. | |
const_edge_iterator | eBegin () const |
Const Iterator for the first HalfEdge of the Polyhedron. | |
const_edge_iterator | eEnd () const |
Const Iterator past the last HalfEdge of the Polyhedron. | |
vertex_iterator | vBegin () |
Iterator for the first Vertex of the Polyhedron. | |
vertex_iterator | vEnd () |
Iterator past the last Vertex of the Polyhedron. | |
const_vertex_iterator | vBegin () const |
Const Iterator for the first Vertex of the Polyhedron. | |
const_vertex_iterator | vEnd () const |
Const Iterator past the last Vertex of the Polyhedron. | |
void | writeVertices (std::ostream &out) const |
Writes the vertex data to a stream. | |
void | writeFaces (std::ostream &out, bool includeHoles=false) const |
Writes the face data to a stream. | |
void | writeHalfEdges (std::ostream &out) const |
Writes the half-edge data to a stream. | |
bool | check (bool holesFilled=true) const |
Verifies that the data structure is internally consistent. | |
Protected Member Functions | |
void | GL (Polyhedron_GL *gl) const |
Protected Attributes | |
std::vector< Face * > | _faces |
std::set< Face * > | _holes |
std::vector< HalfEdge * > | _halfEdges |
std::vector< Vertex * > | _vertices |
Polyhedron_GL * | _gl |
filetype_e | _type |
Friends | |
class | Polyhedron_GL |
Classes | |
class | const_edge_iterator |
Const HalfEdge iterator for the Polyhedron class. It traverses the hald-edges of the Polyhedron, one at a time. More... | |
class | const_face_iterator |
Const Face iterator for the Polyhedron class. It traverses the faces of the Polyhedron, one at a time. More... | |
class | const_vertex_iterator |
Const Vertex iterator for the Polyhedron class. It traverses the vertices of the Polyhedron, one at a time. More... | |
class | edge_iterator |
HalfEdge iterator for the Polyhedron class. It traverses the hald-edges of the Polyhedron, one at a time. More... | |
class | face_iterator |
Face iterator for the Polyhedron class. It traverses the faces of the Polyhedron, one at a time. More... | |
class | vertex_iterator |
Vertex iterator for the Polyhedron class. It traverses the vertices of the Polyhedron, one at a time. More... |
It contains a set of Vertex, HalfEdge and Face objects that together represent the mesh. I/O functionality, get/set methods and other simple manipulation routines are directly implemented in the class. More advanced algorithms are implemented through external functions. Note that HE_exception objects may be thrown if something goes wrong inside this class.
Definition at line 70 of file polyhedron.h.
Polyhedron::Polyhedron | ( | ) |
Polyhedron::Polyhedron | ( | const char * | filename | ) | [explicit] |
Constructor for Polyhedron class.
filename | File from where the mesh is to be read. Must be one of the supported formats. |
Definition at line 31 of file polyhedron.cpp.
References load().
Polyhedron::Polyhedron | ( | const std::vector< Vertex * > & | verts, | |
const std::vector< std::vector< int > > & | faces | |||
) | [explicit] |
Constructor that takes an array of vertices and an array of faces.
verts | Set of Vertex objects to be copied onto the Polyhedron. | |
faces | Set of faces to be loaded onto the Polyhedron. |
Definition at line 43 of file polyhedron.cpp.
References _vertices, and loadFaces().
Polyhedron::~Polyhedron | ( | ) |
Polyhedron * Polyhedron::refine | ( | ) | const |
Constructs a mode refined Polyhedron by adding one edge in the middle point of each edge, and connecting them in a number of interior faces.
Returns a copy of this Polyhedron where each n-vertex face has been split in n+1 faces, thus increasing its resolution.
The refined Polyhedron.
Definition at line 72 of file polyhedron.cpp.
References _halfEdges, _vertices, addFace(), addVertex(), HE::Face::edge(), fBegin(), fEnd(), finalize(), HE::Face::hole(), HE::Vertex::index(), HE::HalfEdge::midpoint(), HE::HalfEdge::next(), numFaces(), numVertices(), HE::HalfEdge::src(), and HE::HalfEdge::twin().
bool Polyhedron::load | ( | const char * | filename | ) |
Loads a mesh from a file.
Clears the current contents of the Polyhedron and loads the mesh described in the indicated file.
filename | File with the mesh to be loaded. |
Definition at line 147 of file polyhedron.cpp.
References clearData(), HE::fileFormat(), HE::FT_NONE, HE::FT_OBJ, HE::FT_OFF, HE::FT_PLY_ASCII, HE::FT_PLY_BIN, HE::FT_TRI, packVertices(), readOff(), readPly(), readTri(), and type().
Referenced by Polyhedron().
bool Polyhedron::readPly | ( | const char * | filename | ) |
Loads a mesh from a PLY ASCII file.
Clears the current contents of the Polyhedron and loads the mesh described in the indicated file, which should be of format PLY ASCII.
filename | File with the mesh to be loaded. |
Definition at line 80 of file mesh_io.cpp.
References loadFaces(), and loadVertices().
Referenced by load().
bool Polyhedron::readOff | ( | const char * | filename | ) |
Loads a mesh from an OFF file.
Clears the current contents of the Polyhedron and loads the mesh described in the indicated file, which should be of format OFF.
filename | File with the mesh to be loaded. |
Definition at line 278 of file mesh_io.cpp.
References face(), loadFaces(), and loadVertices().
Referenced by load().
bool Polyhedron::readTri | ( | const char * | filename | ) |
Loads a mesh from an TRI file.
Clears the current contents of the Polyhedron and loads the mesh described in the indicated file, which should be of format TRI.
filename | File with the mesh to be loaded. |
Definition at line 316 of file mesh_io.cpp.
References face(), loadFaces(), and loadVertices().
Referenced by load().
bool Polyhedron::save | ( | const char * | filename | ) | const |
Saves the mesh in a file.
The output format is the one indicated by type().
filename | File where the mesh will be written. If it exists, it will be overwritten without question. |
Definition at line 414 of file mesh_io.cpp.
References _type, HE::FT_OFF, HE::FT_PLY_ASCII, HE::FT_TRI, saveAsOff(), saveAsPly(), and saveAsTri().
bool Polyhedron::saveAsPly | ( | const char * | filename | ) | const |
Saves the mesh in a PLY ASCII file.
filename | File where the mesh will be written. If it exists, it will be overwritten without question. |
Definition at line 349 of file mesh_io.cpp.
References numFaces(), numVertices(), writeFaces(), and writeVertices().
Referenced by save().
bool Polyhedron::saveAsOff | ( | const char * | filename | ) | const |
Saves the mesh in an OFF file.
filename | File where the mesh will be written. If it exists, it will be overwritten without question. |
Definition at line 434 of file mesh_io.cpp.
References numFaces(), numHoles(), numVertices(), writeFaces(), and writeVertices().
Referenced by save().
bool Polyhedron::saveAsTri | ( | const char * | filename | ) | const |
Saves the mesh in an TRI file.
filename | File where the mesh will be written. If it exists, it will be overwritten without question. |
Definition at line 452 of file mesh_io.cpp.
References HE::Face::begin(), fBegin(), fEnd(), HE::Face::hole(), and numFaces().
Referenced by save().
void Polyhedron::clearData | ( | ) |
Clears all the data in the mesh (vertices, faces.
..).
Definition at line 139 of file polyhedron.cpp.
References _faces, _halfEdges, _holes, and _vertices.
Referenced by load().
Vertex* HE::Polyhedron::addVertex | ( | float | x, | |
float | y, | |||
float | z | |||
) | [inline] |
Adds a new vertex to the Polyhedron.
Its adjacency information is empty.
x | X coordinate of the position of the vertex. | |
y | Y coordinate of the position of the vertex. | |
z | Z coordinate of the position of the vertex. |
Definition at line 183 of file polyhedron.h.
Referenced by refine().
Vertex * Polyhedron::addVertex | ( | const Geometry::Vector3Df & | v | ) |
Adds a new vertex to the Polyhedron.
Its adjacency information is empty.
v | Position of the vertex to be added. |
Definition at line 132 of file polyhedron.cpp.
References _vertices.
Face * Polyhedron::addFace | ( | const std::vector< int > & | corners | ) |
Adds a new face to the Polyhedron.
Its adjacency information (esp. some _twin links) may be empty.
corners |
Definition at line 530 of file mesh_io.cpp.
References _faces, _halfEdges, _vertices, HE::Face::edge(), and numFaces().
Referenced by addFace(), loadFaces(), and refine().
Face * Polyhedron::addFace | ( | int | a, | |
int | b, | |||
int | c | |||
) |
Adds a new triangular face to the Polyhedron.
Its adjacency information (esp. some _twin links) may be empty.
a | First corner of the triangle. | |
b | Second corner of the triangle. | |
c | Third corner of the triangle. |
Definition at line 521 of file mesh_io.cpp.
References addFace().
int HE::Polyhedron::numVertices | ( | ) | const [inline] |
Tells the number of vertices in the Polyhedron.
Definition at line 219 of file polyhedron.h.
References _vertices.
Referenced by HE::operator<<(), packVertices(), HE::Polyhedron_GL::Polyhedron_GL(), refine(), saveAsOff(), and saveAsPly().
int HE::Polyhedron::numFaces | ( | ) | const [inline] |
Tells the number of faces in the Polyhedron.
Definition at line 225 of file polyhedron.h.
References _faces.
Referenced by addFace(), HE::operator<<(), HE::Polyhedron_GL::Polyhedron_GL(), refine(), saveAsOff(), saveAsPly(), and saveAsTri().
int HE::Polyhedron::numHalfEdges | ( | ) | const [inline] |
Tells the number of half-edges in the Polyhedron.
Definition at line 231 of file polyhedron.h.
References _halfEdges.
Referenced by HE::operator<<().
int Polyhedron::numHoles | ( | ) | const |
Tells the number of holes in the Polyhedron.
Some faces are tagged as being holes, thus not representing any surface, but a gap in it. This method counts the number of such faces.
Definition at line 416 of file polyhedron.cpp.
References fBegin(), and fEnd().
Referenced by HE::Polyhedron_GL::Polyhedron_GL(), and saveAsOff().
Tells if two vertices are adjacent.
Definition at line 498 of file polyhedron.cpp.
References HE::Vertex::begin().
Tells if two faces are adjacent.
Definition at line 511 of file polyhedron.cpp.
References HE::Face::begin().
filetype_e HE::Polyhedron::type | ( | ) | const [inline] |
Tells the format of the mesh.
Definition at line 261 of file polyhedron.h.
References _type.
Referenced by load().
void HE::Polyhedron::type | ( | filetype_e | ft | ) | [inline] |
Sets the format of the mesh.
This is only relevant if the mesh is going to be saved to file.
ft | filetype_e value that indicates the desired format. |
Definition at line 267 of file polyhedron.h.
References _type.
HalfEdge * Polyhedron::edge | ( | int | from, | |
int | to | |||
) | const |
Finds the HalfEdge that connects two vertices.
These vertices are indicated by their indices, and should be within range.
from | Index of the vertex from which the searched HalfEdge departs. | |
to | Index of the vertex where the searched HalfEdge ends. |
Definition at line 329 of file polyhedron.cpp.
References _vertices.
Referenced by edge(), and packVertices().
void Polyhedron::scaleAndCenter | ( | float | side = 10 |
) |
Centers the mesh around the origin, and scales it to fit in a bounding box of the indicated size.
side | Side of the desired bounding box after calling this method. Optional parameter. |
Definition at line 355 of file polyhedron.cpp.
References _gl, boundingBox(), HE::Polyhedron_GL::recomputeNormals(), vBegin(), and vEnd().
void Polyhedron::boundingBox | ( | Geometry::Vector3Df & | m, | |
Geometry::Vector3Df & | M | |||
) | const |
Computes the (axis aligned) bounding box of the mesh.
m | Coordinates of the lower corner of the bounding box. | |
M | Coordinates of the upper corner of the bounding box. |
Definition at line 335 of file polyhedron.cpp.
References vBegin(), and vEnd().
Referenced by scaleAndCenter().
void Polyhedron::writeVertices | ( | std::ostream & | out | ) | const |
Writes the vertex data to a stream.
out | Stream where the vertex data has been written. |
Definition at line 377 of file mesh_io.cpp.
References vBegin(), and vEnd().
Referenced by HE::operator<<(), saveAsOff(), and saveAsPly().
void Polyhedron::writeFaces | ( | std::ostream & | out, | |
bool | includeHoles = false | |||
) | const |
Writes the face data to a stream.
out | Stream where the face data has been written. |
Definition at line 389 of file mesh_io.cpp.
References HE::Face::begin(), fBegin(), fEnd(), HE::Face::hole(), and HE::Face::size().
Referenced by HE::operator<<(), saveAsOff(), and saveAsPly().
void Polyhedron::writeHalfEdges | ( | std::ostream & | out | ) | const |
Writes the half-edge data to a stream.
out | Stream where the half-edge data has been written. |
Definition at line 383 of file mesh_io.cpp.
References eBegin(), and eEnd().
Referenced by HE::operator<<().
bool Polyhedron::check | ( | bool | holesFilled = true |
) | const |
Verifies that the data structure is internally consistent.
holesFilled | Have the holes been filled yet? |
Definition at line 422 of file polyhedron.cpp.
References HE::Face::begin(), eBegin(), eEnd(), fBegin(), fEnd(), HE::HalfEdge::next(), vBegin(), and vEnd().
Referenced by finalize(), and invertNormals().