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

 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 <vtkImageConvolve.h>
 8 #include <vtkImageMandelbrotSource.h>
 9 #include <vtkRenderWindow.h>
10 #include <vtkRenderWindowInteractor.h>
11 #include <vtkInteractorStyleImage.h>
12 #include <vtkRenderer.h>
13 #include <vtkImageActor.h>
14 #include <vtkImageCast.h>
15 #include <vtkJPEGReader.h>
16 #include <vtkImageShiftScale.h>
17 
18 //测试图像:../data/lena-gray.jpg
19 int main(int argc, char* argv[])
20 {
21     vtkSmartPointer<vtkJPEGReader> reader =
22         vtkSmartPointer<vtkJPEGReader>::New();
23     reader->SetFileName("lena-gray.jpg");
24     reader->Update();
25 
26     vtkSmartPointer<vtkImageCast> originalCastFilter =
27         vtkSmartPointer<vtkImageCast>::New();
28     originalCastFilter->SetInputConnection(reader->GetOutputPort());
29     originalCastFilter->SetOutputScalarTypeToFloat();
30     originalCastFilter->Update();
31 
32     vtkSmartPointer<vtkImageConvolve> convolveFilter =
33         vtkSmartPointer<vtkImageConvolve>::New();
34     convolveFilter->SetInputConnection(originalCastFilter->GetOutputPort());
35 
36     double kernel[25] = {0.04,0.04,0.04,0.04,0.04,
37         0.04,0.04,0.04,0.04,0.04,
38         0.04,0.04,0.04,0.04,0.04,
39         0.04,0.04,0.04,0.04,0.04,
40         0.04,0.04,0.04,0.04,0.04 };
41     convolveFilter->SetKernel5x5(kernel);
42     convolveFilter->Update();
43 
44     vtkSmartPointer<vtkImageCast> convCastFilter = 
45         vtkSmartPointer<vtkImageCast>::New();
46     convCastFilter->SetInputData(convolveFilter->GetOutput());
47     convCastFilter->SetOutputScalarTypeToUnsignedChar();
48     convCastFilter->Update();
49 
50     vtkSmartPointer<vtkImageActor> originalActor =
51         vtkSmartPointer<vtkImageActor>::New();
52     originalActor->SetInputData(reader->GetOutput());
53 
54     vtkSmartPointer<vtkImageActor> convolvedActor =
55         vtkSmartPointer<vtkImageActor>::New();
56     convolvedActor->SetInputData(convCastFilter->GetOutput());
57 
58     double leftViewport[4] = {0.0, 0.0, 0.5, 1.0};
59     double rightViewport[4] = {0.5, 0.0, 1.0, 1.0};
60 
61     vtkSmartPointer<vtkRenderer> originalRenderer =
62         vtkSmartPointer<vtkRenderer>::New();
63     originalRenderer->SetViewport(leftViewport);
64     originalRenderer->AddActor(originalActor);
65     originalRenderer->SetBackground(1.0, 1.0, 1.0);
66     originalRenderer->ResetCamera();
67 
68     vtkSmartPointer<vtkRenderer> convolvedRenderer =
69         vtkSmartPointer<vtkRenderer>::New();
70     convolvedRenderer->SetViewport(rightViewport);
71     convolvedRenderer->AddActor(convolvedActor);
72     convolvedRenderer->SetBackground(1.0, 1.0, 1.0);
73     convolvedRenderer->ResetCamera();
74 
75     vtkSmartPointer<vtkRenderWindow> renderWindow =
76         vtkSmartPointer<vtkRenderWindow>::New();;
77     renderWindow->AddRenderer(originalRenderer);
78     renderWindow->AddRenderer(convolvedRenderer);
79     renderWindow->SetSize(640, 320);
80     renderWindow->Render();
81     renderWindow->SetWindowName("MeanFilterExample");
82 
83     vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
84         vtkSmartPointer<vtkRenderWindowInteractor>::New();
85     vtkSmartPointer<vtkInteractorStyleImage> style =
86         vtkSmartPointer<vtkInteractorStyleImage>::New();
87 
88     renderWindowInteractor->SetInteractorStyle(style);
89     renderWindowInteractor->SetRenderWindow(renderWindow);
90     renderWindowInteractor->Initialize();
91     renderWindowInteractor->Start();
92 
93     return EXIT_SUCCESS;
94 }

posted on 2023-08-15 11:49  一杯清酒邀明月  阅读(42)  评论(0编辑  收藏  举报