upsample.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include <test_common.h>
  2. #include <igl/upsample.h>
  3. TEST_CASE("upsample: single_triangle", "[igl]")
  4. {
  5. Eigen::MatrixXi NF_groundtruth(4,3);
  6. NF_groundtruth << 0,3,5 ,1,4,3 ,3,4,5 ,4,2,5;
  7. Eigen::MatrixXd NV_groundtruth(6,2);
  8. NV_groundtruth <<0,0 ,1,0 ,0,1 ,0.5,0 ,0.5,0.5 ,0,0.5;
  9. Eigen::MatrixXd S_groundtruth(6,3);
  10. S_groundtruth<<1,0,0 ,0,1,0 ,0,0,1 ,0.5,0.5,0 ,0,0.5,0.5 ,0.5,0,0.5;
  11. Eigen::MatrixXi F(1,3);
  12. F<<0,1,2;
  13. Eigen::MatrixXd V(3,2);
  14. V<<0,0,1,0,0,1;
  15. Eigen::MatrixXi NF;
  16. Eigen::MatrixXd NV;
  17. Eigen::SparseMatrix<double> S;
  18. igl::upsample(V.rows(),F,S,NF);
  19. test_common::assert_eq(NF_groundtruth,NF);
  20. test_common::assert_eq(S_groundtruth,Eigen::MatrixXd(S));
  21. igl::upsample(V,F,NV,NF);
  22. test_common::assert_eq(NF_groundtruth,NF);
  23. test_common::assert_eq(NV_groundtruth,NV);
  24. }
  25. TEST_CASE("upsample: V_comes_first_F_ordering", "[igl]")
  26. {
  27. const auto test_case = [](const std::string &param)
  28. {
  29. Eigen::MatrixXd V,NV;
  30. Eigen::MatrixXi F,NF;
  31. // Load example mesh: GetParam() will be name of mesh file
  32. test_common::load_mesh(param, V, F);
  33. igl::upsample(V,F,NV,NF);
  34. REQUIRE (V.rows() <= NV.rows());
  35. REQUIRE (4*F.rows() == NF.rows());
  36. // V should be first part of V
  37. test_common::assert_eq(V,NV.topLeftCorner(V.rows(),V.cols()));
  38. // Expect a particular order
  39. for(int f = 0;f<F.rows();f++)
  40. {
  41. REQUIRE (NF((f*4)+0,0) == F(f,0));
  42. REQUIRE (NF((f*4)+1,0) == F(f,1));
  43. REQUIRE (NF((f*4)+3,1) == F(f,2));
  44. }
  45. };
  46. test_common::run_test_cases(test_common::manifold_meshes(), test_case);
  47. }