upsample.cpp 1.8 KB

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