ANIMA  4.0
animaBaseTensorTools.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <itkMatrix.h>
4 #include <vnl/vnl_matrix.h>
5 #include <vnl/vnl_diag_matrix.h>
6 
7 #include <itkVariableLengthVector.h>
8 #include <itkMatrixOffsetTransformBase.h>
9 #include <itkSymmetricEigenAnalysis.h>
10 
11 #include <vnl/vnl_diag_matrix.h>
12 #include <vnl/vnl_matrix.h>
13 
14 namespace anima
15 {
16 
17 template <class TScalarType>
18 class LogEuclideanTensorCalculator : public itk::LightObject
19 {
20 public:
22  using Superclass = itk::LightObject;
23  using Pointer = itk::SmartPointer<Self>;
24  using ConstPointer = itk::SmartPointer<const Self>;
25 
27  itkTypeMacro(LogEuclideanTensorCalculator, itk::LightObject)
28 
29  itkNewMacro(Self)
30 
31  using EigenAnalysisType = itk::SymmetricEigenAnalysis < vnl_matrix <double>, vnl_diag_matrix<double>, vnl_matrix <double> >;
32 
33  void GetTensorLogarithm(const vnl_matrix <TScalarType> &tensor, vnl_matrix <TScalarType> &log_tensor);
34  void GetTensorExponential(const vnl_matrix <TScalarType> &tensor, vnl_matrix <TScalarType> &log_tensor);
35  void GetTensorPower(const vnl_matrix <TScalarType> &tensor, vnl_matrix <TScalarType> &outputTensor, double powerValue);
36 
37 private:
38  EigenAnalysisType m_EigenAnalyzer;
39  vnl_matrix <TScalarType> m_EigVecs;
40  vnl_diag_matrix <TScalarType> m_EigVals;
41 
42 };
43 
44 template <class T1, class T2> void GetVectorRepresentation(const vnl_matrix <T1> &tensor, itk::VariableLengthVector <T2> &vector,
45  unsigned int vecDim = 0, bool scale = false);
46 
47 template <class T1, class T2> void GetTensorFromVectorRepresentation(const itk::VariableLengthVector <T1> &vector,
48  vnl_matrix <T2> &tensor, unsigned int tensDim = 0,
49  bool scale = false);
50 
52 template <class T1, class T2>
53 void RecomposeTensor(vnl_diag_matrix <T1> &eigs, vnl_matrix <T1> &eigVecs, vnl_matrix <T2> &resMatrix);
54 
55 template <class T> void ProjectOnTensorSpace(const vnl_matrix <T> &matrix, vnl_matrix <T> &tensor);
56 
57 template <typename RealType>
58 void ExtractRotationFromJacobianMatrix(vnl_matrix <RealType> &jacobianMatrix, vnl_matrix <RealType> &rotationMatrix,
59  vnl_matrix <RealType> &tmpMat);
60 
61 template <typename RealType, typename MatrixType>
62 void ExtractPPDRotationFromJacobianMatrix(vnl_matrix <RealType> &jacobianMatrix, vnl_matrix <RealType> &rotationMatrix,
63  MatrixType &eigenVectors);
64 
66 template <class T1, class T2, class T3>
67 void RotateSymmetricMatrix(T1 &tensor, T2 &rotationMatrix, T3 &rotated_tensor, unsigned int tensorDim);
68 
69 template <class T1, class T2>
70 void RotateSymmetricMatrix(vnl_matrix <T1> &tensor, vnl_matrix <T2> &rotationMatrix, vnl_matrix <T2> &rotated_tensor);
71 
72 template <class T1, class T2, unsigned int NDim>
73 void RotateSymmetricMatrix(itk::Matrix <T1,NDim,NDim> &tensor, itk::Matrix <T2,NDim,NDim> &rotationMatrix,
74  itk::Matrix <T2,NDim,NDim> &rotated_tensor);
75 
76 template <class T1> double ovlScore(vnl_diag_matrix <T1> &eigsX, vnl_matrix <T1> &eigVecsX,
77  vnl_diag_matrix <T1> &eigsY, vnl_matrix <T1> &eigVecsY);
78 
79 
80 } // end of namespace anima
81 
82 #include "animaBaseTensorTools.hxx"
double ovlScore(vnl_diag_matrix< T1 > &eigsX, vnl_matrix< T1 > &eigVecsX, vnl_diag_matrix< T1 > &eigsY, vnl_matrix< T1 > &eigVecsY)
itk::SmartPointer< const Self > ConstPointer
void ExtractRotationFromJacobianMatrix(vnl_matrix< RealType > &jacobianMatrix, vnl_matrix< RealType > &rotationMatrix, vnl_matrix< RealType > &tmpMat)
void GetTensorExponential(const vnl_matrix< TScalarType > &tensor, vnl_matrix< TScalarType > &log_tensor)
void GetVectorRepresentation(const vnl_matrix< T1 > &tensor, itk::VariableLengthVector< T2 > &vector, unsigned int vecDim=0, bool scale=false)
void RotateSymmetricMatrix(T1 &tensor, T2 &rotationMatrix, T3 &rotated_tensor, unsigned int tensorDim)
Rotates a symmetric matrix by performing R^T D R where R is a rotation matrix and D the symmetric mat...
itk::SymmetricEigenAnalysis< vnl_matrix< double >, vnl_diag_matrix< double >, vnl_matrix< double > > EigenAnalysisType
void GetTensorFromVectorRepresentation(const itk::VariableLengthVector< T1 > &vector, vnl_matrix< T2 > &tensor, unsigned int tensDim=0, bool scale=false)
void GetTensorPower(const vnl_matrix< TScalarType > &tensor, vnl_matrix< TScalarType > &outputTensor, double powerValue)
void RecomposeTensor(vnl_diag_matrix< T1 > &eigs, vnl_matrix< T1 > &eigVecs, vnl_matrix< T2 > &resMatrix)
Recompose tensor from values extracted using SymmetricEigenAnalysis (vnl_symmetric_eigensystem transp...
void GetTensorLogarithm(const vnl_matrix< TScalarType > &tensor, vnl_matrix< TScalarType > &log_tensor)
void ProjectOnTensorSpace(const vnl_matrix< T > &matrix, vnl_matrix< T > &tensor)
void ExtractPPDRotationFromJacobianMatrix(vnl_matrix< RealType > &jacobianMatrix, vnl_matrix< RealType > &rotationMatrix, MatrixType &eigenVectors)