forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkPointCloudWidget.cxx
162 lines (135 loc) · 5.4 KB
/
vtkPointCloudWidget.cxx
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
151
152
153
154
155
156
157
158
159
160
161
162
/*=========================================================================
Program: Visualization Toolkit
Module: vtkPointCloudWidget.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkPointCloudWidget.h"
#include "vtkCallbackCommand.h"
#include "vtkCommand.h"
#include "vtkEvent.h"
#include "vtkEventData.h"
#include "vtkObjectFactory.h"
#include "vtkPointCloudRepresentation.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkWidgetCallbackMapper.h"
#include "vtkWidgetEvent.h"
#include "vtkWidgetEventTranslator.h"
vtkStandardNewMacro(vtkPointCloudWidget);
//------------------------------------------------------------------------------
vtkPointCloudWidget::vtkPointCloudWidget()
{
this->WidgetState = vtkPointCloudWidget::Start;
this->ManagesCursor = 1;
// Define widget events: translate mouse events to widget events
this->CallbackMapper->SetCallbackMethod(
vtkCommand::MouseMoveEvent, vtkWidgetEvent::Move, this, vtkPointCloudWidget::MoveAction);
this->CallbackMapper->SetCallbackMethod(vtkCommand::LeftButtonPressEvent, vtkEvent::NoModifier, 0,
0, nullptr, vtkWidgetEvent::Select, this, vtkPointCloudWidget::SelectAction);
this->CallbackMapper->SetCallbackMethod(vtkCommand::LeftButtonReleaseEvent, vtkEvent::AnyModifier,
0, 0, nullptr, vtkWidgetEvent::EndSelect, this, vtkPointCloudWidget::EndSelectAction);
}
//------------------------------------------------------------------------------
vtkPointCloudWidget::~vtkPointCloudWidget() = default;
//------------------------------------------------------------------------------
void vtkPointCloudWidget::SetEnabled(int enabling)
{
// We do this step first because it sets the CurrentRenderer
this->Superclass::SetEnabled(enabling);
}
//------------------------------------------------------------------------------
void vtkPointCloudWidget::MoveAction(vtkAbstractWidget* w)
{
vtkPointCloudWidget* self = reinterpret_cast<vtkPointCloudWidget*>(w);
// See whether we're active, return if we are in the middle of something
// (i.e., a selection process).
if (self->WidgetState == vtkPointCloudWidget::Active)
{
return;
}
// compute some info we need for all cases
int X = self->Interactor->GetEventPosition()[0];
int Y = self->Interactor->GetEventPosition()[1];
// If nothing changes, just return
int oldState = self->WidgetRep->GetInteractionState();
vtkIdType oldPtId = reinterpret_cast<vtkPointCloudRepresentation*>(self->WidgetRep)->GetPointId();
int state = self->WidgetRep->ComputeInteractionState(X, Y);
vtkIdType ptId = reinterpret_cast<vtkPointCloudRepresentation*>(self->WidgetRep)->GetPointId();
if (oldState == state && oldPtId == ptId)
{
return;
}
// A new point has been picked
if (state == vtkPointCloudRepresentation::Over)
{
self->EventCallbackCommand->SetAbortFlag(1);
self->InvokeEvent(vtkCommand::PickEvent, nullptr);
}
// Refresh the renderer
self->Render();
}
//------------------------------------------------------------------------------
void vtkPointCloudWidget::SelectAction(vtkAbstractWidget* w)
{
// We are in a static method, cast to ourself
vtkPointCloudWidget* self = reinterpret_cast<vtkPointCloudWidget*>(w);
// Get the event position
int X = self->Interactor->GetEventPosition()[0];
int Y = self->Interactor->GetEventPosition()[1];
// Okay, make sure that the pick is in the current renderer
if (!self->CurrentRenderer || !self->CurrentRenderer->IsInViewport(X, Y))
{
self->WidgetState = vtkPointCloudWidget::Start;
return;
}
// Only can select if we are over a point
int state = self->WidgetRep->GetInteractionState();
if (state != vtkPointCloudRepresentation::Over)
{
return;
}
// We are definitely selected
self->WidgetState = vtkPointCloudWidget::Active;
if (!self->Parent)
{
self->GrabFocus(self->EventCallbackCommand);
}
// Something has changed, so render to see the changes
self->EventCallbackCommand->SetAbortFlag(1);
self->InvokeEvent(vtkCommand::WidgetActivateEvent, nullptr);
self->Render();
}
//------------------------------------------------------------------------------
void vtkPointCloudWidget::EndSelectAction(vtkAbstractWidget* w)
{
vtkPointCloudWidget* self = reinterpret_cast<vtkPointCloudWidget*>(w);
if (self->WidgetState == vtkPointCloudWidget::Start)
{
return;
}
// Return state to not active
self->WidgetState = vtkPointCloudWidget::Start;
reinterpret_cast<vtkPointCloudRepresentation*>(self->WidgetRep)
->SetInteractionState(vtkPointCloudRepresentation::Outside);
self->ReleaseFocus();
self->Render();
}
//------------------------------------------------------------------------------
void vtkPointCloudWidget::CreateDefaultRepresentation()
{
if (!this->WidgetRep)
{
this->WidgetRep = vtkPointCloudRepresentation::New();
}
}
//------------------------------------------------------------------------------
void vtkPointCloudWidget::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}