KWStyle - itkVersorRigid3DTransform.txx
 
Matrix View
Description

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

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