arap.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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/igl_inline.h>
  11. #include <igl/min_quad_with_fixed.h>
  12. #include <igl/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. int n;
  34. Eigen::VectorXi G;
  35. ARAPEnergyType energy;
  36. bool with_dynamics;
  37. Eigen::MatrixXd f_ext,vel;
  38. double h;
  39. int max_iter;
  40. Eigen::SparseMatrix<double> K,M;
  41. Eigen::SparseMatrix<double> CSM;
  42. min_quad_with_fixed_data<double> solver_data;
  43. Eigen::VectorXi b;
  44. ARAPData():
  45. n(0),
  46. G(),
  47. energy(ARAP_ENERGY_TYPE_DEFAULT),
  48. with_dynamics(false),
  49. f_ext(),
  50. h(1),
  51. max_iter(10),
  52. K(),
  53. CSM(),
  54. solver_data(),
  55. b()
  56. {
  57. };
  58. };
  59. // Compute necessary information to start using an ARAP deformation
  60. //
  61. // Inputs:
  62. // V #V by dim list of mesh positions
  63. // F #F by simplex-size list of triangle|tet indices into V
  64. // b #b list of "boundary" fixed vertex indices into V
  65. // Outputs:
  66. // data struct containing necessary precomputation
  67. template <
  68. typename DerivedV,
  69. typename DerivedF,
  70. typename Derivedb>
  71. IGL_INLINE bool arap_precomputation(
  72. const Eigen::PlainObjectBase<DerivedV> & V,
  73. const Eigen::PlainObjectBase<DerivedF> & F,
  74. const Eigen::PlainObjectBase<Derivedb> & b,
  75. ARAPData & data);
  76. // Inputs:
  77. // bc #b by dim list of boundary conditions
  78. // data struct containing necessary precomputation and parameters
  79. // U #V by dim initial guess
  80. template <
  81. typename Derivedbc,
  82. typename DerivedU>
  83. IGL_INLINE bool arap_solve(
  84. const Eigen::PlainObjectBase<Derivedbc> & bc,
  85. ARAPData & data,
  86. Eigen::PlainObjectBase<DerivedU> & U);
  87. };
  88. #ifdef IGL_HEADER_ONLY
  89. #include "arap.cpp"
  90. #endif
  91. #endif