arap_rhs.cpp 2.1 KB

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