arap.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <alecjacobson@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_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. struct ARAPData
  18. {
  19. // n #V
  20. // G #V list of group indices (1 to k) for each vertex, such that vertex i
  21. // is assigned to group G(i)
  22. // energy type of energy to use
  23. // with_dynamics whether using dynamics (need to call arap_precomputation
  24. // after changing)
  25. // f_ext #V by dim list of external forces
  26. // vel #V by dim list of velocities
  27. // h dynamics time step
  28. // ym ~Young's modulus smaller is softer, larger is more rigid/stiff
  29. // max_iter maximum inner iterations
  30. // K rhs pre-multiplier
  31. // M mass matrix
  32. // solver_data quadratic solver data
  33. // b list of boundary indices into V
  34. // dim dimension being used for solving
  35. int n;
  36. Eigen::VectorXi G;
  37. ARAPEnergyType energy;
  38. bool with_dynamics;
  39. Eigen::MatrixXd f_ext,vel;
  40. double h;
  41. double ym;
  42. int max_iter;
  43. Eigen::SparseMatrix<double> K,M;
  44. Eigen::SparseMatrix<double> CSM;
  45. min_quad_with_fixed_data<double> solver_data;
  46. Eigen::VectorXi b;
  47. int dim;
  48. ARAPData():
  49. n(0),
  50. G(),
  51. energy(ARAP_ENERGY_TYPE_DEFAULT),
  52. with_dynamics(false),
  53. f_ext(),
  54. h(1),
  55. ym(1),
  56. max_iter(10),
  57. K(),
  58. CSM(),
  59. solver_data(),
  60. b(),
  61. dim(-1) // force this to be set by _precomputation
  62. {
  63. };
  64. };
  65. // Compute necessary information to start using an ARAP deformation
  66. //
  67. // Inputs:
  68. // V #V by dim list of mesh positions
  69. // F #F by simplex-size list of triangle|tet indices into V
  70. // dim dimension being used at solve time. For deformation usually dim =
  71. // V.cols(), for surface parameterization V.cols() = 3 and dim = 2
  72. // b #b list of "boundary" fixed vertex indices into V
  73. // Outputs:
  74. // data struct containing necessary precomputation
  75. template <
  76. typename DerivedV,
  77. typename DerivedF,
  78. typename Derivedb>
  79. IGL_INLINE bool arap_precomputation(
  80. const Eigen::PlainObjectBase<DerivedV> & V,
  81. const Eigen::PlainObjectBase<DerivedF> & F,
  82. const int dim,
  83. const Eigen::PlainObjectBase<Derivedb> & b,
  84. ARAPData & data);
  85. // Inputs:
  86. // bc #b by dim list of boundary conditions
  87. // data struct containing necessary precomputation and parameters
  88. // U #V by dim initial guess
  89. template <
  90. typename Derivedbc,
  91. typename DerivedU>
  92. IGL_INLINE bool arap_solve(
  93. const Eigen::PlainObjectBase<Derivedbc> & bc,
  94. ARAPData & data,
  95. Eigen::PlainObjectBase<DerivedU> & U);
  96. };
  97. #ifndef IGL_STATIC_LIBRARY
  98. #include "arap.cpp"
  99. #endif
  100. #endif