Skip to content

Commit 4b3603b

Browse files
committed
Switch to rational-cpp and CCD-Query-IO
1 parent ecc480d commit 4b3603b

18 files changed

+57
-603
lines changed

CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ project(TightInclusion
6161
LANGUAGES CXX
6262
VERSION "1.0.4")
6363

64-
option(TIGHT_INCLUSION_WITH_GMP "Enable rational based predicates (for debugging)" OFF)
64+
option(TIGHT_INCLUSION_WITH_RATIONAL "Enable rational based predicates (for debugging)" OFF)
6565
option(TIGHT_INCLUSION_WITH_TIMER "Enable profiling timers (for debugging)" OFF)
6666
option(TIGHT_INCLUSION_WITH_DOUBLE_PRECISION "Enable double precision floating point numbers as input" ON)
6767
option(TIGHT_INCLUSION_LIMIT_QUEUE_SIZE "Enable limitation of maximal queue size" OFF)
@@ -129,10 +129,10 @@ target_link_libraries(tight_inclusion PUBLIC Eigen3::Eigen)
129129
include(spdlog)
130130
target_link_libraries(tight_inclusion PUBLIC spdlog::spdlog)
131131

132-
# GMP (optional)
133-
if(TIGHT_INCLUSION_WITH_GMP)
134-
find_package(GMP REQUIRED)
135-
target_link_libraries(tight_inclusion PUBLIC gmp::gmp)
132+
# rational-cpp (optional)
133+
if(TIGHT_INCLUSION_WITH_RATIONAL)
134+
include(rational_cpp)
135+
target_link_libraries(tight_inclusion PUBLIC rational::rational)
136136
endif()
137137

138138
# Extra warnings (link last for highest priority)

TightInclusionOptions.cmake.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# IPC Toolkit Options
2929
################################################################################
3030

31-
# option(TIGHT_INCLUSION_WITH_GMP "Enable rational based predicates (for debugging)" OFF)
31+
# option(TIGHT_INCLUSION_WITH_RATIONAL "Enable rational based predicates (for debugging)" OFF)
3232
# option(TIGHT_INCLUSION_WITH_TIMER "Enable profiling timers (for debugging)" OFF)
3333
# option(TIGHT_INCLUSION_WITH_DOUBLE_PRECISION "Enable double precision floating point numbers as input" ON)
3434
# option(TIGHT_INCLUSION_LIMIT_QUEUE_SIZE "Enable limitation of maximal queue size" OFF)

app/CMakeLists.txt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,8 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/config.hpp.in" "${CMAKE_CURRENT_SOUR
1212

1313
# Link to the required libraries
1414
if(TIGHT_INCLUSION_WITH_SAMPLE_QUERIES)
15-
if(NOT TIGHT_INCLUSION_WITH_GMP)
16-
find_package(GMP REQUIRED)
17-
target_link_libraries(Tight_Inclusion_bin PUBLIC gmp::gmp)
18-
endif()
19-
target_sources(Tight_Inclusion_bin PUBLIC "read_rational_csv.cpp")
20-
21-
include(sample_queries)
22-
target_link_libraries(Tight_Inclusion_bin PUBLIC tight_inclusion::sample_queries)
15+
include(ccd_query_io)
16+
target_link_libraries(Tight_Inclusion_bin PUBLIC ccd_io::ccd_io)
2317
endif()
2418

2519
include(pbar)

app/main.cpp

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
#include <tight_inclusion/config.hpp>
77

88
#ifdef TIGHT_INCLUSION_WITH_SAMPLE_QUERIES
9-
#include <tight_inclusion/rational/ccd.hpp>
10-
#include "read_rational_csv.hpp"
9+
#include <ccd_io/read_ccd_queries.hpp>
1110
#endif
1211

1312
#include <pbar.hpp>
@@ -21,7 +20,7 @@ using namespace ticcd;
2120

2221
#ifdef TIGHT_INCLUSION_WITH_SAMPLE_QUERIES
2322

24-
static const std::string root_path(TIGHT_INCLUSION_SAMPLE_QUERIES_DIR);
23+
static const std::string root_path(CCD_IO_SAMPLE_QUERIES_DIR);
2524

2625
static const std::vector<std::string> simulation_folders = {{
2726
"chain",
@@ -52,6 +51,8 @@ void check_sample_queries(
5251
const long max_itr,
5352
const bool print_progress = true)
5453
{
54+
using Matrix8x3 = Eigen::Matrix<double, 8, 3, Eigen::RowMajor>;
55+
5556
const Eigen::Array3d err(-1, -1, -1);
5657
constexpr double t_max = 1;
5758
constexpr bool no_zero_toi = false;
@@ -76,11 +77,12 @@ void check_sample_queries(
7677
for (const std::string &folder : folders) {
7778
fs::path dir = fs::path(root_path) / folder / sub_folder;
7879
for (const auto &csv : fs::directory_iterator(dir)) {
79-
std::vector<bool> _;
80-
const Eigen::MatrixXd all_V =
81-
rational::read_rational_csv(csv.path().string(), _);
82-
assert(all_V.rows() % 8 == 0);
83-
total_number_of_queries += all_V.rows() / 8;
80+
std::ifstream in_stream(csv.path().string());
81+
unsigned int line_count = std::count_if(
82+
std::istreambuf_iterator<char>{in_stream}, {},
83+
[](char c) { return c == '\n'; });
84+
assert(line_count % 8 == 0);
85+
total_number_of_queries += line_count / 8;
8486
}
8587
}
8688
logger().trace("Total number of queries: {}", total_number_of_queries);
@@ -94,21 +96,12 @@ void check_sample_queries(
9496
fs::path dir = fs::path(root_path) / folder / sub_folder;
9597
for (const auto &csv : fs::directory_iterator(dir)) {
9698

97-
std::vector<bool> results;
98-
const Eigen::MatrixXd all_V =
99-
rational::read_rational_csv(csv.path().string(), results);
100-
101-
if (all_V.rows() % 8 != 0 || all_V.cols() != 3) {
102-
logger().error(
103-
"Incorrectly formatted data in file \"{}\": vertices should be of shape (8n)×3 where n is the number of queries! Got {}×{} instead.",
104-
csv.path().string(), all_V.rows(), all_V.cols());
105-
assert(false);
106-
continue;
107-
}
99+
const std::vector<ccd_io::CCDQuery> queries =
100+
ccd_io::read_ccd_queries(csv.path().string());
108101

109-
for (int i = 0; i < all_V.rows(); i += 8) {
110-
const Eigen::Matrix<double, 8, 3> V = all_V.middleRows<8>(i);
111-
const bool expected_result = results[i];
102+
for (int i = 0; i < queries.size(); i++) {
103+
Eigen::Map<const Matrix8x3> V(&queries[i].vertices[0][0]);
104+
const bool expected_result = queries[i].ground_truth;
112105
total_positives += expected_result;
113106

114107
// Output of CCD
@@ -149,7 +142,7 @@ void check_sample_queries(
149142

150143
logger().error(
151144
"False negative encountered in file \"{}\" (query #{})!",
152-
csv.path().string(), i / 8);
145+
csv.path().string(), i);
153146
for (int j = 0; j < 8; j++) {
154147
logger().debug(
155148
"V{}: {:.17f} {:.17f} {:.17f}", //

app/read_rational_csv.cpp

Lines changed: 0 additions & 153 deletions
This file was deleted.

app/read_rational_csv.hpp

Lines changed: 0 additions & 14 deletions
This file was deleted.

cmake/find/FindGMP.cmake

Lines changed: 0 additions & 79 deletions
This file was deleted.

cmake/recipes/ccd_query_io.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
if(TARGET ccd_io::ccd_io)
2+
return()
3+
endif()
4+
5+
message(STATUS "Third-party: creating target 'ccd_io::ccd_io'")
6+
7+
set(CCD_IO_DOWNLOAD_SAMPLE_QUERIES ON CACHE BOOL "Download sample CCD queries" FORCE)
8+
set(CCD_IO_SAMPLE_QUERIES_DIR "${PROJECT_SOURCE_DIR}/sample-queries/" CACHE PATH "Where should we download sample queries?")
9+
10+
include(CPM)
11+
CPMAddPackage("gh:Continuous-Collision-Detection/CCD-Query-IO#efca80cda21d95d74a1477ed22d42db8aabb5835")

0 commit comments

Comments
 (0)