ITK  5.4.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
23namespace itk
24{
25namespace Functor
26{
38template <typename TInput, typename TAccessor>
40{
41public:
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 }
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
97private:
99};
100} // namespace Functor
101
130template <typename TInputImage, typename TOutputImage, typename TAccessor>
132 : public UnaryFunctorImageFilter<TInputImage,
133 TOutputImage,
134 Functor::AccessorFunctor<typename TInputImage::PixelType, TAccessor>>
135{
136public:
137 ITK_DISALLOW_COPY_AND_MOVE(AdaptImageFilter);
142
144 TOutputImage,
146
149 using typename Superclass::FunctorType;
150
152 itkNewMacro(Self);
153
155 using AccessorType = TAccessor;
156
158 itkOverrideGetNameOfClassMacro(AdaptImageFilter);
159
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
182protected:
183 AdaptImageFilter() = default;
184 ~AdaptImageFilter() override = default;
185};
186} // end namespace itk
187
188#endif
Convert an image to another pixel type using the specified data accessor.
AccessorType & GetAccessor()
~AdaptImageFilter() override=default
AdaptImageFilter()=default
void SetAccessor(AccessorType &accessor)
Convert an accessor to a functor so that it can be used in a UnaryFunctorImageFilter.
OutputType operator()(const TInput &A) const
bool operator==(const Self &other) const
typename TAccessor::ExternalType OutputType
void SetAccessor(AccessorType &accessor)
AccessorFunctor & operator=(const AccessorFunctor &functor)
Base class for all process objects that output image data.
virtual void Modified() const
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Implements pixel-wise generic operation on one image.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....