1 #include <vtkAutoInit.h>
2 VTK_MODULE_INIT(vtkRenderingOpenGL);
3
4 #include <vtkSmartPointer.h>
5 #include <vtkConeSource.h>
6 #include <vtkPolyData.h>
7 #include <vtkPolyDataMapper.h>
8 #include <vtkActor.h>
9 #include <vtkRenderer.h>
10 #include <vtkRenderWindow.h>
11 #include <vtkRenderWindowInteractor.h>
12
13 int main()
14 {
15 vtkSmartPointer<vtkConeSource> coneSource =
16 vtkSmartPointer<vtkConeSource>::New();
17 coneSource->Update();
18
19 vtkSmartPointer<vtkPolyData> polyData =
20 vtkSmartPointer<vtkPolyData>::New();
21 polyData = coneSource->GetOutput();
22 int nPoints = polyData->GetNumberOfPoints();
23 int nCells = polyData->GetNumberOfCells();
24 std::cout << "几何数据(点数):" << nPoints << std::endl;
25 std::cout << "拓扑数据(单元):" << nCells << std::endl;
26
27 vtkSmartPointer<vtkPolyDataMapper> mapper =
28 vtkSmartPointer<vtkPolyDataMapper>::New();
29 mapper->SetInputData(polyData);
30
31 vtkSmartPointer<vtkActor> actor =
32 vtkSmartPointer<vtkActor>::New();
33 actor->SetMapper(mapper);
34
35 vtkSmartPointer<vtkRenderer> render =
36 vtkSmartPointer<vtkRenderer>::New();
37 render->AddActor(actor);
38 render->SetBackground(10, 0, 0);
39
40 vtkSmartPointer<vtkRenderWindow> rw =
41 vtkSmartPointer<vtkRenderWindow>::New();
42 rw->AddRenderer(render);
43 rw->SetSize(640, 480);
44 rw->SetWindowName("PolyData Structure Learning");
45 rw->Render();
46
47 vtkSmartPointer<vtkRenderWindowInteractor> rwi =
48 vtkSmartPointer<vtkRenderWindowInteractor>::New();
49 rwi->SetRenderWindow(rw);
50 rwi->Initialize();
51 rwi->Start();
52
53 return 0;
54 }