point_mesh_squared_distance.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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_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. /// @tparam Kernal CGAL computation and construction kernel (e.g.
  23. /// CGAL::Simple_cartesian<double>)
  24. /// @param[in] P #P by 3 list of query point positions
  25. /// @param[in] V #V by 3 list of vertex positions
  26. /// @param[in] F #F by 3 list of triangle indices
  27. /// @param[out] sqrD #P list of smallest squared distances
  28. /// @param[out] I #P list of facet indices corresponding to smallest distances
  29. /// @param[out] C #P by 3 list of closest points
  30. ///
  31. /// \bug This only computes distances to triangles. So unreferenced
  32. /// vertices and degenerate triangles (segments) are ignored.
  33. template <
  34. typename Kernel,
  35. typename DerivedP,
  36. typename DerivedV,
  37. typename DerivedF,
  38. typename DerivedsqrD,
  39. typename DerivedI,
  40. typename DerivedC>
  41. IGL_INLINE void point_mesh_squared_distance(
  42. const Eigen::PlainObjectBase<DerivedP> & P,
  43. const Eigen::PlainObjectBase<DerivedV> & V,
  44. const Eigen::PlainObjectBase<DerivedF> & F,
  45. Eigen::PlainObjectBase<DerivedsqrD> & sqrD,
  46. Eigen::PlainObjectBase<DerivedI> & I,
  47. Eigen::PlainObjectBase<DerivedC> & C);
  48. /// precomputation for point_mesh_squared_distance
  49. ///
  50. /// @param[in] V #V by 3 list of vertex positions
  51. /// @param[in] F #F by 3 list of triangle indices
  52. /// @param[out] tree CGAL's AABB tree
  53. /// @param[out] T list of CGAL triangles in order of F (for determining which was found
  54. /// in computation)
  55. ///
  56. /// \fileinfo
  57. template <
  58. typename Kernel,
  59. typename DerivedV,
  60. typename DerivedF
  61. >
  62. IGL_INLINE void point_mesh_squared_distance_precompute(
  63. const Eigen::PlainObjectBase<DerivedV> & V,
  64. const Eigen::PlainObjectBase<DerivedF> & F,
  65. 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. std::vector<CGAL::Triangle_3<Kernel> > & T);
  73. /// Compute distances from a set of points P to a triangle mesh (V,F)
  74. /// using precomputed trees.
  75. ///
  76. /// @param[in] P #P by 3 list of query point positions
  77. /// @param[in] tree CGAL's AABB tree
  78. /// @param[in] T list of CGAL triangles in order of F (for determining which was found
  79. /// in computation)
  80. /// @param[out] sqrD #P list of smallest squared distances
  81. /// @param[out] I #P list of facet indices corresponding to smallest distances
  82. /// @param[out] C #P by 3 list of closest points
  83. template <
  84. typename Kernel,
  85. typename DerivedP,
  86. typename DerivedsqrD,
  87. typename DerivedI,
  88. typename DerivedC>
  89. IGL_INLINE void point_mesh_squared_distance(
  90. const Eigen::PlainObjectBase<DerivedP> & P,
  91. const CGAL::AABB_tree<
  92. CGAL::AABB_traits<Kernel,
  93. CGAL::AABB_triangle_primitive<Kernel,
  94. typename std::vector<CGAL::Triangle_3<Kernel> >::iterator
  95. >
  96. >
  97. > & tree,
  98. const std::vector<CGAL::Triangle_3<Kernel> > & T,
  99. Eigen::PlainObjectBase<DerivedsqrD> & sqrD,
  100. Eigen::PlainObjectBase<DerivedI> & I,
  101. Eigen::PlainObjectBase<DerivedC> & C);
  102. }
  103. }
  104. }
  105. #ifndef IGL_STATIC_LIBRARY
  106. # include "point_mesh_squared_distance.cpp"
  107. #endif
  108. #endif