-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainAxes.cpp
More file actions
62 lines (46 loc) · 1.76 KB
/
MainAxes.cpp
File metadata and controls
62 lines (46 loc) · 1.76 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
#include "MainAxes.h"
MainAxes::MainAxes() {
build(new int[2]{ 1, 1 }, 3.0);
}
MainAxes::MainAxes(int* sizewin, double parallelScale) {
build(sizewin, parallelScale);
}
void MainAxes::build(int* sizewin, double parallelScale) {
actor = vtkSmartPointer<vtkActor>::New();
vtkSmartPointer<vtkPoints> points = vtkPoints::New();
points->Allocate(4);
double* scale = new double[2]{ 4 * parallelScale ,4 * parallelScale };
if (sizewin[0] / sizewin[1] > 1)
scale[0] *= (sizewin[0] * 1.0) / sizewin[1];
else
scale[1] *= (sizewin[1] * 1.0) / sizewin[0];
points->InsertNextPoint(0, -scale[1], 0);
points->InsertNextPoint(0, scale[1], 0);
points->InsertNextPoint(-scale[0], 0, 0);
points->InsertNextPoint(scale[0], 0, 0);
vtkSmartPointer<vtkPolyData> polydata = vtkPolyData::New();
polydata->SetPoints(points);
vtkSmartPointer<vtkCellArray> lines = vtkCellArray::New();
vtkIdType vert[2] = { 0, 1 };
vtkIdType hor[2] = { 2, 3 };
lines->InsertNextCell(2, vert);
lines->InsertNextCell(2, hor);
polydata->SetLines(lines);
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkPolyDataMapper::New();
mapper->SetInputData(polydata);
actor->SetMapper(mapper);
actor->GetProperty()->SetColor(0, 0, 0);
}
void MainAxes::RebuildAxes(vtkSmartPointer<vtkCamera> camera, int* sizewin) {
auto scaleX = (abs(camera->GetPosition()[0]) + 3.0 * camera->GetParallelScale()) / 12.0;
auto scaleY = (abs(camera->GetPosition()[1]) + 3.0 * camera->GetParallelScale()) / 12.0;
if (sizewin[0] / sizewin[1] > 1)
scaleX *= (sizewin[0] * 1.0) / sizewin[1];
else
scaleY *= (sizewin[1] * 1.0) / sizewin[0];
double scale[3] = { scaleX, scaleY, 0 };
actor->SetScale(scale);
}
vtkSmartPointer<vtkActor> MainAxes::GetActor() {
return actor;
}