arap_rhs.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. #include "arap_rhs.h"
  9. #include "arap_linear_block.h"
  10. #include "verbose.h"
  11. #include "repdiag.h"
  12. #include "cat.h"
  13. IGL_INLINE void igl::arap_rhs(
  14. const Eigen::MatrixXd & V,
  15. const Eigen::MatrixXi & F,
  16. const int dim,
  17. const igl::ARAPEnergyType energy,
  18. Eigen::SparseMatrix<double>& K)
  19. {
  20. using namespace igl;
  21. using namespace Eigen;
  22. // Number of dimensions
  23. int Vdim = V.cols();
  24. //// Number of mesh vertices
  25. //int n = V.rows();
  26. //// Number of mesh elements
  27. //int m = F.rows();
  28. //// number of rotations
  29. //int nr;
  30. switch(energy)
  31. {
  32. case ARAP_ENERGY_TYPE_SPOKES:
  33. //nr = n;
  34. break;
  35. case ARAP_ENERGY_TYPE_SPOKES_AND_RIMS:
  36. //nr = n;
  37. break;
  38. case ARAP_ENERGY_TYPE_ELEMENTS:
  39. //nr = m;
  40. break;
  41. default:
  42. fprintf(
  43. stderr,
  44. "arap_rhs.h: Error: Unsupported arap energy %d\n",
  45. energy);
  46. return;
  47. }
  48. SparseMatrix<double> KX,KY,KZ;
  49. arap_linear_block(V,F,0,energy,KX);
  50. arap_linear_block(V,F,1,energy,KY);
  51. if(Vdim == 2)
  52. {
  53. K = cat(2,repdiag(KX,dim),repdiag(KY,dim));
  54. }else if(Vdim == 3)
  55. {
  56. arap_linear_block(V,F,2,energy,KZ);
  57. if(dim == 3)
  58. {
  59. K = cat(2,cat(2,repdiag(KX,dim),repdiag(KY,dim)),repdiag(KZ,dim));
  60. }else if(dim ==2)
  61. {
  62. SparseMatrix<double> ZZ(KX.rows()*2,KX.cols());
  63. K = cat(2,cat(2,
  64. cat(2,repdiag(KX,dim),ZZ),
  65. cat(2,repdiag(KY,dim),ZZ)),
  66. cat(2,repdiag(KZ,dim),ZZ));
  67. }else
  68. {
  69. assert(false);
  70. fprintf(
  71. stderr,
  72. "arap_rhs.h: Error: Unsupported dimension %d\n",
  73. dim);
  74. }
  75. }else
  76. {
  77. assert(false);
  78. fprintf(
  79. stderr,
  80. "arap_rhs.h: Error: Unsupported dimension %d\n",
  81. Vdim);
  82. return;
  83. }
  84. }