Selaa lähdekoodia

added removeUnreferenced and fixes in removeDuplicates

Former-commit-id: 5f6ae99f8b413a7cd911008f092d90a80dbf1d16
dpanozzo 13 vuotta sitten
vanhempi
commit
d95047cbdd
2 muutettua tiedostoa jossa 79 lisäystä ja 2 poistoa
  1. 1 2
      removeDuplicates.h
  2. 78 0
      removeUnreferenced.h

+ 1 - 2
removeDuplicates.h

@@ -29,7 +29,6 @@ namespace igl
 // Implementation
 inline void igl::removeDuplicates(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F, Eigen::MatrixXd &NV, Eigen::MatrixXi &NF, Eigen::VectorXi &I, const double epsilon = 2.2204e-15)
 {
-  assert (V.cols() == 3);
   assert (F.cols() == 3);
   
   //// build collapse map
@@ -42,7 +41,7 @@ inline void igl::removeDuplicates(const Eigen::MatrixXd &V, const Eigen::MatrixX
   for (int i =0; i <n; ++i)
     VISITED[i] = false;
   
-  NV = Eigen::MatrixXd(n,3);
+  NV = Eigen::MatrixXd(n,V.cols());
   int count = 0;
   Eigen::VectorXd d(n);
   for (int i =0; i <n; ++i)

+ 78 - 0
removeUnreferenced.h

@@ -0,0 +1,78 @@
+//
+//  removeUnreferenced.h
+//  Preview3D
+//
+//  Created by Daniele Panozzo on 17/11/11.
+
+#ifndef RemoveUnreferenced_h
+#define RemoveUnreferenced_h
+
+#include <Eigen/Core>
+namespace igl 
+{
+  // [ NV, NF ] = removeUnreferenced( V,F,epsilon )
+  // Remove unreferenced vertices from V, updating F accordingly
+  //
+  // Input:
+  // V,F: mesh description
+  //
+  // Output:
+  // NV, NF: new mesh without unreferenced vertices
+  
+  void removeUnreferenced(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F, Eigen::MatrixXd &NV, Eigen::MatrixXi &NF, Eigen::VectorXi &I);
+  
+}
+
+// Implementation
+inline void igl::removeUnreferenced(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F, Eigen::MatrixXd &NV, Eigen::MatrixXi &NF, Eigen::VectorXi &I)
+{
+
+  // Mark referenced vertices
+  Eigen::MatrixXi mark = Eigen::MatrixXi::Zero(V.rows(),1);
+  
+  for(int i=0; i<F.rows(); ++i)
+  {
+    for(int j=0; j<F.cols(); ++j)
+    {
+      if (F(i,j) != -1)
+        mark(F(i,j),0) = 1;
+    }
+  }
+  
+  // Sum the occupied cells 
+  int newsize = mark.sum();
+  
+  NV = Eigen::MatrixXd(newsize,V.cols());
+  NF = Eigen::MatrixXi(F.rows(),F.cols());
+  I  = Eigen::MatrixXi(V.rows(),1);
+  
+  // Do a pass on the marked vector and remove the unreferenced vertices
+  int count = 0;
+  for(int i=0;i<mark.rows();++i)
+  {
+    if (mark(i) == 1)
+    {
+      NV.row(count) = V.row(i);
+      I(i) = count;
+      count++;
+    }
+    else
+    {
+      I(i) = -1;
+    }
+  }
+  
+  // Apply I on F
+      
+  count = 0;
+  for (int i =0; i<F.rows(); ++i)
+  {
+    int v0 = I[F(i,0)];
+    int v1 = I[F(i,1)];
+    int v2 = I[F(i,2)];
+    if ( (v0 != v1) && (v2 != v1) && (v0 != v2) )
+      NF.row(count++) << v0, v1, v2;
+  }
+}
+
+#endif