diff --git a/Distance_3/benchmark/Distance_3/CMakeLists.txt b/Distance_3/benchmark/Distance_3/CMakeLists.txt new file mode 100644 index 00000000000..3cc6ca18f7d --- /dev/null +++ b/Distance_3/benchmark/Distance_3/CMakeLists.txt @@ -0,0 +1,23 @@ +# Created by the script cgal_create_cmake_script +# This is the CMake script for compiling a CGAL application. + +cmake_minimum_required(VERSION 3.12...3.31) +project(Distance_3_Benchs) + +find_package(CGAL REQUIRED) + +if(MSVC) + # Turn off a VC++ warning on a potential division by zero + # in Cartesian_kernel/include/CGAL/constructions/kernel_ftC3.h + # where CGAL_assume() does not help + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4723") +endif() + +# create a target per cppfile +file( + GLOB cppfiles + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) +foreach(cppfile ${cppfiles}) + create_single_source_cgal_program("${cppfile}") +endforeach() diff --git a/Distance_3/benchmark/Distance_3/bench_compare_distance_3.cpp b/Distance_3/benchmark/Distance_3/bench_compare_distance_3.cpp new file mode 100644 index 00000000000..d7005a594ab --- /dev/null +++ b/Distance_3/benchmark/Distance_3/bench_compare_distance_3.cpp @@ -0,0 +1,297 @@ +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include +#include +#include + +// #define CGAL_USE_GTE_AS_SANITY_CHECK +#ifdef CGAL_USE_GTE_AS_SANITY_CHECK +#include +#include +#endif + +#include +#include + +struct randomint +{ + randomint() ; + int get() const { return sequence[cur]; } + int next() { + cur = (cur + 1) % 11; + return get(); + } + +private: + int sequence[11]; + int cur; +}; + +inline randomint::randomint() +{ + cur = 0; + sequence[0] = 19; + sequence[1] = 5; + sequence[2] = 17; + sequence[3] = 13; + sequence[4] = 29; + sequence[5] = 2; + sequence[6] = 23; + sequence[7] = 31; + sequence[8] = 3; + sequence[9] = 37; + sequence[10] = 11; +} + +randomint ri; + +template +struct Test +{ + typedef typename K::RT RT; + typedef typename K::FT FT; + typedef typename K::Comparison_result Comparison_result; + typedef typename K::Point_3 P; + typedef typename K::Segment_3 S; + typedef typename K::Vector_3 V; + typedef typename K::Ray_3 R; + typedef typename K::Line_3 L; + typedef typename K::Triangle_3 T; + typedef typename K::Plane_3 Pl; + typedef typename K::Tetrahedron_3 Tet; + typedef typename K::Iso_cuboid_3 Cub; + +private: + CGAL::Random& r; + double m = 0, M = 1; + +public: + Test(CGAL::Random& r) : r(r) { } + +private: + inline RT to_nt(int d) const { return RT(d); } + + P p(int x, int y, int z) + { + int w = ri.next(); + return P(to_nt(x*w), to_nt(y*w), to_nt(z*w), to_nt(w)); + } + + P random_point() const + { + return P(FT(r.get_double(m, M)), FT(r.get_double(m, M)), FT(r.get_double(m, M))); + } + + Pl pl(int a, int b, int c, int d) + { + int w = ri.next(); + return Pl(to_nt(a*w), to_nt(b*w), to_nt(c*w), to_nt(d*w)); + } + + +private: + void P_P(int N, FT d2) + { + std::cout << "Point - Point" << std::endl; + CGAL::Real_timer t; + t.start(); + for(int i=0; i(F& f){ + + }; + P_P(10000000, FT(0.1)); + P_S(1000000, FT(0.1)); + + std::cout << std::endl; + P_T(500000, FT(10)); + P_T(500000, FT(0.1)); + P_T(500000, FT(0.001)); + std::cout << std::endl; + + P_Tet(200000, FT(0.1)); + + std::cout << std::endl; + S_S(500000, FT(10)); + S_S(500000, FT(0.1)); + S_S(500000, FT(0.001)); + std::cout << std::endl; + S_L(500000, FT(0.1)); + + std::cout << std::endl; + T_T(500000, FT(10)); + T_T(500000, FT(0.1)); + T_T(500000, FT(0.001)); + std::cout << std::endl; + std::cout << std::endl; + } +}; + +int main(int argc, char** argv) +{ + std::cout.precision(17); + std::cerr.precision(17); + + std::cout << "3D Distance tests" << std::endl; + + CGAL::Random rp; + CGAL::Random r(argc==1?rp.get_seed():std::stoi(argv[1])); + std::cout << "random seed = " << r.get_seed() << std::endl; + + Test >(r).run(); + Test >(r).run(); +// Test > >(r).run(); + + // Test >(r).run(); + + Test(r).run(); + + Test(r).run(); + + std::cout << "Done!" << std::endl; + + return EXIT_SUCCESS; +} diff --git a/Distance_3/benchmark/Distance_3/bench_distance_3.cpp b/Distance_3/benchmark/Distance_3/bench_distance_3.cpp new file mode 100644 index 00000000000..641bd01f0ae --- /dev/null +++ b/Distance_3/benchmark/Distance_3/bench_distance_3.cpp @@ -0,0 +1,280 @@ +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include +#include +#include + +// #define CGAL_USE_GTE_AS_SANITY_CHECK +#ifdef CGAL_USE_GTE_AS_SANITY_CHECK +#include +#include +#endif + +#include +#include + +struct randomint +{ + randomint() ; + int get() const { return sequence[cur]; } + int next() { + cur = (cur + 1) % 11; + return get(); + } + +private: + int sequence[11]; + int cur; +}; + +inline randomint::randomint() +{ + cur = 0; + sequence[0] = 19; + sequence[1] = 5; + sequence[2] = 17; + sequence[3] = 13; + sequence[4] = 29; + sequence[5] = 2; + sequence[6] = 23; + sequence[7] = 31; + sequence[8] = 3; + sequence[9] = 37; + sequence[10] = 11; +} + +randomint ri; + +template +struct Test +{ + typedef typename K::RT RT; + typedef typename K::FT FT; + typedef typename K::Comparison_result Comparison_result; + typedef typename K::Point_3 P; + typedef typename K::Segment_3 S; + typedef typename K::Vector_3 V; + typedef typename K::Ray_3 R; + typedef typename K::Line_3 L; + typedef typename K::Triangle_3 T; + typedef typename K::Plane_3 Pl; + typedef typename K::Tetrahedron_3 Tet; + typedef typename K::Iso_cuboid_3 Cub; + +private: + CGAL::Random& r; + double m = 0, M = 1; + +public: + Test(CGAL::Random& r) : r(r) { } + +private: + inline RT to_nt(int d) const { return RT(d); } + + P p(int x, int y, int z) + { + int w = ri.next(); + return P(to_nt(x*w), to_nt(y*w), to_nt(z*w), to_nt(w)); + } + + P random_point() const + { + return P(FT(r.get_double(m, M)), FT(r.get_double(m, M)), FT(r.get_double(m, M))); + } + + Pl pl(int a, int b, int c, int d) + { + int w = ri.next(); + return Pl(to_nt(a*w), to_nt(b*w), to_nt(c*w), to_nt(d*w)); + } + + +private: + void P_P(int N) + { + std::cout << "Point - Point" << std::endl; + CGAL::Real_timer t; + t.start(); + for(int i=0; i +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include + +#include +#include + + +template +struct Test +{ + typedef typename K::RT RT; + typedef typename K::FT FT; + typedef typename K::Comparison_result Comparison_result; + typedef typename K::Point_3 P; + typedef typename K::Segment_3 S; + typedef typename K::Vector_3 V; + typedef typename K::Ray_3 R; + typedef typename K::Line_3 L; + typedef typename K::Triangle_3 T; + typedef typename K::Plane_3 Pl; + typedef typename K::Tetrahedron_3 Tet; + typedef typename K::Iso_cuboid_3 Cub; + + typedef std::vector >::iterator Iterator; + typedef CGAL::Box_intersection_d::Box_with_handle_d CBox; + + size_t nb_closed_pairs; + +public: + Test() : nb_closed_pairs(0){ } + + void close_triangles(std::vector

&points, std::vector >& triangles, FT d2){ + std::vector< CBox > boxes; + auto extend_bbox3=[&](const Iterator it, FT& d2){ + CGAL::Bbox_3 bb = points[(*it)[0]].bbox()+points[(*it)[1]].bbox()+points[(*it)[2]].bbox(); + return CGAL::Bbox_3(bb.xmin(),bb.ymin(),bb.zmin(),bb.xmax()+CGAL::to_double(d2),bb.ymax()+CGAL::to_double(d2),bb.zmax()+CGAL::to_double(d2)); + }; + + auto callback=[&](const CBox &ba, const CBox &bb){ + boost::container::small_vector &a = *(ba.handle()); + boost::container::small_vector &b = *(bb.handle()); + + std::sort(a.begin(), a.end()); + std::sort(b.begin(), b.end()); + std::vector v; + std::set_intersection(a.begin(), a.end(), b.begin(), b.end(),std::back_inserter(v)); + + if(v.size()!=0) //they have common vertices + return; + + bool comp = K().compare_squared_distance_3_object()(T(points[a[0]], points[a[1]], points[a[2]]), + T(points[b[0]], points[b[1]], points[b[2]]), + d2)!=CGAL::LARGER; + if(comp) + { + nb_closed_pairs++; + } + }; + + for(Iterator it=triangles.begin(); it!=triangles.end(); ++it) + boxes.emplace_back(extend_bbox3(it, d2), it); + + CGAL::box_self_intersection_d(boxes.begin(), boxes.end(), callback); + } + + void run(std::string filename, FT d2) + { + nb_closed_pairs=0; + std::vector

input_points; + std::vector> input_triangles; + + if (!CGAL::IO::read_polygon_soup(filename, input_points, input_triangles)) + { + std::cerr << "Cannot read " << filename << "\n"; + return; + } + CGAL::Real_timer t; + t.start(); + close_triangles(input_points, input_triangles, d2); + t.stop(); + std::cout << "#points = " << input_points.size() << " and #triangles = " << input_triangles.size() << " has " << nb_closed_pairs << " pairs at squared distance " << d2 << " in " << t.time() << " sec." << std::endl; + } +}; + +int main(int argc, char** argv) +{ + const std::string filename = argc == 1 ? CGAL::data_file_path("meshes/elephant.off") + : std::string(argv[1]); + + // const std::string out_file = argc <= 2 ? "rounded_soup.off" + // : std::string(argv[2]); + + std::cout.precision(17); + std::cerr.precision(17); + + std::cout << "3D Distance bench" << std::endl; + + std::vector input_points; + std::vector> input_triangles; + + if (!CGAL::IO::read_polygon_soup(filename, input_points, input_triangles)) + { + std::cerr << "Cannot read " << filename << "\n"; + return 1; + } + CGAL::Bbox_3 bb = CGAL::bbox_3(input_points.begin(), input_points.end()); + double max= (std::max)((std::max)(bb.xmax()-bb.xmin(),bb.ymax()-bb.ymin()),bb.zmax()-bb.zmin()); + +// Test >().run(filename); +// Test >().run(filename); +// Test > >(r).run(); + + // Test >(r).run(); + + // Test().run(filename, max*max); + // Test().run(filename, 10*max*max/input_points.size()); + Test().run(filename, 100*max/input_points.size()); + Test().run(filename, max/input_points.size()); + Test().run(filename, max/(100*input_points.size())); + + Test().run(filename, 100*max/input_points.size()); + Test().run(filename, max/input_points.size()); + Test().run(filename, max/(100*input_points.size())); + + std::cout << "Done!" << std::endl; + + return EXIT_SUCCESS; +}