point_mesh_squared_distance.h 2.8 KB

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