ITK  5.2.0
Insight Toolkit
itkAdaptImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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 {
38 template <typename TInput, typename TAccessor>
40 {
41 public:
42 
45  using AccessorType = TAccessor;
46 
49  : m_Accessor()
50  {}
51  ~AccessorFunctor() = default;
52 
54  using OutputType = typename TAccessor::ExternalType;
55  inline OutputType
56  operator()(const TInput & A) const
57  {
58  return m_Accessor.Get(A);
59  }
61 
63  AccessorType &
65  {
66  return m_Accessor;
67  }
68 
71  operator=(const AccessorFunctor & functor)
72  {
73  m_Accessor = functor.m_Accessor;
74  return *this;
75  }
76 
82  void
84  {
85  m_Accessor = accessor;
86  }
87 
89  bool
90  operator!=(const Self & functor) const
91  {
92  return (m_Accessor != functor.m_Accessor);
93  }
94 
95  bool
96  operator==(const Self & other) const
97  {
98  return !(*this != other);
99  }
100 
101 private:
103 };
104 } // namespace Functor
105 
134 template <typename TInputImage, typename TOutputImage, typename TAccessor>
136  : public UnaryFunctorImageFilter<TInputImage,
137  TOutputImage,
138  Functor::AccessorFunctor<typename TInputImage::PixelType, TAccessor>>
139 {
140 public:
141  ITK_DISALLOW_COPY_AND_MOVE(AdaptImageFilter);
143 
146 
147  using Superclass = UnaryFunctorImageFilter<TInputImage,
148  TOutputImage,
150 
154 
156  itkNewMacro(Self);
157 
159  using AccessorType = TAccessor;
160 
163 
165  AccessorType &
167  {
168  return this->GetFunctor().GetAccessor();
169  }
170 
172  void
174  {
175  FunctorType functor;
176 
177  functor = this->GetFunctor();
178  if (accessor != functor.GetAccessor())
179  {
180  functor.SetAccessor(accessor);
181  this->SetFunctor(functor);
182  this->Modified();
183  }
184  }
185 
186 protected:
187  AdaptImageFilter() = default;
188  ~AdaptImageFilter() override = default;
189 };
190 } // end namespace itk
191 
192 #endif
itkUnaryFunctorImageFilter.h
itk::Functor::AccessorFunctor< TInputImage::PixelType, TAccessor >::OutputType
typename TAccessor::ExternalType OutputType
Definition: itkAdaptImageFilter.h:54
itk::UnaryFunctorImageFilter
Implements pixel-wise generic operation on one image.
Definition: itkUnaryFunctorImageFilter.h:50
itk::Functor::AccessorFunctor::operator=
AccessorFunctor & operator=(const AccessorFunctor &functor)
Definition: itkAdaptImageFilter.h:71
itk::AdaptImageFilter::AccessorType
TAccessor AccessorType
Definition: itkAdaptImageFilter.h:159
itk::AdaptImageFilter::~AdaptImageFilter
~AdaptImageFilter() override=default
itk::Functor::AccessorFunctor::operator==
bool operator==(const Self &other) const
Definition: itkAdaptImageFilter.h:96
itk::AdaptImageFilter::FunctorType
typename Superclass::FunctorType FunctorType
Definition: itkAdaptImageFilter.h:153
itk::AdaptImageFilter
Convert an image to another pixel type using the specified data accessor.
Definition: itkAdaptImageFilter.h:135
itk::Functor::AccessorFunctor::AccessorFunctor
AccessorFunctor()
Definition: itkAdaptImageFilter.h:48
itk::SmartPointer< Self >
itk::Functor::AccessorFunctor::operator()
OutputType operator()(const TInput &A) const
Definition: itkAdaptImageFilter.h:56
itk::Functor::AccessorFunctor::m_Accessor
AccessorType m_Accessor
Definition: itkAdaptImageFilter.h:102
itk::UnaryFunctorImageFilter< TInputImage, TOutputImage, Functor::AccessorFunctor< TInputImage::PixelType, TAccessor > >::SetFunctor
void SetFunctor(const FunctorType &functor)
Definition: itkUnaryFunctorImageFilter.h:103
itk::Functor::AccessorFunctor::~AccessorFunctor
~AccessorFunctor()=default
itk::Functor::AccessorFunctor
Convert an accessor to a functor so that it can be used in a UnaryFunctorImageFilter.
Definition: itkAdaptImageFilter.h:39
itk::ImageSource
Base class for all process objects that output image data.
Definition: itkImageSource.h:67
itk::UnaryFunctorImageFilter::FunctorType
TFunction FunctorType
Definition: itkUnaryFunctorImageFilter.h:68
itk::AdaptImageFilter::SetAccessor
void SetAccessor(AccessorType &accessor)
Definition: itkAdaptImageFilter.h:173
itk::Functor::AccessorFunctor< TInputImage::PixelType, TAccessor >::AccessorType
TAccessor AccessorType
Definition: itkAdaptImageFilter.h:45
itk::Functor::AccessorFunctor::SetAccessor
void SetAccessor(AccessorType &accessor)
Definition: itkAdaptImageFilter.h:83
itk::Functor::AccessorFunctor::operator!=
bool operator!=(const Self &functor) const
Definition: itkAdaptImageFilter.h:90
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:138
itk::AdaptImageFilter::AdaptImageFilter
AdaptImageFilter()=default
itk::UnaryFunctorImageFilter< TInputImage, TOutputImage, Functor::AccessorFunctor< TInputImage::PixelType, TAccessor > >::GetFunctor
FunctorType & GetFunctor()
Definition: itkUnaryFunctorImageFilter.h:85
itk::AdaptImageFilter::GetAccessor
AccessorType & GetAccessor()
Definition: itkAdaptImageFilter.h:166
itk::Object::Modified
virtual void Modified() const
itk::Functor::AccessorFunctor::GetAccessor
AccessorType & GetAccessor()
Definition: itkAdaptImageFilter.h:64