covariance_scatter_matrix.cpp 1.8 KB

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