ITK  5.0.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< typename TInput, typename TAccessor >
39 {
40 public:
43  using AccessorType = TAccessor;
44 
47  ~AccessorFunctor() = default;
48 
50  using OutputType = typename TAccessor::ExternalType;
51  inline OutputType operator()(const TInput & A) const
52  {
53  return m_Accessor.Get(A);
54  }
56 
59  {
60  return m_Accessor;
61  }
62 
65  {
66  m_Accessor = functor.m_Accessor;
67  return *this;
68  }
69 
75  void SetAccessor(AccessorType & accessor)
76  {
77  m_Accessor = accessor;
78  }
79 
81  bool operator!=(const Self & functor) const
82  {
83  return ( m_Accessor != functor.m_Accessor );
84  }
85 
86  bool operator==(const Self & other) const
87  {
88  return !( *this != other );
89  }
90 
91 private:
93 };
94 }
95 
123 template< typename TInputImage, typename TOutputImage, typename TAccessor >
125  public UnaryFunctorImageFilter< TInputImage, TOutputImage,
126  Functor::AccessorFunctor< typename TInputImage::PixelType, TAccessor > >
127 {
128 public:
129  ITK_DISALLOW_COPY_AND_ASSIGN(AdaptImageFilter);
130 
133 
134  using Superclass = UnaryFunctorImageFilter< TInputImage,
135  TOutputImage,
137  typename TInputImage::PixelType,
138  TAccessor > >;
139 
143 
145  itkNewMacro(Self);
146 
148  using AccessorType = TAccessor;
149 
152 
154  AccessorType & GetAccessor() { return this->GetFunctor().GetAccessor(); }
155 
157  void SetAccessor(AccessorType & accessor)
158  {
159  FunctorType functor;
160 
161  functor = this->GetFunctor();
162  if ( accessor != functor.GetAccessor() )
163  {
164  functor.SetAccessor(accessor);
165  this->SetFunctor(functor);
166  this->Modified();
167  }
168  }
169 
170 protected:
171  AdaptImageFilter() = default;
172  ~AdaptImageFilter() override = default;
173 };
174 } // end namespace itk
175 
176 #endif
AdaptImageFilter()=default
bool operator!=(const Self &functor) const
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
AccessorFunctor & operator=(const AccessorFunctor &functor)
Base class for all process objects that output image data.
AccessorType & GetAccessor()
Convert an accessor to a functor so that it can be used in a UnaryFunctorImageFilter.
typename Superclass::FunctorType FunctorType
bool operator==(const Self &other) const
void SetAccessor(AccessorType &accessor)
virtual void Modified() const
Implements pixel-wise generic operation on one image.
void SetAccessor(AccessorType &accessor)
Convert an image to another pixel type using the specified data accessor.
OutputType operator()(const TInput &A) const
~AdaptImageFilter() override=default