arap.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <[email protected]>
  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_ARAP_H
  9. #define IGL_ARAP_H
  10. #include "igl_inline.h"
  11. #include "min_quad_with_fixed.h"
  12. #include "ARAPEnergyType.h"
  13. #include <Eigen/Core>
  14. #include <Eigen/Sparse>
  15. namespace igl
  16. {
  17. /// Parameters and precomputed values for arap solver.
  18. ///
  19. /// \fileinfo
  20. struct ARAPData
  21. {
  22. /// #V size of mesh
  23. int n;
  24. /// #V list of group indices (1 to k) for each vertex, such that vertex i
  25. /// is assigned to group G(i)
  26. Eigen::VectorXi G;
  27. /// type of energy to use
  28. ARAPEnergyType energy;
  29. /// whether using dynamics (need to call arap_precomputation after changing)
  30. bool with_dynamics;
  31. /// #V by dim list of external forces
  32. Eigen::MatrixXd f_ext;
  33. /// #V by dim list of velocities
  34. Eigen::MatrixXd vel;
  35. /// dynamics time step
  36. double h;
  37. /// "Young's modulus" smaller is softer, larger is more rigid/stiff
  38. double ym;
  39. /// maximum inner iterations
  40. int max_iter;
  41. /// @private rhs pre-multiplier
  42. Eigen::SparseMatrix<double> K;
  43. /// @private mass matrix
  44. Eigen::SparseMatrix<double> M;
  45. /// @private covariance scatter matrix
  46. Eigen::SparseMatrix<double> CSM;
  47. /// @private quadratic solver data
  48. min_quad_with_fixed_data<double> solver_data;
  49. /// @private list of boundary indices into V
  50. Eigen::VectorXi b;
  51. /// @private dimension being used for solving
  52. int dim;
  53. ARAPData():
  54. n(0),
  55. G(),
  56. energy(ARAP_ENERGY_TYPE_DEFAULT),
  57. with_dynamics(false),
  58. f_ext(),
  59. h(1),
  60. ym(1),
  61. max_iter(10),
  62. K(),
  63. CSM(),
  64. solver_data(),
  65. b(),
  66. dim(-1) // force this to be set by _precomputation
  67. {
  68. };
  69. };
  70. /// Compute necessary information to start using an ARAP deformation using
  71. /// local-global solver as described in "As-rigid-as-possible surface
  72. /// modeling" [Sorkine and Alexa 2007].
  73. ///
  74. /// @param[in] V #V by dim list of mesh positions
  75. /// @param[in] F #F by simplex-size list of triangle|tet indices into V
  76. /// @param[in] dim dimension being used at solve time. For deformation usually dim =
  77. /// V.cols(), for surface parameterization V.cols() = 3 and dim = 2
  78. /// @param[in] b #b list of "boundary" fixed vertex indices into V
  79. /// @param[out] data struct containing necessary precomputation
  80. /// @return whether initialization succeeded
  81. ///
  82. /// \fileinfo
  83. template <
  84. typename DerivedV,
  85. typename DerivedF,
  86. typename Derivedb>
  87. IGL_INLINE bool arap_precomputation(
  88. const Eigen::MatrixBase<DerivedV> & V,
  89. const Eigen::MatrixBase<DerivedF> & F,
  90. const int dim,
  91. const Eigen::MatrixBase<Derivedb> & b,
  92. ARAPData & data);
  93. /// Conduct arap solve.
  94. ///
  95. /// @param[in] bc #b by dim list of boundary conditions
  96. /// @param[in] data struct containing necessary precomputation and parameters
  97. /// @param[in,out] U #V by dim initial guess
  98. ///
  99. /// \fileinfo
  100. ///
  101. /// \note While the libigl guidelines require outputs to be of type
  102. /// PlainObjectBase so that the user does not need to worry about allocating
  103. /// memory for the output, in this case, the user is required to give an initial
  104. /// guess and hence fix the size of the problem domain.
  105. /// Taking a reference to MatrixBase in this case thus allows the user to provide e.g.
  106. /// a map to the position data, allowing seamless interoperability with user-defined
  107. /// datastructures without requiring a copy.
  108. template <
  109. typename Derivedbc,
  110. typename DerivedU>
  111. IGL_INLINE bool arap_solve(
  112. const Eigen::MatrixBase<Derivedbc> & bc,
  113. ARAPData & data,
  114. Eigen::MatrixBase<DerivedU> & U);
  115. };
  116. #ifndef IGL_STATIC_LIBRARY
  117. #include "arap.cpp"
  118. #endif
  119. #endif