ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkRealEigenDecomposition.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 itkRealEigenDecomposition_h
19#define itkRealEigenDecomposition_h
20
21#include "vnl/vnl_matrix.h"
22#include "vnl/vnl_vector.h"
23#include <complex>
25#include "itkMacro.h"
26#include "itk_eigen.h"
27#include ITK_EIGEN(Dense)
28
29namespace itk
30{
31
53template <typename TReal>
55{
56public:
57 using ComplexType = std::complex<TReal>;
58 using ComplexMatrixType = vnl_matrix<ComplexType>;
59 using ComplexVectorType = vnl_vector<ComplexType>;
60
61 explicit RealEigenDecomposition(const vnl_matrix<TReal> & M)
62 {
63 using RowMajor = Eigen::Matrix<TReal, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
64 const unsigned int n = M.rows();
65
66 Eigen::Map<const RowMajor> mMap(M.data_block(), n, M.cols());
67 const Eigen::EigenSolver<Eigen::Matrix<TReal, Eigen::Dynamic, Eigen::Dynamic>> solver(mMap);
68
69 if (solver.info() != Eigen::Success)
70 {
71 itkGenericExceptionMacro(<< "RealEigenDecomposition: Eigen EigenSolver failed: "
72 << detail::EigenComputationInfoString(solver.info()) << '.');
73 }
74
75 using ComplexRowMajor = Eigen::Matrix<ComplexType, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
76 m_Eigenvalues.set_size(n);
77 Eigen::Map<Eigen::Matrix<ComplexType, Eigen::Dynamic, 1>>(m_Eigenvalues.data_block(), n) = solver.eigenvalues();
78 m_Eigenvectors.set_size(n, n);
79 Eigen::Map<ComplexRowMajor>(m_Eigenvectors.data_block(), n, n) = solver.eigenvectors();
80 }
81
83 const ComplexVectorType &
85 {
86 return m_Eigenvalues;
87 }
88
90 const ComplexMatrixType &
92 {
93 return m_Eigenvectors;
94 }
95
96private:
99};
100
101} // namespace itk
102
103#endif // itkRealEigenDecomposition_h
RealEigenDecomposition(const vnl_matrix< TReal > &M)
const ComplexMatrixType & GetEigenvectors() const
vnl_vector< ComplexType > ComplexVectorType
const ComplexVectorType & GetEigenvalues() const
vnl_matrix< ComplexType > ComplexMatrixType
const char * EigenComputationInfoString(Eigen::ComputationInfo info)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....