signed_distance.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. }