all_pairs_distances.cpp 562 B

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