#include "stdafx.h"
#include "vtkAutoInit.h"
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);
#include <vtkDICOMImageReader.h>//DCM医学文件读取类
#include <vtkImageViewer.h>//显示2D图像类
#include <vtkRenderWindowInteractor.h>//交互器类
int main()
{
std::string folder = "../DICOM";
int dim[2];
//实例化一个对象dcmReader
vtkDICOMImageReader* dcmReader = vtkDICOMImageReader::New();
dcmReader->SetDirectoryName(folder.c_str());
//dcmReader->SetDirectoryName("D:\\document\\测量相关资料\\DICOM");//读单张切片
//reader->SetDirectoryName("C:\\Users\\Administrator\\Desktop\\VTK2\\hellovtk\\CT_all");//读序列切片
//实例化一个对象dcmViewer
vtkImageViewer* dcmViewer = vtkImageViewer::New();
dcmViewer->SetInputConnection(dcmReader->GetOutputPort());//读取的图像数据输出给显示对象输入
//dcmViewer->SetColorLevel(400);//设置窗位
//dcmViewer->SetColorWindow(800);//设置窗宽
dim[0] = dcmViewer->GetColorLevel();//显示窗位1000
dim[1] = dcmViewer->GetColorWindow();//显示窗宽2000
printf("%d %d", dim[0], dim[1]);
dcmViewer->Render();//显示图像
//加入交互机制
//实例化一个交互器对象interactor
vtkRenderWindowInteractor* interactor = vtkRenderWindowInteractor::New();
dcmViewer->SetupInteractor(interactor);
interactor->Initialize();
interactor->Start();//使交互器处于等待状态
/*getchar();*/
//释放内存
dcmReader->Delete();
dcmViewer->Delete();
interactor->Delete();
return 0;
}
VTK读取单张dicom
最新推荐文章于 2023-07-02 15:22:31 发布