avg_edge_length.cpp 1.4 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 "edges.h"
  10. #include <vector>
  11. template <typename DerivedV, typename DerivedF>
  12. IGL_INLINE double igl::avg_edge_length(
  13. const Eigen::MatrixBase<DerivedV>& V,
  14. const Eigen::MatrixBase<DerivedF>& F)
  15. {
  16. typedef typename DerivedF::Scalar Index;
  17. Eigen::Matrix<Index, Eigen::Dynamic, 2> E;
  18. igl::edges(F, E);
  19. double avg = 0;
  20. for (unsigned i=0;i<E.rows();++i)
  21. {
  22. avg += (V.row(E(i,0)) - V.row(E(i,1))).norm();
  23. }
  24. return avg / (double) E.rows();
  25. }
  26. #ifdef IGL_STATIC_LIBRARY
  27. // Explicit template instantiation
  28. // generated by autoexplicit.sh
  29. 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&);
  30. 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&);
  31. // generated by autoexplicit.sh
  32. #endif