18 #ifndef itkLinearInterpolateImageFunction_h
19 #define itkLinearInterpolateImageFunction_h
48 template<
typename TInputImage,
typename TCoordRep =
double >
77 using RealType =
typename Superclass::RealType;
80 static constexpr
unsigned int ImageDimension = Superclass::ImageDimension;
107 void PrintSelf(std::ostream & os,
Indent indent)
const override;
111 template<
unsigned int >
124 basei[0] = Math::Floor< IndexValueType >(index[0]);
125 if ( basei[0] < this->m_StartIndex[0] )
127 basei[0] = this->m_StartIndex[0];
132 const TInputImage *
const inputImagePtr = this->GetInputImage();
133 const RealType & val0 = inputImagePtr->GetPixel(basei);
134 if ( distance <= 0. )
136 return ( static_cast< OutputType >( val0 ) );
140 if ( basei[0] > this->m_EndIndex[0] )
142 return ( static_cast< OutputType >( val0 ) );
144 const RealType & val1 = inputImagePtr->GetPixel(basei);
146 return ( static_cast< OutputType >( val0 + ( val1 - val0 ) * distance ) );
154 basei[0] = Math::Floor< IndexValueType >(index[0]);
155 if ( basei[0] < this->m_StartIndex[0] )
157 basei[0] = this->m_StartIndex[0];
161 basei[1] = Math::Floor< IndexValueType >(index[1]);
162 if ( basei[1] < this->m_StartIndex[1] )
164 basei[1] = this->m_StartIndex[1];
168 const TInputImage *
const inputImagePtr = this->GetInputImage();
169 const RealType & val00 = inputImagePtr->GetPixel(basei);
170 if ( distance0 <= 0. && distance1 <= 0. )
172 return ( static_cast< OutputType >( val00 ) );
174 else if ( distance1 <= 0. )
177 if ( basei[0] > this->m_EndIndex[0] )
179 return ( static_cast< OutputType >( val00 ) );
181 const RealType & val10 = inputImagePtr->GetPixel(basei);
182 return ( static_cast< OutputType >( val00 + ( val10 - val00 ) * distance0 ) );
184 else if ( distance0 <= 0. )
187 if ( basei[1] > this->m_EndIndex[1] )
189 return ( static_cast< OutputType >( val00 ) );
191 const RealType & val01 = inputImagePtr->GetPixel(basei);
192 return ( static_cast< OutputType >( val00 + ( val01 - val00 ) * distance1 ) );
197 if ( basei[0] > this->m_EndIndex[0] )
201 if ( basei[1] > this->m_EndIndex[1] )
203 return ( static_cast< OutputType >( val00 ) );
205 const RealType & val01 = inputImagePtr->GetPixel(basei);
206 return ( static_cast< OutputType >( val00 + ( val01 - val00 ) * distance1 ) );
208 const RealType & val10 = inputImagePtr->GetPixel(basei);
210 const RealType & valx0 = val00 + ( val10 - val00 ) * distance0;
213 if ( basei[1] > this->m_EndIndex[1] )
215 return ( static_cast< OutputType >( valx0 ) );
217 const RealType & val11 = inputImagePtr->GetPixel(basei);
219 const RealType & val01 = inputImagePtr->GetPixel(basei);
221 const RealType & valx1 = val01 + ( val11 - val01 ) * distance0;
223 return ( static_cast< OutputType >( valx0 + ( valx1 - valx0 ) * distance1 ) );
230 basei[0] = Math::Floor< IndexValueType >(index[0]);
231 if ( basei[0] < this->m_StartIndex[0] )
233 basei[0] = this->m_StartIndex[0];
237 basei[1] = Math::Floor< IndexValueType >(index[1]);
238 if ( basei[1] < this->m_StartIndex[1] )
240 basei[1] = this->m_StartIndex[1];
244 basei[2] = Math::Floor< IndexValueType >(index[2]);
245 if ( basei[2] < this->m_StartIndex[2] )
247 basei[2] = this->m_StartIndex[2];
251 const TInputImage *
const inputImagePtr = this->GetInputImage();
252 const RealType & val000 = inputImagePtr->GetPixel(basei);
253 if ( distance0 <= 0. && distance1 <= 0. && distance2 <= 0. )
255 return ( static_cast< OutputType >( val000 ) );
258 if ( distance2 <= 0. )
260 if ( distance1 <= 0. )
263 if ( basei[0] > this->m_EndIndex[0] )
265 return ( static_cast< OutputType >( val000 ) );
267 const RealType & val100 = inputImagePtr->GetPixel(basei);
269 return static_cast< OutputType >( val000 + ( val100 - val000 ) * distance0 );
271 else if ( distance0 <= 0. )
274 if ( basei[1] > this->m_EndIndex[1] )
276 return ( static_cast< OutputType >( val000 ) );
278 const RealType & val010 = inputImagePtr->GetPixel(basei);
280 return static_cast< OutputType >( val000 + ( val010 - val000 ) * distance1 );
285 if ( basei[0] > this->m_EndIndex[0] )
289 if ( basei[1] > this->m_EndIndex[1] )
291 return ( static_cast< OutputType >( val000 ) );
293 const RealType & val010 = inputImagePtr->GetPixel(basei);
294 return static_cast< OutputType >( val000 + ( val010 - val000 ) * distance1 );
296 const RealType & val100 = inputImagePtr->GetPixel(basei);
297 const RealType & valx00 = val000 + ( val100 - val000 ) * distance0;
300 if ( basei[1] > this->m_EndIndex[1] )
302 return ( static_cast< OutputType >( valx00 ) );
304 const RealType & val110 = inputImagePtr->GetPixel(basei);
307 const RealType & val010 = inputImagePtr->GetPixel(basei);
308 const RealType & valx10 = val010 + ( val110 - val010 ) * distance0;
310 return static_cast< OutputType >( valx00 + ( valx10 - valx00 ) * distance1 );
315 if ( distance1 <= 0. )
317 if ( distance0 <= 0. )
320 if ( basei[2] > this->m_EndIndex[2] )
322 return ( static_cast< OutputType >( val000 ) );
324 const RealType & val001 = inputImagePtr->GetPixel(basei);
326 return static_cast< OutputType >( val000 + ( val001 - val000 ) * distance2 );
331 if ( basei[0] > this->m_EndIndex[0] )
335 if ( basei[2] > this->m_EndIndex[2] )
337 return ( static_cast< OutputType >( val000 ) );
339 const RealType & val001 = inputImagePtr->GetPixel(basei);
341 return static_cast< OutputType >( val000 + ( val001 - val000 ) * distance2 );
343 const RealType & val100 = inputImagePtr->GetPixel(basei);
345 const RealType & valx00 = val000 + ( val100 - val000 ) * distance0;
348 if ( basei[2] > this->m_EndIndex[2] )
350 return ( static_cast< OutputType >( valx00 ) );
352 const RealType & val101 = inputImagePtr->GetPixel(basei);
355 const RealType & val001 = inputImagePtr->GetPixel(basei);
357 const RealType & valx01 = val001 + ( val101 - val001 ) * distance0;
359 return static_cast< OutputType >( valx00 + ( valx01 - valx00 ) * distance2 );
362 else if ( distance0 <= 0. )
365 if ( basei[1] > this->m_EndIndex[1] )
369 if ( basei[2] > this->m_EndIndex[2] )
371 return ( static_cast< OutputType >( val000 ) );
373 const RealType & val001 = inputImagePtr->GetPixel(basei);
375 return static_cast< OutputType >( val000 + ( val001 - val000 ) * distance2 );
377 const RealType & val010 = inputImagePtr->GetPixel(basei);
379 const RealType & val0x0 = val000 + ( val010 - val000 ) * distance1;
382 if ( basei[2] > this->m_EndIndex[2] )
384 return ( static_cast< OutputType >( val0x0 ) );
386 const RealType & val011 = inputImagePtr->GetPixel(basei);
389 const RealType & val001 = inputImagePtr->GetPixel(basei);
391 const RealType & val0x1 = val001 + ( val011 - val001 ) * distance1;
393 return static_cast< OutputType >( val0x0 + ( val0x1 - val0x0 ) * distance2 );
398 if ( basei[0] > this->m_EndIndex[0] )
402 if ( basei[1] > this->m_EndIndex[1] )
406 if ( basei[2] > this->m_EndIndex[2] )
408 return ( static_cast< OutputType >( val000 ) );
410 const RealType & val001 = inputImagePtr->GetPixel(basei);
412 return static_cast< OutputType >( val000 + ( val001 - val000 ) * distance2 );
414 const RealType & val010 = inputImagePtr->GetPixel(basei);
415 const RealType & val0x0 = val000 + ( val010 - val000 ) * distance1;
418 if ( basei[2] > this->m_EndIndex[2] )
420 return ( static_cast< OutputType >( val0x0 ) );
422 const RealType & val011 = inputImagePtr->GetPixel(basei);
425 const RealType & val001 = inputImagePtr->GetPixel(basei);
427 const RealType & val0x1 = val001 + ( val011 - val001 ) * distance1;
429 return static_cast< OutputType >( val0x0 + ( val0x1 - val0x0 ) * distance2 );
431 const RealType & val100 = inputImagePtr->GetPixel(basei);
433 const RealType & valx00 = val000 + ( val100 - val000 ) * distance0;
436 if ( basei[1] > this->m_EndIndex[1] )
440 if ( basei[2] > this->m_EndIndex[2] )
442 return ( static_cast< OutputType >( valx00 ) );
444 const RealType & val101 = inputImagePtr->GetPixel(basei);
447 const RealType & val001 = inputImagePtr->GetPixel(basei);
449 const RealType & valx01 = val001 + ( val101 - val001 ) * distance0;
451 return static_cast< OutputType >( valx00 + ( valx01 - valx00 ) * distance2 );
453 const RealType & val110 = inputImagePtr->GetPixel(basei);
456 const RealType & val010 = inputImagePtr->GetPixel(basei);
458 const RealType & valx10 = val010 + ( val110 - val010 ) * distance0;
460 const RealType & valxx0 = valx00 + ( valx10 - valx00 ) * distance1;
463 if ( basei[2] > this->m_EndIndex[2] )
465 return ( static_cast< OutputType >( valxx0 ) );
467 const RealType & val011 = inputImagePtr->GetPixel(basei);
470 const RealType & val111 = inputImagePtr->GetPixel(basei);
473 const RealType & val101 = inputImagePtr->GetPixel(basei);
476 const RealType & val001 = inputImagePtr->GetPixel(basei);
478 const RealType & valx01 = val001 + ( val101 - val001 ) * distance0;
479 const RealType & valx11 = val011 + ( val111 - val011 ) * distance0;
480 const RealType & valxx1 = valx01 + ( valx11 - valx01 ) * distance1;
482 return ( static_cast< OutputType >( valxx0 + ( valxx1 - valxx0 ) * distance2 ) );
490 return this->EvaluateUnoptimized(index);
494 virtual inline OutputType EvaluateUnoptimized(
495 const ContinuousIndexType & index)
const;
499 template<
typename RealTypeScalarRealType>
507 const typename TInputImage::PixelType & tempPixel = inputImagePtr->GetPixel(idx);
508 const unsigned int sizeOfVarLengthVector = tempPixel.GetSize();
509 tempZeros.
SetSize(sizeOfVarLengthVector);
513 template<
typename RealTypeScalarRealType>
516 RealTypeScalarRealType & tempZeros)
const
525 #ifndef ITK_MANUAL_INSTANTIATION
526 #include "itkLinearInterpolateImageFunction.hxx"
OutputType EvaluateOptimized(const DispatchBase &, const ContinuousIndexType &index) const
Light weight base class for most itk classes.
typename Superclass::ContinuousIndexType ContinuousIndexType
void MakeZeroInitializer(const TInputImage *const , RealTypeScalarRealType &tempZeros) const
Define numeric traits for std::vector.
typename Superclass::OutputType OutputType
void MakeZeroInitializer(const TInputImage *const inputImagePtr, VariableLengthVector< RealTypeScalarRealType > &tempZeros) const
A method to generically set all components to zero.
OutputType EvaluateAtContinuousIndex(const ContinuousIndexType &index) const override
typename NumericTraits< typename TInputImage::PixelType >::RealType RealType
typename Superclass::IndexType IndexType
Represents an array whose length can be defined at run-time.
ImageBaseType::IndexType IndexType
Linearly interpolate an image at specified positions.
Base class for all image interpolaters.
typename Superclass::InputPixelType InputPixelType
typename Superclass::InputImageType InputImageType
void Fill(IndexValueType value)
Control indentation during Print() invocation.
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)
typename ContinuousIndexType::ValueType InternalComputationType
OutputType EvaluateOptimized(const Dispatch< 3 > &, const ContinuousIndexType &index) const
OutputType EvaluateOptimized(const Dispatch< 2 > &, const ContinuousIndexType &index) const