cr_vector_mass.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2020 Oded Stein <[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 "cr_vector_mass.h"
  9. #include <vector>
  10. #include "orient_halfedges.h"
  11. #include "doublearea.h"
  12. #include "squared_edge_lengths.h"
  13. template <typename DerivedV, typename DerivedF, typename DerivedE, typename ScalarM>
  14. IGL_INLINE void
  15. igl::cr_vector_mass(
  16. const Eigen::MatrixBase<DerivedV>& V,
  17. const Eigen::MatrixBase<DerivedF>& F,
  18. const Eigen::MatrixBase<DerivedE>& E,
  19. Eigen::SparseMatrix<ScalarM>& M)
  20. {
  21. Eigen::Matrix<typename DerivedV::Scalar, Eigen::Dynamic, Eigen::Dynamic>
  22. dblA;
  23. doublearea(V,F,dblA);
  24. cr_vector_mass_intrinsic(F, dblA, E, M);
  25. }
  26. template <
  27. typename DerivedV,
  28. typename DerivedF,
  29. typename DerivedE,
  30. typename ScalarM>
  31. IGL_INLINE void
  32. igl::cr_vector_mass(
  33. const Eigen::MatrixBase<DerivedV>& V,
  34. const Eigen::MatrixBase<DerivedF>& F,
  35. Eigen::PlainObjectBase<DerivedE>& E,
  36. Eigen::SparseMatrix<ScalarM>& M)
  37. {
  38. if(E.rows()!=F.rows() || E.cols()!=F.cols())
  39. {
  40. DerivedE oE;
  41. orient_halfedges(F, E, oE);
  42. }
  43. const Eigen::PlainObjectBase<DerivedE>& cE = E;
  44. cr_vector_mass(V, F, cE, M);
  45. }
  46. template <typename DerivedF, typename DeriveddA,
  47. typename DerivedE, typename ScalarM>
  48. IGL_INLINE void
  49. igl::cr_vector_mass_intrinsic(
  50. const Eigen::MatrixBase<DerivedF>& F,
  51. const Eigen::MatrixBase<DeriveddA>& dA,
  52. const Eigen::MatrixBase<DerivedE>& E,
  53. Eigen::SparseMatrix<ScalarM>& M)
  54. {
  55. assert(F.cols()==3 && "Faces have three vertices");
  56. assert(E.rows()==F.rows() && E.cols()==F.cols() && "Wrong dimension in edge vectors");
  57. const Eigen::Index m = F.rows();
  58. const typename DerivedE::Scalar nE = E.maxCoeff() + 1;
  59. std::vector<Eigen::Triplet<ScalarM> > tripletList;
  60. tripletList.reserve(2*3*m);
  61. for(Eigen::Index f=0; f<m; ++f) {
  62. for(int e=0; e<3; ++e) {
  63. //Scaled
  64. const ScalarM entry = dA(f) / 6;
  65. tripletList.emplace_back(E(f,e), E(f,e), entry);
  66. tripletList.emplace_back(E(f,e)+nE, E(f,e)+nE, entry);
  67. }
  68. }
  69. M.resize(2*nE, 2*nE);
  70. M.setFromTriplets(tripletList.begin(), tripletList.end());
  71. }
  72. #ifdef IGL_STATIC_LIBRARY
  73. // Explicit template instantiation
  74. // generated by autoexplicit.sh
  75. template void igl::cr_vector_mass<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -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&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1>>&, Eigen::SparseMatrix<double, 0, int>&);
  76. #endif