1 #include <vtkAutoInit.h>
2 VTK_MODULE_INIT(vtkRenderingOpenGL);
3 VTK_MODULE_INIT(vtkInteractionStyle);
4 VTK_MODULE_INIT(vtkRenderingFreeType);
5
6 #include <vtkSmartPointer.h>
7 #include <vtkPolyDataReader.h>
8 #include <vtkSmoothPolyDataFilter.h>
9 #include <vtkPolyDataMapper.h>
10 #include <vtkActor.h>
11 #include <vtkRenderer.h>
12 #include <vtkRenderWindow.h>
13 #include <vtkRenderWindowInteractor.h>
14 int main()
15 {
16 vtkSmartPointer<vtkPolyDataReader> reader =
17 vtkSmartPointer<vtkPolyDataReader>::New();
18 reader->SetFileName("fran_cut.vtk");
19 reader->Update();
20
21 vtkSmartPointer<vtkSmoothPolyDataFilter> smoothFilter =
22 vtkSmartPointer<vtkSmoothPolyDataFilter>::New();
23 smoothFilter->SetInputConnection(reader->GetOutputPort());
24 smoothFilter->SetNumberOfIterations(100);
25 smoothFilter->Update();
26 /
27 vtkSmartPointer<vtkPolyDataMapper> inputMapper =
28 vtkSmartPointer<vtkPolyDataMapper>::New();
29 inputMapper->SetInputConnection(reader->GetOutputPort());
30 vtkSmartPointer<vtkActor> inputActor =
31 vtkSmartPointer<vtkActor>::New();
32 inputActor->SetMapper(inputMapper);
33
34 vtkSmartPointer<vtkPolyDataMapper> smoothedMapper =
35 vtkSmartPointer<vtkPolyDataMapper>::New();
36 smoothedMapper->SetInputConnection(smoothFilter->GetOutputPort());
37 vtkSmartPointer<vtkActor> smoothedActor =
38 vtkSmartPointer<vtkActor>::New();
39 smoothedActor->SetMapper(smoothedMapper);
40 /
41 double leftViewport[4] = { 0.0, 0.0, 0.5, 1.0 };
42 double rightViewport[4] = { 0.5, 0.0, 1.0, 1.0 };
43
44 vtkSmartPointer<vtkRenderer> leftRenderer =
45 vtkSmartPointer<vtkRenderer>::New();
46 leftRenderer->SetViewport(leftViewport);
47 leftRenderer->AddActor(inputActor);
48 leftRenderer->SetBackground(1, 0, 0);
49 leftRenderer->ResetCamera();
50
51 vtkSmartPointer<vtkRenderer> rightRenderer =
52 vtkSmartPointer<vtkRenderer>::New();
53 rightRenderer->SetViewport(rightViewport);
54 rightRenderer->AddActor(smoothedActor);
55 rightRenderer->SetBackground(0, 0, 0);
56 rightRenderer->ResetCamera();
57 /
58 vtkSmartPointer<vtkRenderWindow> rw =
59 vtkSmartPointer<vtkRenderWindow>::New();
60 rw->AddRenderer(leftRenderer);
61 rw->AddRenderer(rightRenderer);
62 rw->SetSize(640, 320);
63 rw->SetWindowName("PolyData Grid Smooth By LapLasian");
64
65 vtkSmartPointer<vtkRenderWindowInteractor> rwi =
66 vtkSmartPointer<vtkRenderWindowInteractor>::New();
67 rwi->SetRenderWindow(rw);
68 rwi->Initialize();
69 rwi->Start();
70 return 0;
71 }