00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkNearestNeighborExtrapolateImageFunction_h
00018 #define __itkNearestNeighborExtrapolateImageFunction_h
00019
00020 #include "itkExtrapolateImageFunction.h"
00021
00022 namespace itk
00023 {
00024
00038 template <class TInputImage, class TCoordRep = float>
00039 class ITK_EXPORT NearestNeighborExtrapolateImageFunction :
00040 public ExtrapolateImageFunction<TInputImage,TCoordRep>
00041 {
00042 public:
00044 typedef NearestNeighborExtrapolateImageFunction Self;
00045 typedef ExtrapolateImageFunction<TInputImage,TCoordRep> Superclass;
00046 typedef SmartPointer<Self> Pointer;
00047 typedef SmartPointer<const Self> ConstPointer;
00048
00050 itkTypeMacro(NearestNeighborExtrapolateImageFunction,
00051 InterpolateImageFunction);
00052
00054 itkNewMacro(Self);
00055
00057 typedef typename Superclass::OutputType OutputType;
00058
00060 typedef typename Superclass::InputImageType InputImageType;
00061
00063 itkStaticConstMacro(ImageDimension, unsigned int,Superclass::ImageDimension);
00064
00066 typedef typename Superclass::IndexType IndexType;
00067
00069 typedef typename Superclass::ContinuousIndexType ContinuousIndexType;
00070
00078 virtual OutputType EvaluateAtContinuousIndex(
00079 const ContinuousIndexType & index ) const
00080 {
00081 typedef typename IndexType::IndexValueType ValueType;
00082 IndexType nindex;
00083 for ( unsigned int j = 0; j < ImageDimension; j++ )
00084 {
00085 if ( index[j] < this->GetStartContinuousIndex()[j] )
00086 {
00087 nindex[j] = this->GetStartIndex()[j];
00088 }
00089 else if ( index[j] > this->GetEndContinuousIndex()[j] )
00090 {
00091 nindex[j] = this->GetEndIndex()[j];
00092 }
00093 else
00094 {
00095 nindex[j] = static_cast<ValueType>( vnl_math_rnd( index[j] ) );
00096 }
00097 }
00098 return static_cast<OutputType>( this->GetInputImage()->GetPixel( nindex ) );
00099 }
00101
00102
00110 virtual OutputType EvaluateAtIndex(
00111 const IndexType & index ) const
00112 {
00113 IndexType nindex;
00114 for ( unsigned int j = 0; j < ImageDimension; j++ )
00115 {
00116 if ( index[j] < this->GetStartIndex()[j] )
00117 {
00118 nindex[j] = this->GetStartIndex()[j];
00119 }
00120 else if ( index[j] > this->GetEndIndex()[j] )
00121 {
00122 nindex[j] = this->GetEndIndex()[j];
00123 }
00124 else
00125 {
00126 nindex[j] = index[j];
00127 }
00128 }
00129 return static_cast<OutputType>( this->GetInputImage()->GetPixel( nindex ) );
00130 }
00132
00133
00134 protected:
00135 NearestNeighborExtrapolateImageFunction(){};
00136 ~NearestNeighborExtrapolateImageFunction(){};
00137 void PrintSelf(std::ostream& os, Indent indent) const
00138 { Superclass::PrintSelf( os, indent ); }
00139
00140 private:
00141 NearestNeighborExtrapolateImageFunction(const Self&);
00142 void operator=(const Self&);
00143
00144 };
00145
00146 }
00147
00148 #endif
00149