18 #ifndef itkLinearInterpolateImageFunction_h
19 #define itkLinearInterpolateImageFunction_h
50 template <
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);
117 PrintSelf(std::ostream & os,
Indent indent)
const override;
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);
144 return (static_cast<OutputType>(val0));
148 if (basei[0] > this->m_EndIndex[0])
150 return (static_cast<OutputType>(val0));
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.)
172 return (static_cast<OutputType>(val00));
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] = 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.)
243 return (static_cast<OutputType>(val000));
251 if (basei[0] > this->m_EndIndex[0])
253 return (static_cast<OutputType>(val000));
255 const RealType & val100 = inputImagePtr->GetPixel(basei);
257 return static_cast<OutputType>(val000 + (val100 - val000) * distance0);
262 if (basei[1] > this->m_EndIndex[1])
264 return (static_cast<OutputType>(val000));
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])
279 return (static_cast<OutputType>(val000));
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])
290 return (static_cast<OutputType>(valx00));
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])
310 return (static_cast<OutputType>(val000));
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])
324 return (static_cast<OutputType>(val000));
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])
337 return (static_cast<OutputType>(valx00));
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])
357 return (static_cast<OutputType>(val000));
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])
370 return (static_cast<OutputType>(val0x0));
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])
394 return (static_cast<OutputType>(val000));
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])
406 return (static_cast<OutputType>(val0x0));
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])
428 return (static_cast<OutputType>(valx00));
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])
451 return (static_cast<OutputType>(valxx0));
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
481 EvaluateUnoptimized(
const ContinuousIndexType & index)
const;
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"