本文整理汇总了C++中image::pointer::create方法的典型用法代码示例。如果您正苦于以下问题:C++ pointer::create方法的具体用法?C++ pointer::create怎么用?C++ pointer::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类image::pointer
的用法示例。
在下文中一共展示了pointer::create方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: execute
void ImageImporter::execute() {
if (mFilename == "")
throw Exception("No filename was supplied to the ImageImporter");
uchar* convertedPixelData;
// Load image from disk using Qt
QImage image;
reportInfo() << "Trying to load image..." << Reporter::end();
if(!image.load(mFilename.c_str())) {
throw FileNotFoundException(mFilename);
}
reportInfo() << "Loaded image with size " << image.width() << " " << image.height() << Reporter::end();
QImage::Format format;
if(mGrayscale) {
format = QImage::Format_Grayscale8;
} else {
format = QImage::Format_RGB888;
}
QImage convertedImage = image.convertToFormat(format);
// Get pixel data
convertedPixelData = convertedImage.bits();
Image::pointer output = getOutputData<Image>();
std::cout << "image info" << std::endl;
std::cout << convertedImage.width() << std::endl;
std::cout << convertedImage.depth() << std::endl;
std::cout << convertedImage.bytesPerLine() << std::endl;
if(convertedImage.width()*convertedImage.depth()/8 != convertedImage.bytesPerLine()) {
const int bytesPerPixel = (convertedImage.depth()/8);
std::unique_ptr<uchar[]> fixedPixelData = std::make_unique<uchar[]>(image.width()*image.height());
// Misalignment
for(int scanline = 0; scanline < image.height(); ++scanline) {
std::memcpy(
&fixedPixelData[scanline*image.width()*bytesPerPixel],
&convertedPixelData[scanline*convertedImage.bytesPerLine()],
image.width()*bytesPerPixel
);
}
output->create(
image.width(),
image.height(),
TYPE_UINT8,
mGrayscale ? 1 : 3,
getMainDevice(),
fixedPixelData.get()
);
} else {
output->create(
image.width(),
image.height(),
TYPE_UINT8,
mGrayscale ? 1 : 3,
getMainDevice(),
convertedPixelData
);
}
}
示例2: transferVTKDataToFAST
void transferVTKDataToFAST(vtkImageData* image, Image::pointer output) {
void* data;
DataType type;
switch(image->GetScalarType()) {
case VTK_FLOAT:
data = readVTKData<float>(image);
type = TYPE_FLOAT;
break;
case VTK_CHAR:
case VTK_SIGNED_CHAR:
data = readVTKData<char>(image);
type = TYPE_INT8;
break;
case VTK_UNSIGNED_CHAR:
data = readVTKData<uchar>(image);
type = TYPE_UINT8;
break;
case VTK_SHORT:
data = readVTKData<short>(image);
type = TYPE_INT16;
break;
case VTK_UNSIGNED_SHORT:
data = readVTKData<ushort>(image);
type = TYPE_UINT16;
break;
default:
throw Exception("VTK image of unsupported type was supplied to the VTKImageImporter");
break;
}
int * size = image->GetDimensions();
if(image->GetDataDimension() == 2) {
output->create(size[0]-1, size[1]-1,type,1,Host::getInstance(),data);
} else if(image->GetDataDimension() == 3) {
output->create(size[0]-1, size[1]-1,size[2]-1,type,1,Host::getInstance(),data);
} else {
throw Exception("Wrong number of dimensions in VTK image");
}
deleteArray(data, type);
}
示例3: 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;
OpenCLDevice::pointer device = getMainDevice();
recompile = false;
std::string buildOptions = "";
const bool writingTo3DTextures = device->getDevice().getInfo<CL_DEVICE_EXTENSIONS>().find("cl_khr_3d_image_writes") != std::string::npos;
if (!writingTo3DTextures) {
switch (mOutputType) {
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;
}
}
buildOptions += " -D WINDOW=";
buildOptions += std::to_string((windowSize-1)/2);
buildOptions += " -D GROUP=";
buildOptions += std::to_string((groupSize-1)/2);
std::string filename;
//might have to seperate color vs gray here, for better runtime
if (input->getDimensions() == 2) {
if(k == 0){
filename = "Algorithms/NoneLocalMeans/NoneLocalMeans2Dconstant.cl";
}else if(k == 1){
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
//.........这里部分代码省略.........
示例4: execute
//.........这里部分代码省略.........
if(values.size() == 2) {
spacing[2] = 1;
} else {
spacing[2] = boost::lexical_cast<float>(values[2]);
}
}
} else if(key == "CenterOfRotation") {
//reportInfo() << "WARNING: CenterOfRotation in Metaimage file ignored" << Reporter::end;
std::vector<std::string> values;
boost::split(values, value, boost::is_any_of(" "));
// Remove any empty values:
values.erase(std::remove(values.begin(), values.end(), ""), values.end());
if(imageIs3D) {
if(values.size() != 3)
throw Exception("CenterOfRotation in MetaImage file did not contain 3 numbers");
centerOfRotation[0] = boost::lexical_cast<float>(values[0]);
centerOfRotation[1] = boost::lexical_cast<float>(values[1]);
centerOfRotation[2] = boost::lexical_cast<float>(values[2]);
} else {
if(values.size() != 2 && values.size() != 3)
throw Exception("CenterOfRotation in MetaImage file did not contain 2 or 3 numbers");
centerOfRotation[0] = boost::lexical_cast<float>(values[0]);
centerOfRotation[1] = boost::lexical_cast<float>(values[1]);
if(values.size() == 2) {
centerOfRotation[2] = 0;
} else {
centerOfRotation[2] = boost::lexical_cast<float>(values[2]);
}
}
} else if(key == "Offset" || key == "Origin" || key == "Position") {
std::vector<std::string> values;
boost::split(values, value, boost::is_any_of(" "));
// Remove any empty values:
values.erase(std::remove(values.begin(), values.end(), ""), values.end());
if(values.size() != 3)
throw Exception("Offset/Origin/Position in MetaImage file did not contain 3 numbers");
offset[0] = boost::lexical_cast<float>(values[0].c_str());
offset[1] = boost::lexical_cast<float>(values[1].c_str());
offset[2] = boost::lexical_cast<float>(values[2].c_str());
} else if(key == "TransformMatrix" || key == "Rotation" || key == "Orientation") {
std::vector<std::string> values;
boost::split(values, value, boost::is_any_of(" "));
// Remove any empty values:
values.erase(std::remove(values.begin(), values.end(), ""), values.end());
if(values.size() != 9)
throw Exception("Encountered a transform/orientation/rotation matrix with incorrect number of elements in the MetaImageImporter");
for(unsigned int i = 0; i < 3; i++) {
for(unsigned int j = 0; j < 3; j++) {
transformMatrix(j,i) = boost::lexical_cast<float>(values[j+i*3].c_str());
}}
}
} while(!mhdFile.eof());
mhdFile.close();
if(!sizeFound || !rawFilenameFound || !typeFound || !dimensionsFound)
throw Exception("Error reading the mhd file", __LINE__, __FILE__);
void * data;
DataType type;
if(typeName == "MET_SHORT") {
type = TYPE_INT16;
data = readRawData<short>(rawFilename, width, height, depth, nrOfComponents, isCompressed, compressedDataSize);
} else if(typeName == "MET_USHORT") {
type = TYPE_UINT16;
data = readRawData<unsigned short>(rawFilename, width, height, depth, nrOfComponents, isCompressed, compressedDataSize);
} else if(typeName == "MET_CHAR") {
type = TYPE_INT8;
data = readRawData<char>(rawFilename, width, height, depth, nrOfComponents, isCompressed, compressedDataSize);
} else if(typeName == "MET_UCHAR") {
type = TYPE_UINT8;
data = readRawData<unsigned char>(rawFilename, width, height, depth, nrOfComponents, isCompressed, compressedDataSize);
} else if(typeName == "MET_FLOAT") {
type = TYPE_FLOAT;
data = readRawData<float>(rawFilename, width, height, depth, nrOfComponents, isCompressed, compressedDataSize);
}
if(imageIs3D) {
output->create(width,height,depth,type,nrOfComponents,getMainDevice(),data);
} else {
output->create(width,height,type,nrOfComponents,getMainDevice(),data);
}
output->setSpacing(spacing);
// Create transformation
AffineTransformation::pointer T = AffineTransformation::New();
T->translation() = offset;
T->linear() = transformMatrix;
output->getSceneGraphNode()->setTransformation(T);
// Clean up
deleteArray(data, type);
}
示例5: 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
}