point_mesh_squared_distance.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 <
  37. typename Kernel,
  38. typename DerivedP,
  39. typename DerivedV,
  40. typename DerivedF,
  41. typename DerivedsqrD,
  42. typename DerivedI,
  43. typename DerivedC>
  44. IGL_INLINE void point_mesh_squared_distance(
  45. const Eigen::PlainObjectBase<DerivedP> & P,
  46. const Eigen::PlainObjectBase<DerivedV> & V,
  47. const Eigen::PlainObjectBase<DerivedF> & F,
  48. Eigen::PlainObjectBase<DerivedsqrD> & sqrD,
  49. Eigen::PlainObjectBase<DerivedI> & I,
  50. Eigen::PlainObjectBase<DerivedC> & C);
  51. // Probably can do this in a way that we don't pass around `tree` and `T`
  52. //
  53. // Outputs:
  54. // tree CGAL's AABB tree
  55. // T list of CGAL triangles in order of F (for determining which was found
  56. // in computation)
  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. // Inputs:
  74. // see above
  75. // Outputs:
  76. // see above
  77. template <
  78. typename Kernel,
  79. typename DerivedP,
  80. typename DerivedsqrD,
  81. typename DerivedI,
  82. typename DerivedC>
  83. IGL_INLINE void point_mesh_squared_distance(
  84. const Eigen::PlainObjectBase<DerivedP> & P,
  85. const CGAL::AABB_tree<
  86. CGAL::AABB_traits<Kernel,
  87. CGAL::AABB_triangle_primitive<Kernel,
  88. typename std::vector<CGAL::Triangle_3<Kernel> >::iterator
  89. >
  90. >
  91. > & tree,
  92. const std::vector<CGAL::Triangle_3<Kernel> > & T,
  93. Eigen::PlainObjectBase<DerivedsqrD> & sqrD,
  94. Eigen::PlainObjectBase<DerivedI> & I,
  95. Eigen::PlainObjectBase<DerivedC> & C);
  96. }
  97. }
  98. }
  99. #ifndef IGL_STATIC_LIBRARY
  100. # include "point_mesh_squared_distance.cpp"
  101. #endif
  102. #endif