HE::Polyhedron Class Reference

Class that holds the representation of a manifold mesh in a half-edge data structure. More...

#include <polyhedron.h>

List of all members.

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.
Polyhedronrefine () 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.
VertexaddVertex (float x, float y, float z)
 Adds a new vertex to the Polyhedron.
VertexaddVertex (const Geometry::Vector3Df &v)
 Adds a new vertex to the Polyhedron.
FaceaddFace (const std::vector< int > &corners)
 Adds a new face to the Polyhedron.
FaceaddFace (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.
HalfEdgeedge (int from, int to) const
 Finds the HalfEdge that connects two vertices.
HalfEdgeedge (const Vertex *vFrom, const Vertex *vTo) const
Vertexvertex (int v)
 Returns the indicated Vertex.
const Vertexvertex (int v) const
 Returns the indicated Vertex.
Faceface (int f)
 Returns the indicated Face.
const Faceface (int f) const
 Returns the indicated Face.
HalfEdgehalfedge (int h)
 Returns the indicated HalfEdge.
const HalfEdgehalfedge (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...


Detailed Description

Class that holds the representation of a manifold mesh in a half-edge data structure.

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.


Constructor & Destructor Documentation

Polyhedron::Polyhedron (  ) 

Default constructor.

Creates an empty Polyhedron.

Definition at line 38 of file polyhedron.cpp.

Polyhedron::Polyhedron ( const char *  filename  )  [explicit]

Constructor for Polyhedron class.

Parameters:
filename File from where the mesh is to be read. Must be one of the supported formats.
Returns:
A valid Polyhedron object initialized with the data in the file.

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.

Parameters:
verts Set of Vertex objects to be copied onto the Polyhedron.
faces Set of faces to be loaded onto the Polyhedron.
Returns:
A valid Polyhedron initialized with the indicated data.

Definition at line 43 of file polyhedron.cpp.

References _vertices, and loadFaces().

Polyhedron::~Polyhedron (  ) 

Destructor.

Deletes all the used memory.

Definition at line 52 of file polyhedron.cpp.

References _faces, _halfEdges, _vertices, eBegin(), eEnd(), fBegin(), fEnd(), vBegin(), and vEnd().


Member Function Documentation

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.

Returns:
Pointer to the newly created Polyhedron.

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.

Parameters:
filename File with the mesh to be loaded.
Returns:
True in case of success; false otherwise.

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.

Parameters:
filename File with the mesh to be loaded.
Returns:
True in case of success; false otherwise.

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.

Parameters:
filename File with the mesh to be loaded.
Returns:
True in case of success; false otherwise.

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.

Parameters:
filename File with the mesh to be loaded.
Returns:
True in case of success; false otherwise.

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().

See also:
type
Parameters:
filename File where the mesh will be written. If it exists, it will be overwritten without question.
Returns:
True in case of success; false otherwise.

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.

See also:
type
Parameters:
filename File where the mesh will be written. If it exists, it will be overwritten without question.
Returns:
True in case of success; false otherwise.

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.

See also:
type
Parameters:
filename File where the mesh will be written. If it exists, it will be overwritten without question.
Returns:
True in case of success; false otherwise.

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.

See also:
type
Parameters:
filename File where the mesh will be written. If it exists, it will be overwritten without question.
Returns:
True in case of success; false otherwise.

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.

Parameters:
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.
Returns:
A pointer to the newly created 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.

Parameters:
v Position of the vertex to be added.
Returns:
A pointer to the newly created Vertex.

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.

Parameters:
corners 
Returns:
A pointer to the newly created Face.

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.

Parameters:
a First corner of the triangle.
b Second corner of the triangle.
c Third corner of the triangle.
Returns:
The newly added Face.

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.

Returns:
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.

Returns:
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.

Returns:
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.

Returns:
Number of holes in the Polyhedron.

Definition at line 416 of file polyhedron.cpp.

References fBegin(), and fEnd().

Referenced by HE::Polyhedron_GL::Polyhedron_GL(), and saveAsOff().

bool Polyhedron::adjacent ( const Vertex v1,
const Vertex v2 
) const

Tells if two vertices are adjacent.

Parameters:
v1 First Vertex
v2 Second Vertex
Returns:
True if they're adjacent; false otherwise.

Definition at line 498 of file polyhedron.cpp.

References HE::Vertex::begin().

bool Polyhedron::adjacent ( const Face f1,
const Face f2 
) const

Tells if two faces are adjacent.

Parameters:
f1 First Face
f2 Second Face
Returns:
True if they're adjacent; false otherwise.

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.

Returns:
A filetype_e value corresponding to the current format of the mesh. This is useful for knowing the type of file from where the mesh was read, and to properly save it.

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.

Parameters:
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.

Parameters:
from Index of the vertex from which the searched HalfEdge departs.
to Index of the vertex where the searched HalfEdge ends.
Returns:
The desired HalfEdge, or 0 if it does not exist.

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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
holesFilled Have the holes been filled yet?
Returns:
True if everything was fine; False otherwise.

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().


The documentation for this class was generated from the following files:
Generated on Wed Apr 9 19:22:40 2008 for HalfEdge library by  doxygen 1.5.3