VTK  9.7.1
vtkInteractorStyle.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
89 #ifndef vtkInteractorStyle_h
90 #define vtkInteractorStyle_h
91 
92 #include "vtkInteractorObserver.h"
93 #include "vtkRenderingCoreModule.h" // For export macro
94 #include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
95 
96 // Motion flags
97 
98 #define VTKIS_START 0
99 #define VTKIS_NONE 0
100 
101 #define VTKIS_ROTATE 1
102 #define VTKIS_PAN 2
103 #define VTKIS_SPIN 3
104 #define VTKIS_DOLLY 4
105 #define VTKIS_ZOOM 5
106 #define VTKIS_USCALE 6
107 #define VTKIS_TIMER 7
108 #define VTKIS_FORWARDFLY 8
109 #define VTKIS_REVERSEFLY 9
110 #define VTKIS_TWO_POINTER 10
111 #define VTKIS_CLIP 11
112 #define VTKIS_PICK 12 // perform a pick at the last location
113 #define VTKIS_LOAD_CAMERA_POSE 13 // iterate through saved camera poses
114 #define VTKIS_POSITION_PROP 14 // adjust the position, orientation of a prop
115 #define VTKIS_EXIT 15 // call exit callback
116 #define VTKIS_TOGGLE_DRAW_CONTROLS 16 // draw device controls helpers
117 #define VTKIS_MENU 17 // invoke an application menu
118 #define VTKIS_GESTURE 18 // touch interaction in progress
119 #define VTKIS_ENV_ROTATE 19 // rotate the renderer environment texture
120 #define VTKIS_GROUNDMOVEMENT 20 // horizontal movement according to the 4 directions
121 #define VTKIS_ELEVATION 21 // vertical movement (up and down)
122 #define VTKIS_TELEPORTATION 22 // teleportation (move instantly between two positions)
123 
124 #define VTKIS_ANIM_OFF 0
125 #define VTKIS_ANIM_ON 1
126 
127 VTK_ABI_NAMESPACE_BEGIN
128 class vtkActor2D;
129 class vtkActor;
130 class vtkCallbackCommand;
131 class vtkEventData;
133 class vtkOutlineSource;
134 class vtkPolyDataMapper;
135 class vtkProp3D;
136 class vtkProp;
137 class vtkStringArray;
139 
140 class VTKRENDERINGCORE_EXPORT VTK_MARSHALAUTO vtkInteractorStyle : public vtkInteractorObserver
141 {
142 public:
148  static vtkInteractorStyle* New();
149 
151  void PrintSelf(ostream& os, vtkIndent indent) override;
152 
158  void SetInteractor(vtkRenderWindowInteractor* interactor) override;
159 
168  void SetEnabled(int) override;
169 
171 
179  vtkSetClampMacro(AutoAdjustCameraClippingRange, vtkTypeBool, 0, 1);
180  vtkGetMacro(AutoAdjustCameraClippingRange, vtkTypeBool);
181  vtkBooleanMacro(AutoAdjustCameraClippingRange, vtkTypeBool);
183 
189  void FindPokedRenderer(int, int);
190 
192 
195  vtkGetMacro(State, int);
197 
199 
202  vtkGetMacro(UseTimers, vtkTypeBool);
203  vtkSetMacro(UseTimers, vtkTypeBool);
204  vtkBooleanMacro(UseTimers, vtkTypeBool);
206 
208 
214  vtkSetClampMacro(TimerDuration, unsigned long, 1, 100000);
215  vtkGetMacro(TimerDuration, unsigned long);
217 
219 
222  vtkSetMacro(HandleObservers, vtkTypeBool);
223  vtkGetMacro(HandleObservers, vtkTypeBool);
224  vtkBooleanMacro(HandleObservers, vtkTypeBool);
226 
230  virtual void OnMouseMove() {}
231  virtual void OnLeftButtonDown() {}
232  virtual void OnLeftButtonUp() {}
233  virtual void OnMiddleButtonDown() {}
234  virtual void OnMiddleButtonUp() {}
235  virtual void OnRightButtonDown() {}
236  virtual void OnRightButtonUp() {}
237  virtual void OnLeftButtonDoubleClick() {}
238  virtual void OnMiddleButtonDoubleClick() {}
239  virtual void OnRightButtonDoubleClick() {}
240  virtual void OnMouseWheelForward() {}
241  virtual void OnMouseWheelBackward() {}
242  virtual void OnMouseWheelLeft() {}
243  virtual void OnMouseWheelRight() {}
244  virtual void OnFourthButtonDown() {}
245  virtual void OnFourthButtonUp() {}
246  virtual void OnFifthButtonDown() {}
247  virtual void OnFifthButtonUp() {}
248 
252  virtual void OnMove3D(vtkEventData*) {}
253  virtual void OnButton3D(vtkEventData*) {}
254  virtual void OnPick3D(vtkEventData*) {}
255  virtual void OnClip3D(vtkEventData*) {}
256  virtual void OnSelect3D(vtkEventData*) {}
257  virtual void OnMenu3D(vtkEventData*) {}
258  virtual void OnNextPose3D(vtkEventData*) {}
259  virtual void OnPositionProp3D(vtkEventData*) {}
261  virtual void OnElevation3D(vtkEventData*) {}
262 
267  void OnChar() override;
268 
269  // OnKeyDown is triggered by pressing any key (identical to OnKeyPress()).
270  // An empty implementation is provided. The behavior of this function should
271  // be specified in the subclass.
272  virtual void OnKeyDown() {}
273 
274  // OnKeyUp is triggered by releasing any key (identical to OnKeyRelease()).
275  // An empty implementation is provided. The behavior of this function should
276  // be specified in the subclass.
277  virtual void OnKeyUp() {}
278 
279  // OnKeyPress is triggered by pressing any key (identical to OnKeyDown()).
280  // An empty implementation is provided. The behavior of this function should
281  // be specified in the subclass.
282  virtual void OnKeyPress() {}
283 
284  // OnKeyRelease is triggered by pressing any key (identical to OnKeyUp()).
285  // An empty implementation is provided. The behavior of this function should
286  // be specified in the subclass.
287  virtual void OnKeyRelease() {}
288 
292  virtual void OnExpose() {}
293  virtual void OnConfigure() {}
294  virtual void OnEnter() {}
295  virtual void OnLeave() {}
296 
301  virtual void OnTimer();
302 
309  virtual void Rotate() {}
310  virtual void Spin() {}
311  virtual void Pan() {}
312  virtual void Dolly() {}
313  virtual void Zoom() {}
314  virtual void UniformScale() {}
315  virtual void EnvironmentRotate() {}
316 
320  virtual void OnStartSwipe() {}
321  virtual void OnSwipe() {}
322  virtual void OnEndSwipe() {}
323  virtual void OnStartPinch() {}
324  virtual void OnPinch() {}
325  virtual void OnEndPinch() {}
326  virtual void OnStartRotate() {}
327  virtual void OnRotate() {}
328  virtual void OnEndRotate() {}
329  virtual void OnStartPan() {}
330  virtual void OnPan() {}
331  virtual void OnEndPan() {}
332  virtual void OnTap() {}
333  virtual void OnLongTap() {}
334 
336 
339  virtual void StartState(int newstate);
340  virtual void StopState();
342 
344 
347  virtual void StartAnimate();
348  virtual void StopAnimate();
349  virtual void StartRotate();
350  virtual void EndRotate();
351  virtual void StartZoom();
352  virtual void EndZoom();
353  virtual void StartPan();
354  virtual void EndPan();
355  virtual void StartSpin();
356  virtual void EndSpin();
357  virtual void StartDolly();
358  virtual void EndDolly();
359  virtual void StartUniformScale();
360  virtual void EndUniformScale();
361  virtual void StartTimer();
362  virtual void EndTimer();
363  virtual void StartTwoPointer();
364  virtual void EndTwoPointer();
365  virtual void StartGesture();
366  virtual void EndGesture();
367  virtual void StartEnvRotate();
368  virtual void EndEnvRotate();
370 
377  virtual void OnDropLocation(double* vtkNotUsed(position)) {}
378 
384  virtual void OnDropFiles(vtkStringArray* vtkNotUsed(filePaths)) {}
385 
387 
393  virtual void HighlightProp(vtkProp* prop);
394  virtual void HighlightActor2D(vtkActor2D* actor2D);
395  virtual void HighlightProp3D(vtkProp3D* prop3D);
397 
399 
403  vtkSetVector3Macro(PickColor, double);
404  vtkGetVectorMacro(PickColor, double, 3);
406 
408 
413  vtkSetMacro(MouseWheelMotionFactor, double);
414  vtkGetMacro(MouseWheelMotionFactor, double);
416 
418 
423  vtkSetVector3Macro(CenterOfRotation, double);
424  vtkGetVector3Macro(CenterOfRotation, double);
426 
428 
433  vtkGetObjectMacro(TDxStyle, vtkTDxInteractorStyle);
435  virtual void SetTDxStyle(vtkTDxInteractorStyle* tdxStyle);
437 
441  void DelegateTDxEvent(unsigned long event, void* calldata);
442 
446  static void DollyToPosition(double fact, int* position, vtkRenderer* renderer);
447 
451  static void TranslateCamera(vtkRenderer* renderer, int toX, int toY, int fromX, int fromY);
452 
453 protected:
455  ~vtkInteractorStyle() override;
456 
460  static void ProcessEvents(
461  vtkObject* object, unsigned long event, void* clientdata, void* calldata);
462 
463  // Keep track of current state
464  int State;
465  int AnimState;
466 
467  // Should observers be handled here, should we fire timers
468  vtkTypeBool HandleObservers;
469  vtkTypeBool UseTimers;
470  int TimerId; // keep track of the timers that are created/destroyed
471 
472  vtkTypeBool AutoAdjustCameraClippingRange;
473 
474  // For picking and highlighting props
476  vtkPolyDataMapper* OutlineMapper;
477  vtkActor* OutlineActor;
478  vtkRenderer* PickedRenderer;
479  vtkProp* CurrentProp;
480  vtkActor2D* PickedActor2D;
481  int PropPicked; // bool: prop picked?
482  double PickColor[3]; // support 2D picking
483  double MouseWheelMotionFactor;
484  double CenterOfRotation[3] = { 0.0, 0.0, 0.0 };
485 
486  // Control the timer duration
487  unsigned long TimerDuration; // in milliseconds
488 
489  // Forward events to the RenderWindowInteractor
491 
493 
494 private:
495  vtkInteractorStyle(const vtkInteractorStyle&) = delete;
496  void operator=(const vtkInteractorStyle&) = delete;
497 };
498 
499 VTK_ABI_NAMESPACE_END
500 #endif
a simple event forwarder command
virtual void OnLeftButtonDoubleClick()
virtual void OnLeftButtonDown()
virtual void Rotate()
These methods for the different interactions in different modes are overridden in subclasses to perfo...
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:49
virtual void OnSwipe()
virtual void OnMouseWheelRight()
virtual void OnRotate()
virtual void OnMiddleButtonDown()
virtual void OnRightButtonDown()
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:41
abstract base class for most VTK objects
Definition: vtkObject.h:52
virtual void OnClip3D(vtkEventData *)
virtual void OnButton3D(vtkEventData *)
virtual void OnLeftButtonUp()
virtual void OnKeyUp()
virtual void OnMiddleButtonUp()
virtual void OnEndPinch()
virtual void OnFifthButtonUp()
a actor that draws 2D data
Definition: vtkActor2D.h:35
virtual void OnPositionProp3D(vtkEventData *)
virtual void OnEndPan()
virtual void OnDropLocation(double *position)
When the mouse location is updated while dragging files.
#define VTK_MARSHAL_EXCLUDE_REASON_IS_REDUNDANT
virtual void UniformScale()
a vtkAbstractArray subclass for strings
abstract specification for renderers
Definition: vtkRenderer.h:63
virtual void OnMouseWheelLeft()
virtual void OnMouseWheelForward()
represents an 3D object for placement in a rendered scene
Definition: vtkProp3D.h:39
virtual void OnKeyRelease()
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual void OnKeyPress()
virtual void OnEnter()
an abstract superclass for classes observing events invoked by vtkRenderWindowInteractor ...
int vtkTypeBool
Definition: vtkABI.h:64
virtual void OnRightButtonUp()
platform-independent render window interaction including picking and frame rate control.
virtual void OnMiddleButtonDoubleClick()
virtual void OnLongTap()
vtkEventForwarderCommand * EventForwarder
virtual void OnExpose()
These are more esoteric events, but are useful in some cases.
supports function callbacks
virtual void OnMove3D(vtkEventData *)
Generic 3D event bindings can be overridden in subclasses.
virtual void OnRightButtonDoubleClick()
virtual void OnKeyDown()
virtual void OnConfigure()
virtual void OnSelect3D(vtkEventData *)
a simple class to control print indentation
Definition: vtkIndent.h:28
virtual void OnMouseWheelBackward()
unsigned long TimerDuration
virtual void OnStartPinch()
create wireframe outline around bounding box
virtual void OnEndSwipe()
virtual void OnDropFiles(vtkStringArray *filePaths)
When files are dropped on the render window.
virtual void OnStartPan()
#define VTK_MARSHALEXCLUDE(reason)
virtual void OnMenu3D(vtkEventData *)
provide 3DConnexion device event-driven interface to the rendering window
virtual void OnFifthButtonDown()
map vtkPolyData to graphics primitives
virtual void OnNextPose3D(vtkEventData *)
virtual void OnStartSwipe()
gesture based events
virtual void OnStartRotate()
virtual void OnPick3D(vtkEventData *)
provide event-driven interface to the rendering window (defines trackball mode)
virtual void OnElevation3D(vtkEventData *)
virtual void OnLeave()
virtual void OnViewerMovement3D(vtkEventData *)
#define VTK_MARSHALAUTO
virtual void OnChar()
Sets up the keypress-i event.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
virtual void OnEndRotate()
virtual void OnFourthButtonDown()
virtual void OnPinch()
virtual void EnvironmentRotate()
virtual void OnFourthButtonUp()
#define VTK_MARSHAL_EXCLUDE_REASON_IS_INTERNAL
vtkTDxInteractorStyle * TDxStyle