Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkDisplayActionEventFunctions.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 
14 
15 // mitk core
16 #include "mitkBaseRenderer.h"
17 #include "mitkCameraController.h"
20 #include "mitkLevelWindow.h"
23 
25 // STANDARD FUNCTIONS
28 {
29  mitk::StdFunctionCommand::ActionFunction actionFunction = [](const itk::EventObject& displayInteractorEvent)
30  {
31  if (DisplayMoveEvent().CheckEvent(&displayInteractorEvent))
32  {
33  const DisplayMoveEvent* displayActionEvent = dynamic_cast<const DisplayMoveEvent*>(&displayInteractorEvent);
34  const BaseRenderer::Pointer sendingRenderer = displayActionEvent->GetSender();
35  if (nullptr == sendingRenderer)
36  {
37  return;
38  }
39 
40  sendingRenderer->GetCameraController()->MoveBy(displayActionEvent->GetMoveVector());
41  RenderingManager::GetInstance()->RequestUpdate(sendingRenderer->GetRenderWindow());
42  }
43  };
44 
45  return actionFunction;
46 }
47 
49 {
50  auto actionFunction = [](const itk::EventObject& displayInteractorEvent)
51  {
52  if (DisplaySetCrosshairEvent().CheckEvent(&displayInteractorEvent))
53  {
54  const DisplaySetCrosshairEvent* displayActionEvent = dynamic_cast<const DisplaySetCrosshairEvent*>(&displayInteractorEvent);
55  const BaseRenderer::Pointer sendingRenderer = displayActionEvent->GetSender();
56  if (nullptr == sendingRenderer)
57  {
58  return;
59  }
60 
61  BaseRenderer::GetInstance(sendingRenderer->GetRenderWindow())->GetSliceNavigationController()->SelectSliceByPoint(displayActionEvent->GetPosition());
62  }
63  };
64 
65  return actionFunction;
66 }
67 
69 {
70  auto actionFunction = [](const itk::EventObject& displayInteractorEvent)
71  {
72  if (DisplayZoomEvent().CheckEvent(&displayInteractorEvent))
73  {
74  const DisplayZoomEvent* displayActionEvent = dynamic_cast<const DisplayZoomEvent*>(&displayInteractorEvent);
75  const BaseRenderer::Pointer sendingRenderer = displayActionEvent->GetSender();
76  if (nullptr == sendingRenderer)
77  {
78  return;
79  }
80 
81  if (1.0 != displayActionEvent->GetZoomFactor())
82  {
83  sendingRenderer->GetCameraController()->Zoom(displayActionEvent->GetZoomFactor(), displayActionEvent->GetStartCoordinate());
84  RenderingManager::GetInstance()->RequestUpdate(sendingRenderer->GetRenderWindow());
85  }
86  }
87  };
88 
89  return actionFunction;
90 }
91 
93 {
94  auto actionFunction = [](const itk::EventObject& displayInteractorEvent)
95  {
96  if (DisplayScrollEvent().CheckEvent(&displayInteractorEvent))
97  {
98  const DisplayScrollEvent* displayActionEvent = dynamic_cast<const DisplayScrollEvent*>(&displayInteractorEvent);
99  const BaseRenderer::Pointer sendingRenderer = displayActionEvent->GetSender();
100  if (nullptr == sendingRenderer)
101  {
102  return;
103  }
104 
105  mitk::SliceNavigationController* sliceNavigationController = sendingRenderer->GetSliceNavigationController();
106  if (nullptr == sliceNavigationController)
107  {
108  return;
109  }
110  if (sliceNavigationController->GetSliceLocked())
111  {
112  return;
113  }
114  mitk::Stepper* sliceStepper = sliceNavigationController->GetSlice();
115  if (nullptr == sliceStepper)
116  {
117  return;
118  }
119 
120  // if only a single slice image was loaded, scrolling will affect the time steps
121  if (sliceStepper->GetSteps() <= 1)
122  {
123  sliceStepper = sliceNavigationController->GetTime();
124  }
125 
126  sliceStepper->MoveSlice(displayActionEvent->GetSliceDelta());
127  }
128  };
129 
130  return actionFunction;
131 }
132 
134 {
135  auto actionFunction = [](const itk::EventObject& displayInteractorEvent)
136  {
137  if (DisplaySetLevelWindowEvent().CheckEvent(&displayInteractorEvent))
138  {
139  const DisplaySetLevelWindowEvent* displayActionEvent = dynamic_cast<const DisplaySetLevelWindowEvent*>(&displayInteractorEvent);
140  const BaseRenderer::Pointer sendingRenderer = displayActionEvent->GetSender();
141  if (nullptr == sendingRenderer)
142  {
143  return;
144  }
145 
146  // get the the topmost visible image of the sending renderer
147  DataStorage::Pointer storage = sendingRenderer->GetDataStorage();
148  DataStorage::SetOfObjects::ConstPointer allImageNodes = storage->GetSubset(NodePredicateDataType::New("Image"));
149  Point3D worldposition;
150  const auto* positionEvent = dynamic_cast<const InteractionPositionEvent*>(displayActionEvent->GetInteractionEvent());
151  sendingRenderer->DisplayToWorld(positionEvent->GetPointerPositionOnScreen(), worldposition);
152  auto globalCurrentTimePoint = sendingRenderer->GetTime();
153  DataNode::Pointer node = FindTopmostVisibleNode(allImageNodes, worldposition, globalCurrentTimePoint, sendingRenderer);
154  if (node.IsNull())
155  {
156  return;
157  }
158 
159  LevelWindow levelWindow = LevelWindow();
160  node->GetLevelWindow(levelWindow);
161  ScalarType level = levelWindow.GetLevel();
162  ScalarType window = levelWindow.GetWindow();
163 
164  level += displayActionEvent->GetLevel();
165  window += displayActionEvent->GetWindow();
166 
167  levelWindow.SetLevelWindow(level, window);
168  auto* levelWindowProperty = dynamic_cast<LevelWindowProperty*>(node->GetProperty("levelwindow"));
169  if (nullptr != levelWindowProperty)
170  {
171  levelWindowProperty->SetLevelWindow(levelWindow);
172  RenderingManager::GetInstance()->RequestUpdateAll();
173  }
174  }
175  };
176 
177  return actionFunction;
178 }
179 
181 // SYNCHRONIZED FUNCTIONS
184 {
185  mitk::StdFunctionCommand::ActionFunction actionFunction = [](const itk::EventObject& displayInteractorEvent)
186  {
187  if (DisplayMoveEvent().CheckEvent(&displayInteractorEvent))
188  {
189  const DisplayMoveEvent* displayActionEvent = dynamic_cast<const DisplayMoveEvent*>(&displayInteractorEvent);
190  const BaseRenderer::Pointer sendingRenderer = displayActionEvent->GetSender();
191  if (nullptr == sendingRenderer)
192  {
193  return;
194  }
195 
196  auto renderingManager = RenderingManager::GetInstance();
197  auto allRenderWindows = renderingManager->GetAllRegisteredRenderWindows();
198  for (auto renderWindow : allRenderWindows)
199  {
200  if (BaseRenderer::GetInstance(renderWindow)->GetMapperID() == BaseRenderer::Standard2D)
201  {
202  BaseRenderer* currentRenderer = BaseRenderer::GetInstance(renderWindow);
203  currentRenderer->GetCameraController()->MoveBy(displayActionEvent->GetMoveVector());
204  renderingManager->RequestUpdate(currentRenderer->GetRenderWindow());
205  }
206  }
207  }
208  };
209 
210  return actionFunction;
211 }
212 
214 {
215  auto actionFunction = [](const itk::EventObject& displayInteractorEvent)
216  {
217  if (DisplaySetCrosshairEvent().CheckEvent(&displayInteractorEvent))
218  {
219  const DisplaySetCrosshairEvent* displayActionEvent = dynamic_cast<const DisplaySetCrosshairEvent*>(&displayInteractorEvent);
220  const BaseRenderer::Pointer sendingRenderer = displayActionEvent->GetSender();
221  if (nullptr == sendingRenderer)
222  {
223  return;
224  }
225 
226  auto allRenderWindows = RenderingManager::GetInstance()->GetAllRegisteredRenderWindows();
227  for (auto renderWindow : allRenderWindows)
228  {
229  if (BaseRenderer::GetInstance(renderWindow)->GetMapperID() == BaseRenderer::Standard2D)
230  {
231  BaseRenderer::GetInstance(renderWindow)->GetSliceNavigationController()->SelectSliceByPoint(displayActionEvent->GetPosition());
232  }
233  }
234  }
235  };
236 
237  return actionFunction;
238 }
239 
241 {
242  auto actionFunction = [](const itk::EventObject& displayInteractorEvent)
243  {
244  if (DisplayZoomEvent().CheckEvent(&displayInteractorEvent))
245  {
246  const DisplayZoomEvent* displayActionEvent = dynamic_cast<const DisplayZoomEvent*>(&displayInteractorEvent);
247  const BaseRenderer::Pointer sendingRenderer = displayActionEvent->GetSender();
248  if (nullptr == sendingRenderer)
249  {
250  return;
251  }
252 
253  if (1.0 != displayActionEvent->GetZoomFactor())
254  {
255  auto renderingManager = RenderingManager::GetInstance();
256  auto allRenderWindows = renderingManager->GetAllRegisteredRenderWindows();
257  for (auto renderWindow : allRenderWindows)
258  {
259  if (BaseRenderer::GetInstance(renderWindow)->GetMapperID() == BaseRenderer::Standard2D)
260  {
261  BaseRenderer* currentRenderer = BaseRenderer::GetInstance(renderWindow);
262  currentRenderer->GetCameraController()->Zoom(displayActionEvent->GetZoomFactor(), displayActionEvent->GetStartCoordinate());
263  renderingManager->RequestUpdate(currentRenderer->GetRenderWindow());
264  }
265  }
266  }
267  }
268  };
269 
270  return actionFunction;
271 }
272 
274 {
275  auto actionFunction = [](const itk::EventObject& displayInteractorEvent)
276  {
277  if (DisplayScrollEvent().CheckEvent(&displayInteractorEvent))
278  {
279  const DisplayScrollEvent* displayActionEvent = dynamic_cast<const DisplayScrollEvent*>(&displayInteractorEvent);
280  const BaseRenderer::Pointer sendingRenderer = displayActionEvent->GetSender();
281  if (nullptr == sendingRenderer)
282  {
283  return;
284  }
285 
286  auto allRenderWindows = RenderingManager::GetInstance()->GetAllRegisteredRenderWindows();
287  for (auto renderWindow : allRenderWindows)
288  {
289  if (BaseRenderer::GetInstance(renderWindow)->GetMapperID() == BaseRenderer::Standard2D)
290  {
291  mitk::SliceNavigationController* sliceNavigationController = BaseRenderer::GetInstance(renderWindow)->GetSliceNavigationController();
292  if (nullptr == sliceNavigationController)
293  {
294  return;
295  }
296  if (sliceNavigationController->GetSliceLocked())
297  {
298  return;
299  }
300  mitk::Stepper* sliceStepper = sliceNavigationController->GetSlice();
301  if (nullptr == sliceStepper)
302  {
303  return;
304  }
305 
306  // if only a single slice image was loaded, scrolling will affect the time steps
307  if (sliceStepper->GetSteps() <= 1)
308  {
309  sliceStepper = sliceNavigationController->GetTime();
310  }
311 
312  sliceStepper->MoveSlice(displayActionEvent->GetSliceDelta());
313  }
314  }
315  }
316  };
317 
318  return actionFunction;
319 }
mitk::Stepper * GetSlice()
Get the Stepper through the slices.
ScalarType GetLevel() const
method that returns the level value, i.e. the center of the current grey value interval ...
MITKCORE_EXPORT StdFunctionCommand::ActionFunction ZoomCameraSynchronizedAction()
Returns an &#39;std::function&#39; that can be used to react on the &#39;DisplayZoomEvent&#39;. The function performs...
Super class for all position events.
MITKCORE_EXPORT StdFunctionCommand::ActionFunction SetLevelWindowAction()
Returns an &#39;std::function&#39; that can be used to react on the &#39;DisplaySetLevelWindowEvent&#39;. The function sets the &#39;levelwindow&#39; property of the topmost visible image that is display by the sending renderer. The level and window value for this property were previously determined by the mouse interaction event.
void SelectSliceByPoint(const mitk::Point3D &point)
Positions the SNC according to the specified point.
The LevelWindowProperty class Property for the mitk::LevelWindow.
bool CheckEvent(const itk::EventObject *e) const override
bool CheckEvent(const itk::EventObject *e) const override
bool CheckEvent(const itk::EventObject *e) const override
double ScalarType
MITKCORE_EXPORT StdFunctionCommand::ActionFunction ScrollSliceStepperSynchronizedAction()
Returns an &#39;std::function&#39; that can be used to react on the &#39;DisplayScrollEvent&#39;. The function perfor...
void Zoom(ScalarType factor, const Point2D &zoomPointInMM)
Organizes the rendering process.
const Point2D & GetStartCoordinate() const
MITKCORE_EXPORT StdFunctionCommand::ActionFunction MoveCameraSynchronizedAction()
Returns an &#39;std::function&#39; that can be used to react on the &#39;DisplayMoveEvent&#39;. The function performs...
bool CheckEvent(const itk::EventObject *e) const override
void MoveBy(const Vector2D &moveVectorInMM)
bool CheckEvent(const itk::EventObject *e) const override
Controls the selection of the slice the associated BaseRenderer will display.
The LevelWindow class Class to store level/window values.
MITKCORE_EXPORT StdFunctionCommand::ActionFunction SetCrosshairAction()
Returns an &#39;std::function&#39; that can be used to react on the &#39;DisplaySetCrosshairEvent&#39;. The function performs a slice selection of the slice navigation controller and will set the cross hair for all 2D-render windows. The new position was previously determined by the mouse interaction event.
void SetLevelWindow(const LevelWindow &levWin)
std::function< void(const itk::EventObject &)> ActionFunction
virtual CameraController * GetCameraController()
virtual void MoveSlice(int sliceDelta)
BaseRenderer * GetSender() const
ScalarType GetWindow() const
returns the current window size, i.e the range size of the current grey value interval ...
MITKCORE_EXPORT StdFunctionCommand::ActionFunction ZoomSenderCameraAction()
Returns an &#39;std::function&#39; that can be used to react on the &#39;DisplayZoomEvent&#39;. The function performs...
MITKCORE_EXPORT StdFunctionCommand::ActionFunction MoveSenderCameraAction()
Returns an &#39;std::function&#39; that can be used to react on the &#39;DisplayMoveEvent&#39;. The function performs...
vtkRenderWindow * GetRenderWindow() const
Access the RenderWindow into which this renderer renders.
Helper class to step through a list.
Definition: mitkStepper.h:47
InteractionEvent * GetInteractionEvent() const
virtual unsigned int GetSteps() const
const Vector2D & GetMoveVector() const
virtual SliceNavigationController * GetSliceNavigationController()
mitk::Stepper * GetTime()
Get the Stepper through the time.
MITKCORE_EXPORT StdFunctionCommand::ActionFunction SetCrosshairSynchronizedAction()
Returns an &#39;std::function&#39; that can be used to react on the &#39;DisplaySetCrosshairEvent&#39;. The function performs a slice selection of the slice navigation controller and will set the cross hair for all 2D-render windows. The new position was previously determined by the mouse interaction event. #TODO: currently there is no need to distinguish between this and the non-synchronized version.
void SetLevelWindow(ScalarType level, ScalarType window, bool expandRangesIfNecessary=true)
MITKCORE_EXPORT DataNode::Pointer FindTopmostVisibleNode(const DataStorage::SetOfObjects::ConstPointer nodes, const Point3D worldPosition, const TimePointType timePoint, const BaseRenderer *baseRender)
returns the topmost visible node of a given list of nodes. The function returns a node that is visibl...
MITKCORE_EXPORT StdFunctionCommand::ActionFunction ScrollSliceStepperAction()
Returns an &#39;std::function&#39; that can be used to react on the &#39;DisplayScrollEvent&#39;. The function perfor...