forked from lesterlo/cloud_annotation_tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathannotatorinteractor.cpp
131 lines (112 loc) · 4.31 KB
/
annotatorinteractor.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
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
#include "annotatorinteractor.h"
#include <vtkPointPicker.h>
#include <vtkObjectFactory.h>
#include <vtkAssemblyPath.h>
#include <vtkAbstractPicker.h>
#include <vtkCamera.h>
#include <vtkPointPicker.h>
#include <vtkAreaPicker.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
vtkStandardNewMacro(AnnotatorInteractor);
boost::signals2::connection AnnotatorInteractor::registerPaintingCallback(boost::function<void (const double, const double, const double, const long, const bool)> cb)
{
return (paint_signal.connect (cb));
}
void AnnotatorInteractor::Initialize()
{
pcl::visualization::PCLVisualizerInteractorStyle::Initialize();
pp = vtkSmartPointer<vtkPointPicker>::New ();
pp->SetTolerance (pointPickerTolerance);
if (Interactor) {
Interactor->SetPicker (pp);
}
}
void AnnotatorInteractor::OnKeyDown()
{
// Get the status of special keys (Cltr+Alt+Shift)
bool shift = Interactor->GetShiftKey ();
bool ctrl = Interactor->GetControlKey ();
bool alt = Interactor->GetAltKey ();
if ((Interactor->GetKeySym ()[0] == 'p' || Interactor->GetKeySym ()[0] == 'P') && !ctrl && !alt && !shift) {
isPainting = true;
} else if ((Interactor->GetKeySym ()[0] == 'e' || Interactor->GetKeySym ()[0] == 'E') && !ctrl && !alt && !shift) {
isErasing = true;
} else if (Interactor->GetKeySym()[0] == 'f' || Interactor->GetKeySym()[0] == 'F' && !ctrl && !alt && !shift) {
// work around for buggy default "f" key behaviour: use our own picker
int x = this->Interactor->GetEventPosition()[0];
int y = this->Interactor->GetEventPosition()[1];
vtkSmartPointer<vtkPointPicker> pp = vtkSmartPointer<vtkPointPicker>::New ();
pp->SetTolerance (getPointPickerTolerance());
pp->Pick (x, y, 0.0, this->CurrentRenderer);
vtkAbstractPropPicker *picker;
vtkAssemblyPath *path = NULL;
if ((picker = vtkAbstractPropPicker::SafeDownCast (pp)))
path = picker->GetPath ();
if (path != NULL) {
AnimState = VTKIS_ANIM_ON;
Interactor->SetNumberOfFlyFrames(0); // animation doesn't work on QVTKOpenGlWidget so don't waste time on it
Interactor->FlyTo (CurrentRenderer, picker->GetPickPosition ());
AnimState = VTKIS_ANIM_OFF;
}
} else {
pcl::visualization::PCLVisualizerInteractorStyle::OnKeyDown();
}
}
void AnnotatorInteractor::OnMouseMove()
{
if (isPainting || isErasing) {
double cameraPos[4], cameraFP[4];
vtkCamera *camera;
camera = this->CurrentRenderer->GetActiveCamera();
camera->GetPosition(cameraPos);
cameraPos[3] = 1.0;
camera->GetFocalPoint(cameraFP);
cameraFP[3] = 1.0;
vtkAssemblyPath *path = NULL;
int x = this->Interactor->GetEventPosition()[0];
int y = this->Interactor->GetEventPosition()[1];
vtkSmartPointer<vtkPointPicker> pp = vtkSmartPointer<vtkPointPicker>::New ();
pp->SetTolerance (getPainterTolerance());
//Interactor->SetPicker (pp);
pp->Pick (x, y, 0.0, this->CurrentRenderer);
vtkAbstractPropPicker *picker;
if ((picker = vtkAbstractPropPicker::SafeDownCast (pp)))
path = picker->GetPath ();
if (path != NULL) {
auto d1 = picker->GetPickPosition()[0];
auto d2 = picker->GetPickPosition()[1];
auto d3 = picker->GetPickPosition()[2];
paint_signal(d1,d2,d3, pp->GetPointId(), isPainting);
}
} else {
PCLVisualizerInteractorStyle::OnMouseMove();
}
}
double AnnotatorInteractor::getPainterTolerance() const
{
return painterTolerance;
}
void AnnotatorInteractor::setPainterTolerance(double value)
{
painterTolerance = value;
}
double AnnotatorInteractor::getPointPickerTolerance() const
{
return pointPickerTolerance;
}
void AnnotatorInteractor::setPointPickerTolerance(double value)
{
pointPickerTolerance = value;
pp->SetTolerance(value);
}
void AnnotatorInteractor::OnKeyUp()
{
if ((Interactor->GetKeySym ()[0] == 'p' || Interactor->GetKeySym ()[0] == 'P') ) {
isPainting = false;
} else if ((Interactor->GetKeySym ()[0] == 'e' || Interactor->GetKeySym ()[0] == 'E') ) {
isErasing = false;
} else {
pcl::visualization::PCLVisualizerInteractorStyle::OnKeyUp();
}
}