KWStyle - itkVersorTransform.txx
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkVersorTransform.txx.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:49 $
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 _itkVersorTransform_txx
18 DEF #define _itkVersorTransform_txx
19
20 #include "itkVersorTransform.h"
21
22
23 namespace itk
24 {
25
26 // Constructor with default arguments
27 template <class TScalarType>
28 VersorTransform<TScalarType>
29 ::VersorTransform() :
30 IND **Superclass(OutputSpaceDimension, ParametersDimension)
31 {
32   m_Versor.SetIdentity();
33 }
34
35 // Constructor with default arguments
36 template<class TScalarType>
37 VersorTransform<TScalarType>::
38 VersorTransform(unsigned int spaceDimension, 
39                 unsigned int parametersDimension) :
40 IND **Superclass(spaceDimension,parametersDimension)
41 {
42   m_Versor.SetIdentity();
43 }
44
45 // Constructor with default arguments
46 template<class TScalarType>
47 VersorTransform<TScalarType>::
48 VersorTransform(const MatrixType & matrix,
49                 const OutputVectorType & offset) :
50 IND **Superclass(matrix, offset)
51 {
52   this->ComputeMatrixParameters();  // called in MatrixOffset baseclass
53 }
54
55 // Set Parameters
56 template <class TScalarType>
57 void
58 VersorTransform<TScalarType>
59 ::SetParameters( const ParametersType & parameters )
60 {
61   itkDebugMacro( << "Setting paramaters " << parameters );
62
63   // Transfer the versor part
64   AxisType rightPart;
65
66   rightPart[0] = parameters[0];
67   rightPart[1] = parameters[1];
68   rightPart[2] = parameters[2];
69
70   // The versor will compute the scalar part.
71   m_Versor.Set( rightPart ); 
72
73   itkDebugMacro( <<"Versor is now " << m_Versor );
74   
75   this->ComputeMatrix();
76
77   itkDebugMacro(<<"After setting paramaters ");
78 }
79
80 // Set Parameters
81 template <class TScalarType>
82 const typename VersorTransform<TScalarType>::ParametersType & 
83 VersorTransform<TScalarType>
84 ::GetParameters( void ) const
85 {
86   this->m_Parameters[0] = this->m_Versor.GetRight()[0];
87   this->m_Parameters[1] = this->m_Versor.GetRight()[1];
88   this->m_Parameters[2] = this->m_Versor.GetRight()[2];
89
90   return this->m_Parameters;
91 }
92
93
94 // Set Rotational Part
95 template <class TScalarType>
96 void
97 VersorTransform<TScalarType>
98 ::SetRotation( const VersorType & versor )
99 {
100   m_Versor = versor;
101   this->ComputeMatrix();
102   this->ComputeOffset();
103 }
104
105
106 EML
107 // Set Rotational Part
108 template <class TScalarType>
109 void
110 VersorTransform<TScalarType>
111 ::SetRotation( const AxisType & axis, AngleType  angle )
112 {
113   m_Versor.Set( axis, angle );
114   this->ComputeMatrix();
115   this->ComputeOffset();
116 }
117
118 // Set Identity 
119 template <class TScalarType>
120 void
121 VersorTransform<TScalarType>
122 ::SetIdentity( )
123 {
124   Superclass::SetIdentity();
125
126   m_Versor.SetIdentity();
127 }
128
129
130 // Compute the matrix
131 template <class TScalarType>
132 void
133 VersorTransform<TScalarType>
134 ::ComputeMatrix( void )
135 {
136
137   const TScalarType vx = m_Versor.GetX();
138   const TScalarType vy = m_Versor.GetY();
139   const TScalarType vz = m_Versor.GetZ();
140   const TScalarType vw = m_Versor.GetW();
141       
142   const TScalarType xx = vx * vx;
143   const TScalarType yy = vy * vy;
144   const TScalarType zz = vz * vz;
145   const TScalarType xy = vx * vy;
146   const TScalarType xz = vx * vz;
147   const TScalarType xw = vx * vw;
148   const TScalarType yz = vy * vz;
149   const TScalarType yw = vy * vw;
150   const TScalarType zw = vz * vw;
151
152   MatrixType newMatrix;
153   newMatrix[0][0] = 1.0 - 2.0 * ( yy + zz );
154   newMatrix[1][1] = 1.0 - 2.0 * ( xx + zz );
155   newMatrix[2][2] = 1.0 - 2.0 * ( xx + yy );
156   newMatrix[0][1] = 2.0 * ( xy - zw );
157   newMatrix[0][2] = 2.0 * ( xz + yw );
158   newMatrix[1][0] = 2.0 * ( xy + zw );
159   newMatrix[2][0] = 2.0 * ( xz - yw );
160   newMatrix[2][1] = 2.0 * ( yz + xw );
161   newMatrix[1][2] = 2.0 * ( yz - xw );
162   this->SetVarMatrix(newMatrix);
163 }
164
165 // Compute the matrix
166 template <class TScalarType>
167 void
168 VersorTransform<TScalarType>
169 ::ComputeMatrixParameters( void )
170 {
171   m_Versor.Set( this->GetMatrix() );
172 }
173
174 // Set parameters
175 template<class TScalarType>
176 const typename VersorTransform<TScalarType>::JacobianType &
177 VersorTransform<TScalarType>::
178 GetJacobian( const InputPointType & p ) const
179 {
180   typedef typename VersorType::ValueType  ValueType;
181
182   // compute derivatives with respect to rotation
183   const ValueType vx = m_Versor.GetX();
184   const ValueType vy = m_Versor.GetY();
185   const ValueType vz = m_Versor.GetZ();
186   const ValueType vw = m_Versor.GetW();
187
188   this->m_Jacobian.Fill(0.0);
189
190   const double px = p[0];
191   const double py = p[1];
192   const double pz = p[2];
193
194   const double vxx = vx * vx;
195   const double vyy = vy * vy;
196   const double vzz = vz * vz;
197   const double vww = vw * vw;
198
199   const double vxy = vx * vy;
200   const double vxz = vx * vz;
201   const double vxw = vx * vw;
202
203   const double vyz = vy * vz;
204   const double vyw = vy * vw;
205
206   const double vzw = vz * vw;
207
208
209   // compute Jacobian with respect to quaternion parameters
210   this->m_Jacobian[0][0] = 2.0 * (               (vyw+vxz)*py + (vzw-vxy)*pz)
211 IND *************************/ vw;
212   this->m_Jacobian[1][0] = 2.0 * ((vyw-vxz)*px   -2*vxw   *py + (vxx-vww)*pz) 
213 IND *************************/ vw;
214   this->m_Jacobian[2][0] = 2.0 * ((vzw+vxy)*px + (vww-vxx)*py   -2*vxw   *pz) 
215 IND *************************/ vw;
216
217   this->m_Jacobian[0][1] = 2.0 * ( -2*vyw  *px + (vxw+vyz)*py + (vww-vyy)*pz) 
218 IND *************************/ vw;
219   this->m_Jacobian[1][1] = 2.0 * ((vxw-vyz)*px                + (vzw+vxy)*pz) 
220 IND *************************/ vw;
221   this->m_Jacobian[2][1] = 2.0 * ((vyy-vww)*px + (vzw-vxy)*py   -2*vyw   *pz) 
222 IND *************************/ vw;
223
224   this->m_Jacobian[0][2] = 2.0 * ( -2*vzw  *px + (vzz-vww)*py + (vxw-vyz)*pz) 
225 IND *************************/ vw;
226   this->m_Jacobian[1][2] = 2.0 * ((vww-vzz)*px   -2*vzw   *py + (vyw+vxz)*pz) 
227 IND *************************/ vw;
228   this->m_Jacobian[2][2] = 2.0 * ((vxw+vyz)*px + (vyw-vxz)*py               ) 
229 IND *************************/ vw;
230   return this->m_Jacobian;
231
232 }
233   
234 // Print self
235 template<class TScalarType>
236 void
237 VersorTransform<TScalarType>::
238 PrintSelf(std::ostream &os, Indent indent) const
239 {
240
241   Superclass::PrintSelf(os,indent);
242   
243   os << indent << "Versor: " << m_Versor  << std::endl;
244 }
245
246 // namespace
247
248 #endif
249

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