all_pairs_distances.cpp 847 B

1234567891011121314151617181920212223242526272829303132
  1. #include "all_pairs_distances.h"
  2. #include <Eigen/Dense>
  3. template <typename Mat>
  4. IGL_INLINE void igl::all_pairs_distances(
  5. const Mat & V,
  6. const Mat & U,
  7. const bool squared,
  8. Mat & D)
  9. {
  10. // dimension should be the same
  11. assert(V.cols() == U.cols());
  12. // resize output
  13. D.resize(V.rows(),U.rows());
  14. for(int i = 0;i<V.rows();i++)
  15. {
  16. for(int j=0;j<U.rows();j++)
  17. {
  18. D(i,j) = (V.row(i)-U.row(j)).array().pow(2).sum();
  19. if(!squared)
  20. {
  21. D(i,j) = sqrt(D(i,j));
  22. }
  23. }
  24. }
  25. }
  26. #ifndef IGL_HEADER_ONLY
  27. // Explicit template specialization
  28. // generated by autoexplicit.sh
  29. template void igl::all_pairs_distances<Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::Matrix<double, -1, -1, 0, -1, -1> const&, Eigen::Matrix<double, -1, -1, 0, -1, -1> const&, bool, Eigen::Matrix<double, -1, -1, 0, -1, -1>&);
  30. #endif