avg_edge_length.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 "avg_edge_length.h"
  9. #include <vector>
  10. template <typename DerivedV, typename DerivedF>
  11. IGL_INLINE double igl::avg_edge_length(
  12. const Eigen::MatrixBase<DerivedV>& V,
  13. const Eigen::MatrixBase<DerivedF>& F)
  14. {
  15. double avg = 0;
  16. long int count = 0;
  17. // Augh. Technically this is double counting interior edges...
  18. for (unsigned i=0;i<F.rows();++i)
  19. {
  20. for (unsigned j=0;j<F.cols();++j)
  21. {
  22. ++count;
  23. avg += (V.row(F(i,j)) - V.row(F(i,(j+1)%F.cols()))).norm();
  24. }
  25. }
  26. return avg / (double) count;
  27. }
  28. #ifdef IGL_STATIC_LIBRARY
  29. // Explicit template instantiation
  30. // generated by autoexplicit.sh
  31. template double igl::avg_edge_length<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&);
  32. template double igl::avg_edge_length<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&);
  33. // generated by autoexplicit.sh
  34. #endif