ITK 读取Dicom序列 +VTK重建 +VTK显示
https://blog.csdn.net/qq_35007834/article/details/88569821
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;