ANIMA  4.0
animaAxisRotationTransform.hxx
Go to the documentation of this file.
1 #pragma once
4 
5 namespace anima
6 {
7 
8 // Constructor with default arguments
9 template <class TScalarType>
12  Superclass(ParametersDimension)
13 {
14  m_Angle = m_TranslationY = m_TranslationZ = itk::NumericTraits<ScalarType>::Zero;
15  m_ReferencePlane.SetIdentity();
16  m_InverseReferencePlane.SetIdentity();
17 
18  this->ComputeMatrix();
19 }
20 
21 // Constructor with arguments
22 template <class TScalarType>
24 ::AxisRotationTransform(unsigned int spaceDimension,
25  unsigned int parametersDimension):
26  Superclass(spaceDimension, parametersDimension)
27 {
28  m_Angle = m_TranslationY = m_TranslationZ = itk::NumericTraits<ScalarType>::Zero;
29  m_ReferencePlane.SetIdentity();
30  m_InverseReferencePlane.SetIdentity();
31 
32  this->ComputeMatrix();
33 }
34 
35 // Set Parameters
36 template <class TScalarType>
37 void
39 ::SetParameters(const ParametersType & parameters)
40 {
41  m_Angle = parameters[0];
42  m_TranslationY = parameters[1];
43  m_TranslationZ = parameters[2];
44 
45  this->ComputeMatrix();
46  // Modified is always called since we just have a pointer to the
47  // parameters and cannot know if the parameters have changed.
48  this->Modified();
49 }
50 
51 
52 // Get Parameters
53 template <class TScalarType>
57 {
58  this->m_Parameters[0] = m_Angle;
59  this->m_Parameters[1] = m_TranslationY;
60  this->m_Parameters[2] = m_TranslationZ;
61 
62  return this->m_Parameters;
63 }
64 
65 // Compose
66 template <class TScalarType>
67 void
70 {
71  Superclass::SetIdentity();
72  m_Angle = m_TranslationY = m_TranslationZ = itk::NumericTraits<ScalarType>::Zero;
73 
74  this->ComputeMatrix();
75 }
76 
77 // Compute angles from the rotation matrix
78 template <class TScalarType>
79 void
82 {
83  double cosa, sina;
84 
85  cosa = std::cos(m_Angle);
86  sina = std::sin(m_Angle);
87 
88  HomogeneousMatrixType insideMatrix, resultMatrix;
89  insideMatrix.SetIdentity();
90 
91  insideMatrix[1][1] = cosa;
92  insideMatrix[1][2] = -sina;
93 
94  insideMatrix[2][1] = sina;
95  insideMatrix[2][2] = cosa;
96 
97  insideMatrix[1][3] = m_TranslationY;
98  insideMatrix[2][3] = m_TranslationZ;
99 
100  resultMatrix = m_InverseReferencePlane * insideMatrix * m_ReferencePlane;
101 
102  MatrixType linearMatrix;
103  OffsetType off;
104 
105  for (unsigned int i = 0;i < 3;++i)
106  {
107  off[i] = resultMatrix(i,3) + this->GetCenter()[i];
108  for (unsigned int j = 0;j < 3;++j)
109  {
110  off[i] -= resultMatrix(i,j) * this->GetCenter()[j];
111  linearMatrix(i,j) = resultMatrix(i,j);
112  }
113  }
114 
115  this->SetMatrix(linearMatrix);
116  this->SetOffset(off);
117 }
118 
119 template<class TScalarType>
120 void
123 {
124  // The input transforms are matrix transforms realigning each image onto the mid-sagittal plane
125  InputVectorType xAxis;
126  xAxis.Fill(0.0);
127  xAxis[0] = 1;
128 
129  MatrixType rotationMatrix = anima::GetRotationMatrixFromVectors(refPlaneNormal,xAxis);
130  for (unsigned int i = 0;i < 3;++i)
131  for (unsigned int j = 0;j < 3;++j)
132  m_ReferencePlane(i,j) = rotationMatrix(i,j);
133 
134  m_InverseReferencePlane = m_ReferencePlane.GetInverse();
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 << "Symmetry plane parameters: Angle=" << m_Angle
146  << " TranslationY=" << m_TranslationY
147  << " TranslationZ=" << m_TranslationZ
148  << std::endl;
149 }
150 
151 } // end of namespace anima
const ParametersType & GetParameters() const ITK_OVERRIDE
Superclass::InputVectorType InputVectorType
itk::MatrixOffsetTransformBase< TScalarType, 3 > Superclass
void PrintSelf(std::ostream &os, itk::Indent indent) const ITK_OVERRIDE
Superclass::ParametersType ParametersType
void SetParameters(const ParametersType &parameters) ITK_OVERRIDE
itk::Matrix< double, 3, 3 > GetRotationMatrixFromVectors(const VectorType &first_direction, const VectorType &second_direction, const unsigned int dimension)
virtual void SetIdentity() ITK_OVERRIDE
void SetReferencePlaneNormal(InputVectorType &refPlaneNormal)
itk::Matrix< ScalarType, 4, 4 > HomogeneousMatrixType