ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkNearestNeighborExtrapolateImageFunction.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkNearestNeighborExtrapolateImageFunction_h
00019 #define __itkNearestNeighborExtrapolateImageFunction_h
00020 
00021 #include "itkExtrapolateImageFunction.h"
00022 
00023 namespace itk
00024 {
00039 template< class TInputImage, class TCoordRep = float >
00040 class ITK_EXPORT NearestNeighborExtrapolateImageFunction:
00041   public ExtrapolateImageFunction< TInputImage, TCoordRep >
00042 {
00043 public:
00045   typedef NearestNeighborExtrapolateImageFunction            Self;
00046   typedef ExtrapolateImageFunction< TInputImage, TCoordRep > Superclass;
00047   typedef SmartPointer< Self >                               Pointer;
00048   typedef SmartPointer< const Self >                         ConstPointer;
00049 
00051   itkTypeMacro(NearestNeighborExtrapolateImageFunction,
00052                InterpolateImageFunction);
00053 
00055   itkNewMacro(Self);
00056 
00058   typedef typename Superclass::OutputType OutputType;
00059 
00061   typedef typename Superclass::InputImageType InputImageType;
00062 
00064   itkStaticConstMacro(ImageDimension, unsigned int, Superclass::ImageDimension);
00065 
00067   typedef typename Superclass::IndexType      IndexType;
00068   typedef typename IndexType::IndexValueType  IndexValueType;
00069 
00071   typedef typename Superclass::ContinuousIndexType ContinuousIndexType;
00072 
00080   virtual OutputType EvaluateAtContinuousIndex(
00081     const ContinuousIndexType & index) const
00082   {
00083     IndexType nindex;
00084 
00085     for ( unsigned int j = 0; j < ImageDimension; j++ )
00086       {
00087       nindex[j] = Math::RoundHalfIntegerUp< IndexValueType >(index[j]);
00088       if ( nindex[j] < this->GetStartIndex()[j] )
00089         {
00090         nindex[j] = this->GetStartIndex()[j];
00091         }
00092       else if ( nindex[j] > this->GetEndIndex()[j] )
00093         {
00094         nindex[j] = this->GetEndIndex()[j];
00095         }
00096       }
00097     return static_cast< OutputType >( this->GetInputImage()->GetPixel(nindex) );
00098   }
00099 
00107   virtual OutputType EvaluateAtIndex(
00108     const IndexType & index) const
00109   {
00110     IndexType nindex;
00111 
00112     for ( unsigned int j = 0; j < ImageDimension; j++ )
00113       {
00114       if ( index[j] < this->GetStartIndex()[j] )
00115         {
00116         nindex[j] = this->GetStartIndex()[j];
00117         }
00118       else if ( index[j] > this->GetEndIndex()[j] )
00119         {
00120         nindex[j] = this->GetEndIndex()[j];
00121         }
00122       else
00123         {
00124         nindex[j] = index[j];
00125         }
00126       }
00127     return static_cast< OutputType >( this->GetInputImage()->GetPixel(nindex) );
00128   }
00129 
00130 protected:
00131   NearestNeighborExtrapolateImageFunction(){}
00132   ~NearestNeighborExtrapolateImageFunction(){}
00133   void PrintSelf(std::ostream & os, Indent indent) const
00134   { Superclass::PrintSelf(os, indent); }
00135 private:
00136   NearestNeighborExtrapolateImageFunction(const Self &); //purposely not
00137                                                          // implemented
00138   void operator=(const Self &);                          //purposely not
00139 
00140   // implemented
00141 };
00142 } // end namespace itk
00143 
00144 #endif
00145