point_mesh_squared_distance.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2014 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 "point_mesh_squared_distance.h"
  9. #include "AABB.h"
  10. template <
  11. typename DerivedP,
  12. typename DerivedV,
  13. typename DerivedsqrD,
  14. typename DerivedI,
  15. typename DerivedC>
  16. IGL_INLINE void igl::point_mesh_squared_distance(
  17. const Eigen::PlainObjectBase<DerivedP> & P,
  18. const Eigen::PlainObjectBase<DerivedV> & V,
  19. const Eigen::MatrixXi & Ele,
  20. Eigen::PlainObjectBase<DerivedsqrD> & sqrD,
  21. Eigen::PlainObjectBase<DerivedI> & I,
  22. Eigen::PlainObjectBase<DerivedC> & C)
  23. {
  24. using namespace std;
  25. const size_t dim = P.cols();
  26. assert((dim == 2 || dim == 3) && "P.cols() should be 2 or 3");
  27. assert(P.cols() == V.cols() && "P.cols() should equal V.cols()");
  28. switch(dim)
  29. {
  30. default:
  31. // fall-through and pray
  32. case 3:
  33. {
  34. AABB<DerivedV,3> tree;
  35. tree.init(V,Ele);
  36. return tree.squared_distance(V,Ele,P,sqrD,I,C);
  37. }
  38. case 2:
  39. {
  40. AABB<DerivedV,2> tree;
  41. tree.init(V,Ele);
  42. return tree.squared_distance(V,Ele,P,sqrD,I,C);
  43. }
  44. }
  45. }
  46. #ifdef IGL_STATIC_LIBRARY
  47. template void igl::point_mesh_squared_distance<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
  48. template void igl::point_mesh_squared_distance<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
  49. #endif