hausdorff.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. // 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. // Inputs:
  34. // VA #VA by 3 list of vertex positions
  35. // FA #FA by 3 list of face indices into VA
  36. // VB #VB by 3 list of vertex positions
  37. // FB #FB by 3 list of face indices into VB
  38. // Outputs:
  39. // d hausdorff distance
  40. // //pair 2 by 3 list of "determiner points" so that pair(1,:) is from A
  41. // // and pair(2,:) is from B
  42. //
  43. template <
  44. typename DerivedVA,
  45. typename DerivedFA,
  46. typename DerivedVB,
  47. typename DerivedFB,
  48. typename Scalar>
  49. IGL_INLINE void hausdorff(
  50. const Eigen::PlainObjectBase<DerivedVA> & VA,
  51. const Eigen::PlainObjectBase<DerivedFA> & FA,
  52. const Eigen::PlainObjectBase<DerivedVB> & VB,
  53. const Eigen::PlainObjectBase<DerivedFB> & FB,
  54. Scalar & d);
  55. // Compute lower and upper bounds (l,u) on the Hausdorff distance between a triangle
  56. // (V) and a pointset (e.g., mesh, triangle soup) given by a distance function
  57. // handle (dist_to_B).
  58. //
  59. // Inputs:
  60. // V 3 by 3 list of corner positions so that V.row(i) is the position of the
  61. // ith corner
  62. // dist_to_B function taking the x,y,z coordinate of a query position and
  63. // outputting the closest-point distance to some point-set B
  64. // Outputs:
  65. // l lower bound on Hausdorff distance
  66. // u upper bound on Hausdorff distance
  67. //
  68. template <
  69. typename DerivedV,
  70. typename Scalar>
  71. IGL_INLINE void hausdorff(
  72. const Eigen::MatrixBase<DerivedV>& V,
  73. const std::function<
  74. Scalar(const Scalar &,const Scalar &, const Scalar &)> & dist_to_B,
  75. Scalar & l,
  76. Scalar & u);
  77. }
  78. #ifndef IGL_STATIC_LIBRARY
  79. # include "hausdorff.cpp"
  80. #endif
  81. #endif