point_mesh_squared_distance.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. #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. // Inputs:
  18. // P #P by 3 list of query point positions
  19. // V #V by 3 list of vertex positions
  20. // Ele #Ele by (3|2|1) list of (triangle|edge|point) indices
  21. // Outputs:
  22. // sqrD #P list of smallest squared distances
  23. // I #P list of primitive indices corresponding to smallest distances
  24. // C #P by 3 list of closest points
  25. //
  26. // Known bugs: This only computes distances to given primitivess. So
  27. // unreferenced vertices are ignored. However, degenerate primitives are
  28. // handled correctly: triangle [1 2 2] is treated as a segment [1 2], and
  29. // triangle [1 1 1] is treated as a point. So one _could_ add extra
  30. // combinatorially degenerate rows to Ele for all unreferenced vertices to
  31. // also get distances to points.
  32. template <
  33. typename DerivedP,
  34. typename DerivedV,
  35. typename DerivedsqrD,
  36. typename DerivedI,
  37. typename DerivedC>
  38. IGL_INLINE void point_mesh_squared_distance(
  39. const Eigen::PlainObjectBase<DerivedP> & P,
  40. const Eigen::PlainObjectBase<DerivedV> & V,
  41. const Eigen::MatrixXi & Ele,
  42. Eigen::PlainObjectBase<DerivedsqrD> & sqrD,
  43. Eigen::PlainObjectBase<DerivedI> & I,
  44. Eigen::PlainObjectBase<DerivedC> & C);
  45. }
  46. #ifndef IGL_STATIC_LIBRARY
  47. # include "point_mesh_squared_distance.cpp"
  48. #endif
  49. #endif