17 #ifndef __itkRigid2DTransform_txx
18 #define __itkRigid2DTransform_txx
21 #include "vnl/algo/vnl_svd.h"
28 template<
class TScalarType>
31 Superclass(OutputSpaceDimension, ParametersDimension)
33 m_Angle = NumericTraits< TScalarType >::Zero;
38 template<
class TScalarType>
41 unsigned int parametersDimension):
44 m_Angle = NumericTraits< TScalarType >::Zero;
49 template<
class TScalarType>
57 template<
class TScalarType>
62 Superclass::PrintSelf(os,indent);
63 os << indent <<
"Angle = " << m_Angle << std::endl;
68 template<
class TScalarType>
73 itkDebugMacro(
"setting m_Matrix to " << matrix );
76 typename MatrixType::InternalMatrixType test =
77 matrix.GetVnlMatrix() * matrix.GetTranspose();
79 const double tolerance = 1e-10;
80 if( !test.is_identity( tolerance ) )
82 itk::ExceptionObject ex(__FILE__,__LINE__,
"Attempt to set a Non-Orthogonal matrix",ITK_LOCATION);
86 this->SetVarMatrix( matrix );
87 this->ComputeOffset();
88 this->ComputeMatrixParameters();
95 template <
class TScalarType>
103 p = this->GetMatrix().GetVnlMatrix();
104 vnl_svd<TScalarType> svd(p);
106 r = svd.U() * svd.V().transpose();
108 m_Angle = vcl_acos(r[0][0]);
115 if(r[1][0]-vcl_sin(m_Angle) > 0.000001)
117 itkWarningMacro(
"Bad Rotation Matrix " << this->GetMatrix() );
123 template<
class TScalarType>
130 this->SetOffset(newOffset);
131 this->ComputeTranslation();
136 template<
class TScalarType>
146 template<
class TScalarType>
156 inverse->SetCenter( this->GetCenter() );
157 inverse->SetAngle( -this->GetAngle() );
158 inverse->SetTranslation( -( this->GetInverseMatrix() * this->GetTranslation() ) );
164 template<
class TScalarType>
174 template<
class TScalarType>
180 result->SetCenter( this->GetCenter() );
181 result->SetAngle( this->GetAngle() );
182 result->SetTranslation( this->GetTranslation() );
187 template<
class TScalarType >
192 this->Superclass::SetIdentity();
193 m_Angle = NumericTraits< TScalarType >::Zero;
197 template <
class TScalarType>
203 this->ComputeMatrix();
204 this->ComputeOffset();
210 template <
class TScalarType>
215 const TScalarType angleInRadians = angle * vcl_atan(1.0) / 45.0;
216 this->SetAngle( angleInRadians );
220 template <
class TScalarType>
229 rotationMatrix[0][0]= ca; rotationMatrix[0][1]=-sa;
230 rotationMatrix[1][0]= sa; rotationMatrix[1][1]= ca;
232 this->SetVarMatrix( rotationMatrix );
237 template <
class TScalarType>
242 itkDebugMacro( <<
"Setting parameters " << parameters );
245 const TScalarType angle = parameters[0];
246 this->SetVarAngle( angle );
251 for(
unsigned int i=0; i < OutputSpaceDimension; i++)
253 translation[i] = parameters[i+1];
255 this->SetVarTranslation( translation );
258 this->ComputeMatrix();
259 this->ComputeOffset();
265 itkDebugMacro(<<
"After setting parameters ");
269 template <
class TScalarType>
274 itkDebugMacro( <<
"Getting parameters ");
277 this->m_Parameters[0] = this->GetAngle();
280 for(
unsigned int i=0; i < OutputSpaceDimension; i++)
282 this->m_Parameters[i+1] = this->GetTranslation()[i];
285 itkDebugMacro(<<
"After getting parameters " << this->m_Parameters );
287 return this->m_Parameters;
291 template<
class TScalarType>
297 const double ca = vcl_cos(this->GetAngle() );
298 const double sa = vcl_sin(this->GetAngle() );
300 this->m_Jacobian.Fill(0.0);
302 const double cx = this->GetCenter()[0];
303 const double cy = this->GetCenter()[1];
306 this->m_Jacobian[0][0] = -sa * ( p[0] - cx ) - ca * ( p[1] - cy );
307 this->m_Jacobian[1][0] = ca * ( p[0] - cx ) - sa * ( p[1] - cy );
310 unsigned int blockOffset = 1;
311 for(
unsigned int dim=0; dim < OutputSpaceDimension; dim++ )
313 this->m_Jacobian[ dim ][ blockOffset + dim ] = 1.0;
316 return this->m_Jacobian;