Orfeo Toolbox  3.16
itkQuaternionRigidTransformGradientDescentOptimizer.cxx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkQuaternionRigidTransformGradientDescentOptimizer.cxx,v $
5  Language: C++
6  Date: $Date: 2007-03-29 19:37:01 $
7  Version: $Revision: 1.16 $
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 _itkQuaternionRigidTransformGradientDescentOptimizer_txx
18 #define _itkQuaternionRigidTransformGradientDescentOptimizer_txx
19 
21 #include "vnl/vnl_quaternion.h"
22 #include "itkEventObject.h"
23 
24 namespace itk
25 {
26 
30 void
33 {
34 
35  double direction;
36  if( m_Maximize )
37  {
38  direction = 1.0;
39  }
40  else
41  {
42  direction = -1.0;
43  }
44 
45 
46  ScalesType scales = this->GetScales();
47 
48  const unsigned int spaceDimension = m_CostFunction->GetNumberOfParameters();
49 
50  // Make sure the scales have been set
51  if (scales.size() != spaceDimension)
52  {
53  itkExceptionMacro(<< "The size of Scales is "
54  << scales.size()
55  << ", but the NumberOfParameters is "
56  << spaceDimension
57  << ".");
58  }
59 
60  DerivativeType transformedGradient( spaceDimension);
61  for ( unsigned int i=0; i< spaceDimension; i++)
62  {
63  transformedGradient[i] = m_Gradient[i] / scales[i];
64  }
65 
66  ParametersType currentPosition = this->GetCurrentPosition();
67 
68  // compute new quaternion value
69  vnl_quaternion<double> newQuaternion;
70  for ( unsigned int j=0; j < 4; j++ )
71  {
72  newQuaternion[j] = currentPosition[j] + direction * m_LearningRate *
73  transformedGradient[j];
74  }
75 
76  newQuaternion.normalize();
77 
78  ParametersType newPosition( spaceDimension );
79  // update quaternion component of currentPosition
80  for ( unsigned int j=0; j < 4; j++ )
81  {
82  newPosition[j] = newQuaternion[j];
83  }
84 
85  // update the translation component
86  for (unsigned int j=4; j< spaceDimension; j++)
87  {
88  newPosition[j] = currentPosition[j] +
89  direction * m_LearningRate * transformedGradient[j];
90  }
91 
92 
93  // First invoke the event, so the current position
94  // still corresponds to the metric values.
95  this->InvokeEvent( IterationEvent() );
96 
97  this->SetCurrentPosition( newPosition );
98 }
99 
100 } // end namespace itk
101 
102 #endif

Generated at Sun Feb 3 2013 00:01:06 for Orfeo Toolbox with doxygen 1.8.1.1