Skip to content

Commit

Permalink
Switch to rational-cpp and CCD-Query-IO
Browse files Browse the repository at this point in the history
  • Loading branch information
zfergus committed Oct 3, 2023
1 parent ecc480d commit 4b3603b
Show file tree
Hide file tree
Showing 18 changed files with 57 additions and 603 deletions.
10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ project(TightInclusion
LANGUAGES CXX
VERSION "1.0.4")

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

# GMP (optional)
if(TIGHT_INCLUSION_WITH_GMP)
find_package(GMP REQUIRED)
target_link_libraries(tight_inclusion PUBLIC gmp::gmp)
# rational-cpp (optional)
if(TIGHT_INCLUSION_WITH_RATIONAL)
include(rational_cpp)
target_link_libraries(tight_inclusion PUBLIC rational::rational)
endif()

# Extra warnings (link last for highest priority)
Expand Down
2 changes: 1 addition & 1 deletion TightInclusionOptions.cmake.sample
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# IPC Toolkit Options
################################################################################

# option(TIGHT_INCLUSION_WITH_GMP "Enable rational based predicates (for debugging)" OFF)
# option(TIGHT_INCLUSION_WITH_RATIONAL "Enable rational based predicates (for debugging)" OFF)
# option(TIGHT_INCLUSION_WITH_TIMER "Enable profiling timers (for debugging)" OFF)
# option(TIGHT_INCLUSION_WITH_DOUBLE_PRECISION "Enable double precision floating point numbers as input" ON)
# option(TIGHT_INCLUSION_LIMIT_QUEUE_SIZE "Enable limitation of maximal queue size" OFF)
Expand Down
10 changes: 2 additions & 8 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,8 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/config.hpp.in" "${CMAKE_CURRENT_SOUR

# Link to the required libraries
if(TIGHT_INCLUSION_WITH_SAMPLE_QUERIES)
if(NOT TIGHT_INCLUSION_WITH_GMP)
find_package(GMP REQUIRED)
target_link_libraries(Tight_Inclusion_bin PUBLIC gmp::gmp)
endif()
target_sources(Tight_Inclusion_bin PUBLIC "read_rational_csv.cpp")

include(sample_queries)
target_link_libraries(Tight_Inclusion_bin PUBLIC tight_inclusion::sample_queries)
include(ccd_query_io)
target_link_libraries(Tight_Inclusion_bin PUBLIC ccd_io::ccd_io)
endif()

include(pbar)
Expand Down
39 changes: 16 additions & 23 deletions app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
#include <tight_inclusion/config.hpp>

#ifdef TIGHT_INCLUSION_WITH_SAMPLE_QUERIES
#include <tight_inclusion/rational/ccd.hpp>
#include "read_rational_csv.hpp"
#include <ccd_io/read_ccd_queries.hpp>
#endif

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

#ifdef TIGHT_INCLUSION_WITH_SAMPLE_QUERIES

static const std::string root_path(TIGHT_INCLUSION_SAMPLE_QUERIES_DIR);
static const std::string root_path(CCD_IO_SAMPLE_QUERIES_DIR);

static const std::vector<std::string> simulation_folders = {{
"chain",
Expand Down Expand Up @@ -52,6 +51,8 @@ void check_sample_queries(
const long max_itr,
const bool print_progress = true)
{
using Matrix8x3 = Eigen::Matrix<double, 8, 3, Eigen::RowMajor>;

const Eigen::Array3d err(-1, -1, -1);
constexpr double t_max = 1;
constexpr bool no_zero_toi = false;
Expand All @@ -76,11 +77,12 @@ void check_sample_queries(
for (const std::string &folder : folders) {
fs::path dir = fs::path(root_path) / folder / sub_folder;
for (const auto &csv : fs::directory_iterator(dir)) {
std::vector<bool> _;
const Eigen::MatrixXd all_V =
rational::read_rational_csv(csv.path().string(), _);
assert(all_V.rows() % 8 == 0);
total_number_of_queries += all_V.rows() / 8;
std::ifstream in_stream(csv.path().string());
unsigned int line_count = std::count_if(
std::istreambuf_iterator<char>{in_stream}, {},
[](char c) { return c == '\n'; });
assert(line_count % 8 == 0);
total_number_of_queries += line_count / 8;
}
}
logger().trace("Total number of queries: {}", total_number_of_queries);
Expand All @@ -94,21 +96,12 @@ void check_sample_queries(
fs::path dir = fs::path(root_path) / folder / sub_folder;
for (const auto &csv : fs::directory_iterator(dir)) {

std::vector<bool> results;
const Eigen::MatrixXd all_V =
rational::read_rational_csv(csv.path().string(), results);

if (all_V.rows() % 8 != 0 || all_V.cols() != 3) {
logger().error(
"Incorrectly formatted data in file \"{}\": vertices should be of shape (8n)×3 where n is the number of queries! Got {}×{} instead.",
csv.path().string(), all_V.rows(), all_V.cols());
assert(false);
continue;
}
const std::vector<ccd_io::CCDQuery> queries =
ccd_io::read_ccd_queries(csv.path().string());

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

// Output of CCD
Expand Down Expand Up @@ -149,7 +142,7 @@ void check_sample_queries(

logger().error(
"False negative encountered in file \"{}\" (query #{})!",
csv.path().string(), i / 8);
csv.path().string(), i);
for (int j = 0; j < 8; j++) {
logger().debug(
"V{}: {:.17f} {:.17f} {:.17f}", //
Expand Down
153 changes: 0 additions & 153 deletions app/read_rational_csv.cpp

This file was deleted.

14 changes: 0 additions & 14 deletions app/read_rational_csv.hpp

This file was deleted.

79 changes: 0 additions & 79 deletions cmake/find/FindGMP.cmake

This file was deleted.

11 changes: 11 additions & 0 deletions cmake/recipes/ccd_query_io.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
if(TARGET ccd_io::ccd_io)
return()
endif()

message(STATUS "Third-party: creating target 'ccd_io::ccd_io'")

set(CCD_IO_DOWNLOAD_SAMPLE_QUERIES ON CACHE BOOL "Download sample CCD queries" FORCE)
set(CCD_IO_SAMPLE_QUERIES_DIR "${PROJECT_SOURCE_DIR}/sample-queries/" CACHE PATH "Where should we download sample queries?")

include(CPM)
CPMAddPackage("gh:Continuous-Collision-Detection/CCD-Query-IO#efca80cda21d95d74a1477ed22d42db8aabb5835")
Loading

0 comments on commit 4b3603b

Please sign in to comment.