Skip to content

Commit

Permalink
test_fcl_octomap_distance: run different tfs
Browse files Browse the repository at this point in the history
The test had been structured to transform the tree and mesh with the
same transform, meaning if there were bugs due to bounding volume
biases or errors that they might stay hidden. Instead, run different
TFs for the tree and mesh. Help tease out bounding volume bugs by
shrinking the extents of the random transforms. Running these changes
to the fcl octomap distance test results in the RSS octomap distance
test failing if the previous commit that fixes the RSS bouding volume
bugs is reverted. This test is cleaned up to help cover any breakage
in bounding volumes in the future.

Also improve test feedback by using floating point tests so the values
are printed when they don't match.
  • Loading branch information
C. Andy Martin authored and c-andy-martin committed Jul 16, 2020
1 parent 7d7d15f commit 9733887
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions test/test_fcl_octomap_distance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void test_octomap_bvh_rss_d_distance_rss()
#ifdef NDEBUG
octomap_distance_test_BVH<RSS<S>>(5);
#else
octomap_distance_test_BVH<RSS<S>>(1, 1.0);
octomap_distance_test_BVH<RSS<S>>(5, 1.0);
#endif
}

Expand All @@ -139,7 +139,7 @@ void test_octomap_bvh_obb_d_distance_obb()
#ifdef NDEBUG
octomap_distance_test_BVH<OBBRSS<S>>(5);
#else
octomap_distance_test_BVH<OBBRSS<S>>(1, 1.0);
octomap_distance_test_BVH<OBBRSS<S>>(5, 1.0);
#endif
}

Expand All @@ -155,7 +155,7 @@ void test_octomap_bvh_kios_d_distance_kios()
#ifdef NDEBUG
octomap_distance_test_BVH<kIOS<S>>(5);
#else
octomap_distance_test_BVH<kIOS<S>>(1, 1.0);
octomap_distance_test_BVH<kIOS<S>>(5, 1.0);
#endif
}

Expand Down Expand Up @@ -186,26 +186,32 @@ void octomap_distance_test_BVH(std::size_t n, double resolution)
std::shared_ptr<CollisionGeometry<S>> tree_ptr(tree);

aligned_vector<Transform3<S>> transforms;
S extents[] = {-10, -10, 10, 10, 10, 10};
S extents[] = {-5, -5, -5, 5, 5, 5};

test::generateRandomTransforms(extents, transforms, n);

for(std::size_t i = 0; i < n; ++i)
{
Transform3<S> tf(transforms[i]);
Transform3<S> tf1(transforms[i]);
Transform3<S> tf2(transforms[n-1-i]);

CollisionObject<S> obj1(m1_ptr, tf);
CollisionObject<S> obj2(tree_ptr, tf);
CollisionObject<S> obj1(m1_ptr, tf1);
CollisionObject<S> obj2(tree_ptr, tf2);
DefaultDistanceData<S> cdata;
DefaultDistanceData<S> cdata1b;
cdata.request.enable_nearest_points = true;
cdata1b.request.enable_nearest_points = true;
S dist1 = std::numeric_limits<S>::max();
S dist1b = std::numeric_limits<S>::max();
DefaultDistanceFunction(&obj1, &obj2, &cdata, dist1);
DefaultDistanceFunction(&obj2, &obj1, &cdata1b, dist1b);
EXPECT_NEAR(dist1, dist1b, constants<S>::eps());


std::vector<CollisionObject<S>*> boxes;
test::generateBoxesFromOctomap(boxes, *tree);
for(std::size_t j = 0; j < boxes.size(); ++j)
boxes[j]->setTransform(tf * boxes[j]->getTransform());
boxes[j]->setTransform(tf2 * boxes[j]->getTransform());

DynamicAABBTreeCollisionManager<S>* manager = new DynamicAABBTreeCollisionManager<S>();
manager->registerObjects(boxes);
Expand All @@ -219,15 +225,20 @@ void octomap_distance_test_BVH(std::size_t n, double resolution)
delete boxes[j];
delete manager;

std::cout << dist1 << " " << dist2 << std::endl;
EXPECT_TRUE(std::abs(dist1 - dist2) < 0.001);
EXPECT_NEAR(dist1, dist2, 0.001);

// Check that the nearest points are consistent with the distance
// Note that we cannot compare the result with the "boxes" approximation,
// since the problem is ill-posed (i.e. the nearest points may differ widely
// for slightly different geometries)
Vector3<S> nearestPointDistance = cdata.result.nearest_points[0] - cdata.result.nearest_points[1];
EXPECT_NEAR(nearestPointDistance.norm(), dist1, 0.001);
// Only check the nearest point distance for a non-collision.
// For a collision, the nearest points may be tangential and not equal to
// the (potentially fake) signed distance returned by the distance check.
if (dist1 > 0.0)
{
EXPECT_NEAR(nearestPointDistance.norm(), dist1, 0.001);
}
}
}

Expand Down Expand Up @@ -299,9 +310,9 @@ void octomap_distance_test(S env_scale, std::size_t env_size, bool use_mesh, boo
std::cout << cdata.result.min_distance << " " << cdata3.result.min_distance << " " << cdata2.result.min_distance << std::endl;

if(cdata.result.min_distance < 0)
EXPECT_TRUE(cdata2.result.min_distance <= 0);
EXPECT_LE(cdata2.result.min_distance, 0);
else
EXPECT_TRUE(std::abs(cdata.result.min_distance - cdata2.result.min_distance) < 1e-3);
EXPECT_NEAR(cdata.result.min_distance, cdata2.result.min_distance, 1e-3);

delete manager;
delete manager2;
Expand Down

0 comments on commit 9733887

Please sign in to comment.