1 #include <vtkAutoInit.h>
2 VTK_MODULE_INIT(vtkRenderingOpenGL);
3
4 #include <vtkSmartPointer.h>
5 #include <vtkJPEGReader.h>
6 #include <vtkImageCast.h>
7 #include <vtkImageAnisotropicDiffusion2D.h>
8 #include <vtkImageActor.h>
9 #include <vtkCamera.h>
10 #include <vtkRenderer.h>
11 #include <vtkRenderWindow.h>
12 #include <vtkRenderWindowInteractor.h>
13 #include <vtkInteractorStyleImage.h>
14
15 int main()
16 {
17 vtkSmartPointer<vtkJPEGReader> reader =
18 vtkSmartPointer<vtkJPEGReader>::New();
19 reader->SetFileName("lena.jpg");
20
21 vtkSmartPointer<vtkImageAnisotropicDiffusion2D> diffusion =
22 vtkSmartPointer<vtkImageAnisotropicDiffusion2D>::New();
23 diffusion->SetInputConnection(reader->GetOutputPort());
24 diffusion->SetNumberOfIterations(100);
25 diffusion->SetDiffusionThreshold(5); //小于该阈值扩散
26 diffusion->Update();
27 /
28 vtkSmartPointer<vtkImageActor> originalActor =
29 vtkSmartPointer<vtkImageActor>::New();
30 originalActor->SetInputData(reader->GetOutput());
31
32 vtkSmartPointer<vtkImageActor> diffusionActor =
33 vtkSmartPointer<vtkImageActor>::New();
34 diffusionActor->SetInputData(diffusion->GetOutput());
35
36 double leftViewport[4] = { 0.0, 0.0, 0.5, 1.0 };
37 double rightViewport[4] = { 0.5, 0.0, 1.0, 1.0 };
38
39 vtkSmartPointer<vtkCamera> camera =
40 vtkSmartPointer<vtkCamera>::New();
41 vtkSmartPointer<vtkRenderer> leftRenderer =
42 vtkSmartPointer<vtkRenderer>::New();
43 leftRenderer->SetViewport(leftViewport);
44 leftRenderer->AddActor(originalActor);
45 leftRenderer->SetBackground(1.0, 0, 0);
46 leftRenderer->SetActiveCamera(camera);
47 leftRenderer->ResetCamera();
48
49 vtkSmartPointer<vtkRenderer> rightRenderer =
50 vtkSmartPointer<vtkRenderer>::New();
51 rightRenderer->SetViewport(rightViewport);
52 rightRenderer->SetBackground(1.0, 1.0, 1.0);
53 rightRenderer->AddActor(diffusionActor);
54 rightRenderer->SetActiveCamera(camera);
55 /
56 vtkSmartPointer<vtkRenderWindow> rw =
57 vtkSmartPointer<vtkRenderWindow>::New();
58 rw->AddRenderer(leftRenderer);
59 rw->AddRenderer(rightRenderer);
60 rw->SetSize(640, 320);
61 rw->SetWindowName("Smooth by AnistropicFilter");
62
63 vtkSmartPointer<vtkRenderWindowInteractor> rwi =
64 vtkSmartPointer<vtkRenderWindowInteractor>::New();
65 vtkSmartPointer<vtkInteractorStyleImage> style =
66 vtkSmartPointer<vtkInteractorStyleImage>::New();
67 rwi->SetInteractorStyle(style);
68 rwi->SetRenderWindow(rw);
69 rwi->Initialize();
70 rwi->Start();
71
72 return 0;
73 }