point_mesh_squared_distance.h 2.9 KB

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