1 #include "vtkAutoInit.h" 2 VTK_MODULE_INIT(vtkRenderingOpenGL2); 3 VTK_MODULE_INIT(vtkInteractionStyle); 4 5 #include <vtkSmartPointer.h> 6 #include <vtkImageViewer2.h> 7 #include <vtkRenderWindow.h> 8 #include <vtkRenderWindowInteractor.h> 9 #include <vtkRenderer.h> 10 #include <vtkMetaImageReader.h>//mhd类图像处理类 11 12 //测试图像:../data/brain.mhd 13 int main(int argc, char* argv[]) 14 { 15 vtkSmartPointer<vtkMetaImageReader> reader = 16 vtkSmartPointer<vtkMetaImageReader>::New(); 17 //注意:mhd和raw文件要放在同一个文件目录 18 reader->SetFileName("C:\\Users\\Administrator\\Desktop\\VTK2\\hellovtk\\vtk_图像处理学习\\第五章_图像处理\\data\\brain.mhd"); 19 reader->Update(); 20 21 vtkSmartPointer<vtkImageViewer2> imageViewer = 22 vtkSmartPointer<vtkImageViewer2>::New(); 23 imageViewer->SetInputData(reader->GetOutput()); 24 25 vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = 26 vtkSmartPointer<vtkRenderWindowInteractor>::New(); 27 imageViewer->SetupInteractor(renderWindowInteractor); 28 29 imageViewer->SetColorLevel(500);//设置窗位为500 30 imageViewer->SetColorWindow(2000);//设置窗宽为2000 31 imageViewer->SetSlice(40);//设置切片索引 32 imageViewer->SetSliceOrientationToXY();//设置切片方向 33 imageViewer->Render(); 34 35 imageViewer->GetRenderer()->SetBackground(1.0, 1.0, 1.0); 36 imageViewer->SetSize(640, 480); 37 imageViewer->GetRenderWindow()->SetWindowName("DisplayImageExample"); 38 39 renderWindowInteractor->Start(); 40 41 return EXIT_SUCCESS; 42 }标签:20,imageViewer,VTK,reader,vtkSmartPointer,vtkImageViewer2,include,mhd From: https://www.cnblogs.com/ybqjymy/p/17628932.html