本文整理汇总了C++中image::pointer::getOpenCLBufferAccess方法的典型用法代码示例。如果您正苦于以下问题:C++ pointer::getOpenCLBufferAccess方法的具体用法?C++ pointer::getOpenCLBufferAccess怎么用?C++ pointer::getOpenCLBufferAccess使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类image::pointer
的用法示例。
在下文中一共展示了pointer::getOpenCLBufferAccess方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: execute
void Dilation::execute() {
Image::pointer input = getInputData<Image>();
if(input->getDataType() != TYPE_UINT8) {
throw Exception("Data type of image given to Dilation must be UINT8");
}
Image::pointer output = getOutputData<Image>();
output->createFromImage(input);
SceneGraph::setParentNode(output, input);
output->fill(0);
OpenCLDevice::pointer device = std::dynamic_pointer_cast<OpenCLDevice>(getMainDevice());
cl::CommandQueue queue = device->getCommandQueue();
cl::Program program = getOpenCLProgram(device);
cl::Kernel dilateKernel(program, "dilate");
Vector3ui size = input->getSize();
OpenCLImageAccess::pointer access = input->getOpenCLImageAccess(ACCESS_READ, device);
dilateKernel.setArg(0, *access->get3DImage());
dilateKernel.setArg(2, mSize/2);
if(!device->isWritingTo3DTexturesSupported()) {
OpenCLBufferAccess::pointer access2 = output->getOpenCLBufferAccess(ACCESS_READ_WRITE, device);
dilateKernel.setArg(1, *access2->get());
queue.enqueueNDRangeKernel(
dilateKernel,
cl::NullRange,
cl::NDRange(size.x(), size.y(), size.z()),
cl::NullRange
);
} else {
OpenCLImageAccess::pointer access2 = output->getOpenCLImageAccess(ACCESS_READ_WRITE, device);
dilateKernel.setArg(1, *access2->get3DImage());
queue.enqueueNDRangeKernel(
dilateKernel,
cl::NullRange,
cl::NDRange(size.x(), size.y(), size.z()),
cl::NullRange
);
}
}
示例2: recompileOpenCLCode
//.........这里部分代码省略.........
filename = "Algorithms/NoneLocalMeans/NoneLocalMeans2Dgaussian.cl";
}else{
filename = "Algorithms/NoneLocalMeans/NoneLocalMeans2Dconstant.cl";
}
//filename = "Algorithms/NoneLocalMeans/NoneLocalMeans2DgsPixelWise.cl";
//filename = "Algorithms/NoneLocalMeans/NoneLocalMeans2Dgs.cl";
//filename = "Algorithms/NoneLocalMeans/NoneLocalMeans2Dc.cl";
}
else {
filename = "Algorithms/NoneLocalMeans/NoneLocalMeans3Dgs.cl";
}
int programNr = device->createProgramFromSource(std::string(FAST_SOURCE_DIR) + filename, buildOptions);
mKernel = cl::Kernel(device->getProgram(programNr), "noneLocalMeans");
mDimensionCLCodeCompiledFor = input->getDimensions();
mTypeCLCodeCompiledFor = input->getDataType();
}*/
void NoneLocalMeans::execute() {
Image::pointer input = getStaticInputData<Image>(0);
Image::pointer output = getStaticOutputData<Image>(0);
// Initialize output image
ExecutionDevice::pointer device = getMainDevice();
if(mOutputTypeSet) {
output->create(input->getSize(), mOutputType, input->getNrOfComponents());
output->setSpacing(input->getSpacing());
} else {
output->createFromImage(input);
}
mOutputType = output->getDataType();
SceneGraph::setParentNode(output, input);
if(device->isHost()) {
switch(input->getDataType()) {
fastSwitchTypeMacro(executeAlgorithmOnHost<FAST_TYPE>(input, output, groupSize, windowSize, denoiseStrength, sigma));
}
} else {
OpenCLDevice::pointer clDevice = device;
recompileOpenCLCode(input);
cl::NDRange globalSize;
OpenCLImageAccess::pointer inputAccess = input->getOpenCLImageAccess(ACCESS_READ, device);
if(input->getDimensions() == 2) {
OpenCLImageAccess::pointer outputAccess = output->getOpenCLImageAccess(ACCESS_READ_WRITE, device);
mKernel.setArg(2, (denoiseStrength*denoiseStrength));
mKernel.setArg(3, (sigma*sigma));
globalSize = cl::NDRange(input->getWidth(),input->getHeight());
mKernel.setArg(0, *inputAccess->get2DImage());
mKernel.setArg(1, *outputAccess->get2DImage());
clDevice->getCommandQueue().enqueueNDRangeKernel(
mKernel,
cl::NullRange,
globalSize,
cl::NullRange
);
} else {
// Create an auxilliary image
//Image::pointer output2 = Image::New();
//output2->createFromImage(output);
globalSize = cl::NDRange(input->getWidth(),input->getHeight(),input->getDepth());
if(clDevice->isWritingTo3DTexturesSupported()) {
mKernel.setArg(2, (denoiseStrength*denoiseStrength));
mKernel.setArg(3, (sigma*sigma));
OpenCLImageAccess::pointer outputAccess = output->getOpenCLImageAccess(ACCESS_READ_WRITE, device);
//OpenCLImageAccess::pointer outputAccess2 = output2->getOpenCLImageAccess(ACCESS_READ_WRITE, device);
//cl::Image3D* image2;
cl::Image3D* image;
image = outputAccess->get3DImage();
//image2 = outputAccess->get3DImage();
mKernel.setArg(0, *inputAccess->get3DImage());
mKernel.setArg(1, *image);
clDevice->getCommandQueue().enqueueNDRangeKernel(
mKernel,
cl::NullRange,
globalSize,
cl::NullRange
);
}else{
mKernel.setArg(2, (denoiseStrength*denoiseStrength));
mKernel.setArg(3, (sigma*sigma));
OpenCLBufferAccess::pointer outputAccess = output->getOpenCLBufferAccess(ACCESS_READ_WRITE, device);
mKernel.setArg(0, *inputAccess->get3DImage());
mKernel.setArg(1, *outputAccess->get());
clDevice->getCommandQueue().enqueueNDRangeKernel(
mKernel,
cl::NullRange,
globalSize,
cl::NullRange
);
}
}
}
}
示例3: execute
void DoubleFilter::execute() {
if(!mInput.isValid()) {
throw Exception("No input supplied to GaussianSmoothingFilter");
}
Image::pointer input = mInput;
Image::pointer output = mOutput;
// Initialize output image
output->createFromImage(input, mDevice);
if(mDevice->isHost()) {
// Execution device is Host, use the executeAlgorithmOnHost function with the given data type
switch(input->getDataType()) {
// This macro creates a case statement for each data type and sets FAST_TYPE to the correct C++ data type
fastSwitchTypeMacro(executeAlgorithmOnHost<FAST_TYPE>(input, output));
}
} else {
// Execution device is an OpenCL device
OpenCLDevice::pointer device = boost::static_pointer_cast<OpenCLDevice>(mDevice);
// Set build options based on the data type of the data
std::string buildOptions = "";
switch(input->getDataType()) {
case TYPE_FLOAT:
buildOptions = "-DTYPE=float";
break;
case TYPE_INT8:
buildOptions = "-DTYPE=char";
break;
case TYPE_UINT8:
buildOptions = "-DTYPE=uchar";
break;
case TYPE_INT16:
buildOptions = "-DTYPE=short";
break;
case TYPE_UINT16:
buildOptions = "-DTYPE=ushort";
break;
}
// Compile the code
int programNr = device->createProgramFromSource(std::string(FAST_SOURCE_DIR) + "Tests/Algorithms/DoubleFilter.cl", buildOptions);
cl::Kernel kernel = cl::Kernel(device->getProgram(programNr), "doubleFilter");
// Get global size for the kernel
cl::NDRange globalSize(input->getWidth()*input->getHeight()*input->getDepth()*input->getNrOfComponents());
// Set the arguments for the kernel
OpenCLBufferAccess inputAccess = input->getOpenCLBufferAccess(ACCESS_READ, device);
OpenCLBufferAccess outputAccess = output->getOpenCLBufferAccess(ACCESS_READ_WRITE, device);
kernel.setArg(0, *inputAccess.get());
kernel.setArg(1, *outputAccess.get());
// Execute the kernel
device->getCommandQueue().enqueueNDRangeKernel(
kernel,
cl::NullRange,
globalSize,
cl::NullRange
);
}
// Update timestamp of the output data
output->updateModifiedTimestamp();
}