Slicer  5.0
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
vtkMRMLSliceIntersectionWidget.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkMRMLSliceIntersectionWidget.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or https://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
25 #ifndef vtkMRMLSliceIntersectionWidget_h
26 #define vtkMRMLSliceIntersectionWidget_h
27 
28 #include "vtkMRMLDisplayableManagerExport.h" // For export macro
29 #include "vtkMRMLAbstractWidget.h"
30 #include "vtkMRMLSliceLogic.h"
31 #include "vtkMRMLSliceNode.h"
32 
33 #include <vtkCallbackCommand.h>
34 #include <vtkCollection.h>
35 #include <vtkSmartPointer.h>
36 #include <vtkWeakPointer.h>
37 
38 class vtkSliceIntersectionRepresentation2D;
42 
43 class VTK_MRML_DISPLAYABLEMANAGER_EXPORT vtkMRMLSliceIntersectionWidget : public vtkMRMLAbstractWidget
44 {
45 public:
49  static vtkMRMLSliceIntersectionWidget *New();
50 
52 
56  void PrintSelf(ostream& os, vtkIndent indent) override;
58 
62  void CreateDefaultRepresentation();
63 
64  void SetSliceNode(vtkMRMLSliceNode* sliceNode);
65  vtkMRMLSliceNode* GetSliceNode();
66 
67  vtkMRMLSliceDisplayNode* GetSliceDisplayNode();
68 
69  void SetMRMLApplicationLogic(vtkMRMLApplicationLogic* applicationLogic) override;
70 
72  bool CanProcessInteractionEvent(vtkMRMLInteractionEventData* eventData, double &distance2) override;
73 
75  bool ProcessInteractionEvent(vtkMRMLInteractionEventData* eventData) override;
76 
78  void Leave(vtkMRMLInteractionEventData* eventData) override;
79 
81  enum
82  {
83  // Interactions without handles
84  WidgetStateMoveCrosshair = WidgetStateUser,
90 
91  // Interactions with slice intersection handles
98 
99  WidgetState_Last
100  };
101 
103  enum
104  {
105  // Interactions without handles
106  WidgetEventTouchGestureStart = WidgetEventUser,
122  WidgetEventToggleAllSlicesVisibility, // currently does not work, only toggles current slice
128  WidgetEventRotateIntersectingSlicesStart, // rotate all intersecting slices (ctrl-alt-left-click-and-drag)
135  WidgetEventSetCrosshairPositionBackground, //< set crosshair position without consuming the event (so that other widgets can process the event)
137 
138  // Interactions with slice intersection handles
139  // WidgetStateOnTranslateIntersectingSlicesHandle/WidgetStateTranslateIntersectingSlicesHandle
142  // WidgetStateOnRotateIntersectingSlicesHandle/WidgetStateRotateIntersectingSlicesHandle
145  // WidgetStateOnTranslateSingleIntersectingSliceHandle/WidgetStateOnTranslateSingleIntersectingSliceHandle
148  };
149 
151  enum
152  {
153  ActionNone = 0,
154  ActionTranslate = 1,
155  ActionZoom = 2,
156  ActionRotate = 4, /* not used */
157  ActionBlend = 8, /* fg to bg, labelmap to bg */
158  ActionBrowseSlice = 64,
159  ActionShowSlice = 128,
160  ActionAdjustLightbox = 256,
161  ActionSelectVolume = 512,
162  ActionSetCursorPosition = 1024, /* adjust cursor position in crosshair node as mouse is moved */
163  ActionSetCrosshairPosition = 2048, /* adjust cursor position in crosshair node as mouse is moved */
164  ActionTranslateSliceIntersection = 4096,
165  ActionRotateSliceIntersection = 8192,
166  ActionAll = ActionTranslate | ActionZoom | ActionRotate | ActionBlend
167  | ActionBrowseSlice | ActionShowSlice | ActionAdjustLightbox | ActionSelectVolume
168  | ActionSetCursorPosition | ActionSetCrosshairPosition
169  | ActionTranslateSliceIntersection | ActionRotateSliceIntersection
170  };
171 
173  void SetActionsEnabled(int actions);
174 
176  int GetActionsEnabled();
177 
182  void SetActionEnabled(int actionsMask, bool enable = true);
185  bool GetActionEnabled(int actionsMask);
186 
187  void UpdateInteractionEventMapping();
188 
189  // Allows the widget to request a cursor shape
190  int GetMouseCursor() override;
191 
192 protected:
194  ~vtkMRMLSliceIntersectionWidget() override;
195 
196  bool ProcessStartMouseDrag(vtkMRMLInteractionEventData* eventData);
197  bool ProcessMouseMove(vtkMRMLInteractionEventData* eventData);
198  bool ProcessEndMouseDrag(vtkMRMLInteractionEventData* eventData);
199  bool ProcessBlend(vtkMRMLInteractionEventData* eventData);
200 
201  bool ProcessRotateIntersectingSlicesStart(vtkMRMLInteractionEventData* eventData);
202  bool ProcessRotateIntersectingSlices(vtkMRMLInteractionEventData* eventData);
203  bool ProcessSetCrosshair(vtkMRMLInteractionEventData* eventData);
204  bool ProcessSetCrosshairBackground(vtkMRMLInteractionEventData* eventData);
205  double GetSliceRotationAngleRad(double eventPos[2]);
206 
207  // Pan (move slice in-plane) by click-and-drag
208  bool ProcessTranslateSlice(vtkMRMLInteractionEventData* eventData);
209 
210  bool ProcessZoomSlice(vtkMRMLInteractionEventData* eventData);
211 
212  bool ProcessTouchGestureStart(vtkMRMLInteractionEventData* eventData);
213  bool ProcessTouchGestureEnd(vtkMRMLInteractionEventData* eventData);
214  bool ProcessTouchRotate(vtkMRMLInteractionEventData* eventData);
215  bool ProcessTouchZoom(vtkMRMLInteractionEventData* eventData);
216  bool ProcessTouchTranslate(vtkMRMLInteractionEventData* eventData);
217 
218  bool ProcessTranslateIntersectingSlicesHandleStart(vtkMRMLInteractionEventData* eventData);
219  bool ProcessTranslateIntersectingSlicesHandle(vtkMRMLInteractionEventData* eventData);
220  bool ProcessTranslateSingleIntersectingSliceHandleStart(vtkMRMLInteractionEventData* eventData);
221  bool ProcessTranslateSingleIntersectingSliceHandle(vtkMRMLInteractionEventData* eventData);
222  bool ProcessRotateIntersectingSlicesHandleStart(vtkMRMLInteractionEventData* eventData);
223  bool ProcessRotateIntersectingSlicesHandle(vtkMRMLInteractionEventData* eventData);
224 
225  bool ProcessWidgetMenu(vtkMRMLInteractionEventData* eventData);
226 
227  bool ProcessMaximizeView(vtkMRMLInteractionEventData* eventData);
228 
230  bool Rotate(double sliceRotationAngleRad);
231 
235  void ScaleZoom(double zoomScaleFactor, vtkMRMLInteractionEventData* eventData);
236 
238  void SetLabelOpacity(double opacity);
239  double GetLabelOpacity();
240 
243  bool IsEventInsideVolume(bool background, vtkMRMLInteractionEventData* eventData);
244 
245  vtkMRMLSegmentationDisplayNode* GetVisibleSegmentationDisplayNode();
246 
247  static void SliceModifiedCallback(vtkObject* caller, unsigned long eid, void* clientData, void* callData);
248  static void SliceLogicsModifiedCallback(vtkObject* caller, unsigned long eid, void* clientData, void* callData);
249 
250  vtkWeakPointer<vtkCollection> SliceLogics;
251  vtkWeakPointer<vtkMRMLSliceNode> SliceNode;
252  vtkWeakPointer<vtkMRMLSliceLogic> SliceLogic;
253  vtkNew<vtkCallbackCommand> SliceLogicsModifiedCommand;
254  vtkNew<vtkCallbackCommand> SliceModifiedCommand;
255 
256  double StartEventPosition[2];
258  int PreviousEventPosition[2];
259  double StartRotationCenter[2];
260  double StartRotationCenter_RAS[4];
261 
262  double StartTranslationPoint[2];
263  double StartTranslationPoint_RAS[3];
264  double CurrentTranslationPoint_RAS[3];
265 
266  double StartActionFOV[3];
267  double VolumeScalarRange[2];
268 
269  enum
270  {
273  LayerLabelmap
274  };
275 
276  // Blend
280 
281  // Browse slice
285  double GetSliceSpacing();
287  void IncrementSlice();
288  void DecrementSlice();
289  void MoveSlice(double delta);
290 
296  void CycleVolumeLayer(int layer, int direction);
297 
298  bool IsSliceIntersectionInteractive();
299 
303 
305 
315 
316  // Last intersecting slice node where interaction occurred
318 
319 private:
321  void operator=(const vtkMRMLSliceIntersectionWidget&) = delete;
322 };
323 
324 #endif
virtual bool CanProcessInteractionEvent(vtkMRMLInteractionEventData *eventData, double &distance2)
vtkMRMLSegmentationDisplayNode * StartActionSegmentationDisplayNode
vtkWeakPointer< vtkMRMLSliceNode > SliceNode
MRML node to store display properties of slice nodes.
MRML node for storing a slice through RAS space.
Zoom slice (using right-button or mouse wheel)
vtkWeakPointer< vtkMRMLSliceLogic > SliceLogic
vtkWeakPointer< vtkCollection > SliceLogics
translating all intersecting slices by drag-and-dropping handle
vtkNew< vtkCallbackCommand > SliceLogicsModifiedCommand
MRML node for representing segmentation display attributes.
this is a starting index that can be used for widget-specific events
virtual bool ProcessInteractionEvent(vtkMRMLInteractionEventData *eventData)
virtual void Leave(vtkMRMLInteractionEventData *eventData)
Called when the the widget loses the focus.
void PrintSelf(ostream &os, vtkIndent indent) override
virtual int GetMouseCursor()
Fade between foreground/background volumes.
virtual void SetMRMLApplicationLogic(vtkMRMLApplicationLogic *applicationLogic)
Rotate all intersecting slices (ctrl+alt+left-click-and-drag)
Process interaction events to update state of MRML widget nodes.
vtkNew< vtkCallbackCommand > SliceModifiedCommand
this is a starting index that can be used for widget-specific states
Pan (translate in-plane) the current slice (using shift+left-click-and-drag or middle-click-and-drag)...
rotating all intersecting slices by drag-and-dropping handle