hausdorff.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 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_HAUSDORFF_H
  9. #define IGL_HAUSDORFF_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Dense>
  12. #include <functional>
  13. namespace igl
  14. {
  15. /// Compute the Hausdorff distance between mesh (VA,FA) and mesh
  16. /// (VB,FB). This is the
  17. ///
  18. /// d(A,B) = max ( max min d(a,b) , max min d(b,a) )
  19. /// a∈A b∈B b∈B a∈A
  20. ///
  21. /// \bug This is only computing max(min(va,B),min(vb,A)). This is
  22. /// better than max(min(va,Vb),min(vb,Va)). This (at least) is missing
  23. /// "edge-edge" cases like the distance between the two different
  24. /// triangulations of a non-planar quad in 3D. Even simpler, consider the
  25. /// Hausdorff distance between the non-convex, block letter V polygon (with 7
  26. /// vertices) in 2D and its convex hull. The Hausdorff distance is defined by
  27. /// the midpoint in the middle of the segment across the concavity and some
  28. /// non-vertex point _on the edge_ of the V.
  29. /// Known issue: due to the issue above, this also means that unreferenced
  30. /// vertices can give unexpected results. Therefore, we assume the inputs have
  31. /// no unreferenced vertices.
  32. ///
  33. /// @param[in] VA #VA by 3 list of vertex positions
  34. /// @param[in] FA #FA by 3 list of face indices into VA
  35. /// @param[in] VB #VB by 3 list of vertex positions
  36. /// @param[in] FB #FB by 3 list of face indices into VB
  37. /// @param[out] d hausdorff distance
  38. template <
  39. typename DerivedVA,
  40. typename DerivedFA,
  41. typename DerivedVB,
  42. typename DerivedFB,
  43. typename Scalar>
  44. IGL_INLINE void hausdorff(
  45. const Eigen::MatrixBase<DerivedVA> & VA,
  46. const Eigen::MatrixBase<DerivedFA> & FA,
  47. const Eigen::MatrixBase<DerivedVB> & VB,
  48. const Eigen::MatrixBase<DerivedFB> & FB,
  49. Scalar & d);
  50. /// Compute lower and upper bounds (l,u) on the Hausdorff distance between a triangle
  51. /// (V) and a pointset (e.g., mesh, triangle soup) given by a distance function
  52. /// handle (dist_to_B).
  53. ///
  54. /// @param[in] V #V by 3 list of corner positions so that V.row(i) is the position of the
  55. /// ith corner
  56. /// @param[in] dist_to_B function taking the x,y,z coordinate of a query position and
  57. /// outputting the closest-point distance to some point-set B
  58. /// @param[out] l lower bound on Hausdorff distance
  59. /// @param[out] u upper bound on Hausdorff distance
  60. ///
  61. template <
  62. typename DerivedV,
  63. typename Scalar>
  64. IGL_INLINE void hausdorff(
  65. const Eigen::MatrixBase<DerivedV>& V,
  66. const std::function<
  67. Scalar(const Scalar &,const Scalar &, const Scalar &)> & dist_to_B,
  68. Scalar & l,
  69. Scalar & u);
  70. }
  71. #ifndef IGL_STATIC_LIBRARY
  72. # include "hausdorff.cpp"
  73. #endif
  74. #endif