37 #define BOOST_TEST_MODULE FCL_HEIGHT_FIELDS
38 #include <boost/test/included/unit_test.hpp>
39 #include <boost/filesystem.hpp>
41 #include "fcl_resources/config.h"
57 template <
typename BV>
59 const Eigen::DenseIndex ny,
62 const FCL_REAL x_dim = 1., y_dim = 2.;
63 const MatrixXf heights = MatrixXf::Constant(ny, nx, max_altitude);
67 BOOST_CHECK(hfield.
getXDim() == x_dim);
68 BOOST_CHECK(hfield.
getYDim() == y_dim);
71 BOOST_CHECK(x_grid[0] == -x_dim / 2.);
72 BOOST_CHECK(x_grid[nx - 1] == x_dim / 2.);
75 BOOST_CHECK(y_grid[0] == y_dim / 2.);
76 BOOST_CHECK(y_grid[ny - 1] == -y_dim / 2.);
81 for (Eigen::DenseIndex i = 0; i < nx; ++i) {
82 for (Eigen::DenseIndex j = 0; j < ny; ++j) {
83 Vec3f point(x_grid[i], y_grid[j], heights(j, i));
92 BOOST_CHECK(*hfield_clone == hfield);
98 const Box equivalent_box(x_dim, y_dim, max_altitude - min_altitude);
100 Matrix3f::Identity(),
Vec3f(0., 0., (max_altitude + min_altitude) / 2.));
106 const Box box(Vec3f::Ones());
112 const FCL_REAL eps_no_collision = +0.1 * (max_altitude - min_altitude);
114 Vec3f(0., 0., max_altitude +
sphere.radius + eps_no_collision));
115 M_box.setTranslation(
116 Vec3f(0., 0., max_altitude +
box.halfSide[2] + eps_no_collision));
126 request, result_check_sphere);
131 collide(&equivalent_box, IdTransform * box_placement, &
box,
M_box, request,
139 const FCL_REAL eps_collision = -0.1 * (max_altitude - min_altitude);
141 Vec3f(0., 0., max_altitude +
sphere.radius + eps_collision));
142 M_box.setTranslation(
143 Vec3f(0., 0., max_altitude +
box.halfSide[2] + eps_collision));
154 request, result_check);
159 collide(&equivalent_box, IdTransform * box_placement, &
box,
M_box, request,
167 MatrixXf::Constant(ny, nx, max_altitude / 2.));
171 const FCL_REAL eps_no_collision = +0.1 * (max_altitude - min_altitude);
173 Vec3f(0., 0., max_altitude +
sphere.radius + eps_no_collision));
174 M_box.setTranslation(
175 Vec3f(0., 0., max_altitude +
box.halfSide[2] + eps_no_collision));
185 request, result_check_sphere);
190 collide(&equivalent_box, IdTransform * box_placement, &
box,
M_box, request,
198 const FCL_REAL eps_collision = -0.1 * (max_altitude - min_altitude);
200 Vec3f(0., 0., max_altitude +
sphere.radius + eps_collision));
201 M_box.setTranslation(
202 Vec3f(0., 0., max_altitude +
box.halfSide[2] + eps_collision));
213 request, result_check);
218 collide(&equivalent_box, IdTransform * box_placement, &
box,
M_box, request,
226 MatrixXf::Constant(ny, nx, max_altitude));
230 const FCL_REAL eps_collision = -0.1 * (max_altitude - min_altitude);
232 Vec3f(0., 0., max_altitude +
sphere.radius + eps_collision));
233 M_box.setTranslation(
234 Vec3f(0., 0., max_altitude +
box.halfSide[2] + eps_collision));
245 request, result_check);
250 collide(&equivalent_box, IdTransform * box_placement, &
box,
M_box, request,
258 const FCL_REAL max_altitude = 1., min_altitude = 0.;
260 test_constant_hfields<OBBRSS>(2, 2, min_altitude,
262 test_constant_hfields<OBBRSS>(20, 2, min_altitude, max_altitude);
263 test_constant_hfields<OBBRSS>(100, 100, min_altitude, max_altitude);
266 test_constant_hfields<AABB>(2, 2, min_altitude, max_altitude);
267 test_constant_hfields<AABB>(20, 2, min_altitude, max_altitude);
268 test_constant_hfields<AABB>(100, 100, min_altitude, max_altitude);
271 template <
typename BV>
273 const Eigen::DenseIndex ny,
276 const FCL_REAL x_dim = 1., y_dim = 2.;
277 const MatrixXf heights = MatrixXf::Constant(ny, nx, max_altitude);
282 const Box equivalent_box(x_dim, y_dim, max_altitude - min_altitude);
284 Matrix3f::Identity(),
Vec3f(0., 0., (max_altitude + min_altitude) / 2.));
290 const Box box(Vec3f::Ones());
296 const FCL_REAL eps_no_collision = +0.1 * (max_altitude - min_altitude);
298 Vec3f(0., 0., max_altitude +
sphere.radius + eps_no_collision));
299 M_box.setTranslation(
300 Vec3f(0., 0., max_altitude +
box.halfSide[2] + eps_no_collision));
310 request, result_check_sphere);
315 collide(&equivalent_box, IdTransform * box_placement, &
box,
M_box, request,
323 const FCL_REAL eps_no_collision = +0.1 * (max_altitude - min_altitude);
325 Vec3f(0., 0., max_altitude +
sphere.radius + eps_no_collision));
326 M_box.setTranslation(
327 Vec3f(0., 0., max_altitude +
box.halfSide[2] + eps_no_collision));
338 request, result_check_sphere);
343 collide(&equivalent_box, IdTransform * box_placement, &
box,
M_box, request,
351 const FCL_REAL eps_no_collision = -0.1 * (max_altitude - min_altitude);
353 Vec3f(0., 0., max_altitude +
sphere.radius + eps_no_collision));
354 M_box.setTranslation(
355 Vec3f(0., 0., max_altitude +
box.halfSide[2] + eps_no_collision));
365 request, result_check_sphere);
370 collide(&equivalent_box, IdTransform * box_placement, &
box,
M_box, request,
378 const FCL_REAL eps_no_collision = -0.1 * (max_altitude - min_altitude);
380 Vec3f(0., 0., max_altitude +
sphere.radius + eps_no_collision));
381 M_box.setTranslation(
382 Vec3f(0., 0., max_altitude +
box.halfSide[2] + eps_no_collision));
393 request, result_check_sphere);
398 collide(&equivalent_box, IdTransform * box_placement, &
box,
M_box, request,
406 const FCL_REAL max_altitude = 1., min_altitude = 0.;
410 test_negative_security_margin<AABB>(100, 100, min_altitude, max_altitude);
414 const Eigen::DenseIndex nx = 100, ny = 100;
418 Eigen::RowVectorXd::LinSpaced(nx, -1., 1.).replicate(ny, 1);
419 const MatrixXf Y = Eigen::VectorXd::LinSpaced(ny, 1., -1.).replicate(1, nx);
423 const Eigen::Array<bool, Eigen::Dynamic, Eigen::Dynamic> hole =
424 (
X.array().abs() < dim_square) && (
Y.array().abs() < dim_square);
427 MatrixXf::Ones(ny, nx) - hole.cast<
double>().matrix();
439 collide(&hfield, hfield_pos, &
sphere, sphere_pos, request, result);
448 const Sphere sphere2(0.51);
449 collide(&hfield, hfield_pos, &sphere2, sphere_pos, request, result);
456 const Eigen::DenseIndex nx = 100, ny = 100;
462 Eigen::RowVectorXd::LinSpaced(nx, -1., 1.).replicate(ny, 1);
463 const MatrixXf Y = Eigen::VectorXd::LinSpaced(ny, 1., -1.).replicate(1, nx);
467 const Eigen::Array<bool, Eigen::Dynamic, Eigen::Dynamic> hole =
468 (
X.array().square() +
Y.array().square() <= dim_hole);
471 MatrixXf::Ones(ny, nx) - hole.cast<
double>().matrix();
475 BOOST_CHECK(hfield.
getXGrid()[0] == -1.);
476 BOOST_CHECK(hfield.
getXGrid()[nx - 1] == +1.);
478 BOOST_CHECK(hfield.
getYGrid()[0] == +1.);
479 BOOST_CHECK(hfield.
getYGrid()[ny - 1] == -1.);
489 collide(&hfield, hfield_pos, &
sphere, sphere_pos, request, result);
498 collide(&hfield, hfield_pos, &
sphere, sphere_pos, request, result);
507 collide(&hfield, hfield_pos, &
sphere, sphere_pos, request, result);
516 collide(&hfield, hfield_pos, &
sphere, sphere_pos, request, result);