ITK  5.1.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  * 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 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_ASSIGN(BinaryGeneratorImageFilter);
60 
66 
68  itkNewMacro(Self);
69 
72 
74  using Input1ImageType = TInputImage1;
75  using Input1ImagePointer = typename Input1ImageType::ConstPointer;
77  using Input1ImagePixelType = typename Input1ImageType::PixelType;
79 
80  using Input2ImageType = TInputImage2;
81  using Input2ImagePointer = typename Input2ImageType::ConstPointer;
83  using Input2ImagePixelType = typename Input2ImageType::PixelType;
85 
86  using OutputImageType = TOutputImage;
87  using OutputImagePointer = typename OutputImageType::Pointer;
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);
104 
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);
122 
123 
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  }
138 
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 create a copy of f
153  m_DynamicThreadedGenerateDataFunction = [this, f](const OutputImageRegionType & outputRegionForThread) {
154  return this->DynamicThreadedGenerateDataWithFunctor(f, outputRegionForThread);
155  };
157 
158  this->Modified();
159  }
160  void
161  SetFunctor(const std::function<ValueFunctionType> & f)
162  {
163  // the capture create 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  };
182 
183  this->Modified();
184  }
185 
186 
187  void
189  {
190  m_DynamicThreadedGenerateDataFunction = [this, funcPointer](const OutputImageRegionType & outputRegionForThread) {
191  return this->DynamicThreadedGenerateDataWithFunctor(funcPointer, outputRegionForThread);
192  };
193 
194  this->Modified();
195  }
196 
197 
206  template <typename TFunctor>
207  void
208  SetFunctor(const TFunctor & functor)
209  {
210  // the capture creates a copy of the functor
211  m_DynamicThreadedGenerateDataFunction = [this, functor](const OutputImageRegionType & outputRegionForThread) {
212  return this->DynamicThreadedGenerateDataWithFunctor(functor, outputRegionForThread);
213  };
215 
216  this->Modified();
217  }
218 #endif // !defined( ITK_WRAPPING_PARSER )
219 
220 
222  itkStaticConstMacro(InputImage1Dimension, unsigned int, TInputImage1::ImageDimension);
223  itkStaticConstMacro(InputImage2Dimension, unsigned int, TInputImage2::ImageDimension);
224  itkStaticConstMacro(OutputImageDimension, unsigned int, TOutputImage::ImageDimension);
226 
227 #ifdef ITK_USE_CONCEPT_CHECKING
228  // Begin concept checking
229  itkConceptMacro(SameDimensionCheck1,
230  (Concept::SameDimension<itkGetStaticConstMacro(InputImage1Dimension),
231  itkGetStaticConstMacro(InputImage2Dimension)>));
232  itkConceptMacro(SameDimensionCheck2,
233  (Concept::SameDimension<itkGetStaticConstMacro(InputImage1Dimension),
234  itkGetStaticConstMacro(OutputImageDimension)>));
235  // End concept checking
236 #endif
237 
238 protected:
240  ~BinaryGeneratorImageFilter() override = default;
241 
251  template <typename TFunctor>
252  void
253  DynamicThreadedGenerateDataWithFunctor(const TFunctor &, const OutputImageRegionType & outputRegionForThread);
254  void
255  DynamicThreadedGenerateData(const OutputImageRegionType & outputRegionForThread) override;
257 
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:
265 };
266 } // end namespace itk
267 
268 #ifndef ITK_MANUAL_INSTANTIATION
269 # include "itkBinaryGeneratorImageFilter.hxx"
270 #endif
271 
272 #endif
itk::SimpleDataObjectDecorator
Decorates any "simple" data type (data types without smart pointers) with a DataObject API.
Definition: itkSimpleDataObjectDecorator.h:66
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::Concept::SameDimension
Definition: itkConceptChecking.h:692
itk::ImageSource
Base class for all process objects that output image data.
Definition: itkImageSource.h:67
itk::BinaryGeneratorImageFilter::m_DynamicThreadedGenerateDataFunction
std::function< void(const OutputImageRegionType &)> m_DynamicThreadedGenerateDataFunction
Definition: itkBinaryGeneratorImageFilter.h:264
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:208
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:64
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: itkArray.h:26
itkInPlaceImageFilter.h
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:138
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:188
itk::ImageSource::OutputImageType
TOutputImage OutputImageType
Definition: itkImageSource.h:90
itk::BinaryGeneratorImageFilter::SetFunctor
void SetFunctor(const std::function< ConstRefFunctionType > &f)
Definition: itkBinaryGeneratorImageFilter.h:150