miq.cpp 72 KB

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