-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathE_CuttingPlane.cpp
92 lines (66 loc) · 1.92 KB
/
E_CuttingPlane.cpp
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
#include "E_CuttingPlane.h"
#include <vtkPlaneSource.h>
#include <vtkProperty.h>
#include <vtkPolyDAtaMapper.h>
#include <vtkCutter.h>
#include <vtkVector.h>
E_CuttingPlane::E_CuttingPlane()
{
Initialize();
}
E_CuttingPlane::~E_CuttingPlane()
{
}
void E_CuttingPlane::Initialize()
{
// Create a plane
this->SetOrigin(0.0, 0.0, -0.5);
this->SetNormal(1.0, 0.0, 0.0);
vtkSmartPointer<vtkPlaneSource> planeSource = vtkSmartPointer<vtkPlaneSource>::New();
planeSource->SetCenter(0.0, 0.0, -0.5);
planeSource->SetNormal(1.0, 0.0, 0.0);
planeSource->Update();
vtkPolyData* plane = planeSource->GetOutput();
// Create a mapper and actor
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputData(plane);
m_actor = vtkSmartPointer<vtkActor>::New();
m_actor->SetMapper(mapper);
m_actor->SetScale(0.2, 0.2, 0.2);
m_actor->GetProperty()->SetColor(0.0, 0.0, 0.0);
m_actor->GetProperty()->SetOpacity(0.2);
}
void E_CuttingPlane::Start(bool inv, double *ori)
{
double n[3] = { 1.0, 0.0, 0.0 };
if (!inv) n[0] = -1.0;
m_actor->SetOrientation(n);
m_actor->RotateWXYZ(ori[0], ori[1], ori[2], ori[3]);
this->SetNormal(n);
vtkSmartPointer<vtkTransform> trans = vtkSmartPointer<vtkTransform>::New();
trans->RotateWXYZ(ori[0], ori[1], ori[2], ori[3]);
trans->Update();
double *dn;
dn = trans->TransformDoubleNormal(n);
this->SetNormal(dn);
}
void E_CuttingPlane::Update(double* pos, double *ori)
{
//Set Position
this->SetOrigin(pos[0], pos[1], pos[2]);
m_actor->SetPosition(pos[0], pos[1], pos[2]);
//Set Orientation
m_actor->RotateWXYZ(ori[0], ori[1], ori[2], ori[3]);
// Set Normal Plane
vtkSmartPointer<vtkTransform> trans = vtkSmartPointer<vtkTransform>::New();
trans->RotateWXYZ(ori[0], ori[1], ori[2], ori[3]);
trans->Update();
double n[3];
this->GetNormal(n);
double *dn;
dn = trans->TransformDoubleNormal(n);
this->SetNormal(dn);
}
void E_CuttingPlane::Remove()
{
}