ITK  5.4.0
Insight Toolkit
itkBinaryGeneratorImageFilter.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 itkBinaryGeneratorImageFilter_h
19#define itkBinaryGeneratorImageFilter_h
20
23
24
25#include <functional>
26
27namespace itk
28{
55template <typename TInputImage1, typename TInputImage2, typename TOutputImage>
56class ITK_TEMPLATE_EXPORT BinaryGeneratorImageFilter : public InPlaceImageFilter<TInputImage1, TOutputImage>
57{
58public:
59 ITK_DISALLOW_COPY_AND_MOVE(BinaryGeneratorImageFilter);
60
66
68 itkNewMacro(Self);
69
71 itkOverrideGetNameOfClassMacro(BinaryGeneratorImageFilter);
72
74 using Input1ImageType = TInputImage1;
77 using Input1ImagePixelType = typename Input1ImageType::PixelType;
79
80 using Input2ImageType = TInputImage2;
83 using Input2ImagePixelType = typename Input2ImageType::PixelType;
85
86 using OutputImageType = TOutputImage;
89 using OutputImagePixelType = typename OutputImageType::PixelType;
90
92
95
97 virtual void
98 SetInput1(const TInputImage1 * image1);
99 virtual void
101 virtual void
106 virtual void
108
111 virtual const Input1ImagePixelType &
113
115 virtual void
116 SetInput2(const TInputImage2 * image2);
117 virtual void
119 virtual void
125 virtual void
127 void
129 {
130 this->SetConstant2(ct);
131 }
132 const Input2ImagePixelType &
134 {
135 return this->GetConstant2();
136 }
141 virtual const Input2ImagePixelType &
143
144#if !defined(ITK_WRAPPING_PARSER)
149 void
150 SetFunctor(const std::function<ConstRefFunctionType> & f)
151 {
152 // the closure creates a copy of f
153 m_DynamicThreadedGenerateDataFunction = [this, f](const OutputImageRegionType & outputRegionForThread) {
154 return this->DynamicThreadedGenerateDataWithFunctor(f, outputRegionForThread);
155 };
158 this->Modified();
159 }
160 void
161 SetFunctor(const std::function<ValueFunctionType> & f)
162 {
163 // the capture creates a copy of f
164 m_DynamicThreadedGenerateDataFunction = [this, f](const OutputImageRegionType & outputRegionForThread) {
165 return this->DynamicThreadedGenerateDataWithFunctor(f, outputRegionForThread);
166 };
167
168 this->Modified();
169 }
170
175 void
177 {
178 m_DynamicThreadedGenerateDataFunction = [this, funcPointer](const OutputImageRegionType & outputRegionForThread) {
179 return this->DynamicThreadedGenerateDataWithFunctor(funcPointer, outputRegionForThread);
180 };
183 this->Modified();
184 }
185 void
187 {
188 m_DynamicThreadedGenerateDataFunction = [this, funcPointer](const OutputImageRegionType & outputRegionForThread) {
189 return this->DynamicThreadedGenerateDataWithFunctor(funcPointer, outputRegionForThread);
190 };
191
192 this->Modified();
193 }
194
195
204 template <typename TFunctor>
205 void
206 SetFunctor(const TFunctor & functor)
207 {
208 // the capture creates a copy of the functor
209 m_DynamicThreadedGenerateDataFunction = [this, functor](const OutputImageRegionType & outputRegionForThread) {
210 return this->DynamicThreadedGenerateDataWithFunctor(functor, outputRegionForThread);
211 };
214 this->Modified();
215 }
216#endif // !defined( ITK_WRAPPING_PARSER )
217
218
220 static constexpr unsigned int InputImage1Dimension = TInputImage1::ImageDimension;
221 static constexpr unsigned int InputImage2Dimension = TInputImage2::ImageDimension;
222 static constexpr unsigned int OutputImageDimension = TOutputImage::ImageDimension;
223
224#ifdef ITK_USE_CONCEPT_CHECKING
225 // Begin concept checking
226 itkConceptMacro(SameDimensionCheck1,
228 itkConceptMacro(SameDimensionCheck2,
230 // End concept checking
231#endif
232
233protected:
235 ~BinaryGeneratorImageFilter() override = default;
236
246 template <typename TFunctor>
247 void
248 DynamicThreadedGenerateDataWithFunctor(const TFunctor &, const OutputImageRegionType & outputRegionForThread);
249 void
250 DynamicThreadedGenerateData(const OutputImageRegionType & outputRegionForThread) override;
251 void
253 {
254 this->UpdateProgress(1.0);
255 }
258 // Needed to take the image information from the 2nd input, if the first one is
259 // a simple decorated object.
260 void
262
263private:
264 std::function<void(const OutputImageRegionType &)> m_DynamicThreadedGenerateDataFunction{};
265};
266} // end namespace itk
267
268#ifndef ITK_MANUAL_INSTANTIATION
269# include "itkBinaryGeneratorImageFilter.hxx"
270#endif
271
272#endif
Implements pixel-wise generic operation of two images, or of an image and a constant.
typename Input2ImageType::PixelType Input2ImagePixelType
OutputImagePixelType(Input1ImagePixelType, Input2ImagePixelType) ValueFunctionType
virtual const Input2ImagePixelType & GetConstant2() const
virtual void SetInput1(const DecoratedInput1ImagePixelType *input1)
typename Input1ImageType::ConstPointer Input1ImagePointer
OutputImagePixelType(*)(const Input1ImagePixelType &, const Input2ImagePixelType &) FunctionType
void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) override
void SetConstant(Input2ImagePixelType ct)
void DynamicThreadedGenerateDataWithFunctor(const TFunctor &, const OutputImageRegionType &outputRegionForThread)
typename Input2ImageType::ConstPointer Input2ImagePointer
virtual void SetInput2(const DecoratedInput2ImagePixelType *input2)
virtual void SetConstant1(const Input1ImagePixelType &input1)
virtual void SetInput2(const TInputImage2 *image2)
void SetFunctor(const TFunctor &functor)
~BinaryGeneratorImageFilter() override=default
virtual void SetConstant2(const Input2ImagePixelType &input2)
virtual void SetInput1(const Input1ImagePixelType &input1)
typename Input1ImageType::RegionType Input1ImageRegionType
virtual const Input1ImagePixelType & GetConstant1() const
void SetFunctor(ValueFunctionType *funcPointer)
void SetFunctor(const std::function< ValueFunctionType > &f)
void GenerateOutputInformation() override
OutputImagePixelType(const Input1ImagePixelType &, const Input2ImagePixelType &) ConstRefFunctionType
virtual void SetInput2(const Input2ImagePixelType &input2)
typename Input1ImageType::PixelType Input1ImagePixelType
typename Input2ImageType::RegionType Input2ImageRegionType
void SetFunctor(const std::function< ConstRefFunctionType > &f)
virtual void SetInput1(const TInputImage1 *image1)
const Input2ImagePixelType & GetConstant() const
void SetFunctor(ConstRefFunctionType *funcPointer)
Base class for all process objects that output image data.
typename OutputImageType::PixelType OutputImagePixelType
typename OutputImageType::RegionType OutputImageRegionType
TOutputImage OutputImageType
typename OutputImageType::Pointer OutputImagePointer
Base class for filters that take an image as input and overwrite that image as the output.
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Decorates any "simple" data type (data types without smart pointers) with a DataObject API.
SmartPointer< const Self > ConstPointer
SmartPointer< Self > Pointer
#define itkConceptMacro(name, concept)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....