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
2625static 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}" , //
0 commit comments