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

wrapper with iteration parameters

Former-commit-id: b25c991b3067f14cd2c681b9f08a559f5e2977e0
Alec Jacobson 8 жил өмнө
parent
commit
e5d51c1db0

+ 34 - 10
include/igl/bijective_composite_harmonic_mapping.cpp

@@ -11,6 +11,7 @@
 #include "doublearea.h"
 #include "harmonic.h"
 //#include "matlab/MatlabWorkspace.h"
+#include <iostream>
 
 template <
   typename DerivedV,
@@ -24,13 +25,31 @@ IGL_INLINE bool igl::bijective_composite_harmonic_mapping(
   const Eigen::MatrixBase<Derivedb> & b,
   const Eigen::MatrixBase<Derivedbc> & bc,
   Eigen::PlainObjectBase<DerivedU> & U)
+{
+  return bijective_composite_harmonic_mapping(V,F,b,bc,1,200,20,true,U);
+}
+
+template <
+  typename DerivedV,
+  typename DerivedF,
+  typename Derivedb,
+  typename Derivedbc,
+  typename DerivedU>
+IGL_INLINE bool igl::bijective_composite_harmonic_mapping(
+  const Eigen::MatrixBase<DerivedV> & V,
+  const Eigen::MatrixBase<DerivedF> & F,
+  const Eigen::MatrixBase<Derivedb> & b,
+  const Eigen::MatrixBase<Derivedbc> & bc,
+  const int min_steps,
+  const int max_steps,
+  const int num_inner_iters,
+  const bool test_for_flips,
+  Eigen::PlainObjectBase<DerivedU> & U)
 {
   typedef typename Derivedbc::Scalar Scalar;
   assert(V.cols() == 2 && bc.cols() == 2 && "Input should be 2D");
   assert(F.cols() == 3 && "F should contain triangles");
   int tries = 0;
-  const int min_steps = 1;
-  const int max_steps = 64;
   int nsteps = min_steps;
   Derivedbc bc0;
   slice(V,b,1,bc0);
@@ -54,8 +73,7 @@ IGL_INLINE bool igl::bijective_composite_harmonic_mapping(
       // components.
       Derivedbc bct = bc0 + t*(bc - bc0);
       // Compute dsicrete harmonic map using metric of previous step
-      const int ninnersteps = 8;
-      for(int iter = 0;iter<8;iter++)
+      for(int iter = 0;iter<num_inner_iters;iter++)
       {
         //std::cout<<nsteps<<" t: "<<t<<" iter: "<<iter;
         //igl::matlab::MatlabWorkspace mw;
@@ -65,13 +83,16 @@ IGL_INLINE bool igl::bijective_composite_harmonic_mapping(
         //mw.save(bct,"bct");
         //mw.write("numerical.mat");
         harmonic(DerivedU(U),F,b,bct,1,U);
-        Eigen::Matrix<Scalar,Eigen::Dynamic,1> A;
-        doublearea(U,F,A);
-        flipped = (A.array() < 0 ).count();
-        //std::cout<<"  "<<flipped<<"  nan? "<<(U.array() != U.array()).any()<<std::endl;
-        nans = (U.array() != U.array()).count();
-        if(flipped == 0 && nans == 0) break;
         igl::slice(U,b,1,bct);
+        nans = (U.array() != U.array()).count();
+        if(test_for_flips)
+        {
+          Eigen::Matrix<Scalar,Eigen::Dynamic,1> A;
+          doublearea(U,F,A);
+          flipped = (A.array() < 0 ).count();
+          //std::cout<<"  "<<flipped<<"  nan? "<<(U.array() != U.array()).any()<<std::endl;
+          if(flipped == 0 && nans == 0) break;
+        }
       }
       if(flipped > 0 || nans>0) break;
     }
@@ -81,6 +102,7 @@ IGL_INLINE bool igl::bijective_composite_harmonic_mapping(
     }
     nsteps *= 2;
   }
+  //std::cout<<"failed to finish in "<<nsteps<<"..."<<std::endl;
   return false;
 }
 
@@ -88,4 +110,6 @@ IGL_INLINE bool igl::bijective_composite_harmonic_mapping(
 // Explicit template instantiation
 // generated by autoexplicit.sh
 template bool igl::bijective_composite_harmonic_mapping<Eigen::Matrix<double, -1, -1, 1, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 1, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 1, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 1, -1, -1> >&);
+// generated by autoexplicit.sh
+template bool igl::bijective_composite_harmonic_mapping<Eigen::Matrix<double, -1, -1, 1, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 1, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 1, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, int, int, int, bool, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 1, -1, -1> >&);
 #endif

+ 27 - 0
include/igl/bijective_composite_harmonic_mapping.h

@@ -44,6 +44,33 @@ namespace igl
     const Eigen::MatrixBase<Derivedb> & b,
     const Eigen::MatrixBase<Derivedbc> & bc,
     Eigen::PlainObjectBase<DerivedU> & U);
+  //
+  // Inputs:
+  //   min_steps  mininum number of steps to take from V(b,:) to bc
+  //   max_steps  mininum number of steps to take from V(b,:) to bc (if
+  //     max_steps == min_steps then no further number of steps will be tried)
+  //   num_inner_iters  number of iterations of harmonic solves to run after
+  //     for each morph step (to try to push flips back in)
+  //   test_for_flips  wether to check if flips occured (and trigger more
+  //     steps). if test_for_flips = false then this function always returns
+  //     true
+  // 
+  template <
+    typename DerivedV,
+    typename DerivedF,
+    typename Derivedb,
+    typename Derivedbc,
+    typename DerivedU>
+  IGL_INLINE bool bijective_composite_harmonic_mapping(
+    const Eigen::MatrixBase<DerivedV> & V,
+    const Eigen::MatrixBase<DerivedF> & F,
+    const Eigen::MatrixBase<Derivedb> & b,
+    const Eigen::MatrixBase<Derivedbc> & bc,
+    const int min_steps,
+    const int max_steps,
+    const int num_inner_iters,
+    const bool test_for_flips,
+    Eigen::PlainObjectBase<DerivedU> & U);
 }
 
 #ifndef IGL_STATIC_LIBRARY