ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkAdaptImageFilter.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 __itkAdaptImageFilter_h
00019 #define __itkAdaptImageFilter_h
00020 
00021 #include "itkUnaryFunctorImageFilter.h"
00022 
00023 namespace itk
00024 {
00025 namespace Functor
00026 {
00037 template< class TInput, class TAccessor >
00038 class AccessorFunctor
00039 {
00040 public:
00042   typedef AccessorFunctor Self;
00043   typedef TAccessor       AccessorType;
00044 
00046   AccessorFunctor():m_Accessor() {}
00047   ~AccessorFunctor() {}
00049 
00051   typedef typename TAccessor::ExternalType OutputType;
00052   inline OutputType operator()(const TInput & A) const
00053   {
00054     return m_Accessor.Get(A);
00055   }
00057 
00059   AccessorType & GetAccessor()
00060   {
00061     return m_Accessor;
00062   }
00063 
00065   AccessorFunctor & operator=(const AccessorFunctor & functor)
00066   {
00067     m_Accessor = functor.m_Accessor;
00068     return *this;
00069   }
00070 
00076   void SetAccessor(AccessorType & accessor)
00077   {
00078     m_Accessor = accessor;
00079   }
00080 
00082   bool operator!=(const Self & functor) const
00083   {
00084     return ( m_Accessor != functor.m_Accessor );
00085   }
00086 
00087   bool operator==(const Self & other) const
00088   {
00089     return !( *this != other );
00090   }
00091 
00092 private:
00093   AccessorType m_Accessor;
00094 };
00095 }
00096 
00124 template< class TInputImage, class TOutputImage, class TAccessor >
00125 class ITK_EXPORT AdaptImageFilter:
00126   public UnaryFunctorImageFilter< TInputImage, TOutputImage,
00127                                   Functor::AccessorFunctor< typename TInputImage::PixelType, TAccessor > >
00128 {
00129 public:
00131   typedef AdaptImageFilter Self;
00132 
00133   typedef UnaryFunctorImageFilter< TInputImage,
00134                                    TOutputImage,
00135                                    Functor::AccessorFunctor<
00136                                      typename TInputImage::PixelType,
00137                                      TAccessor > >  Superclass;
00138 
00139   typedef SmartPointer< Self >             Pointer;
00140   typedef SmartPointer< const Self >       ConstPointer;
00141   typedef typename Superclass::FunctorType FunctorType;
00142 
00144   itkNewMacro(Self);
00145 
00147   typedef TAccessor AccessorType;
00148 
00150   itkTypeMacro(AdaptImageFilter, UnaryFunctorImageFilter);
00151 
00153   AccessorType & GetAccessor() { return this->GetFunctor().GetAccessor(); }
00154 
00156   void SetAccessor(AccessorType & accessor)
00157   {
00158     FunctorType functor;
00159 
00160     functor = this->GetFunctor();
00161     if ( accessor != functor.GetAccessor() )
00162       {
00163       functor.SetAccessor(accessor);
00164       this->SetFunctor(functor);
00165       this->Modified();
00166       }
00167   }
00168 
00169 protected:
00170   AdaptImageFilter() {}
00171   virtual ~AdaptImageFilter() {}
00172 private:
00173   AdaptImageFilter(const Self &); //purposely not implemented
00174   void operator=(const Self &);   //purposely not implemented
00175 };
00176 } // end namespace itk
00177 
00178 #endif
00179