ANIMA  4.0
animaSplitAffine3DTransform.hxx
Go to the documentation of this file.
1 #pragma once
2 
4 #include <animaMatrixLogExp.h>
5 
6 namespace anima
7 {
8 
9 // Constructor with default arguments
10 template <class TScalarType>
13 : Superclass(ParametersDimension)
14 {
15  m_FirstAngle.Fill(itk::NumericTraits<TScalarType>::Zero);
16  m_SecondAngle.Fill(itk::NumericTraits<TScalarType>::Zero);
17  m_LogScale.Fill(itk::NumericTraits<TScalarType>::Zero);
18 }
19 
20 // Set Parameters
21 template <class TScalarType>
22 void
24 ::SetParameters( const ParametersType & parameters)
25 {
26  m_FirstAngle[0] = parameters[0];
27  m_FirstAngle[1] = parameters[1];
28  m_FirstAngle[2] = parameters[2];
29 
30  // Matrix must be defined before translation so that offset can be computed
31  // from translation
32  m_LogScale[0] = parameters[6];
33  m_LogScale[1] = parameters[7];
34  m_LogScale[2] = parameters[8];
35 
36  m_SecondAngle[0] = parameters[9];
37  m_SecondAngle[1] = parameters[10];
38  m_SecondAngle[2] = parameters[11];
39 
40  TranslationType newTranslation;
41  newTranslation[0] = parameters[3];
42  newTranslation[1] = parameters[4];
43  newTranslation[2] = parameters[5];
44 
45  this->SetTranslation(newTranslation);
46 
47  this->ComputeMatrix();
48  this->ComputeOffset();
49 
50  // Modified is always called since we just have a pointer to the
51  // parameters and cannot know if the parameters have changed.
52  this->Modified();
53 }
54 
55 //
56 // Get Parameters
57 //
58 template <class TScalarType>
61 ::GetParameters( void ) const
62 {
63  this->m_Parameters[0] = this->GetFirstAngle()[0];
64  this->m_Parameters[1] = this->GetFirstAngle()[1];
65  this->m_Parameters[2] = this->GetFirstAngle()[2];
66 
67  this->m_Parameters[3] = this->GetTranslation()[0];
68  this->m_Parameters[4] = this->GetTranslation()[1];
69  this->m_Parameters[5] = this->GetTranslation()[2];
70 
71  this->m_Parameters[6] = this->GetLogScale()[0];
72  this->m_Parameters[7] = this->GetLogScale()[1];
73  this->m_Parameters[8] = this->GetLogScale()[2];
74 
75  this->m_Parameters[9] = this->GetSecondAngle()[0];
76  this->m_Parameters[10] = this->GetSecondAngle()[1];
77  this->m_Parameters[11] = this->GetSecondAngle()[2];
78 
79  return this->m_Parameters;
80 }
81 
82 template <class TScalarType>
83 void
86 {
87  m_FirstAngle.Fill(itk::NumericTraits <TScalarType>::Zero);
88  m_LogScale.Fill(itk::NumericTraits <TScalarType>::Zero);
89  m_SecondAngle.Fill(itk::NumericTraits <TScalarType>::Zero);
90 
91  TranslationType newTranslation;
92  newTranslation.Fill(0.0);
93 
94  this->SetTranslation(newTranslation);
95 
96  this->ComputeMatrix();
97  this->ComputeOffset();
98 }
99 
100 template <class TScalarType>
101 void
104 {
105  m_FirstAngle = angle;
106  this->ComputeMatrix();
107  this->ComputeOffset();
108 }
109 
110 template <class TScalarType>
111 void
114 {
115  m_LogScale = scale;
116  this->ComputeMatrix();
117  this->ComputeOffset();
118 }
119 
120 template <class TScalarType>
121 void
124 {
125  m_SecondAngle = angle;
126  this->ComputeMatrix();
127  this->ComputeOffset();
128 }
129 
130 // Compute the matrix
131 template <class TScalarType>
132 void
135 {
136  std::vector <TScalarType> angles(3, 0.0);
137  for (unsigned int i = 0;i < InputSpaceDimension;++i)
138  angles[i] = m_FirstAngle[i];
139 
140  vnl_matrix <TScalarType> firstRotationMatrix;
141  anima::Get3DRotationExponential(angles,firstRotationMatrix);
142 
143  vnl_matrix <TScalarType> scaleMatrix(InputSpaceDimension, InputSpaceDimension);
144  scaleMatrix.set_identity();
145  for (unsigned int i = 0;i < InputSpaceDimension;++i)
146  scaleMatrix(i,i) = std::exp(m_LogScale[i]);
147 
148  for (unsigned int i = 0;i < InputSpaceDimension;++i)
149  angles[i] = m_SecondAngle[i];
150 
151  vnl_matrix <TScalarType> secondRotationMatrix;
152  anima::Get3DRotationExponential(angles,secondRotationMatrix);
153 
154  MatrixType varMatrix = firstRotationMatrix * scaleMatrix * secondRotationMatrix;
155  this->SetVarMatrix (varMatrix);
156 }
157 
158 template <class TScalarType>
159 void
162 {
163  itkExceptionMacro( << "Setting the matrix of a SplitAffine3D transform is not supported at this time." );
164 }
165 
166 // Print self
167 template<class TScalarType>
168 void
170 PrintSelf(std::ostream &os, itk::Indent indent) const
171 {
172 
173  Superclass::PrintSelf(os,indent);
174 
175  os << indent << "First angle: " << m_FirstAngle << std::endl;
176  os << indent << "Scale: " << m_LogScale << std::endl;
177  os << indent << "Second angle: " << m_SecondAngle << std::endl;
178 }
179 
180 } // end of namespace anima
Superclass::ParametersType ParametersType
itk::MatrixOffsetTransformBase< TScalarType, 3, 3 > Superclass
Superclass::TranslationType TranslationType
void PrintSelf(std::ostream &os, itk::Indent indent) const ITK_OVERRIDE
void SetSecondAngle(const VectorType &angle)
void Get3DRotationExponential(const std::vector< T > &angles, vnl_matrix< T > &outputRotation)
Computation of a 3D rotation matrix exponential. Rodrigues&#39; explicit formula.
void SetFirstAngle(const VectorType &angle)
virtual void SetParameters(const ParametersType &parameters) ITK_OVERRIDE
void SetLogScale(const VectorType &scale)
virtual const ParametersType & GetParameters() const ITK_OVERRIDE
itk::Vector< TScalarType, 3 > VectorType