miq.h 5.8 KB

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