1 #include "vtkAutoInit.h" 2 VTK_MODULE_INIT(vtkRenderingOpenGL2); 3 VTK_MODULE_INIT(vtkInteractionStyle); 4 5 #include <vtkSmartPointer.h> 6 #include <vtkPolyDataReader.h> 7 #include <vtkPolyData.h> 8 #include <vtkSmoothPolyDataFilter.h> 9 #include <vtkWindowedSincPolyDataFilter.h> 10 #include <vtkSphereSource.h> 11 #include <vtkPolyDataMapper.h> 12 #include <vtkActor.h> 13 #include <vtkRenderWindow.h> 14 #include <vtkRenderer.h> 15 #include <vtkRenderWindowInteractor.h> 16 17 //测试文件:../data/fran_cut.vtk 18 int main(int argc, char *argv[]) 19 { 20 vtkSmartPointer<vtkPolyDataReader> reader = 21 vtkSmartPointer<vtkPolyDataReader>::New(); 22 reader->SetFileName("C:\\Users\\Administrator\\Desktop\\VTK2\\hellovtk\\vtk_图像处理学习\\第六章_图像处理\\data\\fran_cut.vtk"); 23 reader->Update(); 24 25 vtkSmartPointer<vtkSmoothPolyDataFilter> smoothFilter = 26 vtkSmartPointer<vtkSmoothPolyDataFilter>::New(); 27 smoothFilter->SetInputConnection(reader->GetOutputPort()); 28 smoothFilter->SetNumberOfIterations(200); 29 smoothFilter->Update(); 30 31 vtkSmartPointer<vtkPolyDataMapper> inputMapper = 32 vtkSmartPointer<vtkPolyDataMapper>::New(); 33 inputMapper->SetInputConnection(reader->GetOutputPort()); 34 vtkSmartPointer<vtkActor> inputActor = 35 vtkSmartPointer<vtkActor>::New(); 36 inputActor->SetMapper(inputMapper); 37 38 vtkSmartPointer<vtkPolyDataMapper> smoothedMapper = 39 vtkSmartPointer<vtkPolyDataMapper>::New(); 40 smoothedMapper->SetInputConnection(smoothFilter->GetOutputPort()); 41 42 vtkSmartPointer<vtkActor> smoothedActor = 43 vtkSmartPointer<vtkActor>::New(); 44 smoothedActor->SetMapper(smoothedMapper); 45 46 double leftViewport[4] = {0.0, 0.0, 0.5, 1.0}; 47 double rightViewport[4] = {0.5, 0.0, 1.0, 1.0}; 48 49 vtkSmartPointer<vtkRenderer> leftRenderer = 50 vtkSmartPointer<vtkRenderer>::New(); 51 52 leftRenderer->SetViewport(leftViewport); 53 leftRenderer->AddActor(inputActor); 54 leftRenderer->SetBackground(0.8, 0.8, 0.8); 55 leftRenderer->ResetCamera(); 56 57 vtkSmartPointer<vtkRenderer> rightRenderer = 58 vtkSmartPointer<vtkRenderer>::New(); 59 rightRenderer->SetViewport(rightViewport); 60 rightRenderer->AddActor(smoothedActor); 61 rightRenderer->SetBackground(0.8, 0.8, 0.8); 62 rightRenderer->SetActiveCamera(leftRenderer->GetActiveCamera()); 63 rightRenderer->ResetCamera(); 64 65 vtkSmartPointer<vtkRenderWindow> renderWindow = 66 vtkSmartPointer<vtkRenderWindow>::New(); 67 renderWindow->AddRenderer(leftRenderer); 68 renderWindow->AddRenderer(rightRenderer); 69 renderWindow->SetSize(640, 320); 70 renderWindow->Render(); 71 renderWindow->SetWindowName("PolyDataLapLasianSmooth"); 72 73 vtkSmartPointer<vtkRenderWindowInteractor> interactor = 74 vtkSmartPointer<vtkRenderWindowInteractor>::New(); 75 interactor->SetRenderWindow(renderWindow); 76 77 renderWindow->Render(); 78 interactor->Start(); 79 80 return EXIT_SUCCESS; 81 }标签:VTK,网格,53,vtkSmartPointer,rightRenderer,renderWindow,New,include,leftRenderer From: https://www.cnblogs.com/ybqjymy/p/17632963.html