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 <vtkProperty.h> 8 #include <vtkPolygon.h> 9 #include <vtkCellArray.h> 10 #include <vtkPoints.h> 11 #include <vtkPolyData.h> 12 #include <vtkPointData.h> 13 #include <vtkDelaunay2D.h> 14 #include <vtkMath.h> 15 #include <vtkPolyDataMapper.h> 16 #include <vtkActor.h> 17 #include <vtkRenderWindow.h> 18 #include <vtkRenderer.h> 19 #include <vtkRenderWindowInteractor.h> 20 #include <vtkVertexGlyphFilter.h> 21 22 int main(int, char *[]) 23 { 24 vtkSmartPointer<vtkPoints> points = 25 vtkSmartPointer<vtkPoints>::New(); 26 27 unsigned int gridSize = 10; 28 for(unsigned int x = 0; x < gridSize; x++) 29 { 30 for(unsigned int y = 0; y < gridSize; y++) 31 { 32 points->InsertNextPoint(x, y, vtkMath::Random(0.0, 3.0)); 33 } 34 } 35 36 vtkSmartPointer<vtkPolyData> polydata = 37 vtkSmartPointer<vtkPolyData>::New(); 38 polydata->SetPoints(points); 39 40 vtkSmartPointer<vtkPolygon> poly = 41 vtkSmartPointer<vtkPolygon>::New(); 42 /*poly->GetPointIds()->InsertNextId(22); 43 poly->GetPointIds()->InsertNextId(23); 44 poly->GetPointIds()->InsertNextId(24); 45 poly->GetPointIds()->InsertNextId(25); 46 poly->GetPointIds()->InsertNextId(35); 47 poly->GetPointIds()->InsertNextId(45); 48 poly->GetPointIds()->InsertNextId(44); 49 poly->GetPointIds()->InsertNextId(43); 50 poly->GetPointIds()->InsertNextId(42); 51 poly->GetPointIds()->InsertNextId(32);*/ 52 53 poly->GetPointIds()->InsertNextId(32); 54 poly->GetPointIds()->InsertNextId(42); 55 poly->GetPointIds()->InsertNextId(43); 56 poly->GetPointIds()->InsertNextId(44); 57 poly->GetPointIds()->InsertNextId(45); 58 poly->GetPointIds()->InsertNextId(35); 59 poly->GetPointIds()->InsertNextId(25); 60 poly->GetPointIds()->InsertNextId(24); 61 poly->GetPointIds()->InsertNextId(23); 62 poly->GetPointIds()->InsertNextId(22); 63 64 vtkSmartPointer<vtkCellArray> cell = 65 vtkSmartPointer<vtkCellArray>::New(); 66 cell->InsertNextCell(poly); 67 68 vtkSmartPointer<vtkPolyData> boundary = 69 vtkSmartPointer<vtkPolyData>::New(); 70 boundary->SetPoints(points); 71 boundary->SetPolys(cell); 72 73 vtkSmartPointer<vtkDelaunay2D> delaunay = 74 vtkSmartPointer<vtkDelaunay2D>::New(); 75 delaunay->SetInputData(polydata); 76 delaunay->SetSourceData(boundary); 77 delaunay->Update(); 78 79 vtkSmartPointer<vtkVertexGlyphFilter> glyphFilter = 80 vtkSmartPointer<vtkVertexGlyphFilter>::New(); 81 glyphFilter->SetInputData(polydata); 82 glyphFilter->Update(); 83 84 vtkSmartPointer<vtkPolyDataMapper> pointsMapper = 85 vtkSmartPointer<vtkPolyDataMapper>::New(); 86 pointsMapper->SetInputData(glyphFilter->GetOutput()); 87 88 vtkSmartPointer<vtkActor> pointsActor = 89 vtkSmartPointer<vtkActor>::New(); 90 pointsActor->SetMapper(pointsMapper); 91 pointsActor->GetProperty()->SetPointSize(3); 92 pointsActor->GetProperty()->SetColor(1,0,0); 93 94 vtkSmartPointer<vtkPolyDataMapper> triangulatedMapper = 95 vtkSmartPointer<vtkPolyDataMapper>::New(); 96 triangulatedMapper->SetInputData(delaunay->GetOutput()); 97 98 vtkSmartPointer<vtkActor> triangulatedActor = 99 vtkSmartPointer<vtkActor>::New(); 100 triangulatedActor->SetMapper(triangulatedMapper); 101 102 vtkSmartPointer<vtkRenderer> renderer = 103 vtkSmartPointer<vtkRenderer>::New(); 104 renderer->AddActor(pointsActor); 105 renderer->AddActor(triangulatedActor); 106 renderer->SetBackground(1.0, 1.0, 1.0); 107 108 vtkSmartPointer<vtkRenderWindow> renderWindow = 109 vtkSmartPointer<vtkRenderWindow>::New(); 110 renderWindow->AddRenderer(renderer); 111 112 vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = 113 vtkSmartPointer<vtkRenderWindowInteractor>::New(); 114 renderWindowInteractor->SetRenderWindow(renderWindow); 115 116 renderWindow->SetSize(640, 480); 117 renderWindow->Render(); 118 renderWindow->SetWindowName("PolyDataConstrainedDelaunay2D"); 119 renderWindow->Render(); 120 renderWindowInteractor->Start(); 121 122 return EXIT_SUCCESS; 123 }标签:59,剖分,GetPointIds,VTK,InsertNextId,poly,vtkSmartPointer,New,include From: https://www.cnblogs.com/ybqjymy/p/17632972.html