18 #ifndef itkLinearInterpolateImageFunction_h
19 #define itkLinearInterpolateImageFunction_h
48 template<
typename TInputImage,
typename TCoordRep =
double >
66 typedef typename Superclass::OutputType
OutputType;
75 typedef typename Superclass::RealType
RealType;
78 itkStaticConstMacro(ImageDimension,
unsigned int, Superclass::ImageDimension);
97 index)
const ITK_OVERRIDE
105 void PrintSelf(std::ostream & os,
Indent indent) const ITK_OVERRIDE;
111 static const
unsigned long m_Neighbors;
114 template<
unsigned int >
127 basei[0] = Math::Floor< IndexValueType >(index[0]);
128 if ( basei[0] < this->m_StartIndex[0] )
130 basei[0] = this->m_StartIndex[0];
135 const TInputImage *
const inputImagePtr = this->GetInputImage();
136 const RealType & val0 = inputImagePtr->GetPixel(basei);
137 if ( distance <= 0. )
139 return ( static_cast< OutputType >( val0 ) );
143 if ( basei[0] > this->m_EndIndex[0] )
145 return ( static_cast< OutputType >( val0 ) );
147 const RealType & val1 = inputImagePtr->GetPixel(basei);
149 return ( static_cast< OutputType >( val0 + ( val1 - val0 ) * distance ) );
157 basei[0] = Math::Floor< IndexValueType >(index[0]);
158 if ( basei[0] < this->m_StartIndex[0] )
160 basei[0] = this->m_StartIndex[0];
164 basei[1] = Math::Floor< IndexValueType >(index[1]);
165 if ( basei[1] < this->m_StartIndex[1] )
167 basei[1] = this->m_StartIndex[1];
171 const TInputImage *
const inputImagePtr = this->GetInputImage();
172 const RealType & val00 = inputImagePtr->GetPixel(basei);
173 if ( distance0 <= 0. && distance1 <= 0. )
175 return ( static_cast< OutputType >( val00 ) );
177 else if ( distance1 <= 0. )
180 if ( basei[0] > this->m_EndIndex[0] )
182 return ( static_cast< OutputType >( val00 ) );
184 const RealType & val10 = inputImagePtr->GetPixel(basei);
185 return ( static_cast< OutputType >( val00 + ( val10 - val00 ) * distance0 ) );
187 else if ( distance0 <= 0. )
190 if ( basei[1] > this->m_EndIndex[1] )
192 return ( static_cast< OutputType >( val00 ) );
194 const RealType & val01 = inputImagePtr->GetPixel(basei);
195 return ( static_cast< OutputType >( val00 + ( val01 - val00 ) * distance1 ) );
200 if ( basei[0] > this->m_EndIndex[0] )
204 if ( basei[1] > this->m_EndIndex[1] )
206 return ( static_cast< OutputType >( val00 ) );
208 const RealType & val01 = inputImagePtr->GetPixel(basei);
209 return ( static_cast< OutputType >( val00 + ( val01 - val00 ) * distance1 ) );
211 const RealType & val10 = inputImagePtr->GetPixel(basei);
213 const RealType & valx0 = val00 + ( val10 - val00 ) * distance0;
216 if ( basei[1] > this->m_EndIndex[1] )
218 return ( static_cast< OutputType >( valx0 ) );
220 const RealType & val11 = inputImagePtr->GetPixel(basei);
222 const RealType & val01 = inputImagePtr->GetPixel(basei);
224 const RealType & valx1 = val01 + ( val11 - val01 ) * distance0;
226 return ( static_cast< OutputType >( valx0 + ( valx1 - valx0 ) * distance1 ) );
233 basei[0] = Math::Floor< IndexValueType >(index[0]);
234 if ( basei[0] < this->m_StartIndex[0] )
236 basei[0] = this->m_StartIndex[0];
240 basei[1] = Math::Floor< IndexValueType >(index[1]);
241 if ( basei[1] < this->m_StartIndex[1] )
243 basei[1] = this->m_StartIndex[1];
247 basei[2] = Math::Floor< IndexValueType >(index[2]);
248 if ( basei[2] < this->m_StartIndex[2] )
250 basei[2] = this->m_StartIndex[2];
254 const TInputImage *
const inputImagePtr = this->GetInputImage();
255 const RealType & val000 = inputImagePtr->GetPixel(basei);
256 if ( distance0 <= 0. && distance1 <= 0. && distance2 <= 0. )
258 return ( static_cast< OutputType >( val000 ) );
261 if ( distance2 <= 0. )
263 if ( distance1 <= 0. )
266 if ( basei[0] > this->m_EndIndex[0] )
268 return ( static_cast< OutputType >( val000 ) );
270 const RealType & val100 = inputImagePtr->GetPixel(basei);
272 return static_cast< OutputType >( val000 + ( val100 - val000 ) * distance0 );
274 else if ( distance0 <= 0. )
277 if ( basei[1] > this->m_EndIndex[1] )
279 return ( static_cast< OutputType >( val000 ) );
281 const RealType & val010 = inputImagePtr->GetPixel(basei);
283 return static_cast< OutputType >( val000 + ( val010 - val000 ) * distance1 );
288 if ( basei[0] > this->m_EndIndex[0] )
292 if ( basei[1] > this->m_EndIndex[1] )
294 return ( static_cast< OutputType >( val000 ) );
296 const RealType & val010 = inputImagePtr->GetPixel(basei);
297 return static_cast< OutputType >( val000 + ( val010 - val000 ) * distance1 );
299 const RealType & val100 = inputImagePtr->GetPixel(basei);
300 const RealType & valx00 = val000 + ( val100 - val000 ) * distance0;
303 if ( basei[1] > this->m_EndIndex[1] )
305 return ( static_cast< OutputType >( valx00 ) );
307 const RealType & val110 = inputImagePtr->GetPixel(basei);
310 const RealType & val010 = inputImagePtr->GetPixel(basei);
311 const RealType & valx10 = val010 + ( val110 - val010 ) * distance0;
313 return static_cast< OutputType >( valx00 + ( valx10 - valx00 ) * distance1 );
318 if ( distance1 <= 0. )
320 if ( distance0 <= 0. )
323 if ( basei[2] > this->m_EndIndex[2] )
325 return ( static_cast< OutputType >( val000 ) );
327 const RealType & val001 = inputImagePtr->GetPixel(basei);
329 return static_cast< OutputType >( val000 + ( val001 - val000 ) * distance2 );
334 if ( basei[0] > this->m_EndIndex[0] )
338 if ( basei[2] > this->m_EndIndex[2] )
340 return ( static_cast< OutputType >( val000 ) );
342 const RealType & val001 = inputImagePtr->GetPixel(basei);
344 return static_cast< OutputType >( val000 + ( val001 - val000 ) * distance2 );
346 const RealType & val100 = inputImagePtr->GetPixel(basei);
348 const RealType & valx00 = val000 + ( val100 - val000 ) * distance0;
351 if ( basei[2] > this->m_EndIndex[2] )
353 return ( static_cast< OutputType >( valx00 ) );
355 const RealType & val101 = inputImagePtr->GetPixel(basei);
358 const RealType & val001 = inputImagePtr->GetPixel(basei);
360 const RealType & valx01 = val001 + ( val101 - val001 ) * distance0;
362 return static_cast< OutputType >( valx00 + ( valx01 - valx00 ) * distance2 );
365 else if ( distance0 <= 0. )
368 if ( basei[1] > this->m_EndIndex[1] )
372 if ( basei[2] > this->m_EndIndex[2] )
374 return ( static_cast< OutputType >( val000 ) );
376 const RealType & val001 = inputImagePtr->GetPixel(basei);
378 return static_cast< OutputType >( val000 + ( val001 - val000 ) * distance2 );
380 const RealType & val010 = inputImagePtr->GetPixel(basei);
382 const RealType & val0x0 = val000 + ( val010 - val000 ) * distance1;
385 if ( basei[2] > this->m_EndIndex[2] )
387 return ( static_cast< OutputType >( val0x0 ) );
389 const RealType & val011 = inputImagePtr->GetPixel(basei);
392 const RealType & val001 = inputImagePtr->GetPixel(basei);
394 const RealType & val0x1 = val001 + ( val011 - val001 ) * distance1;
396 return static_cast< OutputType >( val0x0 + ( val0x1 - val0x0 ) * distance2 );
401 if ( basei[0] > this->m_EndIndex[0] )
405 if ( basei[1] > this->m_EndIndex[1] )
409 if ( basei[2] > this->m_EndIndex[2] )
411 return ( static_cast< OutputType >( val000 ) );
413 const RealType & val001 = inputImagePtr->GetPixel(basei);
415 return static_cast< OutputType >( val000 + ( val001 - val000 ) * distance2 );
417 const RealType & val010 = inputImagePtr->GetPixel(basei);
418 const RealType & val0x0 = val000 + ( val010 - val000 ) * distance1;
421 if ( basei[2] > this->m_EndIndex[2] )
423 return ( static_cast< OutputType >( val0x0 ) );
425 const RealType & val011 = inputImagePtr->GetPixel(basei);
428 const RealType & val001 = inputImagePtr->GetPixel(basei);
430 const RealType & val0x1 = val001 + ( val011 - val001 ) * distance1;
432 return static_cast< OutputType >( val0x0 + ( val0x1 - val0x0 ) * distance2 );
434 const RealType & val100 = inputImagePtr->GetPixel(basei);
436 const RealType & valx00 = val000 + ( val100 - val000 ) * distance0;
439 if ( basei[1] > this->m_EndIndex[1] )
443 if ( basei[2] > this->m_EndIndex[2] )
445 return ( static_cast< OutputType >( valx00 ) );
447 const RealType & val101 = inputImagePtr->GetPixel(basei);
450 const RealType & val001 = inputImagePtr->GetPixel(basei);
452 const RealType & valx01 = val001 + ( val101 - val001 ) * distance0;
454 return static_cast< OutputType >( valx00 + ( valx01 - valx00 ) * distance2 );
456 const RealType & val110 = inputImagePtr->GetPixel(basei);
459 const RealType & val010 = inputImagePtr->GetPixel(basei);
461 const RealType & valx10 = val010 + ( val110 - val010 ) * distance0;
463 const RealType & valxx0 = valx00 + ( valx10 - valx00 ) * distance1;
466 if ( basei[2] > this->m_EndIndex[2] )
468 return ( static_cast< OutputType >( valxx0 ) );
470 const RealType & val011 = inputImagePtr->GetPixel(basei);
473 const RealType & val111 = inputImagePtr->GetPixel(basei);
476 const RealType & val101 = inputImagePtr->GetPixel(basei);
479 const RealType & val001 = inputImagePtr->GetPixel(basei);
481 const RealType & valx01 = val001 + ( val101 - val001 ) * distance0;
482 const RealType & valx11 = val011 + ( val111 - val011 ) * distance0;
483 const RealType & valxx1 = valx01 + ( valx11 - valx01 ) * distance1;
485 return ( static_cast< OutputType >( valxx0 + ( valxx1 - valxx0 ) * distance2 ) );
493 return this->EvaluateUnoptimized(index);
497 virtual inline OutputType EvaluateUnoptimized(
498 const ContinuousIndexType & index)
const;
502 template<
typename RealTypeScalarRealType>
510 const typename TInputImage::PixelType & tempPixel = inputImagePtr->GetPixel(idx);
511 const unsigned int sizeOfVarLengthVector = tempPixel.GetSize();
512 tempZeros.
SetSize(sizeOfVarLengthVector);
516 template<
typename RealTypeScalarRealType>
519 RealTypeScalarRealType & tempZeros)
const
528 #ifndef ITK_MANUAL_INSTANTIATION
529 #include "itkLinearInterpolateImageFunction.hxx"
OutputType EvaluateOptimized(const DispatchBase &, const ContinuousIndexType &index) const
Light weight base class for most itk classes.
void MakeZeroInitializer(const TInputImage *const , RealTypeScalarRealType &tempZeros) const
SmartPointer< Self > Pointer
Superclass::ContinuousIndexType ContinuousIndexType
virtual OutputType EvaluateAtContinuousIndex(const ContinuousIndexType &index) const override
LinearInterpolateImageFunction Self
void MakeZeroInitializer(const TInputImage *const inputImagePtr, VariableLengthVector< RealTypeScalarRealType > &tempZeros) const
A method to generically set all components to zero.
ContinuousIndexType::ValueType InternalComputationType
Superclass::IndexType IndexType
Superclass::OutputType OutputType
Represents an array whose length can be defined at run-time.
void Fill(IndexValueType value)
Linearly interpolate an image at specified positions.
Superclass::IndexType IndexType
SmartPointer< const Self > ConstPointer
Superclass::ContinuousIndexType ContinuousIndexType
Base class for all image interpolaters.
Superclass::InputImageType InputImageType
Superclass::InputPixelType InputPixelType
Superclass::OutputType OutputType
Control indentation during Print() invocation.
Define additional traits for native types such as int or float.
OutputType EvaluateOptimized(const Dispatch< 1 > &, const ContinuousIndexType &index) const
void SetSize(unsigned int sz, TReallocatePolicy reallocatePolicy, TKeepValuesPolicy keepValues)
OutputType EvaluateOptimized(const Dispatch< 0 > &, const ContinuousIndexType &) const
void Fill(TValue const &v)
OutputType EvaluateOptimized(const Dispatch< 3 > &, const ContinuousIndexType &index) const
InterpolateImageFunction< TInputImage, TCoordRep > Superclass
Superclass::RealType RealType
OutputType EvaluateOptimized(const Dispatch< 2 > &, const ContinuousIndexType &index) const
NumericTraits< typename TInputImage::PixelType >::RealType RealType
ImageBaseType::IndexType IndexType