本文整理汇总了C++中image::pointer::getOpenCLImageAccess2D方法的典型用法代码示例。如果您正苦于以下问题:C++ pointer::getOpenCLImageAccess2D方法的具体用法?C++ pointer::getOpenCLImageAccess2D怎么用?C++ pointer::getOpenCLImageAccess2D使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类image::pointer
的用法示例。
在下文中一共展示了pointer::getOpenCLImageAccess2D方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: execute
void SeededRegionGrowing::execute() {
if(mSeedPoints.size() == 0)
throw Exception("No seed points supplied to SeededRegionGrowing");
Image::pointer input = getStaticInputData<Image>();
if(input->getNrOfComponents() != 1)
throw Exception("Seeded region growing currently doesn't support images with several components.");
Segmentation::pointer output = getStaticOutputData<Segmentation>();
// Initialize output image
output->createFromImage(input, getMainDevice());
if(getMainDevice()->isHost()) {
ImageAccess::pointer inputAccess = input->getImageAccess(ACCESS_READ);
void* inputData = inputAccess->get();
switch(input->getDataType()) {
fastSwitchTypeMacro(executeOnHost<FAST_TYPE>((FAST_TYPE*)inputData, output));
}
} else {
OpenCLDevice::pointer device = getMainDevice();
recompileOpenCLCode(input);
ImageAccess::pointer access = output->getImageAccess(ACCESS_READ_WRITE);
uchar* outputData = (uchar*)access->get();
// Initialize to all 0s
memset(outputData,0,sizeof(uchar)*output->getWidth()*output->getHeight()*output->getDepth());
// Add sedd points
for(int i = 0; i < mSeedPoints.size(); i++) {
Vector3ui pos = mSeedPoints[i];
// Check if seed point is in bounds
if(pos.x() < 0 || pos.y() < 0 || pos.z() < 0 ||
pos.x() >= output->getWidth() || pos.y() >= output->getHeight() || pos.z() >= output->getDepth())
throw Exception("One of the seed points given to SeededRegionGrowing was out of bounds.");
outputData[pos.x() + pos.y()*output->getWidth() + pos.z()*output->getWidth()*output->getHeight()] = 2;
}
access->release();
cl::NDRange globalSize;
if(output->getDimensions() == 2) {
globalSize = cl::NDRange(input->getWidth(),input->getHeight());
OpenCLImageAccess2D::pointer inputAccess = input->getOpenCLImageAccess2D(ACCESS_READ, device);
mKernel.setArg(0, *inputAccess->get());
} else {
globalSize = cl::NDRange(input->getWidth(),input->getHeight(), input->getDepth());
OpenCLImageAccess3D::pointer inputAccess = input->getOpenCLImageAccess3D(ACCESS_READ, device);
mKernel.setArg(0, *inputAccess->get());
}
OpenCLBufferAccess::pointer outputAccess = output->getOpenCLBufferAccess(ACCESS_READ_WRITE, device);
cl::Buffer stopGrowingBuffer = cl::Buffer(
device->getContext(),
CL_MEM_READ_WRITE,
sizeof(char));
cl::CommandQueue queue = device->getCommandQueue();
mKernel.setArg(1, *outputAccess->get());
mKernel.setArg(2, stopGrowingBuffer);
mKernel.setArg(3, mMinimumIntensity);
mKernel.setArg(4, mMaximumIntensity);
bool stopGrowing = false;
char stopGrowingInit = 1;
char * stopGrowingResult = new char;
int iterations = 0;
do {
iterations++;
queue.enqueueWriteBuffer(stopGrowingBuffer, CL_TRUE, 0, sizeof(char), &stopGrowingInit);
queue.enqueueNDRangeKernel(
mKernel,
cl::NullRange,
globalSize,
cl::NullRange
);
queue.enqueueReadBuffer(stopGrowingBuffer, CL_TRUE, 0, sizeof(char), stopGrowingResult);
if(*stopGrowingResult == 1)
stopGrowing = true;
} while(!stopGrowing);
}
}