From 6c77cc817a8a1b80a5352dea00a84fc219fb89ff Mon Sep 17 00:00:00 2001 From: Simon Giraudot Date: Wed, 26 Aug 2015 11:55:04 +0200 Subject: [PATCH] Propagating change of eigen API in Bounding_volumes package --- .../Approximate_min_ellipsoid_d_impl.h | 87 +++++++++++-------- 1 file changed, 50 insertions(+), 37 deletions(-) diff --git a/Bounding_volumes/include/CGAL/Approximate_min_ellipsoid_d/Approximate_min_ellipsoid_d_impl.h b/Bounding_volumes/include/CGAL/Approximate_min_ellipsoid_d/Approximate_min_ellipsoid_d_impl.h index d6cbb4ade8b..9c55b1bb92b 100644 --- a/Bounding_volumes/include/CGAL/Approximate_min_ellipsoid_d/Approximate_min_ellipsoid_d_impl.h +++ b/Bounding_volumes/include/CGAL/Approximate_min_ellipsoid_d/Approximate_min_ellipsoid_d_impl.h @@ -18,8 +18,12 @@ // // Author(s) : Kaspar Fischer -#include -#include + +#ifdef CGAL_EIGEN3_ENABLED +#include +#else +#include +#endif #include @@ -150,34 +154,37 @@ namespace CGAL { { CGAL_APPEL_ASSERT(d==2); - typedef Simple_cartesian K; - typedef Vector_2 Vector_2; - // write matrix M' as [ a, b; b, c ]: - const double matrix[3] = { E->matrix(0, 0), // a - E->matrix(0, 1), // b - E->matrix(1, 1) }; // c - - std::pair eigenvectors; // Note: not neces. normalized. - std::pair eigenvalues; // Note: sorted descendent. - internal::eigen_symmetric_2(matrix, eigenvectors, eigenvalues); + const CGAL::cpp11::array matrix = {{ E->matrix(0, 0), // a + E->matrix(0, 1), // b + E->matrix(1, 1) }}; // c + CGAL::cpp11::array eigenvectors; // Note: not neces. normalized. + CGAL::cpp11::array eigenvalues; // Note: sorted ascendent. + +#ifdef CGAL_EIGEN3_ENABLED + CGAL::Eigen_vcm_traits::diagonalize_selfadjoint_covariance_matrix + (matrix, eigenvalues, eigenvectors); +#else + CGAL::Internal_vcm_traits::diagonalize_selfadjoint_covariance_matrix + (matrix, eigenvalues, eigenvectors); +#endif // normalize eigenvectors: - double l1=1.0/std::sqrt(eigenvectors.first.x()*eigenvectors.first.x()+ - eigenvectors.first.y()*eigenvectors.first.y()); - double l2=1.0/std::sqrt(eigenvectors.second.x()*eigenvectors.second.x()+ - eigenvectors.second.y()*eigenvectors.second.y()); + double l1=1.0/std::sqrt(eigenvectors[2]*eigenvectors[2]+ + eigenvectors[3]*eigenvectors[3]); + double l2=1.0/std::sqrt(eigenvectors[0]*eigenvectors[0]+ + eigenvectors[1]*eigenvectors[1]); // store axes lengths: - lengths_.push_back(std::sqrt(factor/eigenvalues.first)); - lengths_.push_back(std::sqrt(factor/eigenvalues.second)); + lengths_.push_back(std::sqrt(factor/eigenvalues[1])); + lengths_.push_back(std::sqrt(factor/eigenvalues[0])); // store directions: directions_.resize(2); - directions_[0].push_back(eigenvectors.first.x()*l1); - directions_[0].push_back(eigenvectors.first.y()*l1); - directions_[1].push_back(eigenvectors.second.x()*l2); - directions_[1].push_back(eigenvectors.second.y()*l2); + directions_[0].push_back(eigenvectors[2]*l1); + directions_[0].push_back(eigenvectors[3]*l1); + directions_[1].push_back(eigenvectors[0]*l2); + directions_[1].push_back(eigenvectors[1]*l2); } template @@ -192,16 +199,22 @@ namespace CGAL { // M' = [ b d e ] // [ c e f ] // - const double matrix[6] = { E->matrix(0, 0), // a - E->matrix(0, 1), // b - E->matrix(1, 1), // d - E->matrix(0, 2), // c - E->matrix(1, 2), // e - E->matrix(2, 2) }; // f + const CGAL::cpp11::array matrix = {{ E->matrix(0, 0), // a + E->matrix(0, 1), // b + E->matrix(0, 2), // c + E->matrix(1, 1), // d + E->matrix(1, 2), // e + E->matrix(2, 2) }}; // f - double eigenvectors[3 * 3]; // Note: not necessarily normalized. - double eigenvalues[3]; // Note: sorted descendent. - internal::eigen_symmetric(matrix, 3, eigenvectors, eigenvalues); + CGAL::cpp11::array eigenvectors; // Note: not necessarily normalized. + CGAL::cpp11::array eigenvalues; // Note: sorted ascendent. +#ifdef CGAL_EIGEN3_ENABLED + CGAL::Eigen_vcm_traits::diagonalize_selfadjoint_covariance_matrix + (matrix, eigenvalues, eigenvectors); +#else + CGAL::Internal_vcm_traits::diagonalize_selfadjoint_covariance_matrix + (matrix, eigenvalues, eigenvectors); +#endif // normalize eigenvectors: double l1 = 1.0/std::sqrt(eigenvectors[0] * eigenvectors[0]+ // x^2 @@ -220,15 +233,15 @@ namespace CGAL { // store directions: directions_.resize(3); - directions_[0].push_back(eigenvectors[0]*l1); - directions_[0].push_back(eigenvectors[1]*l1); - directions_[0].push_back(eigenvectors[2]*l1); + directions_[0].push_back(eigenvectors[6]*l3); + directions_[0].push_back(eigenvectors[7]*l3); + directions_[0].push_back(eigenvectors[8]*l3); directions_[1].push_back(eigenvectors[3]*l2); directions_[1].push_back(eigenvectors[4]*l2); directions_[1].push_back(eigenvectors[5]*l2); - directions_[2].push_back(eigenvectors[6]*l3); - directions_[2].push_back(eigenvectors[7]*l3); - directions_[2].push_back(eigenvectors[8]*l3); + directions_[2].push_back(eigenvectors[0]*l1); + directions_[2].push_back(eigenvectors[1]*l1); + directions_[2].push_back(eigenvectors[2]*l1); } template