ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkBinaryGeneratorImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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,
56  typename TOutputImage >
57 class ITK_TEMPLATE_EXPORT BinaryGeneratorImageFilter:
58  public InPlaceImageFilter< TInputImage1, TOutputImage >
59 {
60 public:
61  ITK_DISALLOW_COPY_AND_ASSIGN(BinaryGeneratorImageFilter);
62 
68 
70  itkNewMacro(Self);
71 
74 
76  using Input1ImageType = TInputImage1;
77  using Input1ImagePointer = typename Input1ImageType::ConstPointer;
79  using Input1ImagePixelType = typename Input1ImageType::PixelType;
81 
82  using Input2ImageType = TInputImage2;
83  using Input2ImagePointer = typename Input2ImageType::ConstPointer;
85  using Input2ImagePixelType = typename Input2ImageType::PixelType;
87 
88  using OutputImageType = TOutputImage;
89  using OutputImagePointer = typename OutputImageType::Pointer;
91  using OutputImagePixelType = typename OutputImageType::PixelType;
92 
95 
100 
102  virtual void SetInput1(const TInputImage1 *image1);
103  virtual void SetInput1(const DecoratedInput1ImagePixelType *input1);
104  virtual void SetInput1(const Input1ImagePixelType &input1);
106 
108  virtual void SetConstant1(const Input1ImagePixelType &input1);
109 
112  virtual const Input1ImagePixelType & GetConstant1() const;
113 
115  virtual void SetInput2(const TInputImage2 *image2);
116  virtual void SetInput2(const DecoratedInput2ImagePixelType *input2);
117  virtual void SetInput2(const Input2ImagePixelType &input2);
119 
120 
122  virtual void SetConstant2(const Input2ImagePixelType &input2);
124  {
125  this->SetConstant2(ct);
126  }
128  {
129  return this->GetConstant2();
130  }
132 
135  virtual const Input2ImagePixelType & GetConstant2() const;
136 
137 #if !defined( ITK_WRAPPING_PARSER )
138 
142  void SetFunctor( const std::function<ConstRefFunctionType> &f)
143  {
144  // the closure create a copy of f
145  m_DynamicThreadedGenerateDataFunction = [this, f](const OutputImageRegionType & outputRegionForThread)
146  { return this->DynamicThreadedGenerateDataWithFunctor(f, outputRegionForThread); };
147 
148  this->Modified();
149  }
150  void SetFunctor( const std::function<ValueFunctionType> &f)
151  {
152  // the capture create a copy of f
153  m_DynamicThreadedGenerateDataFunction = [this, f](const OutputImageRegionType & outputRegionForThread)
154  { return this->DynamicThreadedGenerateDataWithFunctor(f, outputRegionForThread); };
155 
156  this->Modified();
157  }
158 
163  void SetFunctor( ConstRefFunctionType *funcPointer)
164  {
165  m_DynamicThreadedGenerateDataFunction = [this, funcPointer](const OutputImageRegionType & outputRegionForThread)
166  { return this->DynamicThreadedGenerateDataWithFunctor(funcPointer, outputRegionForThread); };
167 
168  this->Modified();
169  }
170 
171 
172  void SetFunctor( ValueFunctionType *funcPointer)
173  {
174  m_DynamicThreadedGenerateDataFunction = [this, funcPointer](const OutputImageRegionType & outputRegionForThread)
175  { return this->DynamicThreadedGenerateDataWithFunctor(funcPointer, outputRegionForThread); };
176 
177  this->Modified();
178  }
179 
180 
189  template <typename TFunctor>
190  void SetFunctor( const TFunctor &functor)
191  {
192  // the capture creates a copy of the functor
193  m_DynamicThreadedGenerateDataFunction = [this, functor](const OutputImageRegionType & outputRegionForThread)
194  { return this->DynamicThreadedGenerateDataWithFunctor(functor, outputRegionForThread); };
195 
196  this->Modified();
197  }
198 #endif // !defined( ITK_WRAPPING_PARSER )
199 
200 
202  itkStaticConstMacro(
203  InputImage1Dimension, unsigned int, TInputImage1::ImageDimension);
204  itkStaticConstMacro(
205  InputImage2Dimension, unsigned int, TInputImage2::ImageDimension);
206  itkStaticConstMacro(
207  OutputImageDimension, unsigned int, TOutputImage::ImageDimension);
209 
210 #ifdef ITK_USE_CONCEPT_CHECKING
211  // Begin concept checking
212  itkConceptMacro( SameDimensionCheck1,
213  ( Concept::SameDimension< itkGetStaticConstMacro(InputImage1Dimension),
214  itkGetStaticConstMacro(InputImage2Dimension) > ) );
215  itkConceptMacro( SameDimensionCheck2,
216  ( Concept::SameDimension< itkGetStaticConstMacro(InputImage1Dimension),
217  itkGetStaticConstMacro(OutputImageDimension) > ) );
218  // End concept checking
219 #endif
220 
221 protected:
223  ~BinaryGeneratorImageFilter() override = default;
224 
234  template <typename TFunctor>
235  void DynamicThreadedGenerateDataWithFunctor(const TFunctor &, const OutputImageRegionType & outputRegionForThread);
236  void DynamicThreadedGenerateData(const OutputImageRegionType & outputRegionForThread) override;
238 
239  // Needed to take the image information from the 2nd input, if the first one is
240  // a simple decorated object.
241  void GenerateOutputInformation() override;
242 
243 private:
244  std::function<void(const OutputImageRegionType &)> m_DynamicThreadedGenerateDataFunction;
245 };
246 } // end namespace itk
247 
248 #ifndef ITK_MANUAL_INSTANTIATION
249 #include "itkBinaryGeneratorImageFilter.hxx"
250 #endif
251 
252 #endif
typename OutputImageType::Pointer OutputImagePointer
OutputImagePixelType(const Input1ImagePixelType &, const Input2ImagePixelType &) ConstRefFunctionType
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
void SetFunctor(ValueFunctionType *funcPointer)
void SetFunctor(ConstRefFunctionType *funcPointer)
std::function< void(const OutputImageRegionType &)> m_DynamicThreadedGenerateDataFunction
Base class for all process objects that output image data.
OutputImagePixelType(Input1ImagePixelType, Input2ImagePixelType) ValueFunctionType
typename OutputImageType::PixelType OutputImagePixelType
Decorates any &quot;simple&quot; data type (data types without smart pointers) with a DataObject API...
typename OutputImageType::RegionType OutputImageRegionType
Implements pixel-wise generic operation of two images, or of an image and a constant.
TOutputImage OutputImageType
void SetConstant(Input2ImagePixelType ct)
void SetFunctor(const std::function< ConstRefFunctionType > &f)
const Input2ImagePixelType & GetConstant() const
void SetFunctor(const TFunctor &functor)
OutputImagePixelType(*)(const Input1ImagePixelType &, const Input2ImagePixelType &) FunctionType
Base class for filters that take an image as input and overwrite that image as the output...
#define itkConceptMacro(name, concept)
void SetFunctor(const std::function< ValueFunctionType > &f)