miq.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. // Limitations:
  26. // - Due to the way of handling of hardFeatures the algorithm may fail in difficult cases.
  27. // - Meshes with boundaries are not hendled properly i.e., jagged edges along the boundary are possible
  28. // Input:
  29. // V #V by 3 list of mesh vertex 3D positions
  30. // F #F by 3 list of faces indices in V
  31. // PD1 #V by 3 first line of the Jacobian per triangle
  32. // PD2 #V by 3 second line of the Jacobian per triangle
  33. // (optional, if empty it will be a vector in the tangent plane orthogonal to PD1)
  34. // gradientSize global scaling for the gradient (controls the quads resolution)
  35. // stiffness weight for the stiffness iterations (Reserved but not used!)
  36. // directRound greedily round all integer variables at once (greatly improves optimization speed but lowers quality)
  37. // iter stiffness iterations (0 = no stiffness)
  38. // localIter number of local iterations for the integer rounding
  39. // doRound enables the integer rounding (disabling it could be useful for debugging)
  40. // singularityRound set true/false to decide if the singularities' coordinates should be rounded to the nearest integers
  41. // roundVertices id of additional vertices that should be snapped to integer coordinates
  42. // hardFeatures #H by 2 list of pairs of vertices that belongs to edges that should be snapped to integer coordinates
  43. //
  44. // Output:
  45. // UV #UV by 2 list of vertices in 2D
  46. // FUV #FUV by 3 list of face indices in UV
  47. //
  48. template <typename DerivedV, typename DerivedF, typename DerivedU>
  49. IGL_INLINE void miq(
  50. const Eigen::PlainObjectBase<DerivedV> &V,
  51. const Eigen::PlainObjectBase<DerivedF> &F,
  52. const Eigen::PlainObjectBase<DerivedV> &PD1,
  53. const Eigen::PlainObjectBase<DerivedV> &PD2,
  54. Eigen::PlainObjectBase<DerivedU> &UV,
  55. Eigen::PlainObjectBase<DerivedF> &FUV,
  56. double gradientSize = 30.0,
  57. double stiffness = 5.0,
  58. bool directRound = false,
  59. int iter = 5,
  60. int localIter = 5,
  61. bool doRound = true,
  62. bool singularityRound = true,
  63. std::vector<int> roundVertices = std::vector<int>(),
  64. std::vector<std::vector<int> > hardFeatures = std::vector<std::vector<int> >());
  65. // Helper function that allows to directly provided pre-combed bisectors for an already cut mesh
  66. // Input:
  67. // V #V by 3 list of mesh vertex 3D positions
  68. // F #F by 3 list of faces indices in V
  69. // Additional Input:
  70. // PD1_combed #F by 3 first combed Jacobian
  71. // PD2_combed #F by 3 second combed Jacobian
  72. // mismatch #F by 3 list of per-corner integer PI/2 rotations
  73. // singular #V list of flag that denotes if a vertex is singular or not
  74. // seams #F by 3 list of per-corner flag that denotes seams
  75. // Input:
  76. // gradientSize global scaling for the gradient (controls the quads resolution)
  77. // stiffness weight for the stiffness iterations (Reserved but not used!)
  78. // directRound greedily round all integer variables at once (greatly improves optimization speed but lowers quality)
  79. // iter stiffness iterations (0 = no stiffness)
  80. // localIter number of local iterations for the integer rounding
  81. // doRound enables the integer rounding (disabling it could be useful for debugging)
  82. // singularityRound set true/false to decide if the singularities' coordinates should be rounded to the nearest integers
  83. // roundVertices id of additional vertices that should be snapped to integer coordinates
  84. // hardFeatures #H by 2 list of pairs of vertices that belongs to edges that should be snapped to integer coordinates
  85. // Output:
  86. // UV #UV by 2 list of vertices in 2D
  87. // FUV #FUV by 3 list of face indices in UV
  88. //
  89. template <typename DerivedV, typename DerivedF, typename DerivedU>
  90. IGL_INLINE void miq(const Eigen::PlainObjectBase<DerivedV> &V,
  91. const Eigen::PlainObjectBase<DerivedF> &F,
  92. const Eigen::PlainObjectBase<DerivedV> &PD1_combed,
  93. const Eigen::PlainObjectBase<DerivedV> &PD2_combed,
  94. const Eigen::Matrix<int, Eigen::Dynamic, 3> &mismatch,
  95. const Eigen::Matrix<int, Eigen::Dynamic, 1> &singular,
  96. const Eigen::Matrix<int, Eigen::Dynamic, 3> &seams,
  97. Eigen::PlainObjectBase<DerivedU> &UV,
  98. Eigen::PlainObjectBase<DerivedF> &FUV,
  99. double gradientSize = 30.0,
  100. double stiffness = 5.0,
  101. bool directRound = false,
  102. int iter = 5,
  103. int localIter = 5,
  104. bool doRound = true,
  105. bool singularityRound = true,
  106. std::vector<int> roundVertices = std::vector<int>(),
  107. std::vector<std::vector<int> > hardFeatures = std::vector<std::vector<int> >());
  108. };
  109. };
  110. };
  111. #ifndef IGL_STATIC_LIBRARY
  112. #include "miq.cpp"
  113. #endif
  114. #endif