ITK 讀取Dicom序列 +VTK重建 +VTK顯示

https://blog.csdn.net/qq_35007834/article/details/88569821app

using ReaderType = itk::ImageSeriesReader< ImageType >;
	using ImageIOType = itk::GDCMImageIO;
	ReaderType::Pointer reader = ReaderType::New();
	ImageIOType::Pointer dicomIO = ImageIOType::New();
	reader->SetImageIO(dicomIO);
	//獲取讀取序列名稱
	using NamesGeneratorType = itk::GDCMSeriesFileNames;
	NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();
	nameGenerator->SetUseSeriesDetails(true);
	nameGenerator->SetDirectory("/Users/mac/Desktop/個人文件/血管分割項目/CT數據/CT掃描數據");
	using SeriesIdContainer = std::vector< std::string >;
	const SeriesIdContainer & seriesUID = nameGenerator->GetSeriesUIDs();
	auto seriesItr = seriesUID.begin();
	auto seriesEnd = seriesUID.end();
	using FileNamesContainer = std::vector< std::string >;
	FileNamesContainer fileNames;
	std::string seriesIdentifier;
	while (seriesItr != seriesEnd)
	{
		seriesIdentifier = seriesItr->c_str();
		fileNames = nameGenerator->GetFileNames(seriesIdentifier);
		++seriesItr;
	}
        //讀取序列
	reader->SetFileNames(fileNames);
	try
	{
		reader->Update();
	}
	catch (itk::ExceptionObject &ex)
	{
		std::cout << ex << std::endl;
		return EXIT_FAILURE;
	}
	ImageType::SizeType imgSize = reader->GetOutput()->GetLargestPossibleRegion().GetSize();
	cout << "read done!Original size: " << imgSize << endl;

	typedef itk::ImageToVTKImageFilter< ImageType> itkTovtkFilterType;
	itkTovtkFilterType::Pointer itkTovtkImageFilter = itkTovtkFilterType::New();
	itkTovtkImageFilter->SetInput(reader->GetOutput());
	itkTovtkImageFilter->Update();

	vtkSmartPointer<vtkMarchingCubes> vesselExtractor = vtkMarchingCubes::New();
	vesselExtractor->SetInputData(itkTovtkImageFilter->GetOutput());
	vesselExtractor->SetNumberOfContours(10);
	vesselExtractor->SetValue(0, 1);   //輪廓

									   //將提取的等值面拼接成連續的
	vtkSmartPointer<vtkStripper> vesselStripper = vtkStripper::New();                           //創建三角帶對象
	vesselStripper->SetInputConnection(vesselExtractor->GetOutputPort());


	vtkSmartPointer<vtkPolyDataMapper>  vesselMapper = vtkPolyDataMapper::New();     //創建一個數據映射對象
	vesselMapper->SetInputConnection(vesselStripper->GetOutputPort());                     //將三角帶映射爲幾何數據
	vesselMapper->SetScalarRange(0, 7);

	//對象和對象屬性等設置
	vtkSmartPointer<vtkActor> vessel = vtkActor::New();
	vessel->SetMapper(vesselMapper);
	vessel->GetProperty()->SetColor(0, 0, 1);

	// A renderer and render window
	vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
	vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
	renderWindow->AddRenderer(renderer);
	renderWindow->SetSize(1000, 1000);
	renderer->AddActor(vessel);
	// An interactor
	vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
		vtkSmartPointer<vtkRenderWindowInteractor>::New();
	renderWindowInteractor->SetRenderWindow(renderWindow);
	renderWindow->Render();
	renderWindow->SetWindowName(「啦啦啦,我是賣報的小行家」);//這一句必定是在render()後面,不然無效,爲何沒人告訴我
	renderWindowInteractor->Initialize();
	renderWindow->Render();
	renderWindowInteractor->Start();
	return 0;
相關文章
相關標籤/搜索