Orfeo Toolbox  3.16
itkInterpolateImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkInterpolateImageFilter.txx,v $
5  Language: C++
6  Date: $Date: 2009-05-11 21:18:31 $
7  Version: $Revision: 1.9 $
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 __itkInterpolateImageFilter_txx
18 #define __itkInterpolateImageFilter_txx
19 
21 
25 #include "itkProgressReporter.h"
26 
27 namespace itk
28 {
29 
33 template <class TInputImage, class TOutputImage>
36 {
37 
38  // The filter requires two inputs
39  this->SetNumberOfRequiredInputs( 2 );
40 
41  // Set default interpolator to linear
43  LinearInterpolatorType;
44  typename LinearInterpolatorType::Pointer interpolator =
45  LinearInterpolatorType::New();
46 
47  m_Interpolator = static_cast<InterpolatorType *>( interpolator.GetPointer() );
48 
49  // Set default distance to 0,5
50  m_Distance = 0.5;
51 
52  m_IntermediateImage = NULL;
53 
54 }
55 
56 
60 template <class TInputImage, class TOutputImage>
61 void
63 ::SetInput2( const InputImageType * image )
64 {
65  // Process object is not const-correct so the const_cast is required here
67  const_cast< InputImageType * >( image ) );
68 
69 }
70 
71 
75 template <class TInputImage, class TOutputImage>
79 {
80  if (this->GetNumberOfInputs() < 2)
81  {
82  return 0;
83  }
84 
85  return static_cast<const TInputImage * >
86  (this->ProcessObject::GetInput(1) );
87 }
88 
89 
93 template <class TInputImage, class TOutputImage>
94 void
96 ::PrintSelf(std::ostream& os, Indent indent) const
97 {
98 
99  this->Superclass::PrintSelf(os,indent);
100 
101  os << indent << "Interpolator: " << m_Interpolator.GetPointer() << std::endl;
102  os << indent << "Distance: " << m_Distance << std::endl;
103 
104 }
105 
111 template <class TInputImage, class TOutputImage>
112 void
115 {
116 
117  if( !m_Interpolator )
118  {
119  itkExceptionMacro(<< "Interpolator not set");
120  }
121 
122  // Create intermediate image
123  typedef typename IntermediateImageType::RegionType IntermediateImageRegionType;
124  typedef typename TOutputImage::RegionType ImageRegionType;
125 
126  ImageRegionType outputRegion = this->GetOutput()->GetRequestedRegion();
127 
128  IntermediateImageRegionType intermediateRegion;
129 
131  RegionCopierType;
132  RegionCopierType regionCopier;
133  regionCopier( intermediateRegion, outputRegion );
134 
135  intermediateRegion.SetIndex( ImageDimension, 0 );
136  intermediateRegion.SetSize( ImageDimension, 2 );
137 
138  m_IntermediateImage = IntermediateImageType::New();
139  m_IntermediateImage->SetRegions( intermediateRegion );
140  m_IntermediateImage->Allocate();
141 
142  // Fill intermediate image
143  intermediateRegion.SetIndex( ImageDimension, 0 );
144  intermediateRegion.SetSize( ImageDimension, 1 );
145 
146  ImageRegionConstIteratorWithIndex<TInputImage> inIter( this->GetInput1(), outputRegion );
147  ImageRegionIteratorWithIndex<IntermediateImageType> outIter( m_IntermediateImage,
148  intermediateRegion );
149 
150  while( !inIter.IsAtEnd() )
151  {
152  outIter.Set( inIter.Get() );
153  ++inIter;
154  ++outIter;
155  }
156 
157 
158  intermediateRegion.SetIndex( ImageDimension, 1 );
159  intermediateRegion.SetSize( ImageDimension, 1 );
160 
161  inIter = ImageRegionConstIteratorWithIndex<TInputImage>( this->GetInput2(), outputRegion );
162  outIter = ImageRegionIteratorWithIndex<IntermediateImageType>( m_IntermediateImage,
163  intermediateRegion );
164 
165  while( !inIter.IsAtEnd() )
166  {
167  outIter.Set( inIter.Get() );
168  ++inIter;
169  ++outIter;
170  }
171 
172 
173  // Connect input image to interpolator
174  m_Interpolator->SetInputImage( m_IntermediateImage );
175 
176 }
177 
178 
182 template <class TInputImage, class TOutputImage>
183 void
186 {
187 
188  // Clean up intermediate memory usage
189  m_IntermediateImage = NULL;
190 
191 }
192 
196 template <class TInputImage, class TOutputImage>
197 void
200  const OutputImageRegionType& outputRegionForThread,
201  int threadId)
202 {
203 
204  // Get the output pointers
205  OutputImagePointer outputPtr = this->GetOutput();
206 
207  // Create an iterator that will walk the output region for this thread.
208  typedef ImageRegionIteratorWithIndex<TOutputImage> OutputIterator;
209 
210  OutputIterator outIt(outputPtr, outputRegionForThread);
211 
212  typedef typename TOutputImage::PixelType OutputPixelType;
213  typedef typename TOutputImage::IndexType IndexType;
214  typedef typename InterpolatorType::ContinuousIndexType ContinuousIndexType;
215 
216  IndexType outputIndex; // Index to current output pixel
217  ContinuousIndexType intermediateIndex; // Coordinates of current intermediate image pixel
218 
219  // Estimate total work for progress methods/callbacks
220  ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
221 
222  // Walk the output region
223  while ( !outIt.IsAtEnd() )
224  {
225  // Determine the intermediate image index
226  outputIndex = outIt.GetIndex();
227  for (unsigned int j = 0; j< ImageDimension; ++j)
228  {
229  intermediateIndex[j] = (double) outputIndex[j];
230  }
231  intermediateIndex[ImageDimension] = m_Distance;
232 
233  // Evaluate input at right position and copy to the output
234  if( m_Interpolator->IsInsideBuffer(intermediateIndex) )
235  {
236  outIt.Set( static_cast<OutputPixelType>(
237  m_Interpolator->EvaluateAtContinuousIndex( intermediateIndex)));
238  }
239  else
240  {
241  // should never be in here
242  itkExceptionMacro( << "Index not within the intermediate buffer" );
243  }
244 
245  ++outIt;
246  progress.CompletedPixel();
247  }
248 
249 }
250 
251 
252 } // end namespace itk
253 
254 #endif

Generated at Sat Feb 2 2013 23:46:10 for Orfeo Toolbox with doxygen 1.8.1.1