hausdorff.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include <test_common.h>
  2. #include <CGAL/Simple_cartesian.h>
  3. #include <igl/copyleft/cgal/hausdorff.h>
  4. #include <igl/copyleft/cgal/point_mesh_squared_distance.h>
  5. #include <igl/upsample.h>
  6. TEST_CASE("hausdorff: knightVScheburashka", "[igl/copyleft/cgal]")
  7. {
  8. Eigen::MatrixXd VA,VB;
  9. Eigen::MatrixXi FA,FB;
  10. test_common::load_mesh("decimated-knight.obj", VA, FA);
  11. test_common::load_mesh("cheburashka.off", VB, FB);
  12. //typedef CGAL::Epeck Kernel;
  13. typedef CGAL::Simple_cartesian<double> Kernel;
  14. CGAL::AABB_tree<
  15. CGAL::AABB_traits<Kernel,
  16. CGAL::AABB_triangle_primitive<Kernel,
  17. typename std::vector<CGAL::Triangle_3<Kernel> >::iterator
  18. >
  19. >
  20. > treeB;
  21. std::vector<CGAL::Triangle_3<Kernel> > TB;
  22. {
  23. igl::copyleft::cgal::point_mesh_squared_distance_precompute(VB,FB,treeB,TB);
  24. }
  25. std::vector<Eigen::VectorXd> U(5);
  26. for(int j = 0;j<U.size();j++)
  27. {
  28. if(j>0)
  29. {
  30. igl::upsample(Eigen::MatrixXd(VA),Eigen::MatrixXi(FA),VA,FA);
  31. }
  32. const int m = FA.rows();
  33. U[j].resize(m);
  34. for(int i = 0;i<m;i++)
  35. {
  36. Eigen::MatrixXd Vi(3,3);
  37. Vi<<VA.row(FA(i,0)),VA.row(FA(i,1)),VA.row(FA(i,2));
  38. double l;
  39. igl::copyleft::cgal::hausdorff(Vi,treeB,TB,l,U[j](i));
  40. if(j>0&&i%4==3)
  41. {
  42. double u4 = std::numeric_limits<double>::infinity();
  43. for(int u = 0;u<4;u++)
  44. {
  45. u4 = std::min(u4,U[j](i-u));
  46. }
  47. REQUIRE (U[j-1](i/4) >= u4);
  48. }
  49. }
  50. break;
  51. }
  52. }