18 #ifndef __itkInverseDeformationFieldImageFilter_txx
19 #define __itkInverseDeformationFieldImageFilter_txx
34 template <
class TInputImage,
class TOutputImage>
38 m_OutputSpacing.Fill(1.0);
39 m_OutputOrigin.Fill(0.0);
40 for (
unsigned int i = 0; i < ImageDimension; i++)
47 itkGetStaticConstMacro( ImageDimension ) > DefaultTransformType;
49 m_KernelTransform = DefaultTransformType::New();
51 m_SubsamplingFactor = 16;
60 template <
class TInputImage,
class TOutputImage>
65 Superclass::PrintSelf(os,indent);
67 os << indent <<
"Size: " << m_Size << std::endl;
68 os << indent <<
"OutputSpacing: " << m_OutputSpacing << std::endl;
69 os << indent <<
"OutputOrigin: " << m_OutputOrigin << std::endl;
70 os << indent <<
"KernelTransform: " << m_KernelTransform.GetPointer() << std::endl;
71 os << indent <<
"SubsamplingFactor: " << m_SubsamplingFactor << std::endl;
79 template <
class TInputImage,
class TOutputImage>
85 this->SetOutputSpacing( s );
91 template <
class TInputImage,
class TOutputImage>
97 this->SetOutputOrigin( p );
104 template <
class TInputImage,
class TOutputImage>
111 typedef typename LandmarkContainer::Pointer LandmarkContainerPointer;
115 LandmarkContainerPointer source = LandmarkContainer::New();
119 LandmarkContainerPointer target = LandmarkContainer::New();
124 InputImageType > ResamplerType;
126 typename ResamplerType::Pointer resampler = ResamplerType::New();
128 const InputImageType * inputImage = this->GetInput();
130 resampler->SetInput( inputImage );
131 resampler->SetOutputOrigin( inputImage->GetOrigin() );
133 typename InputImageType::SpacingType spacing = inputImage->GetSpacing();
136 typedef typename InputImageType::RegionType InputRegionType;
137 typedef typename InputImageType::SizeType InputSizeType;
138 typedef typename InputImageType::IndexType InputIndexType;
140 InputRegionType region;
142 region = inputImage->GetLargestPossibleRegion();
144 InputSizeType size = region.GetSize();
146 for(
unsigned int i=0; i < ImageDimension; i++)
148 size[i] =
static_cast< typename InputSizeType::SizeValueType
>( size[i] / m_SubsamplingFactor );
149 spacing[i] *= m_SubsamplingFactor;
152 InputRegionType subsampledRegion;
153 subsampledRegion.SetSize( size );
154 subsampledRegion.SetIndex( region.GetIndex() );
156 resampler->SetSize( size );
157 resampler->SetOutputStartIndex( subsampledRegion.GetIndex() );
158 resampler->SetOutputSpacing( spacing );
165 const unsigned long numberOfLandmarks = subsampledRegion.GetNumberOfPixels();
166 source->Reserve( numberOfLandmarks );
167 target->Reserve( numberOfLandmarks );
170 const InputImageType * sampledInput = resampler->GetOutput();
174 unsigned int landmarkId = 0;
176 IteratorType ot( sampledInput, subsampledRegion );
183 while( !ot.IsAtEnd() )
186 sampledInput->TransformIndexToPhysicalPoint( ot.GetIndex(), sourcePoint );
188 source->InsertElement( landmarkId, sourcePoint );
190 for(
unsigned int i=0; i < ImageDimension; i++)
192 targetPoint[i] = -value[i];
194 target->InsertElement( landmarkId, targetPoint );
200 itkDebugMacro( <<
"Number of Landmarks created = " << numberOfLandmarks );
202 m_KernelTransform->GetTargetLandmarks()->SetPoints( target );
203 m_KernelTransform->GetSourceLandmarks()->SetPoints( source );
205 itkDebugMacro( <<
"Before ComputeWMatrix() ");
207 m_KernelTransform->ComputeWMatrix();
209 itkDebugMacro( <<
"After ComputeWMatrix() ");
216 template <
class TInputImage,
class TOutputImage>
224 this->PrepareKernelBaseSpline();
226 itkDebugMacro(<<
"Actually executing");
231 outputPtr->SetBufferedRegion( outputPtr->GetRequestedRegion() );
232 outputPtr->Allocate();
236 TOutputImage> OutputIterator;
240 OutputIterator outIt( outputPtr, region );
249 InputPointType outputPoint;
257 while ( !outIt.IsAtEnd() )
260 outputIndex = outIt.GetIndex();
261 outputPtr->TransformIndexToPhysicalPoint( outputIndex, outputPoint );
265 OutputPointType interpolation =
266 m_KernelTransform->TransformPoint( outputPoint );
270 for(
unsigned int i=0; i < ImageDimension; i++)
272 inverseDisplacement[i] = interpolation[i];
275 outIt.Set( inverseDisplacement );
290 template <
class TInputImage,
class TOutputImage>
296 Superclass::GenerateInputRequestedRegion();
298 if ( !this->GetInput() )
309 inputRegion = inputPtr->GetLargestPossibleRegion();
310 inputPtr->SetRequestedRegion(inputRegion);
318 template <
class TInputImage,
class TOutputImage>
324 Superclass::GenerateOutputInformation();
334 typename TOutputImage::RegionType outputLargestPossibleRegion;
335 outputLargestPossibleRegion.SetSize( m_Size );
336 outputPtr->SetLargestPossibleRegion( outputLargestPossibleRegion );
339 outputPtr->SetSpacing( m_OutputSpacing );
340 outputPtr->SetOrigin( m_OutputOrigin );
348 template <
class TInputImage,
class TOutputImage>
355 if( m_KernelTransform )
357 if( latestTime < m_KernelTransform->GetMTime() )
359 latestTime = m_KernelTransform->GetMTime();