hausdorff.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. namespace igl
  13. {
  14. // HAUSDORFF compute lower and upper bounds on the **directed** (asymmetric)
  15. // Hausdorff distance from mesh (VA,FA) to mesh (VB,FB) within a given error
  16. // bound epsilon:
  17. //
  18. // l(A,B) ≤ max min d(a,b) ≤ u(A,B)
  19. // a∈A b∈B
  20. // u(A,B)-l(A,B) ≤ epsilon
  21. //
  22. // This is mostly an implementation of "Fast and accurate Hausdorff distance
  23. // calculation between meshes" [Guthe et al. 2005], with some ideas from
  24. // "Interactive Hausdorff Distance Computation for General Polygonal Models"
  25. // [Tang et al. 2009].
  26. //
  27. // Inputs:
  28. // VA #VA by 3 list of vertex positions
  29. // FA #FA by 3 list of face indices into VA
  30. // VB #VB by 3 list of vertex positions
  31. // FB #FB by 3 list of face indices into VB
  32. // eps desired bound on error
  33. // Outputs:
  34. // lower lower bound on directed Hausdorff distance
  35. // upper upper bound on directed Hausdorff distance
  36. template <
  37. typename DerivedVA,
  38. typename DerivedFA,
  39. typename DerivedVB,
  40. typename DerivedFB,
  41. typename Scalar>
  42. IGL_INLINE void hausdorff(
  43. const Eigen::PlainObjectBase<DerivedVA> & OVA,
  44. const Eigen::PlainObjectBase<DerivedFA> & OFA,
  45. const Eigen::PlainObjectBase<DerivedVB> & VB,
  46. const Eigen::PlainObjectBase<DerivedFB> & FB,
  47. const Scalar eps,
  48. Scalar & lower,
  49. Scalar & upper);
  50. // HAUSDORFF compute the **symmetric** Hausdorff distance between mesh
  51. // (VA,FA) and mesh (VB,FB). That is:
  52. //
  53. // d(A,B) = max ( max min d(a,b) , max min d(b,a) )
  54. // a∈A b∈B b∈B a∈A
  55. //
  56. // Note: this is an iterative method that will compute the distance within
  57. // double precision epsilon times the bounding box diagonal of the combined
  58. // meshes A and B.
  59. //
  60. // Inputs:
  61. // VA #VA by 3 list of vertex positions
  62. // FA #FA by 3 list of face indices into VA
  63. // VB #VB by 3 list of vertex positions
  64. // FB #FB by 3 list of face indices into VB
  65. // Outputs:
  66. // d hausdorff distance
  67. //
  68. template <
  69. typename DerivedVA,
  70. typename DerivedFA,
  71. typename DerivedVB,
  72. typename DerivedFB,
  73. typename Scalar>
  74. IGL_INLINE void hausdorff(
  75. const Eigen::PlainObjectBase<DerivedVA> & VA,
  76. const Eigen::PlainObjectBase<DerivedFA> & FA,
  77. const Eigen::PlainObjectBase<DerivedVB> & VB,
  78. const Eigen::PlainObjectBase<DerivedFB> & FB,
  79. Scalar & d);
  80. }
  81. #ifndef IGL_STATIC_LIBRARY
  82. # include "hausdorff.cpp"
  83. #endif
  84. #endif