// This file is part of libigl, a simple c++ geometry processing library. // // Copyright (C) 2017 Alec Jacobson // // 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 "bijective_composite_harmonic_mapping.h" #include "slice.h" #include "doublearea.h" #include "harmonic.h" //#include "matlab/MatlabWorkspace.h" #include template < typename DerivedV, typename DerivedF, typename Derivedb, typename Derivedbc, typename DerivedU> IGL_INLINE bool igl::bijective_composite_harmonic_mapping( const Eigen::MatrixBase & V, const Eigen::MatrixBase & F, const Eigen::MatrixBase & b, const Eigen::MatrixBase & bc, Eigen::PlainObjectBase & 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 & V, const Eigen::MatrixBase & F, const Eigen::MatrixBase & b, const Eigen::MatrixBase & bc, const int min_steps, const int max_steps, const int num_inner_iters, const bool test_for_flips, Eigen::PlainObjectBase & 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; int nsteps = min_steps; Derivedbc bc0; slice(V,b,1,bc0); // It's difficult to check for flips "robustly" in the sense that the input // mesh might not have positive/consistent sign to begin with. while(nsteps<=max_steps) { U = V; int flipped = 0; int nans = 0; int step = 0; for(;step<=nsteps;step++) { const Scalar t = ((Scalar)step)/((Scalar)nsteps); // linearly interpolate boundary conditions // TODO: replace this with something that guarantees a homotopic "morph" // of the boundary conditions. Something like "Homotopic Morphing of // Planar Curves" [Dym et al. 2015] but also handling multiple connected // components. Derivedbc bct = bc0 + t*(bc - bc0); // Compute dsicrete harmonic map using metric of previous step for(int iter = 0;iter A; doublearea(U,F,A); flipped = (A.array() < 0 ).count(); //std::cout<<" "< 0 || nans>0) break; } if(flipped == 0 && nans == 0) { return step == nsteps+1; } nsteps *= 2; } //std::cout<<"failed to finish in "<, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); // generated by autoexplicit.sh template bool igl::bijective_composite_harmonic_mapping, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, int, int, bool, Eigen::PlainObjectBase >&); #endif