Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
clfImageOperator.cpp
1 /*
2  * clfImageOperator.cpp
3  *
4  * Created on: Dec 16, 2011
5  * Author: fkellner
6  */
7 
8 #include <OpenCLFramework/Algorithm/clfImageOperator.hh>
9 #include <Base/Common/BIASpragma.hh>
10 
11 using namespace BIAS;
12 
13 clfImageOperator::clfImageOperator(clfContext *ctx, bool sharedGL, unsigned int device)
14  : clfAlgorithm(ctx,sharedGL,device)
15 {
16  // add code to our program
17  programCL_->AddSource("/OpenCLFramework/Algorithm/cl/imageOperator.cl");
18  programCL_->Build();
19  programCL_->AddKernel("DifferenceImage");
20  programCL_->AddKernel("DifferenceAbsImage");
21  programCL_->AddKernel("DifferenceZeroLimitImage");
22  programCL_->AddKernel("CutOffMinThreshold");
23 }
24 
26 {
27 }
28 
29 void clfImageOperator::Difference(clfImage2D *im0, clfImage2D *im1, clfImage2D *result, bool asAbs, bool zeroCut)
30 {
31  std::string kernelname = "DifferenceImage";
32  if (asAbs) kernelname = "DifferenceAbsImage";
33  if (zeroCut) kernelname = "DifferenceZeroLimitImage";
34  programCL_->KernelSetArgument(kernelname, 0, *im0);
35  programCL_->KernelSetArgument(kernelname, 1, *im1);
36  programCL_->KernelSetArgument(kernelname, 2, *result);
37  unsigned int w,h;
38  result->GetImageDim(w,h);
39  unsigned int lx=0, ly=0;
40  if (w%16==0) lx=16;
41  if (h%16==0) ly=16;
42  context_->RunOn2DRange(*programCL_, kernelname, w,h, lx,ly);
43 }
44 
45 void clfImageOperator::CutOffMinThreshold(clfImage2D *im0, clfImage2D *result, float minVal) {
46  programCL_->KernelSetArgument("CutOffMinThreshold", 0, *im0);
47  programCL_->KernelSetArgument("CutOffMinThreshold", 1, *result);
48  unsigned int w,h;
49  result->GetImageDim(w,h);
50  unsigned int lx=0, ly=0;
51  if (w%16==0) lx=16;
52  if (h%16==0) ly=16;
53  context_->RunOn2DRange(*programCL_, "CutOffMinThreshold", w,h, lx,ly);
54 }
55 
clfProgram * programCL_
Definition: clfAlgorithm.hh:35
std::string AddSource(std::string filename)
adds source code from a file
Definition: clfProgram.cpp:64
void GetImageDim(unsigned int &width, unsigned int &height) const
Definition: clfImage2D.hh:110
OpenCL Image2D wrapper.
Definition: clfImage2D.hh:46
clfImageOperator(clfContext *ctx=NULL, bool sharedGL=false, unsigned int device=0)
void Build(int deviceNr=0, std::string options="")
builds the sources added by AddSource and AddSourceFromString
Definition: clfProgram.cpp:115
OpenCL Context wrapper.
Definition: clfContext.hh:49
void KernelSetArgument(std::string kernelname, unsigned int argnumber, clfBuffer &buffer)
set kernel argument
Definition: clfProgram.cpp:177
void AddKernel(std::string kernelname)
adds a kernel to the program.
Definition: clfProgram.cpp:158
void RunOn2DRange(clfProgram &program, std::string kernelname, unsigned int globalrangeX, unsigned int globalrangeY, unsigned int localrangeX=0, unsigned int localrangeY=0)
run a kernel on a 2D memory range
Definition: clfContext.cpp:234
void CutOffMinThreshold(clfImage2D *im0, clfImage2D *result, float minVal)
clfContext * context_
Definition: clfAlgorithm.hh:34
void Difference(clfImage2D *im0, clfImage2D *im1, clfImage2D *result, bool asAbs=false, bool zeroCut=false)