MeshKit  1.0
DualGraph.hpp
Go to the documentation of this file.
00001 
00002 //
00003 //  Description:  Construct Dual Graph of from a Mesh. The dual of a triangle
00004 //  ************  is its centroid.
00005 //  Dual Graph can be represented as Node-Node Adjacency or through explcitly 
00006 //  creating and storing the edges. When Adjacency is set to (1,0)  Edges are created 
00007 //  and stored. When Adjacency is set to (0,0)  Node-Node relationships are stored.
00008 //
00009 //  Chaman Singh Verma
00010 //  Department of Computer Sciences,
00011 //  University of Wisconsin Madison.
00012 //  Date 15th Jan 2010.
00013 //
00014 //  License:  Free to download and modify. 
00015 //
00017 
00018 #ifndef DUALGRAPH_H
00019 #define DUALGRAPH_H
00020 
00021 #include "meshkit/Mesh.hpp"
00022 
00023 namespace Jaal {
00024 
00025 class DualGraph
00026 {
00027 public:
00028   static PNode getNewDualNode(Face *f);
00029 
00030   DualGraph()
00031   {
00032     adjTable[0][0] = 1;
00033   }
00034 
00035   ~DualGraph()
00036   {
00037     clear();
00038   }
00039 
00040   void setAdjTable(int src, int dst)
00041   {
00042     if (src == 0 && dst == 0)
00043     {
00044       if (adjTable[1][0])
00045         node_node_adjacency_rep();
00046       return;
00047     }
00048 
00049     if (src == 1 && dst == 0)
00050     {
00051       if (adjTable[0][0])
00052         edge_rep();
00053       return;
00054     }
00055   }
00056 
00057   size_t getSize(int d) const
00058   {
00059     if (d == 0)
00060       return nodes.size();
00061     if (d == 1)
00062       return edges.size();
00063     return 0;
00064   }
00065 
00066   int build(Mesh *m);
00067 
00068   const PNode &getNode(int i) const
00069   {
00070     return nodes[i];
00071   }
00072 
00073   const PEdge &getEdge(int i) const
00074   {
00075     assert(adjTable[1][0]);
00076     return edges[i];
00077   }
00078 
00079   void saveAs(const string &s)
00080   {
00081     writeNodes(s);
00082     writeEdges(s);
00083   }
00084 
00085   void clear()
00086   {
00087       nodes.clear();
00088       edges.clear();
00089   }
00090 
00091   void deleteAll()
00092   {
00093     size_t nSize;
00094 
00095     nSize = nodes.size();
00096     for (size_t i = 0; i < nSize; i++)
00097       delete nodes[i];
00098     nodes.clear();
00099 
00100     nSize = edges.size();
00101     for (size_t i = 0; i < nSize; i++)
00102       delete edges[i];
00103     edges.clear();
00104   }
00105 
00106 private:
00107   char adjTable[4][4];
00108 
00109   Mesh *mesh;
00110 
00111   void node_node_adjacency_rep();
00112   void edge_rep();
00113 
00114   NodeSequence  nodes;
00115   EdgeSequence  edges;
00116 
00117   void addEdge(const PNode n1, const PNode n2);
00118   void getCentroid(int faceid, Point3D &p);
00119   void writeNodes(const string &s);
00120   void writeEdges(const string &s);
00121 };
00122 
00123 inline
00124 void DualGraph::addEdge(const PNode v1, const PNode v2)
00125 {
00126   v1->addRelation(v2);
00127   v2->addRelation(v1);
00128 }
00129 
00130 inline 
00131 PNode DualGraph::getNewDualNode(Face *face) 
00132 {
00133   PNode dualnode = Vertex::newObject();
00134   Point3D p3d;
00135   face->getAvgPos( p3d );
00136   dualnode->setXYZCoords(p3d);
00137 
00138   face->setAttribute("DualNode", dualnode);
00139   dualnode->setAttribute("PrimalFace", face);
00140 
00141   return dualnode;
00142 }
00143 
00144 
00145 } // namespace Jaal
00146 
00147 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines