-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrid.cpp
More file actions
97 lines (79 loc) · 2.42 KB
/
Grid.cpp
File metadata and controls
97 lines (79 loc) · 2.42 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "Grid.h"
Grid::Grid() {
build(new double[3]{ 0.0, 0.0, 0.0 }, new double[2]{ 10.0, 10.0 }, new double[2]{ 1.0, 1.0 });
}
Grid::Grid(double* _position, double* _size, double* _cell) {
build(_position, _size, _cell);
}
void Grid::build(double* _position, double* _size, double* _cell) {
position = { _position[0], _position[1], 0.0 };
size = { _size[0], _size[1] };
cell = { _cell[0], _cell[1] };
actor = vtkSmartPointer<vtkActor>::New();
BuildActor();
actor->SetPosition(position[0], position[1], position[2]);
}
void Grid::SetPosition(double* newpos){
position[0] = newpos[0];
position[1] = newpos[1];
actor->SetPosition(position[0], position[1], position[2]);
}
void Grid::SetPosition(double newX, double newY, double newZ){
position[0] = newX;
position[1] = newY;
position[2] = newZ;
actor->SetPosition(position[0], position[1], position[2]);
}
void Grid::SetSize(double* newsize, bool rebuild){
size[0] = newsize[0];
size[1] = newsize[1];
if (rebuild)
BuildActor();
}
void Grid::SetCell(double cellX, double cellY, bool rebuild){
cell[0] = cellX;
cell[1] = cellY;
if (rebuild)
BuildActor();
}
double* Grid::GetPosition(){
double* getpos = new double[2]{ position[0],position[1] };
return getpos;
}
double* Grid::GetSize(){
double* getsize = new double[2]{ size[0],size[1] };
return getsize;
}
double* Grid::GetCell(){
double* getcell = new double[2]{ cell[0],cell[1] };
return getcell;
}
vtkSmartPointer<vtkActor> Grid::GetActor(){
return actor;
}
void Grid::BuildActor(){
vtkSmartPointer<vtkPoints> points = vtkPoints::New();
vtkSmartPointer<vtkCellArray> lines = vtkCellArray::New();
int num = 0;
for (double i = -size[1] / 2.0; i <= size[1] / 2.0; i += cell[1]) {
points->InsertNextPoint(-size[0] / 2, i, 0);
points->InsertNextPoint(size[0] / 2, i, 0);
vtkIdType tcell[] = { 2 * num, 2 * num + 1 };
lines->InsertNextCell(2, tcell);
num++;
}
for (double i = -size[0] / 2.0; i <= size[0] / 2.0; i += cell[0]) {
points->InsertNextPoint(i, -size[1] / 2, 0);
points->InsertNextPoint(i, size[1] / 2, 0);
vtkIdType tcell[] = { 2 * num, 2 * num + 1 };
lines->InsertNextCell(2, tcell);
num++;
}
vtkSmartPointer<vtkPolyData> polydata = vtkPolyData::New();
polydata->SetPoints(points);
polydata->SetLines(lines);
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkPolyDataMapper::New();
mapper->SetInputData(polydata);
actor->SetMapper(mapper);
actor->GetProperty()->SetColor(0.8, 0.8, 0.8);
}