ANIMA  4.0
animaSymmetryPlaneTransform.hxx
Go to the documentation of this file.
1 #pragma once
2 
3 namespace anima
4 {
5 
6 // Constructor with default arguments
7 template <class TScalarType>
10 Superclass(ParametersDimension)
11 {
12  m_Theta = m_Phi = m_Distance = itk::NumericTraits<ScalarType>::Zero;
13 
14  m_CenterTransform.SetIdentity();
15  m_CenterTransformInv.SetIdentity();
16 
17  this->ComputeMatrix();
18 }
19 
20 // Constructor with default arguments
21 template <class TScalarType>
24  const OutputPointType & offset)
25 {
26  this->SetMatrix(matrix);
27 
28  OffsetType off;
29  off[0] = offset[0];
30  off[1] = offset[1];
31  off[2] = offset[2];
32  this->SetOffset(off);
33 }
34 
35 
36 // Constructor with arguments
37 template <class TScalarType>
39 ::SymmetryPlaneTransform(unsigned int spaceDimension,
40  unsigned int parametersDimension):
41 Superclass(spaceDimension, parametersDimension)
42 {
43  m_Theta = m_Phi = m_Distance = itk::NumericTraits<ScalarType>::Zero;
44 
45  m_CenterTransform.SetIdentity();
46  m_CenterTransformInv.SetIdentity();
47 
48  this->ComputeMatrix();
49 }
50 
51 template <class TScalarType>
52 void
55 {
56  m_CenterTransform.SetIdentity();
57  m_CenterTransformInv.SetIdentity();
58 
59  for (unsigned int i = 0;i < 3;++i)
60  {
61  m_CenterTransform(i,3) = rotCenter[i];
62  m_CenterTransformInv(i,3) = - rotCenter[i];
63  }
64 
65  this->ComputeMatrix();
66  // Modified is always called since we just have a pointer to the
67  // parameters and cannot know if the parameters have changed.
68  this->Modified();
69 }
70 
71 // Set Parameters
72 template <class TScalarType>
73 void
75 ::SetParameters( const ParametersType & parameters )
76 {
77  itkDebugMacro( << "Setting parameters " << parameters );
78 
79  // Set angles with parameters
80  m_Theta = parameters[0];
81  m_Phi = parameters[1];
82  m_Distance = parameters[2];
83 
84  this->ComputeMatrix();
85  // Modified is always called since we just have a pointer to the
86  // parameters and cannot know if the parameters have changed.
87  this->Modified();
88 
89  itkDebugMacro(<<"After setting parameters ");
90 }
91 
92 
93 // Get Parameters
94 template <class TScalarType>
97 ::GetParameters( void ) const
98 {
99  this->m_Parameters[0] = m_Theta;
100  this->m_Parameters[1] = m_Phi;
101  this->m_Parameters[2] = m_Distance;
102 
103  return this->m_Parameters;
104 }
105 
106 // Compose
107 template <class TScalarType>
108 void
111 {
112  Superclass::SetIdentity();
113  m_Theta = 0;
114  m_Phi = 0;
115  m_Distance = 0;
116 
117  this->ComputeMatrix();
118 }
119 
120 // Compute angles from the rotation matrix
121 template <class TScalarType>
122 void
125 {
126  double cosa, sina, cosb, sinb;
127 
128  cosa = std::cos(m_Theta);
129  sina = std::sin(m_Theta);
130  cosb = std::cos(m_Phi);
131  sinb = std::sin(m_Phi);
132 
133  double d = m_Distance;
134 
135  HomogeneousMatrixType rotationMatrix;
136  rotationMatrix.SetIdentity();
137 
138  rotationMatrix[0][0] = 1-2*cosb*cosb*cosa*cosa;
139  rotationMatrix[0][1] = -2*cosb*sinb*cosa*cosa;
140  rotationMatrix[0][2] = -2*cosb*cosa*sina;
141 
142  rotationMatrix[1][0] = rotationMatrix[0][1];
143  rotationMatrix[1][1] = 1-2*sinb*sinb*cosa*cosa;
144  rotationMatrix[1][2] = -2*sinb*cosa*sina;
145 
146  rotationMatrix[2][0] = rotationMatrix[0][2];
147  rotationMatrix[2][1] = rotationMatrix[1][2];
148  rotationMatrix[2][2] = 1-2*sina*sina;
149 
150  rotationMatrix[0][3] = 2*d*cosb*cosa;
151  rotationMatrix[1][3] = 2*d*sinb*cosa;
152  rotationMatrix[2][3] = 2*d*sina;
153 
154  rotationMatrix = m_CenterTransform * rotationMatrix * m_CenterTransformInv;
155 
156  MatrixType linearMatrix;
157  OffsetType off;
158 
159  for (unsigned int i = 0;i < 3;++i)
160  {
161  off[i] = rotationMatrix(i,3);
162  for (unsigned int j = 0;j < 3;++j)
163  linearMatrix(i,j) = rotationMatrix(i,j);
164  }
165 
166  this->SetMatrix(linearMatrix);
167  this->SetOffset(off);
168 }
169 
170 // Print self
171 template<class TScalarType>
172 void
174 PrintSelf(std::ostream &os, itk::Indent indent) const
175 {
176  Superclass::PrintSelf(os,indent);
177 
178  os << indent << "Symmetry plane parameters: Theta=" << m_Theta
179  << " Phi=" << m_Phi
180  << " Distance=" << m_Distance
181  << " Center transform=" << m_CenterTransform
182  << std::endl;
183 }
184 
185 } // end of namespace anima
void SetRotationCenter(OutputPointType &rotCenter)
itk::MatrixOffsetTransformBase< TScalarType, 3 > Superclass
void PrintSelf(std::ostream &os, itk::Indent indent) const ITK_OVERRIDE
void SetParameters(const ParametersType &parameters) ITK_OVERRIDE
itk::Matrix< ScalarType, 4, 4 > HomogeneousMatrixType
const ParametersType & GetParameters() const ITK_OVERRIDE
Superclass::ParametersType ParametersType
Superclass::OutputPointType OutputPointType