ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkGeneralizedEigenDecomposition.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18#ifndef itkGeneralizedEigenDecomposition_h
19#define itkGeneralizedEigenDecomposition_h
20
21#include "vnl/vnl_matrix.h"
22#include "vnl/vnl_vector.h"
25#include "itkMacro.h"
26#include "itk_eigen.h"
27#include ITK_EIGEN(Dense)
28
29namespace itk
30{
31
48template <typename TReal>
50{
51public:
52 using MatrixType = vnl_matrix<TReal>;
53 using VectorType = vnl_vector<TReal>;
54
59 GeneralizedEigenDecomposition(const MatrixType & A, const MatrixType & B, bool canonicalizeSigns = true)
60 {
61 using RowMajor = Eigen::Matrix<TReal, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
62 using ColMajor = Eigen::Matrix<TReal, Eigen::Dynamic, Eigen::Dynamic>;
63 using Vector = Eigen::Matrix<TReal, Eigen::Dynamic, 1>;
64 const unsigned int n = A.rows();
65
66 Eigen::Map<const RowMajor> aMap(A.data_block(), n, n);
67 Eigen::Map<const RowMajor> bMap(B.data_block(), n, n);
68
69 const Eigen::GeneralizedSelfAdjointEigenSolver<ColMajor> solver(aMap, bMap);
70
71 if (solver.info() != Eigen::Success)
72 {
73 itkGenericExceptionMacro(<< "GeneralizedEigenDecomposition: Eigen GeneralizedSelfAdjointEigenSolver failed: "
75 << "; A and B must be finite and B symmetric positive-definite.");
76 }
77
78 m_Eigenvalues.set_size(n);
79 Eigen::Map<Vector>(m_Eigenvalues.data_block(), n) = solver.eigenvalues();
80 m_Eigenvectors.set_size(n, n);
81 Eigen::Map<RowMajor>(m_Eigenvectors.data_block(), n, n) = solver.eigenvectors();
82
83 if (canonicalizeSigns)
84 {
86 }
87 }
88
90 const VectorType &
92 {
93 return m_Eigenvalues;
94 }
95
97 const MatrixType &
99 {
100 return m_Eigenvectors;
101 }
102
103private:
106};
107
108} // namespace itk
109
110#endif // itkGeneralizedEigenDecomposition_h
GeneralizedEigenDecomposition(const MatrixType &A, const MatrixType &B, bool canonicalizeSigns=true)
A templated class holding a n-Dimensional vector.
Definition itkVector.h:63
const char * EigenComputationInfoString(Eigen::ComputationInfo info)
void CanonicalizeEigenvectorColumnSigns(vnl_matrix< T > &V)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....