Orfeo Toolbox  3.16
itkCenteredSimilarity2DTransform.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkCenteredSimilarity2DTransform.txx,v $
5  Language: C++
6  Date: $Date: 2010-03-30 15:20:02 $
7  Version: $Revision: 1.12 $
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 #ifndef __itkCenteredSimilarity2DTransform_txx
18 #define __itkCenteredSimilarity2DTransform_txx
19 
21 
22 
23 namespace itk
24 {
25 
26 // Constructor with default arguments
27 template <class TScalarType>
30  ParametersDimension)
31 {
32 }
33 
34 
35 // Constructor with arguments
36 template<class TScalarType>
38 CenteredSimilarity2DTransform( unsigned int spaceDimension,
39  unsigned int parametersDimension):
40  Superclass(spaceDimension,parametersDimension)
41 {
42 
43 }
44 
45 
46 // Set Parameters
47 template <class TScalarType>
48 void
50 ::SetParameters( const ParametersType & parameters )
51 {
52  itkDebugMacro( << "Setting parameters " << parameters );
53 
54  // Set scale
55  const TScalarType scale = parameters[0];
56  this->SetVarScale( scale );
57 
58  // Set angle
59  const TScalarType angle = parameters[1];
60  this->SetVarAngle( angle );
61 
62  InputPointType center;
63  for(unsigned int j=0; j < SpaceDimension; j++)
64  {
65  center[j] = parameters[j+2];
66  }
67  this->SetVarCenter( center );
68 
69  // Set translation
70  OffsetType translation;
71 
72  for(unsigned int i=0; i < SpaceDimension; i++)
73  {
74  translation[i] = parameters[i+4];
75  }
76 
77  this->SetVarTranslation( translation );
78 
79  this->ComputeMatrix();
80  this->ComputeOffset();
81 
82  // Modified is always called since we just have a pointer to the
83  // parameters and cannot know if the parameters have changed.
84  this->Modified();
85 
86  itkDebugMacro(<<"After setting parameters ");
87 }
88 
89 
90 // Get Parameters
91 template <class TScalarType>
94 ::GetParameters( void ) const
95 {
96  itkDebugMacro( << "Getting parameters ");
97 
98  this->m_Parameters[0] = this->GetScale();
99  this->m_Parameters[1] = this->GetAngle();
100 
101  InputPointType center = this->GetCenter();
102  for(unsigned int j=0; j < SpaceDimension; j++)
103  {
104  this->m_Parameters[j+2] = center[j];
105  }
106 
107  OffsetType translation = this->GetTranslation();
108  for(unsigned int i=0; i < SpaceDimension; i++)
109  {
110  this->m_Parameters[i+4] = translation[i];
111  }
112 
113  itkDebugMacro(<<"After getting parameters " << this->m_Parameters );
114 
115  return this->m_Parameters;
116 }
117 
118 // Compute the Jacobian
119 template<class TScalarType>
122 GetJacobian( const InputPointType & p ) const
123 {
124  const double angle = this->GetAngle();
125  const double ca = vcl_cos(angle );
126  const double sa = vcl_sin(angle );
127 
128  this->m_Jacobian.Fill(0.0);
129 
130  const InputPointType center = this->GetCenter();
131  const double cx = center[0];
132  const double cy = center[1];
133 
134  const OutputVectorType translation = this->GetTranslation();
135 
136  // derivatives with respect to the scale
137  this->m_Jacobian[0][0] = ca * ( p[0] - cx ) - sa * ( p[1] - cy );
138  this->m_Jacobian[1][0] = sa * ( p[0] - cx ) + ca * ( p[1] - cy );
139 
140  // derivatives with respect to the angle
141  this->m_Jacobian[0][1] = ( -sa * ( p[0] - cx ) - ca * ( p[1] - cy ) )
142  * this->GetScale();
143  this->m_Jacobian[1][1] = ( ca * ( p[0] - cx ) - sa * ( p[1] - cy ) )
144  * this->GetScale();
145 
146  // compute derivatives with respect to the center part
147  // first with respect to cx
148  this->m_Jacobian[0][2] = 1.0 - ca * this->GetScale();
149  this->m_Jacobian[1][2] = - sa * this->GetScale();
150  // then with respect to cy
151  this->m_Jacobian[0][3] = sa * this->GetScale();
152  this->m_Jacobian[1][3] = 1.0 - ca * this->GetScale();
153 
154  // compute derivatives with respect to the translation part
155  // first with respect to tx
156  this->m_Jacobian[0][4] = 1.0;
157  this->m_Jacobian[1][4] = 0.0;
158  // first with respect to ty
159  this->m_Jacobian[0][5] = 0.0;
160  this->m_Jacobian[1][5] = 1.0;
161 
162  return this->m_Jacobian;
163 
164 }
165 
166 template <class TScalarType>
167 void
169 SetFixedParameters( const ParametersType & itkNotUsed(parameters) )
170 {
171  // no fixed parameters
172 }
173 
174 template <class TScalarType>
177 GetFixedParameters( void ) const
178 {
179  // return dummy parameters
180  this->m_FixedParameters.SetSize(0);
181  return this->m_FixedParameters;
182 }
183 
184 // Print self
185 template<class TScalarType>
186 void
188 PrintSelf(std::ostream &os, Indent indent) const
189 {
190  Superclass::PrintSelf(os,indent);
191 }
192 
193 // Create and return an inverse transformation
194 template<class TScalarType>
195 void
197 CloneInverseTo( Pointer & result ) const
198 {
199  result = New();
200  this->GetInverse(result.GetPointer());
201 }
202 
203 // return an inverse transformation
204 template<class TScalarType>
205 bool
207 GetInverse( Self* inverse) const
208 {
209  if(!inverse)
210  {
211  return false;
212  }
213 
214  inverse->SetCenter( this->GetCenter() ); // inverse have the same center
215  inverse->SetScale( NumericTraits<double>::One / this->GetScale() );
216  inverse->SetAngle( -this->GetAngle() );
217  inverse->SetTranslation( -( this->GetInverseMatrix() * this->GetTranslation() ) );
218  return true;
219 }
220 
221 // Return an inverse of this transform
222 template<class TScalarType>
226 {
227  Pointer inv = New();
228  if( this->GetInverse(inv) )
229  {
230  return inv.GetPointer();
231  }
232  return NULL;
233 }
234 
235 // Create and return a clone of the transformation
236 template<class TScalarType>
237 void
239 CloneTo( Pointer & result ) const
240 {
241  result = New();
242  result->SetCenter( this->GetCenter() );
243  result->SetScale( this->GetScale() );
244  result->SetAngle( this->GetAngle() );
245  result->SetTranslation( this->GetTranslation() );
246 }
247 
248 } // namespace
249 
250 #endif

Generated at Sat Feb 2 2013 23:31:40 for Orfeo Toolbox with doxygen 1.8.1.1