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

 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 <vtkImageGaussianSmooth.h>
 8 #include <vtkRenderWindow.h>
 9 #include <vtkRenderWindowInteractor.h>
10 #include <vtkInteractorStyleImage.h>
11 #include <vtkRenderer.h>
12 #include <vtkImageActor.h>
13 #include <vtkImageEllipsoidSource.h>
14 #include <vtkImageCast.h>
15 #include <vtkJPEGReader.h>
16 
17 //测试图像:../data/lena-gray.jpg
18 int main(int argc, char* argv[])
19 {
20     vtkSmartPointer<vtkJPEGReader> reader =
21         vtkSmartPointer<vtkJPEGReader>::New();
22     reader->SetFileName("lena-gray.jpg");
23     reader->Update();
24 
25     vtkSmartPointer<vtkImageGaussianSmooth> gaussianSmoothFilter = 
26         vtkSmartPointer<vtkImageGaussianSmooth>::New();
27     gaussianSmoothFilter->SetInputConnection(reader->GetOutputPort());
28     gaussianSmoothFilter->SetDimensionality(2);
29     gaussianSmoothFilter->SetRadiusFactor(5);
30     gaussianSmoothFilter->SetStandardDeviation(3);
31     gaussianSmoothFilter->Update();
32 
33     vtkSmartPointer<vtkImageActor> originalActor =
34         vtkSmartPointer<vtkImageActor>::New();
35     originalActor->SetInputData(reader->GetOutput());
36 
37     vtkSmartPointer<vtkImageActor> smoothedActor =
38         vtkSmartPointer<vtkImageActor>::New();
39     smoothedActor->SetInputData(gaussianSmoothFilter->GetOutput());
40 
41     double originalViewport[4] = {0.0, 0.0, 0.5, 1.0};
42     double smoothedViewport[4] = {0.5, 0.0, 1.0, 1.0};
43 
44     vtkSmartPointer<vtkRenderer> originalRenderer =
45         vtkSmartPointer<vtkRenderer>::New();
46     originalRenderer->SetViewport(originalViewport);
47     originalRenderer->AddActor(originalActor);
48     originalRenderer->ResetCamera();
49     originalRenderer->SetBackground(1.0, 1.0, 1.0);
50 
51     vtkSmartPointer<vtkRenderer> gradientMagnitudeRenderer =
52         vtkSmartPointer<vtkRenderer>::New();
53     gradientMagnitudeRenderer->SetViewport(smoothedViewport);
54     gradientMagnitudeRenderer->AddActor(smoothedActor);
55     gradientMagnitudeRenderer->ResetCamera();
56     gradientMagnitudeRenderer->SetBackground(1.0, 1.0, 1.0);
57 
58     vtkSmartPointer<vtkRenderWindow> renderWindow =
59         vtkSmartPointer<vtkRenderWindow>::New();
60     renderWindow->AddRenderer(originalRenderer);
61     renderWindow->AddRenderer(gradientMagnitudeRenderer);
62     renderWindow->SetSize(640, 320);
63     renderWindow->Render();
64     renderWindow->SetWindowName("GaussianFilterExample");
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 }

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