ITK  5.3.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 & other) const
91  {
92  return m_Accessor == other.m_Accessor;
93  }
94 
96 
97 private:
99 };
100 } // namespace Functor
101 
130 template <typename TInputImage, typename TOutputImage, typename TAccessor>
132  : public UnaryFunctorImageFilter<TInputImage,
133  TOutputImage,
134  Functor::AccessorFunctor<typename TInputImage::PixelType, TAccessor>>
135 {
136 public:
137  ITK_DISALLOW_COPY_AND_MOVE(AdaptImageFilter);
139 
142 
143  using Superclass = UnaryFunctorImageFilter<TInputImage,
144  TOutputImage,
146 
149  using typename Superclass::FunctorType;
150 
152  itkNewMacro(Self);
153 
155  using AccessorType = TAccessor;
156 
159 
161  AccessorType &
163  {
164  return this->GetFunctor().GetAccessor();
165  }
166 
168  void
170  {
171  FunctorType functor;
172 
173  functor = this->GetFunctor();
174  if (accessor != functor.GetAccessor())
175  {
176  functor.SetAccessor(accessor);
177  this->SetFunctor(functor);
178  this->Modified();
179  }
180  }
181 
182 protected:
183  AdaptImageFilter() = default;
184  ~AdaptImageFilter() override = default;
185 };
186 } // end namespace itk
187 
188 #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:155
itk::AdaptImageFilter::~AdaptImageFilter
~AdaptImageFilter() override=default
itk::Functor::AccessorFunctor::operator==
bool operator==(const Self &other) const
Definition: itkAdaptImageFilter.h:90
itk::AdaptImageFilter
Convert an image to another pixel type using the specified data accessor.
Definition: itkAdaptImageFilter.h:131
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:98
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::Self
AccessorFunctor Self
Definition: itkAdaptImageFilter.h:44
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::Functor::AccessorFunctor::ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self)
itk::UnaryFunctorImageFilter::FunctorType
TFunction FunctorType
Definition: itkUnaryFunctorImageFilter.h:68
itk::AdaptImageFilter::SetAccessor
void SetAccessor(AccessorType &accessor)
Definition: itkAdaptImageFilter.h:169
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
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:162
itk::Object::Modified
virtual void Modified() const
itk::Functor::AccessorFunctor::GetAccessor
AccessorType & GetAccessor()
Definition: itkAdaptImageFilter.h:64