covariance_scatter_matrix.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 Eigen;
  23. // number of mesh vertices
  24. int n = V.rows();
  25. assert(n > F.maxCoeff());
  26. // dimension of mesh
  27. int dim = V.cols();
  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. "covariance_scatter_matrix.h: Error: Unsupported arap energy %d\n",
  47. energy);
  48. return;
  49. }
  50. SparseMatrix<double> KX,KY,KZ;
  51. arap_linear_block(V,F,0,energy,KX);
  52. arap_linear_block(V,F,1,energy,KY);
  53. SparseMatrix<double> Z(n,nr);
  54. if(dim == 2)
  55. {
  56. CSM = cat(1,cat(2,KX,Z),cat(2,Z,KY)).transpose();
  57. }else if(dim == 3)
  58. {
  59. arap_linear_block(V,F,2,energy,KZ);
  60. SparseMatrix<double>ZZ(n,nr*2);
  61. CSM =
  62. cat(1,cat(1,cat(2,KX,ZZ),cat(2,cat(2,Z,KY),Z)),cat(2,ZZ,KZ)).transpose();
  63. }else
  64. {
  65. fprintf(
  66. stderr,
  67. "covariance_scatter_matrix.h: Error: Unsupported dimension %d\n",
  68. dim);
  69. return;
  70. }
  71. }