miq.h 5.1 KB

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