miq.h 4.6 KB

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