ITK  6.0.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  * https://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 {
42 template <typename TInput, typename TAccessor>
44 {
45 public:
46 
49  using AccessorType = TAccessor;
50 
52  using OutputType = typename TAccessor::ExternalType;
53  inline OutputType
54  operator()(const TInput & A) const
55  {
56  return m_Accessor.Get(A);
57  }
61  AccessorType &
63  {
64  return m_Accessor;
65  }
66 
72  void
74  {
75  m_Accessor = accessor;
76  }
77 
79  bool
80  operator==(const Self & other) const
81  {
82  return m_Accessor == other.m_Accessor;
83  }
84 
86 
87 private:
89 };
90 } // namespace Functor
91 
120 template <typename TInputImage, typename TOutputImage, typename TAccessor>
122  : public UnaryFunctorImageFilter<TInputImage,
123  TOutputImage,
124  Functor::AccessorFunctor<typename TInputImage::PixelType, TAccessor>>
125 {
126 public:
127  ITK_DISALLOW_COPY_AND_MOVE(AdaptImageFilter);
132 
133  using Superclass = UnaryFunctorImageFilter<TInputImage,
134  TOutputImage,
136 
139  using typename Superclass::FunctorType;
140 
142  itkNewMacro(Self);
143 
145  using AccessorType = TAccessor;
146 
148  itkOverrideGetNameOfClassMacro(AdaptImageFilter);
149 
151  AccessorType &
153  {
154  return this->GetFunctor().GetAccessor();
155  }
156 
158  void
160  {
161  FunctorType functor = this->GetFunctor();
162  if (accessor != functor.GetAccessor())
163  {
164  functor.SetAccessor(accessor);
165  this->SetFunctor(functor);
166  this->Modified();
167  }
168  }
171 protected:
172  AdaptImageFilter() = default;
173  ~AdaptImageFilter() override = default;
174 };
175 } // end namespace itk
176 
177 #endif
itkUnaryFunctorImageFilter.h
itk::Functor::AccessorFunctor< TInputImage::PixelType, TAccessor >::OutputType
typename TAccessor::ExternalType OutputType
Definition: itkAdaptImageFilter.h:52
itk::UnaryFunctorImageFilter
Implements pixel-wise generic operation on one image.
Definition: itkUnaryFunctorImageFilter.h:50
itk::AdaptImageFilter::AccessorType
TAccessor AccessorType
Definition: itkAdaptImageFilter.h:145
itk::AdaptImageFilter::~AdaptImageFilter
~AdaptImageFilter() override=default
itk::Functor::AccessorFunctor::operator==
bool operator==(const Self &other) const
Definition: itkAdaptImageFilter.h:80
itk::AdaptImageFilter
Convert an image to another pixel type using the specified data accessor.
Definition: itkAdaptImageFilter.h:121
itk::SmartPointer< Self >
itk::Functor::AccessorFunctor::operator()
OutputType operator()(const TInput &A) const
Definition: itkAdaptImageFilter.h:54
itk::Functor::AccessorFunctor::m_Accessor
AccessorType m_Accessor
Definition: itkAdaptImageFilter.h:88
itk::UnaryFunctorImageFilter< TInputImage, TOutputImage, Functor::AccessorFunctor< TInputImage::PixelType, TAccessor > >::SetFunctor
void SetFunctor(const FunctorType &functor)
Definition: itkUnaryFunctorImageFilter.h:103
itk::Functor::AccessorFunctor
Convert an accessor to a functor so that it can be used in a UnaryFunctorImageFilter.
Definition: itkAdaptImageFilter.h:43
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:159
itk::Functor::AccessorFunctor< TInputImage::PixelType, TAccessor >::AccessorType
TAccessor AccessorType
Definition: itkAdaptImageFilter.h:49
itk::Functor::AccessorFunctor::SetAccessor
void SetAccessor(AccessorType &accessor)
Definition: itkAdaptImageFilter.h:73
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:139
itk::AdaptImageFilter::AdaptImageFilter
AdaptImageFilter()=default
itk::UnaryFunctorImageFilter< TInputImage, TOutputImage, Functor::AccessorFunctor< TInputImage::PixelType, TAccessor > >::GetFunctor
FunctorType & GetFunctor()
Definition: itkUnaryFunctorImageFilter.h:85
AddImageFilter
Definition: itkAddImageFilter.h:81
itk::AdaptImageFilter::GetAccessor
AccessorType & GetAccessor()
Definition: itkAdaptImageFilter.h:152
itk::Object::Modified
virtual void Modified() const
itk::Functor::AccessorFunctor::GetAccessor
AccessorType & GetAccessor()
Definition: itkAdaptImageFilter.h:62