Medical Imaging Interaction Toolkit  2018.4.99-3e3f1a6e
Medical Imaging Interaction Toolkit
mitkVtkEventAdapter.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "mitkVtkEventAdapter.h"
15 #include "vtkCommand.h"
16 #include <mitkInteractionConst.h> // INTERACTION LEGACY
17 #include <cstring>
18 
19 namespace mitk
20 {
21  std::map<BaseRenderer *, int> VtkEventAdapter::buttonStateMap;
22 }
23 
25  unsigned long vtkCommandEventId,
26  vtkRenderWindowInteractor *rwi)
27 {
28  mitk::Point2D point;
29  point[0] = rwi->GetEventPosition()[0];
30  point[1] = rwi->GetEventPosition()[1];
31 
32  int modifiers = 0;
33 
34  // vtkRenderWindowInteractor does not provide information about mouse buttons during
35  // mouse move events therefore the Press/Release functions update the button state in the buttonStateMap
36  // this button state is then provided for mouse move events
37 
38  int buttonState = 0;
39 
40  if (buttonStateMap.find(sender) != buttonStateMap.end())
41  {
42  // set stored button state
43  buttonState = buttonStateMap.find(sender)->second;
44  }
45 
46  if (vtkCommandEventId == vtkCommand::MouseMoveEvent)
47  {
48  if (buttonState != 0)
49  {
50  modifiers = buttonState;
51  }
52  }
53  else
54  {
55  MITK_WARN << "Wrong usage of function AdaptMouseMoveEvent. Wrong input type.";
56  }
57 
58  if (rwi->GetShiftKey())
59  {
60  modifiers |= InteractionEvent::ShiftKey;
61  }
62  if (rwi->GetControlKey())
63  {
64  modifiers |= InteractionEvent::ControlKey;
65  }
66  if (rwi->GetAltKey())
67  {
68  modifiers |= InteractionEvent::AltKey;
69  }
70 
72  point,
73  static_cast<InteractionEvent::MouseButtons>(buttonState),
74  static_cast<InteractionEvent::ModifierKeys>(modifiers));
75  return mme;
76 }
77 
79  unsigned long vtkCommandEventId,
80  vtkRenderWindowInteractor *rwi)
81 {
82  mitk::Point2D point;
83  point[0] = rwi->GetEventPosition()[0];
84  point[1] = rwi->GetEventPosition()[1];
85 
86  int button = 0;
87  int modifiers = 0;
88  int buttonState = 0;
89 
90  // vtkRenderWindowInteractor does not provide information about mouse buttons during
91  // mouse move events therefore the Press/Release functions update the button state in the buttonStateMap
92  // this button state is then provided for mouse move events
93 
94  if (buttonStateMap.find(sender) != buttonStateMap.end())
95  buttonState = buttonStateMap.find(sender)->second;
96 
97  if (buttonState != 0 && vtkCommandEventId != vtkCommand::MouseMoveEvent)
98  buttonStateMap.erase(buttonStateMap.find(sender)); // press or release event with active map caching
99 
100  switch (vtkCommandEventId)
101  {
102  case vtkCommand::LeftButtonReleaseEvent:
104  // remove left mouse button from button state
105  buttonStateMap[sender] = (buttonState - button);
106  break;
107  case vtkCommand::MiddleButtonReleaseEvent:
109  // remove middle button from button state
110  buttonStateMap[sender] = (buttonState - button);
111  break;
112  case vtkCommand::RightButtonReleaseEvent:
114  // remove right mouse button from button state
115  buttonStateMap[sender] = (buttonState - button);
116  break;
117  }
118 
119  if (rwi->GetShiftKey())
120  {
121  modifiers |= InteractionEvent::ShiftKey;
122  }
123  if (rwi->GetControlKey())
124  {
125  modifiers |= InteractionEvent::ControlKey;
126  }
127  if (rwi->GetAltKey())
128  {
129  modifiers |= InteractionEvent::AltKey;
130  }
131 
132  // after releasing button is no longer pressed, to update it
133  if (buttonStateMap.find(sender) != buttonStateMap.end())
134  {
135  buttonState = buttonStateMap.find(sender)->second;
136  }
137 
139  point,
140  static_cast<InteractionEvent::MouseButtons>(buttonState),
141  static_cast<InteractionEvent::ModifierKeys>(modifiers),
142  static_cast<InteractionEvent::MouseButtons>(button));
143  return mre;
144 }
145 
147  unsigned long vtkCommandEventId,
148  vtkRenderWindowInteractor *rwi)
149 {
150  mitk::Point2D p;
151  p[0] = rwi->GetEventPosition()[0];
152  p[1] = rwi->GetEventPosition()[1];
153 
154  int delta = 0;
155  switch (vtkCommandEventId)
156  {
157  case vtkCommand::MouseWheelForwardEvent:
158  delta = +120; // http://doc.trolltech.com/3.3/qwheelevent.html#delta
159  break;
160  case vtkCommand::MouseWheelBackwardEvent:
161  delta = -120; // http://doc.trolltech.com/3.3/qwheelevent.html#delta
162  break;
163  }
164 
165  int modifiers = 0;
166  if (rwi->GetShiftKey())
167  {
168  modifiers |= mitk::BS_ShiftButton;
169  }
170  if (rwi->GetControlKey())
171  {
172  modifiers |= mitk::BS_ControlButton;
173  }
174  if (rwi->GetAltKey())
175  {
176  modifiers |= mitk::BS_AltButton;
177  }
178 
179  mitk::Point2D point;
180  point[0] = rwi->GetEventPosition()[0];
181  point[1] = rwi->GetEventPosition()[1];
182 
183  // vtkWheelEvent does not have a buttonState or event button
184  int buttonState = 0;
186  point,
187  static_cast<InteractionEvent::MouseButtons>(buttonState),
188  static_cast<InteractionEvent::ModifierKeys>(modifiers),
189  delta);
190  return mpe;
191 }
192 
194  unsigned long vtkCommandEventId,
195  vtkRenderWindowInteractor *rwi)
196 {
197  if (vtkCommandEventId != vtkCommand::KeyPressEvent)
198  {
199  MITK_WARN << "mitk::VtkEventAdapter::AdaptInteractionKeyEvent() called with wrong argument";
200  return nullptr;
201  }
202  int modifiers = 0;
203  if (rwi->GetShiftKey())
204  {
205  modifiers |= mitk::BS_ShiftButton;
206  }
207  if (rwi->GetControlKey())
208  {
209  modifiers |= mitk::BS_ControlButton;
210  }
211  if (rwi->GetAltKey())
212  {
213  modifiers |= mitk::BS_AltButton;
214  }
216  sender, std::string(rwi->GetKeySym()), static_cast<InteractionEvent::ModifierKeys>(modifiers));
217  return ike;
218 }
219 
221  unsigned long vtkCommandEventId,
222  vtkRenderWindowInteractor *rwi)
223 {
224  mitk::Point2D point;
225  point[0] = rwi->GetEventPosition()[0];
226  point[1] = rwi->GetEventPosition()[1];
227 
228  int button = 0;
229  int modifiers = 0;
230  int buttonState = 0;
231 
232  // vtkRenderWindowInteractor does not provide information about mouse buttons during
233  // mouse move events therefore the Press/Release functions update the button state in the buttonStateMap
234  // this button state is then provided for mouse move events
235 
236  if (buttonStateMap.find(sender) != buttonStateMap.end())
237  buttonState = buttonStateMap.find(sender)->second;
238 
239  if (buttonState != 0 && vtkCommandEventId != vtkCommand::MouseMoveEvent)
240  buttonStateMap.erase(buttonStateMap.find(sender)); // press or release event with active map caching
241 
242  switch (vtkCommandEventId)
243  {
244  case vtkCommand::LeftButtonPressEvent:
246  buttonState |= button;
247  buttonStateMap[sender] = buttonState;
248  break;
249  case vtkCommand::MiddleButtonPressEvent:
251  buttonState |= button;
252  buttonStateMap[sender] = buttonState;
253  break;
254  case vtkCommand::RightButtonPressEvent:
256  buttonState |= button;
257  buttonStateMap[sender] = buttonState;
258  break;
259  }
260 
261  if (rwi->GetShiftKey())
262  {
263  modifiers |= InteractionEvent::ShiftKey;
264  }
265  if (rwi->GetControlKey())
266  {
267  modifiers |= InteractionEvent::ControlKey;
268  }
269  if (rwi->GetAltKey())
270  {
271  modifiers |= InteractionEvent::AltKey;
272  }
273 
275  point,
276  static_cast<InteractionEvent::MouseButtons>(buttonState),
277  static_cast<InteractionEvent::ModifierKeys>(modifiers),
278  static_cast<InteractionEvent::MouseButtons>(button));
279  return mpe;
280 }
static Pointer New(BaseRenderer *_arga, const Point2D &_argb, MouseButtons _argc, ModifierKeys _argd, MouseButtons _arge)
static mitk::InteractionKeyEvent::Pointer AdaptInteractionKeyEvent(mitk::BaseRenderer *sender, unsigned long vtkCommandEventId, vtkRenderWindowInteractor *rwi)
static mitk::MouseReleaseEvent::Pointer AdaptMouseReleaseEvent(mitk::BaseRenderer *sender, unsigned long vtkCommandEventId, vtkRenderWindowInteractor *rwi)
Organizes the rendering process.
DataCollection - Class to facilitate loading/accessing structured data.
Constants for most interaction classes, due to the generic StateMachines.
static mitk::MousePressEvent::Pointer AdaptMousePressEvent(mitk::BaseRenderer *sender, unsigned long vtkCommandEventId, vtkRenderWindowInteractor *rwi)
static Pointer New(BaseRenderer *_arga, const Point2D &_argb, MouseButtons _argc, ModifierKeys _argd, int _arge)
#define MITK_WARN
Definition: mitkLogMacros.h:19
static Pointer New(BaseRenderer *_arga, const std::string &_argb, ModifierKeys _argc)
static Pointer New(BaseRenderer *_arga, const Point2D &_argb, MouseButtons _argc, ModifierKeys _argd)
static Pointer New(BaseRenderer *_arga, const Point2D &_argb, MouseButtons _argc, ModifierKeys _argd, MouseButtons _arge)
static mitk::MouseMoveEvent::Pointer AdaptMouseMoveEvent(mitk::BaseRenderer *sender, unsigned long vtkCommandEventId, vtkRenderWindowInteractor *rwi)
static mitk::MouseWheelEvent::Pointer AdaptMouseWheelEvent(mitk::BaseRenderer *sender, unsigned long vtkCommandEventId, vtkRenderWindowInteractor *rwi)
static std::map< BaseRenderer *, int > buttonStateMap