arap.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. // max_iter maximum inner iterations
  29. // K rhs pre-multiplier
  30. // M mass matrix
  31. // solver_data quadratic solver data
  32. // b list of boundary indices into V
  33. // dim dimension being used for solving
  34. int n;
  35. Eigen::VectorXi G;
  36. ARAPEnergyType energy;
  37. bool with_dynamics;
  38. Eigen::MatrixXd f_ext,vel;
  39. double h;
  40. int max_iter;
  41. Eigen::SparseMatrix<double> K,M;
  42. Eigen::SparseMatrix<double> CSM;
  43. min_quad_with_fixed_data<double> solver_data;
  44. Eigen::VectorXi b;
  45. int dim;
  46. ARAPData():
  47. n(0),
  48. G(),
  49. energy(ARAP_ENERGY_TYPE_DEFAULT),
  50. with_dynamics(false),
  51. f_ext(),
  52. h(1),
  53. max_iter(10),
  54. K(),
  55. CSM(),
  56. solver_data(),
  57. b(),
  58. dim(-1) // force this to be set by _precomputation
  59. {
  60. };
  61. };
  62. // Compute necessary information to start using an ARAP deformation
  63. //
  64. // Inputs:
  65. // V #V by dim list of mesh positions
  66. // F #F by simplex-size list of triangle|tet indices into V
  67. // dim dimension being used at solve time. For deformation usually dim =
  68. // V.cols(), for surface parameterization V.cols() = 3 and dim = 2
  69. // b #b list of "boundary" fixed vertex indices into V
  70. // Outputs:
  71. // data struct containing necessary precomputation
  72. template <
  73. typename DerivedV,
  74. typename DerivedF,
  75. typename Derivedb>
  76. IGL_INLINE bool arap_precomputation(
  77. const Eigen::PlainObjectBase<DerivedV> & V,
  78. const Eigen::PlainObjectBase<DerivedF> & F,
  79. const int dim,
  80. const Eigen::PlainObjectBase<Derivedb> & b,
  81. ARAPData & data);
  82. // Inputs:
  83. // bc #b by dim list of boundary conditions
  84. // data struct containing necessary precomputation and parameters
  85. // U #V by dim initial guess
  86. template <
  87. typename Derivedbc,
  88. typename DerivedU>
  89. IGL_INLINE bool arap_solve(
  90. const Eigen::PlainObjectBase<Derivedbc> & bc,
  91. ARAPData & data,
  92. Eigen::PlainObjectBase<DerivedU> & U);
  93. };
  94. #ifndef IGL_STATIC_LIBRARY
  95. #include "arap.cpp"
  96. #endif
  97. #endif