Medical Imaging Interaction Toolkit  2016.11.0
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,
6  Division of Medical and Biological Informatics.
7  All rights reserved.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without
10  even the implied warranty of MERCHANTABILITY or FITNESS FOR
11  A PARTICULAR PURPOSE.
12 
13  See LICENSE.txt or http://www.mitk.org for details.
14 
15  ===================================================================*/
16 
17 #include "mitkVtkEventAdapter.h"
19 #include "vtkCommand.h"
20 #include <mitkInteractionConst.h> // INTERACTION LEGACY
21 #include <string.h>
22 
23 namespace mitk
24 {
25  std::map<BaseRenderer *, int> VtkEventAdapter::buttonStateMap;
26 }
27 
29  unsigned long vtkCommandEventId,
30  vtkRenderWindowInteractor *rwi)
31 {
32  mitk::Point2D point;
33  point[0] = rwi->GetEventPosition()[0];
34  point[1] = rwi->GetEventPosition()[1];
35 
36  int modifiers = 0;
37 
38  // vtkRenderWindowInteractor does not provide information about mouse buttons during
39  // mouse move events therefore the Press/Release functions update the button state in the buttonStateMap
40  // this button state is then provided for mouse move events
41 
42  int buttonState = 0;
43 
44  if (buttonStateMap.find(sender) != buttonStateMap.end())
45  {
46  // set stored button state
47  buttonState = buttonStateMap.find(sender)->second;
48  }
49 
50  if (vtkCommandEventId == vtkCommand::MouseMoveEvent)
51  {
52  if (buttonState != 0)
53  {
54  modifiers = buttonState;
55  }
56  }
57  else
58  {
59  MITK_WARN << "Wrong usage of function AdaptMouseMoveEvent. Wrong input type.";
60  }
61 
62  if (rwi->GetShiftKey())
63  {
64  modifiers |= InteractionEvent::ShiftKey;
65  }
66  if (rwi->GetControlKey())
67  {
68  modifiers |= InteractionEvent::ControlKey;
69  }
70  if (rwi->GetAltKey())
71  {
72  modifiers |= InteractionEvent::AltKey;
73  }
74 
76  point,
77  static_cast<InteractionEvent::MouseButtons>(buttonState),
78  static_cast<InteractionEvent::ModifierKeys>(modifiers));
79  return mme;
80 }
81 
83  unsigned long vtkCommandEventId,
84  vtkRenderWindowInteractor *rwi)
85 {
86  mitk::Point2D point;
87  point[0] = rwi->GetEventPosition()[0];
88  point[1] = rwi->GetEventPosition()[1];
89 
90  int button = 0;
91  int modifiers = 0;
92  int buttonState = 0;
93 
94  // vtkRenderWindowInteractor does not provide information about mouse buttons during
95  // mouse move events therefore the Press/Release functions update the button state in the buttonStateMap
96  // this button state is then provided for mouse move events
97 
98  if (buttonStateMap.find(sender) != buttonStateMap.end())
99  buttonState = buttonStateMap.find(sender)->second;
100 
101  if (buttonState != 0 && vtkCommandEventId != vtkCommand::MouseMoveEvent)
102  buttonStateMap.erase(buttonStateMap.find(sender)); // press or release event with active map caching
103 
104  switch (vtkCommandEventId)
105  {
106  case vtkCommand::LeftButtonReleaseEvent:
108  // remove left mouse button from button state
109  buttonStateMap[sender] = (buttonState - button);
110  break;
111  case vtkCommand::MiddleButtonReleaseEvent:
113  // remove middle button from button state
114  buttonStateMap[sender] = (buttonState - button);
115  break;
116  case vtkCommand::RightButtonReleaseEvent:
118  // remove right mouse button from button state
119  buttonStateMap[sender] = (buttonState - button);
120  break;
121  }
122 
123  if (rwi->GetShiftKey())
124  {
125  modifiers |= InteractionEvent::ShiftKey;
126  }
127  if (rwi->GetControlKey())
128  {
129  modifiers |= InteractionEvent::ControlKey;
130  }
131  if (rwi->GetAltKey())
132  {
133  modifiers |= InteractionEvent::AltKey;
134  }
135 
136  // after releasing button is no longer pressed, to update it
137  if (buttonStateMap.find(sender) != buttonStateMap.end())
138  {
139  buttonState = buttonStateMap.find(sender)->second;
140  }
141 
143  point,
144  static_cast<InteractionEvent::MouseButtons>(buttonState),
145  static_cast<InteractionEvent::ModifierKeys>(modifiers),
146  static_cast<InteractionEvent::MouseButtons>(button));
147  return mre;
148 }
149 
151  unsigned long vtkCommandEventId,
152  vtkRenderWindowInteractor *rwi)
153 {
154  mitk::Point2D p;
155  p[0] = rwi->GetEventPosition()[0];
156  p[1] = rwi->GetEventPosition()[1];
157 
158  int delta = 0;
159  switch (vtkCommandEventId)
160  {
161  case vtkCommand::MouseWheelForwardEvent:
162  delta = +120; // http://doc.trolltech.com/3.3/qwheelevent.html#delta
163  break;
164  case vtkCommand::MouseWheelBackwardEvent:
165  delta = -120; // http://doc.trolltech.com/3.3/qwheelevent.html#delta
166  break;
167  }
168 
169  int modifiers = 0;
170  if (rwi->GetShiftKey())
171  {
172  modifiers |= mitk::BS_ShiftButton;
173  }
174  if (rwi->GetControlKey())
175  {
176  modifiers |= mitk::BS_ControlButton;
177  }
178  if (rwi->GetAltKey())
179  {
180  modifiers |= mitk::BS_AltButton;
181  }
182 
183  mitk::Point2D point;
184  point[0] = rwi->GetEventPosition()[0];
185  point[1] = rwi->GetEventPosition()[1];
186 
187  // vtkWheelEvent does not have a buttonState or event button
188  int buttonState = 0;
190  point,
191  static_cast<InteractionEvent::MouseButtons>(buttonState),
192  static_cast<InteractionEvent::ModifierKeys>(modifiers),
193  delta);
194  return mpe;
195 }
196 
198  unsigned long vtkCommandEventId,
199  vtkRenderWindowInteractor *rwi)
200 {
201  if (vtkCommandEventId != vtkCommand::KeyPressEvent)
202  {
203  MITK_WARN << "mitk::VtkEventAdapter::AdaptInteractionKeyEvent() called with wrong argument";
204  return NULL;
205  }
206  int modifiers = 0;
207  if (rwi->GetShiftKey())
208  {
209  modifiers |= mitk::BS_ShiftButton;
210  }
211  if (rwi->GetControlKey())
212  {
213  modifiers |= mitk::BS_ControlButton;
214  }
215  if (rwi->GetAltKey())
216  {
217  modifiers |= mitk::BS_AltButton;
218  }
220  sender, std::string(rwi->GetKeySym()), static_cast<InteractionEvent::ModifierKeys>(modifiers));
221  return ike;
222 }
223 
225  unsigned long vtkCommandEventId,
226  vtkRenderWindowInteractor *rwi)
227 {
228  mitk::Point2D point;
229  point[0] = rwi->GetEventPosition()[0];
230  point[1] = rwi->GetEventPosition()[1];
231 
232  int button = 0;
233  int modifiers = 0;
234  int buttonState = 0;
235 
236  // vtkRenderWindowInteractor does not provide information about mouse buttons during
237  // mouse move events therefore the Press/Release functions update the button state in the buttonStateMap
238  // this button state is then provided for mouse move events
239 
240  if (buttonStateMap.find(sender) != buttonStateMap.end())
241  buttonState = buttonStateMap.find(sender)->second;
242 
243  if (buttonState != 0 && vtkCommandEventId != vtkCommand::MouseMoveEvent)
244  buttonStateMap.erase(buttonStateMap.find(sender)); // press or release event with active map caching
245 
246  switch (vtkCommandEventId)
247  {
248  case vtkCommand::LeftButtonPressEvent:
250  buttonState |= button;
251  buttonStateMap[sender] = buttonState;
252  break;
253  case vtkCommand::MiddleButtonPressEvent:
255  buttonState |= button;
256  buttonStateMap[sender] = buttonState;
257  break;
258  case vtkCommand::RightButtonPressEvent:
260  buttonState |= button;
261  buttonStateMap[sender] = buttonState;
262  break;
263  }
264 
265  if (rwi->GetShiftKey())
266  {
267  modifiers |= InteractionEvent::ShiftKey;
268  }
269  if (rwi->GetControlKey())
270  {
271  modifiers |= InteractionEvent::ControlKey;
272  }
273  if (rwi->GetAltKey())
274  {
275  modifiers |= InteractionEvent::AltKey;
276  }
277 
279  point,
280  static_cast<InteractionEvent::MouseButtons>(buttonState),
281  static_cast<InteractionEvent::ModifierKeys>(modifiers),
282  static_cast<InteractionEvent::MouseButtons>(button));
283  return mpe;
284 }
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:23
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