point_mesh_squared_distance.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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/igl_inline.h>
  11. #include <Eigen/Core>
  12. #include <vector>
  13. #include "CGAL_includes.hpp"
  14. namespace igl
  15. {
  16. // Compute distances from a set of points P to a triangle mesh (V,F)
  17. //
  18. // Templates:
  19. // Kernal CGAL computation and construction kernel (e.g.
  20. // CGAL::Simple_cartesian<double>)
  21. // Inputs:
  22. // P #P by 3 list of query point positions
  23. // V #V by 3 list of vertex positions
  24. // F #F by 3 list of triangle indices
  25. // Outputs:
  26. // sqrD #P list of smallest squared distances
  27. // I #P list of facet indices corresponding to smallest distances
  28. // C #P by 3 list of closest points
  29. //
  30. // Known bugs: This only computes distances to triangles. So unreferenced
  31. // vertices and degenerate triangles (segments) are ignored.
  32. template <typename Kernel>
  33. IGL_INLINE void point_mesh_squared_distance(
  34. const Eigen::MatrixXd & P,
  35. const Eigen::MatrixXd & V,
  36. const Eigen::MatrixXi & F,
  37. Eigen::VectorXd & sqrD,
  38. Eigen::VectorXi & I,
  39. Eigen::MatrixXd & C);
  40. // Probably can do this in a way that we don't pass around `tree` and `T`
  41. //
  42. // Outputs:
  43. // tree CGAL's AABB tree
  44. // T list of CGAL triangles in order of F (for determining which was found
  45. // in computation)
  46. template <typename Kernel>
  47. IGL_INLINE void point_mesh_squared_distance_precompute(
  48. const Eigen::MatrixXd & V,
  49. const Eigen::MatrixXi & F,
  50. CGAL::AABB_tree<
  51. CGAL::AABB_traits<Kernel,
  52. CGAL::AABB_triangle_primitive<Kernel,
  53. typename std::vector<CGAL::Triangle_3<Kernel> >::iterator
  54. >
  55. >
  56. > & tree,
  57. std::vector<CGAL::Triangle_3<Kernel> > & T);
  58. // Inputs:
  59. // see above
  60. // Outputs:
  61. // see above
  62. template <typename Kernel>
  63. IGL_INLINE void point_mesh_squared_distance(
  64. const Eigen::MatrixXd & P,
  65. const CGAL::AABB_tree<
  66. CGAL::AABB_traits<Kernel,
  67. CGAL::AABB_triangle_primitive<Kernel,
  68. typename std::vector<CGAL::Triangle_3<Kernel> >::iterator
  69. >
  70. >
  71. > & tree,
  72. const std::vector<CGAL::Triangle_3<Kernel> > & T,
  73. Eigen::VectorXd & sqrD,
  74. Eigen::VectorXi & I,
  75. Eigen::MatrixXd & C);
  76. }
  77. #ifndef IGL_STATIC_LIBRARY
  78. # include "point_mesh_squared_distance.cpp"
  79. #endif
  80. #endif