arap_rhs.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. // 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. Eigen::SparseMatrix<typename DerivedK::Scalar> 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. Eigen::SparseMatrix<typename DerivedK::Scalar> 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. }
  85. #ifdef IGL_STATIC_LIBRARY
  86. 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);
  87. #endif