ANIMA  4.0
animaMatrixLogExp.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vector>
4 #include <vnl/vnl_matrix.h>
5 #include <math.h>
6 
7 #include <itkTransform.h>
8 #include <itkMatrixOffsetTransformBase.h>
9 #include <itkMultiThreaderBase.h>
10 
11 namespace anima
12 {
13 /* Implementation of square matrix logarithm and exponential. First implemented by V. Arsigny. */
14 
16 template <class T> vnl_matrix <T> GetSquareRoot(const vnl_matrix <T> & m, const double precision, vnl_matrix <T> & resultM);
17 
19 template <class T> vnl_matrix <T> GetPadeLogarithm(const vnl_matrix <double> & m,const int numApprox);
20 
22 template <class T> vnl_matrix <T> GetLogarithm(const vnl_matrix <T> & m, const double precision=0.00000000001, const int numApprox=1);
23 
25 template <class T> vnl_matrix <T> GetExponential(const vnl_matrix <T> & m, const int numApprox=1);
26 
28 template <class T> void Get3DRotationLogarithm(const vnl_matrix <T> &rotationMatrix, std::vector <T> &outputAngles);
29 
31 template <class T> void Get3DRotationExponential(const std::vector <T> &angles, vnl_matrix <T> &outputRotation);
32 
34 template <class TInputScalarType, class TOutputScalarType, unsigned int NDimensions, unsigned int NDegreesOfFreedom>
36 {
37 public:
39 
40  typedef itk::Vector <TOutputScalarType, NDegreesOfFreedom> OutputVectorType;
41  typedef typename std::vector <OutputVectorType> OutputType;
42 
43  typedef itk::Transform<TInputScalarType,NDimensions,NDimensions> BaseInputTransformType;
44  typedef typename std::vector <typename BaseInputTransformType::Pointer> InputType;
45  typedef itk::MatrixOffsetTransformBase<TInputScalarType,NDimensions,NDimensions> BaseInputMatrixTransformType;
46 
48  {
49  m_Modified = true;
50  m_InputTransforms.clear();
51 
52  m_UseRigidTransforms = false;
53 
54  m_NumberOfThreads = itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads();
55  }
56 
58 
59  void SetInput(InputType &input) {m_InputTransforms = input;m_Modified = true;}
60  void SetNumberOfWorkUnits(unsigned int &numThreads) {m_NumberOfThreads = numThreads;}
61  void SetUseRigidTransforms(bool rigTrsfs)
62  {
63  if (m_UseRigidTransforms != rigTrsfs)
64  m_Modified = true;
65 
66  m_UseRigidTransforms = rigTrsfs;
67  }
68 
69  void Update();
70 
71  OutputType &GetOutput()
72  {
73  if (m_Modified)
74  this->Update();
75 
76  return m_Output;
77  }
78 
79 protected:
81  {
82  Self* loggerFilter;
83  };
84 
85  static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION ThreadedLogging(void *arg);
86  void InternalLogger(unsigned int threadId, unsigned int numThreads);
87 
88 private:
89  InputType m_InputTransforms;
90  OutputType m_Output;
91 
92  unsigned int m_NumberOfThreads;
93  bool m_UseRigidTransforms;
94  bool m_Modified;
95 };
96 
97 } // end of namespace anima
98 
99 #include "animaMatrixLogExp.hxx"
void SetNumberOfWorkUnits(unsigned int &numThreads)
void Get3DRotationLogarithm(const vnl_matrix< T > &rotationMatrix, std::vector< T > &outputAngles)
Computation of a 3D rotation matrix logarithm. Rodrigues&#39; explicit formula.
void SetUseRigidTransforms(bool rigTrsfs)
itk::Vector< TOutputScalarType, NDegreesOfFreedom > OutputVectorType
std::vector< typename BaseInputTransformType::Pointer > InputType
void SetInput(InputType &input)
vnl_matrix< T > GetExponential(const vnl_matrix< T > &m, const int numApprox=1)
Computation of the matrix exponential. Algo: classical scaling and squaring, as in Matlab...
std::vector< OutputVectorType > OutputType
void InternalLogger(unsigned int threadId, unsigned int numThreads)
vnl_matrix< T > GetLogarithm(const vnl_matrix< T > &m, const double precision=0.00000000001, const int numApprox=1)
Computation of the matrix logarithm. Algo: inverse scaling and squaring, variant proposed by Cheng et...
static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION ThreadedLogging(void *arg)
void Get3DRotationExponential(const std::vector< T > &angles, vnl_matrix< T > &outputRotation)
Computation of a 3D rotation matrix exponential. Rodrigues&#39; explicit formula.
itk::Transform< TInputScalarType, NDimensions, NDimensions > BaseInputTransformType
Class to compute many log-vectors in a multi-threaded way.
itk::MatrixOffsetTransformBase< TInputScalarType, NDimensions, NDimensions > BaseInputMatrixTransformType
vnl_matrix< T > GetPadeLogarithm(const vnl_matrix< double > &m, const int numApprox)
Final part of the computation of the log. Estimates the log with a Pade approximation for a matrix m ...
vnl_matrix< T > GetSquareRoot(const vnl_matrix< T > &m, const double precision, vnl_matrix< T > &resultM)
Gets the square root of matrix m.