From 0fef43ef0344566c87ee89bb78e3ff8b3dd4e624 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 4 May 2018 13:53:30 +0100 Subject: [PATCH] Do not do a matrix-matrix multiplication, but do N matrix-vector multiplications as we only want min and max --- .../Optimal_bounding_box/fitness_function.h | 25 ++++++++++++++++++- .../test_optimization_algorithms.cpp | 8 +++--- 2 files changed, 28 insertions(+), 5 deletions(-) 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 249ef98e069..a9592dde168 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 @@ -42,6 +42,27 @@ const double compute_fitness(const Vertex& R, const Matrix& data) CGAL_assertion(data.rows() >= 3); // rotate points + +#if 1 + double xmin, xmax, ymin, ymax, zmin, zmax; + for(int i = 0; i < data.rows(); i++){ + Eigen::Vector3d vec = data.row(i); + vec = R * vec; + if(i == 0){ + xmin = xmax = vec.coeff(0); + ymin = ymax = vec.coeff(1); + zmin = zmax = vec.coeff(2); + }else { + if(vec.coeff(0) < xmin) xmin = vec.coeff(0); + if(vec.coeff(1) < ymin) ymin = vec.coeff(1); + if(vec.coeff(2) < zmin) zmin = vec.coeff(2); + if(vec.coeff(0) > xmax) xmax = vec.coeff(0); + if(vec.coeff(1) > ymax) ymax = vec.coeff(1); + if(vec.coeff(2) > zmax) zmax = vec.coeff(2); + } + } + +#else Vertex RT = R.transpose(); Matrix rotated_data; rotated_data = data * RT; @@ -55,7 +76,9 @@ const double compute_fitness(const Vertex& R, const Matrix& data) double ymax = rotated_data.col(1).maxCoeff(); double zmin = rotated_data.col(2).minCoeff(); double zmax = rotated_data.col(2).maxCoeff(); - + +#endif + double x_dim = abs(xmax - xmin); // abs needed? double y_dim = abs(ymax - ymin); double z_dim = abs(zmax - zmin); 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 ef3a076aba5..27e05b709a7 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 @@ -362,14 +362,14 @@ bench(const char* fname) std::cout << "number of points= " << sm_points.size() << std::endl; - CGAL::Optimal_bounding_box::find_obb(sm_points, obb_points, true); + CGAL::Optimal_bounding_box::find_obb(sm_points, obb_points, false); - /* + 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], @@ -378,7 +378,7 @@ bench(const char* fname) std::ofstream out("/tmp/result_obb.off"); out << mesh; out.close(); - + */ }