ITK  4.3.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 {
35 namespace Functor
36 {
37 template< class TInput, class TOutput >
39 {
40 public:
42  {
47  }
48 
50  }
51 
52  void SetLowerThreshold(const TInput & thresh)
53  {
54  m_LowerThreshold = thresh;
55  }
56  void SetUpperThreshold(const TInput & thresh)
57  {
58  m_UpperThreshold = thresh;
59  }
60  void SetInsideValue(const TOutput & value)
61  {
62  m_InsideValue = value;
63  }
64  void SetOutsideValue(const TOutput & value)
65  {
66  m_OutsideValue = value;
67  }
68 
71  int SetGPUKernelArguments(GPUKernelManager::Pointer KernelManager, int KernelHandle)
72  {
73  KernelManager->SetKernelArg(KernelHandle, 0, sizeof(TInput), &(m_LowerThreshold) );
74  KernelManager->SetKernelArg(KernelHandle, 1, sizeof(TInput), &(m_UpperThreshold) );
75  KernelManager->SetKernelArg(KernelHandle, 2, sizeof(TOutput), &(m_InsideValue) );
76  KernelManager->SetKernelArg(KernelHandle, 3, sizeof(TOutput), &(m_OutsideValue) );
77  return 4;
78  }
80 
81 private:
84  TOutput m_InsideValue;
85  TOutput m_OutsideValue;
86 };
87 } // end of namespace Functor
88 
90 itkGPUKernelClassMacro(GPUBinaryThresholdImageFilterKernel);
91 
93 template< class TInputImage, class TOutputImage >
95  public
96  GPUUnaryFunctorImageFilter< TInputImage, TOutputImage,
97  Functor::GPUBinaryThreshold<
98  typename TInputImage::PixelType,
99  typename TOutputImage::PixelType >,
100  BinaryThresholdImageFilter<TInputImage, TOutputImage> >
101 {
102 public:
103 
106  typedef GPUUnaryFunctorImageFilter< TInputImage, TOutputImage,
108  typename TInputImage::PixelType,
109  typename TOutputImage::PixelType >,
114 
116  itkNewMacro(Self);
117 
120 
122  typedef typename TInputImage::PixelType InputPixelType;
123  typedef typename TOutputImage::PixelType OutputPixelType;
124 
127 
129  itkGetOpenCLSourceFromKernelMacro(GPUBinaryThresholdImageFilterKernel);
130 
131 protected:
134  }
135 
138  //virtual void BeforeThreadedGenerateData();
139 
142  virtual void GPUGenerateData();
143 
144 private:
145  GPUBinaryThresholdImageFilter(const Self &); //purposely not implemented
146  void operator=(const Self &); //purposely not implemented
147 
148 };
149 
152 {
153 public:
158 
160  virtual const char* GetITKSourceVersion() const {
161  return ITK_SOURCE_VERSION;
162  }
163  const char* GetDescription() const {
164  return "A Factory for GPUBinaryThresholdImageFilter";
165  }
167 
169  itkFactorylessNewMacro(Self);
170 
173 
175  static void RegisterOneFactory(void)
176  {
178 
180  }
181 
182 private:
183  GPUBinaryThresholdImageFilterFactory(const Self&); //purposely not implemented
184  void operator=(const Self&); //purposely not implemented
185 
186 #define OverrideThresholdFilterTypeMacro(ipt,opt,dm) \
187  { \
188  typedef itk::Image<ipt,dm> InputImageType; \
189  typedef itk::Image<opt,dm> OutputImageType; \
190  this->RegisterOverride( \
191  typeid(itk::BinaryThresholdImageFilter<InputImageType,OutputImageType>).name(), \
192  typeid(itk::GPUBinaryThresholdImageFilter<InputImageType,OutputImageType>).name(), \
193  "GPU Binary Threshold Image Filter Override", \
194  true, \
195  itk::CreateObjectFunction<GPUBinaryThresholdImageFilter<InputImageType,OutputImageType> >::New() ); \
196  }
197 
199  {
200  if( IsGPUAvailable() )
201  {
202  OverrideThresholdFilterTypeMacro(unsigned char, unsigned char, 1);
203  OverrideThresholdFilterTypeMacro(char, char, 1);
204  OverrideThresholdFilterTypeMacro(float,float,1);
206  OverrideThresholdFilterTypeMacro(unsigned int,unsigned int,1);
207  OverrideThresholdFilterTypeMacro(double,double,1);
208 
209  OverrideThresholdFilterTypeMacro(unsigned char, unsigned char, 2);
210  OverrideThresholdFilterTypeMacro(char, char, 2);
211  OverrideThresholdFilterTypeMacro(float,float,2);
213  OverrideThresholdFilterTypeMacro(unsigned int,unsigned int,2);
214  OverrideThresholdFilterTypeMacro(double,double,2);
215 
216  OverrideThresholdFilterTypeMacro(unsigned char, unsigned char, 3);
217  OverrideThresholdFilterTypeMacro(unsigned short, unsigned short, 3);
218  OverrideThresholdFilterTypeMacro(char, char, 3);
219  OverrideThresholdFilterTypeMacro(float,float,3);
221  OverrideThresholdFilterTypeMacro(unsigned int,unsigned int,3);
222  OverrideThresholdFilterTypeMacro(double,double,3);
223  }
224  }
225 
226 };
227 
228 } // end of namespace itk
229 
230 #ifndef ITK_MANUAL_INSTANTIATION
231 #include "itkGPUBinaryThresholdImageFilter.hxx"
232 #endif
233 
234 #endif
235