Browse Source

hausdorff distance

Former-commit-id: 9db14076510b85de4f605a40bc0d5196f3801905
Alec Jacobson 9 years ago
parent
commit
62c8f20d65
2 changed files with 88 additions and 0 deletions
  1. 37 0
      include/igl/hausdorff.cpp
  2. 51 0
      include/igl/hausdorff.h

+ 37 - 0
include/igl/hausdorff.cpp

@@ -0,0 +1,37 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+// 
+// Copyright (C) 2015 Alec Jacobson <alecjacobson@gmail.com>
+// 
+// This Source Code Form is subject to the terms of the Mozilla Public License 
+// v. 2.0. If a copy of the MPL was not distributed with this file, You can 
+// obtain one at http://mozilla.org/MPL/2.0/.
+#include "hausdorff.h"
+#include "point_mesh_squared_distance.h"
+
+template <
+  typename DerivedVA, 
+  typename DerivedFA,
+  typename DerivedVB,
+  typename DerivedFB,
+  typename Scalar>
+IGL_INLINE void igl::hausdorff(
+  const Eigen::PlainObjectBase<DerivedVA> & VA, 
+  const Eigen::PlainObjectBase<DerivedFA> & FA,
+  const Eigen::PlainObjectBase<DerivedVB> & VB, 
+  const Eigen::PlainObjectBase<DerivedFB> & FB,
+  Scalar & d)
+{
+  using namespace Eigen;
+  assert(VA.cols() == 3 && "VA should contain 3d points");
+  assert(FA.cols() == 3 && "FA should contain triangles");
+  assert(VB.cols() == 3 && "VB should contain 3d points");
+  assert(FB.cols() == 3 && "FB should contain triangles");
+  Matrix<Scalar,Dynamic,1> sqr_DBA,sqr_DAB;
+  Matrix<typename DerivedVA::Index,Dynamic,1> I;
+  Matrix<typename DerivedVA::Scalar,Dynamic,3> C;
+  point_mesh_squared_distance(VB,VA,FA,sqr_DBA,I,C);
+  point_mesh_squared_distance(VA,VB,FB,sqr_DAB,I,C);
+  const Scalar dba = sqr_DBA.maxCoeff();
+  const Scalar dab = sqr_DAB.maxCoeff();
+  d = sqrt(std::max(dba,dab));
+}

+ 51 - 0
include/igl/hausdorff.h

@@ -0,0 +1,51 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+// 
+// Copyright (C) 2015 Alec Jacobson <alecjacobson@gmail.com>
+// 
+// This Source Code Form is subject to the terms of the Mozilla Public License 
+// v. 2.0. If a copy of the MPL was not distributed with this file, You can 
+// obtain one at http://mozilla.org/MPL/2.0/.
+#ifndef IGL_HAUSDORFF_H
+#define IGL_HAUSDORFF_H
+#include "igl_inline.h"
+
+#include <Eigen/Dense>
+
+namespace igl 
+{
+  // HAUSDORFF compute the Hausdorff distance between mesh (VA,FA) and mesh
+  // (VB,FB). This is the 
+  //
+  // d(A,B) = max ( max min d(a,b) , max min d(b,a) )
+  //                a∈A b∈B          b∈B a∈A
+  //
+  // Inputs:
+  //   VA  #VA by 3 list of vertex positions
+  //   FA  #FA by 3 list of face indices into VA
+  //   VB  #VB by 3 list of vertex positions
+  //   FB  #FB by 3 list of face indices into VB
+  // Outputs:
+  //   d  hausdorff distance
+  //   pair  2 by 3 list of "determiner points" so that pair(1,:) is from A and
+  //     pair(2,:) is from B
+  //
+  template <
+    typename DerivedVA, 
+    typename DerivedFA,
+    typename DerivedVB,
+    typename DerivedFB,
+    typename Scalar>
+  IGL_INLINE void hausdorff(
+    const Eigen::PlainObjectBase<DerivedVA> & VA, 
+    const Eigen::PlainObjectBase<DerivedFA> & FA,
+    const Eigen::PlainObjectBase<DerivedVB> & VB, 
+    const Eigen::PlainObjectBase<DerivedFB> & FB,
+    Scalar & d);
+}
+
+#ifndef IGL_STATIC_LIBRARY
+#  include "hausdorff.cpp"
+#endif
+
+#endif
+