hausdorff.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. #include "hausdorff.h"
  9. #include "point_mesh_squared_distance.h"
  10. template <
  11. typename DerivedVA,
  12. typename DerivedFA,
  13. typename DerivedVB,
  14. typename DerivedFB,
  15. typename Scalar>
  16. IGL_INLINE void igl::hausdorff(
  17. const Eigen::PlainObjectBase<DerivedVA> & VA,
  18. const Eigen::PlainObjectBase<DerivedFA> & FA,
  19. const Eigen::PlainObjectBase<DerivedVB> & VB,
  20. const Eigen::PlainObjectBase<DerivedFB> & FB,
  21. Scalar & d)
  22. {
  23. using namespace Eigen;
  24. assert(VA.cols() == 3 && "VA should contain 3d points");
  25. assert(FA.cols() == 3 && "FA should contain triangles");
  26. assert(VB.cols() == 3 && "VB should contain 3d points");
  27. assert(FB.cols() == 3 && "FB should contain triangles");
  28. Matrix<Scalar,Dynamic,1> sqr_DBA,sqr_DAB;
  29. Matrix<typename DerivedVA::Index,Dynamic,1> I;
  30. Matrix<typename DerivedVA::Scalar,Dynamic,3> C;
  31. point_mesh_squared_distance(VB,VA,FA,sqr_DBA,I,C);
  32. point_mesh_squared_distance(VA,VB,FB,sqr_DAB,I,C);
  33. const Scalar dba = sqr_DBA.maxCoeff();
  34. const Scalar dab = sqr_DAB.maxCoeff();
  35. d = sqrt(std::max(dba,dab));
  36. }
  37. #ifdef IGL_STATIC_LIBRARY
  38. template void igl::hausdorff<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, double>(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, double&);
  39. #endif