本文整理汇总了C++中image::pointer::getDataType方法的典型用法代码示例。如果您正苦于以下问题:C++ pointer::getDataType方法的具体用法?C++ pointer::getDataType怎么用?C++ pointer::getDataType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类image::pointer
的用法示例。
在下文中一共展示了pointer::getDataType方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: recompileOpenCLCode
void NoneLocalMeans::recompileOpenCLCode(Image::pointer input) {
// Check if there is a need to recompile OpenCL code
if(input->getDimensions() == mDimensionCLCodeCompiledFor &&
input->getDataType() == mTypeCLCodeCompiledFor && !recompile)
return;
recompile = false;
OpenCLDevice::pointer device = getMainDevice();
std::string buildOptions = "";
if(!device->isWritingTo3DTexturesSupported()) {
buildOptions = "-DTYPE=" + getCTypeAsString(mOutputType);
}
buildOptions += " -D WINDOW=";
buildOptions += std::to_string((windowSize-1)/2);
buildOptions += " -D GROUP=";
buildOptions += std::to_string((groupSize-1)/2);
buildOptions += " -D KVERSION=";
buildOptions += std::to_string(k);
buildOptions += " -D EUCLID=";
buildOptions += std::to_string(k);
cl::Program program;
if(input->getDimensions() == 2) {
program = getOpenCLProgram(device, "2D", buildOptions);
} else {
//createOpenCLProgram(std::string(FAST_SOURCE_DIR) + "Algorithms/NoneLocalMeans/NoneLocalMeans3Dgs.cl", "3D");
program = getOpenCLProgram(device, "3D", buildOptions);
}
mKernel = cl::Kernel(program, "noneLocalMeans");
mDimensionCLCodeCompiledFor = input->getDimensions();
mTypeCLCodeCompiledFor = input->getDataType();
}
示例2: recompileOpenCLCode
void SeededRegionGrowing::recompileOpenCLCode(Image::pointer input) {
// Check if there is a need to recompile OpenCL code
if(input->getDimensions() == mDimensionCLCodeCompiledFor &&
input->getDataType() == mTypeCLCodeCompiledFor)
return;
OpenCLDevice::pointer device = getMainDevice();
std::string buildOptions = "";
if(input->getDataType() == TYPE_FLOAT) {
buildOptions = "-DTYPE_FLOAT";
} else if(input->getDataType() == TYPE_INT8 || input->getDataType() == TYPE_INT16) {
buildOptions = "-DTYPE_INT";
} else {
buildOptions = "-DTYPE_UINT";
}
std::string filename;
if(input->getDimensions() == 2) {
filename = "Algorithms/SeededRegionGrowing/SeededRegionGrowing2D.cl";
} else {
filename = "Algorithms/SeededRegionGrowing/SeededRegionGrowing3D.cl";
}
int programNr = device->createProgramFromSource(std::string(FAST_SOURCE_DIR) + filename, buildOptions);
mKernel = cl::Kernel(device->getProgram(programNr), "seededRegionGrowing");
mDimensionCLCodeCompiledFor = input->getDimensions();
mTypeCLCodeCompiledFor = input->getDataType();
}
示例3: setScalarAsFloat
void setScalarAsFloat(T* data, uint position, Image::pointer image, float value, uchar channel) {
Vector3ui size = image->getSize();
if(position >= size.x()*size.y()*size.z())
throw OutOfBoundsException();
uint address = position*image->getNrOfComponents() + channel;
if(image->getDataType() == TYPE_SNORM_INT16) {
data[address] = value * 32767.0f;;
} else if(image->getDataType() == TYPE_UNORM_INT16) {
data[address] = value * 65535.0f;;
} else {
data[address] = value;
}
}
示例4: getScalarAsFloat
float getScalarAsFloat(T* data, uint position, Image::pointer image, uchar channel) {
Vector3ui size = image->getSize();
if(position >= size.x()*size.y()*size.z())
throw OutOfBoundsException();
T value = data[position*image->getNrOfComponents() + channel];
float floatValue;
if(image->getDataType() == TYPE_SNORM_INT16) {
floatValue = std::max(-1.0f, (float)value / 32767.0f);
} else if(image->getDataType() == TYPE_UNORM_INT16) {
floatValue = (float)value / 65535.0f;
} else {
floatValue = value;
}
return floatValue;
}
示例5: createIGTLImageMessage
static igtl::ImageMessage::Pointer createIGTLImageMessage(Image::pointer image) {
// size parameters
int size[3] = {(int)image->getWidth(), (int)image->getHeight(), (int)image->getDepth()}; // image dimension
float spacing[3] = {image->getSpacing().x(), image->getSpacing().y(), image->getSpacing().z()}; // spacing (mm/pixel)
int svoffset[3] = {0, 0, 0}; // sub-volume offset
int scalarType;
size_t totalSize = image->getWidth()*image->getHeight()*image->getDepth()*image->getNrOfChannels();
switch(image->getDataType()) {
case TYPE_UINT8:
scalarType = igtl::ImageMessage::TYPE_UINT8;
totalSize *= sizeof(unsigned char);
break;
case TYPE_INT8:
scalarType = igtl::ImageMessage::TYPE_INT8;
totalSize *= sizeof(char);
break;
case TYPE_UINT16:
scalarType = igtl::ImageMessage::TYPE_UINT16;
totalSize *= sizeof(unsigned short);
break;
case TYPE_INT16:
scalarType = igtl::ImageMessage::TYPE_INT16;
totalSize *= sizeof(short);
break;
case TYPE_FLOAT:
scalarType = igtl::ImageMessage::TYPE_FLOAT32;
totalSize *= sizeof(float);
break;
}
//------------------------------------------------------------
// Create a new IMAGE type message
igtl::ImageMessage::Pointer imgMsg = igtl::ImageMessage::New();
imgMsg->SetDimensions(size);
imgMsg->SetSpacing(spacing);
imgMsg->SetNumComponents(image->getNrOfChannels());
imgMsg->SetScalarType(scalarType);
imgMsg->SetDeviceName("DummyImage");
imgMsg->SetSubVolume(size, svoffset);
imgMsg->AllocateScalars();
ImageAccess::pointer access = image->getImageAccess(ACCESS_READ);
memcpy(imgMsg->GetScalarPointer(), access->get(), totalSize);
return imgMsg;
}
示例6: 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
);
}
}
示例7: 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();
}
示例8: 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);
}
}
示例9: orthogonalSlicing
void ImageSlicer::orthogonalSlicing(Image::pointer input, Image::pointer output) {
OpenCLDevice::pointer device = getMainDevice();
// Determine slice nr and width and height
unsigned int sliceNr;
if(mOrthogonalSliceNr < 0) {
switch(mOrthogonalSlicePlane) {
case PLANE_X:
sliceNr = input->getWidth()/2;
break;
case PLANE_Y:
sliceNr = input->getHeight()/2;
break;
case PLANE_Z:
sliceNr = input->getDepth()/2;
break;
}
} else {
// Check that mSliceNr is valid
sliceNr = mOrthogonalSliceNr;
switch(mOrthogonalSlicePlane) {
case PLANE_X:
if(sliceNr >= input->getWidth())
sliceNr = input->getWidth()-1;
break;
case PLANE_Y:
if(sliceNr >= input->getHeight())
sliceNr = input->getHeight()-1;
break;
case PLANE_Z:
if(sliceNr >= input->getDepth())
sliceNr = input->getDepth()-1;
break;
}
}
unsigned int slicePlaneNr, width, height;
Vector3f spacing(0,0,0);
switch(mOrthogonalSlicePlane) {
case PLANE_X:
slicePlaneNr = 0;
width = input->getHeight();
height = input->getDepth();
spacing.x() = input->getSpacing().y();
spacing.y() = input->getSpacing().z();
break;
case PLANE_Y:
slicePlaneNr = 1;
width = input->getWidth();
height = input->getDepth();
spacing.x() = input->getSpacing().x();
spacing.y() = input->getSpacing().z();
break;
case PLANE_Z:
slicePlaneNr = 2;
width = input->getWidth();
height = input->getHeight();
spacing.x() = input->getSpacing().x();
spacing.y() = input->getSpacing().y();
break;
}
output->create(width, height, input->getDataType(), input->getNrOfComponents());
output->setSpacing(spacing);
OpenCLImageAccess::pointer inputAccess = input->getOpenCLImageAccess(ACCESS_READ, device);
OpenCLImageAccess::pointer outputAccess = output->getOpenCLImageAccess(ACCESS_READ_WRITE, device);
cl::CommandQueue queue = device->getCommandQueue();
cl::Program program = getOpenCLProgram(device);
cl::Kernel kernel(program, "orthogonalSlicing");
kernel.setArg(0, *inputAccess->get3DImage());
kernel.setArg(1, *outputAccess->get2DImage());
kernel.setArg(2, sliceNr);
kernel.setArg(3, slicePlaneNr);
queue.enqueueNDRangeKernel(
kernel,
cl::NullRange,
cl::NDRange(width, height),
cl::NullRange
);
// TODO set scene graph transformation
}
示例10: 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);
}
示例11: 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,
//.........这里部分代码省略.........