| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkCenteredAffineTransform.txx.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:33 $ |
| 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 _itkCenteredAffineTransform_txx |
| 18 |
DEF |
#define _itkCenteredAffineTransform_txx |
| 19 |
|
|
| 20 |
|
#include "itkNumericTraits.h" |
| 21 |
|
#include "itkCenteredAffineTransform.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> |
| 30 |
|
CenteredAffineTransform<TScalarType, NDimensions>:: |
| 31 |
|
CenteredAffineTransform():Superclass(SpaceDimension,ParametersDimension) |
| 32 |
|
{ |
| 33 |
|
} |
| 34 |
|
|
| 35 |
|
// Destructor |
| 36 |
|
template<class TScalarType, unsigned int NDimensions> |
| 37 |
|
CenteredAffineTransform<TScalarType, NDimensions>:: |
| 38 |
|
~CenteredAffineTransform() |
| 39 |
|
{ |
| 40 |
|
return; |
| 41 |
|
} |
| 42 |
|
|
| 43 |
|
// Get parameters |
| 44 |
|
template<class TScalarType, unsigned int NDimensions> |
| 45 |
LEN |
const typename CenteredAffineTransform<TScalarType, NDimensions>::ParametersType & |
| 46 |
|
CenteredAffineTransform<TScalarType, NDimensions>:: |
| 47 |
|
GetParameters( void ) const |
| 48 |
|
{ |
| 49 |
|
|
| 50 |
|
// Transfer the linear part |
| 51 |
|
unsigned int par = 0; |
| 52 |
|
|
| 53 |
|
const MatrixType & matrix = this->GetMatrix(); |
| 54 |
|
|
| 55 |
|
for(unsigned int row=0; row<NDimensions; row++) |
| 56 |
|
{ |
| 57 |
|
for(unsigned int col=0; col<NDimensions; col++) |
| 58 |
|
{ |
| 59 |
|
this->m_Parameters[par] = matrix[row][col]; |
| 60 |
|
++par; |
| 61 |
|
} |
| 62 |
|
} |
| 63 |
|
|
| 64 |
|
|
| 65 |
|
// Transfer the rotation center |
| 66 |
|
InputPointType center = this->GetCenter(); |
| 67 |
|
for(unsigned int j=0; j<NDimensions; j++) |
| 68 |
|
{ |
| 69 |
|
this->m_Parameters[par] = center[j]; |
| 70 |
|
++par; |
| 71 |
|
} |
| 72 |
|
|
| 73 |
|
// Transfer the translation |
| 74 |
|
OutputVectorType translation = this->GetTranslation(); |
| 75 |
|
for(unsigned int k=0; k<NDimensions; k++) |
| 76 |
|
{ |
| 77 |
|
this->m_Parameters[par] = translation[k]; |
| 78 |
|
++par; |
| 79 |
|
} |
| 80 |
|
|
| 81 |
|
|
| 82 |
|
return this->m_Parameters; |
| 83 |
|
|
| 84 |
|
} |
| 85 |
|
|
| 86 |
|
|
| 87 |
EML |
|
| 88 |
EML |
|
| 89 |
|
// Set parameters |
| 90 |
|
template<class TScalarType, unsigned int NDimensions> |
| 91 |
|
void |
| 92 |
|
CenteredAffineTransform<TScalarType, NDimensions>:: |
| 93 |
|
SetParameters( const ParametersType & parameters ) |
| 94 |
|
{ |
| 95 |
|
|
| 96 |
|
// Transfer the linear part |
| 97 |
|
unsigned int par = 0; |
| 98 |
|
|
| 99 |
|
this->m_Parameters = parameters; |
| 100 |
|
|
| 101 |
|
MatrixType matrix; |
| 102 |
|
|
| 103 |
|
for(unsigned int row=0; row<NDimensions; row++) |
| 104 |
|
{ |
| 105 |
|
for(unsigned int col=0; col<NDimensions; col++) |
| 106 |
|
{ |
| 107 |
|
matrix[row][col] = this->m_Parameters[par]; |
| 108 |
|
++par; |
| 109 |
|
} |
| 110 |
|
} |
| 111 |
|
|
| 112 |
|
this->SetMatrix( matrix ); |
| 113 |
|
|
| 114 |
|
// Transfer the rotation center |
| 115 |
|
InputPointType center; |
| 116 |
|
for(unsigned int i=0; i<NDimensions; i++) |
| 117 |
|
{ |
| 118 |
|
center[i] = this->m_Parameters[par]; |
| 119 |
|
++par; |
| 120 |
|
} |
| 121 |
|
this->SetCenter(center); |
| 122 |
|
|
| 123 |
|
// Transfer the translation |
| 124 |
|
OutputVectorType translation; |
| 125 |
|
for(unsigned int k=0; k<NDimensions; k++) |
| 126 |
|
{ |
| 127 |
|
translation[k] = this->m_Parameters[par]; |
| 128 |
|
++par; |
| 129 |
|
} |
| 130 |
|
this->SetTranslation(translation); |
| 131 |
|
} |
| 132 |
|
|
| 133 |
|
|
| 134 |
|
// Compute the Jacobian in one position |
| 135 |
|
template<class TScalarType, unsigned int NDimensions> |
| 136 |
LEN |
const typename CenteredAffineTransform<TScalarType, NDimensions>::JacobianType & |
| 137 |
|
CenteredAffineTransform<TScalarType, NDimensions>:: |
| 138 |
|
GetJacobian( const InputPointType & p ) const |
| 139 |
|
{ |
| 140 |
|
|
| 141 |
|
// The Jacobian of the affine transform is composed of |
| 142 |
|
// subblocks of diagonal matrices, each one of them having |
| 143 |
|
// a constant value in the diagonal. |
| 144 |
|
// The block corresponding to the center parameters is |
| 145 |
|
// composed by ( Identity matrix - Rotation Matrix). |
| 146 |
|
|
| 147 |
|
this->m_Jacobian.Fill( 0.0 ); |
| 148 |
|
|
| 149 |
|
|
| 150 |
|
unsigned int blockOffset = 0; |
| 151 |
|
|
| 152 |
|
for(unsigned int block=0; block < SpaceDimension; block++) |
| 153 |
|
{ |
| 154 |
|
for(unsigned int dim=0; dim < SpaceDimension; dim++ ) |
| 155 |
|
{ |
| 156 |
|
this->m_Jacobian( block , blockOffset + dim ) = p[dim]; |
| 157 |
|
} |
| 158 |
|
blockOffset += SpaceDimension; |
| 159 |
|
} |
| 160 |
|
|
| 161 |
|
// Block associated with the center parameters |
| 162 |
|
const MatrixType & matrix = this->GetMatrix(); |
| 163 |
|
for(unsigned int k=0; k < SpaceDimension; k++) |
| 164 |
|
{ |
| 165 |
|
this->m_Jacobian( k, blockOffset + k ) = 1.0; |
| 166 |
|
for(unsigned int dim=0; dim < SpaceDimension; dim++ ) |
| 167 |
|
{ |
| 168 |
|
this->m_Jacobian( k, blockOffset + dim ) -= matrix[k][dim]; |
| 169 |
|
} |
| 170 |
|
} |
| 171 |
|
blockOffset += SpaceDimension; |
| 172 |
|
|
| 173 |
|
// Block associated with the translations |
| 174 |
|
for(unsigned int dim=0; dim < SpaceDimension; dim++ ) |
| 175 |
|
{ |
| 176 |
|
this->m_Jacobian( dim , blockOffset + dim ) = 1.0; |
| 177 |
|
} |
| 178 |
|
|
| 179 |
|
return this->m_Jacobian; |
| 180 |
|
|
| 181 |
|
} |
| 182 |
|
|
| 183 |
|
} // namespace |
| 184 |
|
|
| 185 |
|
#endif |
| 186 |
|
|