signed_distance.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #include <test_common.h>
  2. #include <igl/signed_distance.h>
  3. TEST_CASE("signed_distance: single_tet", "[igl]")
  4. {
  5. Eigen::MatrixXd V(4,3);
  6. V<<
  7. 0,0,0,
  8. 1,0,0,
  9. 0,1,0,
  10. 0,0,1;
  11. Eigen::MatrixXi F(4,3);
  12. F<<
  13. 0,1,3,
  14. 0,2,1,
  15. 0,3,2,
  16. 1,2,3;
  17. Eigen::MatrixXd P(1,3);
  18. P<<0.5,0.5,0.5;
  19. for(const igl::SignedDistanceType type :
  20. {
  21. igl::SIGNED_DISTANCE_TYPE_PSEUDONORMAL ,
  22. igl::SIGNED_DISTANCE_TYPE_WINDING_NUMBER,
  23. igl::SIGNED_DISTANCE_TYPE_DEFAULT ,
  24. igl::SIGNED_DISTANCE_TYPE_UNSIGNED ,
  25. igl::SIGNED_DISTANCE_TYPE_FAST_WINDING_NUMBER
  26. })
  27. {
  28. Eigen::VectorXd S;
  29. Eigen::VectorXi I;
  30. Eigen::MatrixXd C,N;
  31. igl::signed_distance( P,V,F,type,S,I,C,N);
  32. Eigen::VectorXd Sexact (1,1);Sexact<<sqrt(1./12.);
  33. if (type == igl::SIGNED_DISTANCE_TYPE_FAST_WINDING_NUMBER) {
  34. // loosen tolerance on fwn.
  35. test_common::assert_near(S,Sexact,1e-7);
  36. } else {
  37. test_common::assert_near(S,Sexact,1e-15);
  38. }
  39. }
  40. }
  41. TEST_CASE("signed_distance: single_triangle", "[igl]")
  42. {
  43. Eigen::MatrixXd V(3,2);
  44. V<<
  45. 0,0,
  46. 1,0,
  47. 0,1;
  48. Eigen::MatrixXi F(3,2);
  49. F<<
  50. 0,1,
  51. 1,2,
  52. 2,0;
  53. Eigen::MatrixXd P(1,2);
  54. P<<1,1;
  55. for(const igl::SignedDistanceType type :
  56. {
  57. igl::SIGNED_DISTANCE_TYPE_PSEUDONORMAL ,
  58. igl::SIGNED_DISTANCE_TYPE_WINDING_NUMBER,
  59. igl::SIGNED_DISTANCE_TYPE_DEFAULT ,
  60. igl::SIGNED_DISTANCE_TYPE_UNSIGNED
  61. })
  62. {
  63. Eigen::VectorXd S;
  64. Eigen::VectorXi I;
  65. Eigen::MatrixXd C,N;
  66. igl::signed_distance( P,V,F,type,S,I,C,N);
  67. Eigen::VectorXd Sexact (1,1);Sexact<<sqrt(2.)/2.;
  68. test_common::assert_near(S,Sexact,1e-15);
  69. }
  70. }
  71. TEST_CASE("signed_distance: dimension-templates", "[igl]")
  72. {
  73. Eigen::MatrixXd VX3(3,3);
  74. VX3<<
  75. 0,0,0,
  76. 1,0,0,
  77. 0,1,0;
  78. Eigen::MatrixXi F(1,3);
  79. F<<0,1,2;
  80. Eigen::MatrixXi E(3,2);
  81. E<<
  82. 0,1,
  83. 1,2,
  84. 2,0;
  85. Eigen::MatrixXd VX2 = VX3.leftCols(2);
  86. Eigen::MatrixX2d V2 = VX3.leftCols(2);
  87. Eigen::MatrixX3d V3 = VX3.leftCols(3);
  88. Eigen::MatrixXd PX3 = VX3;
  89. Eigen::MatrixXd PX2 = VX2;
  90. Eigen::MatrixX2d P2 = VX3.leftCols(2);
  91. Eigen::MatrixX3d P3 = VX3.leftCols(3);
  92. Eigen::VectorXd S;
  93. Eigen::VectorXi I;
  94. Eigen::MatrixXd C,N;
  95. Eigen::MatrixX2d C2,N2;
  96. Eigen::MatrixX3d C3,N3;
  97. igl::SignedDistanceType type = igl::SIGNED_DISTANCE_TYPE_DEFAULT;
  98. double lower_bound = std::numeric_limits<double>::min();
  99. double upper_bound = std::numeric_limits<double>::max();
  100. Eigen::MatrixX2i E2 = E;
  101. Eigen::MatrixX3i F3 = F;
  102. igl::signed_distance(P2,V2,E2,type,lower_bound,upper_bound,S,I,C2,N2);
  103. igl::signed_distance(P3,V3,F3,type,lower_bound,upper_bound,S,I,C3,N3);
  104. igl::signed_distance(PX2,VX2,E,type,lower_bound,upper_bound,S,I,C,N);
  105. igl::signed_distance(PX3,VX3,F,type,lower_bound,upper_bound,S,I,C,N);
  106. }