| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkCenteredTransformInitializer.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 |
|
|
| 18 |
|
#ifndef __itkCenteredTransformInitializer_txx |
| 19 |
|
#define __itkCenteredTransformInitializer_txx |
| 20 |
|
|
| 21 |
|
#include "itkCenteredTransformInitializer.h" |
| 22 |
|
|
| 23 |
|
namespace itk |
| 24 |
|
{ |
| 25 |
|
|
| 26 |
|
|
| 27 |
|
template < class TTransform, class TFixedImage, class TMovingImage > |
| 28 |
|
CenteredTransformInitializer<TTransform, TFixedImage, TMovingImage > |
| 29 |
|
::CenteredTransformInitializer() |
| 30 |
|
{ |
| 31 |
|
m_FixedCalculator = FixedImageCalculatorType::New(); |
| 32 |
|
m_MovingCalculator = MovingImageCalculatorType::New(); |
| 33 |
|
} |
| 34 |
|
|
| 35 |
|
|
| 36 |
EML |
|
| 37 |
|
template < class TTransform, class TFixedImage, class TMovingImage > |
| 38 |
|
void |
| 39 |
|
CenteredTransformInitializer<TTransform, TFixedImage, TMovingImage > |
| 40 |
|
::InitializeTransform() const |
| 41 |
|
{ |
| 42 |
|
// Sanity check |
| 43 |
|
if( !m_FixedImage ) |
| 44 |
|
{ |
| 45 |
|
itkExceptionMacro( "Fixed Image has not been set" ); |
| 46 |
|
return; |
| 47 |
|
} |
| 48 |
|
if( !m_MovingImage ) |
| 49 |
|
{ |
| 50 |
|
itkExceptionMacro( "Moving Image has not been set" ); |
| 51 |
|
return; |
| 52 |
|
} |
| 53 |
|
if( !m_Transform ) |
| 54 |
|
{ |
| 55 |
|
itkExceptionMacro( "Transform has not been set" ); |
| 56 |
|
return; |
| 57 |
|
} |
| 58 |
|
|
| 59 |
|
// If images come from filters, then update those filters. |
| 60 |
|
if( m_FixedImage->GetSource() ) |
| 61 |
|
{ |
| 62 |
|
m_FixedImage->GetSource()->Update(); |
| 63 |
|
} |
| 64 |
|
if( m_MovingImage->GetSource() ) |
| 65 |
|
{ |
| 66 |
|
m_MovingImage->GetSource()->Update(); |
| 67 |
|
} |
| 68 |
|
|
| 69 |
|
|
| 70 |
|
InputPointType rotationCenter; |
| 71 |
|
OutputVectorType translationVector; |
| 72 |
|
|
| 73 |
|
|
| 74 |
|
if( m_UseMoments ) |
| 75 |
|
{ |
| 76 |
|
m_FixedCalculator->SetImage( m_FixedImage ); |
| 77 |
|
m_FixedCalculator->Compute(); |
| 78 |
|
|
| 79 |
|
m_MovingCalculator->SetImage( m_MovingImage ); |
| 80 |
|
m_MovingCalculator->Compute(); |
| 81 |
|
|
| 82 |
|
typename FixedImageCalculatorType::VectorType fixedCenter = |
| 83 |
IND |
******m_FixedCalculator->GetCenterOfGravity(); |
| 84 |
|
|
| 85 |
|
typename MovingImageCalculatorType::VectorType movingCenter = |
| 86 |
IND |
******m_MovingCalculator->GetCenterOfGravity(); |
| 87 |
|
|
| 88 |
|
for( unsigned int i=0; i<InputSpaceDimension; i++) |
| 89 |
|
{ |
| 90 |
|
rotationCenter[i] = fixedCenter[i]; |
| 91 |
|
translationVector[i] = movingCenter[i] - fixedCenter[i]; |
| 92 |
|
} |
| 93 |
|
} |
| 94 |
|
else |
| 95 |
|
{ |
| 96 |
|
// Here use the geometrical center of each image. |
| 97 |
|
|
| 98 |
|
const typename FixedImageType::SpacingType& |
| 99 |
|
fixedSpacing = m_FixedImage->GetSpacing(); |
| 100 |
|
const typename FixedImageType::PointType& |
| 101 |
IND |
******fixedOrigin = m_FixedImage->GetOrigin(); |
| 102 |
|
|
| 103 |
|
typename FixedImageType::SizeType fixedSize = |
| 104 |
IND |
******m_FixedImage->GetLargestPossibleRegion().GetSize(); |
| 105 |
|
|
| 106 |
|
typename TransformType::InputPointType centerFixed; |
| 107 |
|
|
| 108 |
|
for( unsigned int k=0; k<InputSpaceDimension; k++ ) |
| 109 |
|
{ |
| 110 |
|
centerFixed[k] = fixedOrigin[k] + fixedSpacing[k] * fixedSize[k] / 2.0; |
| 111 |
|
} |
| 112 |
|
|
| 113 |
|
|
| 114 |
|
const typename MovingImageType::SpacingType& |
| 115 |
|
movingSpacing = m_MovingImage->GetSpacing(); |
| 116 |
|
const typename MovingImageType::PointType& |
| 117 |
IND |
******movingOrigin = m_MovingImage->GetOrigin(); |
| 118 |
|
|
| 119 |
|
typename MovingImageType::SizeType movingSize = |
| 120 |
IND |
******m_MovingImage->GetLargestPossibleRegion().GetSize(); |
| 121 |
|
|
| 122 |
|
typename TransformType::InputPointType centerMoving; |
| 123 |
|
|
| 124 |
|
for( unsigned int m=0; m<InputSpaceDimension; m++ ) |
| 125 |
|
{ |
| 126 |
LEN |
centerMoving[m] = movingOrigin[m] + movingSpacing[m] * movingSize[m] / 2.0; |
| 127 |
|
} |
| 128 |
|
|
| 129 |
|
for( unsigned int i=0; i<InputSpaceDimension; i++) |
| 130 |
|
{ |
| 131 |
|
rotationCenter[i] = centerFixed[i]; |
| 132 |
|
translationVector[i] = centerMoving[i] - centerFixed[i]; |
| 133 |
|
} |
| 134 |
|
|
| 135 |
|
} |
| 136 |
|
|
| 137 |
|
m_Transform->SetCenter( rotationCenter ); |
| 138 |
|
|
| 139 |
|
m_Transform->SetTranslation( translationVector ); |
| 140 |
|
|
| 141 |
|
|
| 142 |
|
} |
| 143 |
|
|
| 144 |
|
|
| 145 |
|
|
| 146 |
|
|
| 147 |
|
template < class TTransform, class TFixedImage, class TMovingImage > |
| 148 |
|
void |
| 149 |
|
CenteredTransformInitializer<TTransform, TFixedImage, TMovingImage > |
| 150 |
|
::PrintSelf(std::ostream& os, Indent indent) const |
| 151 |
|
{ |
| 152 |
|
Superclass::PrintSelf(os,indent); |
| 153 |
|
|
| 154 |
|
os << indent << "Transform = " << std::endl; |
| 155 |
|
if (m_Transform) |
| 156 |
|
{ |
| 157 |
|
os << indent << m_Transform << std::endl; |
| 158 |
|
} |
| 159 |
|
else |
| 160 |
|
{ |
| 161 |
|
os << indent << "None" << std::endl; |
| 162 |
|
} |
| 163 |
|
|
| 164 |
|
os << indent << "FixedImage = " << std::endl; |
| 165 |
|
if (m_FixedImage) |
| 166 |
|
{ |
| 167 |
|
os << indent << m_FixedImage << std::endl; |
| 168 |
|
} |
| 169 |
|
else |
| 170 |
|
{ |
| 171 |
|
os << indent << "None" << std::endl; |
| 172 |
|
} |
| 173 |
|
|
| 174 |
|
os << indent << "MovingImage = " << std::endl; |
| 175 |
|
if (m_MovingImage) |
| 176 |
|
{ |
| 177 |
|
os << indent << m_MovingImage << std::endl; |
| 178 |
|
} |
| 179 |
|
else |
| 180 |
|
{ |
| 181 |
|
os << indent << "None" << std::endl; |
| 182 |
|
} |
| 183 |
|
|
| 184 |
|
os << indent << "MovingMomentCalculator = " << std::endl; |
| 185 |
|
if (m_MovingCalculator) |
| 186 |
|
{ |
| 187 |
|
os << indent << m_MovingCalculator << std::endl; |
| 188 |
|
} |
| 189 |
|
else |
| 190 |
|
{ |
| 191 |
|
os << indent << "None" << std::endl; |
| 192 |
|
} |
| 193 |
|
|
| 194 |
|
os << indent << "FixedMomentCalculator = " << std::endl; |
| 195 |
|
if (m_FixedCalculator) |
| 196 |
|
{ |
| 197 |
|
os << indent << m_FixedCalculator << std::endl; |
| 198 |
|
} |
| 199 |
|
else |
| 200 |
|
{ |
| 201 |
|
os << indent << "None" << std::endl; |
| 202 |
|
} |
| 203 |
|
|
| 204 |
|
} |
| 205 |
|
|
| 206 |
|
} // namespace itk |
| 207 |
|
|
| 208 |
|
#endif /* __itkCenteredTransformInitializer_txx */ |
| 209 |
|
|