hausdorff.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 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_HAUSDORFF_H
  9. #define IGL_HAUSDORFF_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Dense>
  12. #include <functional>
  13. namespace igl
  14. {
  15. // HAUSDORFF 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. // Known issue: 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. //
  30. // Inputs:
  31. // VA #VA by 3 list of vertex positions
  32. // FA #FA by 3 list of face indices into VA
  33. // VB #VB by 3 list of vertex positions
  34. // FB #FB by 3 list of face indices into VB
  35. // Outputs:
  36. // d hausdorff distance
  37. // //pair 2 by 3 list of "determiner points" so that pair(1,:) is from A
  38. // // and pair(2,:) is from B
  39. //
  40. template <
  41. typename DerivedVA,
  42. typename DerivedFA,
  43. typename DerivedVB,
  44. typename DerivedFB,
  45. typename Scalar>
  46. IGL_INLINE void hausdorff(
  47. const Eigen::PlainObjectBase<DerivedVA> & VA,
  48. const Eigen::PlainObjectBase<DerivedFA> & FA,
  49. const Eigen::PlainObjectBase<DerivedVB> & VB,
  50. const Eigen::PlainObjectBase<DerivedFB> & FB,
  51. Scalar & d);
  52. // Compute lower and upper bounds (l,u) on the Hausdorff distance between a triangle
  53. // (V) and a pointset (e.g., mesh, triangle soup) given by a distance function
  54. // handle (dist_to_B).
  55. //
  56. // Inputs:
  57. // V 3 by 3 list of corner positions so that V.row(i) is the position of the
  58. // ith corner
  59. // dist_to_B function taking the x,y,z coordinate of a query position and
  60. // outputing the closest-point distance to some point-set B
  61. // Outputs:
  62. // l lower bound on Hausdorff distance
  63. // u upper bound on Hausdorff distance
  64. //
  65. template <
  66. typename DerivedV,
  67. typename Scalar>
  68. IGL_INLINE void hausdorff(
  69. const Eigen::MatrixBase<DerivedV>& V,
  70. const std::function<
  71. Scalar(const Scalar &,const Scalar &, const Scalar &)> & dist_to_B,
  72. Scalar & l,
  73. Scalar & u);
  74. }
  75. #ifndef IGL_STATIC_LIBRARY
  76. # include "hausdorff.cpp"
  77. #endif
  78. #endif