fitness function

This commit is contained in:
Konstantinos Katrioplas 2018-04-20 14:48:14 +02:00
parent 5141abe2c3
commit 4f64c44c83
3 changed files with 108 additions and 2 deletions

View File

@ -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 <CGAL/Bbox_3.h>
#include <vector>
namespace CGAL {
namespace Optimal_bounding_box {
template<typename Matrix>
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

View File

@ -38,8 +38,7 @@ void qr_factorization(EigenMatrix& A, EigenMatrix& Q)
} }
}} // end namespaces
}}

View File

@ -2,6 +2,7 @@
#include <CGAL/Surface_mesh.h> #include <CGAL/Surface_mesh.h>
#include <CGAL/Optimal_bounding_box/linear_algebra.h> #include <CGAL/Optimal_bounding_box/linear_algebra.h>
#include <CGAL/Optimal_bounding_box/fitness_function.h>
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
@ -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_qr_factorization();
test_fitness_function();
return 0; return 0;
} }