arap_rhs.cpp 2.1 KB

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