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() {}
00047
00049 typedef typename TAccessor::ExternalType OutputType;
00050 inline OutputType operator()( const TInput & A )
00051 { return m_Accessor.Get( A ); }
00052
00054 AccessorType& GetAccessor()
00055 { return m_Accessor; }
00056
00058 AccessorFunctor & operator=( const AccessorFunctor & functor )
00059 { m_Accessor = functor.m_Accessor;
00060 return *this;}
00061
00067 void SetAccessor(AccessorType& accessor)
00068 { m_Accessor = accessor; };
00069
00071 bool operator!=( const Self& functor ) const
00072 { return (m_Accessor != functor.m_Accessor); }
00073
00074 private:
00075 AccessorType m_Accessor;
00076 };
00077 }
00078
00105 template <class TInputImage, class TOutputImage, class TAccessor>
00106 class ITK_EXPORT AdaptImageFilter:
00107 public UnaryFunctorImageFilter<TInputImage,TOutputImage,Functor::AccessorFunctor<ITK_TYPENAME TInputImage::PixelType, TAccessor> >
00108 {
00109 public:
00111 typedef AdaptImageFilter Self;
00112 typedef UnaryFunctorImageFilter< TInputImage,
00113 TOutputImage,
00114 Functor::AccessorFunctor<
00115 ITK_TYPENAME TInputImage::PixelType,
00116 TAccessor> > Superclass;
00117
00118 typedef SmartPointer<Self> Pointer;
00119 typedef SmartPointer<const Self> ConstPointer;
00120 typedef typename Superclass::FunctorType FunctorType;
00121
00123 itkNewMacro(Self);
00124
00126 typedef TAccessor AccessorType;
00127
00129 itkTypeMacro(AdaptImageFilter, UnaryFunctorImageFilter);
00130
00132 AccessorType& GetAccessor() { return this->GetFunctor().GetAccessor(); };
00133
00135 void SetAccessor(AccessorType& accessor)
00136 {
00137 FunctorType functor;
00138 functor = this->GetFunctor();
00139 if (accessor != functor.GetAccessor())
00140 {
00141 functor.SetAccessor( accessor );
00142 this->SetFunctor( functor );
00143 this->Modified();
00144 }
00145 }
00146
00147 protected:
00148 AdaptImageFilter() {}
00149 virtual ~AdaptImageFilter() {}
00150
00151 private:
00152 AdaptImageFilter(const Self&);
00153 void operator=(const Self&);
00154
00155 };
00156
00157
00158 }
00159
00160 #endif