Orfeo Toolbox  3.16
itkCenteredAffineTransform.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkCenteredAffineTransform.txx,v $
5  Language: C++
6  Date: $Date: 2010-03-30 15:20:03 $
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 __itkCenteredAffineTransform_txx
18 #define __itkCenteredAffineTransform_txx
19 
20 #include "itkNumericTraits.h"
22 #include "vnl/algo/vnl_matrix_inverse.h"
23 
24 
25 namespace itk
26 {
27 
28 // Constructor with default arguments
29 template<class TScalarType, unsigned int NDimensions>
31 CenteredAffineTransform():Superclass(SpaceDimension,ParametersDimension)
32 {
33 }
34 
35 // Destructor
36 template<class TScalarType, unsigned int NDimensions>
39 {
40  return;
41 }
42 
43 // Get parameters
44 template<class TScalarType, unsigned int NDimensions>
45 const typename CenteredAffineTransform<TScalarType,
46  NDimensions>::ParametersType &
48 GetParameters( void ) const
49 {
50 
51  // Transfer the linear part
52  unsigned int par = 0;
53 
54  const MatrixType & matrix = this->GetMatrix();
55 
56  for(unsigned int row=0; row<NDimensions; row++)
57  {
58  for(unsigned int col=0; col<NDimensions; col++)
59  {
60  this->m_Parameters[par] = matrix[row][col];
61  ++par;
62  }
63  }
64 
65 
66  // Transfer the rotation center
67  InputPointType center = this->GetCenter();
68  for(unsigned int j=0; j<NDimensions; j++)
69  {
70  this->m_Parameters[par] = center[j];
71  ++par;
72  }
73 
74  // Transfer the translation
75  OutputVectorType translation = this->GetTranslation();
76  for(unsigned int k=0; k<NDimensions; k++)
77  {
78  this->m_Parameters[par] = translation[k];
79  ++par;
80  }
81 
82 
83  return this->m_Parameters;
84 
85 }
86 
88 template<class TScalarType, unsigned int NDimensions>
89 void
91 SetParameters( const ParametersType & parameters )
92 {
93 
94  // Transfer the linear part
95  unsigned int par = 0;
96 
97  this->m_Parameters = parameters;
98 
99  MatrixType matrix;
100 
101  for(unsigned int row=0; row<NDimensions; row++)
102  {
103  for(unsigned int col=0; col<NDimensions; col++)
104  {
105  matrix[row][col] = this->m_Parameters[par];
106  ++par;
107  }
108  }
109 
110  this->SetMatrix( matrix );
111 
112  // Transfer the rotation center
113  InputPointType center;
114  for(unsigned int i=0; i<NDimensions; i++)
115  {
116  center[i] = this->m_Parameters[par];
117  ++par;
118  }
119  this->SetCenter(center);
120 
121  // Transfer the translation
122  OutputVectorType translation;
123  for(unsigned int k=0; k<NDimensions; k++)
124  {
125  translation[k] = this->m_Parameters[par];
126  ++par;
127  }
128  this->SetTranslation(translation);
129 
130  // Modified is always called since we just have a pointer to the
131  // parameters and cannot know if the parameters have changed.
132  this->Modified();
133 
134 }
135 
136 
137 // Compute the Jacobian in one position
138 template<class TScalarType, unsigned int NDimensions>
140 ::JacobianType &
142 GetJacobian( const InputPointType & p ) const
143 {
144 
145  // The Jacobian of the affine transform is composed of
146  // subblocks of diagonal matrices, each one of them having
147  // a constant value in the diagonal.
148  // The block corresponding to the center parameters is
149  // composed by ( Identity matrix - Rotation Matrix).
150 
151  this->m_Jacobian.Fill( 0.0 );
152 
153 
154  unsigned int blockOffset = 0;
155 
156  for(unsigned int block=0; block < SpaceDimension; block++)
157  {
158  for(unsigned int dim=0; dim < SpaceDimension; dim++ )
159  {
160  this->m_Jacobian( block , blockOffset + dim ) = p[dim];
161  }
162  blockOffset += SpaceDimension;
163  }
164 
165  // Block associated with the center parameters
166  const MatrixType & matrix = this->GetMatrix();
167  for(unsigned int k=0; k < SpaceDimension; k++)
168  {
169  this->m_Jacobian( k, blockOffset + k ) = 1.0;
170  for(unsigned int dim=0; dim < SpaceDimension; dim++ )
171  {
172  this->m_Jacobian( k, blockOffset + dim ) -= matrix[k][dim];
173  }
174  }
175  blockOffset += SpaceDimension;
176 
177  // Block associated with the translations
178  for(unsigned int dim=0; dim < SpaceDimension; dim++ )
179  {
180  this->m_Jacobian( dim , blockOffset + dim ) = 1.0;
181  }
182 
183  return this->m_Jacobian;
184 
185 }
186 
187 // Get an inverse of this transform
188 template<class TScalarType, unsigned int NDimensions>
189 bool
191 ::GetInverse(Self* inverse) const
192 {
193  return this->Superclass::GetInverse(inverse);
194 }
195 
196 // Return an inverse of this transform
197 template<class TScalarType, unsigned int NDimensions>
201 {
202  Pointer inv = New();
203  return this->GetInverse(inv) ? inv.GetPointer() : NULL;
204 }
205 
206 } // namespace
207 
208 #endif

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