diff --git a/Optimal_bounding_box/benchmarks/Optimal_bounding_box/bench_custom.cpp b/Optimal_bounding_box/benchmarks/Optimal_bounding_box/bench_custom.cpp index f1bfa006914..56cc644fd72 100644 --- a/Optimal_bounding_box/benchmarks/Optimal_bounding_box/bench_custom.cpp +++ b/Optimal_bounding_box/benchmarks/Optimal_bounding_box/bench_custom.cpp @@ -1,31 +1,32 @@ #include -#include -#include -#include -#include -#include +#include + +#include +#include #include #include -//#define OBB_DEBUG_BENCHMARK +#include +#include +#include + +//#define CGAL_OPTIMAL_BOUNDING_BOX_DEBUG_BENCHMARK typedef CGAL::Exact_predicates_inexact_constructions_kernel K; -void -bench(const char* fname) +void bench(const char* fname) { std::vector sm_points, obb_points; std::ifstream in(fname); K::Point_3 p; int i = 0; - while(in >> p){ - + while(in >> p) + { if(i % 2 == 0) // avoid normals - { sm_points.push_back(p); - } + ++i; } @@ -40,22 +41,19 @@ bench(const char* fname) std::cout << "done" << '\n'; -#ifdef OBB_DEBUG_BENCHMARK +#ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG_BENCHMARK std::cout.precision(17); for(int i =0; i < obb_points.size(); i++) - { std::cout << obb_points[i] << std::endl; - } CGAL::Surface_mesh mesh; - CGAL::make_hexahedron(obb_points[0], obb_points[1], obb_points[2], obb_points[3], obb_points[4], obb_points[5], - obb_points[6], obb_points[7], mesh); + CGAL::make_hexahedron(obb_points[0], obb_points[1], obb_points[2], obb_points[3], + obb_points[4], obb_points[5], obb_points[6], obb_points[7], mesh); std::ofstream out("/tmp/result_obb.off"); out << mesh; out.close(); #endif - } int main(int argc, char* argv[]) diff --git a/Optimal_bounding_box/benchmarks/Optimal_bounding_box/bench_fitness_function.cpp b/Optimal_bounding_box/benchmarks/Optimal_bounding_box/bench_fitness_function.cpp index 2b70a2610c9..15414eaee48 100644 --- a/Optimal_bounding_box/benchmarks/Optimal_bounding_box/bench_fitness_function.cpp +++ b/Optimal_bounding_box/benchmarks/Optimal_bounding_box/bench_fitness_function.cpp @@ -1,28 +1,32 @@ #include + +#include + +#include #include #include #include -#include + #include -#include #include + #include +#include typedef CGAL::Exact_predicates_inexact_constructions_kernel K; - int main() { - const char* fname = "data/elephant.off"; // 1) import a lot a mesh and subdivide it to create a big mesh std::ifstream input(fname); CGAL::Surface_mesh mesh; - if (!input || !(input >> mesh) || mesh.is_empty()) { + if (!input || !(input >> mesh) || mesh.is_empty()) + { std::cerr << fname << " is not a valid off file.\n"; - exit(1); + std::exit(1); } CGAL::Subdivision_method_3::CatmullClark_subdivision(mesh, @@ -40,11 +44,9 @@ int main() MatrixX3d points_mat(nb_points, 3); CGAL::Optimal_bounding_box::sm_to_matrix(mesh, points_mat); - // 3) create a population of simplices CGAL::Optimal_bounding_box::Population pop(50); - CGAL::Timer timer; timer.start(); @@ -58,7 +60,5 @@ int main() std::cout << "took " << timer.time() << " to compute the fitness of all vertices.\n"; std::cout << "value of fittest vertex= " << result << std::endl; - - return 0; } diff --git a/Optimal_bounding_box/benchmarks/Optimal_bounding_box/bench_obb.cpp b/Optimal_bounding_box/benchmarks/Optimal_bounding_box/bench_obb.cpp index ae20bc16bdb..1d12dc9c4df 100644 --- a/Optimal_bounding_box/benchmarks/Optimal_bounding_box/bench_obb.cpp +++ b/Optimal_bounding_box/benchmarks/Optimal_bounding_box/bench_obb.cpp @@ -1,21 +1,22 @@ #include + #include -#include #include + +#include #include #include -#include + +#include +#include + #include #include -#include - -//#define OBB_DEBUG_BENCHMARK - +//#define CGAL_OPTIMAL_BOUNDING_BOX_DEBUG_BENCHMARK typedef CGAL::Exact_predicates_inexact_constructions_kernel K; - bool assert_doubles(double d1, double d2, double epsilon) { return (d1 < d2 + epsilon && d1 > d2 - epsilon) ? true : false; @@ -49,10 +50,12 @@ void bench_finding_obb(std::string fname) // import a mesh CGAL::Surface_mesh mesh; - if (!input || !(input >> mesh) || mesh.is_empty()) { + if (!input || !(input >> mesh) || mesh.is_empty()) + { std::cerr << fname << " is not a valid off file.\n"; - exit(1); + std::exit(1); } + // get mesh points gather_mesh_points(mesh, sm_points); @@ -83,13 +86,12 @@ void bench_finding_obb(std::string fname) std::cout << "found obb without convex hull: " << timer.time() << " seconds\n"; timer.reset(); -#ifdef OBB_DEBUG_BENCHMARK +#ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG_BENCHMARK CGAL::Surface_mesh result_mesh1; CGAL::make_hexahedron(obb_points1[0], obb_points1[1], obb_points1[2], obb_points1[3], obb_points1[4], obb_points1[5], obb_points1[6], obb_points1[7], result_mesh1); - CGAL::Surface_mesh result_mesh2; CGAL::make_hexahedron(obb_points2[0], obb_points2[1], obb_points2[2], obb_points2[3], obb_points2[4], obb_points2[5], obb_points2[6], obb_points2[7], diff --git a/Optimal_bounding_box/benchmarks/Optimal_bounding_box/bench_perfomance.cpp b/Optimal_bounding_box/benchmarks/Optimal_bounding_box/bench_perfomance.cpp index fa1447df22c..3108af27af6 100644 --- a/Optimal_bounding_box/benchmarks/Optimal_bounding_box/bench_perfomance.cpp +++ b/Optimal_bounding_box/benchmarks/Optimal_bounding_box/bench_perfomance.cpp @@ -1,14 +1,17 @@ #include + #include -#include + #include -#include -#include +#include #include #include -//#define OBB_DEBUG_BENCHMARK +#include +#include + +//#define CGAL_OPTIMAL_BOUNDING_BOX_DEBUG_BENCHMARK typedef CGAL::Exact_predicates_inexact_constructions_kernel K; @@ -18,9 +21,10 @@ void bench_finding_obb(std::string fname) // import a mesh CGAL::Surface_mesh mesh; - if (!input || !(input >> mesh) || mesh.is_empty()) { + if (!input || !(input >> mesh) || mesh.is_empty()) + { std::cerr << fname << " is not a valid off file.\n"; - exit(1); + std::exit(1); } // export some times @@ -62,8 +66,7 @@ void bench_finding_obb(std::string fname) outt.close(); - -#ifdef OBB_DEBUG_BENCHMARK +#ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG_BENCHMARK std::ofstream out1("data/obb_result1.off"); out1 << obb_points1; out1.close(); diff --git a/Optimal_bounding_box/benchmarks/Optimal_bounding_box/readme.txt b/Optimal_bounding_box/benchmarks/Optimal_bounding_box/readme.txt index b8995463fa7..ac22f73a877 100644 --- a/Optimal_bounding_box/benchmarks/Optimal_bounding_box/readme.txt +++ b/Optimal_bounding_box/benchmarks/Optimal_bounding_box/readme.txt @@ -1,2 +1 @@ -To draw a graph with the benchmark times set the path-to-the-measurments in draw_benchmark_times.py if necessary, -and run the script with python 3. +To draw a graph with the benchmark times set the path-to-the-measurments in draw_benchmark_times.py if necessary, and run the script with python 3. diff --git a/Optimal_bounding_box/include/CGAL/Optimal_bounding_box/evolution.h b/Optimal_bounding_box/include/CGAL/Optimal_bounding_box/evolution.h index 5e0ecced2de..ee334df7e55 100644 --- a/Optimal_bounding_box/include/CGAL/Optimal_bounding_box/evolution.h +++ b/Optimal_bounding_box/include/CGAL/Optimal_bounding_box/evolution.h @@ -16,7 +16,6 @@ // $Id$ // SPDX-License-Identifier: GPL-3.0+ // -// // Author(s) : Konstantinos Katrioplas #ifndef CGAL_OPTIMAL_BOUNDING_BOX_EVOLUTION_H @@ -24,13 +23,20 @@ #include #include - #include + +#include +#include + #include -namespace CGAL { -namespace Optimal_bounding_box { +#include +#include +#include +namespace CGAL { + +namespace Optimal_bounding_box { template class Evolution @@ -40,19 +46,19 @@ class Evolution typedef typename Linear_algebra_traits::Vector3d Vector3d; public: - Evolution(Population& pop, MatrixXd& points) : - population(pop), - point_data(points) + Evolution(Population& pop, MatrixXd& points) + : population(pop), point_data(points) {} // simplex: 4 rotation matrices are its vertices - void nelder_mead(std::vector& simplex, std::size_t nelder_mead_iterations) + void nelder_mead(std::vector& simplex, + std::size_t nelder_mead_iterations) { CGAL_assertion(simplex.size() == 4); // tetrahedron std::vector fitness(4); - std::vector indices( boost::counting_iterator( 0 ), - boost::counting_iterator( simplex.size() ) ); + std::vector indices(boost::counting_iterator(0), + boost::counting_iterator(simplex.size())); for(std::size_t t = 0; t < nelder_mead_iterations; ++t) { @@ -165,12 +171,12 @@ public: for(std::size_t i = 0; i < ids4.size(); ++i) group4[i] = population[ids4[i]]; - #ifdef OBB_DEBUG +#ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG check_det(group1); check_det(group2); check_det(group3); check_det(group4); - #endif +#endif // crossover I Population offspringsA(size_first_group); @@ -185,10 +191,12 @@ public: double fitnessA = compute_fitness(group1[i][j], point_data); double fitnessB = compute_fitness(group2[i][j], point_data); double threshold; + if(fitnessA < fitnessB) threshold = 0.5 + bias; else threshold = 0.5 - bias; + if(r < threshold) // choose A offspring[j] = group1[i][j]; else // choose B @@ -197,11 +205,11 @@ public: offspringsA[i] = offspring; } - #ifdef OBB_DEBUG +#ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG std::cout << "offspringsA: \n" ; check_det(offspringsA); std::cin.get(); - #endif +#endif // crossover II Population offspringsB(size_second_group); @@ -228,10 +236,10 @@ public: offspringsB[i] = offspring; } - #ifdef OBB_DEBUG +#ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG std::cout << "offspringsB: \n" ; check_det(offspringsB); - #endif +#endif CGAL_assertion(offspringsA.size() == size_first_group); CGAL_assertion(offspringsB.size() == size_second_group); @@ -239,14 +247,10 @@ public: // next generatrion for(std::size_t i = 0; i < size_first_group; ++i) - { population[i] = offspringsA[i]; - } for(std::size_t i = 0; i < size_second_group; ++i) - { population[size_first_group + i] = offspringsB[i]; - } } void evolve(std::size_t generations) @@ -262,35 +266,35 @@ public: for(std::size_t t = 0; t < generations; ++t) { - - #ifdef OBB_DEBUG +#ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG std::cout << "generation= " << t << "\n"; - #endif +#endif genetic_algorithm(); - #ifdef OBB_DEBUG +#ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG //std::cout << "pop after genetic" << std::endl; //pop.show_population(); //std::cout << std::endl; - #endif +#endif for(std::size_t s = 0; s < population.size(); ++s) nelder_mead(population[s], nelder_mead_iterations); - #ifdef OBB_DEBUG +#ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG //std::cout << "pop after nelder mead: " << std::endl; //pop.show_population(); //std::cout << std::endl; Fitness_map fitness_map_debug(population, point_data); Matrix3d R_now = fitness_map_debug.get_best(); std::cout << "det= " << Linear_algebra_traits::determinant(R_now) << std::endl; - #endif +#endif // stopping criteria Fitness_map fitness_map(population, point_data); new_fit_value = fitness_map.get_best_fitness_value(); double difference = new_fit_value - prev_fit_value; + if(CGAL::abs(difference) < tolerance * new_fit_value) stale++; @@ -313,10 +317,10 @@ private: { Comparator(const std::vector& in) : fitness(in) {} - inline bool operator() (std::size_t& i, std::size_t& j) - { + inline bool operator() (std::size_t& i, std::size_t& j) { return fitness[i] < fitness[j]; } + const std::vector& fitness; }; @@ -325,8 +329,7 @@ private: MatrixXd point_data; }; - -#ifdef OBB_DEBUG +#ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG template void check_det(Population& pop) { @@ -341,10 +344,7 @@ void check_det(Population& pop) } #endif +} // end namespace Optimal_bounding_box +} // end namespace CGAL - -}} // end namespaces - - - -#endif +#endif // CGAL_OPTIMAL_BOUNDING_BOX_EVOLUTION_H diff --git a/Optimal_bounding_box/include/CGAL/Optimal_bounding_box/fitness_function.h b/Optimal_bounding_box/include/CGAL/Optimal_bounding_box/fitness_function.h index 5810bb1a99c..649dacb40d5 100644 --- a/Optimal_bounding_box/include/CGAL/Optimal_bounding_box/fitness_function.h +++ b/Optimal_bounding_box/include/CGAL/Optimal_bounding_box/fitness_function.h @@ -16,18 +16,19 @@ // $Id$ // SPDX-License-Identifier: GPL-3.0+ // -// // Author(s) : Konstantinos Katrioplas #ifndef CGAL_OPTIMAL_BOUNDING_FITNESS_FUNCTION_H #define CGAL_OPTIMAL_BOUNDING_FITNESS_FUNCTION_H -#include -#include #include + +#include + #include namespace CGAL { + namespace Optimal_bounding_box { template @@ -74,7 +75,8 @@ double compute_fitness(const Vertex& R, const Matrix& data) template struct Fitness_map { - Fitness_map(Population& p, Matrix& points) : pop(p), points(points) + Fitness_map(Population& p, Matrix& points) + : pop(p), points(points) {} const Vertex get_best() @@ -109,14 +111,7 @@ struct Fitness_map const Matrix& points; }; -}} // end namespaces - - - - - - -#endif //CGAL_FITNESS_FUNCTION_H - - +} // end namespace Optimal_bounding_box +} // end namespace CGAL +#endif // CGAL_OPTIMAL_BOUNDING_FITNESS_FUNCTION_H diff --git a/Optimal_bounding_box/include/CGAL/Optimal_bounding_box/helper.h b/Optimal_bounding_box/include/CGAL/Optimal_bounding_box/helper.h index febf283f5a3..d207feb93ea 100644 --- a/Optimal_bounding_box/include/CGAL/Optimal_bounding_box/helper.h +++ b/Optimal_bounding_box/include/CGAL/Optimal_bounding_box/helper.h @@ -19,18 +19,24 @@ // // Author(s) : Konstantinos Katrioplas -#ifndef CGAL_OPTIMAL_BOUNDING_HELPER_H -#define CGAL_OPTIMAL_BOUNDING_HELPER_H +#ifndef CGAL_OPTIMAL_BOUNDING_BOX_HELPER_H +#define CGAL_OPTIMAL_BOUNDING_BOX_HELPER_H -#include -#include #include + +#include +#include +#include +#include #include +#include +#include +#include namespace CGAL { -namespace Optimal_bounding_box { +namespace Optimal_bounding_box { template void fill_matrix(const std::vector& v_points, Matrix& points_mat) @@ -93,16 +99,15 @@ void matrix_to_mesh_and_draw(Matrix& data_points, std::string filename) } Mesh mesh; - CGAL::make_hexahedron(points[0], points[1], points[2], points[3], points[4], points[5], - points[6], points[7], mesh); + CGAL::make_hexahedron(points[0], points[1], points[2], points[3], + points[4], points[5], points[6], points[7], mesh); std::ofstream out(filename); out << mesh; out.close(); } -}} // end namespaces +} // end namespace Optimal_bounding_box +} // end namespace CGAL - - -#endif +#endif // CGAL_OPTIMAL_BOUNDING_BOX_HELPER_H diff --git a/Optimal_bounding_box/include/CGAL/Optimal_bounding_box/nelder_mead_functions.h b/Optimal_bounding_box/include/CGAL/Optimal_bounding_box/nelder_mead_functions.h index 06a050ffa87..d8b9763af00 100644 --- a/Optimal_bounding_box/include/CGAL/Optimal_bounding_box/nelder_mead_functions.h +++ b/Optimal_bounding_box/include/CGAL/Optimal_bounding_box/nelder_mead_functions.h @@ -16,7 +16,6 @@ // $Id$ // SPDX-License-Identifier: GPL-3.0+ // -// // Author(s) : Konstantinos Katrioplas #ifndef CGAL_OPTIMAL_BOUNDING_BOX_NEALDER_MEAD_FUNCTIONS_H @@ -25,8 +24,8 @@ #include namespace CGAL { -namespace Optimal_bounding_box { +namespace Optimal_bounding_box { template const Matrix reflection(const Matrix& S_centroid, const Matrix& S_worst) @@ -76,7 +75,7 @@ const Matrix nm_centroid(const Matrix& S1, const Matrix& S2, const Matrix& S3) return Q / det; } -}} // end namespaces - +} // end namespace Optimal_bounding_box +} // end namespace CGAL #endif diff --git a/Optimal_bounding_box/include/CGAL/Optimal_bounding_box/optimal_bounding_box.h b/Optimal_bounding_box/include/CGAL/Optimal_bounding_box/optimal_bounding_box.h index 80e294ef5c5..aaffae6d88a 100644 --- a/Optimal_bounding_box/include/CGAL/Optimal_bounding_box/optimal_bounding_box.h +++ b/Optimal_bounding_box/include/CGAL/Optimal_bounding_box/optimal_bounding_box.h @@ -25,24 +25,30 @@ #include #include #include -#include -#include + +#include #include -#include +#include #include -#include #include -#ifdef OBB_BENCHMARKS -#include +#include +#include + +#ifdef CGAL_OPTIMAL_BOUNDING_BOX_BENCHMARKS + #include #endif #if defined(CGAL_EIGEN3_ENABLED) #include #endif -namespace CGAL { -namespace Optimal_bounding_box { +#include +#include +#include +namespace CGAL { + +namespace Optimal_bounding_box { // works on matrices only /// \cond SKIP_IN_MANUAL @@ -127,21 +133,20 @@ void find_obb(const std::vector& points, CGAL::Optimal_bounding_box::fill_matrix(points, points_mat); } -#ifdef OBB_BENCHMARKS +#ifdef CGAL_OPTIMAL_BOUNDING_BOX_BENCHMARKS CGAL::Timer timer; #endif std::size_t max_generations = 100; Population pop(50); -#ifdef OBB_BENCHMARKS +#ifdef CGAL_OPTIMAL_BOUNDING_BOX_BENCHMARKS timer.start(); #endif - CGAL::Optimal_bounding_box::Evolution - search_solution(pop, points_mat); + CGAL::Optimal_bounding_box::Evolution search_solution(pop, points_mat); -#ifdef OBB_BENCHMARKS +#ifdef CGAL_OPTIMAL_BOUNDING_BOX_BENCHMARKS timer.stop(); std::cout << "constructor: " << timer.time() << std::endl; timer.reset(); @@ -150,7 +155,7 @@ void find_obb(const std::vector& points, search_solution.evolve(max_generations); -#ifdef OBB_BENCHMARKS +#ifdef CGAL_OPTIMAL_BOUNDING_BOX_BENCHMARKS timer.stop(); std::cout << "evolve: " << timer.time() << std::endl; timer.reset(); @@ -159,7 +164,7 @@ void find_obb(const std::vector& points, Matrix3d rotation = search_solution.get_best(); -#ifdef OBB_BENCHMARKS +#ifdef CGAL_OPTIMAL_BOUNDING_BOX_BENCHMARKS timer.stop(); std::cout << "get best: " << timer.time() << std::endl; #endif @@ -167,14 +172,14 @@ void find_obb(const std::vector& points, MatrixXd obb; // may be preallocated at compile time obb.resize(8, 3); -#ifdef OBB_BENCHMARKS +#ifdef CGAL_OPTIMAL_BOUNDING_BOX_BENCHMARKS timer.reset(); timer.start(); #endif post_processing(points_mat, rotation, obb); -#ifdef OBB_BENCHMARKS +#ifdef CGAL_OPTIMAL_BOUNDING_BOX_BENCHMARKS timer.stop(); std::cout << "post porcessing: " << timer.time() << std::endl; #endif @@ -242,8 +247,7 @@ void find_obb(const PolygonMesh& pmesh, find_obb(points, obb_points, la_traits, use_ch); CGAL::make_hexahedron(obb_points[0], obb_points[1], obb_points[2], obb_points[3], - obb_points[4], obb_points[5], - obb_points[6], obb_points[7], obbmesh); + obb_points[4], obb_points[5], obb_points[6], obb_points[7], obbmesh); } template @@ -261,11 +265,7 @@ void find_obb(const PolygonMesh& pmesh, find_obb(pmesh, obbmesh, la_traits, use_ch); } -}} // end namespaces - - - -#endif //CGAL_OPTIMAL_BOUNDING_BOX_OBB_H - - +} // end namespace Optimal_bounding_box +} // end namespace CGAL +#endif // CGAL_OPTIMAL_BOUNDING_BOX_OBB_H diff --git a/Optimal_bounding_box/include/CGAL/Optimal_bounding_box/population.h b/Optimal_bounding_box/include/CGAL/Optimal_bounding_box/population.h index eb8ca1aaf4e..4404acdcd3a 100644 --- a/Optimal_bounding_box/include/CGAL/Optimal_bounding_box/population.h +++ b/Optimal_bounding_box/include/CGAL/Optimal_bounding_box/population.h @@ -22,13 +22,14 @@ #ifndef CGAL_OPTIMAL_BOUNDING_BOX_POPULATION_H #define CGAL_OPTIMAL_BOUNDING_BOX_POPULATION_H -#include +#include #include +#include namespace CGAL { -namespace Optimal_bounding_box { +namespace Optimal_bounding_box { template class Population @@ -37,7 +38,8 @@ class Population typedef std::vector Simplex; public: - Population(std::size_t size) : n(size), random_generator(CGAL::Random()) + Population(std::size_t size) + : n(size), random_generator(CGAL::Random()) { // reserve pop space pop.reserve(n); @@ -52,9 +54,9 @@ public: } } - #ifdef OBB_DEBUG +#ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG void show_population(); - #endif +#endif std::size_t size(){return n;} @@ -72,7 +74,6 @@ public: } private: - // create random population void create_simplex(Simplex& simplex) { @@ -110,8 +111,7 @@ private: std::vector pop; }; - -#ifdef OBB_DEBUG +#ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG template void Population::show_population() { @@ -130,14 +130,7 @@ void Population::show_population() } #endif +} // end namespace Optimal_bounding_box +} // end namespace CGAL - -} } // end namespaces - - - - - - - -#endif //CGAL_OPTIMAL_BOUNDING_BOX_POPULATION_H +#endif // CGAL_OPTIMAL_BOUNDING_BOX_POPULATION_H diff --git a/Optimal_bounding_box/test/Optimal_bounding_box/test_linear_algebra_functions.cpp b/Optimal_bounding_box/test/Optimal_bounding_box/test_linear_algebra_functions.cpp index 0278b1cce15..5ae7753271f 100644 --- a/Optimal_bounding_box/test/Optimal_bounding_box/test_linear_algebra_functions.cpp +++ b/Optimal_bounding_box/test/Optimal_bounding_box/test_linear_algebra_functions.cpp @@ -1,9 +1,8 @@ +#include #include #include + #include -#include -#include -#include bool assert_doubles(double d1, double d2, double epsilon) { diff --git a/Optimal_bounding_box/test/Optimal_bounding_box/test_optimization_algorithms.cpp b/Optimal_bounding_box/test/Optimal_bounding_box/test_optimization_algorithms.cpp index f67dd655891..257dcd02ac5 100644 --- a/Optimal_bounding_box/test/Optimal_bounding_box/test_optimization_algorithms.cpp +++ b/Optimal_bounding_box/test/Optimal_bounding_box/test_optimization_algorithms.cpp @@ -1,14 +1,15 @@ #include + #include + +#include #include #include #include + #include #include -#include - - typedef CGAL::Exact_predicates_inexact_constructions_kernel K; bool assert_doubles(double d1, double d2, double epsilon) @@ -195,7 +196,7 @@ void test_random_unit_tetra() Point p4(0.166461, 0.149912, 0.364944); CGAL::make_tetrahedron(p1, p2, p3, p4, mesh); -#ifdef OBB_DEBUG_TEST +#ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG_TEST std::ofstream out("data/random_unit_tetra.off"); out << mesh; out.close(); @@ -221,7 +222,7 @@ void test_random_unit_tetra() CGAL_assertion(assert_doubles(R(2,1), 0.512847, epsilon)); CGAL_assertion(assert_doubles(R(2,2), 0.836992, epsilon)); -#ifdef OBB_DEBUG_TEST +#ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG_TEST // postprocessing CGAL::Eigen_dense_matrix obb(8, 3); CGAL::Optimal_bounding_box::post_processing(data_points, R, obb); @@ -235,7 +236,7 @@ void test_reference_tetrahedron(const char* fname) CGAL::Surface_mesh mesh; if (!input || !(input >> mesh) || mesh.is_empty()) { std::cerr << fname << " is not a valid off file.\n"; - exit(1); + std::exit(1); } typedef CGAL::Eigen_linear_algebra_traits Linear_algebra_traits; @@ -255,7 +256,7 @@ void test_reference_tetrahedron(const char* fname) CGAL_assertion_code(double epsilon = 1e-5); CGAL_assertion(assert_doubles(Linear_algebra_traits::determinant(R), 1, epsilon)); - #ifdef OBB_DEBUG_TEST + #ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG_TEST // postprocessing MatrixXd obb(8, 3); CGAL::Optimal_bounding_box::post_processing(points, R, obb); @@ -269,7 +270,7 @@ void test_long_tetrahedron(std::string fname) CGAL::Surface_mesh mesh; if (!input || !(input >> mesh) || mesh.is_empty()) { std::cerr << fname << " is not a valid off file.\n"; - exit(1); + std::exit(1); } typedef CGAL::Eigen_linear_algebra_traits Linear_algebra_traits; @@ -300,7 +301,7 @@ void test_long_tetrahedron(std::string fname) assert_doubles(R(1,2), -0.707106, epsilon)); CGAL_assertion(assert_doubles(R(2,2), 0.707107, epsilon)); - #ifdef OBB_DEBUG_TEST + #ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG_TEST // postprocessing MatrixXd obb(8, 3); CGAL::Optimal_bounding_box::post_processing(points, R, obb); @@ -315,7 +316,7 @@ void test_find_obb_evolution(std::string fname) SMesh mesh; if (!input || !(input >> mesh) || mesh.is_empty()) { std::cerr << fname << " is not a valid off file.\n"; - exit(1); + std::exit(1); } // get mesh points std::vector sm_points; @@ -334,7 +335,7 @@ void test_find_obb_evolution(std::string fname) CGAL_assertion_code(double vol = CGAL::Optimal_bounding_box::calculate_volume(obb_points)); CGAL_assertion(assert_doubles(vol, 0.883371, epsilon)); - #ifdef OBB_DEBUG_TEST + #ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG_TEST /* for(int i = 0; i < 8; ++i) std::cout << obb_points[i].x() << " " << obb_points[i].y() << " " << obb_points[i].z() << "\n" ; @@ -353,16 +354,17 @@ void test_find_obb_mesh(std::string fname) { std::ifstream input(fname); CGAL::Surface_mesh mesh; - if (!input || !(input >> mesh) || mesh.is_empty()) { + if (!input || !(input >> mesh) || mesh.is_empty()) + { std::cerr << fname << " is not a valid off file.\n"; - exit(1); + std::exit(1); } CGAL::Eigen_linear_algebra_traits la_traits; CGAL::Surface_mesh< K::Point_3> obbmesh; CGAL::Optimal_bounding_box::find_obb(mesh, obbmesh, la_traits, true); - #ifdef OBB_DEBUG_TEST + #ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG_TEST std::ofstream out("/tmp/result_elephant.off"); out << obbmesh; out.close(); @@ -373,16 +375,18 @@ void test_function_defaults_traits(std::string fname1, std::string fname2) { std::ifstream input1(fname1); CGAL::Surface_mesh mesh1; - if (!input1 || !(input1 >> mesh1) || mesh1.is_empty()) { + if (!input1 || !(input1 >> mesh1) || mesh1.is_empty()) + { std::cerr << fname1 << " is not a valid off file.\n"; - exit(1); + std::exit(1); } std::ifstream input2(fname2); CGAL::Surface_mesh mesh2; - if (!input2 || !(input2 >> mesh2) || mesh2.is_empty()) { + if (!input2 || !(input2 >> mesh2) || mesh2.is_empty()) + { std::cerr << fname2 << " is not a valid off file.\n"; - exit(1); + std::exit(1); } // test one @@ -391,6 +395,7 @@ void test_function_defaults_traits(std::string fname1, std::string fname2) typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; typedef typename boost::property_map::const_type PointPMap; PointPMap pmap = get(boost::vertex_point, mesh1); + BOOST_FOREACH(vertex_descriptor v, vertices(mesh1)) sm_points.push_back(get(pmap, v));