miq.cpp 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282
  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. // includes for VertexIndexing
  12. #include <igl/HalfEdgeIterator.h>
  13. #include <igl/is_border_vertex.h>
  14. #include <igl/vertex_triangle_adjacency.h>
  15. // includes for poissonSolver
  16. #include <gmm/gmm.h>
  17. #include <CoMISo/Solver/ConstrainedSolver.hh>
  18. #include <CoMISo/Solver/MISolver.hh>
  19. #include <CoMISo/Solver/GMM_Tools.hh>
  20. #include <igl/doublearea.h>
  21. #include <igl/per_face_normals.h>
  22. //
  23. #include <igl/cross_field_missmatch.h>
  24. #include <igl/comb_frame_field.h>
  25. #include <igl/comb_cross_field.h>
  26. #include <igl/cut_mesh_from_singularities.h>
  27. #include <igl/find_cross_field_singularities.h>
  28. #include <igl/compute_frame_field_bisectors.h>
  29. #include <igl/rotate_vectors.h>
  30. #define DEBUGPRINT 0
  31. namespace igl {
  32. class SparseMatrixData{
  33. protected:
  34. unsigned int m_nrows;
  35. unsigned int m_ncols;
  36. std::vector<unsigned int> m_rowind;
  37. std::vector<unsigned int> m_colind;
  38. std::vector<double> m_vals;
  39. public:
  40. unsigned int nrows() { return m_nrows ; }
  41. unsigned int ncols() { return m_ncols ; }
  42. unsigned int nentries() { return m_vals.size(); }
  43. std::vector<unsigned int>& rowind() { return m_rowind ; }
  44. std::vector<unsigned int>& colind() { return m_colind ; }
  45. std::vector<double>& vals() { return m_vals ; }
  46. // create an empty matrix with a fixed number of rows
  47. IGL_INLINE SparseMatrixData()
  48. {
  49. initialize(0,0);
  50. }
  51. // create an empty matrix with a fixed number of rows
  52. IGL_INLINE void initialize(int nr, int nc) {
  53. assert(nr >= 0 && nc >=0);
  54. m_nrows = nr;
  55. m_ncols = nc;
  56. m_rowind.resize(0);
  57. m_colind.resize(0);
  58. m_vals.resize(0);
  59. }
  60. // add a nonzero entry to the matrix
  61. // no checks are done for coinciding entries
  62. // the interpretation of the repeated entries (replace or add)
  63. // depends on how the actual sparse matrix datastructure is constructed
  64. IGL_INLINE void addEntryCmplx(unsigned int i, unsigned int j, std::complex<double> val) {
  65. m_rowind.push_back(2*i); m_colind.push_back(2*j); m_vals.push_back( val.real());
  66. m_rowind.push_back(2*i); m_colind.push_back(2*j+1); m_vals.push_back(-val.imag());
  67. m_rowind.push_back(2*i+1); m_colind.push_back(2*j); m_vals.push_back( val.imag());
  68. m_rowind.push_back(2*i+1); m_colind.push_back(2*j+1); m_vals.push_back( val.real());
  69. }
  70. IGL_INLINE void addEntryReal(unsigned int i, unsigned int j, double val) {
  71. m_rowind.push_back(i); m_colind.push_back(j); m_vals.push_back(val);
  72. }
  73. IGL_INLINE virtual ~SparseMatrixData() {
  74. }
  75. };
  76. // a small class to manage storage for matrix data
  77. // not using stl vectors: want to make all memory management
  78. // explicit to avoid hidden automatic reallocation
  79. // TODO: redo with STL vectors but with explicit mem. management
  80. class SparseSystemData {
  81. private:
  82. // matrix representation, A[rowind[i],colind[i]] = vals[i]
  83. // right-hand side
  84. SparseMatrixData m_A;
  85. double *m_b;
  86. double *m_x;
  87. public:
  88. IGL_INLINE SparseMatrixData& A() { return m_A; }
  89. IGL_INLINE double* b() { return m_b ; }
  90. IGL_INLINE double* x() { return m_x ; }
  91. IGL_INLINE unsigned int nrows() { return m_A.nrows(); }
  92. public:
  93. IGL_INLINE SparseSystemData(): m_A(), m_b(NULL), m_x(NULL){ }
  94. IGL_INLINE void initialize(unsigned int nr, unsigned int nc) {
  95. m_A.initialize(nr,nc);
  96. m_b = new double[nr];
  97. m_x = new double[nr];
  98. assert(m_b);
  99. std::fill( m_b, m_b+nr, 0.);
  100. }
  101. IGL_INLINE void addRHSCmplx(unsigned int i, std::complex<double> val) {
  102. assert( 2*i+1 < m_A.nrows());
  103. m_b[2*i] += val.real(); m_b[2*i+1] += val.imag();
  104. }
  105. IGL_INLINE void setRHSCmplx(unsigned int i, std::complex<double> val) {
  106. assert( 2*i+1 < m_A.nrows());
  107. m_b[2*i] = val.real(); m_b[2*i+1] = val.imag();
  108. }
  109. IGL_INLINE std::complex<double> getRHSCmplx(unsigned int i) {
  110. assert( 2*i+1 < m_A.nrows());
  111. return std::complex<double>( m_b[2*i], m_b[2*i+1]);
  112. }
  113. IGL_INLINE double getRHSReal(unsigned int i) {
  114. assert( i < m_A.nrows());
  115. return m_b[i];
  116. }
  117. IGL_INLINE std::complex<double> getXCmplx(unsigned int i) {
  118. assert( 2*i+1 < m_A.nrows());
  119. return std::complex<double>( m_x[2*i], m_x[2*i+1]);
  120. }
  121. IGL_INLINE void cleanMem() {
  122. //m_A.cleanup();
  123. delete [] m_b;
  124. delete [] m_x;
  125. }
  126. IGL_INLINE virtual ~SparseSystemData() {
  127. delete [] m_b;
  128. delete [] m_x;
  129. }
  130. };
  131. struct SeamInfo
  132. {
  133. int v0,v0p,v1,v1p;
  134. int integerVar;
  135. unsigned char MMatch;
  136. IGL_INLINE SeamInfo(int _v0,
  137. int _v1,
  138. int _v0p,
  139. int _v1p,
  140. int _MMatch,
  141. int _integerVar);
  142. IGL_INLINE SeamInfo(const SeamInfo &S1);
  143. };
  144. struct MeshSystemInfo
  145. {
  146. ///total number of scalar variables
  147. int num_scalar_variables;
  148. ////number of vertices variables
  149. int num_vert_variables;
  150. ///num of integer for cuts
  151. int num_integer_cuts;
  152. ///this are used for drawing purposes
  153. std::vector<SeamInfo> EdgeSeamInfo;
  154. #if 0
  155. ///this are values of integer variables after optimization
  156. std::vector<int> IntegerValues;
  157. #endif
  158. };
  159. template <typename DerivedV, typename DerivedF>
  160. class VertexIndexing
  161. {
  162. public:
  163. // Input:
  164. const Eigen::PlainObjectBase<DerivedV> &V;
  165. const Eigen::PlainObjectBase<DerivedF> &F;
  166. const Eigen::PlainObjectBase<DerivedF> &TT;
  167. const Eigen::PlainObjectBase<DerivedF> &TTi;
  168. const Eigen::PlainObjectBase<DerivedV> &PD1;
  169. const Eigen::PlainObjectBase<DerivedV> &PD2;
  170. const Eigen::Matrix<int, Eigen::Dynamic, 3> &Handle_MMatch;
  171. const Eigen::Matrix<int, Eigen::Dynamic, 1> &Handle_Singular; // bool
  172. const Eigen::Matrix<int, Eigen::Dynamic, 1> &Handle_SingularDegree; // vertex;
  173. const Eigen::Matrix<int, Eigen::Dynamic, 3> &Handle_Seams; // 3 bool
  174. ///this handle for mesh TODO: move with the other global variables
  175. MeshSystemInfo Handle_SystemInfo;
  176. // Output:
  177. ///this maps the integer for edge - face
  178. Eigen::MatrixXi Handle_Integer; // TODO: remove it is useless
  179. ///per face indexes of vertex in the solver
  180. Eigen::MatrixXi HandleS_Index;
  181. ///per vertex variable indexes
  182. std::vector<std::vector<int> > HandleV_Integer;
  183. // internal
  184. std::vector<std::vector<int> > VF, VFi;
  185. std::vector<bool> V_border; // bool
  186. IGL_INLINE VertexIndexing(const Eigen::PlainObjectBase<DerivedV> &_V,
  187. const Eigen::PlainObjectBase<DerivedF> &_F,
  188. const Eigen::PlainObjectBase<DerivedF> &_TT,
  189. const Eigen::PlainObjectBase<DerivedF> &_TTi,
  190. const Eigen::PlainObjectBase<DerivedV> &_PD1,
  191. const Eigen::PlainObjectBase<DerivedV> &_PD2,
  192. const Eigen::Matrix<int, Eigen::Dynamic, 3> &_Handle_MMatch,
  193. const Eigen::Matrix<int, Eigen::Dynamic, 1> &_Handle_Singular,
  194. const Eigen::Matrix<int, Eigen::Dynamic, 1> &_Handle_SingularDegree,
  195. const Eigen::Matrix<int, Eigen::Dynamic, 3> &_Handle_Seams
  196. );
  197. ///vertex to variable mapping
  198. IGL_INLINE void InitMapping();
  199. IGL_INLINE void InitFaceIntegerVal();
  200. IGL_INLINE void InitSeamInfo();
  201. private:
  202. ///this maps back index to vertices
  203. std::vector<int> IndexToVert; // TODO remove it is useless
  204. ///this is used for drawing purposes
  205. std::vector<int> duplicated; // TODO remove it is useless
  206. IGL_INLINE void FirstPos(const int v, int &f, int &edge);
  207. IGL_INLINE int AddNewIndex(const int v0);
  208. IGL_INLINE bool HasIndex(int indexVert,int indexVar);
  209. IGL_INLINE void GetSeamInfo(const int f0,
  210. const int f1,
  211. const int indexE,
  212. int &v0,int &v1,
  213. int &v0p,int &v1p,
  214. unsigned char &_MMatch,
  215. int &integerVar);
  216. IGL_INLINE bool IsSeam(const int f0, const int f1);
  217. ///find initial position of the pos to
  218. // assing face to vert inxex correctly
  219. IGL_INLINE void FindInitialPos(const int vert, int &edge, int &face);
  220. ///intialize the mapping given an initial pos
  221. ///whih must be initialized with FindInitialPos
  222. IGL_INLINE void MapIndexes(const int vert, const int edge_init, const int f_init);
  223. ///intialize the mapping for a given vertex
  224. IGL_INLINE void InitMappingSeam(const int vert);
  225. ///intialize the mapping for a given sampled mesh
  226. IGL_INLINE void InitMappingSeam();
  227. ///test consistency of face variables per vert mapping
  228. IGL_INLINE void TestSeamMappingFace(const int f);
  229. ///test consistency of face variables per vert mapping
  230. IGL_INLINE void TestSeamMappingVertex(int indexVert);
  231. ///check consistency of variable mapping across seams
  232. IGL_INLINE void TestSeamMapping();
  233. };
  234. template <typename DerivedV, typename DerivedF>
  235. class PoissonSolver
  236. {
  237. public:
  238. IGL_INLINE void SolvePoisson(Eigen::VectorXd Stiffness,
  239. double vector_field_scale=0.1f,
  240. double grid_res=1.f,
  241. bool direct_round=true,
  242. int localIter=0,
  243. bool _integer_rounding=true,
  244. std::vector<int> roundVertices = std::vector<int>(),
  245. std::vector<std::vector<int> > hardFeatures = std::vector<std::vector<int> >());
  246. IGL_INLINE PoissonSolver(const Eigen::PlainObjectBase<DerivedV> &_V,
  247. const Eigen::PlainObjectBase<DerivedF> &_F,
  248. const Eigen::PlainObjectBase<DerivedF> &_TT,
  249. const Eigen::PlainObjectBase<DerivedF> &_TTi,
  250. const Eigen::PlainObjectBase<DerivedV> &_PD1,
  251. const Eigen::PlainObjectBase<DerivedV> &_PD2,
  252. const Eigen::MatrixXi &_HandleS_Index,
  253. const Eigen::Matrix<int, Eigen::Dynamic, 1>&_Handle_Singular,
  254. const MeshSystemInfo &_Handle_SystemInfo
  255. );
  256. const Eigen::PlainObjectBase<DerivedV> &V;
  257. const Eigen::PlainObjectBase<DerivedF> &F;
  258. const Eigen::PlainObjectBase<DerivedF> &TT;
  259. const Eigen::PlainObjectBase<DerivedF> &TTi;
  260. const Eigen::PlainObjectBase<DerivedV> &PD1;
  261. const Eigen::PlainObjectBase<DerivedV> &PD2;
  262. const Eigen::Matrix<int, Eigen::Dynamic, 1> &Handle_Singular; // bool
  263. const Eigen::MatrixXi &HandleS_Index; //todo
  264. const MeshSystemInfo &Handle_SystemInfo;
  265. // Internal:
  266. Eigen::MatrixXd doublearea;
  267. Eigen::VectorXd Handle_Stiffness;
  268. Eigen::PlainObjectBase<DerivedV> N;
  269. std::vector<std::vector<int> > VF;
  270. std::vector<std::vector<int> > VFi;
  271. Eigen::MatrixXd UV; // this is probably useless
  272. // Output:
  273. // per wedge UV coordinates, 6 coordinates (1 face) per row
  274. Eigen::MatrixXd WUV;
  275. ///solver data
  276. SparseSystemData S;
  277. ///vector of unknowns
  278. std::vector< double > X;
  279. ////REAL PART
  280. ///number of fixed vertex
  281. unsigned int n_fixed_vars;
  282. ///the number of REAL variables for vertices
  283. unsigned int n_vert_vars;
  284. ///total number of variables of the system,
  285. ///do not consider constraints, but consider integer vars
  286. unsigned int num_total_vars;
  287. //////INTEGER PART
  288. ///the total number of integer variables
  289. unsigned int n_integer_vars;
  290. ///CONSTRAINT PART
  291. ///number of cuts constraints
  292. unsigned int num_cut_constraint;
  293. // number of user-defined constraints
  294. unsigned int num_userdefined_constraint;
  295. ///total number of constraints equations
  296. unsigned int num_constraint_equations;
  297. ///total size of the system including constraints
  298. unsigned int system_size;
  299. ///if you intend to make integer rotation
  300. ///and translations
  301. bool integer_jumps_bary;
  302. ///vector of blocked vertices
  303. std::vector<int> Hard_constraints;
  304. ///vector of indexes to round
  305. std::vector<int> ids_to_round;
  306. ///vector of indexes to round
  307. std::vector<std::vector<int > > userdefined_constraints;
  308. ///boolean that is true if rounding to integer is needed
  309. bool integer_rounding;
  310. ///START SYSTEM ACCESS METHODS
  311. ///add an entry to the LHS
  312. IGL_INLINE void AddValA(int Xindex,
  313. int Yindex,
  314. double val);
  315. ///add a complex entry to the LHS
  316. IGL_INLINE void AddComplexA(int VarXindex,
  317. int VarYindex,
  318. std::complex<double> val);
  319. ///add a velue to the RHS
  320. IGL_INLINE void AddValB(int Xindex,
  321. double val);
  322. ///add the area term, scalefactor is used to sum up
  323. ///and normalize on the overlap zones
  324. IGL_INLINE void AddAreaTerm(int index[3][3][2],double ScaleFactor);
  325. ///set the diagonal of the matrix (which is zero at the beginning)
  326. ///such that the sum of a row or a colums is zero
  327. IGL_INLINE void SetDiagonal(double val[3][3]);
  328. ///given a vector of scalar values and
  329. ///a vector of indexes add such values
  330. ///as specified by the indexes
  331. IGL_INLINE void AddRHS(double b[6],
  332. int index[3]);
  333. ///add a 3x3 block matrix to the system matrix...
  334. ///indexes are specified in the 3x3 matrix of x,y pairs
  335. ///indexes must be multiplied by 2 cause u and v
  336. IGL_INLINE void Add33Block(double val[3][3], int index[3][3][2]);
  337. ///add a 3x3 block matrix to the system matrix...
  338. ///indexes are specified in the 3x3 matrix of x,y pairs
  339. ///indexes must be multiplied by 2 cause u and v
  340. IGL_INLINE void Add44Block(double val[4][4],int index[4][4][2]);
  341. ///END SYSTEM ACCESS METHODS
  342. ///START COMMON MATH FUNCTIONS
  343. ///return the complex encoding the rotation
  344. ///for a given missmatch interval
  345. IGL_INLINE std::complex<double> GetRotationComplex(int interval);
  346. ///END COMMON MATH FUNCTIONS
  347. ///START ENERGY MINIMIZATION PART
  348. ///initialize the LHS for a given face
  349. ///for minimization of Dirichlet's energy
  350. IGL_INLINE void perElementLHS(int f,
  351. double val[3][3],
  352. int index[3][3][2]);
  353. ///initialize the RHS for a given face
  354. ///for minimization of Dirichlet's energy
  355. IGL_INLINE void perElementRHS(int f,
  356. double b[6],
  357. double vector_field_scale=1);
  358. ///evaluate the LHS and RHS for a single face
  359. ///for minimization of Dirichlet's energy
  360. IGL_INLINE void PerElementSystemReal(int f,
  361. double val[3][3],
  362. int index[3][3][2],
  363. double b[6],
  364. double vector_field_scale=1.0);
  365. ///END ENERGY MINIMIZATION PART
  366. ///START FIXING VERTICES
  367. ///set a given vertex as fixed
  368. IGL_INLINE void AddFixedVertex(int v);
  369. ///find vertex to fix in case we're using
  370. ///a vector field NB: multiple components not handled
  371. IGL_INLINE void FindFixedVertField();
  372. ///find hard constraint depending if using or not
  373. ///a vector field
  374. IGL_INLINE void FindFixedVert();
  375. IGL_INLINE int GetFirstVertexIndex(int v);
  376. ///fix the vertices which are flagged as fixed
  377. IGL_INLINE void FixBlockedVertex();
  378. ///END FIXING VERTICES
  379. ///HANDLING SINGULARITY
  380. //set the singularity round to integer location
  381. IGL_INLINE void AddSingularityRound();
  382. IGL_INLINE void AddToRoundVertices(std::vector<int> ids);
  383. ///START GENERIC SYSTEM FUNCTIONS
  384. //build the laplacian matrix cyclyng over all rangemaps
  385. //and over all faces
  386. IGL_INLINE void BuildLaplacianMatrix(double vfscale=1);
  387. ///find different sized of the system
  388. IGL_INLINE void FindSizes();
  389. IGL_INLINE void AllocateSystem();
  390. ///intitialize the whole matrix
  391. IGL_INLINE void InitMatrix();
  392. ///map back coordinates after that
  393. ///the system has been solved
  394. IGL_INLINE void MapCoords();
  395. ///END GENERIC SYSTEM FUNCTIONS
  396. ///set the constraints for the inter-range cuts
  397. IGL_INLINE void BuildSeamConstraintsExplicitTranslation();
  398. ///set the constraints for the inter-range cuts
  399. IGL_INLINE void BuildUserDefinedConstraints();
  400. ///call of the mixed integer solver
  401. IGL_INLINE void MixedIntegerSolve(double cone_grid_res=1,
  402. bool direct_round=true,
  403. int localIter=0);
  404. IGL_INLINE void clearUserConstraint();
  405. IGL_INLINE void addSharpEdgeConstraint(int fid, int vid);
  406. };
  407. template <typename DerivedV, typename DerivedF, typename DerivedU>
  408. class MIQ_class
  409. {
  410. private:
  411. const Eigen::PlainObjectBase<DerivedV> &V;
  412. const Eigen::PlainObjectBase<DerivedF> &F;
  413. Eigen::MatrixXd WUV;
  414. // internal
  415. Eigen::PlainObjectBase<DerivedF> TT;
  416. Eigen::PlainObjectBase<DerivedF> TTi;
  417. // Stiffness per face
  418. Eigen::VectorXd Handle_Stiffness;
  419. Eigen::PlainObjectBase<DerivedV> B1, B2, B3;
  420. public:
  421. IGL_INLINE MIQ_class(const Eigen::PlainObjectBase<DerivedV> &V_,
  422. const Eigen::PlainObjectBase<DerivedF> &F_,
  423. const Eigen::PlainObjectBase<DerivedV> &PD1_combed,
  424. const Eigen::PlainObjectBase<DerivedV> &PD2_combed,
  425. const Eigen::PlainObjectBase<DerivedV> &BIS1_combed,
  426. const Eigen::PlainObjectBase<DerivedV> &BIS2_combed,
  427. const Eigen::Matrix<int, Eigen::Dynamic, 3> &Handle_MMatch,
  428. const Eigen::Matrix<int, Eigen::Dynamic, 1> &Handle_Singular,
  429. const Eigen::Matrix<int, Eigen::Dynamic, 1> &Handle_SingularDegree,
  430. const Eigen::Matrix<int, Eigen::Dynamic, 3> &Handle_Seams,
  431. Eigen::PlainObjectBase<DerivedU> &UV,
  432. Eigen::PlainObjectBase<DerivedF> &FUV,
  433. double GradientSize = 30.0,
  434. double Stiffness = 5.0,
  435. bool DirectRound = false,
  436. int iter = 5,
  437. int localIter = 5,
  438. bool DoRound = true,
  439. std::vector<int> roundVertices = std::vector<int>(),
  440. std::vector<std::vector<int> > hardFeatures = std::vector<std::vector<int> >());
  441. IGL_INLINE void extractUV(Eigen::PlainObjectBase<DerivedU> &UV_out,
  442. Eigen::PlainObjectBase<DerivedF> &FUV_out);
  443. private:
  444. IGL_INLINE int NumFlips(const Eigen::MatrixXd& WUV);
  445. IGL_INLINE double Distortion(int f, double h, const Eigen::MatrixXd& WUV);
  446. IGL_INLINE double LaplaceDistortion(const int f, double h, const Eigen::MatrixXd& WUV);
  447. IGL_INLINE bool updateStiffeningJacobianDistorsion(double grad_size, const Eigen::MatrixXd& WUV);
  448. IGL_INLINE bool IsFlipped(const Eigen::Vector2d &uv0,
  449. const Eigen::Vector2d &uv1,
  450. const Eigen::Vector2d &uv2);
  451. IGL_INLINE bool IsFlipped(const int i, const Eigen::MatrixXd& WUV);
  452. };
  453. };
  454. IGL_INLINE igl::SeamInfo::SeamInfo(int _v0,
  455. int _v1,
  456. int _v0p,
  457. int _v1p,
  458. int _MMatch,
  459. int _integerVar)
  460. {
  461. v0=_v0;
  462. v1=_v1;
  463. v0p=_v0p;
  464. v1p=_v1p;
  465. integerVar=_integerVar;
  466. MMatch=_MMatch;
  467. }
  468. IGL_INLINE igl::SeamInfo::SeamInfo(const SeamInfo &S1)
  469. {
  470. v0=S1.v0;
  471. v1=S1.v1;
  472. v0p=S1.v0p;
  473. v1p=S1.v1p;
  474. integerVar=S1.integerVar;
  475. MMatch=S1.MMatch;
  476. }
  477. template <typename DerivedV, typename DerivedF>
  478. IGL_INLINE igl::VertexIndexing<DerivedV, DerivedF>::VertexIndexing(const Eigen::PlainObjectBase<DerivedV> &_V,
  479. const Eigen::PlainObjectBase<DerivedF> &_F,
  480. const Eigen::PlainObjectBase<DerivedF> &_TT,
  481. const Eigen::PlainObjectBase<DerivedF> &_TTi,
  482. const Eigen::PlainObjectBase<DerivedV> &_PD1,
  483. const Eigen::PlainObjectBase<DerivedV> &_PD2,
  484. const Eigen::Matrix<int, Eigen::Dynamic, 3> &_Handle_MMatch,
  485. const Eigen::Matrix<int, Eigen::Dynamic, 1> &_Handle_Singular,
  486. const Eigen::Matrix<int, Eigen::Dynamic, 1> &_Handle_SingularDegree,
  487. const Eigen::Matrix<int, Eigen::Dynamic, 3> &_Handle_Seams
  488. ):
  489. V(_V),
  490. F(_F),
  491. TT(_TT),
  492. TTi(_TTi),
  493. PD1(_PD1),
  494. PD2(_PD2),
  495. Handle_MMatch(_Handle_MMatch),
  496. Handle_Singular(_Handle_Singular),
  497. Handle_SingularDegree(_Handle_SingularDegree),
  498. Handle_Seams(_Handle_Seams)
  499. {
  500. V_border = igl::is_border_vertex(V,F);
  501. igl::vertex_triangle_adjacency(V,F,VF,VFi);
  502. IndexToVert.clear();
  503. Handle_SystemInfo.num_scalar_variables=0;
  504. Handle_SystemInfo.num_vert_variables=0;
  505. Handle_SystemInfo.num_integer_cuts=0;
  506. duplicated.clear();
  507. HandleS_Index = Eigen::MatrixXi::Constant(F.rows(),3,-1);
  508. Handle_Integer = Eigen::MatrixXi::Constant(F.rows(),3,-1);
  509. HandleV_Integer.resize(V.rows());
  510. }
  511. template <typename DerivedV, typename DerivedF>
  512. IGL_INLINE void igl::VertexIndexing<DerivedV, DerivedF>::FirstPos(const int v, int &f, int &edge)
  513. {
  514. f = VF[v][0]; // f=v->cVFp();
  515. edge = VFi[v][0]; // edge=v->cVFi();
  516. }
  517. template <typename DerivedV, typename DerivedF>
  518. IGL_INLINE int igl::VertexIndexing<DerivedV, DerivedF>::AddNewIndex(const int v0)
  519. {
  520. Handle_SystemInfo.num_scalar_variables++;
  521. HandleV_Integer[v0].push_back(Handle_SystemInfo.num_scalar_variables);
  522. IndexToVert.push_back(v0);
  523. return Handle_SystemInfo.num_scalar_variables;
  524. }
  525. template <typename DerivedV, typename DerivedF>
  526. IGL_INLINE bool igl::VertexIndexing<DerivedV, DerivedF>::HasIndex(int indexVert,int indexVar)
  527. {
  528. for (unsigned int i=0;i<HandleV_Integer[indexVert].size();i++)
  529. if (HandleV_Integer[indexVert][i]==indexVar)return true;
  530. return false;
  531. }
  532. template <typename DerivedV, typename DerivedF>
  533. IGL_INLINE void igl::VertexIndexing<DerivedV, DerivedF>::GetSeamInfo(const int f0,
  534. const int f1,
  535. const int indexE,
  536. int &v0,int &v1,
  537. int &v0p,int &v1p,
  538. unsigned char &_MMatch,
  539. int &integerVar)
  540. {
  541. int edgef0 = indexE;
  542. v0 = HandleS_Index(f0,edgef0);
  543. v1 = HandleS_Index(f0,(edgef0+1)%3);
  544. ////get the index on opposite side
  545. assert(TT(f0,edgef0) == f1);
  546. int edgef1 = TTi(f0,edgef0);
  547. v1p = HandleS_Index(f1,edgef1);
  548. v0p = HandleS_Index(f1,(edgef1+1)%3);
  549. integerVar = Handle_Integer(f0,edgef0);
  550. _MMatch = Handle_MMatch(f0,edgef0);
  551. assert(F(f0,edgef0) == F(f1,((edgef1+1)%3)));
  552. assert(F(f0,((edgef0+1)%3)) == F(f1,edgef1));
  553. }
  554. template <typename DerivedV, typename DerivedF>
  555. IGL_INLINE bool igl::VertexIndexing<DerivedV, DerivedF>::IsSeam(const int f0, const int f1)
  556. {
  557. for (int i=0;i<3;i++)
  558. {
  559. int f_clos = TT(f0,i);
  560. if (f_clos == -1)
  561. continue; ///border
  562. if (f_clos == f1)
  563. return(Handle_Seams(f0,i));
  564. }
  565. assert(0);
  566. return false;
  567. }
  568. ///find initial position of the pos to
  569. // assing face to vert inxex correctly
  570. template <typename DerivedV, typename DerivedF>
  571. IGL_INLINE void igl::VertexIndexing<DerivedV, DerivedF>::FindInitialPos(const int vert,
  572. int &edge,
  573. int &face)
  574. {
  575. int f_init;
  576. int edge_init;
  577. FirstPos(vert,f_init,edge_init); // todo manually IGL_INLINE the function
  578. igl::HalfEdgeIterator<DerivedF> VFI(&F,&TT,&TTi,f_init,edge_init);
  579. bool vertexB = V_border[vert];
  580. bool possible_split=false;
  581. bool complete_turn=false;
  582. do
  583. {
  584. int curr_f = VFI.Fi();
  585. int curr_edge=VFI.Ei();
  586. VFI.NextFE();
  587. int next_f=VFI.Fi();
  588. ///test if I've just crossed a border
  589. bool on_border=(TT(curr_f,curr_edge)==-1);
  590. //bool mismatch=false;
  591. bool seam=false;
  592. ///or if I've just crossed a seam
  593. ///if I'm on a border I MUST start from the one next t othe border
  594. if (!vertexB)
  595. //seam=curr_f->IsSeam(next_f);
  596. seam=IsSeam(curr_f,next_f);
  597. if (vertexB)
  598. assert(!Handle_Singular(vert));
  599. ;
  600. //assert(!vert->IsSingular());
  601. possible_split=((on_border)||(seam));
  602. complete_turn = next_f == f_init;
  603. } while ((!possible_split)&&(!complete_turn));
  604. face=VFI.Fi();
  605. edge=VFI.Ei();
  606. ///test that is not on a border
  607. //assert(face->FFp(edge)!=face);
  608. }
  609. ///intialize the mapping given an initial pos
  610. ///whih must be initialized with FindInitialPos
  611. template <typename DerivedV, typename DerivedF>
  612. IGL_INLINE void igl::VertexIndexing<DerivedV, DerivedF>::MapIndexes(const int vert,
  613. const int edge_init,
  614. const int f_init)
  615. {
  616. ///check that is not on border..
  617. ///in such case maybe it's non manyfold
  618. ///insert an initial index
  619. int curr_index=AddNewIndex(vert);
  620. ///and initialize the jumping pos
  621. igl::HalfEdgeIterator<DerivedF> VFI(&F,&TT,&TTi,f_init,edge_init);
  622. bool complete_turn=false;
  623. do
  624. {
  625. int curr_f = VFI.Fi();
  626. int curr_edge = VFI.Ei();
  627. ///assing the current index
  628. HandleS_Index(curr_f,curr_edge) = curr_index;
  629. VFI.NextFE();
  630. int next_f = VFI.Fi();
  631. ///test if I've finiseh with the face exploration
  632. complete_turn = (next_f==f_init);
  633. ///or if I've just crossed a mismatch
  634. if (!complete_turn)
  635. {
  636. bool seam=false;
  637. //seam=curr_f->IsSeam(next_f);
  638. seam=IsSeam(curr_f,next_f);
  639. if (seam)
  640. {
  641. ///then add a new index
  642. curr_index=AddNewIndex(vert);
  643. }
  644. }
  645. } while (!complete_turn);
  646. }
  647. ///intialize the mapping for a given vertex
  648. template <typename DerivedV, typename DerivedF>
  649. IGL_INLINE void igl::VertexIndexing<DerivedV, DerivedF>::InitMappingSeam(const int vert)
  650. {
  651. ///first rotate until find the first pos after a mismatch
  652. ///or a border or return to the first position...
  653. int f_init = VF[vert][0];
  654. int indexE = VFi[vert][0];
  655. igl::HalfEdgeIterator<DerivedF> VFI(&F,&TT,&TTi,f_init,indexE);
  656. int edge_init;
  657. int face_init;
  658. FindInitialPos(vert,edge_init,face_init);
  659. MapIndexes(vert,edge_init,face_init);
  660. }
  661. ///intialize the mapping for a given sampled mesh
  662. template <typename DerivedV, typename DerivedF>
  663. IGL_INLINE void igl::VertexIndexing<DerivedV, DerivedF>::InitMappingSeam()
  664. {
  665. //num_scalar_variables=-1;
  666. Handle_SystemInfo.num_scalar_variables=-1;
  667. for (unsigned int i=0;i<V.rows();i++)
  668. InitMappingSeam(i);
  669. for (unsigned int j=0;j<V.rows();j++)
  670. {
  671. assert(HandleV_Integer[j].size()>0);
  672. if (HandleV_Integer[j].size()>1)
  673. duplicated.push_back(j);
  674. }
  675. }
  676. ///test consistency of face variables per vert mapping
  677. template <typename DerivedV, typename DerivedF>
  678. IGL_INLINE void igl::VertexIndexing<DerivedV, DerivedF>::TestSeamMappingFace(const int f)
  679. {
  680. for (int k=0;k<3;k++)
  681. {
  682. int indexV=HandleS_Index(f,k);
  683. int v = F(f,k);
  684. bool has_index=HasIndex(v,indexV);
  685. assert(has_index);
  686. }
  687. }
  688. ///test consistency of face variables per vert mapping
  689. template <typename DerivedV, typename DerivedF>
  690. IGL_INLINE void igl::VertexIndexing<DerivedV, DerivedF>::TestSeamMappingVertex(int indexVert)
  691. {
  692. for (unsigned int k=0;k<HandleV_Integer[indexVert].size();k++)
  693. {
  694. int indexV=HandleV_Integer[indexVert][k];
  695. ///get faces sharing vertex
  696. std::vector<int> faces = VF[indexVert];
  697. std::vector<int> indexes = VFi[indexVert];
  698. for (unsigned int j=0;j<faces.size();j++)
  699. {
  700. int f = faces[j];
  701. int index = indexes[j];
  702. assert(F(f,index) == indexVert);
  703. assert((index>=0)&&(index<3));
  704. if (HandleS_Index(f,index) == indexV)
  705. return;
  706. }
  707. }
  708. assert(0);
  709. }
  710. ///check consistency of variable mapping across seams
  711. template <typename DerivedV, typename DerivedF>
  712. IGL_INLINE void igl::VertexIndexing<DerivedV, DerivedF>::TestSeamMapping()
  713. {
  714. printf("\n TESTING SEAM INDEXES \n");
  715. ///test F-V mapping
  716. for (unsigned int j=0;j<F.rows();j++)
  717. TestSeamMappingFace(j);
  718. ///TEST V-F MAPPING
  719. for (unsigned int j=0;j<V.rows();j++)
  720. TestSeamMappingVertex(j);
  721. }
  722. ///vertex to variable mapping
  723. template <typename DerivedV, typename DerivedF>
  724. IGL_INLINE void igl::VertexIndexing<DerivedV, DerivedF>::InitMapping()
  725. {
  726. //use_direction_field=_use_direction_field;
  727. IndexToVert.clear();
  728. duplicated.clear();
  729. InitMappingSeam();
  730. Handle_SystemInfo.num_vert_variables=Handle_SystemInfo.num_scalar_variables+1;
  731. ///end testing...
  732. TestSeamMapping();
  733. }
  734. template <typename DerivedV, typename DerivedF>
  735. IGL_INLINE void igl::VertexIndexing<DerivedV, DerivedF>::InitFaceIntegerVal()
  736. {
  737. Handle_SystemInfo.num_integer_cuts=0;
  738. for (unsigned int j=0;j<F.rows();j++)
  739. {
  740. for (int k=0;k<3;k++)
  741. {
  742. if (Handle_Seams(j,k))
  743. {
  744. Handle_Integer(j,k) = Handle_SystemInfo.num_integer_cuts;
  745. Handle_SystemInfo.num_integer_cuts++;
  746. }
  747. else
  748. Handle_Integer(j,k)=-1;
  749. }
  750. }
  751. }
  752. template <typename DerivedV, typename DerivedF>
  753. IGL_INLINE void igl::VertexIndexing<DerivedV, DerivedF>::InitSeamInfo()
  754. {
  755. Handle_SystemInfo.EdgeSeamInfo.clear();
  756. for (unsigned int f0=0;f0<F.rows();f0++)
  757. {
  758. for (int k=0;k<3;k++)
  759. {
  760. int f1 = TT(f0,k);
  761. if (f1 == -1)
  762. continue;
  763. bool seam = Handle_Seams(f0,k);
  764. if (seam)
  765. {
  766. int v0,v0p,v1,v1p;
  767. unsigned char MM;
  768. int integerVar;
  769. GetSeamInfo(f0,f1,k,v0,v1,v0p,v1p,MM,integerVar);
  770. Handle_SystemInfo.EdgeSeamInfo.push_back(SeamInfo(v0,v1,v0p,v1p,MM,integerVar));
  771. }
  772. }
  773. }
  774. }
  775. template <typename DerivedV, typename DerivedF>
  776. IGL_INLINE void igl::PoissonSolver<DerivedV, DerivedF>::SolvePoisson(Eigen::VectorXd Stiffness,
  777. double vector_field_scale,
  778. double grid_res,
  779. bool direct_round,
  780. int localIter,
  781. bool _integer_rounding,
  782. std::vector<int> roundVertices,
  783. std::vector<std::vector<int> > hardFeatures)
  784. {
  785. Handle_Stiffness = Stiffness;
  786. //initialization of flags and data structures
  787. integer_rounding=_integer_rounding;
  788. ids_to_round.clear();
  789. clearUserConstraint();
  790. // copy the user constraints number
  791. for (int i = 0; i < hardFeatures.size(); ++i)
  792. {
  793. addSharpEdgeConstraint(hardFeatures[i][0],hardFeatures[i][1]);
  794. }
  795. ///Initializing Matrix
  796. int t0=clock();
  797. ///initialize the matrix ALLOCATING SPACE
  798. InitMatrix();
  799. if (DEBUGPRINT)
  800. printf("\n ALLOCATED THE MATRIX \n");
  801. ///build the laplacian system
  802. BuildLaplacianMatrix(vector_field_scale);
  803. // add seam constraints
  804. BuildSeamConstraintsExplicitTranslation();
  805. // add user defined constraints
  806. BuildUserDefinedConstraints();
  807. ////add the lagrange multiplier
  808. FixBlockedVertex();
  809. if (DEBUGPRINT)
  810. printf("\n BUILT THE MATRIX \n");
  811. if (integer_rounding)
  812. {
  813. AddSingularityRound();
  814. AddToRoundVertices(roundVertices);
  815. }
  816. int t1=clock();
  817. if (DEBUGPRINT) printf("\n time:%d \n",t1-t0);
  818. if (DEBUGPRINT) printf("\n SOLVING \n");
  819. MixedIntegerSolve(grid_res,direct_round,localIter);
  820. int t2=clock();
  821. if (DEBUGPRINT) printf("\n time:%d \n",t2-t1);
  822. if (DEBUGPRINT) printf("\n ASSIGNING COORDS \n");
  823. MapCoords();
  824. int t3=clock();
  825. if (DEBUGPRINT) printf("\n time:%d \n",t3-t2);
  826. if (DEBUGPRINT) printf("\n FINISHED \n");
  827. }
  828. template <typename DerivedV, typename DerivedF>
  829. IGL_INLINE igl::PoissonSolver<DerivedV, DerivedF>
  830. ::PoissonSolver(const Eigen::PlainObjectBase<DerivedV> &_V,
  831. const Eigen::PlainObjectBase<DerivedF> &_F,
  832. const Eigen::PlainObjectBase<DerivedF> &_TT,
  833. const Eigen::PlainObjectBase<DerivedF> &_TTi,
  834. const Eigen::PlainObjectBase<DerivedV> &_PD1,
  835. const Eigen::PlainObjectBase<DerivedV> &_PD2,
  836. const Eigen::MatrixXi &_HandleS_Index,
  837. const Eigen::Matrix<int, Eigen::Dynamic, 1>&_Handle_Singular,
  838. const MeshSystemInfo &_Handle_SystemInfo //todo: const?
  839. ):
  840. V(_V),
  841. F(_F),
  842. TT(_TT),
  843. TTi(_TTi),
  844. PD1(_PD1),
  845. PD2(_PD2),
  846. HandleS_Index(_HandleS_Index),
  847. Handle_Singular(_Handle_Singular),
  848. Handle_SystemInfo(_Handle_SystemInfo)
  849. {
  850. UV = Eigen::MatrixXd(V.rows(),2);
  851. WUV = Eigen::MatrixXd(F.rows(),6);
  852. igl::doublearea(V,F,doublearea);
  853. igl::per_face_normals(V,F,N);
  854. igl::vertex_triangle_adjacency(V,F,VF,VFi);
  855. }
  856. ///START SYSTEM ACCESS METHODS
  857. ///add an entry to the LHS
  858. template <typename DerivedV, typename DerivedF>
  859. IGL_INLINE void igl::PoissonSolver<DerivedV, DerivedF>::AddValA(int Xindex,
  860. int Yindex,
  861. double val)
  862. {
  863. int size=(int)S.nrows();
  864. assert(0 <= Xindex && Xindex < size);
  865. assert(0 <= Yindex && Yindex < size);
  866. S.A().addEntryReal(Xindex,Yindex,val);
  867. }
  868. ///add a complex entry to the LHS
  869. template <typename DerivedV, typename DerivedF>
  870. IGL_INLINE void igl::PoissonSolver<DerivedV, DerivedF>::AddComplexA(int VarXindex,
  871. int VarYindex,
  872. std::complex<double> val)
  873. {
  874. int size=(int)S.nrows()/2;
  875. assert(0 <= VarXindex && VarXindex < size);
  876. assert(0 <= VarYindex && VarYindex < size);
  877. S.A().addEntryCmplx(VarXindex,VarYindex,val);
  878. }
  879. ///add a velue to the RHS
  880. template <typename DerivedV, typename DerivedF>
  881. IGL_INLINE void igl::PoissonSolver<DerivedV, DerivedF>::AddValB(int Xindex,
  882. double val)
  883. {
  884. int size=(int)S.nrows();
  885. assert(0 <= Xindex && Xindex < size);
  886. S.b()[Xindex] += val;
  887. }
  888. ///add the area term, scalefactor is used to sum up
  889. ///and normalize on the overlap zones
  890. template <typename DerivedV, typename DerivedF>
  891. IGL_INLINE void igl::PoissonSolver<DerivedV, DerivedF>::AddAreaTerm(int index[3][3][2],double ScaleFactor)
  892. {
  893. const double entry = 0.5*ScaleFactor;
  894. double val[3][3]= {
  895. {0, entry, -entry},
  896. {-entry, 0, entry},
  897. {entry, -entry, 0}
  898. };
  899. for (int i=0;i<3;i++)
  900. for (int j=0;j<3;j++)
  901. {
  902. ///add for both u and v
  903. int Xindex=index[i][j][0]*2;
  904. int Yindex=index[i][j][1]*2;
  905. AddValA(Xindex+1,Yindex,-val[i][j]);
  906. AddValA(Xindex,Yindex+1,val[i][j]);
  907. }
  908. }
  909. ///set the diagonal of the matrix (which is zero at the beginning)
  910. ///such that the sum of a row or a colums is zero
  911. template <typename DerivedV, typename DerivedF>
  912. IGL_INLINE void igl::PoissonSolver<DerivedV, DerivedF>::SetDiagonal(double val[3][3])
  913. {
  914. for (int i=0;i<3;i++)
  915. {
  916. double sum=0;
  917. for (int j=0;j<3;j++)
  918. sum+=val[i][j];
  919. val[i][i]=-sum;
  920. }
  921. }
  922. ///given a vector of scalar values and
  923. ///a vector of indexes add such values
  924. ///as specified by the indexes
  925. template <typename DerivedV, typename DerivedF>
  926. IGL_INLINE void igl::PoissonSolver<DerivedV, DerivedF>::AddRHS(double b[6],
  927. int index[3])
  928. {
  929. for (int i=0;i<3;i++)
  930. {
  931. double valU=b[i*2];
  932. double valV=b[(i*2)+1];
  933. AddValB((index[i]*2),valU);
  934. AddValB((index[i]*2)+1,valV);
  935. }
  936. }
  937. ///add a 3x3 block matrix to the system matrix...
  938. ///indexes are specified in the 3x3 matrix of x,y pairs
  939. ///indexes must be multiplied by 2 cause u and v
  940. template <typename DerivedV, typename DerivedF>
  941. IGL_INLINE void igl::PoissonSolver<DerivedV, DerivedF>::Add33Block(double val[3][3], int index[3][3][2])
  942. {
  943. for (int i=0;i<3;i++)
  944. for (int j=0;j<3;j++)
  945. {
  946. ///add for both u and v
  947. int Xindex=index[i][j][0]*2;
  948. int Yindex=index[i][j][1]*2;
  949. assert((unsigned)Xindex<(n_vert_vars*2));
  950. assert((unsigned)Yindex<(n_vert_vars*2));
  951. AddValA(Xindex,Yindex,val[i][j]);
  952. AddValA(Xindex+1,Yindex+1,val[i][j]);
  953. }
  954. }
  955. ///add a 3x3 block matrix to the system matrix...
  956. ///indexes are specified in the 3x3 matrix of x,y pairs
  957. ///indexes must be multiplied by 2 cause u and v
  958. template <typename DerivedV, typename DerivedF>
  959. IGL_INLINE void igl::PoissonSolver<DerivedV, DerivedF>::Add44Block(double val[4][4],int index[4][4][2])
  960. {
  961. for (int i=0;i<4;i++)
  962. for (int j=0;j<4;j++)
  963. {
  964. ///add for both u and v
  965. int Xindex=index[i][j][0]*2;
  966. int Yindex=index[i][j][1]*2;
  967. assert((unsigned)Xindex<(n_vert_vars*2));
  968. assert((unsigned)Yindex<(n_vert_vars*2));
  969. AddValA(Xindex,Yindex,val[i][j]);
  970. AddValA(Xindex+1,Yindex+1,val[i][j]);
  971. }
  972. }
  973. ///END SYSTEM ACCESS METHODS
  974. ///START COMMON MATH FUNCTIONS
  975. ///return the complex encoding the rotation
  976. ///for a given missmatch interval
  977. template <typename DerivedV, typename DerivedF>
  978. IGL_INLINE std::complex<double> igl::PoissonSolver<DerivedV, DerivedF>::GetRotationComplex(int interval)
  979. {
  980. assert((interval>=0)&&(interval<4));
  981. switch(interval)
  982. {
  983. case 0:return std::complex<double>(1,0);
  984. case 1:return std::complex<double>(0,1);
  985. case 2:return std::complex<double>(-1,0);
  986. default:return std::complex<double>(0,-1);
  987. }
  988. }
  989. ///END COMMON MATH FUNCTIONS
  990. ///START ENERGY MINIMIZATION PART
  991. ///initialize the LHS for a given face
  992. ///for minimization of Dirichlet's energy
  993. template <typename DerivedV, typename DerivedF>
  994. IGL_INLINE void igl::PoissonSolver<DerivedV, DerivedF>::perElementLHS(int f,
  995. double val[3][3],
  996. int index[3][3][2])
  997. {
  998. ///initialize to zero
  999. for (int x=0;x<3;x++)
  1000. for (int y=0;y<3;y++)
  1001. val[x][y]=0;
  1002. ///get the vertices
  1003. int v[3];
  1004. v[0] = F(f,0);
  1005. v[1] = F(f,1);
  1006. v[2] = F(f,2);
  1007. ///get the indexes of vertex instance (to consider cuts)
  1008. ///for the current face
  1009. int Vindexes[3];
  1010. Vindexes[0]=HandleS_Index(f,0);
  1011. Vindexes[1]=HandleS_Index(f,1);
  1012. Vindexes[2]=HandleS_Index(f,2);
  1013. ///initialize the indexes for the block
  1014. for (int x=0;x<3;x++)
  1015. for (int y=0;y<3;y++)
  1016. {
  1017. index[x][y][0]=Vindexes[x];
  1018. index[x][y][1]=Vindexes[y];
  1019. }
  1020. ///initialize edges
  1021. Eigen::Matrix<typename DerivedV::Scalar, 3, 1> e[3];
  1022. for (int k=0;k<3;k++)
  1023. e[k] = V.row(v[(k+2)%3]) - V.row(v[(k+1)%3]);
  1024. ///then consider area but also considering scale factor dur to overlaps
  1025. double areaT = doublearea(f)/2.0;
  1026. for (int x=0;x<3;x++)
  1027. for (int y=0;y<3;y++)
  1028. if (x!=y)
  1029. {
  1030. double num = (e[x].dot(e[y]));
  1031. val[x][y] = num/(4.0*areaT);
  1032. val[x][y] *= Handle_Stiffness[f];//f->stiffening;
  1033. }
  1034. ///set the matrix as diagonal
  1035. SetDiagonal(val);
  1036. }
  1037. ///initialize the RHS for a given face
  1038. ///for minimization of Dirichlet's energy
  1039. template <typename DerivedV, typename DerivedF>
  1040. IGL_INLINE void igl::PoissonSolver<DerivedV, DerivedF>::perElementRHS(int f,
  1041. double b[6],
  1042. double vector_field_scale)
  1043. {
  1044. /// then set the rhs
  1045. Eigen::Matrix<typename DerivedV::Scalar, 3, 1> scaled_Kreal;
  1046. Eigen::Matrix<typename DerivedV::Scalar, 3, 1> scaled_Kimag;
  1047. Eigen::Matrix<typename DerivedV::Scalar, 3, 1> fNorm = N.row(f);
  1048. Eigen::Matrix<typename DerivedV::Scalar, 3, 1> p[3];
  1049. p[0] = V.row(F(f,0));
  1050. p[1] = V.row(F(f,1));
  1051. p[2] = V.row(F(f,2));
  1052. Eigen::Matrix<typename DerivedV::Scalar, 3, 1> neg_t[3];
  1053. neg_t[0] = fNorm.cross(p[2] - p[1]);
  1054. neg_t[1] = fNorm.cross(p[0] - p[2]);
  1055. neg_t[2] = fNorm.cross(p[1] - p[0]);
  1056. Eigen::Matrix<typename DerivedV::Scalar, 3, 1> K1,K2;
  1057. K1 = PD1.row(f);
  1058. K2 = -PD2.row(f); // TODO: the "-" accounts for the orientation of local_basis.h, adapt the code before and remove the "-"
  1059. scaled_Kreal = K1*(vector_field_scale)/2;
  1060. scaled_Kimag = K2*(vector_field_scale)/2;
  1061. double stiff_val = Handle_Stiffness[f];
  1062. b[0] = scaled_Kreal.dot(neg_t[0]) * stiff_val;
  1063. b[1] = scaled_Kimag.dot(neg_t[0]) * stiff_val;
  1064. b[2] = scaled_Kreal.dot(neg_t[1]) * stiff_val;
  1065. b[3] = scaled_Kimag.dot(neg_t[1]) * stiff_val;
  1066. b[4] = scaled_Kreal.dot(neg_t[2]) * stiff_val;
  1067. b[5] = scaled_Kimag.dot(neg_t[2]) * stiff_val;
  1068. // if (f == 0)
  1069. // {
  1070. // cerr << "DEBUG!!!" << endl;
  1071. //
  1072. //
  1073. // for (unsigned z = 0; z<6; ++z)
  1074. // cerr << b[z] << " ";
  1075. // cerr << endl;
  1076. //
  1077. // scaled_Kreal = K1*(vector_field_scale)/2;
  1078. // scaled_Kimag = -K2*(vector_field_scale)/2;
  1079. //
  1080. // double stiff_val = Handle_Stiffness[f];
  1081. //
  1082. // b[0] = scaled_Kreal.dot(neg_t[0]) * stiff_val;
  1083. // b[1] = scaled_Kimag.dot(neg_t[0]) * stiff_val;
  1084. // b[2] = scaled_Kreal.dot(neg_t[1]) * stiff_val;
  1085. // b[3] = scaled_Kimag.dot(neg_t[1]) * stiff_val;
  1086. // b[4] = scaled_Kreal.dot(neg_t[2]) * stiff_val;
  1087. // b[5] = scaled_Kimag.dot(neg_t[2]) * stiff_val;
  1088. //
  1089. // for (unsigned z = 0; z<6; ++z)
  1090. // cerr << b[z] << " ";
  1091. // cerr << endl;
  1092. //
  1093. // }
  1094. }
  1095. ///evaluate the LHS and RHS for a single face
  1096. ///for minimization of Dirichlet's energy
  1097. template <typename DerivedV, typename DerivedF>
  1098. IGL_INLINE void igl::PoissonSolver<DerivedV, DerivedF>::PerElementSystemReal(int f,
  1099. double val[3][3],
  1100. int index[3][3][2],
  1101. double b[6],
  1102. double vector_field_scale)
  1103. {
  1104. perElementLHS(f,val,index);
  1105. perElementRHS(f,b,vector_field_scale);
  1106. }
  1107. ///END ENERGY MINIMIZATION PART
  1108. ///START FIXING VERTICES
  1109. ///set a given vertex as fixed
  1110. template <typename DerivedV, typename DerivedF>
  1111. IGL_INLINE void igl::PoissonSolver<DerivedV, DerivedF>::AddFixedVertex(int v)
  1112. {
  1113. n_fixed_vars++;
  1114. Hard_constraints.push_back(v);
  1115. }
  1116. ///find vertex to fix in case we're using
  1117. ///a vector field NB: multiple components not handled
  1118. template <typename DerivedV, typename DerivedF>
  1119. IGL_INLINE void igl::PoissonSolver<DerivedV, DerivedF>::FindFixedVertField()
  1120. {
  1121. Hard_constraints.clear();
  1122. n_fixed_vars=0;
  1123. ///fix the first singularity
  1124. for (unsigned int v=0;v<V.rows();v++)
  1125. {
  1126. if (Handle_Singular(v))
  1127. {
  1128. AddFixedVertex(v);
  1129. UV.row(v) << 0,0;
  1130. return;
  1131. }
  1132. }
  1133. ///if anything fixed fix the first
  1134. AddFixedVertex(0); // TODO HERE IT ISSSSSS
  1135. UV.row(0) << 0,0;
  1136. std::cerr << "No vertices to fix, I am fixing the first vertex to the origin!" << std::endl;
  1137. }
  1138. ///find hard constraint depending if using or not
  1139. ///a vector field
  1140. template <typename DerivedV, typename DerivedF>
  1141. IGL_INLINE void igl::PoissonSolver<DerivedV, DerivedF>::FindFixedVert()
  1142. {
  1143. Hard_constraints.clear();
  1144. FindFixedVertField();
  1145. }
  1146. template <typename DerivedV, typename DerivedF>
  1147. IGL_INLINE int igl::PoissonSolver<DerivedV, DerivedF>::GetFirstVertexIndex(int v)
  1148. {
  1149. return HandleS_Index(VF[v][0],VFi[v][0]);
  1150. }
  1151. ///fix the vertices which are flagged as fixed
  1152. template <typename DerivedV, typename DerivedF>
  1153. IGL_INLINE void igl::PoissonSolver<DerivedV, DerivedF>::FixBlockedVertex()
  1154. {
  1155. int offset_row = n_vert_vars*2 + num_cut_constraint*2;
  1156. unsigned int constr_num = 0;
  1157. for (unsigned int i=0;i<Hard_constraints.size();i++)
  1158. {
  1159. int v = Hard_constraints[i];
  1160. ///get first index of the vertex that must blocked
  1161. //int index=v->vertex_index[0];
  1162. int index = GetFirstVertexIndex(v);
  1163. ///multiply times 2 because of uv
  1164. int indexvert = index*2;
  1165. ///find the first free row to add the constraint
  1166. int indexRow = (offset_row+constr_num*2);
  1167. int indexCol = indexRow;
  1168. ///add fixing constraint LHS
  1169. AddValA(indexRow,indexvert,1);
  1170. AddValA(indexRow+1,indexvert+1,1);
  1171. ///add fixing constraint RHS
  1172. AddValB(indexCol, UV(v,0));
  1173. AddValB(indexCol+1,UV(v,1));
  1174. constr_num++;
  1175. }
  1176. assert(constr_num==n_fixed_vars);
  1177. }
  1178. ///END FIXING VERTICES
  1179. ///HANDLING SINGULARITY
  1180. //set the singularity round to integer location
  1181. template <typename DerivedV, typename DerivedF>
  1182. IGL_INLINE void igl::PoissonSolver<DerivedV, DerivedF>::AddSingularityRound()
  1183. {
  1184. for (unsigned int v=0;v<V.rows();v++)
  1185. {
  1186. if (Handle_Singular(v))
  1187. {
  1188. int index0=GetFirstVertexIndex(v);
  1189. ids_to_round.push_back( index0*2 );
  1190. ids_to_round.push_back((index0*2)+1);
  1191. }
  1192. }
  1193. }
  1194. template <typename DerivedV, typename DerivedF>
  1195. IGL_INLINE void igl::PoissonSolver<DerivedV, DerivedF>::AddToRoundVertices(std::vector<int> ids)
  1196. {
  1197. for (int i = 0; i < ids.size(); ++i)
  1198. {
  1199. if (ids[i] < 0 || ids[i] >= V.rows())
  1200. std::cerr << "WARNING: Ignored round vertex constraint, vertex " << ids[i] << " does not exist in the mesh." << std::endl;
  1201. int index0 = GetFirstVertexIndex(ids[i]);
  1202. ids_to_round.push_back( index0*2 );
  1203. ids_to_round.push_back((index0*2)+1);
  1204. }
  1205. }
  1206. ///START GENERIC SYSTEM FUNCTIONS
  1207. //build the laplacian matrix cyclyng over all rangemaps
  1208. //and over all faces
  1209. template <typename DerivedV, typename DerivedF>
  1210. IGL_INLINE void igl::PoissonSolver<DerivedV, DerivedF>::BuildLaplacianMatrix(double vfscale)
  1211. {
  1212. ///then for each face
  1213. for (unsigned int f=0;f<F.rows();f++)
  1214. {
  1215. int var_idx[3]; //vertex variable indices
  1216. for(int k = 0; k < 3; ++k)
  1217. var_idx[k] = HandleS_Index(f,k);
  1218. ///block of variables
  1219. double val[3][3];
  1220. ///block of vertex indexes
  1221. int index[3][3][2];
  1222. ///righe hand side
  1223. double b[6];
  1224. ///compute the system for the given face
  1225. PerElementSystemReal(f, val,index, b, vfscale);
  1226. //Add the element to the matrix
  1227. Add33Block(val,index);
  1228. ///add right hand side
  1229. AddRHS(b,var_idx);
  1230. }
  1231. }
  1232. ///find different sized of the system
  1233. template <typename DerivedV, typename DerivedF>
  1234. IGL_INLINE void igl::PoissonSolver<DerivedV, DerivedF>::FindSizes()
  1235. {
  1236. ///find the vertex that need to be fixed
  1237. FindFixedVert();
  1238. ///REAL PART
  1239. n_vert_vars = Handle_SystemInfo.num_vert_variables;
  1240. ///INTEGER PART
  1241. ///the total number of integer variables
  1242. n_integer_vars = Handle_SystemInfo.num_integer_cuts;
  1243. ///CONSTRAINT PART
  1244. num_cut_constraint = Handle_SystemInfo.EdgeSeamInfo.size()*2;
  1245. num_constraint_equations = num_cut_constraint*2 + n_fixed_vars*2 + num_userdefined_constraint;
  1246. ///total variable of the system
  1247. num_total_vars = n_vert_vars*2+n_integer_vars*2;
  1248. ///initialize matrix size
  1249. system_size = num_total_vars + num_constraint_equations;
  1250. if (DEBUGPRINT) printf("\n*** SYSTEM VARIABLES *** \n");
  1251. if (DEBUGPRINT) printf("* NUM REAL VERTEX VARIABLES %d \n",n_vert_vars);
  1252. if (DEBUGPRINT) printf("\n*** SINGULARITY *** \n ");
  1253. if (DEBUGPRINT) printf("* NUM SINGULARITY %d\n",(int)ids_to_round.size()/2);
  1254. if (DEBUGPRINT) printf("\n*** INTEGER VARIABLES *** \n");
  1255. if (DEBUGPRINT) printf("* NUM INTEGER VARIABLES %d \n",(int)n_integer_vars);
  1256. if (DEBUGPRINT) printf("\n*** CONSTRAINTS *** \n ");
  1257. if (DEBUGPRINT) printf("* NUM FIXED CONSTRAINTS %d\n",n_fixed_vars);
  1258. if (DEBUGPRINT) printf("* NUM CUTS CONSTRAINTS %d\n",num_cut_constraint);
  1259. if (DEBUGPRINT) printf("* NUM USER DEFINED CONSTRAINTS %d\n",num_userdefined_constraint);
  1260. if (DEBUGPRINT) printf("\n*** TOTAL SIZE *** \n");
  1261. if (DEBUGPRINT) printf("* TOTAL VARIABLE SIZE (WITH INTEGER TRASL) %d \n",num_total_vars);
  1262. if (DEBUGPRINT) printf("* TOTAL CONSTRAINTS %d \n",num_constraint_equations);
  1263. if (DEBUGPRINT) printf("* MATRIX SIZE %d \n",system_size);
  1264. }
  1265. template <typename DerivedV, typename DerivedF>
  1266. IGL_INLINE void igl::PoissonSolver<DerivedV, DerivedF>::AllocateSystem()
  1267. {
  1268. S.initialize(system_size, system_size);
  1269. printf("\n INITIALIZED SPARSE MATRIX OF %d x %d \n",system_size, system_size);
  1270. }
  1271. ///intitialize the whole matrix
  1272. template <typename DerivedV, typename DerivedF>
  1273. IGL_INLINE void igl::PoissonSolver<DerivedV, DerivedF>::InitMatrix()
  1274. {
  1275. FindSizes();
  1276. AllocateSystem();
  1277. }
  1278. ///map back coordinates after that
  1279. ///the system has been solved
  1280. template <typename DerivedV, typename DerivedF>
  1281. IGL_INLINE void igl::PoissonSolver<DerivedV, DerivedF>::MapCoords()
  1282. {
  1283. ///map coords to faces
  1284. for (unsigned int f=0;f<F.rows();f++)
  1285. {
  1286. for (int k=0;k<3;k++)
  1287. {
  1288. //get the index of the variable in the system
  1289. int indexUV = HandleS_Index(f,k);
  1290. ///then get U and V coords
  1291. double U=X[indexUV*2];
  1292. double V=X[indexUV*2+1];
  1293. WUV(f,k*2 + 0) = U;
  1294. WUV(f,k*2 + 1) = V;
  1295. }
  1296. }
  1297. #if 0
  1298. ///initialize the vector of integer variables to return their values
  1299. Handle_SystemInfo.IntegerValues.resize(n_integer_vars*2);
  1300. int baseIndex = (n_vert_vars)*2;
  1301. int endIndex = baseIndex+n_integer_vars*2;
  1302. int index = 0;
  1303. for (int i=baseIndex; i<endIndex; i++)
  1304. {
  1305. ///assert that the value is an integer value
  1306. double value=X[i];
  1307. double diff = value-(int)floor(value+0.5);
  1308. assert(diff<0.00000001);
  1309. Handle_SystemInfo.IntegerValues[index] = value;
  1310. index++;
  1311. }
  1312. #endif
  1313. }
  1314. ///END GENERIC SYSTEM FUNCTIONS
  1315. ///set the constraints for the inter-range cuts
  1316. template <typename DerivedV, typename DerivedF>
  1317. IGL_INLINE void igl::PoissonSolver<DerivedV, DerivedF>::BuildSeamConstraintsExplicitTranslation()
  1318. {
  1319. ///add constraint(s) for every seam edge (not halfedge)
  1320. int offset_row = n_vert_vars;
  1321. ///current constraint row
  1322. int constr_row = offset_row;
  1323. ///current constraint
  1324. unsigned int constr_num = 0;
  1325. for (unsigned int i=0; i<num_cut_constraint/2; i++)
  1326. {
  1327. unsigned char interval = Handle_SystemInfo.EdgeSeamInfo[i].MMatch;
  1328. if (interval==1)
  1329. interval=3;
  1330. else
  1331. if(interval==3)
  1332. interval=1;
  1333. int p0 = Handle_SystemInfo.EdgeSeamInfo[i].v0;
  1334. int p1 = Handle_SystemInfo.EdgeSeamInfo[i].v1;
  1335. int p0p = Handle_SystemInfo.EdgeSeamInfo[i].v0p;
  1336. int p1p = Handle_SystemInfo.EdgeSeamInfo[i].v1p;
  1337. std::complex<double> rot = GetRotationComplex(interval);
  1338. ///get the integer variable
  1339. int integerVar = offset_row+Handle_SystemInfo.EdgeSeamInfo[i].integerVar;
  1340. if (integer_rounding)
  1341. {
  1342. ids_to_round.push_back(integerVar*2);
  1343. ids_to_round.push_back(integerVar*2+1);
  1344. }
  1345. AddComplexA(constr_row, p0 , rot);
  1346. AddComplexA(constr_row, p0p, -1);
  1347. ///then translation...considering the rotation
  1348. ///due to substitution
  1349. AddComplexA(constr_row, integerVar, 1);
  1350. AddValB(2*constr_row ,0);
  1351. AddValB(2*constr_row+1,0);
  1352. constr_row +=1;
  1353. constr_num++;
  1354. AddComplexA(constr_row, p1, rot);
  1355. AddComplexA(constr_row, p1p, -1);
  1356. ///other translation
  1357. AddComplexA(constr_row, integerVar , 1);
  1358. AddValB(2*constr_row,0);
  1359. AddValB(2*constr_row+1,0);
  1360. constr_row +=1;
  1361. constr_num++;
  1362. }
  1363. }
  1364. ///set the constraints for the inter-range cuts
  1365. template <typename DerivedV, typename DerivedF>
  1366. IGL_INLINE void igl::PoissonSolver<DerivedV, DerivedF>::BuildUserDefinedConstraints()
  1367. {
  1368. /// the user defined constraints are at the end
  1369. int offset_row = n_vert_vars*2 + num_cut_constraint*2 + n_fixed_vars*2;
  1370. ///current constraint row
  1371. int constr_row = offset_row;
  1372. assert(num_userdefined_constraint == userdefined_constraints.size());
  1373. for (unsigned int i=0; i<num_userdefined_constraint; i++)
  1374. {
  1375. for (unsigned int j=0; j<userdefined_constraints[i].size()-1; ++j)
  1376. {
  1377. AddValA(constr_row, j , userdefined_constraints[i][j]);
  1378. }
  1379. AddValB(constr_row,userdefined_constraints[i][userdefined_constraints[i].size()-1]);
  1380. constr_row +=1;
  1381. }
  1382. }
  1383. ///call of the mixed integer solver
  1384. template <typename DerivedV, typename DerivedF>
  1385. IGL_INLINE void igl::PoissonSolver<DerivedV, DerivedF>::MixedIntegerSolve(double cone_grid_res,
  1386. bool direct_round,
  1387. int localIter)
  1388. {
  1389. X = std::vector<double>((n_vert_vars+n_integer_vars)*2);
  1390. ///variables part
  1391. int ScalarSize = n_vert_vars*2;
  1392. int SizeMatrix = (n_vert_vars+n_integer_vars)*2;
  1393. if (DEBUGPRINT)
  1394. printf("\n ALLOCATED X \n");
  1395. ///matrix A
  1396. gmm::col_matrix< gmm::wsvector< double > > A(SizeMatrix,SizeMatrix); // lhs matrix variables +
  1397. ///constraints part
  1398. int CsizeX = num_constraint_equations;
  1399. int CsizeY = SizeMatrix+1;
  1400. gmm::row_matrix< gmm::wsvector< double > > C(CsizeX,CsizeY); // constraints
  1401. if (DEBUGPRINT)
  1402. printf("\n ALLOCATED QMM STRUCTURES \n");
  1403. std::vector<double> rhs(SizeMatrix,0); // rhs
  1404. if (DEBUGPRINT)
  1405. printf("\n ALLOCATED RHS STRUCTURES \n");
  1406. //// copy LHS
  1407. for(int i = 0; i < (int)S.A().nentries(); ++i)
  1408. {
  1409. int row = S.A().rowind()[i];
  1410. int col = S.A().colind()[i];
  1411. int size =(int)S.nrows();
  1412. assert(0 <= row && row < size);
  1413. assert(0 <= col && col < size);
  1414. // it's either part of the matrix
  1415. if (row < ScalarSize)
  1416. {
  1417. A(row, col) += S.A().vals()[i];
  1418. }
  1419. // or it's a part of the constraint
  1420. else
  1421. {
  1422. assert ((unsigned int)row < (n_vert_vars+num_constraint_equations)*2);
  1423. int r = row - ScalarSize;
  1424. assert(r < CsizeX);
  1425. assert(col < CsizeY);
  1426. C(r , col ) += S.A().vals()[i];
  1427. }
  1428. }
  1429. if (DEBUGPRINT)
  1430. printf("\n SET %d INTEGER VALUES \n",n_integer_vars);
  1431. ///add penalization term for integer variables
  1432. double penalization = 0.000001;
  1433. int offline_index = ScalarSize;
  1434. for(unsigned int i = 0; i < (n_integer_vars)*2; ++i)
  1435. {
  1436. int index=offline_index+i;
  1437. A(index,index)=penalization;
  1438. }
  1439. if (DEBUGPRINT)
  1440. printf("\n SET RHS \n");
  1441. // copy RHS
  1442. for(int i = 0; i < (int)ScalarSize; ++i)
  1443. {
  1444. rhs[i] = S.getRHSReal(i) * cone_grid_res;
  1445. }
  1446. // copy constraint RHS
  1447. if (DEBUGPRINT)
  1448. printf("\n SET %d CONSTRAINTS \n",num_constraint_equations);
  1449. for(unsigned int i = 0; i < num_constraint_equations; ++i)
  1450. {
  1451. C(i, SizeMatrix) = -S.getRHSReal(ScalarSize + i) * cone_grid_res;
  1452. }
  1453. ///copy values back into S
  1454. COMISO::ConstrainedSolver solver;
  1455. solver.misolver().set_local_iters(localIter);
  1456. solver.misolver().set_direct_rounding(direct_round);
  1457. std::sort(ids_to_round.begin(),ids_to_round.end());
  1458. std::vector<int>::iterator new_end=std::unique(ids_to_round.begin(),ids_to_round.end());
  1459. int dist=distance(ids_to_round.begin(),new_end);
  1460. ids_to_round.resize(dist);
  1461. solver.solve( C, A, X, rhs, ids_to_round, 0.0, false, false);
  1462. }
  1463. template <typename DerivedV, typename DerivedF>
  1464. IGL_INLINE void igl::PoissonSolver<DerivedV, DerivedF>::clearUserConstraint()
  1465. {
  1466. num_userdefined_constraint = 0;
  1467. userdefined_constraints.clear();
  1468. }
  1469. template <typename DerivedV, typename DerivedF>
  1470. IGL_INLINE void igl::PoissonSolver<DerivedV, DerivedF>::addSharpEdgeConstraint(int fid, int vid)
  1471. {
  1472. // prepare constraint
  1473. std::vector<int> c(Handle_SystemInfo.num_vert_variables*2 + 1);
  1474. for (int i = 0; i < c.size(); ++i)
  1475. {
  1476. c[i] = 0;
  1477. }
  1478. int v1 = F(fid,vid);
  1479. int v2 = F(fid,(vid+1)%3);
  1480. Eigen::Matrix<typename DerivedV::Scalar, 3, 1> e = V.row(v2) - V.row(v1);
  1481. int v1i = GetFirstVertexIndex(v1);
  1482. int v2i = GetFirstVertexIndex(v2);
  1483. double d1 = fabs(e.dot(PD1.row(fid)));
  1484. double d2 = fabs(e.dot(PD2.row(fid)));
  1485. int offset = 0;
  1486. if (d1>d2)
  1487. offset = 1;
  1488. ids_to_round.push_back((v1i * 2) + offset);
  1489. ids_to_round.push_back((v2i * 2) + offset);
  1490. // add constraint
  1491. c[(v1i * 2) + offset] = 1;
  1492. c[(v2i * 2) + offset] = -1;
  1493. // add to the user-defined constraints
  1494. num_userdefined_constraint++;
  1495. userdefined_constraints.push_back(c);
  1496. }
  1497. template <typename DerivedV, typename DerivedF, typename DerivedU>
  1498. IGL_INLINE igl::MIQ_class<DerivedV, DerivedF, DerivedU>::MIQ_class(const Eigen::PlainObjectBase<DerivedV> &V_,
  1499. const Eigen::PlainObjectBase<DerivedF> &F_,
  1500. const Eigen::PlainObjectBase<DerivedV> &PD1_combed,
  1501. const Eigen::PlainObjectBase<DerivedV> &PD2_combed,
  1502. const Eigen::PlainObjectBase<DerivedV> &BIS1_combed,
  1503. const Eigen::PlainObjectBase<DerivedV> &BIS2_combed,
  1504. const Eigen::Matrix<int, Eigen::Dynamic, 3> &Handle_MMatch,
  1505. const Eigen::Matrix<int, Eigen::Dynamic, 1> &Handle_Singular,
  1506. const Eigen::Matrix<int, Eigen::Dynamic, 1> &Handle_SingularDegree,
  1507. const Eigen::Matrix<int, Eigen::Dynamic, 3> &Handle_Seams,
  1508. Eigen::PlainObjectBase<DerivedU> &UV,
  1509. Eigen::PlainObjectBase<DerivedF> &FUV,
  1510. double GradientSize,
  1511. double Stiffness,
  1512. bool DirectRound,
  1513. int iter,
  1514. int localIter,
  1515. bool DoRound,
  1516. std::vector<int> roundVertices,
  1517. std::vector<std::vector<int> > hardFeatures):
  1518. V(V_),
  1519. F(F_)
  1520. {
  1521. igl::local_basis(V,F,B1,B2,B3);
  1522. igl::triangle_triangle_adjacency(V,F,TT,TTi);
  1523. // Prepare indexing for the linear system
  1524. VertexIndexing<DerivedV, DerivedF> VInd(V, F, TT, TTi, BIS1_combed, BIS2_combed, Handle_MMatch, Handle_Singular, Handle_SingularDegree, Handle_Seams);
  1525. VInd.InitMapping();
  1526. VInd.InitFaceIntegerVal();
  1527. VInd.InitSeamInfo();
  1528. Eigen::PlainObjectBase<DerivedV> PD1_combed_for_poisson, PD2_combed_for_poisson;
  1529. // Rotate by 90 degrees CCW
  1530. PD1_combed_for_poisson.setZero(BIS1_combed.rows(),3);
  1531. PD2_combed_for_poisson.setZero(BIS2_combed.rows(),3);
  1532. for (unsigned i=0; i<PD1_combed.rows();++i)
  1533. {
  1534. double n1 = PD1_combed.row(i).norm();
  1535. double n2 = PD2_combed.row(i).norm();
  1536. double a1 = atan2(B2.row(i).dot(PD1_combed.row(i)),B1.row(i).dot(PD1_combed.row(i)));
  1537. double a2 = atan2(B2.row(i).dot(PD2_combed.row(i)),B1.row(i).dot(PD2_combed.row(i)));
  1538. a1 += M_PI/2;
  1539. a2 += M_PI/2;
  1540. PD1_combed_for_poisson.row(i) = cos(a1) * B1.row(i) + sin(a1) * B2.row(i);
  1541. PD2_combed_for_poisson.row(i) = cos(a2) * B1.row(i) + sin(a2) * B2.row(i);
  1542. PD1_combed_for_poisson.row(i) = PD1_combed_for_poisson.row(i).normalized() * n1;
  1543. PD2_combed_for_poisson.row(i) = PD2_combed_for_poisson.row(i).normalized() * n2;
  1544. }
  1545. // Assemble the system and solve
  1546. PoissonSolver<DerivedV, DerivedF> PSolver(V,
  1547. F,
  1548. TT,
  1549. TTi,
  1550. PD1_combed_for_poisson,
  1551. PD2_combed_for_poisson,
  1552. VInd.HandleS_Index,
  1553. VInd.Handle_Singular,
  1554. VInd.Handle_SystemInfo);
  1555. Handle_Stiffness = Eigen::VectorXd::Constant(F.rows(),1);
  1556. if (iter > 0) // do stiffening
  1557. {
  1558. for (int i=0;i<iter;i++)
  1559. {
  1560. PSolver.SolvePoisson(Handle_Stiffness, GradientSize,1.f,DirectRound,localIter,DoRound,roundVertices,hardFeatures);
  1561. int nflips=NumFlips(PSolver.WUV);
  1562. bool folded = updateStiffeningJacobianDistorsion(GradientSize,PSolver.WUV);
  1563. printf("ITERATION %d FLIPS %d \n",i,nflips);
  1564. if (!folded)break;
  1565. }
  1566. }
  1567. else
  1568. {
  1569. PSolver.SolvePoisson(Handle_Stiffness,GradientSize,1.f,DirectRound,localIter,DoRound,roundVertices,hardFeatures);
  1570. }
  1571. int nflips=NumFlips(PSolver.WUV);
  1572. printf("**** END OPTIMIZING #FLIPS %d ****\n",nflips);
  1573. fflush(stdout);
  1574. WUV = PSolver.WUV;
  1575. }
  1576. template <typename DerivedV, typename DerivedF, typename DerivedU>
  1577. IGL_INLINE void igl::MIQ_class<DerivedV, DerivedF, DerivedU>::extractUV(Eigen::PlainObjectBase<DerivedU> &UV_out,
  1578. Eigen::PlainObjectBase<DerivedF> &FUV_out)
  1579. {
  1580. // int f = F.rows();
  1581. int f = WUV.rows();
  1582. unsigned vtfaceid[f*3];
  1583. std::vector<double> vtu;
  1584. std::vector<double> vtv;
  1585. std::vector<std::vector<double> > listUV;
  1586. unsigned counter = 0;
  1587. for (unsigned i=0; i<f; ++i)
  1588. {
  1589. for (unsigned j=0; j<3; ++j)
  1590. {
  1591. std::vector<double> t(3);
  1592. t[0] = WUV(i,j*2 + 0);
  1593. t[1] = WUV(i,j*2 + 1);
  1594. t[2] = counter++;
  1595. listUV.push_back(t);
  1596. }
  1597. }
  1598. std::sort(listUV.begin(),listUV.end());
  1599. counter = 0;
  1600. unsigned k = 0;
  1601. while (k < f*3)
  1602. {
  1603. double u = listUV[k][0];
  1604. double v = listUV[k][1];
  1605. unsigned id = round(listUV[k][2]);
  1606. vtfaceid[id] = counter;
  1607. vtu.push_back(u);
  1608. vtv.push_back(v);
  1609. unsigned j=1;
  1610. while(k+j < f*3 && u == listUV[k+j][0] && v == listUV[k+j][1])
  1611. {
  1612. unsigned tid = round(listUV[k+j][2]);
  1613. vtfaceid[tid] = counter;
  1614. ++j;
  1615. }
  1616. k = k+j;
  1617. counter++;
  1618. }
  1619. UV_out.resize(vtu.size(),2);
  1620. for (unsigned i=0; i<vtu.size(); ++i)
  1621. {
  1622. UV_out(i,0) = vtu[i];
  1623. UV_out(i,1) = vtv[i];
  1624. }
  1625. FUV_out.resize(f,3);
  1626. unsigned vcounter = 0;
  1627. for (unsigned i=0; i<f; ++i)
  1628. {
  1629. FUV_out(i,0) = vtfaceid[vcounter++];
  1630. FUV_out(i,1) = vtfaceid[vcounter++];
  1631. FUV_out(i,2) = vtfaceid[vcounter++];
  1632. }
  1633. }
  1634. template <typename DerivedV, typename DerivedF, typename DerivedU>
  1635. IGL_INLINE int igl::MIQ_class<DerivedV, DerivedF, DerivedU>::NumFlips(const Eigen::MatrixXd& WUV)
  1636. {
  1637. int numFl=0;
  1638. for (unsigned int i=0;i<F.rows();i++)
  1639. {
  1640. if (IsFlipped(i, WUV))
  1641. numFl++;
  1642. }
  1643. return numFl;
  1644. }
  1645. template <typename DerivedV, typename DerivedF, typename DerivedU>
  1646. IGL_INLINE double igl::MIQ_class<DerivedV, DerivedF, DerivedU>::Distortion(int f, double h, const Eigen::MatrixXd& WUV)
  1647. {
  1648. assert(h > 0);
  1649. Eigen::Vector2d uv0,uv1,uv2;
  1650. uv0 << WUV(f,0), WUV(f,1);
  1651. uv1 << WUV(f,2), WUV(f,3);
  1652. uv2 << WUV(f,4), WUV(f,5);
  1653. Eigen::Matrix<typename DerivedV::Scalar, 3, 1> p0 = V.row(F(f,0));
  1654. Eigen::Matrix<typename DerivedV::Scalar, 3, 1> p1 = V.row(F(f,1));
  1655. Eigen::Matrix<typename DerivedV::Scalar, 3, 1> p2 = V.row(F(f,2));
  1656. Eigen::Matrix<typename DerivedV::Scalar, 3, 1> norm = (p1 - p0).cross(p2 - p0);
  1657. double area2 = norm.norm();
  1658. double area2_inv = 1.0 / area2;
  1659. norm *= area2_inv;
  1660. if (area2 > 0)
  1661. {
  1662. // Singular values of the Jacobian
  1663. Eigen::Matrix<typename DerivedV::Scalar, 3, 1> neg_t0 = norm.cross(p2 - p1);
  1664. Eigen::Matrix<typename DerivedV::Scalar, 3, 1> neg_t1 = norm.cross(p0 - p2);
  1665. Eigen::Matrix<typename DerivedV::Scalar, 3, 1> neg_t2 = norm.cross(p1 - p0);
  1666. Eigen::Matrix<typename DerivedV::Scalar, 3, 1> diffu = (neg_t0 * uv0(0) +neg_t1 *uv1(0) + neg_t2 * uv2(0) )*area2_inv;
  1667. Eigen::Matrix<typename DerivedV::Scalar, 3, 1> diffv = (neg_t0 * uv0(1) + neg_t1*uv1(1) + neg_t2*uv2(1) )*area2_inv;
  1668. // first fundamental form
  1669. double I00 = diffu.dot(diffu); // guaranteed non-neg
  1670. double I01 = diffu.dot(diffv); // I01 = I10
  1671. double I11 = diffv.dot(diffv); // guaranteed non-neg
  1672. // eigenvalues of a 2x2 matrix
  1673. // [a00 a01]
  1674. // [a10 a11]
  1675. // 1/2 * [ (a00 + a11) +/- sqrt((a00 - a11)^2 + 4 a01 a10) ]
  1676. double trI = I00 + I11; // guaranteed non-neg
  1677. double diffDiag = I00 - I11; // guaranteed non-neg
  1678. double sqrtDet = sqrt(std::max(0.0, diffDiag*diffDiag +
  1679. 4 * I01 * I01)); // guaranteed non-neg
  1680. double sig1 = 0.5 * (trI + sqrtDet); // higher singular value
  1681. double sig2 = 0.5 * (trI - sqrtDet); // lower singular value
  1682. // Avoid sig2 < 0 due to numerical error
  1683. if (fabs(sig2) < 1.0e-8)
  1684. sig2 = 0;
  1685. assert(sig1 >= 0);
  1686. assert(sig2 >= 0);
  1687. if (sig2 < 0) {
  1688. printf("Distortion will be NaN! sig1^2 is negative (%lg)\n",
  1689. sig2);
  1690. }
  1691. // The singular values of the Jacobian are the sqrts of the
  1692. // eigenvalues of the first fundamental form.
  1693. sig1 = sqrt(sig1);
  1694. sig2 = sqrt(sig2);
  1695. // distortion
  1696. double tao = IsFlipped(f,WUV) ? -1 : 1;
  1697. double factor = tao / h;
  1698. double lam = fabs(factor * sig1 - 1) + fabs(factor * sig2 - 1);
  1699. return lam;
  1700. }
  1701. else {
  1702. return 10; // something "large"
  1703. }
  1704. }
  1705. ////////////////////////////////////////////////////////////////////////////
  1706. // Approximate the distortion laplacian using a uniform laplacian on
  1707. // the dual mesh:
  1708. // ___________
  1709. // \-1 / \-1 /
  1710. // \ / 3 \ /
  1711. // \-----/
  1712. // \-1 /
  1713. // \ /
  1714. //
  1715. // @param[in] f facet on which to compute distortion laplacian
  1716. // @param[in] h scaling factor applied to cross field
  1717. // @return distortion laplacian for f
  1718. ///////////////////////////////////////////////////////////////////////////
  1719. template <typename DerivedV, typename DerivedF, typename DerivedU>
  1720. IGL_INLINE double igl::MIQ_class<DerivedV, DerivedF, DerivedU>::LaplaceDistortion(const int f, double h, const Eigen::MatrixXd& WUV)
  1721. {
  1722. double mydist = Distortion(f, h, WUV);
  1723. double lapl=0;
  1724. for (int i=0;i<3;i++)
  1725. {
  1726. if (TT(f,i) != -1)
  1727. lapl += (mydist - Distortion(TT(f,i), h, WUV));
  1728. }
  1729. return lapl;
  1730. }
  1731. template <typename DerivedV, typename DerivedF, typename DerivedU>
  1732. IGL_INLINE bool igl::MIQ_class<DerivedV, DerivedF, DerivedU>::updateStiffeningJacobianDistorsion(double grad_size, const Eigen::MatrixXd& WUV)
  1733. {
  1734. bool flipped = NumFlips(WUV)>0;
  1735. if (!flipped)
  1736. return false;
  1737. double maxL=0;
  1738. double maxD=0;
  1739. if (flipped)
  1740. {
  1741. const double c = 1.0;
  1742. const double d = 5.0;
  1743. for (unsigned int i = 0; i < F.rows(); ++i)
  1744. {
  1745. double dist=Distortion(i,grad_size,WUV);
  1746. if (dist > maxD)
  1747. maxD=dist;
  1748. double absLap=fabs(LaplaceDistortion(i, grad_size,WUV));
  1749. if (absLap > maxL)
  1750. maxL = absLap;
  1751. double stiffDelta = std::min(c * absLap, d);
  1752. Handle_Stiffness[i]+=stiffDelta;
  1753. }
  1754. }
  1755. printf("Maximum Distorsion %4.4f \n",maxD);
  1756. printf("Maximum Laplacian %4.4f \n",maxL);
  1757. return flipped;
  1758. }
  1759. template <typename DerivedV, typename DerivedF, typename DerivedU>
  1760. IGL_INLINE bool igl::MIQ_class<DerivedV, DerivedF, DerivedU>::IsFlipped(const Eigen::Vector2d &uv0,
  1761. const Eigen::Vector2d &uv1,
  1762. const Eigen::Vector2d &uv2)
  1763. {
  1764. Eigen::Vector2d e0 = (uv1-uv0);
  1765. Eigen::Vector2d e1 = (uv2-uv0);
  1766. double Area = e0(0)*e1(1) - e0(1)*e1(0);
  1767. return (Area<=0);
  1768. }
  1769. template <typename DerivedV, typename DerivedF, typename DerivedU>
  1770. IGL_INLINE bool igl::MIQ_class<DerivedV, DerivedF, DerivedU>::IsFlipped(const int i, const Eigen::MatrixXd& WUV)
  1771. {
  1772. Eigen::Vector2d uv0,uv1,uv2;
  1773. uv0 << WUV(i,0), WUV(i,1);
  1774. uv1 << WUV(i,2), WUV(i,3);
  1775. uv2 << WUV(i,4), WUV(i,5);
  1776. return (IsFlipped(uv0,uv1,uv2));
  1777. }
  1778. template <typename DerivedV, typename DerivedF, typename DerivedU>
  1779. IGL_INLINE void igl::miq(const Eigen::PlainObjectBase<DerivedV> &V,
  1780. const Eigen::PlainObjectBase<DerivedF> &F,
  1781. const Eigen::PlainObjectBase<DerivedV> &PD1_combed,
  1782. const Eigen::PlainObjectBase<DerivedV> &PD2_combed,
  1783. const Eigen::PlainObjectBase<DerivedV> &BIS1_combed,
  1784. const Eigen::PlainObjectBase<DerivedV> &BIS2_combed,
  1785. const Eigen::Matrix<int, Eigen::Dynamic, 3> &Handle_MMatch,
  1786. const Eigen::Matrix<int, Eigen::Dynamic, 1> &Handle_Singular,
  1787. const Eigen::Matrix<int, Eigen::Dynamic, 1> &Handle_SingularDegree,
  1788. const Eigen::Matrix<int, Eigen::Dynamic, 3> &Handle_Seams,
  1789. Eigen::PlainObjectBase<DerivedU> &UV,
  1790. Eigen::PlainObjectBase<DerivedF> &FUV,
  1791. double GradientSize,
  1792. double Stiffness,
  1793. bool DirectRound,
  1794. int iter,
  1795. int localIter,
  1796. bool DoRound,
  1797. std::vector<int> roundVertices,
  1798. std::vector<std::vector<int> > hardFeatures)
  1799. {
  1800. GradientSize = GradientSize/(V.colwise().maxCoeff()-V.colwise().minCoeff()).norm();
  1801. igl::MIQ_class<DerivedV, DerivedF, DerivedU> miq(V,
  1802. F,
  1803. PD1_combed,
  1804. PD2_combed,
  1805. BIS1_combed,
  1806. BIS2_combed,
  1807. Handle_MMatch,
  1808. Handle_Singular,
  1809. Handle_SingularDegree,
  1810. Handle_Seams,
  1811. UV,
  1812. FUV,
  1813. GradientSize,
  1814. Stiffness,
  1815. DirectRound,
  1816. iter,
  1817. localIter,
  1818. DoRound,
  1819. roundVertices,
  1820. hardFeatures);
  1821. miq.extractUV(UV,FUV);
  1822. }
  1823. template <typename DerivedV, typename DerivedF, typename DerivedU>
  1824. IGL_INLINE void igl::miq(const Eigen::PlainObjectBase<DerivedV> &V,
  1825. const Eigen::PlainObjectBase<DerivedF> &F,
  1826. const Eigen::PlainObjectBase<DerivedV> &PD1,
  1827. const Eigen::PlainObjectBase<DerivedV> &PD2,
  1828. Eigen::PlainObjectBase<DerivedU> &UV,
  1829. Eigen::PlainObjectBase<DerivedF> &FUV,
  1830. double GradientSize,
  1831. double Stiffness,
  1832. bool DirectRound,
  1833. int iter,
  1834. int localIter,
  1835. bool DoRound,
  1836. std::vector<int> roundVertices,
  1837. std::vector<std::vector<int> > hardFeatures)
  1838. {
  1839. // Eigen::MatrixXd PD2i = PD2;
  1840. // if (PD2i.size() == 0)
  1841. // {
  1842. // Eigen::MatrixXd B1, B2, B3;
  1843. // igl::local_basis(V,F,B1,B2,B3);
  1844. // PD2i = igl::rotate_vectors(V,Eigen::VectorXd::Constant(1,M_PI/2),B1,B2);
  1845. // }
  1846. Eigen::PlainObjectBase<DerivedV> BIS1, BIS2;
  1847. igl::compute_frame_field_bisectors(V, F, PD1, PD2, BIS1, BIS2);
  1848. Eigen::PlainObjectBase<DerivedV> BIS1_combed, BIS2_combed;
  1849. igl::comb_cross_field(V, F, BIS1, BIS2, BIS1_combed, BIS2_combed);
  1850. Eigen::Matrix<int, Eigen::Dynamic, 3> Handle_MMatch;
  1851. igl::cross_field_missmatch(V, F, BIS1_combed, BIS2_combed, true, Handle_MMatch);
  1852. Eigen::Matrix<int, Eigen::Dynamic, 1> isSingularity, singularityIndex;
  1853. igl::find_cross_field_singularities(V, F, Handle_MMatch, isSingularity, singularityIndex);
  1854. Eigen::Matrix<int, Eigen::Dynamic, 3> Handle_Seams;
  1855. igl::cut_mesh_from_singularities(V, F, Handle_MMatch, isSingularity, singularityIndex, Handle_Seams);
  1856. Eigen::PlainObjectBase<DerivedV> PD1_combed, PD2_combed;
  1857. igl::comb_frame_field(V, F, PD1, PD2, BIS1_combed, BIS2_combed, PD1_combed, PD2_combed);
  1858. igl::miq(V,
  1859. F,
  1860. PD1_combed,
  1861. PD2_combed,
  1862. BIS1_combed,
  1863. BIS2_combed,
  1864. Handle_MMatch,
  1865. isSingularity,
  1866. singularityIndex,
  1867. Handle_Seams,
  1868. UV,
  1869. FUV,
  1870. GradientSize,
  1871. Stiffness,
  1872. DirectRound,
  1873. iter,
  1874. localIter,
  1875. DoRound);
  1876. }
  1877. #ifdef IGL_STATIC_LIBRARY
  1878. // Explicit template specialization
  1879. template void igl::miq<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3>, Eigen::Matrix<double, -1, 2, 0, -1, 2> >(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, 2, 0, -1, 2> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> >&, double, double, bool, int, int, 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> > > >);
  1880. #endif