Эх сурвалжийг харах

boolean coplanar bug fix, now correct on A union A

Former-commit-id: 3510ec09265a69beea7f78cb918a99d441a6ca9f
Alec Jacobson 10 жил өмнө
parent
commit
952b776a5d

+ 4 - 4
include/igl/cgal/SelfIntersectMesh.h

@@ -1026,14 +1026,14 @@ inline void igl::SelfIntersectMesh<
   const Index total_shared_vertices = comb_shared_vertices + geo_shared_vertices;
   if(comb_shared_vertices== 3)
   {
-    // Combinatorially duplicate face, these should be removed by preprocessing
-    cerr<<REDRUM("Facets "<<fa<<" and "<<fb<<" are combinatorial duplicates")<<endl;
+    //// Combinatorially duplicate face, these should be removed by preprocessing
+    //cerr<<REDRUM("Facets "<<fa<<" and "<<fb<<" are combinatorial duplicates")<<endl;
     goto done;
   }
   if(total_shared_vertices== 3)
   {
-    // Geometrically duplicate face, these should be removed by preprocessing
-    cerr<<REDRUM("Facets "<<fa<<" and "<<fb<<" are geometrical duplicates")<<endl;
+    //// Geometrically duplicate face, these should be removed by preprocessing
+    //cerr<<REDRUM("Facets "<<fa<<" and "<<fb<<" are geometrical duplicates")<<endl;
     goto done;
   }
   //// SPECIAL CASES ARE BROKEN FOR COPLANAR TRIANGLES

+ 32 - 24
include/igl/outer_hull.cpp

@@ -103,7 +103,9 @@ IGL_INLINE void igl::outer_hull(
           di_I(fei,0) = di_I(fei,0) - 2.*M_PI;
         }
       }
-      di_I(fei,1) = f;
+      // This signing is very important to make sure different edges sort
+      // duplicate faces the same way, regardless of their orientations
+      di_I(fei,1) = (cons[fei]?1.:-1.)*f;
     }
     VectorXi IM;
 
@@ -189,7 +191,8 @@ IGL_INLINE void igl::outer_hull(
 #ifdef IGL_OUTER_HULL_DEBUG
   cout<<"outer facet: "<<f<<endl;
 #endif
-    int FHcount = 0;
+    int FHcount = 1;
+    FH[f] = true;
     // Q contains list of face edges to continue traversing upong
     queue<int> Q;
     Q.push(f+0*m);
@@ -215,15 +218,6 @@ IGL_INLINE void igl::outer_hull(
         continue;
       }
       EH[e] = true;
-      // first time seeing face
-      if(!FH[f])
-      {
-//#ifdef IGL_OUTER_HULL_DEBUG
-//      cout<<(f+1)<<endl;
-//#endif
-        FH[f] = true;
-        FHcount++;
-      }
       // source of edge according to f
       const int fs = flip(f)?F(f,(c+2)%3):F(f,(c+1)%3);
       // destination of edge according to f
@@ -250,28 +244,30 @@ IGL_INLINE void igl::outer_hull(
       // Loop once around trying to find suitable next face
       for(size_t step = 1; step<val+2;step++)
       {
-        nfei = (diIM(e) + 2*val + e_cons*step*(flip(f)?-1:1))%val;
-#ifdef IGL_OUTER_HULL_DEBUG
-        const int nf = uE2E[EMAP(e)][nfei] % m;
-#endif
+        const int nfei_new = (diIM(e) + 2*val + e_cons*step*(flip(f)?-1:1))%val;
+        const int nf = uE2E[EMAP(e)][nfei_new] % m;
         // Don't consider faces with identical dihedral angles
-        if(di[EMAP(e)][diIM(e)] != di[EMAP(e)][nfei])
+        if(di[EMAP(e)][diIM(e)] != di[EMAP(e)][nfei_new])
 //#warning "THIS IS HACK, FIX ME"
-//        if( abs(di[EMAP(e)][diIM(e)] - di[EMAP(e)][nfei]) < 1e-16 )
+//        if( abs(di[EMAP(e)][diIM(e)] - di[EMAP(e)][nfei_new]) < 1e-16 )
         {
 //#ifdef IGL_OUTER_HULL_DEBUG
 //        cout<<"Next facet: "<<(f+1)<<" --> "<<(nf+1)<<", |"<<
-//          di[EMAP(e)][diIM(e)]<<" - "<<di[EMAP(e)][nfei]<<"| = "<<
-//            abs(di[EMAP(e)][diIM(e)] - di[EMAP(e)][nfei])
+//          di[EMAP(e)][diIM(e)]<<" - "<<di[EMAP(e)][nfei_new]<<"| = "<<
+//            abs(di[EMAP(e)][diIM(e)] - di[EMAP(e)][nfei_new])
 //            <<endl;
 //#endif
+          // Only use this face if not already seen
+          if(!FH[nf])
+          {
+            nfei = nfei_new;
+          }
           break;
         }
-#ifdef IGL_OUTER_HULL_DEBUG
-        cout<<"Skipping co-planar facet: "<<(f+1)<<" --> "<<(nf+1)<<endl;
-#endif
+//#ifdef IGL_OUTER_HULL_DEBUG
+//        cout<<"Skipping co-planar facet: "<<(f+1)<<" --> "<<(nf+1)<<endl;
+//#endif
       }
-      const int max_ne_2 = uE2E[EMAP(e)][nfei];
 
       int max_ne = -1;
       //// Loop over and find max dihedral angle
@@ -332,12 +328,24 @@ IGL_INLINE void igl::outer_hull(
       //    }
       //  }
       //}
-      max_ne = max_ne_2;
+      if(nfei >= 0)
+      {
+        max_ne = uE2E[EMAP(e)][nfei];
+      }
 
       if(max_ne>=0)
       {
         // face of neighbor
         const int nf = max_ne%m;
+#ifdef IGL_OUTER_HULL_DEBUG
+        if(!FH[nf])
+        {
+          // first time seeing face
+          cout<<(f+1)<<" --> "<<(nf+1)<<endl;
+        }
+#endif
+        FH[nf] = true;
+        FHcount++;
         // corner of neighbor
         const int nc = max_ne/m;
         const int nd = F(nf,(nc+2)%3);

+ 4 - 0
include/igl/peel_outer_hull_layers.cpp

@@ -35,6 +35,10 @@ IGL_INLINE size_t igl::peel_outer_hull_layers(
 #ifdef IGL_PEEL_OUTER_HULL_LAYERS_DEBUG
   cout<<"peel outer hull layers..."<<endl;
 #endif
+#ifdef IGL_PEEL_OUTER_HULL_LAYERS_DEBUG
+  cout<<"calling outer hull..."<<endl;
+  writePLY(STR("peel-outer-hull-input.ply"),V,F);
+#endif
 
 #ifdef IGL_PEEL_OUTER_HULL_LAYERS_DEBUG
   cout<<"resize output ..."<<endl;