18 #ifndef itkLinearInterpolateImageFunction_h
19 #define itkLinearInterpolateImageFunction_h
50 template <
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);
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));
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] = 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);
259 else if (distance0 <= 0.)
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);
319 if (basei[0] > this->m_EndIndex[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);
331 const RealType & val100 = inputImagePtr->GetPixel(basei);
333 const RealType & valx00 = val000 + (val100 - val000) * distance0;
336 if (basei[2] > this->m_EndIndex[2])
338 return (static_cast<OutputType>(valx00));
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])
359 return (static_cast<OutputType>(val000));
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])
372 return (static_cast<OutputType>(val0x0));
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])
396 return (static_cast<OutputType>(val000));
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])
408 return (static_cast<OutputType>(val0x0));
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])
430 return (static_cast<OutputType>(valx00));
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])
453 return (static_cast<OutputType>(valxx0));
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
483 EvaluateUnoptimized(
const ContinuousIndexType & index)
const;
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"