The Parametric Pseudo-Manifold (PPS) Library 1.0
|
This class represents a triangle surface mesh with empty boundary. More...
#include <surface.h>
Public Types | |
typedef dcel::Vertex< VAttrib, FAttrib, EAttrib, HAttrib > | Vertex |
Defines Vertex as an alias for dcel::Vertex< VAttrib, FAttrib , EAttrib , HAttrib >. | |
typedef dcel::Face< VAttrib, FAttrib, EAttrib, HAttrib > | Face |
Defines Face as an alias for dcel::Face< VAttrib, FAttrib , EAttrib , HAttrib >. | |
typedef dcel::Edge< VAttrib, FAttrib, EAttrib, HAttrib > | Edge |
Defines Edge as an alias for dcel::Edge< VAttrib, FAttrib , EAttrib , HAttrib >. | |
typedef dcel::Halfedge < VAttrib, FAttrib, EAttrib, HAttrib > | Halfedge |
Defines Halfedge as an alias for dcel::Halfedge< VAttrib, FAttrib , EAttrib , HAttrib >. | |
typedef std::list< Vertex * > ::const_iterator | VertexIterator |
Defines an iterator for the list of vertices of this mesh. | |
typedef std::list< Edge * > ::const_iterator | EdgeIterator |
Defines an iterator for the list of edge of this mesh. | |
typedef std::list< Face * > ::const_iterator | FaceIterator |
Defines an iterator for the list of faces of this mesh. | |
typedef std::map< unsigned, Vertex * > | VMAP |
Defines a dictionary for vertex identifiers and pointers. | |
typedef std::map< std::pair < unsigned, unsigned > , Halfedge * > | HMAP |
Defines a dictionary for half-edge identifiers and pointers. | |
Public Member Functions | |
Surface (unsigned nverts, double *lverts, unsigned nfaces, unsigned *lfaces) | |
Creates an instance of this class. | |
virtual | ~Surface () |
Releases the memory held fy an instance of this class. | |
unsigned | get_number_of_vertices () const |
Returns the number of vertices of this surface. | |
unsigned | get_number_of_edges () const |
Returns the number of edges of this surface. | |
unsigned | get_number_of_faces () const |
Returns the number of faces of this surface. | |
VertexIterator | vertices_begin () const |
Returns a vertex iterator set to the first vertex of the list of vertices of this surface. | |
EdgeIterator | edges_begin () const |
Returns an edge iterator set to the first edge of the list of edges of this surface. | |
FaceIterator | faces_begin () const |
Returns a face iterator set to the first face of the list of faces of this surface. | |
VertexIterator | vertices_end () const |
Returns a vertex iterator set past the last vertex of the list of vertices of this surface. | |
EdgeIterator | edges_end () const |
Returns an edge iterator set past the last edge of the list of edges of this surface. | |
FaceIterator | faces_end () const |
Returns a face iterator set past the last face of the list of faces of this surface. | |
void | add_vertex (Vertex *v) |
Performs an insertion of a vertex in the mesh. | |
void | add_face (Face *f) |
Performs an insertion of a face in the mesh. | |
void | add_edge (Edge *e) |
Performs an insertion of an edge in the mesh. | |
Protected Attributes | |
std::list< Vertex * > | _list_of_vertices |
List of vertices of this surface. | |
std::list< Edge * > | _list_of_edges |
List of edges of this surface. | |
std::list< Face * > | _list_of_faces |
List of faces of this surface. | |
Private Member Functions | |
void | create_vertices (unsigned nverts, double *lverts, VMAP &vmap) |
Creates the vertices of this surface. | |
void | create_faces (unsigned nfaces, unsigned *lfaces, HMAP &hmap, VMAP &vmap) |
Creates the faces and half-edges of this surface. | |
void | create_edges (HMAP &hmap) |
Creates the edges of this surface. | |
bool | is_consistent () const |
Performs a topological consistency check in this surface. |
This class represents a triangle surface mesh with empty boundary.
dcel::Surface< VAttrib, FAttrib, EAttrib, HAttrib >::Surface | ( | unsigned | nverts, |
double * | lverts, | ||
unsigned | nfaces, | ||
unsigned * | lfaces | ||
) |
Creates an instance of this class.
nverts | The number of vertices of this surface. |
lverts | An array with the vertex coordinates. |
nfaces | The number of faces of this surface. |
lfaces | An array with the vertex identifiers of each face of this surface. |
Define a dictionary to keep track of vertex IDs.
Create the vertices and initialize the table.
Define a dictionary to keep track of the halfedge IDs.
Create the faces and halfedges and initialize the table.
Release memory associated with the vertex ID table.
Release memory associated with the halfedge ID table.
Check if this surface is topologically consistent.
Definition at line 447 of file surface.h.
{ // // Create the vertices of the surface. // VMAP vmap ; create_vertices( nverts , lverts , vmap ) ; // // Create the faces and halfedges of the surface. // HMAP hmap ; create_faces( nfaces , lfaces , hmap , vmap ) ; vmap.clear(); // // Create the edges of the surface. // create_edges( hmap ) ; hmap.clear(); assert( is_consistent() ) ; return ; }
dcel::Surface< VAttrib, FAttrib, EAttrib, HAttrib >::~Surface | ( | ) | [virtual] |
Releases the memory held fy an instance of this class.
Releases the memory held by an instance of this class.
Releases memory associated with the vertices.
Releases memory associated with the edges and half-edges.
Releases memory associated with the faces.
Definition at line 503 of file surface.h.
References dcel::Edge< VAttrib, FAttrib, EAttrib, HAttrib >::get_first_halfedge(), and dcel::Edge< VAttrib, FAttrib, EAttrib, HAttrib >::get_second_halfedge().
{ for( VertexIterator vit = vertices_begin() ; vit != vertices_end() ; ++vit ) { Vertex* vertex = *vit ; if ( vertex != 0 ) delete vertex ; } _list_of_vertices.clear() ; for( EdgeIterator eit = edges_begin() ; eit != edges_end() ; ++eit ) { Edge* edge = *eit ; Halfedge* h1 = edge->get_first_halfedge() ; Halfedge* h2 = edge->get_second_halfedge() ; if ( h1 != 0 ) delete h1 ; if ( h2 != 0 ) delete h2 ; if ( edge != 0 ) delete edge ; } _list_of_edges.clear() ; for( FaceIterator fit = faces_begin() ; fit != faces_end() ; ++fit ) { Face* face = *fit ; if ( face != 0 ) delete face ; } _list_of_faces.clear() ; return; }
void dcel::Surface< VAttrib, FAttrib, EAttrib, HAttrib >::add_edge | ( | Edge * | e | ) | [inline] |
Performs an insertion of an edge in the mesh.
e | A pointer of the edge to be inserted. |
Definition at line 345 of file surface.h.
References dcel::Surface< VAttrib, FAttrib, EAttrib, HAttrib >::_list_of_edges.
{ _list_of_edges.push_back(e); }
void dcel::Surface< VAttrib, FAttrib, EAttrib, HAttrib >::add_face | ( | Face * | f | ) | [inline] |
Performs an insertion of a face in the mesh.
f | A pointer of the face to be inserted. |
Definition at line 333 of file surface.h.
References dcel::Surface< VAttrib, FAttrib, EAttrib, HAttrib >::_list_of_faces.
{ _list_of_faces.push_back(f); }
void dcel::Surface< VAttrib, FAttrib, EAttrib, HAttrib >::add_vertex | ( | Vertex * | v | ) | [inline] |
Performs an insertion of a vertex in the mesh.
v | A pointer of the vertex to be inserted. |
Definition at line 321 of file surface.h.
References dcel::Surface< VAttrib, FAttrib, EAttrib, HAttrib >::_list_of_vertices.
{ _list_of_vertices.push_back(v); }
void dcel::Surface< VAttrib, FAttrib, EAttrib, HAttrib >::create_edges | ( | HMAP & | hmap | ) | [private] |
Creates the edges of this surface.
hmap | A dictionary for half-edge identifiers and pointers. |
Loop over the set of half-edges of this surface and, for each of them, create an edge (if the edge has not been created already) and update their edge and half-edge pointers, respectively.
If the edge pointer of the current half-edge has not been assigned an edge yet, do it now. Otherwise, skip to the next iteration.
Create a new edge and initializes its pointer to its first half-edge.
Initializes the edge pointer of the current half-edge.
Insert the newly created edge into the list of edges of this surface.
Get the half-edge vertex identifiers.
Initialize the edge pointer of the second half-edge.
Definition at line 736 of file surface.h.
References dcel::Edge< VAttrib, FAttrib, EAttrib, HAttrib >::set_second_halfedge().
{ for ( typename HMAP::iterator hit = hmap.begin(); hit != hmap.end(); ++hit ) { if ( hit->second->get_edge() == 0 ) { Edge* edge = new Edge( hit->second , 0 ) ; hit->second->set_edge( edge ) ; _list_of_edges.push_back( edge ) ; unsigned v1 = hit->first.first ; unsigned v2 = hit->first.second ; typename HMAP::iterator ait = hmap.find( std::make_pair( v2 , v1 ) ) ; if ( ait != hmap.end() ) { ait->second->set_edge( edge ) ; edge->set_second_halfedge( ait->second ) ; } } } return ; }
void dcel::Surface< VAttrib, FAttrib, EAttrib, HAttrib >::create_faces | ( | unsigned | nfaces, |
unsigned * | lfaces, | ||
HMAP & | hmap, | ||
VMAP & | vmap | ||
) | [private] |
Creates the faces and half-edges of this surface.
nfaces | The number of faces of this surface. |
lfaces | An array with the vertex identifiers of each face of this surface. |
hmap | A dictionary for half-edge identifiers and pointers. |
vmap | A dictionary for vertex identifiers and pointers. |
Loop over the array of face vertex identifiers and for each iteration i, create the i-th face ( i.e., a triangle) of this surface.
Create a face vertex counter.
Allocate memory for a new face.
Find the ID of the k-th vertex of the i-th face.
If k-th vertex cannot be found, throw an exception.
Allocate memory for the k-th half-edge.
Set the half-edge pointer of the vertex pointed by vertex.
Update the pointers to previous and next half-edges.
Set the pointer to the first half-edge of the i-th face.
Add information to the table of halfedge IDs.
Insert face into the list of faces of this surface.
Place in the list of vertices only the vertices that are the origin of some half-edge. The ones that are not should be ignored.
Definition at line 613 of file surface.h.
References dcel::Face< VAttrib, FAttrib, EAttrib, HAttrib >::set_halfedge(), dcel::Halfedge< VAttrib, FAttrib, EAttrib, HAttrib >::set_next(), and dcel::Halfedge< VAttrib, FAttrib, EAttrib, HAttrib >::set_prev().
{ for ( unsigned i = 0 ; i < nfaces ; i++ ) { unsigned j = 3 * i ; Face* face = new Face( 0 ) ; // // Create the three half-edges of the i-th face. // Halfedge* h[ 3 ] ; for ( unsigned k = 0 ; k < 3 ; k++ ) { typename VMAP::const_iterator vit = vmap.find( lfaces[ j + k ] ) ; assert( vit != vmap.end() ) ; Vertex* vertex = vit->second ; h[ k ] = new Halfedge( vertex , 0 , face , 0 , 0 ) ; vertex->set_halfedge( h[ k ] ) ; } h[ 0 ]->set_prev( h[ 2 ] ) ; h[ 2 ]->set_next( h[ 0 ] ) ; h[ 1 ]->set_prev( h[ 0 ] ) ; h[ 0 ]->set_next( h[ 1 ] ) ; h[ 2 ]->set_prev( h[ 1 ] ) ; h[ 1 ]->set_next( h[ 2 ] ) ; face->set_halfedge( h[ 0 ] ) ; for ( unsigned k = 0 ; k < 3 ; k++ ) { const unsigned v1 = lfaces[ j + k ] ; const unsigned v2 = lfaces[ j + ( ( k + 1 ) % 3 ) ] ; hmap.insert( std::make_pair( std::make_pair( v1 , v2 ) , h[ k ] ) ) ; } _list_of_faces.push_back( face ) ; } for ( typename VMAP::iterator vit = vmap.begin() ; vit != vmap.end() ; vit++ ) { if ( vit->second->get_halfedge() != 0 ) { _list_of_vertices.push_back( vit->second ) ; } else { delete vit->second ; vit->second = 0 ; } } return ; }
void dcel::Surface< VAttrib, FAttrib, EAttrib, HAttrib >::create_vertices | ( | unsigned | nverts, |
double * | lverts, | ||
VMAP & | vmap | ||
) | [private] |
Creates the vertices of this surface.
nverts | The number of vertices of this surface. |
lverts | An array with the vertex coordinates. |
vmap | A dictionary for vertex identifiers and pointers. |
nverts | The number of vertices of this surface. |
lverts | An array with the vertex coordinates. |
vmap | A dictionary with vertex identifiers and pointers. |
For each set of coordinates, ( x , y , z ), in the given array of coordinates, create a vertex element with the given coordinates.
Get the index of the first coordinate of the i-th vertex.
Allocate memory for the vertex.
Insert the vertex and its identifier into a dictionary.
EdgeIterator dcel::Surface< VAttrib, FAttrib, EAttrib, HAttrib >::edges_begin | ( | ) | const [inline] |
Returns an edge iterator set to the first edge of the list of edges of this surface.
Definition at line 251 of file surface.h.
References dcel::Surface< VAttrib, FAttrib, EAttrib, HAttrib >::_list_of_edges.
{ return _list_of_edges.begin() ; }
EdgeIterator dcel::Surface< VAttrib, FAttrib, EAttrib, HAttrib >::edges_end | ( | ) | const [inline] |
Returns an edge iterator set past the last edge of the list of edges of this surface.
Definition at line 295 of file surface.h.
References dcel::Surface< VAttrib, FAttrib, EAttrib, HAttrib >::_list_of_edges.
{ return _list_of_edges.end() ; }
FaceIterator dcel::Surface< VAttrib, FAttrib, EAttrib, HAttrib >::faces_begin | ( | ) | const [inline] |
Returns a face iterator set to the first face of the list of faces of this surface.
Definition at line 265 of file surface.h.
References dcel::Surface< VAttrib, FAttrib, EAttrib, HAttrib >::_list_of_faces.
{ return _list_of_faces.begin() ; }
FaceIterator dcel::Surface< VAttrib, FAttrib, EAttrib, HAttrib >::faces_end | ( | ) | const [inline] |
Returns a face iterator set past the last face of the list of faces of this surface.
Definition at line 309 of file surface.h.
References dcel::Surface< VAttrib, FAttrib, EAttrib, HAttrib >::_list_of_faces.
{ return _list_of_faces.end() ; }
unsigned dcel::Surface< VAttrib, FAttrib, EAttrib, HAttrib >::get_number_of_edges | ( | ) | const [inline] |
Returns the number of edges of this surface.
Definition at line 208 of file surface.h.
References dcel::Surface< VAttrib, FAttrib, EAttrib, HAttrib >::_list_of_edges.
{ return _list_of_edges.size() ; }
unsigned dcel::Surface< VAttrib, FAttrib, EAttrib, HAttrib >::get_number_of_faces | ( | ) | const [inline] |
Returns the number of faces of this surface.
Definition at line 221 of file surface.h.
References dcel::Surface< VAttrib, FAttrib, EAttrib, HAttrib >::_list_of_faces.
{ return _list_of_faces.size() ; }
unsigned dcel::Surface< VAttrib, FAttrib, EAttrib, HAttrib >::get_number_of_vertices | ( | ) | const [inline] |
Returns the number of vertices of this surface.
Definition at line 194 of file surface.h.
References dcel::Surface< VAttrib, FAttrib, EAttrib, HAttrib >::_list_of_vertices.
{ return _list_of_vertices.size() ; }
bool dcel::Surface< VAttrib, FAttrib, EAttrib, HAttrib >::is_consistent | ( | ) | const [private] |
Performs a topological consistency check in this surface.
Get the pointer to the first half-edge of the cycle of half-edges of the face.
Pointer to the first half-edge cannot be null.
Get the other two half-edges of the face.
Pointers to the next and previous half-edges cannot be null.
Pointers to face cannot be null.
Pointer to face must be the same.
Pointers to the previous and next must be consistent.
Pointers to origin vertices cannot be null.
Pointers to edges cannot be null.
Check edge pointers consistency.
Check mate half-edge pointers.
Get the pointer to one of the half-edges of the current vertex.
The half-edge pointer cannot be null.
The half-edge pointer to the origin vertex must agree with the pointer to the current vertex.
Get the next half-edge in a counterclowise traversal of the edges incident to the current vertex.
The half-edge pointer to the origin vertex must agree with the pointer to the current vertex.
Check the edge pointers.
Get the pointer to the first half-edge of the edge.
The pointer to the first half-edge cannot be null.
Check the edge pointer of the first half-edge.
Get the pointer to the second half-edge of the edge.
The pointer to the second half-edge cannot be null.
Check the edge pointer of the first half-edge.
The first and second half-edges cannot be the same.
The first and second half-edges must be mates of each other.
Definition at line 808 of file surface.h.
References dcel::Halfedge< VAttrib, FAttrib, EAttrib, HAttrib >::get_edge(), dcel::Halfedge< VAttrib, FAttrib, EAttrib, HAttrib >::get_face(), dcel::Edge< VAttrib, FAttrib, EAttrib, HAttrib >::get_first_halfedge(), dcel::Halfedge< VAttrib, FAttrib, EAttrib, HAttrib >::get_mate(), dcel::Halfedge< VAttrib, FAttrib, EAttrib, HAttrib >::get_next(), dcel::Halfedge< VAttrib, FAttrib, EAttrib, HAttrib >::get_origin(), dcel::Halfedge< VAttrib, FAttrib, EAttrib, HAttrib >::get_prev(), and dcel::Edge< VAttrib, FAttrib, EAttrib, HAttrib >::get_second_halfedge().
{ // // Check half-edge and face pointers. // for ( FaceIterator fit = faces_begin(); fit != faces_end() ; ++fit ) { Halfedge* h1 = ( *fit )->get_halfedge() ; if ( h1 == 0 ) return false ; Halfedge* h2 = h1->get_next() ; Halfedge* h3 = h1->get_prev() ; if ( ( h2 == 0 ) || ( h3 == 0 ) ) return false ; if ( ( h1->get_face() == 0 ) || ( h2->get_face() == 0 ) || ( h3->get_face() == 0 ) ) { return false ; } if ( ( h1->get_face() != h2->get_face() ) || ( h1->get_face() != h3->get_face() ) || ( h2->get_face() != h3->get_face() ) ) { return false ; } if ( h2->get_prev() != h1 ) return false ; if ( h3->get_next() != h1 ) return false ; if ( h2->get_next() != h3 ) return false ; if ( h3->get_prev() != h2 ) return false ; if ( h1->get_origin() == 0 ) return false ; if ( h2->get_origin() == 0 ) return false ; if ( h3->get_origin() == 0 ) return false ; if ( h1->get_edge() == 0 ) return false ; if ( h2->get_edge() == 0 ) return false ; if ( h3->get_edge() == 0 ) return false ; if ( ( h1 != h1->get_edge()->get_first_halfedge() ) && ( h1 != h1->get_edge()->get_second_halfedge() ) ) { return false ; } if ( ( h2 != h2->get_edge()->get_first_halfedge() ) && ( h2 != h2->get_edge()->get_second_halfedge() ) ) { return false ; } if ( ( h3 != h3->get_edge()->get_first_halfedge() ) && ( h3 != h3->get_edge()->get_second_halfedge() ) ) { return false ; } if ( h1->get_mate() == 0 ) return false ; if ( h2->get_mate() == 0 ) return false ; if ( h3->get_mate() == 0 ) return false ; if ( h1->get_mate()->get_mate() != h1 ) return false ; if ( h2->get_mate()->get_mate() != h2 ) return false ; if ( h3->get_mate()->get_mate() != h3 ) return false ; } // end of the for loop for checking faces. // // Check vertex pointers. // for ( VertexIterator vit = vertices_begin() ; vit != vertices_end() ; ++vit ) { Halfedge* h1 = ( *vit )->get_halfedge() ; if ( h1 == 0 ) return false ; if ( h1->get_origin() != *vit ) return false ; Halfedge* h2 = h1->get_prev()->get_mate() ; do { if ( h2->get_origin() != *vit ) { return false; } else { h2 = h2->get_prev()->get_mate() ; } } while ( h2 != h1) ; } // end of the for loop for checking vertices for( EdgeIterator eit = edges_begin(); eit != edges_end() ; ++eit ) { Halfedge* h1 = (*eit)->get_first_halfedge() ; if ( h1 == 0 ) return false ; if ( h1->get_edge() != *eit ) return false ; Halfedge* h2 = (*eit)->get_second_halfedge() ; if ( h2 == 0 ) return false ; if ( h2->get_edge() != *eit ) return false ; if ( h1 == h2 ) return false ; if ( ( h1 != h2->get_mate() ) || ( h2 != h1->get_mate() ) ) { return false ; } } // end of the for loop for checking edges return true; }
VertexIterator dcel::Surface< VAttrib, FAttrib, EAttrib, HAttrib >::vertices_begin | ( | ) | const [inline] |
Returns a vertex iterator set to the first vertex of the list of vertices of this surface.
Definition at line 236 of file surface.h.
References dcel::Surface< VAttrib, FAttrib, EAttrib, HAttrib >::_list_of_vertices.
{ return _list_of_vertices.begin() ; }
VertexIterator dcel::Surface< VAttrib, FAttrib, EAttrib, HAttrib >::vertices_end | ( | ) | const [inline] |
Returns a vertex iterator set past the last vertex of the list of vertices of this surface.
Definition at line 280 of file surface.h.
References dcel::Surface< VAttrib, FAttrib, EAttrib, HAttrib >::_list_of_vertices.
{ return _list_of_vertices.end() ; }