KWStyle - itkScaleTransform.txx
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkScaleTransform.txx.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:47 $
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 _itkScaleTransform_txx
18 DEF #define _itkScaleTransform_txx
19
20 #include "itkScaleTransform.h"
21
22
23 namespace itk
24 {
25
26 // Constructor with default arguments
27 template<class ScalarType, unsigned int NDimensions>
28 ScaleTransform<ScalarType, NDimensions>::
29 ScaleTransform():Superclass(SpaceDimension,ParametersDimension)
30 {
31   m_Scale.Fill( 1.0 );
32   m_Center.Fill( 0.0 );
33 }
34     
35
36
37 // Destructor
38 template<class ScalarType, unsigned int NDimensions>
39 ScaleTransform<ScalarType, NDimensions>::
40 ~ScaleTransform()
41 {
42   return;
43 }
44
45
46 // Set the parameters
47 template <class ScalarType, unsigned int NDimensions>
48 void
49 ScaleTransform<ScalarType, NDimensions>
50 ::SetParameters( const ParametersType & parameters )
51 {
52   for( unsigned int i=0; i<SpaceDimension; i++ )
53     {
54     m_Scale[i] = parameters[i];
55     }
56   this->m_Parameters = parameters;
57 }
58
59
60 // Get Parameters
61 template <class TScalarType,unsigned int NDimensions>
62 const typename ScaleTransform<TScalarType,NDimensions>::ParametersType &
63 ScaleTransform<TScalarType,NDimensions>
64 ::GetParameters( void ) const
65 {
66   itkDebugMacro( << "Getting parameters ");
67
68   // Transfer the translation part
69   for(unsigned int i=0; i < SpaceDimension; i++) 
70     {
71     this->m_Parameters[i] = m_Scale[i];
72     }
73
74   itkDebugMacro(<<"After getting parameters " << this->m_Parameters );
75
76   return this->m_Parameters;
77 }
78
79
80 EML
81 // Print self
82 template<class ScalarType, unsigned int NDimensions>
83 void
84 ScaleTransform<ScalarType, NDimensions>::
85 PrintSelf(std::ostream &os, Indent indent) const
86 {
87   Superclass::PrintSelf(os, indent);
88   
89   os << indent << "Scale: " << m_Scale << std::endl;
90   os << indent << "Center: " << m_Center << std::endl;
91 }
92
93
94 // Compose with another affine transformation
95 template<class ScalarType, unsigned int NDimensions>
96 void
97 ScaleTransform<ScalarType, NDimensions>::
98 Compose(const Self * other, bool )
99 {
100   for( unsigned int i=0; i<SpaceDimension; i++ )
101     {
102     m_Scale[i] *= other->m_Scale[i];
103     }
104   return;
105 }
106
107
108 // Compose with a scale
109 template<class ScalarType, unsigned int NDimensions>
110 void
111 ScaleTransform<ScalarType, NDimensions>::
112 Scale(const ScaleType & scale, bool )
113 {
114   for( unsigned int i=0; i<SpaceDimension; i++ )
115     {
116     m_Scale[i] *= scale[i];
117     }
118   return;
119 }
120
121
122 EML
123 // Transform a point
124 template<class ScalarType, unsigned int NDimensions>
125 typename ScaleTransform<ScalarType, NDimensions>::OutputPointType
126 ScaleTransform<ScalarType, NDimensions>::
127 TransformPoint(const InputPointType &point) const 
128 {
129   OutputPointType result;
130   for( unsigned int i=0; i<SpaceDimension; i++ )
131     {
132     result[i] = ( point[i] - m_Center[i] ) * m_Scale[i] + m_Center[i];
133     }
134   return result;
135 }
136
137
138 // Transform a vector
139 template<class ScalarType, unsigned int NDimensions>
140 typename ScaleTransform<ScalarType, NDimensions>::OutputVectorType
141 ScaleTransform<ScalarType, NDimensions>::
142 TransformVector(const InputVectorType &vect) const 
143 {
144   OutputVectorType result;
145   for( unsigned int i=0; i<SpaceDimension; i++ )
146     {
147     result[i] = vect[i] * m_Scale[i];
148     }
149   return result;
150 }
151
152
153 // Transform a vnl_vector_fixed
154 template<class ScalarType, unsigned int NDimensions>
155 typename ScaleTransform<ScalarType, NDimensions>::OutputVnlVectorType
156 ScaleTransform<ScalarType, NDimensions>::
157 TransformVector(const InputVnlVectorType &vect) const 
158 {
159   OutputVnlVectorType result;
160   for( unsigned int i=0; i<SpaceDimension; i++ )
161     {
162     result[i] = vect[i] * m_Scale[i];
163     }
164   return result;
165 }
166
167
168 // Transform a CovariantVector
169 template<class ScalarType, unsigned int NDimensions>
170 typename ScaleTransform<ScalarType, NDimensions>::OutputCovariantVectorType
171 ScaleTransform<ScalarType, NDimensions>::
172 TransformCovariantVector(const InputCovariantVectorType &vect) const 
173 {
174   // Covariant Vectors are scaled by the inverse
175   OutputCovariantVectorType result;
176   for( unsigned int i=0; i<SpaceDimension; i++ )
177     {
178     result[i] = vect[i] / m_Scale[i];
179     }
180   return result;
181 }
182
183
184 EML
185 // Back transform a point
186 template<class ScalarType, unsigned int NDimensions>
187 typename ScaleTransform<ScalarType, NDimensions>::InputPointType
188 ScaleTransform<ScalarType, NDimensions>::
189 BackTransform(const OutputPointType &point) const {
190   InputPointType result;
191   for( unsigned int i=0; i<SpaceDimension; i++ )
192     {
193     result[i] = ( point[i] + m_Center[i] ) / m_Scale[i] - m_Center[i]; 
194     }
195   return result;
196 }
197
198
199 EML
200 EML
201 // Back transform a vector
202 template<class ScalarType, unsigned int NDimensions>
203 typename ScaleTransform<ScalarType, NDimensions>::InputVectorType
204 ScaleTransform<ScalarType, NDimensions>::
205 BackTransform(const OutputVectorType &vect ) const 
206 {
207   InputVectorType result;
208   for( unsigned int i=0; i<SpaceDimension; i++ )
209     {
210     result[i] = vect[i] / m_Scale[i];
211     }
212   return result;
213 }
214
215
216 EML
217 EML
218 // Back transform a vnl_vector
219 template<class ScalarType, unsigned int NDimensions>
220 typename ScaleTransform<ScalarType, NDimensions>::InputVnlVectorType
221 ScaleTransform<ScalarType, NDimensions>::
222 BackTransform(const OutputVnlVectorType &vect ) const 
223 {
224   InputVnlVectorType result;
225   for( unsigned int i=0; i<SpaceDimension; i++ )
226     {
227     result[i] = vect[i] / m_Scale[i];
228     }
229   return result;
230 }
231
232
233 // Back Transform a CovariantVector
234 template<class ScalarType, unsigned int NDimensions>
235 typename ScaleTransform<ScalarType, NDimensions>::InputCovariantVectorType
236 ScaleTransform<ScalarType, NDimensions>::
237 BackTransform(const OutputCovariantVectorType &vect) const 
238 {
239   // Covariant Vectors are scaled by the inverse
240   InputCovariantVectorType result;
241   for( unsigned int i=0; i<SpaceDimension; i++ )
242     {
243     result[i] = vect[i] * m_Scale[i];
244     }
245   return result;
246 }
247
248 // Create and return an inverse transformation
249 template<class ScalarType, unsigned int NDimensions>
250 bool 
251 ScaleTransform<ScalarType, NDimensions>::
252 GetInverse(Self* inverse) const
253 {
254   if(!inverse)
255     {
256     return false;
257     }
258
259   for( unsigned int i=0; i<SpaceDimension; i++ )
260     {
261     inverse->m_Scale[i] = 1.0 / m_Scale[i];
262     }
263
264   return true;
265 }
266
267
268 // Compute the Jacobian of the transformation
269 // It follows the same order of Parameters vector 
270 template<class ScalarType, unsigned int NDimensions>
271 const typename ScaleTransform<ScalarType, NDimensions>::JacobianType &
272 ScaleTransform<ScalarType, NDimensions>
273 ::GetJacobian( const InputPointType & p ) const
274 {
275   
276   this->m_Jacobian.Fill(0);
277   for(unsigned int dim=0; dim<SpaceDimension; dim++)
278     {
279     this->m_Jacobian(dim,dim) = p[dim];
280     }
281   return this->m_Jacobian;
282 }
283
284
285 // namespace
286
287 #endif
288

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