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

Check distance when no motion in CCD #71

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
66 changes: 35 additions & 31 deletions src/ipc/ccd/ccd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@
assert(v.size() == 2 || v.size() == 3);
return v.size() == 2 ? Eigen::Vector3d(v.x(), v.y(), 0) : v.head<3>();
}

inline bool check_initial_distance(
const double initial_distance, const double min_distance, double& toi)
{
if (initial_distance > min_distance) {
return false;
}

logger().warn(
"Initial distance {} ≤ d_min={}, returning toi=0!",
initial_distance, min_distance);

toi = 0; // Initially touching

return true;
}
} // namespace

/// @brief Scale the distance tolerance to be at most this fraction of the initial distance.
Expand All @@ -49,11 +65,7 @@
const double conservative_rescaling,
double& toi)
{
if (initial_distance <= min_distance) {
logger().warn(
"Initial distance {} ≤ d_min={}, returning toi=0!",
initial_distance, min_distance);
toi = 0;
if (check_initial_distance(initial_distance, min_distance, toi)) {
return true;
}

Expand Down Expand Up @@ -111,12 +123,12 @@
{
assert(tmax >= 0 && tmax <= 1.0);

if (p0_t0 == p0_t1 && p1_t0 == p1_t1) {
return false; // No motion
}

const double initial_distance = sqrt(point_point_distance(p0_t0, p1_t0));

if (p0_t0 == p0_t1 && p1_t0 == p1_t1) { // No motion
return check_initial_distance(initial_distance, min_distance, toi);
}

const double adjusted_tolerance = std::min(
INITIAL_DISTANCE_TOLERANCE_SCALE * initial_distance, tolerance);

Expand Down Expand Up @@ -182,13 +194,13 @@
{
assert(tmax >= 0 && tmax <= 1.0);

if (p_t0 == p_t1 && e0_t0 == e0_t1 && e1_t0 == e1_t1) {
return false; // No motion
}

const double initial_distance =
sqrt(point_edge_distance(p_t0, e0_t0, e1_t0));

if (p_t0 == p_t1 && e0_t0 == e0_t1 && e1_t0 == e1_t1) { // No motion
return check_initial_distance(initial_distance, min_distance, toi);

Check warning on line 201 in src/ipc/ccd/ccd.cpp

View check run for this annotation

Codecov / codecov/patch

src/ipc/ccd/ccd.cpp#L201

Added line #L201 was not covered by tests
}

const double adjusted_tolerance = std::min(
INITIAL_DISTANCE_TOLERANCE_SCALE * initial_distance, tolerance);

Expand Down Expand Up @@ -244,15 +256,6 @@
assert(p_t1.size() == dim);
assert(e0_t0.size() == dim && e1_t0.size() == dim);
assert(e0_t1.size() == dim && e1_t1.size() == dim);

#ifndef IPC_TOOLKIT_WITH_CORRECT_CCD
if (dim == 2) {
return inexact_point_edge_ccd_2D(
p_t0, e0_t0, e1_t0, p_t1, e0_t1, e1_t1, toi,
conservative_rescaling);
}
#endif

return point_edge_ccd_3D(
to_3D(p_t0), to_3D(e0_t0), to_3D(e1_t0), to_3D(p_t1), to_3D(e0_t1),
to_3D(e1_t1), toi, min_distance, tmax, tolerance, max_iterations,
Expand All @@ -277,14 +280,14 @@
{
assert(tmax >= 0 && tmax <= 1.0);

if (ea0_t0 == ea0_t1 && ea1_t0 == ea1_t1 && eb0_t0 == eb0_t1
&& eb1_t0 == eb1_t1) {
return false; // No motion
}

const double initial_distance =
sqrt(edge_edge_distance(ea0_t0, ea1_t0, eb0_t0, eb1_t0));

if (ea0_t0 == ea0_t1 && ea1_t0 == ea1_t1 && eb0_t0 == eb0_t1
&& eb1_t0 == eb1_t1) { // No motion
return check_initial_distance(initial_distance, min_distance, toi);
}

const double adjusted_tolerance = std::min(
INITIAL_DISTANCE_TOLERANCE_SCALE * initial_distance, tolerance);

Expand Down Expand Up @@ -340,13 +343,14 @@
{
assert(tmax >= 0 && tmax <= 1.0);

if (p_t0 == p_t1 && t0_t0 == t0_t1 && t1_t0 == t1_t1 && t2_t0 == t2_t1) {
return false; // No motion
}

const double initial_distance =
sqrt(point_triangle_distance(p_t0, t0_t0, t1_t0, t2_t0));

if (p_t0 == p_t1 && t0_t0 == t0_t1 && t1_t0 == t1_t1 && t2_t0 == t2_t1) {
// No motion
return check_initial_distance(initial_distance, min_distance, toi);
}

const double adjusted_tolerance = std::min(
INITIAL_DISTANCE_TOLERANCE_SCALE * initial_distance, tolerance);

Expand Down
7 changes: 7 additions & 0 deletions src/ipc/ccd/inexact_point_edge.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//
// NOTE: This method is provided for reference comparison and is not utilized by
// the high-level functionality. In compairson to Tight Inclusion CCD, this CCD
// method is not provably conservative and so can potentially produce false
// negatives (i.e., miss collisions) due to floating-point rounding error.
//

#include "inexact_point_edge.hpp"

#include <ipc/distance/distance_type.hpp>
Expand Down
7 changes: 7 additions & 0 deletions src/ipc/ccd/inexact_point_edge.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//
// NOTE: This method is provided for reference comparison and is not utilized by
// the high-level functionality. In compairson to Tight Inclusion CCD, this CCD
// method is not provably conservative and so can potentially produce false
// negatives (i.e., miss collisions) due to floating-point rounding error.
//

#pragma once

#include <Eigen/Core>
Expand Down
39 changes: 23 additions & 16 deletions tests/src/tests/ccd/test_ccd_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,30 +256,37 @@ TEST_CASE(
// TEST_CASE("Failing Benchmark Cases", "[ccd]")
// {
// using Matrix8x3 = Eigen::Matrix<double, 8, 3, Eigen::RowMajor>;

// const static std::vector<std::string> paths;
// const static std::vector<std::vector<int>> qids;

//
// const static std::vector<std::filesystem::path> paths = { {
// tests::NEW_CCD_BENCHMARK_DIR / "n-body-simulation/queries/42ee.csv",
// } };
// const static std::vector<std::vector<int>> qids { {
// 2647,
// 2648,
// } };
//
// for (int i = 0; i < paths.size(); i++) {
// const std::vector<ccd_io::CCDQuery> queries =
// ccd_io::read_ccd_queries(
// std::string(CCD_IO_SAMPLE_QUERIES_DIR) + paths[i]);
// paths[i].string(),
// paths[i].parent_path().parent_path() / "mma_bool"
// / (paths[i].stem().string() + "_mma_bool.json"));
// for (const auto& qi : qids[i]) {
// Eigen::Map<const Matrix8x3> V(&queries[qi].vertices[0][0]);
// const bool expected_result = queries[qi].ground_truth;

//
// bool result;
// double toi;
// // if (subfolder == "edge-edge") {
// // result = edge_edge_ccd(
// // V.row(0), V.row(1), V.row(2), V.row(3), V.row(4),
// // V.row(5), V.row(6), V.row(7), toi);
// // } else {
// result = additive_ccd::point_triangle_ccd(
// V.row(0), V.row(1), V.row(2), V.row(3), V.row(4), V.row(5),
// V.row(6), V.row(7), toi);
// // }
// CHECK(result || !expected_result); // false positive is ok
// if (paths[i].stem().string().find("ee") != std::string::npos) {
// result = edge_edge_ccd(
// V.row(0), V.row(1), V.row(2), V.row(3), V.row(4),
// V.row(5), V.row(6), V.row(7), toi);
// } else {
// result = point_triangle_ccd(
// V.row(0), V.row(1), V.row(2), V.row(3), V.row(4),
// V.row(5), V.row(6), V.row(7), toi);
// }
// CHECK((result || !expected_result)); // false positive is ok
// }
// }
// }
Expand Down