point_mesh_squared_distance.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2014 Alec Jacobson <[email protected]>
  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. #ifndef IGL_POINT_MESH_SQUARED_DISTANCE_H
  9. #define IGL_POINT_MESH_SQUARED_DISTANCE_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. #include <vector>
  13. namespace igl
  14. {
  15. /// Compute distances from a set of points P to a triangle mesh (V,F)
  16. ///
  17. /// @param[in] P #P by 3 list of query point positions
  18. /// @param[in] V #V by 3 list of vertex positions
  19. /// @param[in] Ele #Ele by (3|2|1) list of (triangle|edge|point) indices
  20. /// @param[out] sqrD #P list of smallest squared distances
  21. /// @param[out] I #P list of primitive indices corresponding to smallest distances
  22. /// @param[out] C #P by 3 list of closest points
  23. ///
  24. /// \bug This only computes distances to given primitives. So
  25. /// unreferenced vertices are ignored. However, degenerate primitives are
  26. /// handled correctly: triangle [1 2 2] is treated as a segment [1 2], and
  27. /// triangle [1 1 1] is treated as a point. So one _could_ add extra
  28. /// combinatorially degenerate rows to Ele for all unreferenced vertices to
  29. /// also get distances to points.
  30. template <
  31. typename DerivedP,
  32. typename DerivedV,
  33. typename DerivedEle,
  34. typename DerivedsqrD,
  35. typename DerivedI,
  36. typename DerivedC>
  37. IGL_INLINE void point_mesh_squared_distance(
  38. const Eigen::MatrixBase<DerivedP> &P,
  39. const Eigen::MatrixBase<DerivedV> &V,
  40. const Eigen::MatrixBase<DerivedEle> &Ele,
  41. Eigen::PlainObjectBase<DerivedsqrD> &sqrD,
  42. Eigen::PlainObjectBase<DerivedI> &I,
  43. Eigen::PlainObjectBase<DerivedC> &C);
  44. }
  45. #ifndef IGL_STATIC_LIBRARY
  46. # include "point_mesh_squared_distance.cpp"
  47. #endif
  48. #endif