一杯清酒邀明月
天下本无事,庸人扰之而烦耳。

 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 <vtkPoints.h>
 9 #include <vtkPolyData.h>
10 #include <vtkPointData.h>
11 #include <vtkDelaunay2D.h>
12 #include <vtkMath.h>
13 #include <vtkPolyDataMapper.h>
14 #include <vtkActor.h>
15 #include <vtkRenderWindow.h>
16 #include <vtkRenderer.h>
17 #include <vtkRenderWindowInteractor.h>
18 #include <vtkVertexGlyphFilter.h>
19 
20 int main(int, char *[])
21 {
22     unsigned int gridSize = 10;
23     vtkSmartPointer<vtkPoints> points =
24         vtkSmartPointer<vtkPoints>::New();
25     for(unsigned int x = 0; x < gridSize; x++)
26     {
27         for(unsigned int y = 0; y < gridSize; y++)
28         {
29             points->InsertNextPoint(x, y, vtkMath::Random(0.0, 3.0));
30         }
31     }
32 
33     vtkSmartPointer<vtkPolyData> polydata =
34         vtkSmartPointer<vtkPolyData>::New();
35     polydata->SetPoints(points);
36 
37     vtkSmartPointer<vtkDelaunay2D> delaunay =
38         vtkSmartPointer<vtkDelaunay2D>::New();
39     delaunay->SetInputData(polydata);
40     delaunay->Update();
41 
42     vtkSmartPointer<vtkVertexGlyphFilter> glyphFilter =
43         vtkSmartPointer<vtkVertexGlyphFilter>::New();
44     glyphFilter->SetInputData(polydata);
45     glyphFilter->Update();
46 
47     vtkSmartPointer<vtkPolyDataMapper> pointsMapper =
48         vtkSmartPointer<vtkPolyDataMapper>::New();
49     pointsMapper->SetInputData(glyphFilter->GetOutput());
50 
51     vtkSmartPointer<vtkActor> pointsActor =
52         vtkSmartPointer<vtkActor>::New();
53     pointsActor->SetMapper(pointsMapper);
54     pointsActor->GetProperty()->SetPointSize(3);
55     pointsActor->GetProperty()->SetColor(1,0,0);
56 
57     vtkSmartPointer<vtkPolyDataMapper> triangulatedMapper =
58         vtkSmartPointer<vtkPolyDataMapper>::New();
59     triangulatedMapper->SetInputData(delaunay->GetOutput());
60 
61     vtkSmartPointer<vtkActor> triangulatedActor =
62         vtkSmartPointer<vtkActor>::New();
63     triangulatedActor->SetMapper(triangulatedMapper);
64 
65     vtkSmartPointer<vtkRenderer> renderer =
66         vtkSmartPointer<vtkRenderer>::New();
67     renderer->AddActor(pointsActor);
68     renderer->AddActor(triangulatedActor);
69     renderer->SetBackground(1.0, 1.0, 1.0);
70 
71     vtkSmartPointer<vtkRenderWindow> renderWindow =
72         vtkSmartPointer<vtkRenderWindow>::New();
73     renderWindow->AddRenderer(renderer);
74 
75     vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
76         vtkSmartPointer<vtkRenderWindowInteractor>::New();
77     renderWindowInteractor->SetRenderWindow(renderWindow);
78 
79     renderWindow->SetSize(640, 320);
80     renderWindow->Render();
81     renderWindow->SetWindowName("PolyDataDelaunay2D");
82     renderWindow->Render();
83 
84     renderWindowInteractor->Start();
85 
86     return EXIT_SUCCESS;
87 }

posted on 2023-08-16 08:41  一杯清酒邀明月  阅读(105)  评论(0编辑  收藏  举报