mirror of https://github.com/CGAL/cgal
qr factorization
This commit is contained in:
parent
202a0ce9e6
commit
5141abe2c3
|
|
@ -0,0 +1,51 @@
|
|||
// 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_OPTIMAL_BOUNDING_BOX_H
|
||||
#define CGAL_OPTIMAL_BOUNDING_BOX_H
|
||||
|
||||
|
||||
#include <Eigen/QR>
|
||||
|
||||
|
||||
namespace CGAL {
|
||||
namespace Optimal_bounding_box {
|
||||
|
||||
|
||||
template<typename EigenMatrix>
|
||||
void qr_factorization(EigenMatrix& A, EigenMatrix& Q)
|
||||
{
|
||||
Eigen::HouseholderQR<EigenMatrix> qr(A);
|
||||
Q = qr.householderQ();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif //CGAL_OPTIMAL_BOUNDING_BOX_H
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
# Created by the script cgal_create_CMakeLists
|
||||
# This is the CMake script for compiling a set of CGAL applications.
|
||||
|
||||
project( Optimal_bounding_box_Tests )
|
||||
|
||||
|
||||
cmake_minimum_required(VERSION 2.6.2)
|
||||
if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6)
|
||||
if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3)
|
||||
cmake_policy(VERSION 2.8.4)
|
||||
else()
|
||||
cmake_policy(VERSION 2.6)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
# CGAL and its components
|
||||
find_package( CGAL QUIET COMPONENTS )
|
||||
|
||||
if ( NOT CGAL_FOUND )
|
||||
|
||||
message(STATUS "This project requires the CGAL library, and will not be compiled.")
|
||||
return()
|
||||
|
||||
endif()
|
||||
|
||||
# include helper file
|
||||
include( ${CGAL_USE_FILE} )
|
||||
|
||||
|
||||
# Boost and its components
|
||||
find_package( Boost REQUIRED )
|
||||
|
||||
if ( NOT Boost_FOUND )
|
||||
|
||||
message(STATUS "This project requires the Boost library, and will not be compiled.")
|
||||
|
||||
return()
|
||||
|
||||
endif()
|
||||
|
||||
# include for local directory
|
||||
|
||||
# include for local package
|
||||
include_directories( BEFORE ../../include )
|
||||
|
||||
find_package(Eigen3 3.2.0) #(requires 3.2.0 or greater)
|
||||
|
||||
find_package( TBB )
|
||||
|
||||
include( CGAL_CreateSingleSourceCGALProgram )
|
||||
if (EIGEN3_FOUND)
|
||||
include( ${EIGEN3_USE_FILE} )
|
||||
|
||||
create_single_source_cgal_program("test_linear_algebra_functions.cpp")
|
||||
|
||||
endif(EIGEN3_FOUND)
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
#include <CGAL/Surface_mesh.h>
|
||||
|
||||
#include <CGAL/Optimal_bounding_box/linear_algebra.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include <Eigen/Dense>
|
||||
|
||||
//typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
|
||||
//typedef CGAL::Surface_mesh<K::Point_3> Surface_mesh;
|
||||
|
||||
typedef Eigen::MatrixXf MatrixXf;
|
||||
|
||||
|
||||
bool assert_doubles(double d1, double d2, double epsilon)
|
||||
{
|
||||
return (d1 < d2 + epsilon && d1 > d2 - epsilon) ? true : false;
|
||||
}
|
||||
|
||||
|
||||
void test_qr_factorization()
|
||||
{
|
||||
|
||||
MatrixXf A(3, 3);
|
||||
A << 0.3011944, 0.9932761, 0.5483701,
|
||||
0.5149142, 0.5973263, 0.5162336,
|
||||
0.0039213, 0.0202949, 0.9240308;
|
||||
|
||||
MatrixXf Q;
|
||||
CGAL::Optimal_bounding_box::qr_factorization(A, Q);
|
||||
|
||||
double epsilon = 1e-6;
|
||||
CGAL_assertion(assert_doubles(Q(0,0), -0.504895, epsilon));
|
||||
CGAL_assertion(assert_doubles(Q(0,1), 0.862834, epsilon));
|
||||
CGAL_assertion(assert_doubles(Q(0,2), -0.024447, epsilon));
|
||||
CGAL_assertion(assert_doubles(Q(1,0), -0.863156, epsilon));
|
||||
CGAL_assertion(assert_doubles(Q(1,1), -0.504894, epsilon));
|
||||
CGAL_assertion(assert_doubles(Q(1,2), 0.006687, epsilon));
|
||||
CGAL_assertion(assert_doubles(Q(2,0), -0.006573, epsilon));
|
||||
CGAL_assertion(assert_doubles(Q(2,1), 0.024478, epsilon));
|
||||
CGAL_assertion(assert_doubles(Q(2,2), 0.999679, epsilon));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
test_qr_factorization();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in New Issue