per_vertex_attribute_smoothing.cpp 1.5 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 "per_vertex_attribute_smoothing.h"
  9. #include <vector>
  10. template <typename DerivedV, typename DerivedF>
  11. IGL_INLINE void igl::per_vertex_attribute_smoothing(
  12. const Eigen::PlainObjectBase<DerivedV>& Ain,
  13. const Eigen::PlainObjectBase<DerivedF>& F,
  14. Eigen::PlainObjectBase<DerivedV> & Aout)
  15. {
  16. std::vector<double> denominator(Ain.rows(), 0);
  17. Aout = Eigen::PlainObjectBase<DerivedV>::Zero(Ain.rows(), Ain.cols());
  18. for (int i = 0; i < F.rows(); ++i) {
  19. for (int j = 0; j < 3; ++j) {
  20. int j1 = (j + 1) % 3;
  21. int j2 = (j + 2) % 3;
  22. Aout.row(F(i, j)) += Ain.row(F(i, j1)) + Ain.row(F(i, j2));
  23. denominator[F(i, j)] += 2;
  24. }
  25. }
  26. for (int i = 0; i < Ain.rows(); ++i)
  27. Aout.row(i) /= denominator[i];
  28. }
  29. #ifdef IGL_STATIC_LIBRARY
  30. template void igl::per_vertex_attribute_smoothing<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
  31. #endif