miq.cpp 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@gmail.com>, Olga Diamanti <olga.diam@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include <igl/comiso/miq.h>
  9. #include <igl/local_basis.h>
  10. #include <igl/triangle_triangle_adjacency.h>
  11. #include <igl/cut_mesh.h>
  12. // includes for VertexIndexing
  13. #include <igl/HalfEdgeIterator.h>
  14. #include <igl/is_border_vertex.h>
  15. #include <igl/vertex_triangle_adjacency.h>
  16. // includes for PoissonSolver
  17. #include <igl/slice_into.h>
  18. #include <igl/grad.h>
  19. #include <igl/cotmatrix.h>
  20. #include <igl/doublearea.h>
  21. #include <gmm/gmm.h>
  22. #include <CoMISo/Solver/ConstrainedSolver.hh>
  23. #include <CoMISo/Solver/MISolver.hh>
  24. #include <CoMISo/Solver/GMM_Tools.hh>
  25. //
  26. #include <igl/cross_field_missmatch.h>
  27. #include <igl/comb_frame_field.h>
  28. #include <igl/comb_cross_field.h>
  29. #include <igl/cut_mesh_from_singularities.h>
  30. #include <igl/find_cross_field_singularities.h>
  31. #include <igl/compute_frame_field_bisectors.h>
  32. #include <igl/rotate_vectors.h>
  33. #include <fstream>
  34. #include <iostream>
  35. #include <igl/matlab_format.h>
  36. using namespace std;
  37. using namespace Eigen;
  38. #define DEBUGPRINT 1
  39. namespace igl {
  40. namespace comiso {
  41. struct SeamInfo
  42. {
  43. int v0,v0p;
  44. int integerVar;
  45. unsigned char MMatch;
  46. IGL_INLINE SeamInfo(int _v0,
  47. int _v0p,
  48. int _MMatch,
  49. int _integerVar);
  50. IGL_INLINE SeamInfo(const SeamInfo &S1);
  51. };
  52. struct MeshSystemInfo
  53. {
  54. ////number of vertices variables
  55. int num_vert_variables;
  56. ///num of integer for cuts
  57. int num_integer_cuts;
  58. ///this are used for drawing purposes
  59. std::vector<SeamInfo> EdgeSeamInfo;
  60. #if 0
  61. ///this are values of integer variables after optimization
  62. std::vector<int> IntegerValues;
  63. #endif
  64. };
  65. template <typename DerivedV, typename DerivedF>
  66. class VertexIndexing
  67. {
  68. public:
  69. // Input:
  70. const Eigen::PlainObjectBase<DerivedV> &V;
  71. const Eigen::PlainObjectBase<DerivedF> &F;
  72. const Eigen::PlainObjectBase<DerivedV> &Vcut;
  73. const Eigen::PlainObjectBase<DerivedF> &Fcut;
  74. const Eigen::PlainObjectBase<DerivedF> &TT;
  75. const Eigen::PlainObjectBase<DerivedF> &TTi;
  76. const Eigen::Matrix<int, Eigen::Dynamic, 3> &Handle_MMatch;
  77. const Eigen::Matrix<int, Eigen::Dynamic, 1> &Handle_Singular; // bool
  78. const Eigen::Matrix<int, Eigen::Dynamic, 3> &Handle_Seams; // 3 bool
  79. ///this handle for mesh TODO: move with the other global variables
  80. MeshSystemInfo Handle_SystemInfo;
  81. //DEBUG
  82. std::vector<DebugFaceEdgeInfo> DebugInfo;
  83. IGL_INLINE VertexIndexing(const Eigen::PlainObjectBase<DerivedV> &_V,
  84. const Eigen::PlainObjectBase<DerivedF> &_F,
  85. const Eigen::PlainObjectBase<DerivedV> &_Vcut,
  86. const Eigen::PlainObjectBase<DerivedF> &_Fcut,
  87. const Eigen::PlainObjectBase<DerivedF> &_TT,
  88. const Eigen::PlainObjectBase<DerivedF> &_TTi,
  89. const Eigen::Matrix<int, Eigen::Dynamic, 3> &_Handle_MMatch,
  90. const Eigen::Matrix<int, Eigen::Dynamic, 1> &_Handle_Singular,
  91. const Eigen::Matrix<int, Eigen::Dynamic, 3> &_Handle_Seams
  92. );
  93. // provide information about every vertex per seam
  94. IGL_INLINE void InitSeamInfo();
  95. private:
  96. struct VertexInfo{
  97. int v; // vertex index (according to V)
  98. int f0, k0; // face and local edge information of the edge that connects this vertex to the previous vertex (previous in the vector)
  99. int f1, k1; // face and local edge information of the other face corresponding to the same edge
  100. VertexInfo(int _v, int _f0, int _k0, int _f1, int _k1) :
  101. v(_v), f0(_f0), k0(_k0), f1(_f1), k1(_k1){}
  102. bool operator==(VertexInfo const& other){
  103. return other.v == v;
  104. }
  105. };
  106. IGL_INLINE void GetSeamInfo(const int f0,
  107. const int f1,
  108. const int indexE,
  109. int &v0,int &v1,
  110. int &v0p,int &v1p,
  111. unsigned char &_MMatch);
  112. IGL_INLINE std::vector<std::vector<VertexInfo> > GetVerticesPerSeam();
  113. };
  114. template <typename DerivedV, typename DerivedF>
  115. class PoissonSolver
  116. {
  117. public:
  118. IGL_INLINE void SolvePoisson(Eigen::VectorXd Stiffness,
  119. double vector_field_scale=0.1f,
  120. double grid_res=1.f,
  121. bool direct_round=true,
  122. int localIter=0,
  123. bool _integer_rounding=true,
  124. bool _singularity_rounding=true,
  125. std::vector<int> roundVertices = std::vector<int>(),
  126. std::vector<std::vector<int> > hardFeatures = std::vector<std::vector<int> >());
  127. IGL_INLINE PoissonSolver(const Eigen::PlainObjectBase<DerivedV> &_V,
  128. const Eigen::PlainObjectBase<DerivedF> &_F,
  129. const Eigen::PlainObjectBase<DerivedV> &_Vcut,
  130. const Eigen::PlainObjectBase<DerivedF> &_Fcut,
  131. const Eigen::PlainObjectBase<DerivedF> &_TT,
  132. const Eigen::PlainObjectBase<DerivedF> &_TTi,
  133. const Eigen::PlainObjectBase<DerivedV> &_PD1,
  134. const Eigen::PlainObjectBase<DerivedV> &_PD2,
  135. const Eigen::Matrix<int, Eigen::Dynamic, 1>&_Handle_Singular,
  136. const MeshSystemInfo &_Handle_SystemInfo
  137. );
  138. const Eigen::PlainObjectBase<DerivedV> &V;
  139. const Eigen::PlainObjectBase<DerivedF> &F;
  140. const Eigen::PlainObjectBase<DerivedV> &Vcut;
  141. const Eigen::PlainObjectBase<DerivedF> &Fcut;
  142. const Eigen::PlainObjectBase<DerivedF> &TT;
  143. const Eigen::PlainObjectBase<DerivedF> &TTi;
  144. const Eigen::PlainObjectBase<DerivedV> &PD1;
  145. const Eigen::PlainObjectBase<DerivedV> &PD2;
  146. const Eigen::Matrix<int, Eigen::Dynamic, 1> &Handle_Singular; // bool
  147. const MeshSystemInfo &Handle_SystemInfo;
  148. // Internal:
  149. Eigen::VectorXd Handle_Stiffness;
  150. std::vector<std::vector<int> > VF;
  151. std::vector<std::vector<int> > VFi;
  152. Eigen::MatrixXd UV; // this is probably useless
  153. // Output:
  154. // per wedge UV coordinates, 6 coordinates (1 face) per row
  155. Eigen::MatrixXd WUV;
  156. // per vertex UV coordinates, Vcut.rows() x 2
  157. Eigen::MatrixXd UV_out;
  158. // Matrices
  159. Eigen::SparseMatrix<double> Lhs;
  160. Eigen::SparseMatrix<double> Constraints;
  161. Eigen::VectorXd rhs;
  162. Eigen::VectorXd constraints_rhs;
  163. ///vector of unknowns
  164. std::vector< double > X;
  165. ////REAL PART
  166. ///number of fixed vertex
  167. unsigned int n_fixed_vars;
  168. ///the number of REAL variables for vertices
  169. unsigned int n_vert_vars;
  170. ///total number of variables of the system,
  171. ///do not consider constraints, but consider integer vars
  172. unsigned int num_total_vars;
  173. //////INTEGER PART
  174. ///the total number of integer variables
  175. unsigned int n_integer_vars;
  176. ///CONSTRAINT PART
  177. ///number of cuts constraints
  178. unsigned int num_cut_constraint;
  179. // number of user-defined constraints
  180. unsigned int num_userdefined_constraint;
  181. ///total number of constraints equations
  182. unsigned int num_constraint_equations;
  183. ///vector of blocked vertices
  184. std::vector<int> Hard_constraints;
  185. ///vector of indexes to round
  186. std::vector<int> ids_to_round;
  187. ///vector of indexes to round
  188. std::vector<std::vector<int > > userdefined_constraints;
  189. ///boolean that is true if rounding to integer is needed
  190. bool integer_rounding;
  191. ///START COMMON MATH FUNCTIONS
  192. ///return the complex encoding the rotation
  193. ///for a given missmatch interval
  194. IGL_INLINE std::complex<double> GetRotationComplex(int interval);
  195. ///END COMMON MATH FUNCTIONS
  196. ///START FIXING VERTICES
  197. ///set a given vertex as fixed
  198. IGL_INLINE void AddFixedVertex(int v);
  199. ///find vertex to fix in case we're using
  200. ///a vector field NB: multiple components not handled
  201. IGL_INLINE void FindFixedVertField();
  202. ///find hard constraint depending if using or not
  203. ///a vector field
  204. IGL_INLINE void FindFixedVert();
  205. IGL_INLINE int GetFirstVertexIndex(int v);
  206. ///fix the vertices which are flagged as fixed
  207. IGL_INLINE void FixBlockedVertex();
  208. ///END FIXING VERTICES
  209. ///HANDLING SINGULARITY
  210. //set the singularity round to integer location
  211. IGL_INLINE void AddSingularityRound();
  212. IGL_INLINE void AddToRoundVertices(std::vector<int> ids);
  213. ///START GENERIC SYSTEM FUNCTIONS
  214. //build the laplacian matrix cyclyng over all rangemaps
  215. //and over all faces
  216. IGL_INLINE void BuildLaplacianMatrix(double vfscale=1);
  217. ///find different sized of the system
  218. IGL_INLINE void FindSizes();
  219. IGL_INLINE void AllocateSystem();
  220. ///intitialize the whole matrix
  221. IGL_INLINE void InitMatrix();
  222. ///map back coordinates after that
  223. ///the system has been solved
  224. IGL_INLINE void MapCoords();
  225. ///END GENERIC SYSTEM FUNCTIONS
  226. ///set the constraints for the inter-range cuts
  227. IGL_INLINE void BuildSeamConstraintsExplicitTranslation();
  228. ///set the constraints for the inter-range cuts
  229. IGL_INLINE void BuildUserDefinedConstraints();
  230. ///call of the mixed integer solver
  231. IGL_INLINE void MixedIntegerSolve(double cone_grid_res=1,
  232. bool direct_round=true,
  233. int localIter=0);
  234. IGL_INLINE void clearUserConstraint();
  235. IGL_INLINE void addSharpEdgeConstraint(int fid, int vid);
  236. };
  237. template <typename DerivedV, typename DerivedF, typename DerivedU>
  238. class MIQ_class
  239. {
  240. private:
  241. const Eigen::PlainObjectBase<DerivedV> &V;
  242. const Eigen::PlainObjectBase<DerivedF> &F;
  243. Eigen::PlainObjectBase<DerivedV> Vcut;
  244. Eigen::PlainObjectBase<DerivedF> Fcut;
  245. Eigen::MatrixXd UV_out;
  246. Eigen::PlainObjectBase<DerivedF> FUV_out;
  247. //DEBUG
  248. std::vector<DebugFaceEdgeInfo> debugFaceEdgeInfo_out;
  249. // internal
  250. Eigen::PlainObjectBase<DerivedF> TT;
  251. Eigen::PlainObjectBase<DerivedF> TTi;
  252. // Stiffness per face
  253. Eigen::VectorXd Handle_Stiffness;
  254. Eigen::PlainObjectBase<DerivedV> B1, B2, B3;
  255. public:
  256. IGL_INLINE MIQ_class(const Eigen::PlainObjectBase<DerivedV> &V_,
  257. const Eigen::PlainObjectBase<DerivedF> &F_,
  258. const Eigen::PlainObjectBase<DerivedV> &PD1_combed,
  259. const Eigen::PlainObjectBase<DerivedV> &PD2_combed,
  260. const Eigen::Matrix<int, Eigen::Dynamic, 3> &Handle_MMatch,
  261. const Eigen::Matrix<int, Eigen::Dynamic, 1> &Handle_Singular,
  262. const Eigen::Matrix<int, Eigen::Dynamic, 3> &Handle_Seams,
  263. Eigen::PlainObjectBase<DerivedU> &UV,
  264. Eigen::PlainObjectBase<DerivedF> &FUV,
  265. double GradientSize = 30.0,
  266. double Stiffness = 5.0,
  267. bool DirectRound = false,
  268. int iter = 5,
  269. int localIter = 5,
  270. bool DoRound = true,
  271. bool SingularityRound=true,
  272. std::vector<int> roundVertices = std::vector<int>(),
  273. std::vector<std::vector<int> > hardFeatures = std::vector<std::vector<int> >());
  274. IGL_INLINE void extractUV(Eigen::PlainObjectBase<DerivedU> &UV_out,
  275. Eigen::PlainObjectBase<DerivedF> &FUV_out);
  276. //DEBUG
  277. IGL_INLINE void extractDebugInfo(std::vector<igl::comiso::DebugFaceEdgeInfo>& debugFaceEdgeInfo);
  278. private:
  279. IGL_INLINE int NumFlips(const Eigen::MatrixXd& WUV);
  280. IGL_INLINE double Distortion(int f, double h, const Eigen::MatrixXd& WUV);
  281. IGL_INLINE double LaplaceDistortion(const int f, double h, const Eigen::MatrixXd& WUV);
  282. IGL_INLINE bool updateStiffeningJacobianDistorsion(double grad_size, const Eigen::MatrixXd& WUV);
  283. IGL_INLINE bool IsFlipped(const Eigen::Vector2d &uv0,
  284. const Eigen::Vector2d &uv1,
  285. const Eigen::Vector2d &uv2);
  286. IGL_INLINE bool IsFlipped(const int i, const Eigen::MatrixXd& WUV);
  287. };
  288. };
  289. }
  290. IGL_INLINE igl::comiso::SeamInfo::SeamInfo(int _v0,
  291. int _v0p,
  292. int _MMatch,
  293. int _integerVar)
  294. {
  295. v0=_v0;
  296. v0p=_v0p;
  297. integerVar=_integerVar;
  298. MMatch=_MMatch;
  299. }
  300. IGL_INLINE igl::comiso::SeamInfo::SeamInfo(const SeamInfo &S1)
  301. {
  302. v0=S1.v0;
  303. v0p=S1.v0p;
  304. integerVar=S1.integerVar;
  305. MMatch=S1.MMatch;
  306. }
  307. template <typename DerivedV, typename DerivedF>
  308. IGL_INLINE igl::comiso::VertexIndexing<DerivedV, DerivedF>::VertexIndexing(const Eigen::PlainObjectBase<DerivedV> &_V,
  309. const Eigen::PlainObjectBase<DerivedF> &_F,
  310. const Eigen::PlainObjectBase<DerivedV> &_Vcut,
  311. const Eigen::PlainObjectBase<DerivedF> &_Fcut,
  312. const Eigen::PlainObjectBase<DerivedF> &_TT,
  313. const Eigen::PlainObjectBase<DerivedF> &_TTi,
  314. const Eigen::Matrix<int, Eigen::Dynamic, 3> &_Handle_MMatch,
  315. const Eigen::Matrix<int, Eigen::Dynamic, 1> &_Handle_Singular,
  316. const Eigen::Matrix<int, Eigen::Dynamic, 3> &_Handle_Seams
  317. ):
  318. V(_V),
  319. F(_F),
  320. Vcut(_Vcut),
  321. Fcut(_Fcut),
  322. TT(_TT),
  323. TTi(_TTi),
  324. Handle_MMatch(_Handle_MMatch),
  325. Handle_Singular(_Handle_Singular),
  326. Handle_Seams(_Handle_Seams)
  327. {
  328. #ifdef DEBUG_PRINT
  329. cerr<<igl::matlab_format(Handle_Seams,"Handle_Seams");
  330. #endif
  331. Handle_SystemInfo.num_vert_variables=Vcut.rows();
  332. Handle_SystemInfo.num_integer_cuts=0;
  333. }
  334. template <typename DerivedV, typename DerivedF>
  335. IGL_INLINE void igl::comiso::VertexIndexing<DerivedV, DerivedF>::GetSeamInfo(const int f0,
  336. const int f1,
  337. const int indexE,
  338. int &v0,int &v1,
  339. int &v0p,int &v1p,
  340. unsigned char &_MMatch)
  341. {
  342. int edgef0 = indexE;
  343. v0 = Fcut(f0,edgef0);
  344. v1 = Fcut(f0,(edgef0+1)%3);
  345. ////get the index on opposite side
  346. assert(TT(f0,edgef0) == f1);
  347. int edgef1 = TTi(f0,edgef0);
  348. v1p = Fcut(f1,edgef1);
  349. v0p = Fcut(f1,(edgef1+1)%3);
  350. _MMatch = Handle_MMatch(f0,edgef0);
  351. assert(F(f0,edgef0) == F(f1,((edgef1+1)%3)));
  352. assert(F(f0,((edgef0+1)%3)) == F(f1,edgef1));
  353. }
  354. template <typename DerivedV, typename DerivedF>
  355. IGL_INLINE std::vector<std::vector<typename igl::comiso::VertexIndexing<DerivedV, DerivedF>::VertexInfo> > igl::comiso::VertexIndexing<DerivedV, DerivedF>::GetVerticesPerSeam()
  356. {
  357. // Return value
  358. std::vector<std::vector<VertexInfo> >verticesPerSeam;
  359. // for every vertex, keep track of their adjacent vertices on seams.
  360. // regular vertices have two neighbors on a seam, start- and endvertices may have any other numbers of neighbors (e.g. 1 or 3)
  361. std::vector<std::list<VertexInfo> > VVSeam(V.rows());
  362. Eigen::MatrixXi F_hit = Eigen::MatrixXi::Zero(F.rows(), 3);
  363. for (unsigned int f=0; f<F.rows();f++)
  364. {
  365. int f0 = f;
  366. for(int k0=0; k0<3; k0++){
  367. int f1 = TT(f0,k0);
  368. if(f1 == -1)
  369. continue;
  370. bool seam = Handle_Seams(f0,k0);
  371. if (seam && F_hit(f0,k0) == 0)
  372. {
  373. int v0 = F(f0, k0);
  374. int v1 = F(f0, (k0+1)%3);
  375. int k1 = TTi(f0,k0);
  376. VVSeam[v0].push_back(VertexInfo(v1, f0, k0, f1, k1));
  377. VVSeam[v1].push_back(VertexInfo(v0, f0, k0, f1, k1));
  378. F_hit(f0, k0) = 1;
  379. F_hit(f1, k1) = 1;
  380. }
  381. }
  382. }
  383. // Find start vertices, i.e. vertices that start or end a seam branch
  384. std::vector<int> startVertexIndices;
  385. std::vector<bool> isStartVertex(V.rows());
  386. for (unsigned int i=0;i<V.rows();i++)
  387. {
  388. isStartVertex[i] = false;
  389. // vertices with two neighbors are regular vertices, unless the vertex is a singularity, in which case it qualifies as a start vertex
  390. if (VVSeam[i].size() > 0 && VVSeam[i].size() != 2 || Handle_Singular(i) == true)
  391. {
  392. startVertexIndices.push_back(i);
  393. isStartVertex[i] = true;
  394. }
  395. }
  396. // For each startVertex, walk along its seam
  397. for (unsigned int i=0;i<startVertexIndices.size();i++)
  398. {
  399. auto startVertexNeighbors = &VVSeam[startVertexIndices[i]];
  400. const int neighborSize = startVertexNeighbors->size();
  401. // explore every seam to which this vertex is a start vertex
  402. // note: a vertex can never be a start vertex and a regular vertex simultaneously
  403. for (unsigned int j=0;j<neighborSize;j++)
  404. {
  405. std::vector<VertexInfo> thisSeam; // temporary container
  406. // Create vertexInfo struct for start vertex
  407. auto startVertex = VertexInfo(startVertexIndices[i], -1, -1, -1, -1);// -1 values are arbitrary (will never be used)
  408. auto currentVertex = startVertex;
  409. // Add start vertex to the seam
  410. thisSeam.push_back(currentVertex);
  411. // advance on the seam
  412. auto currentVertexNeighbors = startVertexNeighbors;
  413. auto nextVertex = currentVertexNeighbors->front();
  414. currentVertexNeighbors->pop_front();
  415. auto prevVertex = startVertex; // bogus initialization to get the type
  416. while (true)
  417. {
  418. // move to the next vertex
  419. prevVertex = currentVertex;
  420. currentVertex = nextVertex;
  421. currentVertexNeighbors = &VVSeam[nextVertex.v];
  422. // add current vertex to this seam
  423. thisSeam.push_back(currentVertex);
  424. // remove the previous vertex
  425. auto it = std::find(currentVertexNeighbors->begin(), currentVertexNeighbors->end(), prevVertex);
  426. assert(it != currentVertexNeighbors->end());
  427. currentVertexNeighbors->erase(it);
  428. if (currentVertexNeighbors->size() == 1 && !isStartVertex[currentVertex.v])
  429. {
  430. nextVertex = currentVertexNeighbors->front();
  431. currentVertexNeighbors->pop_front();
  432. }
  433. else
  434. break;
  435. }
  436. verticesPerSeam.push_back(thisSeam);
  437. }
  438. }
  439. return verticesPerSeam;
  440. }
  441. template <typename DerivedV, typename DerivedF>
  442. IGL_INLINE void igl::comiso::VertexIndexing<DerivedV, DerivedF>::InitSeamInfo()
  443. {
  444. auto verticesPerSeam = GetVerticesPerSeam();
  445. Handle_SystemInfo.EdgeSeamInfo.clear();
  446. int integerVar = 0;
  447. // Loop over each seam
  448. for(auto seam : verticesPerSeam){
  449. //choose initial side of the seam such that the start vertex corresponds to Fcut(f, k) and the end vertex corresponds to Fcut(f, (k+1)%3) and not vice versa.
  450. int priorVertexIdx;
  451. if(seam.size() > 2){
  452. auto v1 = seam[1];
  453. auto v2 = seam[2];
  454. if(Fcut(v1.f0, (v1.k0+1) % 3) == Fcut(v2.f0, v2.k0) || Fcut(v1.f0, (v1.k0+1) % 3) == Fcut(v2.f1, v2.k1)){
  455. priorVertexIdx = Fcut(v1.f0, v1.k0);
  456. }
  457. else{
  458. priorVertexIdx = Fcut(v1.f1, v1.k1);
  459. assert(Fcut(v1.f1, (v1.k1+1) % 3) == Fcut(v2.f0, v2.k0) || Fcut(v1.f1, (v1.k1+1) % 3) == Fcut(v2.f1, v2.k1));
  460. }
  461. }
  462. else{
  463. auto v1 = seam[1];
  464. priorVertexIdx = Fcut(v1.f0, v1.k0);
  465. }
  466. // Loop over each vertex of the seam
  467. for(auto it=seam.begin()+1; it != seam.end(); ++it){
  468. auto vertex = *it;
  469. // choose the correct side of the seam
  470. int f,k,ff,kk;
  471. if(priorVertexIdx == Fcut(vertex.f0, vertex.k0)){
  472. f = vertex.f0; ff = vertex.f1;
  473. k = vertex.k0; kk = vertex.k1;
  474. }
  475. else{
  476. f = vertex.f1; ff = vertex.f0;
  477. k = vertex.k1; kk = vertex.k0;
  478. assert(priorVertexIdx == Fcut(vertex.f1, vertex.k1));
  479. }
  480. int vtx0,vtx0p,vtx1,vtx1p;
  481. unsigned char MM;
  482. GetSeamInfo(f,ff,k,vtx0,vtx1,vtx0p,vtx1p,MM);
  483. Handle_SystemInfo.EdgeSeamInfo.push_back(SeamInfo(vtx0,vtx0p,MM,integerVar));
  484. if(it == seam.end() -1){
  485. Handle_SystemInfo.EdgeSeamInfo.push_back(SeamInfo(vtx1,vtx1p,MM,integerVar));
  486. }
  487. priorVertexIdx = vtx1;
  488. //DEBUG
  489. DebugInfo.push_back(DebugFaceEdgeInfo(f,k,integerVar));
  490. }
  491. // use the same integer for each seam
  492. integerVar++;
  493. }
  494. Handle_SystemInfo.num_integer_cuts = integerVar;
  495. #ifndef NDEBUG
  496. int totalNVerticesOnSeams = 0;
  497. for(auto seam : verticesPerSeam){
  498. totalNVerticesOnSeams += seam.size();
  499. }
  500. assert(Handle_SystemInfo.EdgeSeamInfo.size() == totalNVerticesOnSeams);
  501. #endif
  502. }
  503. template <typename DerivedV, typename DerivedF>
  504. IGL_INLINE void igl::comiso::PoissonSolver<DerivedV, DerivedF>::SolvePoisson(Eigen::VectorXd Stiffness,
  505. double vector_field_scale,
  506. double grid_res,
  507. bool direct_round,
  508. int localIter,
  509. bool _integer_rounding,
  510. bool _singularity_rounding,
  511. std::vector<int> roundVertices,
  512. std::vector<std::vector<int> > hardFeatures)
  513. {
  514. Handle_Stiffness = Stiffness;
  515. //initialization of flags and data structures
  516. integer_rounding=_integer_rounding;
  517. ids_to_round.clear();
  518. clearUserConstraint();
  519. // copy the user constraints number
  520. for (size_t i = 0; i < hardFeatures.size(); ++i)
  521. {
  522. addSharpEdgeConstraint(hardFeatures[i][0],hardFeatures[i][1]);
  523. }
  524. ///Initializing Matrix
  525. int t0=clock();
  526. ///initialize the matrix ALLOCATING SPACE
  527. InitMatrix();
  528. if (DEBUGPRINT)
  529. printf("\n ALLOCATED THE MATRIX \n");
  530. ///build the laplacian system
  531. BuildLaplacianMatrix(vector_field_scale);
  532. // add seam constraints
  533. BuildSeamConstraintsExplicitTranslation();
  534. // add user defined constraints
  535. BuildUserDefinedConstraints();
  536. ////add the lagrange multiplier
  537. FixBlockedVertex();
  538. if (DEBUGPRINT)
  539. printf("\n BUILT THE MATRIX \n");
  540. if (integer_rounding)
  541. AddToRoundVertices(roundVertices);
  542. if (_singularity_rounding)
  543. AddSingularityRound();
  544. int t1=clock();
  545. if (DEBUGPRINT) printf("\n time:%d \n",t1-t0);
  546. if (DEBUGPRINT) printf("\n SOLVING \n");
  547. MixedIntegerSolve(grid_res,direct_round,localIter);
  548. int t2=clock();
  549. if (DEBUGPRINT) printf("\n time:%d \n",t2-t1);
  550. if (DEBUGPRINT) printf("\n ASSIGNING COORDS \n");
  551. MapCoords();
  552. int t3=clock();
  553. if (DEBUGPRINT) printf("\n time:%d \n",t3-t2);
  554. if (DEBUGPRINT) printf("\n FINISHED \n");
  555. }
  556. template <typename DerivedV, typename DerivedF>
  557. IGL_INLINE igl::comiso::PoissonSolver<DerivedV, DerivedF>
  558. ::PoissonSolver(const Eigen::PlainObjectBase<DerivedV> &_V,
  559. const Eigen::PlainObjectBase<DerivedF> &_F,
  560. const Eigen::PlainObjectBase<DerivedV> &_Vcut,
  561. const Eigen::PlainObjectBase<DerivedF> &_Fcut,
  562. const Eigen::PlainObjectBase<DerivedF> &_TT,
  563. const Eigen::PlainObjectBase<DerivedF> &_TTi,
  564. const Eigen::PlainObjectBase<DerivedV> &_PD1,
  565. const Eigen::PlainObjectBase<DerivedV> &_PD2,
  566. const Eigen::Matrix<int, Eigen::Dynamic, 1>&_Handle_Singular,
  567. const MeshSystemInfo &_Handle_SystemInfo
  568. ):
  569. V(_V),
  570. F(_F),
  571. Vcut(_Vcut),
  572. Fcut(_Fcut),
  573. TT(_TT),
  574. TTi(_TTi),
  575. PD1(_PD1),
  576. PD2(_PD2),
  577. Handle_Singular(_Handle_Singular),
  578. Handle_SystemInfo(_Handle_SystemInfo)
  579. {
  580. UV = Eigen::MatrixXd(V.rows(),2);
  581. WUV = Eigen::MatrixXd(F.rows(),6);
  582. UV_out = Eigen::MatrixXd(Vcut.rows(),2);
  583. igl::vertex_triangle_adjacency(V,F,VF,VFi);
  584. }
  585. ///START COMMON MATH FUNCTIONS
  586. ///return the complex encoding the rotation
  587. ///for a given missmatch interval
  588. template <typename DerivedV, typename DerivedF>
  589. IGL_INLINE std::complex<double> igl::comiso::PoissonSolver<DerivedV, DerivedF>::GetRotationComplex(int interval)
  590. {
  591. assert((interval>=0)&&(interval<4));
  592. switch(interval)
  593. {
  594. case 0:return std::complex<double>(1,0);
  595. case 1:return std::complex<double>(0,1);
  596. case 2:return std::complex<double>(-1,0);
  597. default:return std::complex<double>(0,-1);
  598. }
  599. }
  600. ///END COMMON MATH FUNCTIONS
  601. ///START FIXING VERTICES
  602. ///set a given vertex as fixed
  603. template <typename DerivedV, typename DerivedF>
  604. IGL_INLINE void igl::comiso::PoissonSolver<DerivedV, DerivedF>::AddFixedVertex(int v)
  605. {
  606. n_fixed_vars++;
  607. Hard_constraints.push_back(v);
  608. }
  609. ///find vertex to fix in case we're using
  610. ///a vector field NB: multiple components not handled
  611. template <typename DerivedV, typename DerivedF>
  612. IGL_INLINE void igl::comiso::PoissonSolver<DerivedV, DerivedF>::FindFixedVertField()
  613. {
  614. Hard_constraints.clear();
  615. n_fixed_vars=0;
  616. //fix the first singularity
  617. for (unsigned int v=0;v<V.rows();v++)
  618. {
  619. if (Handle_Singular(v))
  620. {
  621. AddFixedVertex(v);
  622. UV.row(v) << 0,0;
  623. return;
  624. }
  625. }
  626. ///if anything fixed fix the first
  627. AddFixedVertex(0); // TODO HERE IT ISSSSSS
  628. UV.row(0) << 0,0;
  629. std::cerr << "No vertices to fix, I am fixing the first vertex to the origin!" << std::endl;
  630. }
  631. ///find hard constraint depending if using or not
  632. ///a vector field
  633. template <typename DerivedV, typename DerivedF>
  634. IGL_INLINE void igl::comiso::PoissonSolver<DerivedV, DerivedF>::FindFixedVert()
  635. {
  636. Hard_constraints.clear();
  637. FindFixedVertField();
  638. }
  639. template <typename DerivedV, typename DerivedF>
  640. IGL_INLINE int igl::comiso::PoissonSolver<DerivedV, DerivedF>::GetFirstVertexIndex(int v)
  641. {
  642. return Fcut(VF[v][0],VFi[v][0]);
  643. }
  644. ///fix the vertices which are flagged as fixed
  645. template <typename DerivedV, typename DerivedF>
  646. IGL_INLINE void igl::comiso::PoissonSolver<DerivedV, DerivedF>::FixBlockedVertex()
  647. {
  648. int offset_row = num_cut_constraint*2;
  649. unsigned int constr_num = 0;
  650. for (unsigned int i=0;i<Hard_constraints.size();i++)
  651. {
  652. int v = Hard_constraints[i];
  653. ///get first index of the vertex that must blocked
  654. //int index=v->vertex_index[0];
  655. int index = GetFirstVertexIndex(v);
  656. ///multiply times 2 because of uv
  657. int indexvert = index*2;
  658. ///find the first free row to add the constraint
  659. int indexRow = (offset_row+constr_num*2);
  660. int indexCol = indexRow;
  661. ///add fixing constraint LHS
  662. Constraints.coeffRef(indexRow, indexvert) += 1;
  663. Constraints.coeffRef(indexRow+1,indexvert+1) += 1;
  664. ///add fixing constraint RHS
  665. constraints_rhs[indexCol] = UV(v,0);
  666. constraints_rhs[indexCol+1] = UV(v,1);
  667. constr_num++;
  668. }
  669. assert(constr_num==n_fixed_vars);
  670. }
  671. ///END FIXING VERTICES
  672. ///HANDLING SINGULARITY
  673. //set the singularity round to integer location
  674. template <typename DerivedV, typename DerivedF>
  675. IGL_INLINE void igl::comiso::PoissonSolver<DerivedV, DerivedF>::AddSingularityRound()
  676. {
  677. for (unsigned int v=0;v<V.rows();v++)
  678. {
  679. if (Handle_Singular(v))
  680. {
  681. int index0=GetFirstVertexIndex(v);
  682. ids_to_round.push_back( index0*2 );
  683. ids_to_round.push_back((index0*2)+1);
  684. }
  685. }
  686. }
  687. template <typename DerivedV, typename DerivedF>
  688. IGL_INLINE void igl::comiso::PoissonSolver<DerivedV, DerivedF>::AddToRoundVertices(std::vector<int> ids)
  689. {
  690. for (size_t i = 0; i < ids.size(); ++i)
  691. {
  692. if (ids[i] < 0 || ids[i] >= V.rows())
  693. std::cerr << "WARNING: Ignored round vertex constraint, vertex " << ids[i] << " does not exist in the mesh." << std::endl;
  694. int index0 = GetFirstVertexIndex(ids[i]);
  695. ids_to_round.push_back( index0*2 );
  696. ids_to_round.push_back((index0*2)+1);
  697. }
  698. }
  699. ///START GENERIC SYSTEM FUNCTIONS
  700. //build the laplacian matrix cyclyng over all rangemaps
  701. //and over all faces
  702. template <typename DerivedV, typename DerivedF>
  703. IGL_INLINE void igl::comiso::PoissonSolver<DerivedV, DerivedF>::BuildLaplacianMatrix(double vfscale)
  704. {
  705. Eigen::VectorXi idx = Eigen::VectorXi::LinSpaced(Vcut.rows(), 0, 2*Vcut.rows()-2);
  706. Eigen::VectorXi idx2 = Eigen::VectorXi::LinSpaced(Vcut.rows(), 1, 2*Vcut.rows()-1);
  707. // get gradient matrix
  708. Eigen::SparseMatrix<double> G(Fcut.rows() * 3, Vcut.rows());
  709. igl::grad(Vcut, Fcut, G);
  710. // get triangle weights
  711. Eigen::VectorXd dblA(Fcut.rows());
  712. igl::doublearea(Vcut, Fcut, dblA);
  713. // compute intermediate result
  714. Eigen::SparseMatrix<double> G2;
  715. G2 = G.transpose() * dblA.replicate<3,1>().asDiagonal() * Handle_Stiffness.replicate<3,1>().asDiagonal();
  716. /// Compute LHS
  717. Eigen::SparseMatrix<double> Cotmatrix;
  718. Cotmatrix = 0.5 * G2 * G;
  719. igl::slice_into(Cotmatrix, idx, idx, Lhs);
  720. igl::slice_into(Cotmatrix, idx2, idx2, Lhs);
  721. /// Compute RHS
  722. // reshape nrosy vectors
  723. const Eigen::MatrixXd u = Eigen::Map<const Eigen::MatrixXd>(PD1.data(),Fcut.rows()*3,1); // this mimics a reshape at the cost of a copy.
  724. const Eigen::MatrixXd v = Eigen::Map<const Eigen::MatrixXd>(PD2.data(),Fcut.rows()*3,1); // this mimics a reshape at the cost of a copy.
  725. // multiply with weights
  726. Eigen::VectorXd rhs1 = G2 * u * 0.5 * vfscale;
  727. Eigen::VectorXd rhs2 = -G2 * v * 0.5 * vfscale;
  728. igl::slice_into(rhs1, idx, 1, rhs);
  729. igl::slice_into(rhs2, idx2, 1, rhs);
  730. }
  731. ///find different sized of the system
  732. template <typename DerivedV, typename DerivedF>
  733. IGL_INLINE void igl::comiso::PoissonSolver<DerivedV, DerivedF>::FindSizes()
  734. {
  735. ///find the vertex that need to be fixed
  736. FindFixedVert();
  737. ///REAL PART
  738. n_vert_vars = Handle_SystemInfo.num_vert_variables;
  739. ///INTEGER PART
  740. ///the total number of integer variables
  741. n_integer_vars = Handle_SystemInfo.num_integer_cuts;
  742. ///CONSTRAINT PART
  743. num_cut_constraint = Handle_SystemInfo.EdgeSeamInfo.size();
  744. num_constraint_equations = num_cut_constraint * 2 + n_fixed_vars * 2 + num_userdefined_constraint;
  745. ///total variable of the system
  746. num_total_vars = (n_vert_vars+n_integer_vars) * 2;
  747. ///initialize matrix size
  748. if (DEBUGPRINT) printf("\n*** SYSTEM VARIABLES *** \n");
  749. if (DEBUGPRINT) printf("* NUM REAL VERTEX VARIABLES %d \n",n_vert_vars);
  750. if (DEBUGPRINT) printf("\n*** INTEGER VARIABLES *** \n");
  751. if (DEBUGPRINT) printf("* NUM INTEGER VARIABLES %d \n",(int)n_integer_vars);
  752. if (DEBUGPRINT) printf("\n*** CONSTRAINTS *** \n ");
  753. if (DEBUGPRINT) printf("* NUM FIXED CONSTRAINTS %d\n",n_fixed_vars);
  754. if (DEBUGPRINT) printf("* NUM CUTS CONSTRAINTS %d\n",num_cut_constraint);
  755. if (DEBUGPRINT) printf("* NUM USER DEFINED CONSTRAINTS %d\n",num_userdefined_constraint);
  756. if (DEBUGPRINT) printf("\n*** TOTAL SIZE *** \n");
  757. if (DEBUGPRINT) printf("* TOTAL VARIABLE SIZE (WITH INTEGER TRASL) %d \n",num_total_vars);
  758. if (DEBUGPRINT) printf("* TOTAL CONSTRAINTS %d \n",num_constraint_equations);
  759. }
  760. template <typename DerivedV, typename DerivedF>
  761. IGL_INLINE void igl::comiso::PoissonSolver<DerivedV, DerivedF>::AllocateSystem()
  762. {
  763. Lhs.resize(n_vert_vars * 2, n_vert_vars * 2);
  764. Constraints.resize(num_constraint_equations, num_total_vars);
  765. rhs.resize(n_vert_vars * 2);
  766. constraints_rhs.resize(num_constraint_equations);
  767. printf("\n INITIALIZED SPARSE MATRIX OF %d x %d \n",n_vert_vars*2, n_vert_vars*2);
  768. printf("\n INITIALIZED SPARSE MATRIX OF %d x %d \n",num_constraint_equations, num_total_vars);
  769. printf("\n INITIALIZED VECTOR OF %d x 1 \n",n_vert_vars*2);
  770. printf("\n INITIALIZED VECTOR OF %d x 1 \n",num_constraint_equations);
  771. }
  772. ///intitialize the whole matrix
  773. template <typename DerivedV, typename DerivedF>
  774. IGL_INLINE void igl::comiso::PoissonSolver<DerivedV, DerivedF>::InitMatrix()
  775. {
  776. FindSizes();
  777. AllocateSystem();
  778. }
  779. ///map back coordinates after that
  780. ///the system has been solved
  781. template <typename DerivedV, typename DerivedF>
  782. IGL_INLINE void igl::comiso::PoissonSolver<DerivedV, DerivedF>::MapCoords()
  783. {
  784. ///map coords to faces
  785. for (unsigned int f=0;f<Fcut.rows();f++)
  786. {
  787. for (int k=0;k<3;k++)
  788. {
  789. //get the index of the variable in the system
  790. int indexUV = Fcut(f,k);
  791. ///then get U and V coords
  792. double U=X[indexUV*2];
  793. double V=X[indexUV*2+1];
  794. WUV(f,k*2 + 0) = U;
  795. WUV(f,k*2 + 1) = V;
  796. }
  797. }
  798. for(int i = 0; i < Vcut.rows(); i++){
  799. UV_out(i,0) = X[i*2];
  800. UV_out(i,1) = X[i*2+1];
  801. }
  802. #if 0
  803. ///initialize the vector of integer variables to return their values
  804. Handle_SystemInfo.IntegerValues.resize(n_integer_vars*2);
  805. int baseIndex = (n_vert_vars)*2;
  806. int endIndex = baseIndex+n_integer_vars*2;
  807. int index = 0;
  808. for (int i=baseIndex; i<endIndex; i++)
  809. {
  810. ///assert that the value is an integer value
  811. double value=X[i];
  812. double diff = value-(int)floor(value+0.5);
  813. assert(diff<0.00000001);
  814. Handle_SystemInfo.IntegerValues[index] = value;
  815. index++;
  816. }
  817. #endif
  818. }
  819. ///END GENERIC SYSTEM FUNCTIONS
  820. ///set the constraints for the inter-range cuts
  821. template <typename DerivedV, typename DerivedF>
  822. IGL_INLINE void igl::comiso::PoissonSolver<DerivedV, DerivedF>::BuildSeamConstraintsExplicitTranslation()
  823. {
  824. ///current constraint row
  825. int constr_row = 0;
  826. for (unsigned int i=0; i<num_cut_constraint; i++)
  827. {
  828. unsigned char interval = Handle_SystemInfo.EdgeSeamInfo[i].MMatch;
  829. if (interval==1)
  830. interval=3;
  831. else
  832. if(interval==3)
  833. interval=1;
  834. int p0 = Handle_SystemInfo.EdgeSeamInfo[i].v0;
  835. int p0p = Handle_SystemInfo.EdgeSeamInfo[i].v0p;
  836. std::complex<double> rot = GetRotationComplex(interval);
  837. ///get the integer variable
  838. int integerVar = n_vert_vars + Handle_SystemInfo.EdgeSeamInfo[i].integerVar;
  839. if (integer_rounding)
  840. {
  841. ids_to_round.push_back(integerVar*2);
  842. ids_to_round.push_back(integerVar*2+1);
  843. }
  844. // cross boundary compatibility conditions
  845. Constraints.coeffRef(constr_row, 2*p0) += rot.real();
  846. Constraints.coeffRef(constr_row, 2*p0+1) += -rot.imag();
  847. Constraints.coeffRef(constr_row+1, 2*p0) += rot.imag();
  848. Constraints.coeffRef(constr_row+1, 2*p0+1) += rot.real();
  849. Constraints.coeffRef(constr_row, 2*p0p) += -1;
  850. Constraints.coeffRef(constr_row+1, 2*p0p+1) += -1;
  851. Constraints.coeffRef(constr_row, 2*integerVar) += 1;
  852. Constraints.coeffRef(constr_row+1, 2*integerVar+1) += 1;
  853. constraints_rhs[constr_row] = 0;
  854. constraints_rhs[constr_row+1] = 0;
  855. constr_row += 2;
  856. }
  857. }
  858. ///set the constraints for the inter-range cuts
  859. template <typename DerivedV, typename DerivedF>
  860. IGL_INLINE void igl::comiso::PoissonSolver<DerivedV, DerivedF>::BuildUserDefinedConstraints()
  861. {
  862. /// the user defined constraints are at the end
  863. int offset_row = num_cut_constraint*2 + n_fixed_vars*2;
  864. ///current constraint row
  865. int constr_row = offset_row;
  866. assert(num_userdefined_constraint == userdefined_constraints.size());
  867. for (unsigned int i=0; i<num_userdefined_constraint; i++)
  868. {
  869. for (unsigned int j=0; j<userdefined_constraints[i].size()-1; ++j)
  870. {
  871. Constraints.coeffRef(constr_row, j) = userdefined_constraints[i][j];
  872. }
  873. constraints_rhs[constr_row] = userdefined_constraints[i][userdefined_constraints[i].size()-1];
  874. constr_row +=1;
  875. }
  876. }
  877. ///call of the mixed integer solver
  878. template <typename DerivedV, typename DerivedF>
  879. IGL_INLINE void igl::comiso::PoissonSolver<DerivedV, DerivedF>::MixedIntegerSolve(double cone_grid_res,
  880. bool direct_round,
  881. int localIter)
  882. {
  883. X = std::vector<double>((n_vert_vars+n_integer_vars)*2);
  884. if (DEBUGPRINT)
  885. printf("\n ALLOCATED X \n");
  886. ///variables part
  887. int ScalarSize = n_vert_vars*2;
  888. int SizeMatrix = (n_vert_vars+n_integer_vars)*2;
  889. ///matrix A
  890. gmm::col_matrix< gmm::wsvector< double > > A(SizeMatrix,SizeMatrix); // lhs matrix variables
  891. ///constraints part
  892. int CsizeX = num_constraint_equations;
  893. int CsizeY = SizeMatrix+1;
  894. gmm::row_matrix< gmm::wsvector< double > > C(CsizeX,CsizeY); // constraints
  895. if (DEBUGPRINT)
  896. printf("\n ALLOCATED QMM STRUCTURES \n");
  897. std::vector<double> B(SizeMatrix,0); // rhs
  898. if (DEBUGPRINT)
  899. printf("\n ALLOCATED RHS STRUCTURES \n");
  900. //// copy LHS
  901. for (int k=0; k < Lhs.outerSize(); ++k){
  902. for (Eigen::SparseMatrix<double>::InnerIterator it(Lhs,k); it; ++it){
  903. int row = it.row();
  904. int col = it.col();
  905. A(row, col) += it.value();
  906. }
  907. }
  908. //// copy Constraints
  909. for (int k=0; k < Constraints.outerSize(); ++k){
  910. for (Eigen::SparseMatrix<double>::InnerIterator it(Constraints,k); it; ++it){
  911. int row = it.row();
  912. int col = it.col();
  913. C(row, col) += it.value();
  914. }
  915. }
  916. if (DEBUGPRINT)
  917. printf("\n SET %d INTEGER VALUES \n",n_integer_vars);
  918. ///add penalization term for integer variables
  919. double penalization = 0.000001;
  920. int offline_index = ScalarSize;
  921. for(unsigned int i = 0; i < (n_integer_vars)*2; ++i)
  922. {
  923. int index=offline_index+i;
  924. A(index,index)=penalization;
  925. }
  926. if (DEBUGPRINT)
  927. printf("\n SET RHS \n");
  928. // copy RHS
  929. for(int i = 0; i < (int)ScalarSize; ++i)
  930. {
  931. B[i] = rhs[i] * cone_grid_res;
  932. }
  933. // copy constraint RHS
  934. if (DEBUGPRINT)
  935. printf("\n SET %d CONSTRAINTS \n",num_constraint_equations);
  936. for(unsigned int i = 0; i < num_constraint_equations; ++i)
  937. {
  938. C(i, SizeMatrix) = -constraints_rhs[i] * cone_grid_res;
  939. }
  940. COMISO::ConstrainedSolver solver;
  941. solver.misolver().set_local_iters(localIter);
  942. solver.misolver().set_direct_rounding(direct_round);
  943. std::sort(ids_to_round.begin(),ids_to_round.end());
  944. std::vector<int>::iterator new_end=std::unique(ids_to_round.begin(),ids_to_round.end());
  945. int dist=distance(ids_to_round.begin(),new_end);
  946. ids_to_round.resize(dist);
  947. solver.solve( C, A, X, B, ids_to_round, 0.0, false, false);
  948. ////DEBUG OUTPUT
  949. if(integer_rounding){
  950. std::ofstream idsout("ids.txt");
  951. for(auto elem : ids_to_round){
  952. idsout << elem << std::endl;
  953. }
  954. idsout.close();
  955. std::ofstream consout("Cmat.txt");
  956. Eigen::SparseMatrix<double, Eigen::RowMajor> Cmat = Constraints;
  957. for (int k=0; k < Cmat.outerSize(); ++k){
  958. for (Eigen::SparseMatrix<double, Eigen::RowMajor>::InnerIterator it(Cmat,k); it; ++it){
  959. int row = it.row();
  960. int col = it.col();
  961. consout << "(" << row << ", " << col << ")" << "\t" << it.value() << std::endl;
  962. }
  963. }
  964. consout.close();
  965. std::ofstream rhsCout("rhsC.txt");
  966. rhsCout << rhs;
  967. rhsCout.close();
  968. std::ofstream xout("Xout.txt");
  969. for(auto it = X.begin(); it != X.end(); it+=2){
  970. xout << *it << "\t" << *(it+1) << std::endl;
  971. }
  972. xout.close();
  973. }
  974. }
  975. template <typename DerivedV, typename DerivedF>
  976. IGL_INLINE void igl::comiso::PoissonSolver<DerivedV, DerivedF>::clearUserConstraint()
  977. {
  978. num_userdefined_constraint = 0;
  979. userdefined_constraints.clear();
  980. }
  981. template <typename DerivedV, typename DerivedF>
  982. IGL_INLINE void igl::comiso::PoissonSolver<DerivedV, DerivedF>::addSharpEdgeConstraint(int fid, int vid)
  983. {
  984. // prepare constraint
  985. std::vector<int> c(Handle_SystemInfo.num_vert_variables*2 + 1);
  986. for (size_t i = 0; i < c.size(); ++i)
  987. {
  988. c[i] = 0;
  989. }
  990. int v1 = Fcut(fid,vid);
  991. int v2 = Fcut(fid,(vid+1)%3);
  992. Eigen::Matrix<typename DerivedV::Scalar, 3, 1> e = Vcut.row(v2) - Vcut.row(v1);
  993. e = e.normalized();
  994. double d1 = fabs(e.dot(PD1.row(fid).normalized()));
  995. double d2 = fabs(e.dot(PD2.row(fid).normalized()));
  996. int offset = 0;
  997. if (d1>d2)
  998. offset = 1;
  999. ids_to_round.push_back((v1 * 2) + offset);
  1000. ids_to_round.push_back((v2 * 2) + offset);
  1001. // add constraint
  1002. c[(v1 * 2) + offset] = 1;
  1003. c[(v2 * 2) + offset] = -1;
  1004. // add to the user-defined constraints
  1005. num_userdefined_constraint++;
  1006. userdefined_constraints.push_back(c);
  1007. }
  1008. template <typename DerivedV, typename DerivedF, typename DerivedU>
  1009. IGL_INLINE igl::comiso::MIQ_class<DerivedV, DerivedF, DerivedU>::MIQ_class(const Eigen::PlainObjectBase<DerivedV> &V_,
  1010. const Eigen::PlainObjectBase<DerivedF> &F_,
  1011. const Eigen::PlainObjectBase<DerivedV> &PD1_combed,
  1012. const Eigen::PlainObjectBase<DerivedV> &PD2_combed,
  1013. const Eigen::Matrix<int, Eigen::Dynamic, 3> &Handle_MMatch,
  1014. const Eigen::Matrix<int, Eigen::Dynamic, 1> &Handle_Singular,
  1015. const Eigen::Matrix<int, Eigen::Dynamic, 3> &Handle_Seams,
  1016. Eigen::PlainObjectBase<DerivedU> &UV,
  1017. Eigen::PlainObjectBase<DerivedF> &FUV,
  1018. double GradientSize,
  1019. double Stiffness,
  1020. bool DirectRound,
  1021. int iter,
  1022. int localIter,
  1023. bool DoRound,
  1024. bool SingularityRound,
  1025. std::vector<int> roundVertices,
  1026. std::vector<std::vector<int> > hardFeatures):
  1027. V(V_),
  1028. F(F_)
  1029. {
  1030. igl::cut_mesh(V, F, Handle_Seams, Vcut, Fcut);
  1031. igl::local_basis(V,F,B1,B2,B3);
  1032. igl::triangle_triangle_adjacency(V,F,TT,TTi);
  1033. // Prepare indexing for the linear system
  1034. VertexIndexing<DerivedV, DerivedF> VInd(V, F, Vcut, Fcut, TT, TTi, Handle_MMatch, Handle_Singular, Handle_Seams);
  1035. VInd.InitSeamInfo();
  1036. // Eigen::PlainObjectBase<DerivedV> PD1_combed_for_poisson, PD2_combed_for_poisson;
  1037. // // Rotate by 90 degrees CCW
  1038. // PD1_combed_for_poisson.setZero(PD1_combed.rows(),3);
  1039. // PD2_combed_for_poisson.setZero(PD2_combed.rows(),3);
  1040. // for (unsigned i=0; i<PD1_combed.rows();++i)
  1041. // {
  1042. // double n1 = PD1_combed.row(i).norm();
  1043. // double n2 = PD2_combed.row(i).norm();
  1044. //
  1045. // double a1 = atan2(B2.row(i).dot(PD1_combed.row(i)),B1.row(i).dot(PD1_combed.row(i)));
  1046. // double a2 = atan2(B2.row(i).dot(PD2_combed.row(i)),B1.row(i).dot(PD2_combed.row(i)));
  1047. //
  1048. // // a1 += M_PI/2;
  1049. // // a2 += M_PI/2;
  1050. //
  1051. //
  1052. // PD1_combed_for_poisson.row(i) = cos(a1) * B1.row(i) + sin(a1) * B2.row(i);
  1053. // PD2_combed_for_poisson.row(i) = cos(a2) * B1.row(i) + sin(a2) * B2.row(i);
  1054. //
  1055. // PD1_combed_for_poisson.row(i) = PD1_combed_for_poisson.row(i).normalized() * n1;
  1056. // PD2_combed_for_poisson.row(i) = PD2_combed_for_poisson.row(i).normalized() * n2;
  1057. // }
  1058. // Assemble the system and solve
  1059. PoissonSolver<DerivedV, DerivedF> PSolver(V,
  1060. F,
  1061. Vcut,
  1062. Fcut,
  1063. TT,
  1064. TTi,
  1065. PD1_combed,
  1066. PD2_combed,
  1067. Handle_Singular,
  1068. VInd.Handle_SystemInfo);
  1069. Handle_Stiffness = Eigen::VectorXd::Constant(F.rows(),1);
  1070. if (iter > 0) // do stiffening
  1071. {
  1072. for (int i=0;i<iter;i++)
  1073. {
  1074. PSolver.SolvePoisson(Handle_Stiffness, GradientSize,1.f,DirectRound,localIter,DoRound,SingularityRound,roundVertices,hardFeatures);
  1075. int nflips=NumFlips(PSolver.WUV);
  1076. bool folded = updateStiffeningJacobianDistorsion(GradientSize,PSolver.WUV);
  1077. printf("ITERATION %d FLIPS %d \n",i,nflips);
  1078. if (!folded)break;
  1079. }
  1080. }
  1081. else
  1082. {
  1083. PSolver.SolvePoisson(Handle_Stiffness,GradientSize,1.f,DirectRound,localIter,DoRound,SingularityRound,roundVertices,hardFeatures);
  1084. }
  1085. int nflips=NumFlips(PSolver.WUV);
  1086. printf("**** END OPTIMIZING #FLIPS %d ****\n",nflips);
  1087. UV_out = PSolver.UV_out;
  1088. FUV_out = PSolver.Fcut;
  1089. debugFaceEdgeInfo_out = VInd.DebugInfo;
  1090. fflush(stdout);
  1091. }
  1092. template <typename DerivedV, typename DerivedF, typename DerivedU>
  1093. IGL_INLINE void igl::comiso::MIQ_class<DerivedV, DerivedF, DerivedU>::extractUV(Eigen::PlainObjectBase<DerivedU> &UV_out,
  1094. Eigen::PlainObjectBase<DerivedF> &FUV_out)
  1095. {
  1096. UV_out = this->UV_out;
  1097. FUV_out = this->FUV_out;
  1098. }
  1099. //DEBUG
  1100. template <typename DerivedV, typename DerivedF, typename DerivedU>
  1101. IGL_INLINE void igl::comiso::MIQ_class<DerivedV, DerivedF, DerivedU>::extractDebugInfo(std::vector<igl::comiso::DebugFaceEdgeInfo>& debugFaceEdgeInfo){
  1102. debugFaceEdgeInfo = this->debugFaceEdgeInfo_out;
  1103. }
  1104. template <typename DerivedV, typename DerivedF, typename DerivedU>
  1105. IGL_INLINE int igl::comiso::MIQ_class<DerivedV, DerivedF, DerivedU>::NumFlips(const Eigen::MatrixXd& WUV)
  1106. {
  1107. int numFl=0;
  1108. for (unsigned int i=0;i<F.rows();i++)
  1109. {
  1110. if (IsFlipped(i, WUV))
  1111. numFl++;
  1112. }
  1113. return numFl;
  1114. }
  1115. template <typename DerivedV, typename DerivedF, typename DerivedU>
  1116. IGL_INLINE double igl::comiso::MIQ_class<DerivedV, DerivedF, DerivedU>::Distortion(int f, double h, const Eigen::MatrixXd& WUV)
  1117. {
  1118. assert(h > 0);
  1119. Eigen::Vector2d uv0,uv1,uv2;
  1120. uv0 << WUV(f,0), WUV(f,1);
  1121. uv1 << WUV(f,2), WUV(f,3);
  1122. uv2 << WUV(f,4), WUV(f,5);
  1123. Eigen::Matrix<typename DerivedV::Scalar, 3, 1> p0 = V.row(Fcut(f,0));
  1124. Eigen::Matrix<typename DerivedV::Scalar, 3, 1> p1 = V.row(Fcut(f,1));
  1125. Eigen::Matrix<typename DerivedV::Scalar, 3, 1> p2 = V.row(Fcut(f,2));
  1126. Eigen::Matrix<typename DerivedV::Scalar, 3, 1> norm = (p1 - p0).cross(p2 - p0);
  1127. double area2 = norm.norm();
  1128. double area2_inv = 1.0 / area2;
  1129. norm *= area2_inv;
  1130. if (area2 > 0)
  1131. {
  1132. // Singular values of the Jacobian
  1133. Eigen::Matrix<typename DerivedV::Scalar, 3, 1> neg_t0 = norm.cross(p2 - p1);
  1134. Eigen::Matrix<typename DerivedV::Scalar, 3, 1> neg_t1 = norm.cross(p0 - p2);
  1135. Eigen::Matrix<typename DerivedV::Scalar, 3, 1> neg_t2 = norm.cross(p1 - p0);
  1136. Eigen::Matrix<typename DerivedV::Scalar, 3, 1> diffu = (neg_t0 * uv0(0) +neg_t1 *uv1(0) + neg_t2 * uv2(0) )*area2_inv;
  1137. Eigen::Matrix<typename DerivedV::Scalar, 3, 1> diffv = (neg_t0 * uv0(1) + neg_t1*uv1(1) + neg_t2*uv2(1) )*area2_inv;
  1138. // first fundamental form
  1139. double I00 = diffu.dot(diffu); // guaranteed non-neg
  1140. double I01 = diffu.dot(diffv); // I01 = I10
  1141. double I11 = diffv.dot(diffv); // guaranteed non-neg
  1142. // eigenvalues of a 2x2 matrix
  1143. // [a00 a01]
  1144. // [a10 a11]
  1145. // 1/2 * [ (a00 + a11) +/- sqrt((a00 - a11)^2 + 4 a01 a10) ]
  1146. double trI = I00 + I11; // guaranteed non-neg
  1147. double diffDiag = I00 - I11; // guaranteed non-neg
  1148. double sqrtDet = sqrt(std::max(0.0, diffDiag*diffDiag +
  1149. 4 * I01 * I01)); // guaranteed non-neg
  1150. double sig1 = 0.5 * (trI + sqrtDet); // higher singular value
  1151. double sig2 = 0.5 * (trI - sqrtDet); // lower singular value
  1152. // Avoid sig2 < 0 due to numerical error
  1153. if (fabs(sig2) < 1.0e-8)
  1154. sig2 = 0;
  1155. assert(sig1 >= 0);
  1156. assert(sig2 >= 0);
  1157. if (sig2 < 0) {
  1158. printf("Distortion will be NaN! sig1^2 is negative (%lg)\n",
  1159. sig2);
  1160. }
  1161. // The singular values of the Jacobian are the sqrts of the
  1162. // eigenvalues of the first fundamental form.
  1163. sig1 = sqrt(sig1);
  1164. sig2 = sqrt(sig2);
  1165. // distortion
  1166. double tao = IsFlipped(f,WUV) ? -1 : 1;
  1167. double factor = tao / h;
  1168. double lam = fabs(factor * sig1 - 1) + fabs(factor * sig2 - 1);
  1169. return lam;
  1170. }
  1171. else {
  1172. return 10; // something "large"
  1173. }
  1174. }
  1175. ////////////////////////////////////////////////////////////////////////////
  1176. // Approximate the distortion laplacian using a uniform laplacian on
  1177. // the dual mesh:
  1178. // ___________
  1179. // \-1 / \-1 /
  1180. // \ / 3 \ /
  1181. // \-----/
  1182. // \-1 /
  1183. // \ /
  1184. //
  1185. // @param[in] f facet on which to compute distortion laplacian
  1186. // @param[in] h scaling factor applied to cross field
  1187. // @return distortion laplacian for f
  1188. ///////////////////////////////////////////////////////////////////////////
  1189. template <typename DerivedV, typename DerivedF, typename DerivedU>
  1190. IGL_INLINE double igl::comiso::MIQ_class<DerivedV, DerivedF, DerivedU>::LaplaceDistortion(const int f, double h, const Eigen::MatrixXd& WUV)
  1191. {
  1192. double mydist = Distortion(f, h, WUV);
  1193. double lapl=0;
  1194. for (int i=0;i<3;i++)
  1195. {
  1196. if (TT(f,i) != -1)
  1197. lapl += (mydist - Distortion(TT(f,i), h, WUV));
  1198. }
  1199. return lapl;
  1200. }
  1201. template <typename DerivedV, typename DerivedF, typename DerivedU>
  1202. IGL_INLINE bool igl::comiso::MIQ_class<DerivedV, DerivedF, DerivedU>::updateStiffeningJacobianDistorsion(double grad_size, const Eigen::MatrixXd& WUV)
  1203. {
  1204. bool flipped = NumFlips(WUV)>0;
  1205. if (!flipped)
  1206. return false;
  1207. double maxL=0;
  1208. double maxD=0;
  1209. if (flipped)
  1210. {
  1211. const double c = 1.0;
  1212. const double d = 5.0;
  1213. for (unsigned int i = 0; i < Fcut.rows(); ++i)
  1214. {
  1215. double dist=Distortion(i,grad_size,WUV);
  1216. if (dist > maxD)
  1217. maxD=dist;
  1218. double absLap=fabs(LaplaceDistortion(i, grad_size,WUV));
  1219. if (absLap > maxL)
  1220. maxL = absLap;
  1221. double stiffDelta = std::min(c * absLap, d);
  1222. Handle_Stiffness[i]+=stiffDelta;
  1223. }
  1224. }
  1225. printf("Maximum Distorsion %4.4f \n",maxD);
  1226. printf("Maximum Laplacian %4.4f \n",maxL);
  1227. return flipped;
  1228. }
  1229. template <typename DerivedV, typename DerivedF, typename DerivedU>
  1230. IGL_INLINE bool igl::comiso::MIQ_class<DerivedV, DerivedF, DerivedU>::IsFlipped(const Eigen::Vector2d &uv0,
  1231. const Eigen::Vector2d &uv1,
  1232. const Eigen::Vector2d &uv2)
  1233. {
  1234. Eigen::Vector2d e0 = (uv1-uv0);
  1235. Eigen::Vector2d e1 = (uv2-uv0);
  1236. double Area = e0(0)*e1(1) - e0(1)*e1(0);
  1237. return (Area<=0);
  1238. }
  1239. template <typename DerivedV, typename DerivedF, typename DerivedU>
  1240. IGL_INLINE bool igl::comiso::MIQ_class<DerivedV, DerivedF, DerivedU>::IsFlipped(
  1241. const int i, const Eigen::MatrixXd& WUV)
  1242. {
  1243. Eigen::Vector2d uv0,uv1,uv2;
  1244. uv0 << WUV(i,0), WUV(i,1);
  1245. uv1 << WUV(i,2), WUV(i,3);
  1246. uv2 << WUV(i,4), WUV(i,5);
  1247. return (IsFlipped(uv0,uv1,uv2));
  1248. }
  1249. template <typename DerivedV, typename DerivedF, typename DerivedU>
  1250. IGL_INLINE void igl::comiso::miq(
  1251. const Eigen::PlainObjectBase<DerivedV> &V,
  1252. const Eigen::PlainObjectBase<DerivedF> &F,
  1253. const Eigen::PlainObjectBase<DerivedV> &PD1_combed,
  1254. const Eigen::PlainObjectBase<DerivedV> &PD2_combed,
  1255. const Eigen::Matrix<int, Eigen::Dynamic, 3> &Handle_MMatch,
  1256. const Eigen::Matrix<int, Eigen::Dynamic, 1> &Handle_Singular,
  1257. const Eigen::Matrix<int, Eigen::Dynamic, 3> &Handle_Seams,
  1258. Eigen::PlainObjectBase<DerivedU> &UV,
  1259. Eigen::PlainObjectBase<DerivedF> &FUV,
  1260. //DEBUG
  1261. std::vector<igl::comiso::DebugFaceEdgeInfo> &debugFaceEdgeInfo,
  1262. double GradientSize,
  1263. double Stiffness,
  1264. bool DirectRound,
  1265. int iter,
  1266. int localIter,
  1267. bool DoRound,
  1268. bool SingularityRound,
  1269. std::vector<int> roundVertices,
  1270. std::vector<std::vector<int> > hardFeatures)
  1271. {
  1272. GradientSize = GradientSize/(V.colwise().maxCoeff()-V.colwise().minCoeff()).norm();
  1273. igl::comiso::MIQ_class<DerivedV, DerivedF, DerivedU> miq(V,
  1274. F,
  1275. PD1_combed,
  1276. PD2_combed,
  1277. Handle_MMatch,
  1278. Handle_Singular,
  1279. Handle_Seams,
  1280. UV,
  1281. FUV,
  1282. GradientSize,
  1283. Stiffness,
  1284. DirectRound,
  1285. iter,
  1286. localIter,
  1287. DoRound,
  1288. SingularityRound,
  1289. roundVertices,
  1290. hardFeatures);
  1291. miq.extractUV(UV,FUV);
  1292. miq.extractDebugInfo(debugFaceEdgeInfo);
  1293. }
  1294. template <typename DerivedV, typename DerivedF, typename DerivedU>
  1295. IGL_INLINE void igl::comiso::miq(
  1296. const Eigen::PlainObjectBase<DerivedV> &V,
  1297. const Eigen::PlainObjectBase<DerivedF> &F,
  1298. const Eigen::PlainObjectBase<DerivedV> &PD1,
  1299. const Eigen::PlainObjectBase<DerivedV> &PD2,
  1300. Eigen::PlainObjectBase<DerivedU> &UV,
  1301. Eigen::PlainObjectBase<DerivedF> &FUV,
  1302. //DEBUG
  1303. std::vector<igl::comiso::DebugFaceEdgeInfo> &debugFaceEdgeInfo,
  1304. double GradientSize,
  1305. double Stiffness,
  1306. bool DirectRound,
  1307. int iter,
  1308. int localIter,
  1309. bool DoRound,
  1310. bool SingularityRound,
  1311. std::vector<int> roundVertices,
  1312. std::vector<std::vector<int> > hardFeatures)
  1313. {
  1314. // Eigen::MatrixXd PD2i = PD2;
  1315. // if (PD2i.size() == 0)
  1316. // {
  1317. // Eigen::MatrixXd B1, B2, B3;
  1318. // igl::local_basis(V,F,B1,B2,B3);
  1319. // PD2i = igl::rotate_vectors(V,Eigen::VectorXd::Constant(1,M_PI/2),B1,B2);
  1320. // }
  1321. Eigen::PlainObjectBase<DerivedV> BIS1, BIS2;
  1322. igl::compute_frame_field_bisectors(V, F, PD1, PD2, BIS1, BIS2);
  1323. Eigen::PlainObjectBase<DerivedV> BIS1_combed, BIS2_combed;
  1324. igl::comb_cross_field(V, F, BIS1, BIS2, BIS1_combed, BIS2_combed);
  1325. Eigen::PlainObjectBase<DerivedF> Handle_MMatch;
  1326. igl::cross_field_missmatch(V, F, BIS1_combed, BIS2_combed, true, Handle_MMatch);
  1327. Eigen::Matrix<int, Eigen::Dynamic, 1> isSingularity, singularityIndex;
  1328. igl::find_cross_field_singularities(V, F, Handle_MMatch, isSingularity, singularityIndex);
  1329. Eigen::Matrix<int, Eigen::Dynamic, 3> Handle_Seams;
  1330. igl::cut_mesh_from_singularities(V, F, Handle_MMatch, Handle_Seams);
  1331. Eigen::PlainObjectBase<DerivedV> PD1_combed, PD2_combed;
  1332. igl::comb_frame_field(V, F, PD1, PD2, BIS1_combed, BIS2_combed, PD1_combed, PD2_combed);
  1333. igl::comiso::miq(V,
  1334. F,
  1335. PD1_combed,
  1336. PD2_combed,
  1337. Handle_MMatch,
  1338. isSingularity,
  1339. Handle_Seams,
  1340. UV,
  1341. FUV,
  1342. //DEBUG
  1343. debugFaceEdgeInfo,
  1344. GradientSize,
  1345. Stiffness,
  1346. DirectRound,
  1347. iter,
  1348. localIter,
  1349. DoRound,
  1350. SingularityRound,
  1351. roundVertices,
  1352. hardFeatures);
  1353. }
  1354. #ifdef IGL_STATIC_LIBRARY
  1355. // Explicit template specialization
  1356. template void igl::comiso::miq<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> >&, double, double, bool, int, int, bool, bool, std::__1::vector<int, std::__1::allocator<int> >, std::__1::vector<std::__1::vector<int, std::__1::allocator<int> >, std::__1::allocator<std::__1::vector<int, std::__1::allocator<int> > > >);
  1357. template void igl::comiso::miq<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::Matrix<int, -1, 3, 0, -1, 3> const&, Eigen::Matrix<int, -1, 1, 0, -1, 1> const&, Eigen::Matrix<int, -1, 3, 0, -1, 3> const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, double, double, bool, int, int, bool, bool, std::__1::vector<int, std::__1::allocator<int> >, std::__1::vector<std::__1::vector<int, std::__1::allocator<int> >, std::__1::allocator<std::__1::vector<int, std::__1::allocator<int> > > >);
  1358. template void igl::comiso::miq<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, double, double, bool, int, int, bool, bool, std::__1::vector<int, std::__1::allocator<int> >, std::__1::vector<std::__1::vector<int, std::__1::allocator<int> >, std::__1::allocator<std::__1::vector<int, std::__1::allocator<int> > > >);
  1359. #endif