18#ifndef itkLinearInterpolateImageFunction_h
19#define itkLinearInterpolateImageFunction_h
50template <
typename TInputImage,
typename TCoordinate =
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.)
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);
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);
318 if (basei[0] > this->m_EndIndex[0])
322 if (basei[2] > this->m_EndIndex[2])
326 const RealType & val001 = inputImagePtr->GetPixel(basei);
328 return static_cast<OutputType>(val000 + (val001 - val000) * distance2);
330 const RealType & val100 = inputImagePtr->GetPixel(basei);
332 const RealType & valx00 = val000 + (val100 - val000) * distance0;
335 if (basei[2] > this->m_EndIndex[2])
339 const RealType & val101 = inputImagePtr->GetPixel(basei);
342 const RealType & val001 = inputImagePtr->GetPixel(basei);
344 const RealType & valx01 = val001 + (val101 - val001) * distance0;
346 return static_cast<OutputType>(valx00 + (valx01 - valx00) * distance2);
348 else if (distance0 <= 0.)
351 if (basei[1] > this->m_EndIndex[1])
355 if (basei[2] > this->m_EndIndex[2])
359 const RealType & val001 = inputImagePtr->GetPixel(basei);
361 return static_cast<OutputType>(val000 + (val001 - val000) * distance2);
363 const RealType & val010 = inputImagePtr->GetPixel(basei);
365 const RealType & val0x0 = val000 + (val010 - val000) * distance1;
368 if (basei[2] > this->m_EndIndex[2])
372 const RealType & val011 = inputImagePtr->GetPixel(basei);
375 const RealType & val001 = inputImagePtr->GetPixel(basei);
377 const RealType & val0x1 = val001 + (val011 - val001) * distance1;
379 return static_cast<OutputType>(val0x0 + (val0x1 - val0x0) * distance2);
384 if (basei[0] > this->m_EndIndex[0])
388 if (basei[1] > this->m_EndIndex[1])
392 if (basei[2] > this->m_EndIndex[2])
396 const RealType & val001 = inputImagePtr->GetPixel(basei);
398 return static_cast<OutputType>(val000 + (val001 - val000) * distance2);
400 const RealType & val010 = inputImagePtr->GetPixel(basei);
401 const RealType & val0x0 = val000 + (val010 - val000) * distance1;
404 if (basei[2] > this->m_EndIndex[2])
408 const RealType & val011 = inputImagePtr->GetPixel(basei);
411 const RealType & val001 = inputImagePtr->GetPixel(basei);
413 const RealType & val0x1 = val001 + (val011 - val001) * distance1;
415 return static_cast<OutputType>(val0x0 + (val0x1 - val0x0) * distance2);
417 const RealType & val100 = inputImagePtr->GetPixel(basei);
419 const RealType & valx00 = val000 + (val100 - val000) * distance0;
422 if (basei[1] > this->m_EndIndex[1])
426 if (basei[2] > this->m_EndIndex[2])
430 const RealType & val101 = inputImagePtr->GetPixel(basei);
433 const RealType & val001 = inputImagePtr->GetPixel(basei);
435 const RealType & valx01 = val001 + (val101 - val001) * distance0;
437 return static_cast<OutputType>(valx00 + (valx01 - valx00) * distance2);
439 const RealType & val110 = inputImagePtr->GetPixel(basei);
442 const RealType & val010 = inputImagePtr->GetPixel(basei);
444 const RealType & valx10 = val010 + (val110 - val010) * distance0;
446 const RealType & valxx0 = valx00 + (valx10 - valx00) * distance1;
449 if (basei[2] > this->m_EndIndex[2])
453 const RealType & val011 = inputImagePtr->GetPixel(basei);
456 const RealType & val111 = inputImagePtr->GetPixel(basei);
459 const RealType & val101 = inputImagePtr->GetPixel(basei);
462 const RealType & val001 = inputImagePtr->GetPixel(basei);
464 const RealType & valx01 = val001 + (val101 - val001) * distance0;
465 const RealType & valx11 = val011 + (val111 - val011) * distance0;
466 const RealType & valxx1 = valx01 + (valx11 - valx01) * distance1;
468 return (
static_cast<OutputType>(valxx0 + (valxx1 - valxx0) * distance2));
476 return this->EvaluateUnoptimized(index);
480 virtual inline OutputType
485 template <
typename RealTypeScalarRealType>
492 const typename TInputImage::PixelType & tempPixel = inputImagePtr->GetPixel(idx);
493 const unsigned int sizeOfVarLengthVector = tempPixel.GetSize();
494 tempZeros.SetSize(sizeOfVarLengthVector);
495 tempZeros.Fill(RealTypeScalarRealType{});
498 template <
typename RealTypeScalarRealType>
500 MakeZeroInitializer(
const TInputImage *
const itkNotUsed(inputImagePtr), RealTypeScalarRealType & tempZeros)
const
503 tempZeros = RealTypeScalarRealType{};
508#ifndef ITK_MANUAL_INSTANTIATION
509# 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.
typename ContinuousIndexType::ValueType InternalComputationType
void PrintSelf(std::ostream &os, Indent indent) const override
LinearInterpolateImageFunction()=default
SizeType GetRadius() const override
OutputType EvaluateOptimized(const Dispatch< 2 > &, const ContinuousIndexType &index) const
OutputType EvaluateOptimized(const Dispatch< 1 > &, const ContinuousIndexType &index) const
virtual OutputType EvaluateUnoptimized(const ContinuousIndexType &index) const
OutputType EvaluateOptimized(const Dispatch< 3 > &, const ContinuousIndexType &index) const
OutputType EvaluateAtContinuousIndex(const ContinuousIndexType &index) const override
OutputType EvaluateOptimized(const Dispatch< 0 > &, const ContinuousIndexType &) const
void MakeZeroInitializer(const TInputImage *const, RealTypeScalarRealType &tempZeros) const
~LinearInterpolateImageFunction() override=default
OutputType EvaluateOptimized(const DispatchBase &, const ContinuousIndexType &index) const
void MakeZeroInitializer(const TInputImage *const inputImagePtr, VariableLengthVector< RealTypeScalarRealType > &tempZeros) const
A method to generically set all components to zero.
ImageBaseType::IndexType IndexType
ImageBaseType::SizeType SizeType
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....