ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkGPUBinaryThresholdImageFilter.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 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 
45  }
46 
47  void SetLowerThreshold(const TInput & thresh)
48  {
49  m_LowerThreshold = thresh;
50  }
51  void SetUpperThreshold(const TInput & thresh)
52  {
53  m_UpperThreshold = thresh;
54  }
55  void SetInsideValue(const TOutput & value)
56  {
57  m_InsideValue = value;
58  }
59  void SetOutsideValue(const TOutput & value)
60  {
61  m_OutsideValue = value;
62  }
63 
66  int SetGPUKernelArguments(GPUKernelManager::Pointer KernelManager, int KernelHandle)
67  {
68  KernelManager->SetKernelArg(KernelHandle, 0, sizeof(TInput), &(m_LowerThreshold) );
69  KernelManager->SetKernelArg(KernelHandle, 1, sizeof(TInput), &(m_UpperThreshold) );
70  KernelManager->SetKernelArg(KernelHandle, 2, sizeof(TOutput), &(m_InsideValue) );
71  KernelManager->SetKernelArg(KernelHandle, 3, sizeof(TOutput), &(m_OutsideValue) );
72  return 4;
73  }
75 
76 private:
79  TOutput m_InsideValue;
80  TOutput m_OutsideValue;
81 };
82 } // end of namespace Functor
83 
85 itkGPUKernelClassMacro(GPUBinaryThresholdImageFilterKernel);
86 
94 template< typename TInputImage, typename TOutputImage >
95 class ITK_TEMPLATE_EXPORT GPUBinaryThresholdImageFilter :
96  public
97  GPUUnaryFunctorImageFilter< TInputImage, TOutputImage,
98  Functor::GPUBinaryThreshold<
99  typename TInputImage::PixelType,
100  typename TOutputImage::PixelType >,
101  BinaryThresholdImageFilter<TInputImage, TOutputImage> >
102 {
103 public:
104  ITK_DISALLOW_COPY_AND_ASSIGN(GPUBinaryThresholdImageFilter);
105 
108  using GPUSuperclass = GPUUnaryFunctorImageFilter< TInputImage, TOutputImage,
110  typename TInputImage::PixelType,
111  typename TOutputImage::PixelType >,
116 
118  itkNewMacro(Self);
119 
122 
124  using InputPixelType = typename TInputImage::PixelType;
125  using OutputPixelType = typename TOutputImage::PixelType;
126 
129 
131  itkGetOpenCLSourceFromKernelMacro(GPUBinaryThresholdImageFilterKernel);
132 
133 protected:
136 
139  //virtual void BeforeThreadedGenerateData();
140 
143  void GPUGenerateData() override;
144 };
145 
153 {
154 public:
155  ITK_DISALLOW_COPY_AND_ASSIGN(GPUBinaryThresholdImageFilterFactory);
156 
161 
163  const char* GetITKSourceVersion() const override
164  {
165  return ITK_SOURCE_VERSION;
166  }
167  const char* GetDescription() const override
168  {
169  return "A Factory for GPUBinaryThresholdImageFilter";
170  }
172 
174  itkFactorylessNewMacro(Self);
175 
178 
180  static void RegisterOneFactory()
181  {
183 
185  }
186 
187 private:
188 #define OverrideThresholdFilterTypeMacro(ipt,opt,dm) \
189  { \
190  using InputImageType = itk::Image<ipt,dm>; \
191  using OutputImageType = itk::Image<opt,dm>; \
192  this->RegisterOverride( \
193  typeid(itk::BinaryThresholdImageFilter<InputImageType,OutputImageType>).name(), \
194  typeid(itk::GPUBinaryThresholdImageFilter<InputImageType,OutputImageType>).name(), \
195  "GPU Binary Threshold Image Filter Override", \
196  true, \
197  itk::CreateObjectFunction<GPUBinaryThresholdImageFilter<InputImageType,OutputImageType> >::New() ); \
198  }
199 
201  {
202  if( IsGPUAvailable() )
203  {
204  OverrideThresholdFilterTypeMacro(unsigned char, unsigned char, 1);
205  OverrideThresholdFilterTypeMacro(char, char, 1);
206  OverrideThresholdFilterTypeMacro(float,float,1);
208  OverrideThresholdFilterTypeMacro(unsigned int,unsigned int,1);
209  OverrideThresholdFilterTypeMacro(double,double,1);
210 
211  OverrideThresholdFilterTypeMacro(unsigned char, unsigned char, 2);
212  OverrideThresholdFilterTypeMacro(char, char, 2);
213  OverrideThresholdFilterTypeMacro(float,float,2);
215  OverrideThresholdFilterTypeMacro(unsigned int,unsigned int,2);
216  OverrideThresholdFilterTypeMacro(double,double,2);
217 
218  OverrideThresholdFilterTypeMacro(unsigned char, unsigned char, 3);
219  OverrideThresholdFilterTypeMacro(unsigned short, unsigned short, 3);
220  OverrideThresholdFilterTypeMacro(char, char, 3);
221  OverrideThresholdFilterTypeMacro(float,float,3);
223  OverrideThresholdFilterTypeMacro(unsigned int,unsigned int,3);
224  OverrideThresholdFilterTypeMacro(double,double,3);
225  }
226  }
227 
228 };
229 
230 } // end of namespace itk
231 
232 #ifndef ITK_MANUAL_INSTANTIATION
233 #include "itkGPUBinaryThresholdImageFilter.hxx"
234 #endif
235 
236 #endif
Light weight base class for most itk classes.
#define ITK_SOURCE_VERSION
Definition: itkVersion.h:40
Define numeric traits for std::vector.
int SetGPUKernelArguments(GPUKernelManager::Pointer KernelManager, int KernelHandle)
Base class for all process objects that output image data.
Create instances of classes using an object factory.
itkGPUKernelClassMacro(GPUImageOpsKernel)
GPU version of binary threshold image filter.
Binarize an input image by thresholding.
Base functor class for GPU functor image filters.
Decorates any &quot;simple&quot; data type (data types without smart pointers) with a DataObject API...
typename TInputImage::PixelType InputPixelType
#define OverrideThresholdFilterTypeMacro(ipt, opt, dm)
static bool RegisterFactory(ObjectFactoryBase *, InsertionPositionType where=INSERT_AT_BACK, vcl_size_t position=0)
Implements pixel-wise generic operation on one image using the GPU.
bool IsGPUAvailable()
typename TOutputImage::PixelType OutputPixelType