covariance_scatter_matrix.cpp 1.9 KB

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