欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

VTK读取单张dicom

程序员文章站 2022-03-31 23:05:01
...
#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 c++