Browse Source

fixed compilation errors in tt and edge topology, added basic example of usage

dpanozzo 13 years ago
parent
commit
ae6d6b9bc8
5 changed files with 117 additions and 40 deletions
  1. 18 26
      edgetopology.h
  2. 61 0
      example1.cpp
  3. 8 7
      ismanifold.h
  4. 20 0
      main.cpp
  5. 10 7
      tt.h

+ 18 - 26
edgetopology.h

@@ -8,21 +8,24 @@
 
 #include <Eigen/Core>
 #include <string>
+#include <ismanifold.h>
+
+#include <vector>
 
 namespace igl 
 {
     // Initialize Edges and their topological relations
     
     // Output:
-    // E  : #Ex2, Stores the edge description as pair of indices to vertices
+    // EV  : #Ex2, Stores the edge description as pair of indices to vertices
     // FE : #Fx3, Stores the Triangle-Edge relation
     // EF : #Ex2: Stores the Edge-Triangle relation (unsorted)
 
     void edgetopology(Eigen::MatrixXd& V, Eigen::MatrixXi& F, 
-                      Eigen::MatrixXi& E, Eigen::MatrixXi& FE, Eigen::MatrixXi& EF)
+                      Eigen::MatrixXi& EV, Eigen::MatrixXi& FE, Eigen::MatrixXi& EF)
     {
-        assert(isManifold());
-        vector<vector<int> > ETT;
+        assert(igl::isManifold(V,F));
+        std::vector<std::vector<int> > ETT;
         for(int f=0;f<F.rows();++f)
             for (int i=0;i<3;++i)
             {
@@ -30,7 +33,7 @@ namespace igl
                 int v1 = F(f,i);
                 int v2 = F(f,(i+1)%3);
                 if (v1 > v2) std::swap(v1,v2);
-                vector<int> r(4);
+                std::vector<int> r(4);
                 r[0] = v1; r[1] = v2;
                 r[2] = f;  r[3] = i;
                 ETT.push_back(r);
@@ -43,22 +46,11 @@ namespace igl
             if (!((ETT[i][0] == ETT[i+1][0]) && (ETT[i][1] == ETT[i+1][1])))
                 ++En;
         
-        E  = MatrixXi::Constant((int)(En),2,-1);
-        FE = MatrixXi::Constant((int)(F.rows()),3,-1);
-        EF = MatrixXi::Constant((int)(En),2,-1);
+        EV  = Eigen::MatrixXi::Constant((int)(En),2,-1);
+        FE = Eigen::MatrixXi::Constant((int)(F.rows()),3,-1);
+        EF = Eigen::MatrixXi::Constant((int)(En),2,-1);
         En = 0;
         
-        for(int i=0;i<ETT.size();++i)
-        {
-            
-            for(int j=0;j<ETT[i].size();++j)
-            {
-                cerr << ETT[i][j] << "\t\t";
-            }
-            cerr << endl;
-        }
-        
-        
         for(int i=0;i<ETT.size();++i)
         {
             if (i == ETT.size()-1 ||
@@ -66,18 +58,18 @@ namespace igl
                 )
             {
                 // Border edge
-                vector<int>& r1 = ETT[i];
-                E(En,0)         = r1[0];
-                E(En,1)         = r1[1];
+                std::vector<int>& r1 = ETT[i];
+                EV(En,0)         = r1[0];
+                EV(En,1)         = r1[1];
                 EF(En,0)        = r1[2];
                 FE(r1[2],r1[3]) = En;
             } 
             else
             {
-                vector<int>& r1 = ETT[i];
-                vector<int>& r2 = ETT[i+1];
-                E(En,0)         = r1[0];
-                E(En,1)         = r1[1];
+                std::vector<int>& r1 = ETT[i];
+                std::vector<int>& r2 = ETT[i+1];
+                EV(En,0)         = r1[0];
+                EV(En,1)         = r1[1];
                 EF(En,0)        = r1[2];
                 EF(En,1)        = r2[2];
                 FE(r1[2],r1[3]) = En;

+ 61 - 0
example1.cpp

@@ -0,0 +1,61 @@
+//
+//  IGL Lib - Simple C++ mesh library 
+//
+//  Copyright 2011, Daniele Panozzo. All rights reserved.
+
+// IMPORTANT DO NOT REMOVE OR MOVE
+#define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET 
+
+#include <iostream>
+#include <string>
+#include <read.h>
+#include <write.h>
+#include <cotmatrix.h>
+#include <tt.h>
+#include <edgetopology.h>
+
+using namespace std;
+
+int main (int argc, const char * argv[])
+{
+    Eigen::MatrixXd V;
+    Eigen::MatrixXi F;
+    igl::read(string(argv[1]),V,F);
+
+    std::cout << "Mesh loaded!\n";
+    cout << "Vertex Array:" << endl;
+    cout << V << endl;
+    cout << "-------------" << endl;
+    cout << "Face Array:" << endl;
+    cout << F << endl;
+    cout << "-------------" << endl;
+
+    cout << "CotMatrix:" << endl;
+    Eigen::SparseMatrix<double> L;
+    igl::cotmatrix(V,F,L);
+    cout << L << endl;
+    cout << "-------------" << endl;
+    
+    igl::write(string(argv[2]),V,F);
+    
+    // Face Topology
+    cout << "TT Topology:" << endl;
+    Eigen::MatrixXi TT;
+    igl::tt(V,F,TT);
+    cout << TT << endl;
+    cout << "-------------" << endl;
+
+    // Edge Topology
+    cout << "Edge Topology:" << endl;
+    Eigen::MatrixXi EV;
+    Eigen::MatrixXi FE;
+    Eigen::MatrixXi EF;
+    
+    igl::edgetopology(V,F,EV,FE, EF);
+    cout << EV << endl << FE << endl << EF << endl;
+    cout << "-------------" << endl;
+    
+    
+    return 0;
+}
+

+ 8 - 7
ismanifold.h

@@ -9,12 +9,14 @@
 #include <Eigen/Core>
 #include <string>
 
+#include <vector>
+
 namespace igl 
 {
     // check if the mesh is edge-manifold
-    bool isManifold(Eigen::MatrixXd& V, Eigen::MatrixXd& F)
+    bool isManifold(Eigen::MatrixXd& V, Eigen::MatrixXi& F)
     {
-        vector<vector<int> > TTT;
+        std::vector<std::vector<int> > TTT;
         for(int f=0;f<F.rows();++f)
             for (int i=0;i<3;++i)
             {
@@ -22,19 +24,18 @@ namespace igl
                 int v1 = F(f,i);
                 int v2 = F(f,(i+1)%3);
                 if (v1 > v2) std::swap(v1,v2);
-                vector<int> r(4);
+                std::vector<int> r(4);
                 r[0] = v1; r[1] = v2;
                 r[2] = f;  r[3] = i;
                 TTT.push_back(r);
             }
         std::sort(TTT.begin(),TTT.end());
-        TT = MatrixXi::Constant((int)(F.rows()),3,-1);
         
         for(int i=2;i<TTT.size();++i)
         {
-            vector<int>& r1 = TTT[i-2];
-            vector<int>& r2 = TTT[i-1];
-            vector<int>& r3 = TTT[i];
+            std::vector<int>& r1 = TTT[i-2];
+            std::vector<int>& r2 = TTT[i-1];
+            std::vector<int>& r3 = TTT[i];
             if ( (r1[0] == r2[0] && r2[0] == r3[0]) 
                 && 
                 (r1[1] == r2[1] && r2[1] == r3[1]) )

+ 20 - 0
main.cpp

@@ -11,6 +11,8 @@
 #include <read.h>
 #include <write.h>
 #include <cotmatrix.h>
+#include <tt.h>
+#include <edgetopology.h>
 
 using namespace std;
 
@@ -36,6 +38,24 @@ int main (int argc, const char * argv[])
     
     igl::write(string(argv[2]),V,F);
     
+    // Face Topology
+    cout << "TT Topology:" << endl;
+    Eigen::MatrixXi TT;
+    igl::tt(V,F,TT);
+    cout << TT << endl;
+    cout << "-------------" << endl;
+
+    // Edge Topology
+    cout << "Edge Topology:" << endl;
+    Eigen::MatrixXi EV;
+    Eigen::MatrixXi FE;
+    Eigen::MatrixXi EF;
+    
+    igl::edgetopology(V,F,EV,FE, EF);
+    cout << EV << endl << FE << endl << EF << endl;
+    cout << "-------------" << endl;
+    
+    
     return 0;
 }
 

+ 10 - 7
tt.h

@@ -8,14 +8,17 @@
 
 #include <Eigen/Core>
 #include <string>
+#include <ismanifold.h>
+
+#include <vector>
 
 namespace igl 
 {
     // Compute triangle-triangle adjacency
-    void tt(Eigen::MatrixXd& V, Eigen::MatrixXd& F, Eigen::MatrixXd& TT)
+    void tt(Eigen::MatrixXd& V, Eigen::MatrixXi& F, Eigen::MatrixXi& TT)
     {
-        assert(isManifold());
-        vector<vector<int> > TTT;
+        assert(igl::isManifold(V,F));
+        std::vector<std::vector<int> > TTT;
         for(int f=0;f<F.rows();++f)
             for (int i=0;i<3;++i)
             {
@@ -23,18 +26,18 @@ namespace igl
                 int v1 = F(f,i);
                 int v2 = F(f,(i+1)%3);
                 if (v1 > v2) std::swap(v1,v2);
-                vector<int> r(4);
+                std::vector<int> r(4);
                 r[0] = v1; r[1] = v2;
                 r[2] = f;  r[3] = i;
                 TTT.push_back(r);
             }
         std::sort(TTT.begin(),TTT.end());
-        TT = MatrixXi::Constant((int)(F.rows()),3,-1);
+        TT = Eigen::MatrixXi::Constant((int)(F.rows()),3,-1);
         
         for(int i=1;i<TTT.size();++i)
         {
-            vector<int>& r1 = TTT[i-1];
-            vector<int>& r2 = TTT[i];
+            std::vector<int>& r1 = TTT[i-1];
+            std::vector<int>& r2 = TTT[i];
             if ((r1[0] == r2[0]) && (r1[1] == r2[1]))
             {
                 TT(r1[2],r1[3]) = r2[2];