1 #include <vtkAutoInit.h> 2 VTK_MODULE_INIT(vtkRenderingOpenGL2); 3 VTK_MODULE_INIT(vtkRenderingFreeType); 4 VTK_MODULE_INIT(vtkInteractionStyle); 5 6 #include <vtkSmartPointer.h> 7 #include <vtkPolyDataReader.h> 8 #include <vtkPolyData.h> 9 #include <vtkSurfaceReconstructionFilter.h> 10 #include <vtkContourFilter.h> 11 #include <vtkVertexGlyphFilter.h> 12 #include <vtkPolyDataMapper.h> 13 #include <vtkActor.h> 14 #include <vtkRenderer.h> 15 #include <vtkCamera.h> 16 #include <vtkRenderWindow.h> 17 #include <vtkRenderWindowInteractor.h> 18 #include <vtkProperty.h> 19 20 int main() 21 { 22 vtkSmartPointer<vtkPolyDataReader> reader = 23 vtkSmartPointer<vtkPolyDataReader>::New(); 24 reader->SetFileName("C:\\Users\\Administrator\\Desktop\\VTK2\\hellovtk\\vtk_图像处理学习\\第六章_图像处理\\data\\fran_cut.vtk"); 25 reader->Update(); 26 27 vtkSmartPointer<vtkPolyData> points = 28 vtkSmartPointer<vtkPolyData>::New(); 29 points->SetPoints(reader->GetOutput()->GetPoints()); //获得网格模型中的几何数据:点集 30 31 vtkSmartPointer<vtkSurfaceReconstructionFilter> surf = 32 vtkSmartPointer<vtkSurfaceReconstructionFilter>::New(); 33 surf->SetInputData(points); 34 surf->SetNeighborhoodSize(20); 35 surf->SetSampleSpacing(0.005); 36 surf->Update(); 37 38 vtkSmartPointer<vtkContourFilter> contour = 39 vtkSmartPointer<vtkContourFilter>::New(); 40 contour->SetInputConnection(surf->GetOutputPort()); 41 contour->SetValue(0, 0.0); 42 contour->Update(); 43 // 44 vtkSmartPointer <vtkVertexGlyphFilter> vertexGlyphFilter = 45 vtkSmartPointer<vtkVertexGlyphFilter>::New(); 46 vertexGlyphFilter->AddInputData(points); 47 vertexGlyphFilter->Update(); 48 vtkSmartPointer<vtkPolyDataMapper> pointMapper = 49 vtkSmartPointer<vtkPolyDataMapper>::New(); 50 pointMapper->SetInputData(vertexGlyphFilter->GetOutput()); 51 pointMapper->ScalarVisibilityOff(); 52 53 vtkSmartPointer<vtkActor> pointActor = 54 vtkSmartPointer<vtkActor>::New(); 55 pointActor->SetMapper(pointMapper); 56 pointActor->GetProperty()->SetColor(1, 0, 0); 57 pointActor->GetProperty()->SetPointSize(4); 58 59 vtkSmartPointer<vtkPolyDataMapper> contourMapper = 60 vtkSmartPointer<vtkPolyDataMapper>::New(); 61 contourMapper->SetInputData(contour->GetOutput()); 62 vtkSmartPointer<vtkActor> contourActor = 63 vtkSmartPointer<vtkActor>::New(); 64 contourActor->SetMapper(contourMapper); 65 /// 66 double pointView[4] = { 0, 0, 0.5, 1 }; 67 double contourView[4] = { 0.5, 0, 1, 1 }; 68 69 vtkSmartPointer<vtkRenderer> pointRender = 70 vtkSmartPointer<vtkRenderer>::New(); 71 pointRender->AddActor(pointActor); 72 pointRender->SetViewport(pointView); 73 pointRender->SetBackground(1, 1, 1); 74 75 vtkSmartPointer<vtkRenderer> contourRender = 76 vtkSmartPointer<vtkRenderer>::New(); 77 contourRender->AddActor(contourActor); 78 contourRender->SetViewport(contourView); 79 contourRender->SetBackground(0, 1, 0); 80 81 pointRender->GetActiveCamera()->SetPosition(0, -1, 0); 82 pointRender->GetActiveCamera()->SetFocalPoint(0, 0, 0); 83 pointRender->GetActiveCamera()->SetViewUp(0, 0, 1); 84 pointRender->GetActiveCamera()->Azimuth(30); 85 pointRender->GetActiveCamera()->Elevation(30); 86 pointRender->ResetCamera(); 87 contourRender->SetActiveCamera(pointRender->GetActiveCamera()); 88 89 vtkSmartPointer<vtkRenderWindow> rw = 90 vtkSmartPointer<vtkRenderWindow>::New(); 91 rw->AddRenderer(pointRender); 92 rw->AddRenderer(contourRender); 93 rw->SetSize(640, 320); 94 rw->SetWindowName("3D Surface Reconstruction "); 95 rw->Render(); 96 97 vtkSmartPointer<vtkRenderWindowInteractor> rwi = 98 vtkSmartPointer<vtkRenderWindowInteractor>::New(); 99 rwi->SetRenderWindow(rw); 100 rwi->Initialize(); 101 rwi->Start(); 102 103 return 0; 104 }标签:rw,VTK,contourRender,vtkSmartPointer,61,pointRender,New,include,重建 From: https://www.cnblogs.com/ybqjymy/p/17632975.html