|
@@ -0,0 +1,77 @@
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+#include "bijective_composite_harmonic_mapping.h"
|
|
|
+
|
|
|
+#include "slice.h"
|
|
|
+#include "doublearea.h"
|
|
|
+#include "harmonic.h"
|
|
|
+
|
|
|
+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,
|
|
|
+ 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);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ while(nsteps<=max_steps)
|
|
|
+ {
|
|
|
+ U = V;
|
|
|
+ int flipped = 0;
|
|
|
+ int nans = 0;
|
|
|
+ for(int step = 0;step<=nsteps;step++)
|
|
|
+ {
|
|
|
+ const Scalar t = ((Scalar)step)/((Scalar)nsteps);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Derivedbc bct = bc0 + t*(bc - bc0);
|
|
|
+
|
|
|
+ const int ninnersteps = 8;
|
|
|
+ for(int iter = 0;iter<8;iter++)
|
|
|
+ {
|
|
|
+
|
|
|
+ harmonic(DerivedU(U),F,b,bct,1,U);
|
|
|
+ Eigen::Matrix<Scalar,Eigen::Dynamic,1> A;
|
|
|
+ doublearea(U,F,A);
|
|
|
+ flipped = (A.array() < 0 ).count();
|
|
|
+
|
|
|
+ nans = (U.array() != U.array()).count();
|
|
|
+ if(flipped == 0 && nans == 0) break;
|
|
|
+ igl::slice(U,b,1,bct);
|
|
|
+ }
|
|
|
+ if(flipped > 0 || nans>0) break;
|
|
|
+ }
|
|
|
+ if(flipped == 0 && nans == 0)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ nsteps *= 2;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+}
|