一杯清酒邀明月
天下本无事,庸人扰之而烦耳。

VTKstd在VTK7版本中不再使用,用std替代

VTK7中需添加命名空间

using namespace std;
std::string fileStr(fileName);
 1 #include "vtkAutoInit.h" 
 2 VTK_MODULE_INIT(vtkRenderingOpenGL2); // VTK was built with vtkRenderingOpenGL2
 3 VTK_MODULE_INIT(vtkInteractionStyle);
 4 #include <vtkSmartPointer.h>
 5 #include <vtkJPEGReader.h>
 6 #include <vtkImageViewer2.h>
 7 #include <vtkRenderWindowInteractor.h>
 8 #include <vtkInteractorStyleImage.h>
 9 #include <vtkRenderer.h>
10 #include <vtkStringArray.h>
11 #include <vtkRenderWindow.h>
12  
13 using namespace std;
14 int main()
15 {
16     //生成图像序列的文件名数组
17     vtkSmartPointer< vtkStringArray > fileArray = vtkSmartPointer< vtkStringArray >::New();
18     char fileName[128];
19     for (int i = 1; i < 100; i++)
20     {
21         sprintf(fileName, "G:/First_year_graduate/VTK/VTKexamle/VTKtest1/Debug/data/Head/head%03d.jpg", i);
22          std::string fileStr(fileName);
23         fileArray->InsertNextValue(fileStr);
24     }
25  
26     //读取JPG序列图像
27     vtkSmartPointer<vtkJPEGReader> reader = vtkSmartPointer<vtkJPEGReader>::New();
28     reader->SetFileNames(fileArray);
29  
30     vtkSmartPointer<vtkInteractorStyleImage> style = vtkSmartPointer<vtkInteractorStyleImage>::New();
31  
32     //显示读取的JPG图像
33     vtkSmartPointer<vtkImageViewer2> imageViewer = vtkSmartPointer<vtkImageViewer2>::New();
34     imageViewer->SetInputConnection(reader->GetOutputPort());
35  
36     vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
37         vtkSmartPointer<vtkRenderWindowInteractor>::New();
38     renderWindowInteractor->SetInteractorStyle(style);
39  
40     imageViewer->SetSlice(50); //默认显示第50个切片(即第50层)
41     imageViewer->SetSliceOrientationToXY();
42     //imageViewer->SetSliceOrientationToYZ();
43     //imageViewer->SetSliceOrientationToXZ();
44     imageViewer->SetupInteractor(renderWindowInteractor);
45     imageViewer->Render();
46  
47     imageViewer->GetRenderer()->SetBackground(1.0, 1.0, 1.0);
48     imageViewer->SetSize(640, 480);
49     imageViewer->GetRenderWindow()->SetWindowName("ReadSeriesImages1");
50  
51     renderWindowInteractor->Start();
52  
53     return EXIT_SUCCESS;
54 }

 

 

posted on 2020-11-03 14:56  一杯清酒邀明月  阅读(530)  评论(0编辑  收藏  举报