KWStyle - itkCenteredSimilarity2DTransform.txx
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkCenteredSimilarity2DTransform.txx.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:33 $
7   Version:   $Revision: 1.4 $
8
9   Copyright (c) Insight Software Consortium. All rights reserved.
10   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12      This software is distributed WITHOUT ANY WARRANTY; without even 
13      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14      PURPOSE.  See the above copyright notices for more information.
15
16 =========================================================================*/
17 DEF #ifndef _itkCenteredSimilarity2DTransform_txx
18 DEF #define _itkCenteredSimilarity2DTransform_txx
19
20 #include "itkCenteredSimilarity2DTransform.h"
21
22
23 namespace itk
24 {
25
26 // Constructor with default arguments
27 template <class TScalarType>
28 CenteredSimilarity2DTransform<TScalarType>
29 LEN ::CenteredSimilarity2DTransform():Superclass(OutputSpaceDimension, ParametersDimension)
30 {
31 }
32
33
34 // Constructor with arguments
35 template<class TScalarType>
36 CenteredSimilarity2DTransform<TScalarType>::
37 CenteredSimilarity2DTransform( unsigned int spaceDimension, 
38                   unsigned int parametersDimension):
39 IND **Superclass(spaceDimension,parametersDimension)
40 {
41
42 }
43
44
45 // Set Parameters
46 template <class TScalarType>
47 void
48 CenteredSimilarity2DTransform<TScalarType>
49 ::SetParameters( const ParametersType & parameters )
50 {
51   itkDebugMacro( << "Setting paramaters " << parameters );
52
53   // Set scale
54   this->SetVarScale(parameters[0]);
55  
56   // Set angle
57   this->SetVarAngle( parameters[1] );
58
59   InputPointType center;
60   for(unsigned int j=0; j < SpaceDimension; j++) 
61     {
62     center[j] = parameters[j+2];
63     }
64   this->SetVarCenter( center );
65
66   // Set translation
67   OffsetType translation;
68   for(unsigned int i=0; i < SpaceDimension; i++) 
69     {
70     translation[i] = parameters[i+4];
71     }
72
73   this->SetVarTranslation( translation );
74
75   this->ComputeMatrix();
76   this->ComputeOffset();
77
78   itkDebugMacro(<<"After setting paramaters ");
79 }
80
81
82 // Get Parameters
83 template <class TScalarType>
84 const typename CenteredSimilarity2DTransform<TScalarType>::ParametersType &
85 CenteredSimilarity2DTransform<TScalarType>
86 ::GetParameters( void ) const
87 {
88   itkDebugMacro( << "Getting parameters ");
89
90   this->m_Parameters[0] = this->GetScale();
91   this->m_Parameters[1] = this->GetAngle();
92  
93   InputPointType center = this->GetCenter();
94   for(unsigned int j=0; j < SpaceDimension; j++) 
95     {
96     this->m_Parameters[j+2] = center[j];
97     }
98
99   OffsetType translation = this->GetTranslation();
100   for(unsigned int i=0; i < SpaceDimension; i++) 
101     {
102     this->m_Parameters[i+4] = translation[i];
103     }
104
105   itkDebugMacro(<<"After getting parameters " << this->m_Parameters );
106
107   return this->m_Parameters;
108 }
109
110 // Compute the Jacobian
111 template<class TScalarType>
112 const typename CenteredSimilarity2DTransform<TScalarType>::JacobianType &
113 CenteredSimilarity2DTransform<TScalarType>::
114 GetJacobian( const InputPointType & p ) const
115 {
116   const double angle = this->GetAngle();
117   const double ca = cos( angle );
118   const double sa = sin( angle );
119
120   this->m_Jacobian.Fill(0.0);
121
122   const InputPointType center = this->GetCenter();  
123   const double cx = center[0];
124   const double cy = center[1];
125
126   const OutputVectorType translation = this->GetTranslation();
127
128   // derivatives with respect to the scale
129   this->m_Jacobian[0][0] =    ca * ( p[0] - cx ) - sa * ( p[1] - cy );
130   this->m_Jacobian[1][0] =    sa * ( p[0] - cx ) + ca * ( p[1] - cy ); 
131
132   // derivatives with respect to the angle
133 LEN   this->m_Jacobian[0][1] = ( -sa * ( p[0] - cx ) - ca * ( p[1] - cy ) ) * this->GetScale();
134 LEN   this->m_Jacobian[1][1] = (  ca * ( p[0] - cx ) - sa * ( p[1] - cy ) ) * this->GetScale();
135
136   // compute derivatives with respect to the center part
137   // first with respect to cx
138   this->m_Jacobian[0][2] = 1.0 - ca * this->GetScale();
139   this->m_Jacobian[1][2] =     - sa * this->GetScale();
140   // then with respect to cy
141   this->m_Jacobian[0][3] =       sa * this->GetScale();
142   this->m_Jacobian[1][3] = 1.0 - ca * this->GetScale();
143
144   // compute derivatives with respect to the translation part
145   // first with respect to tx
146   this->m_Jacobian[0][4] = 1.0;
147   this->m_Jacobian[1][4] = 0.0;
148   // first with respect to ty
149   this->m_Jacobian[0][5] = 0.0;
150   this->m_Jacobian[1][5] = 1.0;
151
152   return this->m_Jacobian;
153
154 }
155
156 template <class TScalarType>
157 void
158 CenteredSimilarity2DTransform<TScalarType>::
159 SetFixedParameters( const ParametersType & itkNotUsed(parameters) )
160 {
161 IND *// no fixed parameters
162 }
163
164 template <class TScalarType>
165 const typename CenteredSimilarity2DTransform<TScalarType>::ParametersType &
166 CenteredSimilarity2DTransform<TScalarType>::
167 GetFixedParameters( void ) const
168 {
169   // return dummy parameters
170   this->m_FixedParameters.SetSize(0);
171   return this->m_FixedParameters;
172 }
173  
174 // Print self
175 template<class TScalarType>
176 void
177 CenteredSimilarity2DTransform<TScalarType>::
178 PrintSelf(std::ostream &os, Indent indent) const
179 {
180   Superclass::PrintSelf(os,indent);
181 }
182
183 // Create and return an inverse transformation
184 template<class TScalarType>
185 void
186 CenteredSimilarity2DTransform<TScalarType>::
187 CloneInverseTo( Pointer & result ) const
188 {
189   result = New();
190   result->SetCenter( this->GetCenter() );  // inverse have the same center
191   result->SetScale( 1.0 / this->GetScale() );
192   result->SetAngle( -this->GetAngle() );
193 LEN   result->SetTranslation( -( this->GetInverseMatrix() * this->GetTranslation() ) );
194 }
195
196 // Create and return a clone of the transformation
197 template<class TScalarType>
198 void
199 CenteredSimilarity2DTransform<TScalarType>::
200 CloneTo( Pointer & result ) const
201 {
202   result = New();
203   result->SetCenter( this->GetCenter() );
204   result->SetScale( this->GetScale() );
205   result->SetAngle( this->GetAngle() );
206   result->SetTranslation( this->GetTranslation() );
207 }
208
209 // namespace
210
211 #endif
212

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:01PM
© Kitware Inc.