ITK  4.2.0
Insight Segmentation and Registration Toolkit
itkAdaptImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkAdaptImageFilter_h
19 #define __itkAdaptImageFilter_h
20 
22 
23 namespace itk
24 {
25 namespace Functor
26 {
37 template< class TInput, class TAccessor >
39 {
40 public:
43  typedef TAccessor AccessorType;
44 
49 
51  typedef typename TAccessor::ExternalType OutputType;
52  inline OutputType operator()(const TInput & A) const
53  {
54  return m_Accessor.Get(A);
55  }
57 
60  {
61  return m_Accessor;
62  }
63 
66  {
67  m_Accessor = functor.m_Accessor;
68  return *this;
69  }
70 
76  void SetAccessor(AccessorType & accessor)
77  {
78  m_Accessor = accessor;
79  }
80 
82  bool operator!=(const Self & functor) const
83  {
84  return ( m_Accessor != functor.m_Accessor );
85  }
86 
87  bool operator==(const Self & other) const
88  {
89  return !( *this != other );
90  }
91 
92 private:
94 };
95 }
96 
124 template< class TInputImage, class TOutputImage, class TAccessor >
125 class ITK_EXPORT AdaptImageFilter:
126  public UnaryFunctorImageFilter< TInputImage, TOutputImage,
127  Functor::AccessorFunctor< typename TInputImage::PixelType, TAccessor > >
128 {
129 public:
132 
133  typedef UnaryFunctorImageFilter< TInputImage,
134  TOutputImage,
136  typename TInputImage::PixelType,
137  TAccessor > > Superclass;
138 
141  typedef typename Superclass::FunctorType FunctorType;
142 
144  itkNewMacro(Self);
145 
147  typedef TAccessor AccessorType;
148 
151 
153  AccessorType & GetAccessor() { return this->GetFunctor().GetAccessor(); }
154 
156  void SetAccessor(AccessorType & accessor)
157  {
158  FunctorType functor;
159 
160  functor = this->GetFunctor();
161  if ( accessor != functor.GetAccessor() )
162  {
163  functor.SetAccessor(accessor);
164  this->SetFunctor(functor);
165  this->Modified();
166  }
167  }
168 
169 protected:
171  virtual ~AdaptImageFilter() {}
172 private:
173  AdaptImageFilter(const Self &); //purposely not implemented
174  void operator=(const Self &); //purposely not implemented
175 };
176 } // end namespace itk
177 
178 #endif
179