KWStyle - itkRigid3DPerspectiveTransform.txx
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkRigid3DPerspectiveTransform.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 _itkRigid3DPerspectiveTransform_txx
18 DEF #define _itkRigid3DPerspectiveTransform_txx
19
20 #include "itkRigid3DPerspectiveTransform.h"
21
22
23 namespace itk
24 {
25
26 // Constructor with default arguments
27 template<class TScalarType>
28 Rigid3DPerspectiveTransform<TScalarType>::
29 Rigid3DPerspectiveTransform():Superclass(SpaceDimension,ParametersDimension)
30 {
31   m_Offset.Fill( 0 );
32   m_Versor.SetIdentity();
33   m_RotationMatrix = m_Versor.GetMatrix();
34   m_FocalDistance = 1.0;
35   m_FixedOffset.Fill(0);
36   m_CenterOfRotation.Fill(0);
37   this->m_Parameters.Fill(0);
38   this->m_Parameters[3]=1; // identity versor
39 }
40  
41
42 // Destructor
43 template<class TScalarType>
44 Rigid3DPerspectiveTransform<TScalarType>::
45 ~Rigid3DPerspectiveTransform()
46 {
47
48 }
49
50
51 // Print self
52 template<class TScalarType>
53 void
54 Rigid3DPerspectiveTransform<TScalarType>::
55 PrintSelf(std::ostream &os, Indent indent) const
56 {
57   Superclass::PrintSelf(os,indent);
58
59   os << indent << "Parameters: "   << this->m_Parameters  << std::endl;
60   os << indent << "Offset: "       << m_Offset   << std::endl;
61   os << indent << "Rotation: "     << m_Versor << std::endl;
62   os << indent << "FocalDistance: "<< m_FocalDistance << std::endl;
63   os << indent << "RotationMatrix: " << m_RotationMatrix   << std::endl;
64   os << indent << "FixedOffset: " << m_FixedOffset   << std::endl;
65   os << indent << "CenterOfRotation: " << m_CenterOfRotation   << std::endl;
66 }
67
68
69 // Set Parameters
70 template <class TScalarType>
71 void
72 Rigid3DPerspectiveTransform<TScalarType>
73 ::SetParameters( const ParametersType & parameters )
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   
98   m_Versor.Set(axis);
99
100   itkDebugMacro( <<"Versor is now " << this->GetRotation() );
101
102   // Transfer the translation part
103   OffsetType offset;
104   for(unsigned int i=0; i < SpaceDimension; i++) 
105     { 
106     offset[i] = parameters[i+3];
107     }
108
109   this->SetOffset( offset );
110
111   this->ComputeMatrix();
112 }
113
114
115 EML
116 EML
117 // Set Parameters
118 template <class TScalarType>
119 const typename Rigid3DPerspectiveTransform<TScalarType>::ParametersType &
120 Rigid3DPerspectiveTransform<TScalarType>
121 ::GetParameters() const
122 {
123   itkDebugMacro( << "Getting parameters ");
124
125   this->m_Parameters[0] = this->GetRotation().GetX();
126   this->m_Parameters[1] = this->GetRotation().GetY();
127   this->m_Parameters[2] = this->GetRotation().GetZ();
128
129   // Transfer the translation
130   this->m_Parameters[3] = this->GetOffset()[0];
131   this->m_Parameters[4] = this->GetOffset()[1];
132   this->m_Parameters[5] = this->GetOffset()[2];
133
134   itkDebugMacro(<<"After getting parameters " << this->m_Parameters );
135
136   return this->m_Parameters;
137 }
138
139
140 EML
141 // Set rotation
142 template<class TScalarType>
143 void
144 Rigid3DPerspectiveTransform<TScalarType>::
145 SetRotation(const VersorType &rotation )
146 {
147   m_Versor          = rotation;
148   m_RotationMatrix  = m_Versor.GetMatrix();
149   return;
150 }
151
152
153 // Set rotation
154 template<class TScalarType>
155 void
156 Rigid3DPerspectiveTransform<TScalarType>::
157 SetRotation(const Vector<TScalarType,3> & axis, double angle )
158 {
159   const double sinus   = sin(angle/2.0);
160   const double cosinus = cos(angle/2.0);
161   Vector<TScalarType,3> norm;
162   norm = axis;
163   norm.Normalize();
164   norm *= sinus;
165   VnlQuaternionType q;
166
167   q[0] = cosinus;
168   q[1] = norm[0];
169   q[2] = norm[1];
170   q[3] = norm[2]; 
171  
172
173   VersorType v;
174   v.Set(q);
175   this->SetRotation(v);
176 }
177
178
179 // Transform a point
180 template<class TScalarType>
181 typename Rigid3DPerspectiveTransform<TScalarType>::OutputPointType
182 Rigid3DPerspectiveTransform<TScalarType>::
183 TransformPoint(const InputPointType &point) const 
184 {
185   unsigned int i;
186   InputPointType centered;
187   for(i=0;i<3;i++)
188     { 
189     centered[i] = point[i] - m_CenterOfRotation[i];
190     }
191
192   InputPointType rotated =  m_RotationMatrix * centered;
193
194   InputPointType rigided;
195   for(i=0;i<3;i++)
196     { 
197     rigided[i] = rotated[i] + m_Offset[i] + m_CenterOfRotation[i] 
198       + m_FixedOffset[i];
199     }
200
201   OutputPointType result;
202   
203   TScalarType factor = m_FocalDistance / rigided[2];
204   
205   result[0] = rigided[0] * factor;
206   result[1] = rigided[1] * factor;
207
208   return result;
209 }
210
211
212 EML
213 // Transform a point
214 template<class TScalarType>
215 void
216 Rigid3DPerspectiveTransform<TScalarType>::
217 ComputeMatrix(void) 
218 {
219   m_RotationMatrix = m_Versor.GetMatrix();
220 }
221
222
223  
224 // Compute the Jacobian in one position 
225 template<class TScalarType >
226 const typename Rigid3DPerspectiveTransform<TScalarType>::JacobianType & 
227 Rigid3DPerspectiveTransform< TScalarType >::
228 GetJacobian( const InputPointType &) const
229 {
230   
231
232   this->m_Jacobian.Fill( 0.0 );
233
234   // TODO
235
236   return this->m_Jacobian;
237
238 }
239
240
241  
242
243 // namespace
244
245 #endif
246

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