Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolves the error in EPA when the query point is colinear with an edge #417

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,6 @@ static bool ComputeVisiblePatchRecursiveSanityCheck(
return true;
}
#endif

/**
* This function contains the implementation detail of ComputeVisiblePatch()
* function. It should not be called by any function other than
Expand All @@ -1187,18 +1186,15 @@ static void ComputeVisiblePatchRecursive(
if (!isOutsidePolytopeFace(&polytope, g, &query_point)) {
// Cannot see the neighbouring face from the new vertex.

// TODO(hongkai.dai@tri.global): when the new vertex is colinear with a
// border edge, we should remove the degenerate triangle. We could remove
// the middle vertex on that line from the polytope, and then reconnect
// the polytope.
if (triangle_area_is_zero(query_point, f.edge[edge_index]->vertex[0]->v.v,
f.edge[edge_index]->vertex[1]->v.v)) {
FCL_THROW_FAILED_AT_THIS_CONFIGURATION(
"The new vertex is colinear with an existing edge. The added "
"triangle would be degenerate.");
// If the query point is colinear with the edge, then both neighbouring
// faces of this edge (namely face f and g) should be visible. This edge
// is an internal edge. Othewise, this edge is a border edge.
if (!triangle_area_is_zero(query_point,
f.edge[edge_index]->vertex[0]->v.v,
f.edge[edge_index]->vertex[1]->v.v)) {
border_edges->insert(f.edge[edge_index]);
return;
}
border_edges->insert(f.edge[edge_index]);
return;
}
visible_faces->insert(g);
internal_edges->insert(f.edge[edge_index]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,40 @@ GTEST_TEST(FCL_GJK_EPA, ComputeVisiblePatch_2FacesVisible) {
{0, 1}, {0});
}

void CheckComputeVisiblePatchColinearNewVertex(EquilateralTetrahedron& tet,
double rho) {
// A new vertex is colinear with an edge e[0] of the tetrahedron. The border
// edges should be e[1], e[4], e[5]. The visible faces should be f[0], f[1],
// f[3], and the internal edges should be e[0], e[2], e[3].
ccd_vec3_t query_point;
for (int i = 0; i < 3; ++i) {
query_point.v[i] = (1 + rho) * tet.v(0).v.v.v[i] - rho * tet.v(1).v.v.v[i];
}
std::unordered_set<ccd_pt_edge_t*> border_edges;
std::unordered_set<ccd_pt_face_t*> visible_faces;
std::unordered_set<ccd_pt_edge_t*> internal_edges;
libccd_extension::ComputeVisiblePatch(tet.polytope(), tet.f(3), query_point,
&border_edges, &visible_faces,
&internal_edges);

EXPECT_EQ(border_edges.size(), 3u);
EXPECT_EQ(border_edges, std::unordered_set<ccd_pt_edge_t*>(
{&(tet.e(1)), &(tet.e(4)), &(tet.e(5))}));
EXPECT_EQ(visible_faces.size(), 3u);
EXPECT_EQ(visible_faces, std::unordered_set<ccd_pt_face_t*>(
{&(tet.f(0)), &(tet.f(1)), &(tet.f(3))}));
EXPECT_EQ(internal_edges.size(), 3u);
EXPECT_EQ(internal_edges, std::unordered_set<ccd_pt_edge_t*>(
{&(tet.e(0)), &(tet.e(2)), &(tet.e(3))}));
}

GTEST_TEST(FCL_GJK_EPA, ComputeVisiblePatchColinearNewVertex) {
EquilateralTetrahedron tet1(-0.05, -0.13, 0.12);
CheckComputeVisiblePatchColinearNewVertex(tet1, 1.9);
EquilateralTetrahedron tet2(0.1, 0.2, 0.3);
CheckComputeVisiblePatchColinearNewVertex(tet2, 0.3);
}

// Tests that the sanity check causes `ComputeVisiblePatch()` to throw in
// debug builds.
GTEST_TEST(FCL_GJK_EPA, ComputeVisiblePatchSanityCheck) {
Expand Down
40 changes: 29 additions & 11 deletions test/test_fcl_signed_distance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ void test_distance_box_box_helper(const Vector3<S>& box1_size,
request.enable_signed_distance = true;
fcl::DistanceResult<S> result;

ASSERT_NO_THROW(fcl::distance(&box1, &box2, request, result));
fcl::distance(&box1, &box2, request, result);
EXPECT_NEAR(abs(result.min_distance),
(result.nearest_points[0] - result.nearest_points[1]).norm(),
request.distance_tolerance);
Expand Down Expand Up @@ -379,30 +379,47 @@ void test_distance_box_box2() {
test_distance_box_box_helper(box1_size, X_WB1, box2_size, X_WB2);
}

template <typename S>
void test_distance_box_box3() {
const Vector3<S> box1_size(0.49, 0.05, 0.21);
Transform3<S> X_WB1 = Transform3<S>::Identity();
// clang-format off
X_WB1.matrix() << 4.8966386501092529215e-12, -1,0,-0.43999999999999994671,
1, 4.8966386501092529215e-12,0,-0.61499999999858001587,
0,0,1,0.35499999999999998224,
0,0,0,1;
// clang-format on
const Vector3<S> box2_size(0.035, 0.12, 0.03);
Transform3<S> X_WB2 = Transform3<S>::Identity();
// clang-format off
X_WB2.matrix() << 0.83512153565236335595, -0.55006546945762568868, -9.4542360608233572896e-16, -0.40653441507331000704,
0.55006546945762568868, 0.83512153565236313391, 1.1787444236552387666e-15, -0.69166166923735727945,
1.2902271444330665572e-16, -1.4878153530113264589e-15, 1, 0.43057093858718892276,
0, 0, 0, 1;
// clang-format on
test_distance_box_box_helper(box1_size, X_WB1, box2_size, X_WB2);

}

//==============================================================================

GTEST_TEST(FCL_NEGATIVE_DISTANCE, sphere_sphere_ccd)
{
GTEST_TEST(FCL_NEGATIVE_DISTANCE, sphere_sphere_ccd) {
test_distance_spheresphere<double>(GST_LIBCCD);
}

GTEST_TEST(FCL_NEGATIVE_DISTANCE, sphere_sphere_indep)
{
GTEST_TEST(FCL_NEGATIVE_DISTANCE, sphere_sphere_indep) {
test_distance_spheresphere<double>(GST_INDEP);
}

GTEST_TEST(FCL_NEGATIVE_DISTANCE, sphere_capsule_ccd)
{
GTEST_TEST(FCL_NEGATIVE_DISTANCE, sphere_capsule_ccd) {
test_distance_spherecapsule<double>(GST_LIBCCD);
}

GTEST_TEST(FCL_NEGATIVE_DISTANCE, sphere_capsule_indep)
{
GTEST_TEST(FCL_NEGATIVE_DISTANCE, sphere_capsule_indep) {
test_distance_spherecapsule<double>(GST_INDEP);
}

GTEST_TEST(FCL_SIGNED_DISTANCE, cylinder_sphere1_ccd)
{
GTEST_TEST(FCL_SIGNED_DISTANCE, cylinder_sphere1_ccd) {
test_distance_cylinder_sphere1<double>();
}

Expand All @@ -413,6 +430,7 @@ GTEST_TEST(FCL_SIGNED_DISTANCE, cylinder_box_ccd) {
GTEST_TEST(FCL_SIGNED_DISTANCE, box_box1_ccd) {
test_distance_box_box1<double>();
test_distance_box_box2<double>();
test_distance_box_box3<double>();
}

//==============================================================================
Expand Down