all_pairs_distances.cpp 1.2 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 "all_pairs_distances.h"
  9. #include <Eigen/Dense>
  10. template <typename Mat>
  11. IGL_INLINE void igl::all_pairs_distances(
  12. const Mat & V,
  13. const Mat & U,
  14. const bool squared,
  15. Mat & D)
  16. {
  17. // dimension should be the same
  18. assert(V.cols() == U.cols());
  19. // resize output
  20. D.resize(V.rows(),U.rows());
  21. for(int i = 0;i<V.rows();i++)
  22. {
  23. for(int j=0;j<U.rows();j++)
  24. {
  25. D(i,j) = (V.row(i)-U.row(j)).squaredNorm();
  26. if(!squared)
  27. {
  28. D(i,j) = sqrt(D(i,j));
  29. }
  30. }
  31. }
  32. }
  33. #ifdef IGL_STATIC_LIBRARY
  34. // Explicit template specialization
  35. // generated by autoexplicit.sh
  36. 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>&);
  37. #endif