18 #ifndef __itkLinearInterpolateImageFunction_h
19 #define __itkLinearInterpolateImageFunction_h
47 template<
class TInputImage,
class TCoordRep =
double >
65 typedef typename Superclass::OutputType
OutputType;
74 typedef typename Superclass::RealType
RealType;
77 itkStaticConstMacro(ImageDimension,
unsigned int, Superclass::ImageDimension);
93 virtual inline OutputType EvaluateAtContinuousIndex(
const
103 void PrintSelf(std::ostream & os,
Indent indent)
const;
107 void operator=(
const Self &);
113 template<
unsigned int >
127 basei[0] = Math::Floor< IndexValueType >(index[0]);
128 if ( basei[0] < this->m_StartIndex[0] )
130 basei[0] = this->m_StartIndex[0];
133 const double distance = index[0] -
static_cast< double >( basei[0] );
135 const RealType val0 = this->GetInputImage()->GetPixel(basei);
137 if ( distance <= 0. )
139 return ( static_cast< OutputType >( val0 ) );
143 if ( basei[0] > this->m_EndIndex[0] )
145 return ( static_cast< OutputType >( val0 ) );
147 const RealType val1 = this->GetInputImage()->GetPixel(basei);
149 return ( static_cast< OutputType >( val0 + ( val1 - val0 ) * distance ) );
157 basei[0] = Math::Floor< IndexValueType >(index[0]);
158 if ( basei[0] < this->m_StartIndex[0] )
160 basei[0] = this->m_StartIndex[0];
162 const double distance0 = index[0] -
static_cast< double >( basei[0] );
164 basei[1] = Math::Floor< IndexValueType >(index[1]);
165 if ( basei[1] < this->m_StartIndex[1] )
167 basei[1] = this->m_StartIndex[1];
169 const double distance1 = index[1] -
static_cast< double >( basei[1] );
171 const RealType val00 = this->GetInputImage()->GetPixel(basei);
172 if ( distance0 <= 0. && distance1 <= 0. )
174 return ( static_cast< OutputType >( val00 ) );
176 else if ( distance1 <= 0. )
179 if ( basei[0] > this->m_EndIndex[0] )
181 return ( static_cast< OutputType >( val00 ) );
183 const RealType val10 = this->GetInputImage()->GetPixel(basei);
184 return ( static_cast< OutputType >( val00 + ( val10 - val00 ) * distance0 ) );
186 else if ( distance0 <= 0. )
189 if ( basei[1] > this->m_EndIndex[1] )
191 return ( static_cast< OutputType >( val00 ) );
193 const RealType val01 = this->GetInputImage()->GetPixel(basei);
194 return ( static_cast< OutputType >( val00 + ( val01 - val00 ) * distance1 ) );
199 if ( basei[0] > this->m_EndIndex[0] )
203 if ( basei[1] > this->m_EndIndex[1] )
205 return ( static_cast< OutputType >( val00 ) );
207 const RealType val01 = this->GetInputImage()->GetPixel(basei);
208 return ( static_cast< OutputType >( val00 + ( val01 - val00 ) * distance1 ) );
210 const RealType val10 = this->GetInputImage()->GetPixel(basei);
212 const RealType valx0 = val00 + ( val10 - val00 ) * distance0;
215 if ( basei[1] > this->m_EndIndex[1] )
217 return ( static_cast< OutputType >( valx0 ) );
219 const RealType val11 = this->GetInputImage()->GetPixel(basei);
221 const RealType val01 = this->GetInputImage()->GetPixel(basei);
223 const RealType valx1 = val01 + ( val11 - val01 ) * distance0;
225 return ( static_cast< OutputType >( valx0 + ( valx1 - valx0 ) * distance1 ) );
233 basei[0] = Math::Floor< IndexValueType >(index[0]);
234 if ( basei[0] < this->m_StartIndex[0] )
236 basei[0] = this->m_StartIndex[0];
238 const double distance0 = index[0] -
static_cast< double >( basei[0] );
240 basei[1] = Math::Floor< IndexValueType >(index[1]);
241 if ( basei[1] < this->m_StartIndex[1] )
243 basei[1] = this->m_StartIndex[1];
245 const double distance1 = index[1] -
static_cast< double >( basei[1] );
247 basei[2] = Math::Floor< IndexValueType >(index[2]);
248 if ( basei[2] < this->m_StartIndex[2] )
250 basei[2] = this->m_StartIndex[2];
252 const double distance2 = index[2] -
static_cast< double >( basei[2] );
254 if ( distance0 <= 0. && distance1 <= 0. && distance2 <= 0. )
256 return ( static_cast< OutputType >( this->GetInputImage()->GetPixel(basei) ) );
259 const RealType val000 = this->GetInputImage()->GetPixel(basei);
261 if ( distance2 <= 0. )
263 if ( distance1 <= 0. )
266 if ( basei[0] > this->m_EndIndex[0] )
268 return ( static_cast< OutputType >( val000 ) );
270 const RealType val100 = this->GetInputImage()->GetPixel(basei);
272 return static_cast< OutputType >( val000 + ( val100 - val000 ) * distance0 );
274 else if ( distance0 <= 0. )
277 if ( basei[1] > this->m_EndIndex[1] )
279 return ( static_cast< OutputType >( val000 ) );
281 const RealType val010 = this->GetInputImage()->GetPixel(basei);
283 return static_cast< OutputType >( val000 + ( val010 - val000 ) * distance1 );
288 if ( basei[0] > this->m_EndIndex[0] )
292 if ( basei[1] > this->m_EndIndex[1] )
294 return ( static_cast< OutputType >( val000 ) );
296 const RealType val010 = this->GetInputImage()->GetPixel(basei);
298 return static_cast< OutputType >( val000 + ( val010 - val000 ) * distance1 );
300 const RealType val100 = this->GetInputImage()->GetPixel(basei);
302 const RealType valx00 = val000 + ( val100 - val000 ) * distance0;
305 if ( basei[1] > this->m_EndIndex[1] )
307 return ( static_cast< OutputType >( valx00 ) );
309 const RealType val110 = this->GetInputImage()->GetPixel(basei);
312 const RealType val010 = this->GetInputImage()->GetPixel(basei);
314 const RealType valx10 = val010 + ( val110 - val010 ) * distance0;
316 return static_cast< OutputType >( valx00 + ( valx10 - valx00 ) * distance1 );
321 if ( distance1 <= 0. )
323 if ( distance0 <= 0. )
326 if ( basei[2] > this->m_EndIndex[2] )
328 return ( static_cast< OutputType >( val000 ) );
330 const RealType val001 = this->GetInputImage()->GetPixel(basei);
332 return static_cast< OutputType >( val000 + ( val001 - val000 ) * distance2 );
337 if ( basei[0] > this->m_EndIndex[0] )
341 if ( basei[2] > this->m_EndIndex[2] )
343 return ( static_cast< OutputType >( val000 ) );
345 const RealType val001 = this->GetInputImage()->GetPixel(basei);
347 return static_cast< OutputType >( val000 + ( val001 - val000 ) * distance2 );
349 const RealType val100 = this->GetInputImage()->GetPixel(basei);
351 const RealType valx00 = val000 + ( val100 - val000 ) * distance0;
354 if ( basei[2] > this->m_EndIndex[2] )
356 return ( static_cast< OutputType >( valx00 ) );
358 const RealType val101 = this->GetInputImage()->GetPixel(basei);
361 const RealType val001 = this->GetInputImage()->GetPixel(basei);
363 const RealType valx01 = val001 + ( val101 - val001 ) * distance0;
365 return static_cast< OutputType >( valx00 + ( valx01 - valx00 ) * distance2 );
368 else if ( distance0 <= 0. )
371 if ( basei[1] > this->m_EndIndex[1] )
375 if ( basei[2] > this->m_EndIndex[2] )
377 return ( static_cast< OutputType >( val000 ) );
379 const RealType val001 = this->GetInputImage()->GetPixel(basei);
381 return static_cast< OutputType >( val000 + ( val001 - val000 ) * distance2 );
383 const RealType val010 = this->GetInputImage()->GetPixel(basei);
385 const RealType val0x0 = val000 + ( val010 - val000 ) * distance1;
388 if ( basei[2] > this->m_EndIndex[2] )
390 return ( static_cast< OutputType >( val0x0 ) );
392 const RealType val011 = this->GetInputImage()->GetPixel(basei);
395 const RealType val001 = this->GetInputImage()->GetPixel(basei);
397 const RealType val0x1 = val001 + ( val011 - val001 ) * distance1;
399 return static_cast< OutputType >( val0x0 + ( val0x1 - val0x0 ) * distance2 );
404 if ( basei[0] > this->m_EndIndex[0] )
408 if ( basei[1] > this->m_EndIndex[1] )
412 if ( basei[2] > this->m_EndIndex[2] )
414 return ( static_cast< OutputType >( val000 ) );
416 const RealType val001 = this->GetInputImage()->GetPixel(basei);
418 return static_cast< OutputType >( val000 + ( val001 - val000 ) * distance2 );
420 const RealType val010 = this->GetInputImage()->GetPixel(basei);
422 const RealType val0x0 = val000 + ( val010 - val000 ) * distance1;
425 if ( basei[2] > this->m_EndIndex[2] )
427 return ( static_cast< OutputType >( val0x0 ) );
429 const RealType val011 = this->GetInputImage()->GetPixel(basei);
432 const RealType val001 = this->GetInputImage()->GetPixel(basei);
434 const RealType val0x1 = val001 + ( val011 - val001 ) * distance1;
436 return static_cast< OutputType >( val0x0 + ( val0x1 - val0x0 ) * distance2 );
438 const RealType val100 = this->GetInputImage()->GetPixel(basei);
440 const RealType valx00 = val000 + ( val100 - val000 ) * distance0;
443 if ( basei[1] > this->m_EndIndex[1] )
447 if ( basei[2] > this->m_EndIndex[2] )
449 return ( static_cast< OutputType >( valx00 ) );
451 const RealType val101 = this->GetInputImage()->GetPixel(basei);
454 const RealType val001 = this->GetInputImage()->GetPixel(basei);
456 const RealType valx01 = val001 + ( val101 - val001 ) * distance0;
458 return static_cast< OutputType >( valx00 + ( valx01 - valx00 ) * distance2 );
460 const RealType val110 = this->GetInputImage()->GetPixel(basei);
463 const RealType val010 = this->GetInputImage()->GetPixel(basei);
465 const RealType valx10 = val010 + ( val110 - val010 ) * distance0;
467 const RealType valxx0 = valx00 + ( valx10 - valx00 ) * distance1;
470 if ( basei[2] > this->m_EndIndex[2] )
472 return ( static_cast< OutputType >( valxx0 ) );
474 const RealType val011 = this->GetInputImage()->GetPixel(basei);
477 const RealType val111 = this->GetInputImage()->GetPixel(basei);
480 const RealType val101 = this->GetInputImage()->GetPixel(basei);
483 const RealType val001 = this->GetInputImage()->GetPixel(basei);
485 const RealType valx01 = val001 + ( val101 - val001 ) * distance0;
486 const RealType valx11 = val011 + ( val111 - val011 ) * distance0;
487 const RealType valxx1 = valx01 + ( valx11 - valx01 ) * distance1;
489 return ( static_cast< OutputType >( valxx0 + ( valxx1 - valxx0 ) * distance2 ) );
497 return this->EvaluateUnoptimized(index);
500 virtual inline OutputType EvaluateUnoptimized(
501 const ContinuousIndexType & index)
const;
505 #ifndef ITK_MANUAL_INSTANTIATION
506 #include "itkLinearInterpolateImageFunction.hxx"