Mesh.h

Go to the documentation of this file.
00001 
00006 #ifndef MESH_CM
00007 #define MESH_CM
00008 #include <vector>
00009 #include <set>
00010 #include <iostream>
00011 
00012 #include "Edge.h"
00013 #include "Face.h"
00014 #include "Vertex.h"
00015 
00020 class Mesh
00021 {
00022 private:
00027    struct edge_comp {
00028       edge_comp() {}
00029       bool operator()( const Edge *e1, const Edge *e2 ) const {
00030           int b1 = e1->vertex->ID, t1 = e1->pair->vertex->ID;
00031           int b2 = e2->vertex->ID, t2 = e2->pair->vertex->ID; 
00032 
00033           int min1, min2, max1, max2;
00034           min1 = std::min(b1, t1); min2 = std::min(b2, t2);
00035           max1 = std::max(b1, t1); max2 = std::max(b2, t2);
00036           if (min1 == min2 && max1 == max2){
00037              if (b1 < b2) return true;
00038              return (b1 == b2 && t1 < t2);
00039           }
00040           if (min1 < min2)     return true;
00041           return (min1 == min2 && max1 < max2);       
00042       }
00043    };
00044 
00045 
00046    std::vector<Vertex *> vertices;
00047    std::vector<Face *> faces;
00048    std::multiset<Edge*, Mesh::edge_comp> edges;
00049 
00050 public:
00051 
00053    int numBoundaryVertices;
00054 
00056    int numBoundaryLoops;
00058    int numConnectedComponents;
00059 
00061    int numGenus;
00062 
00063    typedef std::multiset<Edge*, Mesh::edge_comp>  EdgeSet;
00064    typedef std::vector<Face *> FaceSet;
00065    typedef std::vector<Vertex *> VertexSet;
00066 
00067    Mesh(void);
00068    ~Mesh(void);
00069    void clear();
00070 
00071    Vertex * addVertex(const Vector3 & p);
00072    Face * addFace(std::vector<int> faceVerts);
00073    Edge * addEdge(int i, int j);
00074    Edge * addEdge(Edge * e) {
00075       edges.insert(e);
00076       return e;
00077    }
00078 
00079    bool cutAlongEdge(Edge * forward);
00080 
00081    inline Vertex * vertexAt (int i) {return vertices[i];}
00082    inline Face * faceAt (int i) {return faces[i];}
00083 
00084    inline int numFaces()     { return (int)faces.size();    }
00085    inline int numVertices()  { return (int)vertices.size(); }
00086    inline int numEdges()     { return (int)edges.size()/2;  }
00087    inline int numBoundary()  { return numBoundaryVertices;  }
00088 
00089    void linkBoundary();
00090    bool checkManifold();
00091    bool checkVertexConection();
00092    void checkGaussianCurvature();
00093 
00103    void computeMeshInfo();
00104 
00105    void computeLengths();
00106    void computeInitAngles();
00107 
00108    void readOBJ(const char * obj_file);
00109    void readCON(const char * conn_file);
00110    void readCONE_VERT(const char * vert_file);
00111    void readCUT_EDGES(const char * edge_file);
00112    void writeOBJ(const char * obj_file);
00113    void writeVT(const char * vt_file);
00114    void writeCON(const char * conn_file);
00115 
00116    void finishMesh() {
00117       linkBoundary();
00118       checkManifold();
00119       checkVertexConection();
00120       std::cout << "*--------------------*" << std::endl;               
00121       std::cout << "* Faces:    " << numFaces() << std::endl;           
00122       std::cout << "* Edges:    " << numEdges() << std::endl;           
00123       std::cout << "* Vertices: " << numVertices() << std::endl;                 
00124       std::cout << "*--------------------*\n" << std::endl;             
00125    }
00126 
00127    class FaceIterator {
00128    private:
00129       FaceSet::iterator fIter;
00130       FaceSet * facesPtr;
00131    public:
00132       FaceIterator() {
00133           facesPtr = NULL;
00134       }
00135 
00136       FaceIterator(FaceSet * _faces) {
00137           facesPtr = _faces;
00138           fIter = _faces->begin();
00139       }
00140       FaceIterator& operator++( void ){
00141           fIter++;
00142           return *this;
00143       }
00144       FaceIterator operator++( int ){
00145           FaceIterator r = *this; ++*this; return r;
00146       }
00147       FaceIterator& operator--( void ){
00148           fIter--;
00149           return *this;
00150       }
00151       FaceIterator operator--( int ){
00152           FaceIterator r = *this; --*this; return r;
00153       }
00154 
00155       Face * face( void ) const { return *fIter; }
00156       //Face * & face( void )     { return *fIter; }
00157 
00158       void reset() {fIter = facesPtr->begin(); }
00159       bool end(void) { return fIter == facesPtr->end();
00160       ;}
00161    };
00162 
00163    class VertexIterator {
00164    private:
00165       VertexSet::iterator vIter;
00166       VertexSet * verticesPtr;
00167    public:
00168       VertexIterator() {
00169           verticesPtr = NULL;
00170       }
00171 
00172       VertexIterator(VertexSet * _vertices) {
00173           vIter = _vertices->begin();
00174           verticesPtr = _vertices;
00175       }
00176       VertexIterator& operator++( void ){
00177           vIter++;
00178           return *this;
00179       }
00180       VertexIterator operator++( int ){
00181           VertexIterator r = *this; ++*this; return r;
00182       }
00183       VertexIterator& operator--( void ){
00184           vIter--;
00185           return *this;
00186       }
00187       VertexIterator operator--( int ){
00188           VertexIterator r = *this; --*this; return r;
00189       }
00190 
00191       Vertex * vertex( void ) const { return *vIter; }
00192       //Vertex * & vertex( void )     { return *vIter; }
00193 
00194       void reset() {vIter = verticesPtr->begin();}
00195       bool end(void) { return vIter == verticesPtr->end();}
00196    };
00197 
00198    class HalfEdgeIterator {
00199    private:
00200       EdgeSet::iterator eIter;
00201       EdgeSet * edgesPtr;
00202    public:
00203       HalfEdgeIterator() {
00204           edgesPtr = NULL;
00205       }
00206       HalfEdgeIterator(EdgeSet * _edges) {
00207           eIter = _edges->begin();
00208           edgesPtr = _edges;
00209       }
00210       HalfEdgeIterator& operator++( void ){
00211           eIter++;
00212           return *this;
00213       }
00214       HalfEdgeIterator operator++( int ){
00215           HalfEdgeIterator r = *this; ++*this; return r;
00216       }
00217       HalfEdgeIterator& operator--( void ){
00218           eIter--;
00219           return *this;
00220       }
00221       HalfEdgeIterator operator--( int ){
00222           HalfEdgeIterator r = *this; --*this; return r;
00223       }
00224 
00225       Edge * half_edge( void ) const { return *eIter; }
00226       //          Edge * & operator*( void )     { return *eIter; }
00227 
00228       void find (Edge * eTmp) {
00229           eIter = edgesPtr->find(eTmp);
00230       }
00231 
00232       void reset() {eIter = edgesPtr->begin(); }
00233       bool end (void) { return eIter == edgesPtr->end();}
00234    };
00235 
00236    class EdgeIterator {
00237    private:
00238       EdgeSet::iterator eIter;
00239       EdgeSet * edgesPtr;
00240 
00241    public:
00242       EdgeIterator() {
00243           edgesPtr = NULL;
00244       }
00245 
00246       EdgeIterator(EdgeSet * _edges) {
00247           eIter = _edges->begin();
00248           edgesPtr = _edges;
00249       }
00250       EdgeIterator& operator++( void ){
00251           eIter++; eIter++;
00252           return *this;
00253       }
00254       EdgeIterator operator++( int ){
00255           EdgeIterator r = *this; ++*this; return r;
00256       }
00257       EdgeIterator& operator--( void ){
00258           eIter--; eIter--;
00259           return *this;
00260       }
00261       EdgeIterator operator--( int ){
00262           EdgeIterator r = *this; --*this; return r;
00263       }
00264 
00265       Edge * edge( void ) const { return *eIter; }
00266       //          Edge * & operator*( void )     { return *eIter; }
00267 
00268       void reset() {eIter = edgesPtr->begin(); }
00269       bool end(void) { return eIter == edgesPtr->end();}
00270    };
00271 
00272 
00273 
00274    FaceIterator faceIterator() {return FaceIterator(&faces);}
00275    VertexIterator vertexIterator() {return VertexIterator(&vertices);}
00276    HalfEdgeIterator halfEdgeIterator() {return HalfEdgeIterator(&edges);}
00277    EdgeIterator edgeIterator() {return EdgeIterator(&edges);}
00278 };
00279 #endif
00280 

Generated on Sat Jun 3 13:33:42 2006 for CirclePatterns by  doxygen 1.4.5