ITK  5.2.0
Insight Toolkit
itkGPUBinaryThresholdImageFilter.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 itkGPUBinaryThresholdImageFilter_h
19 #define itkGPUBinaryThresholdImageFilter_h
20 
21 #include "itkOpenCLUtil.h"
22 #include "itkGPUFunctorBase.h"
23 #include "itkGPUKernelManager.h"
26 
27 namespace itk
28 {
29 
30 namespace Functor
31 {
32 template <typename TInput, typename TOutput>
33 class ITK_TEMPLATE_EXPORT GPUBinaryThreshold : public GPUFunctorBase
34 {
35 public:
37  {
38  m_LowerThreshold = NumericTraits<TInput>::NonpositiveMin();
39  m_UpperThreshold = NumericTraits<TInput>::max();
40  m_OutsideValue = NumericTraits<TOutput>::ZeroValue();
41  m_InsideValue = NumericTraits<TOutput>::max();
42  }
43 
44  ~GPUBinaryThreshold() override = default;
45 
46  void
47  SetLowerThreshold(const TInput & thresh)
48  {
49  m_LowerThreshold = thresh;
50  }
51  void
52  SetUpperThreshold(const TInput & thresh)
53  {
54  m_UpperThreshold = thresh;
55  }
56  void
57  SetInsideValue(const TOutput & value)
58  {
59  m_InsideValue = value;
60  }
61  void
62  SetOutsideValue(const TOutput & value)
63  {
64  m_OutsideValue = value;
65  }
66 
69  int
70  SetGPUKernelArguments(GPUKernelManager::Pointer KernelManager, int KernelHandle) override
71  {
72  KernelManager->SetKernelArg(KernelHandle, 0, sizeof(TInput), &(m_LowerThreshold));
73  KernelManager->SetKernelArg(KernelHandle, 1, sizeof(TInput), &(m_UpperThreshold));
74  KernelManager->SetKernelArg(KernelHandle, 2, sizeof(TOutput), &(m_InsideValue));
75  KernelManager->SetKernelArg(KernelHandle, 3, sizeof(TOutput), &(m_OutsideValue));
76  return 4;
77  }
79 
80 private:
83  TOutput m_InsideValue;
84  TOutput m_OutsideValue;
85 };
86 } // end of namespace Functor
87 
89 class itkGPUKernelClassMacro(GPUBinaryThresholdImageFilterKernel);
90 
98 template <typename TInputImage, typename TOutputImage>
99 class ITK_TEMPLATE_EXPORT GPUBinaryThresholdImageFilter
101  TInputImage,
102  TOutputImage,
103  Functor::GPUBinaryThreshold<typename TInputImage::PixelType, typename TOutputImage::PixelType>,
104  BinaryThresholdImageFilter<TInputImage, TOutputImage>>
105 {
106 public:
107  ITK_DISALLOW_COPY_AND_MOVE(GPUBinaryThresholdImageFilter);
108 
112  TInputImage,
113  TOutputImage,
119 
121  itkNewMacro(Self);
122 
125 
127  using InputPixelType = typename TInputImage::PixelType;
128  using OutputPixelType = typename TOutputImage::PixelType;
129 
132 
134  itkGetOpenCLSourceFromKernelMacro(GPUBinaryThresholdImageFilterKernel);
135 
136 protected:
138  ~GPUBinaryThresholdImageFilter() override = default;
139 
142  // virtual void BeforeThreadedGenerateData();
143 
146  void
147  GPUGenerateData() override;
148 };
149 
157 {
158 public:
159  ITK_DISALLOW_COPY_AND_MOVE(GPUBinaryThresholdImageFilterFactory);
160 
165 
167  const char *
168  GetITKSourceVersion() const override
169  {
170  return ITK_SOURCE_VERSION;
171  }
172  const char *
173  GetDescription() const override
174  {
175  return "A Factory for GPUBinaryThresholdImageFilter";
176  }
178 
180  itkFactorylessNewMacro(Self);
181 
184 
186  static void
188  {
190 
192  }
193 
194 private:
195 #define OverrideThresholdFilterTypeMacro(ipt, opt, dm) \
196  { \
197  using InputImageType = itk::Image<ipt, dm>; \
198  using OutputImageType = itk::Image<opt, dm>; \
199  this->RegisterOverride( \
200  typeid(itk::BinaryThresholdImageFilter<InputImageType, OutputImageType>).name(), \
201  typeid(itk::GPUBinaryThresholdImageFilter<InputImageType, OutputImageType>).name(), \
202  "GPU Binary Threshold Image Filter Override", \
203  true, \
204  itk::CreateObjectFunction<GPUBinaryThresholdImageFilter<InputImageType, OutputImageType>>::New()); \
205  }
206 
208  {
209  if (IsGPUAvailable())
210  {
211  OverrideThresholdFilterTypeMacro(unsigned char, unsigned char, 1);
212  OverrideThresholdFilterTypeMacro(char, char, 1);
213  OverrideThresholdFilterTypeMacro(float, float, 1);
215  OverrideThresholdFilterTypeMacro(unsigned int, unsigned int, 1);
216  OverrideThresholdFilterTypeMacro(double, double, 1);
217 
218  OverrideThresholdFilterTypeMacro(unsigned char, unsigned char, 2);
219  OverrideThresholdFilterTypeMacro(char, char, 2);
220  OverrideThresholdFilterTypeMacro(float, float, 2);
222  OverrideThresholdFilterTypeMacro(unsigned int, unsigned int, 2);
223  OverrideThresholdFilterTypeMacro(double, double, 2);
224 
225  OverrideThresholdFilterTypeMacro(unsigned char, unsigned char, 3);
226  OverrideThresholdFilterTypeMacro(unsigned short, unsigned short, 3);
227  OverrideThresholdFilterTypeMacro(char, char, 3);
228  OverrideThresholdFilterTypeMacro(float, float, 3);
230  OverrideThresholdFilterTypeMacro(unsigned int, unsigned int, 3);
231  OverrideThresholdFilterTypeMacro(double, double, 3);
232  }
233  }
234 };
235 
236 } // end of namespace itk
237 
238 #ifndef ITK_MANUAL_INSTANTIATION
239 # include "itkGPUBinaryThresholdImageFilter.hxx"
240 #endif
241 
242 #endif
itk::Functor::GPUFunctorBase
Base functor class for GPU functor image filters.
Definition: itkGPUFunctorBase.h:33
itk::Functor::GPUBinaryThreshold::GPUBinaryThreshold
GPUBinaryThreshold()
Definition: itkGPUBinaryThresholdImageFilter.h:36
itk::GPUBinaryThresholdImageFilterFactory::GetDescription
const char * GetDescription() const override
Definition: itkGPUBinaryThresholdImageFilter.h:173
itk::SimpleDataObjectDecorator
Decorates any "simple" data type (data types without smart pointers) with a DataObject API.
Definition: itkSimpleDataObjectDecorator.h:66
itk::GPUBinaryThresholdImageFilter
GPU version of binary threshold image filter.
Definition: itkGPUBinaryThresholdImageFilter.h:99
itk::ObjectFactoryBase
Create instances of classes using an object factory.
Definition: itkObjectFactoryBase.h:62
itk::Functor::GPUBinaryThreshold::SetGPUKernelArguments
int SetGPUKernelArguments(GPUKernelManager::Pointer KernelManager, int KernelHandle) override
Definition: itkGPUBinaryThresholdImageFilter.h:70
OverrideThresholdFilterTypeMacro
#define OverrideThresholdFilterTypeMacro(ipt, opt, dm)
Definition: itkGPUBinaryThresholdImageFilter.h:195
itk::Functor::GPUBinaryThreshold::SetLowerThreshold
void SetLowerThreshold(const TInput &thresh)
Definition: itkGPUBinaryThresholdImageFilter.h:47
itk::BinaryThresholdImageFilter
Binarize an input image by thresholding.
Definition: itkBinaryThresholdImageFilter.h:139
itk::NumericTraits::NonpositiveMin
static constexpr T NonpositiveMin()
Definition: itkNumericTraits.h:97
itk::GPUBinaryThresholdImageFilterFactory::New
static Pointer New()
itk::SmartPointer< Self >
itk::Functor::GPUBinaryThreshold::m_InsideValue
TOutput m_InsideValue
Definition: itkGPUBinaryThresholdImageFilter.h:83
itk::Functor::GPUBinaryThreshold::SetOutsideValue
void SetOutsideValue(const TOutput &value)
Definition: itkGPUBinaryThresholdImageFilter.h:62
itkGPUKernelManager.h
itk::GPUBinaryThresholdImageFilterFactory::GPUBinaryThresholdImageFilterFactory
GPUBinaryThresholdImageFilterFactory()
Definition: itkGPUBinaryThresholdImageFilter.h:207
itk::Functor::GPUBinaryThreshold
Definition: itkGPUBinaryThresholdImageFilter.h:33
itkOpenCLUtil.h
itk::Functor::GPUBinaryThreshold::m_UpperThreshold
TInput m_UpperThreshold
Definition: itkGPUBinaryThresholdImageFilter.h:82
ITK_SOURCE_VERSION
#define ITK_SOURCE_VERSION
Definition: itkVersion.h:39
itk::ImageSource
Base class for all process objects that output image data.
Definition: itkImageSource.h:67
itk::GPUBinaryThresholdImageFilterFactory::GetITKSourceVersion
const char * GetITKSourceVersion() const override
Definition: itkGPUBinaryThresholdImageFilter.h:168
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::BinaryThresholdImageFilter::OutputPixelType
typename TOutputImage::PixelType OutputPixelType
Definition: itkBinaryThresholdImageFilter.h:165
itk::GPUBinaryThresholdImageFilterFactory
Definition: itkGPUBinaryThresholdImageFilter.h:156
itk::GPUUnaryFunctorImageFilter
Implements pixel-wise generic operation on one image using the GPU.
Definition: itkGPUUnaryFunctorImageFilter.h:39
itk::Functor::GPUBinaryThreshold::m_OutsideValue
TOutput m_OutsideValue
Definition: itkGPUBinaryThresholdImageFilter.h:84
itkGPUFunctorBase.h
itk::BinaryThresholdImageFilter::InputPixelType
typename TInputImage::PixelType InputPixelType
Definition: itkBinaryThresholdImageFilter.h:164
itk::Functor::GPUBinaryThreshold::SetUpperThreshold
void SetUpperThreshold(const TInput &thresh)
Definition: itkGPUBinaryThresholdImageFilter.h:52
itk::GPUBinaryThresholdImageFilterFactory::RegisterOneFactory
static void RegisterOneFactory()
Definition: itkGPUBinaryThresholdImageFilter.h:187
itk::NumericTraits::max
static constexpr T max(const T &)
Definition: itkNumericTraits.h:167
itk::NumericTraits::ZeroValue
static T ZeroValue()
Definition: itkNumericTraits.h:148
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::Functor::GPUBinaryThreshold::SetInsideValue
void SetInsideValue(const TOutput &value)
Definition: itkGPUBinaryThresholdImageFilter.h:57
itkBinaryThresholdImageFilter.h
itk::Functor::GPUBinaryThreshold::m_LowerThreshold
TInput m_LowerThreshold
Definition: itkGPUBinaryThresholdImageFilter.h:81
itk::ObjectFactoryBase::RegisterFactory
static bool RegisterFactory(ObjectFactoryBase *, InsertionPositionEnum where=InsertionPositionEnum::INSERT_AT_BACK, vcl_size_t position=0)
itkGPUUnaryFunctorImageFilter.h
itk::IsGPUAvailable
bool IsGPUAvailable()