ANIMA  4.0
animaLogRigid3DTransform.hxx
Go to the documentation of this file.
1 #pragma once
2 
3 #include <animaMatrixLogExp.h>
4 
5 namespace anima
6 {
7 
8 // Constructor with default arguments
9 template <class TScalarType>
12 Superclass(ParametersDimension)
13 {
14  m_Angles.Fill(itk::NumericTraits<TScalarType>::Zero);
15  m_LogVector.Fill(itk::NumericTraits<TScalarType>::Zero);
16  m_LogTransform.set_size(4,4);
17 
18  this->ComputeMatrix();
19 }
20 
21 // Set Parameters
22 template <class TScalarType>
23 void
25 ::SetParameters( const ParametersType & parameters )
26 {
27  itkDebugMacro( << "Setting parameters " << parameters );
28 
29  m_Angles[0] = parameters[0];
30  m_Angles[1] = parameters[1];
31  m_Angles[2] = parameters[2];
32 
33  TranslationType newTranslation;
34  newTranslation[0] = parameters[3];
35  newTranslation[1] = parameters[4];
36  newTranslation[2] = parameters[5];
37 
38  this->SetTranslation(newTranslation);
39 
40  this->ComputeMatrix();
41 
42  // Modified is always called since we just have a pointer to the
43  // parameters and cannot know if the parameters have changed.
44  this->Modified();
45 
46  itkDebugMacro(<<"After setting parameters ");
47 }
48 
49 
50 // Get Parameters
51 template <class TScalarType>
55 {
56  this->m_Parameters[0] = m_Angles[0];
57  this->m_Parameters[1] = m_Angles[1];
58  this->m_Parameters[2] = m_Angles[2];
59 
60  this->m_Parameters[3] = this->GetTranslation()[0];
61  this->m_Parameters[4] = this->GetTranslation()[1];
62  this->m_Parameters[5] = this->GetTranslation()[2];
63 
64  return this->m_Parameters;
65 }
66 
67 // Compose
68 template <class TScalarType>
69 void
72 {
73  Superclass::SetIdentity();
74  m_Angles.Fill(itk::NumericTraits<TScalarType>::Zero);
75 
76  this->ComputeMatrix();
77 }
78 
79 // Compute angles from the rotation matrix
80 template <class TScalarType>
81 void
84 {
85  this->ComputeLogRepresentations();
86 
87  vnl_matrix <TScalarType> transformMatrix = GetExponential(m_LogTransform);
88 
89  MatrixType linearMatrix;
90  OffsetType off;
91 
92  for (unsigned int i = 0;i < 3;++i)
93  {
94  off[i] = transformMatrix(i,3);
95  for (unsigned int j = 0;j < 3;++j)
96  linearMatrix(i,j) = transformMatrix(i,j);
97  }
98 
99  this->SetMatrix(linearMatrix);
100  this->SetOffset(off);
101 }
102 
103 template <class TScalarType>
104 void
107 {
108  m_LogVector.Fill(itk::NumericTraits<TScalarType>::Zero);
109 
110  for (unsigned int i = 0;i < 3;++i)
111  m_LogVector[i] = m_Angles[i];
112 
113  m_LogTransform.fill(itk::NumericTraits<TScalarType>::Zero);
114 
115  unsigned int pos = 0;
116  for (unsigned int i = 0;i < 3;++i)
117  {
118  for (unsigned int j = i+1;j < 3;++j)
119  {
120  m_LogTransform(i,j) = m_Angles[pos];
121  m_LogTransform(j,i) = - m_Angles[pos];
122  ++pos;
123  }
124  }
125 
126  for (unsigned int i = 0;i < 3;++i)
127  {
128  m_LogVector[i+3] = this->GetTranslation()[i];
129  for (unsigned int j = 0;j < 3;++j)
130  m_LogVector[i+3] -= m_LogTransform(i,j) * this->GetCenter()[j];
131  }
132 
133  for (unsigned int i = 0;i < 3;++i)
134  m_LogTransform(i,3) = m_LogVector[i+3];
135 }
136 
137 // Print self
138 template<class TScalarType>
139 void
141 PrintSelf(std::ostream &os, itk::Indent indent) const
142 {
143  Superclass::PrintSelf(os,indent);
144 
145  os << indent << "Log-transform parameters: Angles=" << m_Angles << std::endl;
146 }
147 
148 } // end of namespace anima
itk::MatrixOffsetTransformBase< TScalarType, 3 > Superclass
Superclass::MatrixType MatrixType
virtual void SetIdentity() ITK_OVERRIDE
Superclass::OffsetType OffsetType
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...
virtual void SetParameters(const ParametersType &parameters) ITK_OVERRIDE
Superclass::ParametersType ParametersType
Superclass::TranslationType TranslationType
void PrintSelf(std::ostream &os, itk::Indent indent) const ITK_OVERRIDE
virtual const ParametersType & GetParameters() const ITK_OVERRIDE