vtk读取raw格式vs2010编译成功,但是运行出错,求大神帮忙!
vtk吧
全部回复
仅看楼主
level 2
Career1209 楼主
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL);
#include "vtkDICOMImageReader.h"
#include "vtkPiecewiseFunction.h"
#include "vtkColorTransferFunction.h"
#include "vtkVolumeProperty.h"
#include "vtkVolumeRayCastCompositeFunction.h"
#include "vtkVolumeRayCastMapper.h"
#include "vtkVolume.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkImageCast.h"
#include "vtkInteractorStyleTrackballCamera.h"
#include "vtkBMPReader.h"
#include "vtkVolume16Reader.h"
#include "vtkPNGReader.h"
#include "vtkJPEGReader.h"
#include "vtkRayCastImageDisplayHelper.h"
//#pragma comment(lib,"oraocci11.lib")
//#pragma comment (lib, "vtkCommon.lib")
void main()
{
vtkRenderer *ren = vtkRenderer::New();//设置绘制者(绘制对象指针)
vtkRenderWindow *renWin = vtkRenderWindow::New();//设置绘制窗口
renWin->AddRenderer(ren);//将绘制者加入绘制窗口
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();//设置绘制交互操作窗口的
iren->SetRenderWindow(renWin);//将绘制窗口添加到交互窗口
vtkInteractorStyleTrackballCamera *style = vtkInteractorStyleTrackballCamera::New();//交互摄像机
iren->SetInteractorStyle(style);//style为交互模式
//raw 图片
vtkImageReader *reader = vtkImageReader::New();
reader->SetFileName("F:\\vs 练习\\readraw\\Debug\\CTData128_69.raw");
reader->SetFileDimensionality(3);//设置显示图像的维数
reader->SetDataScalarType(VTK_UNSIGNED_CHAR);//VTK_UNSIGNED_short将数据转换为unsigned char型
reader->SetDataExtent(0,64,0,64,0,64);//图片属性图片像素256x256,最后两参数表示有124张图
reader->SetDataSpacing (0.9,0.9,0.9); //设置像素间间距
reader->SetDataOrigin(0.0, 0.0, 0.0);//设置基准点,(一般没有用)做虚拟切片时可能会用的上
reader->Update();
vtkImageCast *readerImageCast = vtkImageCast::New();//数据类型转换
readerImageCast->SetInputConnection(reader->GetOutputPort());
readerImageCast->SetOutputScalarTypeToUnsignedShort ();
readerImageCast->ClampOverflowOn();//阀值
//reader->Delete();
//设置不透明度传递函数//该函数确定各体绘像素或单位长度值的不透明度
vtkPiecewiseFunction *opacityTransferFunction = vtkPiecewiseFunction::New();//一维分段函数变换
opacityTransferFunction->AddPoint(20, 0.0);
opacityTransferFunction->AddPoint(255, 0.2);
//设置颜色传递函数//该函数确定体绘像素的颜色值或者灰度值
vtkColorTransferFunction *colorTransferFunction = vtkColorTransferFunction::New();
colorTransferFunction->AddRGBPoint(0.0, 0.0, 0.5, 0.0);//添加色彩点(第一个参数索引)
colorTransferFunction->AddRGBPoint(60.0, 1.0, 0.0, 0.0);
colorTransferFunction->AddRGBPoint(128.0, 0.2, 0.1, 0.9);
colorTransferFunction->AddRGBPoint(196.0, 0.27, 0.21, 0.1);
colorTransferFunction->AddRGBPoint(255.0, 0.8, 0.8, 0.8);
vtkVolumeProperty *volumeProperty = vtkVolumeProperty::New();
//设定一个体绘容器的属性
volumeProperty->SetColor(colorTransferFunction);//设置颜色
volumeProperty->SetScalarOpacity(opacityTransferFunction);//不透明度
volumeProperty->ShadeOn();//影阴
volumeProperty->SetInterpolationTypeToLinear();//直线与样条插值之间逐发函数
volumeProperty->SetAmbient(0.2);//环境光系数
volumeProperty->SetDiffuse(0.9);//漫反射
volumeProperty->SetSpecular(0.2);//高光系数
volumeProperty->SetSpecularPower(10); //高光强度
//定义光线投射方法为MIP体绘制方法,MIP为体绘制经典算法
// vtkVolumeRayCastMIPFunction*mipRaycastFunction = vtkVolumeRayCastMIPFunction::New();
// mipRaycastFunction->SetMaximizeMethodToOpacity();
vtkVolumeRayCastCompositeFunction *compositeFunction = vtkVolumeRayCastCompositeFunction::New();
//运行沿着光线合成
//定义绘制者
vtkVolumeRayCastMapper *volumeMapper = vtkVolumeRayCastMapper::New(); //体绘制器
volumeMapper->SetVolumeRayCastFunction(compositeFunction); //载入绘制方法
volumeMapper->SetInputConnection(readerImageCast->GetOutputPort());//图像数据输入
volumeMapper->SetNumberOfThreads(3);
//定义Volume
vtkVolume *volume = vtkVolume::New();//表示透示图中的一组三维数据
volume->SetMapper(volumeMapper);
volume->SetProperty(volumeProperty);//设置体属性
ren->AddVolume(volume);//将Volume装载到绘制类中
ren->SetBackground(1, 1, 1);
renWin->SetSize(600, 600);//设置背景颜色和绘制窗口大小
renWin->Render();////窗口进行绘制
iren->Initialize();
iren->Start();//初始化并进行交互绘制
ren->ResetCameraClippingRange ();
volumeMapper->Delete();//释放类存
readerImageCast->Delete();
iren->Delete();
ren->Delete();
renWin->Delete();
opacityTransferFunction->Delete();
volumeProperty->Delete();
compositeFunction->Delete();
volume->Delete();
colorTransferFunction->Delete();
}
2016年06月01日 01点06分 1
level 2
Career1209 楼主
编译后出现了无法解析:
1>readraw.obj : error LNK2019: 无法解析的外部符号 "void __cdecl vtkRenderingFreeTypeOpenGL_AutoInit_Construct(void)" (?vtkRenderingFreeTypeOpenGL_AutoInit_Construct@@YAXXZ),该符号在函数 "public: __thiscall vtkRenderingCore_AutoInit::vtkRenderingCore_AutoInit(void)" (??0vtkRenderingCore_AutoInit@@QAE@XZ) 中被引用
1>readraw.obj : error LNK2019: 无法解析的外部符号 "void __cdecl vtkRenderingFreeTypeOpenGL_AutoInit_Destruct(void)" (?vtkRenderingFreeTypeOpenGL_AutoInit_Destruct@@YAXXZ),该符号在函数 "public: __thiscall vtkRenderingCore_AutoInit::~vtkRenderingCore_AutoInit(void)" (??1vtkRenderingCore_AutoInit@@QAE@XZ) 中被引用
1>F:\vs 练习\readraw\Debug\readraw.exe : fatal error LNK1120: 2 个无法解析的外部命令
2016年06月01日 13点06分 5
你这明显是缺少lib库~把VTK的lib都一个一个加进去
2016年06月02日 00点06分
@rabbitbride vtk所有的库都加进去了,但是还是出现无法解析的两个外部命令,我用vs2010编译,vtk6.3.0,前面两句是不是不能换成#define
2016年06月02日 02点06分
@Career1209 @三生草 都替你编译过了~
2016年06月02日 09点06分
真的要换版本吗[泪]
2016年06月02日 09点06分
level 2
Career1209 楼主
/*******************************************************************************
Simple VTK Example
A very simple VTK example - a raw 2D datafile is read
it's magnified by a factor of 3 and then it's displayed on a window.
The pipeline:
vtkImageReader->vtkImageMagnify->vtkRenderWindow
The image file is a raw file of 64 rows * 64 columns. The values are
2 byte (short int) long.
It's a greyscale dataset (NumberOfScalrComponents = 1)
*******************************************************************************/
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL);
//#include <vtkAutoInit.h>
//VTK_MODULE_INIT(vtkInteractionStyle);
#include "vtkImageReader.h"
#include "vtkImageViewer.h"
#include "vtkImageMagnify.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkAlgorithm.h"
#define IMG_FILE "F:\\vs 练习\\rawraw\\Debug\\Solid Box_64_64_8bits.raw" //F:\vs 练习\rawraw\Debug\Solid Box_64_64_8bits.raw
//C:data.raw
int main (void)
{
vtkImageReader *imgReader = vtkImageReader::New();
imgReader->SetFileDimensionality(3);
imgReader->SetFileName(IMG_FILE);
imgReader->SetNumberOfScalarComponents(1);
imgReader->SetDataExtent(0,511, 0,511, 0,0);
imgReader->Update();
vtkImageMagnify *imgMagnify = vtkImageMagnify::New();
imgMagnify->SetInputConnection(imgReader->GetOutputPort());
imgMagnify->SetMagnificationFactors(3, 3, 3);
vtkImageViewer* imgViewer = vtkImageViewer::New();
imgViewer->SetInputConnection(imgMagnify->GetOutputPort());
vtkRenderWindow *renWindow = vtkRenderWindow::New();
renWindow->AddRenderer(imgViewer->GetRenderer());
renWindow->SetSize(64*3, 64*3);
vtkRenderWindowInteractor *renWindowInteractor = vtkRenderWindowInteractor::New();
renWindowInteractor->SetRenderWindow(renWindow);
renWindowInteractor->Initialize();
renWindowInteractor->Start();
return 0;
}
2016年06月02日 10点06分 6
从文件名来猜是64*64的数据,如果是这样那extent错了
2016年06月02日 13点06分
@三生草 不知道怎么回事,老师给的数据上面那样标,刚开始以为是64*64呢,后来用ps看了一下图片的像素是512*512,通道1,8位的
2016年06月02日 13点06分
@三生草 DataExtent最后一个数据位深0 0,那样位深为1,不知道是多少,位深参数改变会出现error
2016年06月02日 13点06分
@Career1209 建议找其他通用数据试试
2016年06月03日 01点06分
1