00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkAdaptImageFilter_h
00018 #define __itkAdaptImageFilter_h
00019
00020 #include "itkUnaryFunctorImageFilter.h"
00021
00022 namespace itk
00023 {
00024
00025 namespace Functor {
00026
00036 template <class TInput, class TAccessor>
00037 class AccessorFunctor
00038 {
00039 public:
00041 typedef AccessorFunctor Self;
00042 typedef TAccessor AccessorType;
00043
00045 AccessorFunctor(): m_Accessor() {}
00046 ~AccessorFunctor() {}
00048
00050 typedef typename TAccessor::ExternalType OutputType;
00051 inline OutputType operator()( const TInput & A )
00052 { return m_Accessor.Get( A ); }
00054
00056 AccessorType& GetAccessor()
00057 { return m_Accessor; }
00058
00060 AccessorFunctor & operator=( const AccessorFunctor & functor )
00061 { m_Accessor = functor.m_Accessor;
00062 return *this;}
00063
00069 void SetAccessor(AccessorType& accessor)
00070 { m_Accessor = accessor; };
00071
00073 bool operator!=( const Self& functor ) const
00074 {
00075 return (m_Accessor != functor.m_Accessor);
00076 }
00077 bool operator==( const Self& other ) const
00078 {
00079 return !(*this != other);
00080 }
00082
00083 private:
00084 AccessorType m_Accessor;
00085 };
00086 }
00087
00114 template <class TInputImage, class TOutputImage, class TAccessor>
00115 class ITK_EXPORT AdaptImageFilter:
00116 public UnaryFunctorImageFilter<TInputImage,TOutputImage,Functor::AccessorFunctor<ITK_TYPENAME TInputImage::PixelType, TAccessor> >
00117 {
00118 public:
00120 typedef AdaptImageFilter Self;
00121 typedef UnaryFunctorImageFilter< TInputImage,
00122 TOutputImage,
00123 Functor::AccessorFunctor<
00124 ITK_TYPENAME TInputImage::PixelType,
00125 TAccessor> > Superclass;
00126
00127 typedef SmartPointer<Self> Pointer;
00128 typedef SmartPointer<const Self> ConstPointer;
00129 typedef typename Superclass::FunctorType FunctorType;
00130
00132 itkNewMacro(Self);
00133
00135 typedef TAccessor AccessorType;
00136
00138 itkTypeMacro(AdaptImageFilter, UnaryFunctorImageFilter);
00139
00141 AccessorType& GetAccessor() { return this->GetFunctor().GetAccessor(); };
00142
00144 void SetAccessor(AccessorType& accessor)
00145 {
00146 FunctorType functor;
00147 functor = this->GetFunctor();
00148 if (accessor != functor.GetAccessor())
00149 {
00150 functor.SetAccessor( accessor );
00151 this->SetFunctor( functor );
00152 this->Modified();
00153 }
00154 }
00156
00157 protected:
00158 AdaptImageFilter() {}
00159 virtual ~AdaptImageFilter() {}
00160
00161 private:
00162 AdaptImageFilter(const Self&);
00163 void operator=(const Self&);
00164
00165 };
00166
00167
00168 }
00169
00170 #endif
00171