1 #include "vtkAutoInit.h"
2 VTK_MODULE_INIT(vtkRenderingOpenGL2);
3 VTK_MODULE_INIT(vtkInteractionStyle);
4
5 #include <vtkSmartPointer.h>
6 #include <vtkImageData.h>
7 #include <vtkRenderWindow.h>
8 #include <vtkRenderWindowInteractor.h>
9 #include <vtkInteractorStyleImage.h>
10 #include <vtkRenderer.h>
11 #include <vtkImageActor.h>
12 #include <vtkBMPReader.h>
13 #include <vtkExtractVOI.h>
14
15 //测试图像:../data/lena.bmp
16 int main(int argc, char* argv[])
17 {
18 vtkSmartPointer<vtkBMPReader> reader =
19 vtkSmartPointer<vtkBMPReader>::New();
20 reader->SetFileName ("lena.bmp");
21 reader->Update();
22
23 int dims[3];
24 reader->GetOutput()->GetDimensions(dims);
25
26 vtkSmartPointer<vtkExtractVOI> extractVOI =
27 vtkSmartPointer<vtkExtractVOI>::New();
28 extractVOI->SetInputConnection(reader->GetOutputPort());
29 extractVOI->SetVOI(dims[0]/4.,3.*dims[0]/4.,dims[1]/4.,3.*dims[1]/4., 0, 0);
30 extractVOI->Update();
31
32 vtkSmartPointer<vtkImageActor> originalActor =
33 vtkSmartPointer<vtkImageActor>::New();
34 originalActor->SetInputData(reader->GetOutput());
35
36 vtkSmartPointer<vtkImageActor> voiActor =
37 vtkSmartPointer<vtkImageActor>::New();
38 voiActor->SetInputData(extractVOI->GetOutput());
39
40 double originalViewport[4] = {0.0, 0.0, 0.5, 1.0};
41 double voiviewport[4] = {0.5, 0.0, 1.0, 1.0};
42
43 vtkSmartPointer<vtkRenderer> originalRenderer =
44 vtkSmartPointer<vtkRenderer>::New();
45 originalRenderer->SetViewport(originalViewport);
46 originalRenderer->AddActor(originalActor);
47 originalRenderer->ResetCamera();
48 originalRenderer->SetBackground(1.0, 1.0, 1.0);
49
50 vtkSmartPointer<vtkRenderer> shiftscaleRenderer =
51 vtkSmartPointer<vtkRenderer>::New();
52 shiftscaleRenderer->SetViewport(voiviewport);
53 shiftscaleRenderer->AddActor(voiActor);
54 shiftscaleRenderer->ResetCamera();
55 shiftscaleRenderer->SetBackground(1.0, 1.0, 1.0);
56
57 vtkSmartPointer<vtkRenderWindow> renderWindow =
58 vtkSmartPointer<vtkRenderWindow>::New();
59 renderWindow->AddRenderer(originalRenderer);
60 renderWindow->AddRenderer(shiftscaleRenderer);
61 renderWindow->SetSize(900, 300);
62 renderWindow->Render();
63 renderWindow->SetWindowName("ExtractVOIExample");
64
65
66 vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
67 vtkSmartPointer<vtkRenderWindowInteractor>::New();
68 vtkSmartPointer<vtkInteractorStyleImage> style =
69 vtkSmartPointer<vtkInteractorStyleImage>::New();
70
71 renderWindowInteractor->SetInteractorStyle(style);
72 renderWindowInteractor->SetRenderWindow(renderWindow);
73 renderWindowInteractor->Initialize();
74 renderWindowInteractor->Start();
75
76 return EXIT_SUCCESS;
77 }