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 }
00100
00101
00109 virtual OutputType EvaluateAtIndex(
00110 const IndexType & index ) const
00111 {
00112 IndexType nindex;
00113 for ( unsigned int j = 0; j < ImageDimension; j++ )
00114 {
00115 if ( index[j] < this->GetStartIndex()[j] )
00116 {
00117 nindex[j] = this->GetStartIndex()[j];
00118 }
00119 else if ( index[j] > this->GetEndIndex()[j] )
00120 {
00121 nindex[j] = this->GetEndIndex()[j];
00122 }
00123 else
00124 {
00125 nindex[j] = index[j];
00126 }
00127 }
00128 return static_cast<OutputType>( this->GetInputImage()->GetPixel( nindex ) );
00129 }
00130
00131
00132 protected:
00133 NearestNeighborExtrapolateImageFunction(){};
00134 ~NearestNeighborExtrapolateImageFunction(){};
00135 void PrintSelf(std::ostream& os, Indent indent) const
00136 { Superclass::PrintSelf( os, indent ); }
00137
00138 private:
00139 NearestNeighborExtrapolateImageFunction(const Self&);
00140 void operator=(const Self&);
00141
00142 };
00143
00144 }
00145
00146 #endif