miq.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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>, Kevin Walliman <wkevin@student.ethz.ch>
  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. #ifndef IGL_COMISO_MIQ_H
  9. #define IGL_COMISO_MIQ_H
  10. #include "../../igl_inline.h"
  11. #include <Eigen/Core>
  12. #include <vector>
  13. namespace igl
  14. {
  15. namespace copyleft
  16. {
  17. namespace comiso
  18. {
  19. // Global seamless parametrization aligned with a given per-face jacobian (PD1,PD2).
  20. // The algorithm is based on
  21. // "Mixed-Integer Quadrangulation" by D. Bommes, H. Zimmer, L. Kobbelt
  22. // ACM SIGGRAPH 2009, Article No. 77 (http://dl.acm.org/citation.cfm?id=1531383)
  23. // We thank Nico Pietroni for providing a reference implementation of MIQ
  24. // on which our code is based.
  25. // Inputs:
  26. // V #V by 3 list of mesh vertex 3D positions
  27. // F #F by 3 list of faces indices in V
  28. // PD1 #V by 3 first line of the Jacobian per triangle
  29. // PD2 #V by 3 second line of the Jacobian per triangle
  30. // (optional, if empty it will be a vector in the tangent plane orthogonal to PD1)
  31. // scale global scaling for the gradient (controls the quads resolution)
  32. // stiffness weight for the stiffness iterations
  33. // direct_round greedily round all integer variables at once (greatly improves optimization speed but lowers quality)
  34. // iter stiffness iterations (0 = no stiffness)
  35. // local_iter number of local iterations for the integer rounding
  36. // do_round enables the integer rounding (disabling it could be useful for debugging)
  37. // round_vertices id of additional vertices that should be snapped to integer coordinates
  38. // hard_features #H by 2 list of pairs of vertices that belongs to edges that should be snapped to integer coordinates
  39. //
  40. // Output:
  41. // UV #UV by 2 list of vertices in 2D
  42. // FUV #FUV by 3 list of face indices in UV
  43. //
  44. // TODO: rename the parameters name in the cpp consistenly
  45. // improve the handling of hard_features, right now it might fail in difficult cases
  46. template <typename DerivedV, typename DerivedF, typename DerivedU>
  47. IGL_INLINE void miq(
  48. const Eigen::PlainObjectBase<DerivedV> &V,
  49. const Eigen::PlainObjectBase<DerivedF> &F,
  50. const Eigen::PlainObjectBase<DerivedV> &PD1,
  51. const Eigen::PlainObjectBase<DerivedV> &PD2,
  52. Eigen::PlainObjectBase<DerivedU> &UV,
  53. Eigen::PlainObjectBase<DerivedF> &FUV,
  54. double scale = 30.0,
  55. double stiffness = 5.0,
  56. bool direct_round = false,
  57. int iter = 5,
  58. int local_iter = 5,
  59. bool DoRound = true,bool SingularityRound=true,
  60. std::vector<int> round_vertices = std::vector<int>(),
  61. std::vector<std::vector<int> > hard_features = std::vector<std::vector<int> >());
  62. // Helper function that allows to directly provided pre-combed bisectors for an already cut mesh
  63. // Additional input:
  64. // PD1_combed, PD2_combed : #F by 3 combed jacobian
  65. // BIS1_combed, BIS2_combed: #F by 3 pre combed bi-sectors
  66. // MMatch: #F by 3 list of per-corner integer PI/2 rotations
  67. // Singular: #V list of flag that denotes if a vertex is singular or not
  68. // SingularDegree: #V list of flag that denotes the degree of the singularity
  69. // Seams: #F by 3 list of per-corner flag that denotes seams
  70. template <typename DerivedV, typename DerivedF, typename DerivedU>
  71. IGL_INLINE void miq(const Eigen::PlainObjectBase<DerivedV> &V,
  72. const Eigen::PlainObjectBase<DerivedF> &F,
  73. const Eigen::PlainObjectBase<DerivedV> &PD1_combed,
  74. const Eigen::PlainObjectBase<DerivedV> &PD2_combed,
  75. const Eigen::Matrix<int, Eigen::Dynamic, 3> &MMatch,
  76. const Eigen::Matrix<int, Eigen::Dynamic, 1> &Singular,
  77. const Eigen::Matrix<int, Eigen::Dynamic, 3> &Seams,
  78. Eigen::PlainObjectBase<DerivedU> &UV,
  79. Eigen::PlainObjectBase<DerivedF> &FUV,
  80. double GradientSize = 30.0,
  81. double Stiffness = 5.0,
  82. bool DirectRound = false,
  83. int iter = 5,
  84. int localIter = 5, bool DoRound = true,bool SingularityRound=true,
  85. std::vector<int> roundVertices = std::vector<int>(),
  86. std::vector<std::vector<int> > hardFeatures = std::vector<std::vector<int> >());
  87. };
  88. };
  89. };
  90. #ifndef IGL_STATIC_LIBRARY
  91. #include "miq.cpp"
  92. #endif
  93. #endif