-
Notifications
You must be signed in to change notification settings - Fork 0
/
InteractorStyleMoveGlyph.h
150 lines (121 loc) · 4.05 KB
/
InteractorStyleMoveGlyph.h
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#ifndef InteractorStyleMoveGlyph_H
#define InteractorStyleMoveGlyph_H
#include "vtkWidget.h"
#include <vtkVertexGlyphFilter.h>
class InteractorStyleMoveGlyph : public vtkInteractorStyleTrackballActor
{
public:
//static InteractorStyleMoveGlyph* New();
vtkTypeMacro(InteractorStyleMoveGlyph,vtkInteractorStyleTrackballActor);
InteractorStyleMoveGlyph()
{
this->Move = false;
this->MoveData = vtkSmartPointer<vtkPolyData>::New();
this->Data = vtkSmartPointer<vtkPolyData>::New();
}
void renderMoveData()
{
vtkSmartPointer<vtkVertexGlyphFilter> vertexFilter = vtkSmartPointer<vtkVertexGlyphFilter>::New();
vertexFilter->SetInputConnection(this->MoveData->GetProducerPort());
vertexFilter->Update();
// In selection
//this->MoveData = vtkSmartPointer<vtkUnstructuredGrid>::New();
this->MoveMapper = vtkSmartPointer<vtkDataSetMapper>::New();
this->MoveMapper->SetInputConnection(vertexFilter->GetOutputPort());
this->MoveActor = vtkSmartPointer<vtkActor>::New();
this->MoveActor->SetMapper(this->MoveMapper);
this->MoveActor->GetProperty()->SetColor(1,0,0);
}
void OnMouseMove()
{
if(!this->Move) return;
vtkInteractorStyleTrackballActor::OnMouseMove();
}
virtual void OnLeftButtonDown()
{
vtkInteractorStyleTrackballActor::OnLeftButtonDown();
}
virtual void OnLeftButtonUp()
{
vtkInteractorStyleTrackballActor::OnLeftButtonUp();
}
void OnMiddleButtonUp()
{
// Forward events
vtkInteractorStyleTrackballActor::OnMiddleButtonUp();
this->MoveActor->VisibilityOff();
if (!this->Move)
{
return;
}
this->Move = false;
this->EndPan();
double *end = new double[3];
double displayPt[4];
int currPos[2];
this->widget->mInteractor->GetEventPosition(currPos);
end = this->MoveActor->GetPosition();
double distance[3];
distance[0] = end[0] - start[0];
distance[1] = end[1] - start[1];
distance[2] = end[2] - start[2];
double pointPos[3];
vtkSmartPointer<vtkPoints> ptOnObject = vtkSmartPointer<vtkPoints>::New();
for (int i = 0; i < typeId.size(); i++)
{
this->Data->GetPoint(typeId[i], pointPos);
pointPos[0] += distance[0];
pointPos[1] += distance[1];
pointPos[2] += distance[2];
this->Data->GetPoints()->SetPoint(typeId[i], pointPos);
MoveData->GetPoints()->SetPoint(i, pointPos);
ptOnObject->InsertNextPoint(pointPos);
}
vtkSmartPointer<vtkPolyData> pointdata = vtkSmartPointer<vtkPolyData>::New();
pointdata->SetPoints(ptOnObject);
vtkSmartPointer<vtkVertexGlyphFilter> vertexFilter = vtkSmartPointer<vtkVertexGlyphFilter>::New();
vertexFilter->SetInputConnection(pointdata->GetProducerPort());
vertexFilter->Update();
surfaceMapper->SetInputConnection(vertexFilter->GetOutputPort());
MoveData->Modified();
this->Data->Modified();
this->GetCurrentRenderer()->Render();
this->GetCurrentRenderer()->GetRenderWindow()->Render();
widget->renderUpdate();
}
void OnMiddleButtonDown()
{
// Forward events
vtkInteractorStyleTrackballActor::OnMiddleButtonDown();
widget->renderUpdate();
if(static_cast<vtkCellPicker*>(this->InteractionPicker)->GetPointId() >= 0)
{
int id = static_cast<vtkCellPicker*>(this->InteractionPicker)->GetPointId();
if (std::find(typeId.begin(), typeId.end(), id) == typeId.end()) // the selected point is not on the selected mesh
{
this->Move = false;
return;
}
this->StartPan();
this->MoveActor->VisibilityOn();
qDebug() << "Id: " << id;
this->Move = true;
this->Data->GetPoint(id, start);
this->MoveActor->SetPosition(start);
}
//this->GetCurrentRenderer()->AddActor(this->MoveActor);
this->InteractionProp = this->MoveActor;
}
double start[3];
vtkSmartPointer<vtkDataSetMapper> MoveMapper;
vtkSmartPointer<vtkDataSetMapper> surfaceMapper;
vtkSmartPointer<vtkActor> MoveActor;
vtkSmartPointer<vtkPolyData> Data;
std::vector<int> typeId;
//vtkSmartPointer<vtkIdTypeArray> ids;
vtkSmartPointer<vtkPolyData> MoveData;
VtkWidget* widget;
bool Move;
};
//vtkStandardNewMacro(InteractorStyleMoveGlyph);
#endif