average_from_edges_onto_vertices.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 "average_from_edges_onto_vertices.h"
  9. template<typename DerivedF,typename DerivedE,typename DerivedoE,
  10. typename DeriveduE,typename DeriveduV>
  11. IGL_INLINE void
  12. igl::average_from_edges_onto_vertices(
  13. const Eigen::MatrixBase<DerivedF> &F,
  14. const Eigen::MatrixBase<DerivedE> &E,
  15. const Eigen::MatrixBase<DerivedoE> &oE,
  16. const Eigen::MatrixBase<DeriveduE> &uE,
  17. Eigen::PlainObjectBase<DeriveduV> &uV)
  18. {
  19. using Scalar = typename DeriveduE::Scalar;
  20. using VecX = Eigen::Matrix<Scalar, Eigen::Dynamic, 1>;
  21. using Int = typename DerivedF::Scalar;
  22. assert(E.rows()==F.rows() && "E does not match dimensions of F.");
  23. assert(oE.rows()==F.rows() && "oE does not match dimensions of F.");
  24. assert(E.cols()==3 && F.cols()==3 && oE.cols()==3 &&
  25. "This method is for triangle meshes.");
  26. const Int n = F.maxCoeff()+1;
  27. VecX edgesPerVertex(n);
  28. edgesPerVertex.setZero();
  29. uV.resize(n,1);
  30. uV.setZero();
  31. for(Eigen::Index i=0; i<F.rows(); ++i) {
  32. for(int j=0; j<3; ++j) {
  33. if(oE(i,j)<0) {
  34. continue;
  35. }
  36. const Int e = E(i,j);
  37. const Int vi=F(i,(j+1)%3), vj=F(i,(j+2)%3);
  38. //Count vertex valence
  39. ++edgesPerVertex(vi);
  40. ++edgesPerVertex(vj);
  41. //Average uE value onto vertices
  42. uV(vi) += uE(e);
  43. uV(vj) += uE(e);
  44. }
  45. }
  46. //Divide by valence
  47. for(Int i=0; i<n; ++i) {
  48. const Scalar valence = edgesPerVertex(i);
  49. if(valence>0) {
  50. uV(i) /= valence;
  51. }
  52. }
  53. }
  54. #ifdef IGL_STATIC_LIBRARY
  55. // Explicit template instantiation
  56. // generated by autoexplicit.sh
  57. template void igl::average_from_edges_onto_vertices<Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
  58. template void igl::average_from_edges_onto_vertices<Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
  59. template void igl::average_from_edges_onto_vertices<Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
  60. #endif