38 #define BOOST_TEST_MODULE FCL_GEOMETRIC_SHAPES
39 #include <boost/test/included/unit_test.hpp>
58 #define SET_LINE line = __LINE__
59 #define FCL_CHECK(cond) \
60 BOOST_CHECK_MESSAGE(cond, "from line " << line << ": " #cond)
61 #define FCL_CHECK_EQUAL(a, b) \
62 BOOST_CHECK_MESSAGE((a) == (b), "from line " << line << ": " #a "[" << (a) \
63 << "] != " #b "[" << (b) \
65 #define BOOST_CHECK_FALSE(p) BOOST_CHECK(!(p))
70 return os <<
"a_shape";
74 return os <<
"Box(" << 2 *
b.halfSide.transpose() <<
')';
79 template <
typename S1,
typename S2>
83 const Vec3f& contact_or_normal,
84 const Vec3f& expected_contact_or_normal,
85 bool check_opposite_normal,
FCL_REAL tol) {
86 std::cout <<
"Disagreement between " << comparison_type <<
" and expected_"
89 <<
"tf1.quaternion: " <<
tf1.getQuatRotation() << std::endl
90 <<
"tf1.translation: " <<
tf1.getTranslation().transpose()
92 <<
"tf2.quaternion: " <<
tf2.getQuatRotation() << std::endl
93 <<
"tf2.translation: " <<
tf2.getTranslation().transpose()
95 << comparison_type <<
": " << contact_or_normal.transpose()
97 <<
"expected_" << comparison_type <<
": "
98 << expected_contact_or_normal.transpose();
100 if (check_opposite_normal)
101 std::cout <<
" or " << -expected_contact_or_normal.transpose();
103 std::cout << std::endl
105 << (contact_or_normal - expected_contact_or_normal).norm()
107 <<
"tolerance: " << tol << std::endl;
110 template <
typename S1,
typename S2>
115 std::cout <<
"Disagreement between " << comparison_type <<
" and expected_"
118 <<
"tf1.quaternion: " <<
tf1.getQuatRotation() << std::endl
119 <<
"tf1.translation: " <<
tf1.getTranslation() << std::endl
120 <<
"tf2.quaternion: " <<
tf2.getQuatRotation() << std::endl
121 <<
"tf2.translation: " <<
tf2.getTranslation() << std::endl
122 <<
"depth: " << depth << std::endl
123 <<
"expected_depth: " << expected_depth << std::endl
124 <<
"difference: " << std::fabs(depth - expected_depth) << std::endl
125 <<
"tolerance: " << tol << std::endl;
128 template <
typename S1,
typename S2>
133 Vec3f* expected_normal,
bool check_opposite_normal,
135 if (expected_point) {
136 bool contact_equal =
isEqual(contact, *expected_point, tol);
140 *expected_point,
false, tol);
143 if (expected_depth) {
144 bool depth_equal = std::fabs(depth - *expected_depth) < tol;
151 if (expected_normal) {
152 bool normal_equal =
isEqual(normal, *expected_normal, tol);
154 if (!normal_equal && check_opposite_normal)
155 normal_equal =
isEqual(normal, -(*expected_normal), tol);
160 check_opposite_normal, tol);
164 template <
typename S1,
typename S2>
167 Vec3f* expected_point = NULL,
169 Vec3f* expected_normal = NULL,
170 bool check_opposite_normal =
false,
178 bool check_failed =
false;
184 check_failed = check_failed || (
collision != expect_collision);
190 check_failed = check_failed || (
collision != expect_collision);
193 BOOST_TEST_MESSAGE(
"Failure occured between " << s1 <<
" and " << s2
194 <<
" at transformations\n"
199 if (expect_collision) {
205 expected_normal, check_opposite_normal, tol);
239 Box s2(1.6, 0.6, 0.025);
243 -0.67596178682051911, 0.0668715876735793),
244 Vec3f(0.041218354748013122, 1.2022554710435607, 0.77338855025700015));
247 Quaternion3f(0.70738826916719977, 0, 0, 0.70682518110536596),
248 Vec3f(-0.29936284351096382, 0.80023864435868775, 0.71750000000000003));
257 Vec3f p2Loc(
tf1.inverse().transform(p2));
258 bool p2_in_cylinder((fabs(p2Loc[2]) <= s1.
halfLength) &&
259 (p2Loc[0] * p2Loc[0] + p2Loc[1] * p2Loc[1] <= s1.
radius));
261 bool p1_in_box = (p1Loc.array().abs() <= s2.
halfSide.array()).all();
262 std::cout <<
"p2 in cylinder = (" << p2Loc.transpose() <<
")" << std::endl;
263 std::cout <<
"p1 in box = (" << p1Loc.transpose() <<
")" << std::endl;
265 BOOST_CHECK((
res && !p2_in_cylinder && !p1_in_box) ||
266 (!
res && p2_in_cylinder && p1_in_box));
273 p2Loc =
tf1.inverse().transform(p2);
274 p2_in_cylinder = (fabs(p2Loc[2]) <= s1.
halfLength) &&
275 (p2Loc[0] * p2Loc[0] + p2Loc[1] * p2Loc[1] <= s1.
radius);
276 p1Loc =
tf2.inverse().transform(
p1);
277 p1_in_box = (p1Loc.array().abs() <= s2.
halfSide.array()).all();
279 std::cout <<
"p2 in cylinder = (" << p2Loc.transpose() <<
")" << std::endl;
280 std::cout <<
"p1 in box = (" <<
p1.transpose() <<
")" << std::endl;
282 BOOST_CHECK((
res && !p2_in_cylinder && !p1_in_box) ||
283 (!
res && p2_in_cylinder && p1_in_box));
287 Vec3f(-0.66734052046473924, 0.22219183277457269, 0.76825248755616293));
288 tf1.setQuatRotation(
Quaternion3f(0.52613359459338371, 0.32189408354839893,
289 0.70415587451837913, -0.35175580165512249));
391 return c1[2] <
c2[2];
395 Box s1(100, 100, 100);
399 std::vector<Vec3f> vertices(8);
400 vertices[0] << 1, 1, 1;
401 vertices[1] << 1, 1, -1;
402 vertices[2] << 1, -1, 1;
403 vertices[3] << 1, -1, -1;
404 vertices[4] << -1, 1, 1;
405 vertices[5] << -1, 1, -1;
406 vertices[6] << -1, -1, 1;
407 vertices[7] << -1, -1, -1;
409 for (std::size_t i = 0; i < 8; ++i) {
410 vertices[i].array() *= s2.
halfSide.array();
417 Vec3f point(0., 0., 0.);
428 for (std::size_t i = 0; i < 8; ++i) vertices[i] =
tf2.transform(vertices[i]);
436 FCL_CHECK(vertices[0][2] <= point[2] && point[2] < 0);
497 for (
int i = 0; i < numTests; ++i) {
561 rotSphere << 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0;
565 rotBox << 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0;
963 t[1] << -0.1, -20, 0;
1014 contact << -2.5, 0, 0;
1030 contact << -7.5, 0, 0;
1056 contact << 0.05, 0, 0;
1119 contact << -5, 0, 0;
1170 contact << -1.25, 0, 0;
1186 contact << -0.625, 0, 0;
1202 contact << -1.875, 0, 0;
1218 contact << 0.005, 0, 0;
1280 contact << 1.25, 0, 0;
1296 contact << -1.25, 0, 0;
1352 contact << -2.5, 0, 0;
1368 contact << -1.25, 0, 0;
1384 contact << -3.75, 0, 0;
1400 contact << 0.05, 0, 0;
1428 contact << 0, -2.5, 0;
1444 contact << 0, -1.25, 0;
1460 contact << 0, -3.75, 0;
1476 contact << 0, 0.05, 0;
1504 contact << 0, 0, -5;
1520 contact << 0, 0, -3.75;
1536 contact << 0, 0, -6.25;
1552 contact << 0, 0, 0.05;
1609 contact << 2.5, 0, 0;
1625 contact << -2.5, 0, 0;
1679 contact << 0, 2.5, 0;
1695 contact << 0, -2.5, 0;
1749 contact << 0, 0, 2.5;
1765 contact << 0, 0, -2.5;
1816 contact << -2.5, 0, 0;
1832 contact << -1.25, 0, 0;
1848 contact << -3.75, 0, 0;
1864 contact << 0.05, 0, 0;
1892 contact << 0, -2.5, 0;
1908 contact << 0, -1.25, 0;
1924 contact << 0, -3.75, 0;
1940 contact << 0, 0.05, 0;
1968 contact << 0, 0, -2.5;
1984 contact << 0, 0, -1.25;
2000 contact << 0, 0, -3.75;
2016 contact << 0, 0, 0.05;
2073 contact << 2.5, 0, 0;
2089 contact << -2.5, 0, 0;
2143 contact << 0, 2.5, 0;
2159 contact << 0, -2.5, 0;
2213 contact << 0, 0, 2.5;
2229 contact << 0, 0, -2.5;
2280 contact << -2.5, 0, -5;
2296 contact << -1.25, 0, -5;
2312 contact << -3.75, 0, -5;
2328 contact << 0.05, 0, -5;
2356 contact << 0, -2.5, -5;
2372 contact << 0, -1.25, -5;
2388 contact << 0, -3.75, -5;
2404 contact << 0, 0.05, -5;
2432 contact << 0, 0, -2.5;
2448 contact << 0, 0, -1.25;
2464 contact << 0, 0, -3.75;
2480 contact << 0, 0, 0.05;
2538 contact << 2.5, 0, -2.5;
2554 contact << -2.5, 0, -2.5;
2608 contact << 0, 2.5, -2.5;
2624 contact << 0, -2.5, -2.5;
2678 contact << 0, 0, 2.5;
2694 contact << 0, 0, -2.5;
2738 Vec3f closest_p1, closest_p2, normal;
2741 dist, closest_p1, closest_p2, normal);
2742 BOOST_CHECK(fabs(dist - 10) < 0.001);
2747 closest_p2, normal);
2748 BOOST_CHECK(fabs(dist - 0.1) < 0.001);
2753 closest_p2, normal);
2754 BOOST_CHECK(dist < 0);
2759 dist, closest_p1, closest_p2, normal);
2760 BOOST_CHECK(fabs(dist - 10) < 0.001);
2766 BOOST_CHECK(fabs(dist - 0.1) < 0.001);
2772 BOOST_CHECK(dist < 0);
2777 closest_p1, closest_p2, normal);
2779 BOOST_CHECK(fabs(dist - 10) < 0.1);
2784 closest_p1, closest_p2, normal);
2785 BOOST_CHECK(fabs(dist - 0.1) < 0.06);
2790 closest_p1, closest_p2, normal);
2791 BOOST_CHECK(dist < 0);
2795 transform, dist, closest_p1, closest_p2, normal);
2796 BOOST_CHECK(fabs(dist - 10) < 0.1);
2801 transform, dist, closest_p1, closest_p2, normal);
2802 BOOST_CHECK(fabs(dist - 0.1) < 0.1);
2807 transform, dist, closest_p1, closest_p2, normal);
2808 BOOST_CHECK(dist < 0);
2815 Vec3f closest_p1, closest_p2, normal;
2824 closest_p1, closest_p2, normal);
2825 BOOST_CHECK(dist <= 0);
2829 closest_p2, normal);
2830 BOOST_CHECK(dist <= 0);
2835 closest_p2, normal);
2836 BOOST_CHECK(fabs(dist - 0.1) < 0.001);
2841 closest_p2, normal);
2842 BOOST_CHECK(fabs(dist - 10.1) < 0.001);
2847 closest_p2, normal);
2848 BOOST_CHECK(fabs(dist - 10.2) < 0.001);
2853 closest_p1, closest_p2, normal);
2854 BOOST_CHECK(fabs(dist - 0.1 * 1.414) < 0.001);
2859 closest_p2, normal);
2860 BOOST_CHECK(fabs(dist - 0.1) < 0.001);
2865 closest_p2, normal);
2866 BOOST_CHECK(fabs(dist - 10.1) < 0.001);
2871 closest_p2, normal);
2872 BOOST_CHECK(fabs(dist - 10.1) < 0.001);
2877 closest_p1, closest_p2, normal);
2878 BOOST_CHECK(fabs(dist - 0.1 * 1.414) < 0.001);
2883 closest_p1, closest_p2, normal);
2884 BOOST_CHECK(fabs(dist - 0.1) < 0.001);
2889 dist, closest_p1, closest_p2, normal);
2890 BOOST_CHECK(fabs(dist - 5) < 0.001);
2895 closest_p1, closest_p2, normal);
2896 BOOST_CHECK(fabs(dist - 5) < 0.001);
2903 Vec3f closest_p1, closest_p2, normal;
2912 for (
int i = 0; i < N + 1; ++i) {
2917 BOOST_CHECK_CLOSE(dist, (dbox - s1.
radius - s2.
halfSide(0)), 1e-6);
2921 closest_p2, normal);
2924 closest_p1, closest_p2, normal);
2925 BOOST_CHECK_CLOSE(dist, (dbox - s1.
radius - s2.
halfSide(0)), 1e-6);
2930 closest_p1, closest_p2, normal);
2931 BOOST_CHECK(dist <= 0);
2935 closest_p2, normal);
2936 BOOST_CHECK(dist <= 0);
2941 closest_p2, normal);
2942 BOOST_CHECK(fabs(dist - 0.1) < 0.001);
2947 closest_p1, closest_p2, normal);
2948 BOOST_CHECK(fabs(dist - 0.1) < 0.05);
2953 dist, closest_p1, closest_p2, normal);
2954 BOOST_CHECK(fabs(dist - 17.5) < 0.001);
2959 closest_p1, closest_p2, normal);
2960 BOOST_CHECK(fabs(dist - 17.5) < 0.001);
2967 Vec3f closest_p1, closest_p2, normal;
2976 closest_p1, closest_p2, normal);
2977 BOOST_CHECK(dist <= 0);
2981 closest_p2, normal);
2982 BOOST_CHECK(dist <= 0);
2987 closest_p2, normal);
2988 BOOST_CHECK(fabs(dist - 0.1) < 0.001);
2993 closest_p1, closest_p2, normal);
2994 BOOST_CHECK(fabs(dist - 0.1) < 0.001);
2999 dist, closest_p1, closest_p2, normal);
3000 BOOST_CHECK(fabs(dist - 30) < 0.001);
3005 closest_p1, closest_p2, normal);
3006 BOOST_CHECK(fabs(dist - 30) < 0.001);
3013 Vec3f closest_p1, closest_p2, normal;
3022 closest_p1, closest_p2, normal);
3023 BOOST_CHECK(dist <= 0);
3027 closest_p2, normal);
3028 BOOST_CHECK(dist <= 0);
3033 closest_p2, normal);
3034 BOOST_CHECK(fabs(dist - 0.1) < 0.001);
3039 closest_p1, closest_p2, normal);
3040 BOOST_CHECK(fabs(dist - 0.1) < 0.001);
3045 dist, closest_p1, closest_p2, normal);
3046 BOOST_CHECK(fabs(dist - 30) < 1);
3051 closest_p1, closest_p2, normal);
3052 BOOST_CHECK(fabs(dist - 30) < 1);
3059 Vec3f closest_p1, closest_p2, normal;
3068 closest_p1, closest_p2, normal);
3069 BOOST_CHECK(dist <= 0);
3073 closest_p2, normal);
3074 BOOST_CHECK(dist <= 0);
3079 closest_p2, normal);
3080 BOOST_CHECK(fabs(dist - 0.1) < 0.01);
3085 closest_p1, closest_p2, normal);
3086 BOOST_CHECK(fabs(dist - 0.1) < 0.02);
3091 dist, closest_p1, closest_p2, normal);
3092 BOOST_CHECK(fabs(dist - 30) < 0.01);
3097 closest_p1, closest_p2, normal);
3098 BOOST_CHECK(fabs(dist - 30) < 0.1);
3290 s1,
tf1, s2,
tf2,
true, NULL, NULL, &normal,
false,
3303 s1,
tf1, s2,
tf2,
true, NULL, NULL, &normal,
false,
3464 normal =
transform.getRotation() * normal;
3594 t[1] << 9.9, -20, 0;
3690 t[1] << -0.1, -20, 0;
3691 t[2] << -0.1, 20, 0;
3716 Vec3f closest_p1, closest_p2, normal;
3726 dist, closest_p1, closest_p2, normal);
3727 BOOST_CHECK(fabs(dist - 10) < 0.001);
3732 closest_p2, normal);
3733 BOOST_CHECK(fabs(dist - 0.1) < 0.001);
3738 closest_p2, normal);
3739 BOOST_CHECK(dist <= 0);
3744 dist, closest_p1, closest_p2, normal);
3745 BOOST_CHECK(fabs(dist - 10) < 0.001);
3751 BOOST_CHECK(fabs(dist - 0.1) < 0.001);
3757 BOOST_CHECK(dist <= 0);
3762 closest_p1, closest_p2, normal);
3763 BOOST_CHECK(fabs(dist - 10) < 0.001);
3768 closest_p1, closest_p2, normal);
3769 BOOST_CHECK(fabs(dist - 0.1) < 0.001);
3774 closest_p1, closest_p2, normal);
3775 BOOST_CHECK(dist <= 0);
3779 transform, dist, closest_p1, closest_p2, normal);
3780 BOOST_CHECK(fabs(dist - 10) < 0.001);
3785 transform, dist, closest_p1, closest_p2, normal);
3786 BOOST_CHECK(fabs(dist - 0.1) < 0.001);
3791 transform, dist, closest_p1, closest_p2, normal);
3792 BOOST_CHECK(dist <= 0);
3799 Vec3f closest_p1, closest_p2, normal;
3808 closest_p1, closest_p2, normal);
3809 BOOST_CHECK(dist <= 0);
3813 closest_p2, normal);
3814 BOOST_CHECK(dist <= 0);
3819 closest_p2, normal);
3820 BOOST_CHECK(fabs(dist - 0.1) < 0.001);
3825 closest_p1, closest_p2, normal);
3826 BOOST_CHECK(fabs(dist - 0.1) < 0.001);
3831 dist, closest_p1, closest_p2, normal);
3832 BOOST_CHECK(fabs(dist - 5) < 0.001);
3837 closest_p1, closest_p2, normal);
3838 BOOST_CHECK(fabs(dist - 5) < 0.001);
3845 Vec3f closest_p1, closest_p2, normal;
3854 closest_p1, closest_p2, normal);
3855 BOOST_CHECK(dist <= 0);
3859 closest_p2, normal);
3860 BOOST_CHECK(dist <= 0);
3865 closest_p2, normal);
3866 BOOST_CHECK(fabs(dist - 0.1) < 0.01);
3871 closest_p1, closest_p2, normal);
3872 BOOST_CHECK(fabs(dist - 0.1) < 0.01);
3877 dist, closest_p1, closest_p2, normal);
3878 BOOST_CHECK(fabs(dist - 17.5) < 0.001);
3883 closest_p1, closest_p2, normal);
3884 BOOST_CHECK(fabs(dist - 17.5) < 0.001);
3891 Vec3f closest_p1, closest_p2, normal;
3900 closest_p1, closest_p2, normal);
3901 BOOST_CHECK(dist <= 0);
3905 closest_p2, normal);
3906 BOOST_CHECK(dist <= 0);
3911 closest_p2, normal);
3912 BOOST_CHECK(fabs(dist - 0.1) < 0.001);
3917 closest_p1, closest_p2, normal);
3918 BOOST_CHECK(fabs(dist - 0.1) < 0.001);
3923 dist, closest_p1, closest_p2, normal);
3924 BOOST_CHECK(fabs(dist - 30) < 0.001);
3929 closest_p1, closest_p2, normal);
3930 BOOST_CHECK(fabs(dist - 30) < 0.001);
3937 Vec3f closest_p1, closest_p2, normal;
3946 closest_p1, closest_p2, normal);
3947 BOOST_CHECK(dist <= 0);
3951 closest_p2, normal);
3952 BOOST_CHECK(dist <= 0);
3957 closest_p2, normal);
3958 BOOST_CHECK(fabs(dist - 0.1) < 0.001);
3963 closest_p1, closest_p2, normal);
3964 BOOST_CHECK(fabs(dist - 0.1) < 0.001);
3969 dist, closest_p1, closest_p2, normal);
3970 BOOST_CHECK(fabs(dist - 30) < 0.001);
3975 closest_p1, closest_p2, normal);
3976 BOOST_CHECK(fabs(dist - 30) < 0.001);
3980 template <
typename S1,
typename S2>
3992 Vec3f normalA, normalB;
3997 const double tol = 1e-6;
4004 BOOST_CHECK_CLOSE(distA, distB, tol);
4007 BOOST_CHECK(
isEqual(p2A, p1B, tol));
4014 BOOST_CHECK_CLOSE(distA, distB, tol);
4015 BOOST_CHECK(
isEqual(p1A, p2B, tol));
4016 BOOST_CHECK(
isEqual(p2A, p1B, tol));