18 #ifndef itkLinearInterpolateImageFunction_h
19 #define itkLinearInterpolateImageFunction_h
49 template <
typename TInputImage,
typename TCoordRep =
double>
77 using RealType =
typename Superclass::RealType;
80 static constexpr
unsigned int ImageDimension = Superclass::ImageDimension;
109 return SizeType::Filled(1);
116 PrintSelf(std::ostream & os,
Indent indent)
const override;
121 template <
unsigned int>
135 basei[0] = Math::Floor<IndexValueType>(index[0]);
136 if (basei[0] < this->m_StartIndex[0])
138 basei[0] = this->m_StartIndex[0];
143 const TInputImage *
const inputImagePtr = this->GetInputImage();
144 const RealType & val0 = inputImagePtr->GetPixel(basei);
147 return (static_cast<OutputType>(val0));
151 if (basei[0] > this->m_EndIndex[0])
153 return (static_cast<OutputType>(val0));
155 const RealType & val1 = inputImagePtr->GetPixel(basei);
157 return (static_cast<OutputType>(val0 + (val1 - val0) * distance));
165 basei[0] = Math::Floor<IndexValueType>(index[0]);
166 if (basei[0] < this->m_StartIndex[0])
168 basei[0] = this->m_StartIndex[0];
172 basei[1] = Math::Floor<IndexValueType>(index[1]);
173 if (basei[1] < this->m_StartIndex[1])
175 basei[1] = this->m_StartIndex[1];
179 const TInputImage *
const inputImagePtr = this->GetInputImage();
180 const RealType & val00 = inputImagePtr->GetPixel(basei);
181 if (distance0 <= 0. && distance1 <= 0.)
183 return (static_cast<OutputType>(val00));
185 else if (distance1 <= 0.)
188 if (basei[0] > this->m_EndIndex[0])
190 return (static_cast<OutputType>(val00));
192 const RealType & val10 = inputImagePtr->GetPixel(basei);
193 return (static_cast<OutputType>(val00 + (val10 - val00) * distance0));
195 else if (distance0 <= 0.)
198 if (basei[1] > this->m_EndIndex[1])
200 return (static_cast<OutputType>(val00));
202 const RealType & val01 = inputImagePtr->GetPixel(basei);
203 return (static_cast<OutputType>(val00 + (val01 - val00) * distance1));
208 if (basei[0] > this->m_EndIndex[0])
212 if (basei[1] > this->m_EndIndex[1])
214 return (static_cast<OutputType>(val00));
216 const RealType & val01 = inputImagePtr->GetPixel(basei);
217 return (static_cast<OutputType>(val00 + (val01 - val00) * distance1));
219 const RealType & val10 = inputImagePtr->GetPixel(basei);
221 const RealType & valx0 = val00 + (val10 - val00) * distance0;
224 if (basei[1] > this->m_EndIndex[1])
226 return (static_cast<OutputType>(valx0));
228 const RealType & val11 = inputImagePtr->GetPixel(basei);
230 const RealType & val01 = inputImagePtr->GetPixel(basei);
232 const RealType & valx1 = val01 + (val11 - val01) * distance0;
234 return (static_cast<OutputType>(valx0 + (valx1 - valx0) * distance1));
241 basei[0] = Math::Floor<IndexValueType>(index[0]);
242 if (basei[0] < this->m_StartIndex[0])
244 basei[0] = this->m_StartIndex[0];
248 basei[1] = Math::Floor<IndexValueType>(index[1]);
249 if (basei[1] < this->m_StartIndex[1])
251 basei[1] = this->m_StartIndex[1];
255 basei[2] = Math::Floor<IndexValueType>(index[2]);
256 if (basei[2] < this->m_StartIndex[2])
258 basei[2] = this->m_StartIndex[2];
262 const TInputImage *
const inputImagePtr = this->GetInputImage();
263 const RealType & val000 = inputImagePtr->GetPixel(basei);
264 if (distance0 <= 0. && distance1 <= 0. && distance2 <= 0.)
266 return (static_cast<OutputType>(val000));
274 if (basei[0] > this->m_EndIndex[0])
276 return (static_cast<OutputType>(val000));
278 const RealType & val100 = inputImagePtr->GetPixel(basei);
280 return static_cast<OutputType>(val000 + (val100 - val000) * distance0);
282 else if (distance0 <= 0.)
285 if (basei[1] > this->m_EndIndex[1])
287 return (static_cast<OutputType>(val000));
289 const RealType & val010 = inputImagePtr->GetPixel(basei);
291 return static_cast<OutputType>(val000 + (val010 - val000) * distance1);
296 if (basei[0] > this->m_EndIndex[0])
300 if (basei[1] > this->m_EndIndex[1])
302 return (static_cast<OutputType>(val000));
304 const RealType & val010 = inputImagePtr->GetPixel(basei);
305 return static_cast<OutputType>(val000 + (val010 - val000) * distance1);
307 const RealType & val100 = inputImagePtr->GetPixel(basei);
308 const RealType & valx00 = val000 + (val100 - val000) * distance0;
311 if (basei[1] > this->m_EndIndex[1])
313 return (static_cast<OutputType>(valx00));
315 const RealType & val110 = inputImagePtr->GetPixel(basei);
318 const RealType & val010 = inputImagePtr->GetPixel(basei);
319 const RealType & valx10 = val010 + (val110 - val010) * distance0;
321 return static_cast<OutputType>(valx00 + (valx10 - valx00) * distance1);
331 if (basei[2] > this->m_EndIndex[2])
333 return (static_cast<OutputType>(val000));
335 const RealType & val001 = inputImagePtr->GetPixel(basei);
337 return static_cast<OutputType>(val000 + (val001 - val000) * distance2);
342 if (basei[0] > this->m_EndIndex[0])
346 if (basei[2] > this->m_EndIndex[2])
348 return (static_cast<OutputType>(val000));
350 const RealType & val001 = inputImagePtr->GetPixel(basei);
352 return static_cast<OutputType>(val000 + (val001 - val000) * distance2);
354 const RealType & val100 = inputImagePtr->GetPixel(basei);
356 const RealType & valx00 = val000 + (val100 - val000) * distance0;
359 if (basei[2] > this->m_EndIndex[2])
361 return (static_cast<OutputType>(valx00));
363 const RealType & val101 = inputImagePtr->GetPixel(basei);
366 const RealType & val001 = inputImagePtr->GetPixel(basei);
368 const RealType & valx01 = val001 + (val101 - val001) * distance0;
370 return static_cast<OutputType>(valx00 + (valx01 - valx00) * distance2);
373 else if (distance0 <= 0.)
376 if (basei[1] > this->m_EndIndex[1])
380 if (basei[2] > this->m_EndIndex[2])
382 return (static_cast<OutputType>(val000));
384 const RealType & val001 = inputImagePtr->GetPixel(basei);
386 return static_cast<OutputType>(val000 + (val001 - val000) * distance2);
388 const RealType & val010 = inputImagePtr->GetPixel(basei);
390 const RealType & val0x0 = val000 + (val010 - val000) * distance1;
393 if (basei[2] > this->m_EndIndex[2])
395 return (static_cast<OutputType>(val0x0));
397 const RealType & val011 = inputImagePtr->GetPixel(basei);
400 const RealType & val001 = inputImagePtr->GetPixel(basei);
402 const RealType & val0x1 = val001 + (val011 - val001) * distance1;
404 return static_cast<OutputType>(val0x0 + (val0x1 - val0x0) * distance2);
409 if (basei[0] > this->m_EndIndex[0])
413 if (basei[1] > this->m_EndIndex[1])
417 if (basei[2] > this->m_EndIndex[2])
419 return (static_cast<OutputType>(val000));
421 const RealType & val001 = inputImagePtr->GetPixel(basei);
423 return static_cast<OutputType>(val000 + (val001 - val000) * distance2);
425 const RealType & val010 = inputImagePtr->GetPixel(basei);
426 const RealType & val0x0 = val000 + (val010 - val000) * distance1;
429 if (basei[2] > this->m_EndIndex[2])
431 return (static_cast<OutputType>(val0x0));
433 const RealType & val011 = inputImagePtr->GetPixel(basei);
436 const RealType & val001 = inputImagePtr->GetPixel(basei);
438 const RealType & val0x1 = val001 + (val011 - val001) * distance1;
440 return static_cast<OutputType>(val0x0 + (val0x1 - val0x0) * distance2);
442 const RealType & val100 = inputImagePtr->GetPixel(basei);
444 const RealType & valx00 = val000 + (val100 - val000) * distance0;
447 if (basei[1] > this->m_EndIndex[1])
451 if (basei[2] > this->m_EndIndex[2])
453 return (static_cast<OutputType>(valx00));
455 const RealType & val101 = inputImagePtr->GetPixel(basei);
458 const RealType & val001 = inputImagePtr->GetPixel(basei);
460 const RealType & valx01 = val001 + (val101 - val001) * distance0;
462 return static_cast<OutputType>(valx00 + (valx01 - valx00) * distance2);
464 const RealType & val110 = inputImagePtr->GetPixel(basei);
467 const RealType & val010 = inputImagePtr->GetPixel(basei);
469 const RealType & valx10 = val010 + (val110 - val010) * distance0;
471 const RealType & valxx0 = valx00 + (valx10 - valx00) * distance1;
474 if (basei[2] > this->m_EndIndex[2])
476 return (static_cast<OutputType>(valxx0));
478 const RealType & val011 = inputImagePtr->GetPixel(basei);
481 const RealType & val111 = inputImagePtr->GetPixel(basei);
484 const RealType & val101 = inputImagePtr->GetPixel(basei);
487 const RealType & val001 = inputImagePtr->GetPixel(basei);
489 const RealType & valx01 = val001 + (val101 - val001) * distance0;
490 const RealType & valx11 = val011 + (val111 - val011) * distance0;
491 const RealType & valxx1 = valx01 + (valx11 - valx01) * distance1;
493 return (static_cast<OutputType>(valxx0 + (valxx1 - valxx0) * distance2));
501 return this->EvaluateUnoptimized(index);
505 virtual inline OutputType
506 EvaluateUnoptimized(
const ContinuousIndexType & index)
const;
510 template <
typename RealTypeScalarRealType>
518 const typename TInputImage::PixelType & tempPixel = inputImagePtr->GetPixel(idx);
519 const unsigned int sizeOfVarLengthVector = tempPixel.GetSize();
520 tempZeros.
SetSize(sizeOfVarLengthVector);
524 template <
typename RealTypeScalarRealType>
526 MakeZeroInitializer(
const TInputImage *
const itkNotUsed(inputImagePtr), RealTypeScalarRealType & tempZeros)
const
534 #ifndef ITK_MANUAL_INSTANTIATION
535 # include "itkLinearInterpolateImageFunction.hxx"