KWStyle - itkSimilarity3DTransform.txx
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkSimilarity3DTransform.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 _itkSimilarity3DTransform_txx
18 DEF #define _itkSimilarity3DTransform_txx
19
20 #include "itkSimilarity3DTransform.h"
21
22
23 namespace itk
24 {
25
26 // Constructor with default arguments
27 template <class TScalarType>
28 Similarity3DTransform<TScalarType>
29 ::Similarity3DTransform() :
30 IND **Superclass(OutputSpaceDimension, ParametersDimension)
31 {
32   m_Scale = 1.0;
33 }
34
35
36 // Constructor with arguments
37 template<class TScalarType>
38 Similarity3DTransform<TScalarType>::
39 Similarity3DTransform( unsigned int outputSpaceDim, 
40                         unsigned int paramDim) :
41 IND **Superclass(outputSpaceDim,paramDim)
42 {
43 }
44  
45
46 // Constructor with arguments
47 template<class TScalarType>
48 Similarity3DTransform<TScalarType>::
49 Similarity3DTransform( const MatrixType & matrix,
50                         const OutputVectorType & offset) :
51 IND **Superclass(matrix,offset)
52 {
53 }
54  
55
56 // Set the scale factor
57 template <class TScalarType>
58 void
59 Similarity3DTransform<TScalarType>
60 ::SetScale( ScaleType scale )
61 {
62 IND ***m_Scale = scale;
63 IND ***this->ComputeMatrix();
64 }
65
66
67 // Set Parameters
68 template <class TScalarType>
69 void
70 Similarity3DTransform<TScalarType>
71 ::SetParameters( const ParametersType & parameters )
72 {
73
74
75   itkDebugMacro( << "Setting paramaters " << parameters );
76
77   // Transfer the versor part
78   
79   AxisType axis;
80
81   double norm = parameters[0]*parameters[0];
82   axis[0] = parameters[0];
83   norm += parameters[1]*parameters[1];
84   axis[1] = parameters[1];
85   norm += parameters[2]*parameters[2];
86   axis[2] = parameters[2];
87   if( norm > 0)
88     {
89     norm = sqrt(norm);
90     }
91
92   double epsilon = 1e-10;
93   if(norm >= 1.0-epsilon)
94     {
95     axis = axis / (norm+epsilon*norm);
96     }
97   VersorType newVersor;
98   newVersor.Set(axis);
99   this->SetVarVersor( newVersor );
100   m_Scale = parameters[6]; // must be set before calling ComputeMatrix();
101   this->ComputeMatrix();
102
103   itkDebugMacro( <<"Versor is now " << this->GetVersor() );
104   
105    
106   // Transfer the translation part
107   TranslationType newTranslation;
108   newTranslation[0] = parameters[3];
109   newTranslation[1] = parameters[4];
110   newTranslation[2] = parameters[5];
111   this->SetVarTranslation(newTranslation);
112   this->ComputeOffset();
113
114   itkDebugMacro(<<"After setting paramaters ");
115 }
116
117
118 //
119 // Get Parameters
120 // 
121 // Parameters are ordered as:
122 //
123 // p[0:2] = right part of the versor (axis times sin(t/2))
124 // p[3:5} = translation components
125 // p[6:6} = scaling factor (isotropic)
126 //
127
128 template <class TScalarType>
129 IND const typename Similarity3DTransform<TScalarType>::ParametersType &
130 IND Similarity3DTransform<TScalarType>
131 IND ::GetParameters( void ) const
132 IND {
133 IND **itkDebugMacro( << "Getting parameters ");
134
135   this->m_Parameters[0] = this->GetVersor().GetX();
136 IND **this->m_Parameters[1] = this->GetVersor().GetY();
137 IND **this->m_Parameters[2] = this->GetVersor().GetZ();
138
139 IND **// Transfer the translation
140 IND **this->m_Parameters[3] = this->GetTranslation()[0];
141 IND **this->m_Parameters[4] = this->GetTranslation()[1];
142 IND **this->m_Parameters[5] = this->GetTranslation()[2];
143
144 IND **this->m_Parameters[6] = this->GetScale();
145
146 IND **itkDebugMacro(<<"After getting parameters " << this->m_Parameters );
147
148 IND **return this->m_Parameters;
149 IND }
150
151 IND // Set parameters
152 IND template<class TScalarType>
153 IND const typename Similarity3DTransform<TScalarType>::JacobianType &
154 IND Similarity3DTransform<TScalarType>::
155 IND GetJacobian( const InputPointType & p ) const
156 IND {
157 IND **typedef typename VersorType::ValueType  ValueType;
158
159 IND **// compute derivatives with respect to rotation
160 IND **const ValueType vx = this->GetVersor().GetX();
161 IND **const ValueType vy = this->GetVersor().GetY();
162 IND **const ValueType vz = this->GetVersor().GetZ();
163 IND **const ValueType vw = this->GetVersor().GetW();
164
165 IND **this->m_Jacobian.Fill(0.0);
166
167 IND **const InputVectorType pp = p - this->GetCenter();
168
169 IND **const double px = pp[0];
170 IND **const double py = pp[1];
171 IND **const double pz = pp[2];
172
173 IND **const double vxx = vx * vx;
174 IND **const double vyy = vy * vy;
175 IND **const double vzz = vz * vz;
176 IND **const double vww = vw * vw;
177
178 IND **const double vxy = vx * vy;
179 IND **const double vxz = vx * vz;
180 IND **const double vxw = vx * vw;
181
182 IND **const double vyz = vy * vz;
183 IND **const double vyw = vy * vw;
184
185 IND **const double vzw = vz * vw;
186
187
188 IND **// compute Jacobian with respect to quaternion parameters
189 IND **this->m_Jacobian[0][0] = 2.0 * (               (vyw+vxz)*py + (vzw-vxy)*pz)
190 IND *************************/ vw;
191 IND **this->m_Jacobian[1][0] = 2.0 * ((vyw-vxz)*px   -2*vxw   *py + (vxx-vww)*pz) 
192 IND *************************/ vw;
193 IND **this->m_Jacobian[2][0] = 2.0 * ((vzw+vxy)*px + (vww-vxx)*py   -2*vxw   *pz) 
194 IND *************************/ vw;
195
196 IND **this->m_Jacobian[0][1] = 2.0 * ( -2*vyw  *px + (vxw+vyz)*py + (vww-vyy)*pz) 
197 IND *************************/ vw;
198 IND **this->m_Jacobian[1][1] = 2.0 * ((vxw-vyz)*px                + (vzw+vxy)*pz) 
199 IND *************************/ vw;
200 IND **this->m_Jacobian[2][1] = 2.0 * ((vyy-vww)*px + (vzw-vxy)*py   -2*vyw   *pz) 
201 IND *************************/ vw;
202
203 IND **this->m_Jacobian[0][2] = 2.0 * ( -2*vzw  *px + (vzz-vww)*py + (vxw-vyz)*pz) 
204 IND *************************/ vw;
205 IND **this->m_Jacobian[1][2] = 2.0 * ((vww-vzz)*px   -2*vzw   *py + (vyw+vxz)*pz) 
206 IND *************************/ vw;
207 IND **this->m_Jacobian[2][2] = 2.0 * ((vxw+vyz)*px + (vyw-vxz)*py               ) 
208 IND *************************/ vw;
209
210 IND **// compute Jacobian with respect to the translation parameters
211 IND **this->m_Jacobian[0][3] = 1.0;
212 IND **this->m_Jacobian[1][4] = 1.0;
213 IND **this->m_Jacobian[2][5] = 1.0;
214
215 IND **// compute Jacobian with respect to the scale parameter
216 IND **const MatrixType & matrix = this->GetMatrix();
217
218 IND **const InputVectorType mpp = matrix * pp;
219
220 IND **this->m_Jacobian[0][6] = mpp[0] / m_Scale;
221 IND **this->m_Jacobian[1][6] = mpp[1] / m_Scale;
222 IND **this->m_Jacobian[2][6] = mpp[2] / m_Scale;
223
224 IND **return this->m_Jacobian;
225
226 IND }
227  
228
229 IND // Set the scale factor
230 IND template <class TScalarType>
231 IND void
232 IND Similarity3DTransform<TScalarType>
233 IND ::ComputeMatrix()
234 IND {
235 IND **this->Superclass::ComputeMatrix();
236 IND **MatrixType newMatrix = this->GetMatrix();
237 IND **newMatrix *= m_Scale;
238 IND **this->SetVarMatrix(newMatrix);
239 IND }
240
241  
242 IND // Print self
243 IND template<class TScalarType>
244 IND void
245 IND Similarity3DTransform<TScalarType>::
246 IND PrintSelf(std::ostream &os, Indent indent) const
247 IND {
248 IND **Superclass::PrintSelf(os,indent);
249 IND **os << indent << "Scale = " << m_Scale << std::endl;
250 IND }
251
252 IND // namespace
253
254 #endif
255

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