average_onto_vertices.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233
  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 "average_onto_vertices.h"
  9. template<typename DerivedV,typename DerivedF,typename DerivedS>
  10. IGL_INLINE void igl::average_onto_vertices(const Eigen::MatrixBase<DerivedV> &V,
  11. const Eigen::MatrixBase<DerivedF> &F,
  12. const Eigen::MatrixBase<DerivedS> &S,
  13. Eigen::MatrixBase<DerivedS> &SV)
  14. {
  15. SV = DerivedS::Zero(V.rows(),S.cols());
  16. Eigen::Matrix<typename DerivedF::Scalar,Eigen::Dynamic,1> COUNT(V.rows());
  17. COUNT.setZero();
  18. for (int i = 0; i <F.rows(); ++i)
  19. {
  20. for (int j = 0; j<F.cols(); ++j)
  21. {
  22. SV.row(F(i,j)) += S.row(i);
  23. COUNT[F(i,j)] ++;
  24. }
  25. }
  26. for (int i = 0; i <V.rows(); ++i)
  27. SV.row(i) /= COUNT[i];
  28. };
  29. #ifdef IGL_STATIC_LIBRARY
  30. // Explicit template specialization
  31. #endif