18#ifndef itkLinearInterpolateImageFunction_h
19#define itkLinearInterpolateImageFunction_h
50template <
typename TInputImage,
typename TCoordRep =
double>
69 using typename Superclass::OutputType;
72 using typename Superclass::InputImageType;
75 using typename Superclass::InputPixelType;
78 using typename Superclass::RealType;
81 static constexpr unsigned int ImageDimension = Superclass::ImageDimension;
90 using typename Superclass::ContinuousIndexType;
110 return SizeType::Filled(1);
122 template <
unsigned int>
136 basei[0] = std::max(Math::Floor<IndexValueType>(index[0]), this->m_StartIndex[0]);
140 const TInputImage *
const inputImagePtr = this->GetInputImage();
141 const RealType & val0 = inputImagePtr->GetPixel(basei);
148 if (basei[0] > this->m_EndIndex[0])
152 const RealType & val1 = inputImagePtr->GetPixel(basei);
154 return (
static_cast<OutputType>(val0 + (val1 - val0) * distance));
162 basei[0] = std::max(Math::Floor<IndexValueType>(index[0]), this->m_StartIndex[0]);
165 basei[1] = std::max(Math::Floor<IndexValueType>(index[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.)
174 else if (distance1 <= 0.)
177 if (basei[0] > this->m_EndIndex[0])
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])
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])
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])
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] = std::max(Math::Floor<IndexValueType>(index[0]), this->m_StartIndex[0]);
233 basei[1] = std::max(Math::Floor<IndexValueType>(index[1]), this->m_StartIndex[1]);
236 basei[2] = std::max(Math::Floor<IndexValueType>(index[2]), this->m_StartIndex[2]);
239 const TInputImage *
const inputImagePtr = this->GetInputImage();
240 const RealType & val000 = inputImagePtr->GetPixel(basei);
241 if (distance0 <= 0. && distance1 <= 0. && distance2 <= 0.)
251 if (basei[0] > this->m_EndIndex[0])
255 const RealType & val100 = inputImagePtr->GetPixel(basei);
257 return static_cast<OutputType>(val000 + (val100 - val000) * distance0);
259 else if (distance0 <= 0.)
262 if (basei[1] > this->m_EndIndex[1])
266 const RealType & val010 = inputImagePtr->GetPixel(basei);
268 return static_cast<OutputType>(val000 + (val010 - val000) * distance1);
273 if (basei[0] > this->m_EndIndex[0])
277 if (basei[1] > this->m_EndIndex[1])
281 const RealType & val010 = inputImagePtr->GetPixel(basei);
282 return static_cast<OutputType>(val000 + (val010 - val000) * distance1);
284 const RealType & val100 = inputImagePtr->GetPixel(basei);
285 const RealType & valx00 = val000 + (val100 - val000) * distance0;
288 if (basei[1] > this->m_EndIndex[1])
292 const RealType & val110 = inputImagePtr->GetPixel(basei);
295 const RealType & val010 = inputImagePtr->GetPixel(basei);
296 const RealType & valx10 = val010 + (val110 - val010) * distance0;
298 return static_cast<OutputType>(valx00 + (valx10 - valx00) * distance1);
308 if (basei[2] > this->m_EndIndex[2])
312 const RealType & val001 = inputImagePtr->GetPixel(basei);
314 return static_cast<OutputType>(val000 + (val001 - val000) * distance2);
319 if (basei[0] > this->m_EndIndex[0])
323 if (basei[2] > this->m_EndIndex[2])
327 const RealType & val001 = inputImagePtr->GetPixel(basei);
329 return static_cast<OutputType>(val000 + (val001 - val000) * distance2);
331 const RealType & val100 = inputImagePtr->GetPixel(basei);
333 const RealType & valx00 = val000 + (val100 - val000) * distance0;
336 if (basei[2] > this->m_EndIndex[2])
340 const RealType & val101 = inputImagePtr->GetPixel(basei);
343 const RealType & val001 = inputImagePtr->GetPixel(basei);
345 const RealType & valx01 = val001 + (val101 - val001) * distance0;
347 return static_cast<OutputType>(valx00 + (valx01 - valx00) * distance2);
350 else if (distance0 <= 0.)
353 if (basei[1] > this->m_EndIndex[1])
357 if (basei[2] > this->m_EndIndex[2])
361 const RealType & val001 = inputImagePtr->GetPixel(basei);
363 return static_cast<OutputType>(val000 + (val001 - val000) * distance2);
365 const RealType & val010 = inputImagePtr->GetPixel(basei);
367 const RealType & val0x0 = val000 + (val010 - val000) * distance1;
370 if (basei[2] > this->m_EndIndex[2])
374 const RealType & val011 = inputImagePtr->GetPixel(basei);
377 const RealType & val001 = inputImagePtr->GetPixel(basei);
379 const RealType & val0x1 = val001 + (val011 - val001) * distance1;
381 return static_cast<OutputType>(val0x0 + (val0x1 - val0x0) * distance2);
386 if (basei[0] > this->m_EndIndex[0])
390 if (basei[1] > this->m_EndIndex[1])
394 if (basei[2] > this->m_EndIndex[2])
398 const RealType & val001 = inputImagePtr->GetPixel(basei);
400 return static_cast<OutputType>(val000 + (val001 - val000) * distance2);
402 const RealType & val010 = inputImagePtr->GetPixel(basei);
403 const RealType & val0x0 = val000 + (val010 - val000) * distance1;
406 if (basei[2] > this->m_EndIndex[2])
410 const RealType & val011 = inputImagePtr->GetPixel(basei);
413 const RealType & val001 = inputImagePtr->GetPixel(basei);
415 const RealType & val0x1 = val001 + (val011 - val001) * distance1;
417 return static_cast<OutputType>(val0x0 + (val0x1 - val0x0) * distance2);
419 const RealType & val100 = inputImagePtr->GetPixel(basei);
421 const RealType & valx00 = val000 + (val100 - val000) * distance0;
424 if (basei[1] > this->m_EndIndex[1])
428 if (basei[2] > this->m_EndIndex[2])
432 const RealType & val101 = inputImagePtr->GetPixel(basei);
435 const RealType & val001 = inputImagePtr->GetPixel(basei);
437 const RealType & valx01 = val001 + (val101 - val001) * distance0;
439 return static_cast<OutputType>(valx00 + (valx01 - valx00) * distance2);
441 const RealType & val110 = inputImagePtr->GetPixel(basei);
444 const RealType & val010 = inputImagePtr->GetPixel(basei);
446 const RealType & valx10 = val010 + (val110 - val010) * distance0;
448 const RealType & valxx0 = valx00 + (valx10 - valx00) * distance1;
451 if (basei[2] > this->m_EndIndex[2])
455 const RealType & val011 = inputImagePtr->GetPixel(basei);
458 const RealType & val111 = inputImagePtr->GetPixel(basei);
461 const RealType & val101 = inputImagePtr->GetPixel(basei);
464 const RealType & val001 = inputImagePtr->GetPixel(basei);
466 const RealType & valx01 = val001 + (val101 - val001) * distance0;
467 const RealType & valx11 = val011 + (val111 - val011) * distance0;
468 const RealType & valxx1 = valx01 + (valx11 - valx01) * distance1;
470 return (
static_cast<OutputType>(valxx0 + (valxx1 - valxx0) * distance2));
478 return this->EvaluateUnoptimized(index);
482 virtual inline OutputType
487 template <
typename RealTypeScalarRealType>
494 const typename TInputImage::PixelType & tempPixel = inputImagePtr->GetPixel(idx);
495 const unsigned int sizeOfVarLengthVector = tempPixel.GetSize();
496 tempZeros.SetSize(sizeOfVarLengthVector);
497 tempZeros.Fill(RealTypeScalarRealType{});
500 template <
typename RealTypeScalarRealType>
502 MakeZeroInitializer(
const TInputImage *
const itkNotUsed(inputImagePtr), RealTypeScalarRealType & tempZeros)
const
505 tempZeros = RealTypeScalarRealType{};
510#ifndef ITK_MANUAL_INSTANTIATION
511# include "itkLinearInterpolateImageFunction.hxx"
NumericTraits< TInputImage::PixelType >::RealType OutputType
typename InputImageType::IndexType IndexType
Control indentation during Print() invocation.
Base class for all image interpolators.
typename NumericTraits< typename TInputImage::PixelType >::RealType RealType
Light weight base class for most itk classes.
Linearly interpolate an image at specified positions.
void PrintSelf(std::ostream &os, Indent indent) const override
~LinearInterpolateImageFunction() override=default
OutputType EvaluateOptimized(const Dispatch< 2 > &, const ContinuousIndexType &index) const
void MakeZeroInitializer(const TInputImage *const inputImagePtr, VariableLengthVector< RealTypeScalarRealType > &tempZeros) const
A method to generically set all components to zero.
OutputType EvaluateOptimized(const Dispatch< 3 > &, const ContinuousIndexType &index) const
LinearInterpolateImageFunction()=default
void MakeZeroInitializer(const TInputImage *const, RealTypeScalarRealType &tempZeros) const
virtual OutputType EvaluateUnoptimized(const ContinuousIndexType &index) const
OutputType EvaluateOptimized(const Dispatch< 0 > &, const ContinuousIndexType &) const
typename ContinuousIndexType::ValueType InternalComputationType
SizeType GetRadius() const override
OutputType EvaluateOptimized(const DispatchBase &, const ContinuousIndexType &index) const
OutputType EvaluateOptimized(const Dispatch< 1 > &, const ContinuousIndexType &index) const
OutputType EvaluateAtContinuousIndex(const ContinuousIndexType &index) const override
ImageBaseType::IndexType IndexType
ImageBaseType::SizeType SizeType
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....