avg_edge_length.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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::PlainObjectBase<DerivedV>& V,
  13. const Eigen::PlainObjectBase<DerivedF>& F)
  14. {
  15. double avg = 0;
  16. long int count = 0;
  17. for (unsigned i=0;i<F.rows();++i)
  18. {
  19. for (unsigned j=0;j<F.cols();++j)
  20. {
  21. ++count;
  22. avg += (V.row(F(i,j)) - V.row(F(i,(j+1)%F.cols()))).norm();
  23. }
  24. }
  25. return avg / (double) count;
  26. }
  27. #ifdef IGL_STATIC_LIBRARY
  28. // Explicit template specialization
  29. // generated by autoexplicit.sh
  30. template double igl::avg_edge_length<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&);
  31. template double igl::avg_edge_length<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&);
  32. // generated by autoexplicit.sh
  33. #endif