KWStyle - itkCenteredRigid2DTransform.txx
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkCenteredRigid2DTransform.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 _itkCenteredRigid2DTransform_txx
18 DEF #define _itkCenteredRigid2DTransform_txx
19
20 #include "itkCenteredRigid2DTransform.h"
21
22
23 namespace itk
24 {
25
26 // Constructor with default arguments
27 template <class TScalarType>
28 CenteredRigid2DTransform<TScalarType>
29 ::CenteredRigid2DTransform():
30 IND **Superclass(OutputSpaceDimension, ParametersDimension)
31 {
32 }
33
34 // Constructor with arguments
35 template<class TScalarType>
36 CenteredRigid2DTransform<TScalarType>::
37 CenteredRigid2DTransform( unsigned int spaceDimension, 
38                           unsigned int parametersDimension):
39 IND **Superclass(spaceDimension,parametersDimension)
40 {
41 }
42
43 //
44 // Set Parameters
45 // 
46 // Parameters are ordered as:
47 //
48 // p[0]   = angle
49 // p[1:2} = center of rotation coordinates
50 // p[3:4} = translation components
51 IND //
52 IND //
53 IND template <class TScalarType>
54 IND void
55 IND CenteredRigid2DTransform<TScalarType>
56 IND ::SetParameters( const ParametersType & parameters )
57 IND {
58 IND **itkDebugMacro( << "Setting paramaters " << parameters );
59
60   this->m_Parameters = parameters;
61
62 IND **// Set the angle
63 IND **this->SetVarAngle( parameters[0] );
64 IND **// Set the center
65 IND **InputPointType center;
66 IND **for(unsigned int i=0; i < SpaceDimension; i++) 
67     {
68     center[i] = parameters[i+1];
69     }
70   this->SetVarCenter( center );
71   
72 IND **// Set the translation
73 IND **OutputVectorType translation;
74 IND **for(unsigned int j=0; j < SpaceDimension; j++) 
75     {
76     translation[j] = parameters[j+1+SpaceDimension];
77     }
78   this->SetVarTranslation( translation );
79
80 IND **// Update matrix and offset
81 IND **this->ComputeMatrix();
82 IND **this->ComputeOffset();
83
84 IND **this->Modified();
85 IND **itkDebugMacro(<<"After setting parameters ");
86 IND }
87
88 //
89 // Get Parameters
90 // 
91 // Parameters are ordered as:
92 //
93 // p[0]   = angle
94 // p[1:2} = center of rotation coordinates
95 // p[3:4} = translation components
96 //
97 template <class TScalarType>
98 IND const typename CenteredRigid2DTransform<TScalarType>::ParametersType &
99 IND CenteredRigid2DTransform<TScalarType>
100 IND ::GetParameters( void ) const
101 IND {
102 IND **itkDebugMacro( << "Getting parameters ");
103
104   // Get the angle
105   this->m_Parameters[0] = this->GetAngle();
106  
107 IND **// Get the center 
108 IND **for(unsigned int i=0; i < SpaceDimension; i++) 
109     {
110     this->m_Parameters[i+1] = this->GetCenter()[i];
111 IND ****}
112
113 IND **// Get the translation
114 IND **for(unsigned int j=0; j < SpaceDimension; j++) 
115     {
116     this->m_Parameters[j+1+SpaceDimension] =this->GetTranslation()[j];
117 IND ****}
118
119 IND **itkDebugMacro(<<"After getting parameters " << this->m_Parameters );
120
121 IND **return this->m_Parameters;
122 IND }
123
124
125 EML
126 IND // Compute the transformation Jacobian
127 IND template<class TScalarType>
128 IND const typename CenteredRigid2DTransform<TScalarType>::JacobianType &
129 IND CenteredRigid2DTransform<TScalarType>::
130 IND GetJacobian( const InputPointType & p ) const
131 IND {
132 IND **const double ca = cos(this->GetAngle());
133 IND **const double sa = sin(this->GetAngle());
134
135 IND **this->m_Jacobian.Fill(0.0);
136
137 IND **const double cx = this->GetCenter()[0];
138 IND **const double cy = this->GetCenter()[1];
139
140 IND **// derivatives with respect to the angle
141 IND **this->m_Jacobian[0][0] = -sa * ( p[0] - cx ) - ca * ( p[1] - cy );
142 IND **this->m_Jacobian[1][0] =  ca * ( p[0] - cx ) - sa * ( p[1] - cy ); 
143
144 IND **// compute derivatives with respect to the center part
145 IND **// first with respect to cx
146 IND **this->m_Jacobian[0][1] = 1.0 - ca;
147 IND **this->m_Jacobian[1][1] =     - sa;  
148 IND **// then with respect to cy
149 IND **this->m_Jacobian[0][2] =       sa;
150 IND **this->m_Jacobian[1][2] = 1.0 - ca;
151
152
153 IND **// compute derivatives with respect to the translation part
154 IND **// first with respect to tx
155 IND **this->m_Jacobian[0][3] = 1.0;
156 IND **this->m_Jacobian[1][3] = 0.0;
157 IND **// first with respect to ty
158 IND **this->m_Jacobian[0][4] = 0.0;
159 IND **this->m_Jacobian[1][4] = 1.0;
160
161 IND **return this->m_Jacobian;
162
163 IND }
164
165 IND template <class TScalarType>
166 IND void
167 IND CenteredRigid2DTransform<TScalarType>
168 IND ::SetFixedParameters( const ParametersType & itkNotUsed(parameters) )
169 IND {
170 IND *// no fixed parameters
171 IND }
172
173 IND template <class TScalarType>
174 IND const typename CenteredRigid2DTransform<TScalarType>::ParametersType &
175 IND CenteredRigid2DTransform<TScalarType>
176 IND ::GetFixedParameters( void ) const
177 IND {
178 IND **// return dummy parameters
179 IND **this->m_FixedParameters.SetSize(0);
180 IND **return this->m_FixedParameters;
181 IND }
182
183   
184 IND // Create and return an inverse transformation
185 IND template<class TScalarType>
186 IND void
187 IND CenteredRigid2DTransform<TScalarType>::
188 IND CloneInverseTo( Pointer & result ) const
189 IND {
190 IND **result = New();
191 IND **result->SetCenter( this->GetCenter() );  // inverse have the same center
192 IND **result->SetAngle( -this->GetAngle() );
193 LEN,IND **result->SetTranslation( -( this->GetInverseMatrix() * this->GetTranslation() ) );
194 IND }
195
196 IND // Create and return an clone transformation
197 IND template<class TScalarType>
198 IND void
199 IND CenteredRigid2DTransform<TScalarType>::
200 IND CloneTo( Pointer & result ) const
201 IND {
202 IND **result = New();
203 IND **result->SetCenter( this->GetCenter() );
204 IND **result->SetAngle( this->GetAngle() );
205 IND **result->SetTranslation( this->GetTranslation() );
206 IND }
207
208 IND // Print self
209 IND template<class TScalarType>
210 IND void
211 IND CenteredRigid2DTransform<TScalarType>::
212 IND PrintSelf(std::ostream &os, Indent indent) const
213 IND {
214 IND **this->Superclass::PrintSelf(os,indent);
215 IND }
216
217 IND // namespace
218
219 #endif
220

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