ITK  5.4.0
Insight Toolkit
itkUnaryGeneratorImageFilter.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 itkUnaryGeneratorImageFilter_h
19 #define itkUnaryGeneratorImageFilter_h
20 
21 #include "itkMath.h"
22 #include "itkInPlaceImageFilter.h"
24 
25 #include <functional>
26 
27 namespace itk
28 {
29 
54 template <typename TInputImage, typename TOutputImage>
55 class ITK_TEMPLATE_EXPORT UnaryGeneratorImageFilter : public InPlaceImageFilter<TInputImage, TOutputImage>
56 {
57 public:
58  ITK_DISALLOW_COPY_AND_MOVE(UnaryGeneratorImageFilter);
59 
65 
67  itkNewMacro(Self);
68 
70  itkOverrideGetNameOfClassMacro(UnaryGeneratorImageFilter);
71 
72  using InputImageType = TInputImage;
75  using InputImagePixelType = typename InputImageType::PixelType;
76 
77  using OutputImageType = TOutputImage;
80  using OutputImagePixelType = typename OutputImageType::PixelType;
81 
84 
85 
86 #if !defined(ITK_WRAPPING_PARSER)
87 
91  void
92  SetFunctor(const std::function<ConstRefFunctionType> & f)
93  {
94  m_DynamicThreadedGenerateDataFunction = [this, f](const OutputImageRegionType & outputRegionForThread) {
95  return this->DynamicThreadedGenerateDataWithFunctor(f, outputRegionForThread);
96  };
99  this->Modified();
100  }
101  void
102  SetFunctor(const std::function<ValueFunctionType> & f)
103  {
104  m_DynamicThreadedGenerateDataFunction = [this, f](const OutputImageRegionType & outputRegionForThread) {
105  return this->DynamicThreadedGenerateDataWithFunctor(f, outputRegionForThread);
106  };
107 
108  this->Modified();
109  }
110 
111 
116  void
118  {
119  m_DynamicThreadedGenerateDataFunction = [this, funcPointer](const OutputImageRegionType & outputRegionForThread) {
120  return this->DynamicThreadedGenerateDataWithFunctor(funcPointer, outputRegionForThread);
121  };
124  this->Modified();
125  }
126  void
128  {
129  m_DynamicThreadedGenerateDataFunction = [this, funcPointer](const OutputImageRegionType & outputRegionForThread) {
130  return this->DynamicThreadedGenerateDataWithFunctor(funcPointer, outputRegionForThread);
131  };
132 
133  this->Modified();
134  }
135 
136 
144  template <typename TFunctor>
145  void
146  SetFunctor(const TFunctor & functor)
147  {
148  m_DynamicThreadedGenerateDataFunction = [this, functor](const OutputImageRegionType & outputRegionForThread) {
149  return this->DynamicThreadedGenerateDataWithFunctor(functor, outputRegionForThread);
150  };
153  this->Modified();
154  }
155 #endif // !defined( ITK_WRAPPING_PARSER )
156 
157 protected:
159  ~UnaryGeneratorImageFilter() override = default;
160 
170  void
171  GenerateOutputInformation() override;
172 
173 
183  template <typename TFunctor>
184  void
185  DynamicThreadedGenerateDataWithFunctor(const TFunctor &, const OutputImageRegionType & outputRegionForThread);
186  void
187  DynamicThreadedGenerateData(const OutputImageRegionType & outputRegionForThread) override;
190 private:
191  std::function<void(const OutputImageRegionType &)> m_DynamicThreadedGenerateDataFunction{};
192 };
193 } // end namespace itk
194 
195 #ifndef ITK_MANUAL_INSTANTIATION
196 # include "itkUnaryGeneratorImageFilter.hxx"
197 #endif
198 
199 #endif
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
ConstPointer
SmartPointer< const Self > ConstPointer
Definition: itkAddImageFilter.h:94
itk::UnaryGeneratorImageFilter::SetFunctor
void SetFunctor(ConstRefFunctionType *funcPointer)
Definition: itkUnaryGeneratorImageFilter.h:117
itk::ImageSource::OutputImagePointer
typename OutputImageType::Pointer OutputImagePointer
Definition: itkImageSource.h:91
itk::UnaryGeneratorImageFilter::ConstRefFunctionType
OutputImagePixelType(const InputImagePixelType &) ConstRefFunctionType
Definition: itkUnaryGeneratorImageFilter.h:82
itk::InPlaceImageFilter
Base class for filters that take an image as input and overwrite that image as the output.
Definition: itkInPlaceImageFilter.h:77
itk::UnaryGeneratorImageFilter::SetFunctor
void SetFunctor(const std::function< ConstRefFunctionType > &f)
Definition: itkUnaryGeneratorImageFilter.h:92
itk::UnaryGeneratorImageFilter
Implements pixel-wise generic "operation" on one image.
Definition: itkUnaryGeneratorImageFilter.h:55
itk::SmartPointer< Self >
itkImageRegionIteratorWithIndex.h
itk::UnaryGeneratorImageFilter::SetFunctor
void SetFunctor(const std::function< ValueFunctionType > &f)
Definition: itkUnaryGeneratorImageFilter.h:102
itk::ImageToImageFilter::InputImagePixelType
typename InputImageType::PixelType InputImagePixelType
Definition: itkImageToImageFilter.h:133
itk::ImageSource
Base class for all process objects that output image data.
Definition: itkImageSource.h:67
itk::UnaryGeneratorImageFilter::ValueFunctionType
OutputImagePixelType(InputImagePixelType) ValueFunctionType
Definition: itkUnaryGeneratorImageFilter.h:83
itk::ImageToImageFilter::InputImagePointer
typename InputImageType::Pointer InputImagePointer
Definition: itkImageToImageFilter.h:130
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::UnaryGeneratorImageFilter::SetFunctor
void SetFunctor(ValueFunctionType *funcPointer)
Definition: itkUnaryGeneratorImageFilter.h:127
itk::ImageToImageFilter::InputImageType
TInputImage InputImageType
Definition: itkImageToImageFilter.h:129
itk::UnaryGeneratorImageFilter::SetFunctor
void SetFunctor(const TFunctor &functor)
Definition: itkUnaryGeneratorImageFilter.h:146
itk::ImageSource::OutputImageRegionType
typename OutputImageType::RegionType OutputImageRegionType
Definition: itkImageSource.h:92
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
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::ImageSource::OutputImagePixelType
typename OutputImageType::PixelType OutputImagePixelType
Definition: itkImageSource.h:93
itk::ImageToImageFilter::InputImageRegionType
typename InputImageType::RegionType InputImageRegionType
Definition: itkImageToImageFilter.h:132
itkMath.h
itk::ImageSource::OutputImageType
TOutputImage OutputImageType
Definition: itkImageSource.h:90