covariance_scatter_matrix.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 "covariance_scatter_matrix.h"
  9. #include "arap_linear_block.h"
  10. #include "cotmatrix.h"
  11. #include "sum.h"
  12. #include "edges.h"
  13. #include "verbose.h"
  14. #include "cat.h"
  15. #include "PI.h"
  16. template <
  17. typename DerivedV,
  18. typename DerivedF,
  19. typename CSM_type>
  20. IGL_INLINE void igl::covariance_scatter_matrix(
  21. const Eigen::MatrixBase<DerivedV> & V,
  22. const Eigen::MatrixBase<DerivedF> & F,
  23. const ARAPEnergyType energy,
  24. Eigen::SparseMatrix<CSM_type>& CSM)
  25. {
  26. // number of mesh vertices
  27. int n = V.rows();
  28. assert(n > F.maxCoeff());
  29. // dimension of mesh
  30. int dim = V.cols();
  31. // Number of mesh elements
  32. int m = F.rows();
  33. // number of rotations
  34. int nr;
  35. switch(energy)
  36. {
  37. case ARAP_ENERGY_TYPE_SPOKES:
  38. nr = n;
  39. break;
  40. case ARAP_ENERGY_TYPE_SPOKES_AND_RIMS:
  41. nr = n;
  42. break;
  43. case ARAP_ENERGY_TYPE_ELEMENTS:
  44. nr = m;
  45. break;
  46. default:
  47. fprintf(
  48. stderr,
  49. "covariance_scatter_matrix.h: Error: Unsupported arap energy %d\n",
  50. energy);
  51. return;
  52. }
  53. Eigen::SparseMatrix<double> KX,KY,KZ;
  54. arap_linear_block(V,F,0,energy,KX);
  55. arap_linear_block(V,F,1,energy,KY);
  56. Eigen::SparseMatrix<double> Z(n,nr);
  57. if(dim == 2)
  58. {
  59. CSM = cat(1,cat(2,KX,Z),cat(2,Z,KY)).transpose();
  60. }else if(dim == 3)
  61. {
  62. arap_linear_block(V,F,2,energy,KZ);
  63. Eigen::SparseMatrix<double>ZZ(n,nr*2);
  64. CSM =
  65. cat(1,cat(1,cat(2,KX,ZZ),cat(2,cat(2,Z,KY),Z)),cat(2,ZZ,KZ)).transpose();
  66. }else
  67. {
  68. fprintf(
  69. stderr,
  70. "covariance_scatter_matrix.h: Error: Unsupported dimension %d\n",
  71. dim);
  72. return;
  73. }
  74. }
  75. #ifdef IGL_STATIC_LIBRARY
  76. // Explicit template instantiation
  77. template void igl::covariance_scatter_matrix<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, double>(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1>> const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1>> const&, igl::ARAPEnergyType, Eigen::SparseMatrix<double, 0, int>&);
  78. #endif