Browse Source

outer hull

Former-commit-id: c8968e2eb7cadea1de0cb74e3d70e705d3b78e61
Alec Jacobson 9 years ago
parent
commit
332e02575a

+ 0 - 17
include/igl/copyleft/boolean/mesh_boolean.cpp

@@ -85,23 +85,6 @@ IGL_INLINE bool igl::copyleft::boolean::mesh_boolean(
       DerivedFC FF(FA.rows() + FB.rows(), 3);
       VV << VA, VB;
       FF << FA, FB.array() + VA.rows();
-      //// Handle annoying empty cases
-      //if(VA.size()>0)
-      //{
-      //  VV<<VA;
-      //}
-      //if(VB.size()>0)
-      //{
-      //  VV<<VB;
-      //}
-      //if(FA.size()>0)
-      //{
-      //  FF<<FA;
-      //}
-      //if(FB.size()>0)
-      //{
-      //  FF<<FB.array()+VA.rows();
-      //}
       resolve_fun(VV, FF, V, F, CJ);
   }
 #ifdef MESH_BOOLEAN_TIMING

+ 95 - 5
include/igl/copyleft/cgal/outer_hull.cpp

@@ -5,8 +5,101 @@
 // This Source Code Form is subject to the terms of the Mozilla Public License 
 // v. 2.0. If a copy of the MPL was not distributed with this file, You can 
 // obtain one at http://mozilla.org/MPL/2.0/.
-#include "points_inside_component.h"
 #include "outer_hull.h"
+#include "extract_cells.h"
+#include "remesh_self_intersections.h"
+#include "../../remove_unreferenced.h"
+
+template <
+  typename DerivedV,
+  typename DerivedF,
+  typename DerivedHV,
+  typename DerivedHF,
+  typename DerivedJ,
+  typename Derivedflip>
+IGL_INLINE void igl::copyleft::cgal::outer_hull(
+  const Eigen::PlainObjectBase<DerivedV> & V,
+  const Eigen::PlainObjectBase<DerivedF> & F,
+  Eigen::PlainObjectBase<DerivedHV> & HV,
+  Eigen::PlainObjectBase<DerivedHF> & HF,
+  Eigen::PlainObjectBase<DerivedJ> & J,
+  Eigen::PlainObjectBase<Derivedflip> & flip)
+{
+  // Exact types
+  typedef CGAL::Epeck Kernel;
+  typedef Kernel::FT ExactScalar;
+  typedef 
+    Eigen::Matrix<
+    ExactScalar,
+    Eigen::Dynamic,
+    Eigen::Dynamic,
+    DerivedHV::IsRowMajor> 
+      MatrixXES;
+  // Remesh self-intersections
+  MatrixXES Vr;
+  DerivedHF Fr;
+  DerivedJ Jr;
+  {
+    RemeshSelfIntersectionsParam params;
+    Eigen::VectorXi I;
+    Eigen::MatrixXi IF;
+    remesh_self_intersections(V, F, params, Vr, Fr, IF, Jr, I);
+    // Merge coinciding vertices into non-manifold vertices.
+    std::for_each(Fr.data(), Fr.data()+Fr.size(),
+      [&I](typename DerivedHF::Scalar& a) { a=I[a]; });
+      // Remove unreferenced vertices.
+    Eigen::VectorXi UIM;
+    remove_unreferenced(MatrixXES(Vr),DerivedHF(Fr), Vr, Fr, UIM);
+  }
+  // Extract cells for each face
+  Eigen::MatrixXi C;
+  extract_cells(Vr,Fr,C);
+  // Extract faces on ambient cell
+  int num_outer = 0;
+  for(int i = 0;i<C.rows();i++)
+  {
+    num_outer += ( C(i,0) == 0 || C(i,1) == 0 ) ? 1 : 0;
+  }
+  HF.resize(num_outer,3);
+  J.resize(num_outer,1);
+  flip.resize(num_outer,1);
+  {
+    int h = 0;
+    for(int i = 0;i<C.rows();i++)
+    {
+      if(C(i,0)==0)
+      {
+        HF.row(h) = Fr.row(i);
+        J(h) = Jr(i);
+        flip(h) = false;
+        h++;
+      }else if(C(i,1) == 0)
+      {
+        HF.row(h) = Fr.row(i).reverse();
+        J(h) = Jr(i);
+        flip(h) = true;
+        h++;
+      }
+    }
+    assert(h == num_outer);
+  }
+  // Remove unreferenced vertices and re-index faces
+  {
+    // Cast to output type
+    DerivedHV Vr_cast(Vr.rows(),Vr.cols());
+    for(int i = 0;i<Vr.rows();i++)
+    {
+      for(int j = 0;j<Vr.cols();j++)
+      {
+        assign_scalar(Vr(i,j), Vr_cast(i,j));
+      }
+    }
+    Eigen::VectorXi I;
+    remove_unreferenced(Vr_cast,DerivedHF(HF),HV,HF,I);
+  }
+}
+
+#include "points_inside_component.h"
 #include "order_facets_around_edges.h"
 #include "outer_facet.h"
 #include "../../sortrows.h"
@@ -16,10 +109,7 @@
 #include "../../unique_edge_map.h"
 #include "../../barycenter.h"
 #include "../../per_face_normals.h"
-#include "../../writePLY.h"
 #include "../../sort_angles.h"
-#include "../../writePLY.h"
-
 #include <Eigen/Geometry>
 #include <vector>
 #include <map>
@@ -35,7 +125,7 @@ template <
   typename DerivedG,
   typename DerivedJ,
   typename Derivedflip>
-IGL_INLINE void igl::copyleft::cgal::outer_hull(
+IGL_INLINE void igl::copyleft::cgal::outer_hull_legacy(
   const Eigen::PlainObjectBase<DerivedV> & V,
   const Eigen::PlainObjectBase<DerivedF> & F,
   Eigen::PlainObjectBase<DerivedG> & G,

+ 31 - 1
include/igl/copyleft/cgal/outer_hull.h

@@ -15,6 +15,32 @@ namespace igl
   {
     namespace cgal
     {
+      // Compute the "outer hull" of a piecewise constant winding number induce
+      // triangle mesh (V,F).
+      //
+      // Inputs:
+      //   V  #V by 3 list of vertex positions
+      //   F  #F by 3 list of triangle indices into V
+      // Outputs:
+      //   HV  #HV by 3 list of output vertex positions
+      //   HF  #HF by 3 list of output triangle indices into HV
+      //   J  #HF list of indices into F
+      //   flip  #HF list of whether facet was flipped when added to HF
+      //
+      template <
+        typename DerivedV,
+        typename DerivedF,
+        typename DerivedHV,
+        typename DerivedHF,
+        typename DerivedJ,
+        typename Derivedflip>
+      IGL_INLINE void outer_hull(
+        const Eigen::PlainObjectBase<DerivedV> & V,
+        const Eigen::PlainObjectBase<DerivedF> & F,
+        Eigen::PlainObjectBase<DerivedHV> & HV,
+        Eigen::PlainObjectBase<DerivedHF> & HF,
+        Eigen::PlainObjectBase<DerivedJ> & J,
+        Eigen::PlainObjectBase<Derivedflip> & flip);
       // Compute the "outer hull" of a potentially non-manifold mesh (V,F) whose
       // intersections have been "resolved" (e.g. using `cork` or
       // `igl::copyleft::cgal::selfintersect`). The outer hull is defined to be all facets
@@ -24,6 +50,10 @@ namespace igl
       // "flaps".  This implementation largely follows Section 3.6 of "Direct
       // repair of self-intersecting meshes" [Attene 2014].
       //
+      // Note: This doesn't require the input mesh to be piecewise constant
+      // winding number, but won't handle multiple non-nested connected
+      // components.
+      //
       // Inputs:
       //   V  #V by 3 list of vertex positions
       //   F  #F by 3 list of triangle indices into V
@@ -38,7 +68,7 @@ namespace igl
         typename DerivedG,
         typename DerivedJ,
         typename Derivedflip>
-      IGL_INLINE void outer_hull(
+      IGL_INLINE void outer_hull_legacy(
         const Eigen::PlainObjectBase<DerivedV> & V,
         const Eigen::PlainObjectBase<DerivedF> & F,
         Eigen::PlainObjectBase<DerivedG> & G,