arap_rhs.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <[email protected]>
  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. template<typename DerivedV, typename DerivedF, typename DerivedK>
  15. IGL_INLINE void igl::arap_rhs(
  16. const Eigen::MatrixBase<DerivedV> & V,
  17. const Eigen::MatrixBase<DerivedF> & F,
  18. const int dim,
  19. const igl::ARAPEnergyType energy,
  20. Eigen::SparseCompressedBase<DerivedK>& K)
  21. {
  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. DerivedK 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. DerivedK 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. }
  87. #ifdef IGL_STATIC_LIBRARY
  88. template void igl::arap_rhs(const Eigen::MatrixBase<Eigen::MatrixXd> & V, const Eigen::MatrixBase<Eigen::MatrixXi> & F,const int dim, const igl::ARAPEnergyType energy,Eigen::SparseCompressedBase<Eigen::SparseMatrix<double>>& K);
  89. #endif