-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdraw_polygon.cxx
56 lines (46 loc) · 1.5 KB
/
draw_polygon.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <vtkActor.h>
#include <vtkCellArray.h>
#include <vtkIdList.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkPoints.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkPolygon.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
auto main(int argc, char** argv) -> int {
vtkNew<vtkNamedColors> colors;
vtkNew<vtkPoints> points;
points->InsertNextPoint(0.0, 0.0, 0.0);
points->InsertNextPoint(1.0, 0.0, 0.0);
points->InsertNextPoint(1.0, 1.0, 0.0);
points->InsertNextPoint(0.0, 1.0, 0.0);
vtkNew<vtkPolygon> polygon;
auto ids = polygon->GetPointIds();
ids->SetNumberOfIds(points->GetNumberOfPoints());
for (int i = 0; i < points->GetNumberOfPoints(); ++i) {
ids->SetId(i, i);
}
vtkNew<vtkCellArray> polygons;
polygons->InsertNextCell(polygon);
vtkNew<vtkPolyData> polygon_polydata;
polygon_polydata->SetPoints(points);
polygon_polydata->SetPolys(polygons);
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputData(polygon_polydata);
vtkNew<vtkActor> actor;
actor->SetMapper(mapper);
actor->GetProperty()->SetColor(colors->GetColor3d("Silver").GetData());
vtkNew<vtkRenderer> render;
render->AddActor(actor);
render->SetBackground(colors->GetColor3d("Salmon").GetData());
vtkNew<vtkRenderWindow> window;
window->AddRenderer(render);
vtkNew<vtkRenderWindowInteractor> interactor;
interactor->SetRenderWindow(window);
window->Render();
interactor->Start();
}