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 new file mode 100644 index 00000000000..87b4c662a44 --- /dev/null +++ b/Optimal_bounding_box/include/CGAL/Optimal_bounding_box/fitness_function.h @@ -0,0 +1,85 @@ +// Copyright (c) 2018 GeometryFactory (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0+ +// +// +// Author(s) : Konstantinos Katrioplas + +#ifndef CGAL_FITNESS_FUNCTION_H +#define CGAL_FITNESS_FUNCTION_H + +#include +#include + + +namespace CGAL { +namespace Optimal_bounding_box { + +template +const double compute_fitness(Matrix& R, Matrix& data) +{ + + // R: rotation matrix + CGAL_assertion(R.cols() == 3); + CGAL_assertion(R.rows() == 3); + // data: points + CGAL_assertion(data.cols() == 3); + CGAL_assertion(data.rows() >= 3); + + CGAL_assertion(R.rows() == data.cols()); + + // rotate points + Matrix RT = R.transpose(); + Matrix rotated_data = data * RT; + CGAL_assertion(rotated_data.cols() == data.cols()); + CGAL_assertion(rotated_data.rows() == data.rows()); + + // AABB: take mins and maxs + double xmin = rotated_data.col(0).minCoeff(); + double xmax = rotated_data.col(0).maxCoeff(); + double ymin = rotated_data.col(1).minCoeff(); + double ymax = rotated_data.col(1).maxCoeff(); + double zmin = rotated_data.col(2).minCoeff(); + double zmax = rotated_data.col(2).maxCoeff(); + + double x_dim = abs(xmax - xmin); + double y_dim = abs(ymax - ymin); + double z_dim = abs(zmax - zmin); + + // volume + return (x_dim * y_dim * z_dim); + +} + + + + + + + + +}} // end namespaces + + + + + + +#endif //CGAL_FITNESS_FUNCTION_H + + + diff --git a/Optimal_bounding_box/include/CGAL/Optimal_bounding_box/linear_algebra.h b/Optimal_bounding_box/include/CGAL/Optimal_bounding_box/linear_algebra.h index 8570964f2f1..83be8c79885 100644 --- a/Optimal_bounding_box/include/CGAL/Optimal_bounding_box/linear_algebra.h +++ b/Optimal_bounding_box/include/CGAL/Optimal_bounding_box/linear_algebra.h @@ -38,8 +38,7 @@ void qr_factorization(EigenMatrix& A, EigenMatrix& Q) } - -}} +}} // end namespaces 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 435c8a755da..27b00e3229f 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 @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -46,6 +47,26 @@ void test_qr_factorization() } +void test_fitness_function() +{ + MatrixXf data_points(4, 3); + data_points << 0.866802, 0.740808, 0.895304, + 0.912651, 0.761565, 0.160330, + 0.093661, 0.892578, 0.737412, + 0.166461, 0.149912, 0.364944; + + MatrixXf rotation(3, 3); + rotation << -0.809204, 0.124296, 0.574230, + -0.574694, 0.035719, -0.817589, + -0.122134, -0.991602, 0.042528; + + double fitness = CGAL::Optimal_bounding_box::compute_fitness(rotation, data_points); + CGAL_assertion(assert_doubles(fitness, 0.58606, 1e-6)); + +} + + + @@ -53,6 +74,7 @@ int main() { test_qr_factorization(); + test_fitness_function(); return 0; }