ITK  6.0.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 
21 #include "itkInPlaceImageFilter.h"
23 
24 
25 #include <functional>
26 
27 namespace itk
28 {
55 template <typename TInputImage1, typename TInputImage2, typename TOutputImage>
56 class ITK_TEMPLATE_EXPORT BinaryGeneratorImageFilter : public InPlaceImageFilter<TInputImage1, TOutputImage>
57 {
58 public:
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
100  SetInput1(const DecoratedInput1ImagePixelType * input1);
101  virtual void
102  SetInput1(const Input1ImagePixelType & input1);
106  virtual void
107  SetConstant1(const Input1ImagePixelType & input1);
108 
111  virtual const Input1ImagePixelType &
112  GetConstant1() const;
113 
115  virtual void
116  SetInput2(const TInputImage2 * image2);
117  virtual void
118  SetInput2(const DecoratedInput2ImagePixelType * input2);
119  virtual void
120  SetInput2(const Input2ImagePixelType & input2);
125  virtual void
126  SetConstant2(const Input2ImagePixelType & input2);
127  void
129  {
130  this->SetConstant2(ct);
131  }
132  const Input2ImagePixelType &
133  GetConstant() const
134  {
135  return this->GetConstant2();
136  }
141  virtual const Input2ImagePixelType &
142  GetConstant2() const;
143 
144 #if !defined(ITK_WRAPPING_PARSER)
145 
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 
233 protected:
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
261  GenerateOutputInformation() override;
262 
263 private:
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
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::SimpleDataObjectDecorator
Decorates any "simple" data type (data types without smart pointers) with a DataObject API.
Definition: itkSimpleDataObjectDecorator.h:66
ConstPointer
SmartPointer< const Self > ConstPointer
Definition: itkAddImageFilter.h:94
itk::BinaryGeneratorImageFilter< TInputImage, TLabelImage, TOutputImage >::Input1ImagePixelType
typename Input1ImageType::PixelType Input1ImagePixelType
Definition: itkBinaryGeneratorImageFilter.h:77
itk::ImageSource::OutputImagePointer
typename OutputImageType::Pointer OutputImagePointer
Definition: itkImageSource.h:91
itk::BinaryGeneratorImageFilter::GetConstant
const Input2ImagePixelType & GetConstant() const
Definition: itkBinaryGeneratorImageFilter.h:133
itk::BinaryGeneratorImageFilter::SetConstant
void SetConstant(Input2ImagePixelType ct)
Definition: itkBinaryGeneratorImageFilter.h:128
itk::BinaryGeneratorImageFilter< TInputImage, TLabelImage, TOutputImage >::Input2ImagePointer
typename Input2ImageType::ConstPointer Input2ImagePointer
Definition: itkBinaryGeneratorImageFilter.h:81
itk::InPlaceImageFilter
Base class for filters that take an image as input and overwrite that image as the output.
Definition: itkInPlaceImageFilter.h:77
itk::BinaryGeneratorImageFilter
Implements pixel-wise generic operation of two images, or of an image and a constant.
Definition: itkBinaryGeneratorImageFilter.h:56
itk::BinaryGeneratorImageFilter::SetFunctor
void SetFunctor(const std::function< ValueFunctionType > &f)
Definition: itkBinaryGeneratorImageFilter.h:161
itk::SmartPointer< Self >
itk::BinaryGeneratorImageFilter::AfterThreadedGenerateData
void AfterThreadedGenerateData() override
Definition: itkBinaryGeneratorImageFilter.h:252
itk::Concept::SameDimension
Definition: itkConceptChecking.h:697
itk::ImageSource
Base class for all process objects that output image data.
Definition: itkImageSource.h:67
itk::BinaryGeneratorImageFilter< TInputImage, TLabelImage, TOutputImage >::Input2ImageType
TLabelImage Input2ImageType
Definition: itkBinaryGeneratorImageFilter.h:80
itk::BinaryGeneratorImageFilter< TInputImage, TLabelImage, TOutputImage >::Input1ImageType
TInputImage Input1ImageType
Definition: itkBinaryGeneratorImageFilter.h:74
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::BinaryGeneratorImageFilter::SetFunctor
void SetFunctor(ConstRefFunctionType *funcPointer)
Definition: itkBinaryGeneratorImageFilter.h:176
itk::BinaryGeneratorImageFilter< TInputImage, TLabelImage, TOutputImage >::Input2ImagePixelType
typename Input2ImageType::PixelType Input2ImagePixelType
Definition: itkBinaryGeneratorImageFilter.h:83
itk::BinaryGeneratorImageFilter< TInputImage, TLabelImage, TOutputImage >::Input1ImagePointer
typename Input1ImageType::ConstPointer Input1ImagePointer
Definition: itkBinaryGeneratorImageFilter.h:75
itk::BinaryGeneratorImageFilter::SetFunctor
void SetFunctor(const TFunctor &functor)
Definition: itkBinaryGeneratorImageFilter.h:206
itk::ImageSource::OutputImageRegionType
typename OutputImageType::RegionType OutputImageRegionType
Definition: itkImageSource.h:92
itk::BinaryGeneratorImageFilter< TInputImage, TLabelImage, TOutputImage >::FunctionType
OutputImagePixelType(*)(const Input1ImagePixelType &, const Input2ImagePixelType &) FunctionType
Definition: itkBinaryGeneratorImageFilter.h:91
itkConceptMacro
#define itkConceptMacro(name, concept)
Definition: itkConceptChecking.h:65
itk::BinaryGeneratorImageFilter< TInputImage, TLabelImage, TOutputImage >::Input1ImageRegionType
typename Input1ImageType::RegionType Input1ImageRegionType
Definition: itkBinaryGeneratorImageFilter.h:76
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itkInPlaceImageFilter.h
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:139
itk::BinaryGeneratorImageFilter< TInputImage, TLabelImage, TOutputImage >::ConstRefFunctionType
OutputImagePixelType(const Input1ImagePixelType &, const Input2ImagePixelType &) ConstRefFunctionType
Definition: itkBinaryGeneratorImageFilter.h:93
itk::ImageSource::OutputImagePixelType
typename OutputImageType::PixelType OutputImagePixelType
Definition: itkImageSource.h:93
itk::BinaryGeneratorImageFilter< TInputImage, TLabelImage, TOutputImage >::ValueFunctionType
OutputImagePixelType(Input1ImagePixelType, Input2ImagePixelType) ValueFunctionType
Definition: itkBinaryGeneratorImageFilter.h:94
itkSimpleDataObjectDecorator.h
itk::BinaryGeneratorImageFilter< TInputImage, TLabelImage, TOutputImage >::Input2ImageRegionType
typename Input2ImageType::RegionType Input2ImageRegionType
Definition: itkBinaryGeneratorImageFilter.h:82
itk::BinaryGeneratorImageFilter::SetFunctor
void SetFunctor(ValueFunctionType *funcPointer)
Definition: itkBinaryGeneratorImageFilter.h:186
itk::ImageSource::OutputImageType
TOutputImage OutputImageType
Definition: itkImageSource.h:90
itk::BinaryGeneratorImageFilter::SetFunctor
void SetFunctor(const std::function< ConstRefFunctionType > &f)
Definition: itkBinaryGeneratorImageFilter.h:150