[效果显示]
将脚部骨骼扫描的CT照片进行的连续读取, 运行结果存为了两个动态gif, 不知道能不能正常显示
[主程序实现]
1 int main(int argc, char* argv[])
2 {
3 // Verify input arguments
4 if ( argc != 2 )
5 {
6 std::cout << "Usage: " << argv[0]
7 << " FolderName" << std::endl;
8 return EXIT_FAILURE;
9 }
10
11 std::string folder = argv[1];
12
13 // Read all the DICOM files in the specified directory.
14 vtkSmartPointer<vtkDICOMImageReader> reader =
15 vtkSmartPointer<vtkDICOMImageReader>::New();
16 reader->SetDirectoryName(folder.c_str());
17 reader->Update();
18
19 // Visualize
20 vtkSmartPointer<vtkImageViewer2> imageViewer =
21 vtkSmartPointer<vtkImageViewer2>::New();
22 imageViewer->SetInputConnection(reader->GetOutputPort());
23
24 // slice status message
25 vtkSmartPointer<vtkTextProperty> sliceTextProp = vtkSmartPointer<vtkTextProperty>::New();
26 sliceTextProp->SetFontFamilyToCourier();
27 sliceTextProp->SetFontSize(20);
28 sliceTextProp->SetVerticalJustificationToBottom();
29 sliceTextProp->SetJustificationToLeft();
30
31 vtkSmartPointer<vtkTextMapper> sliceTextMapper = vtkSmartPointer<vtkTextMapper>::New();
32 std::string msg = StatusMessage::Format(imageViewer->GetSliceMin(), imageViewer->GetSliceMax());
33 sliceTextMapper->SetInput(msg.c_str());
34 sliceTextMapper->SetTextProperty(sliceTextProp);
35
36 vtkSmartPointer<vtkActor2D> sliceTextActor = vtkSmartPointer<vtkActor2D>::New();
37 sliceTextActor->SetMapper(sliceTextMapper);
38 sliceTextActor->SetPosition(15, 10);
39
40 // usage hint message
41 vtkSmartPointer<vtkTextProperty> usageTextProp = vtkSmartPointer<vtkTextProperty>::New();
42 usageTextProp->SetFontFamilyToCourier();
43 usageTextProp->SetFontSize(14);
44 usageTextProp->SetVerticalJustificationToTop();
45 usageTextProp->SetJustificationToLeft();
46
47 vtkSmartPointer<vtkTextMapper> usageTextMapper = vtkSmartPointer<vtkTextMapper>::New();
48 usageTextMapper->SetInput("- Slice with mouse wheel
or Up/Down-Key
- Zoom with pressed right
mouse button while dragging");
49 usageTextMapper->SetTextProperty(usageTextProp);
50
51 vtkSmartPointer<vtkActor2D> usageTextActor = vtkSmartPointer<vtkActor2D>::New();
52 usageTextActor->SetMapper(usageTextMapper);
53 usageTextActor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedDisplay();
54 usageTextActor->GetPositionCoordinate()->SetValue( 0.05, 0.95);
55
56 vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
57 vtkSmartPointer<vtkRenderWindowInteractor>::New();
58
59 vtkSmartPointer<myVtkInteractorStyleImage> myInteractorStyle =
60 vtkSmartPointer<myVtkInteractorStyleImage>::New();
61
62 myInteractorStyle->SetImageViewer(imageViewer);
63 myInteractorStyle->SetStatusMapper(sliceTextMapper);
64
65 imageViewer->SetupInteractor(renderWindowInteractor);
66 renderWindowInteractor->SetInteractorStyle(myInteractorStyle);
67
68 imageViewer->GetRenderer()->AddActor2D(sliceTextActor);
69 imageViewer->GetRenderer()->AddActor2D(usageTextActor);
70
71 imageViewer->Render();
72 imageViewer->GetRenderer()->ResetCamera();
73 imageViewer->Render();
74 renderWindowInteractor->Start();
75 return EXIT_SUCCESS;
76 }