本文整理汇总了C++中image::pointer::getWidth方法的典型用法代码示例。如果您正苦于以下问题:C++ pointer::getWidth方法的具体用法?C++ pointer::getWidth怎么用?C++ pointer::getWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类image::pointer
的用法示例。
在下文中一共展示了pointer::getWidth方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
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;
OpenCLImageAccess::pointer inputAccess = input->getOpenCLImageAccess(ACCESS_READ, device);
if(output->getDimensions() == 2) {
globalSize = cl::NDRange(input->getWidth(),input->getHeight());
mKernel.setArg(0, *inputAccess->get2DImage());
} else {
globalSize = cl::NDRange(input->getWidth(),input->getHeight(), input->getDepth());
mKernel.setArg(0, *inputAccess->get3DImage());
}
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);
}
}
示例2: CHECK
#include "VTKImageImporter.hpp"
#include "VTKImageExporter.hpp"
#include "ImageImporter.hpp"
using namespace fast;
// TODO rewrite this test so that it doesn't use the vtk exporter
TEST_CASE("Import an image from VTK to FAST", "[fast][VTK]") {
ImageImporter::pointer importer = ImageImporter::New();
importer->setFilename(std::string(FAST_TEST_DATA_DIR) + "US-2D.jpg");
Image::pointer fastImage = importer->getOutput();
// VTK Export
vtkSmartPointer<VTKImageExporter> vtkExporter = VTKImageExporter::New();
vtkExporter->SetInput(fastImage);
vtkSmartPointer<vtkImageData> vtkImage = vtkExporter->GetOutput();
vtkExporter->Update();
// VTK Import example
VTKImageImporter::pointer vtkImporter = VTKImageImporter::New();
vtkImporter->setInput(vtkImage);
Image::pointer importedImage = vtkImporter->getOutput();
vtkImporter->update();
CHECK(fastImage->getWidth() == importedImage->getWidth());
CHECK(fastImage->getHeight() == importedImage->getHeight());
CHECK(fastImage->getDepth() == 1);
CHECK(fastImage->getDimensions() == 2);
CHECK(fastImage->getDataType() == TYPE_FLOAT);
}
示例3: Exception
void
SegmentationRenderer::draw(Matrix4f perspectiveMatrix, Matrix4f viewingMatrix, float zNear, float zFar, bool mode2D) {
std::lock_guard<std::mutex> lock(mMutex);
OpenCLDevice::pointer device = std::dynamic_pointer_cast<OpenCLDevice>(getMainDevice());
if(mColorsModified) {
// Transfer colors to device (this doesn't have to happen every render call..)
std::unique_ptr<float[]> colorData(new float[3*mLabelColors.size()]);
std::unordered_map<int, Color>::iterator it;
for(it = mLabelColors.begin(); it != mLabelColors.end(); it++) {
colorData[it->first*3] = it->second.getRedValue();
colorData[it->first*3+1] = it->second.getGreenValue();
colorData[it->first*3+2] = it->second.getBlueValue();
}
mColorBuffer = cl::Buffer(
device->getContext(),
CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
sizeof(float)*3*mLabelColors.size(),
colorData.get()
);
}
if(mFillAreaModified) {
// Transfer colors to device (this doesn't have to happen every render call..)
std::unique_ptr<char[]> fillAreaData(new char[mLabelColors.size()]);
std::unordered_map<int, Color>::iterator it;
for(it = mLabelColors.begin(); it != mLabelColors.end(); it++) {
if(mLabelFillArea.count(it->first) == 0) {
// Use default value
fillAreaData[it->first] = mFillArea;
} else {
fillAreaData[it->first] = mLabelFillArea[it->first];
}
}
mFillAreaBuffer = cl::Buffer(
device->getContext(),
CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
sizeof(char)*mLabelColors.size(),
fillAreaData.get()
);
}
mKernel = cl::Kernel(getOpenCLProgram(device), "renderToTexture");
mKernel.setArg(2, mColorBuffer);
mKernel.setArg(3, mFillAreaBuffer);
mKernel.setArg(4, mBorderRadius);
mKernel.setArg(5, mOpacity);
for(auto it : mDataToRender) {
Image::pointer input = std::static_pointer_cast<Image>(it.second);
uint inputNr = it.first;
if(input->getDimensions() != 2)
throw Exception("SegmentationRenderer only supports 2D images. Use ImageSlicer to extract a 2D slice from a 3D image.");
if(input->getDataType() != TYPE_UINT8)
throw Exception("SegmentationRenderer only support images with dat type uint8.");
// Check if a texture has already been created for this image
if(mTexturesToRender.count(inputNr) > 0 && mImageUsed[inputNr] == input)
continue; // If it has already been created, skip it
// If it has not been created, create the texture
OpenCLImageAccess::pointer access = input->getOpenCLImageAccess(ACCESS_READ, device);
cl::Image2D *clImage = access->get2DImage();
// Run kernel to fill the texture
cl::CommandQueue queue = device->getCommandQueue();
if (mTexturesToRender.count(inputNr) > 0) {
// Delete old texture
glDeleteTextures(1, &mTexturesToRender[inputNr]);
mTexturesToRender.erase(inputNr);
glDeleteVertexArrays(1, &mVAO[inputNr]);
mVAO.erase(inputNr);
}
cl::Image2D image;
cl::ImageGL imageGL;
std::vector<cl::Memory> v;
GLuint textureID;
// TODO The GL-CL interop here is causing glClear to not work on AMD systems and therefore disabled
/*
if(DeviceManager::isGLInteropEnabled()) {
// Create OpenGL texture
glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_2D, textureID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, input->getWidth(), input->getHeight(), 0, GL_RGBA, GL_FLOAT, 0);
// Create CL-GL image
imageGL = cl::ImageGL(
device->getContext(),
CL_MEM_READ_WRITE,
//.........这里部分代码省略.........