Browse Source

return bool

Former-commit-id: 17db44d78e495cb87d5f0edb6e23082ef62f33db
Alec Jacobson 9 years ago
parent
commit
ae23f4c773

+ 19 - 11
include/igl/copyleft/cgal/propagate_winding_numbers.cpp

@@ -34,11 +34,12 @@ template<
   typename DerivedF,
   typename DerivedL,
   typename DerivedW>
-IGL_INLINE void igl::copyleft::cgal::propagate_winding_numbers(
+IGL_INLINE bool igl::copyleft::cgal::propagate_winding_numbers(
     const Eigen::PlainObjectBase<DerivedV>& V,
     const Eigen::PlainObjectBase<DerivedF>& F,
     const Eigen::PlainObjectBase<DerivedL>& labels,
-    Eigen::PlainObjectBase<DerivedW>& W) {
+    Eigen::PlainObjectBase<DerivedW>& W) 
+{
 #ifdef PROPAGATE_WINDING_NUMBER_TIMING
   const auto & tictoc = []() -> double
   {
@@ -60,9 +61,11 @@ IGL_INLINE void igl::copyleft::cgal::propagate_winding_numbers(
   Eigen::VectorXi EMAP;
   std::vector<std::vector<size_t> > uE2E;
   igl::unique_edge_map(F, E, uE, EMAP, uE2E);
+  bool valid = true;
   if (!piecewise_constant_winding_number(F, uE, uE2E)) 
   {
     std::cerr << "Input mesh is not orientable!" << std::endl;
+    valid = false;
   }
 
   Eigen::VectorXi P;
@@ -138,26 +141,29 @@ IGL_INLINE void igl::copyleft::cgal::propagate_winding_numbers(
           Q.pop();
           int curr_label = cell_labels[curr_idx];
           for (const auto& neighbor : cell_adjacency[curr_idx]) {
-            if (cell_labels[std::get<0>(neighbor)] == 0) {
+            if (cell_labels[std::get<0>(neighbor)] == 0) 
+            {
               cell_labels[std::get<0>(neighbor)] = curr_label * -1;
               Q.push(std::get<0>(neighbor));
               parents[std::get<0>(neighbor)] = curr_idx;
-            } else {
-              if (cell_labels[std::get<0>(neighbor)] !=
-                  curr_label * -1) {
+            } else 
+            {
+              if (cell_labels[std::get<0>(neighbor)] != curr_label * -1) 
+              {
                 std::cerr << "Odd cell cycle detected!" << std::endl;
                 auto path = trace_parents(curr_idx);
                 path.reverse();
                 auto path2 = trace_parents(std::get<0>(neighbor));
-                path.insert(path.end(),
-                    path2.begin(), path2.end());
-                for (auto cell_id : path) {
+                path.insert(path.end(), path2.begin(), path2.end());
+                for (auto cell_id : path) 
+                {
                   std::cout << cell_id << " ";
                   std::stringstream filename;
                   filename << "cell_" << cell_id << ".ply";
                   save_cell(filename.str(), cell_id);
                 }
                 std::cout << std::endl;
+                valid = false;
               }
               // Do not fail when odd cycle is detected because the resulting
               // integer winding number field, although inconsistent, may still
@@ -249,7 +255,8 @@ IGL_INLINE void igl::copyleft::cgal::propagate_winding_numbers(
 #endif
 
   W.resize(num_faces, num_labels*2);
-  for (size_t i=0; i<num_faces; i++) {
+  for (size_t i=0; i<num_faces; i++) 
+  {
     const size_t patch = P[i];
     const size_t positive_cell = per_patch_cells(patch, 0);
     const size_t negative_cell = per_patch_cells(patch, 1);
@@ -261,9 +268,10 @@ IGL_INLINE void igl::copyleft::cgal::propagate_winding_numbers(
 #ifdef PROPAGATE_WINDING_NUMBER_TIMING
   log_time("store_result");
 #endif
+  return valid;
 }
 
 
 #ifdef IGL_STATIC_LIBRARY
-template void igl::copyleft::cgal::propagate_winding_numbers<Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
+template bool igl::copyleft::cgal::propagate_winding_numbers<Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
 #endif

+ 15 - 9
include/igl/copyleft/cgal/propagate_winding_numbers.h

@@ -19,11 +19,16 @@
 // clockwise facing facets should equal the number of counterclockwise facing
 // facets.
 
-namespace igl {
+namespace igl
+{
   namespace copyleft
   {
-    namespace cgal {
-
+    namespace cgal
+    {
+      // TODO: This shouldn't need to be in igl::copyleft::cgal, it should
+      // instead take as input an index of the ambient cell and the winding
+      // number vector there.
+      //
       // Compute winding number on each side of the face.  The input mesh
       // could contain multiple connected components.  The input mesh must
       // represent the boundary of a valid 3D volume, which means it is
@@ -33,23 +38,24 @@ namespace igl {
       //   V  #V by 3 list of vertex positions.
       //   F  #F by 3 list of triangle indices into V.
       //   labels  #F list of facet labels ranging from 0 to k-1.
-      //
       // Output:
       //   W  #F by k*2 list of winding numbers.  ``W(i,j*2)`` is the winding
       //      number on the positive side of facet ``i`` with respect to the
       //      facets labeled ``j``.  Similarly, ``W(i,j*2+1)`` is the winding
       //      number on the negative side of facet ``i`` with respect to the
       //      facets labeled ``j``.
+      // Returns true iff the input induces a piecewise-constant winding number
+      //   field.
       template<
         typename DerivedV,
         typename DerivedF,
         typename DerivedL,
         typename DerivedW>
-      IGL_INLINE void propagate_winding_numbers(
-          const Eigen::PlainObjectBase<DerivedV>& V,
-          const Eigen::PlainObjectBase<DerivedF>& F,
-          const Eigen::PlainObjectBase<DerivedL>& labels,
-          Eigen::PlainObjectBase<DerivedW>& W);
+      IGL_INLINE bool propagate_winding_numbers(
+        const Eigen::PlainObjectBase<DerivedV>& V,
+        const Eigen::PlainObjectBase<DerivedF>& F,
+        const Eigen::PlainObjectBase<DerivedL>& labels,
+        Eigen::PlainObjectBase<DerivedW>& W);
     }
   }
 }