VTK  9.7.1
vtkRenderWindowInteractor.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
42 #ifndef vtkRenderWindowInteractor_h
43 #define vtkRenderWindowInteractor_h
44 
45 #include "vtkCommand.h" // for method sig
46 #include "vtkNew.h" // For InteractorObservers
47 #include "vtkObject.h"
48 #include "vtkRenderingCoreModule.h" // For export macro
49 #include "vtkSmartPointer.h" // For InteractorStyle
50 #include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
51 
52 VTK_ABI_NAMESPACE_BEGIN
53 class vtkTimerIdMap;
54 
55 // Timer flags for win32/X compatibility
56 #define VTKI_TIMER_FIRST 0
57 #define VTKI_TIMER_UPDATE 1
58 
59 // maximum pointers active at once
60 // for example in multitouch
61 #define VTKI_MAX_POINTERS 5
62 
63 class vtkAbstractPicker;
65 class vtkAssemblyPath;
66 class vtkCollection;
67 class vtkHardwareWindow;
69 class vtkRenderWindow;
70 class vtkRenderer;
73 class vtkPickingManager;
74 
75 class VTKRENDERINGCORE_EXPORT VTK_MARSHALAUTO vtkRenderWindowInteractor : public vtkObject
76 {
77 
79  friend class vtkInteractorObserver;
80 
81 public:
84  void PrintSelf(ostream& os, vtkIndent indent) override;
85 
87 
94  virtual void Initialize();
95  void ReInitialize()
96  {
97  this->Initialized = 0;
98  this->Enabled = 0;
99  this->Initialize();
100  }
102 
107  void UnRegister(vtkObjectBase* o) override;
108 
114  virtual void Start();
115 
122  virtual void ProcessEvents() {}
123 
127  vtkGetMacro(Done, bool);
128  vtkSetMacro(Done, bool);
129 
139  virtual void Enable()
140  {
141  this->Enabled = 1;
142  this->Modified();
143  }
144  virtual void Disable()
145  {
146  this->Enabled = 0;
147  this->Modified();
148  }
149  vtkGetMacro(Enabled, int);
150 
152 
156  vtkBooleanMacro(EnableRender, bool);
158  vtkSetMacro(EnableRender, bool);
160  vtkGetMacro(EnableRender, bool);
162 
164 
167  void SetRenderWindow(vtkRenderWindow* aren);
168  vtkGetObjectMacro(RenderWindow, vtkRenderWindow);
170 
172 
177  void SetHardwareWindow(vtkHardwareWindow* aren);
178  vtkGetObjectMacro(HardwareWindow, vtkHardwareWindow);
180 
189  virtual void UpdateSize(int x, int y);
190 
208  virtual int CreateTimer(int timerType); // first group, for backward compatibility
209  virtual int DestroyTimer(); // first group, for backward compatibility
210 
215  int CreateRepeatingTimer(unsigned long duration);
216 
221  int CreateOneShotTimer(unsigned long duration);
222 
227  int IsOneShotTimer(int timerId);
228 
232  unsigned long GetTimerDuration(int timerId);
233 
237  int ResetTimer(int timerId);
238 
243  int DestroyTimer(int timerId);
244 
248  virtual int GetVTKTimerId(int platformTimerId);
249 
250  // Moved into the public section of the class so that classless timer procs
251  // can access these enum members without being "friends"...
252  enum
253  {
254  OneShotTimer = 1,
255  RepeatingTimer
256  };
257 
259 
268  vtkSetClampMacro(TimerDuration, unsigned long, 1, 100000);
269  vtkGetMacro(TimerDuration, unsigned long);
271 
273 
285  vtkSetMacro(TimerEventId, int);
286  vtkGetMacro(TimerEventId, int);
287  vtkSetMacro(TimerEventType, int);
288  vtkGetMacro(TimerEventType, int);
289  vtkSetMacro(TimerEventDuration, int);
290  vtkGetMacro(TimerEventDuration, int);
291  vtkSetMacro(TimerEventPlatformId, int);
292  vtkGetMacro(TimerEventPlatformId, int);
294 
300  virtual void TerminateApp() { this->Done = true; }
301 
303 
307  virtual void SetInteractorStyle(vtkInteractorObserver*);
308  virtual vtkInteractorObserver* GetInteractorStyle();
310 
318  vtkGetObjectMacro(InteractorObservers, vtkCollection);
319 
321 
325  vtkSetMacro(LightFollowCamera, vtkTypeBool);
326  vtkGetMacro(LightFollowCamera, vtkTypeBool);
327  vtkBooleanMacro(LightFollowCamera, vtkTypeBool);
329 
331 
338  vtkSetClampMacro(DesiredUpdateRate, double, 0.0001, VTK_FLOAT_MAX);
339  vtkGetMacro(DesiredUpdateRate, double);
341 
343 
348  vtkSetClampMacro(StillUpdateRate, double, 0.0001, VTK_FLOAT_MAX);
349  vtkGetMacro(StillUpdateRate, double);
351 
353 
357  vtkGetMacro(Initialized, int);
359 
361 
367  virtual void SetPicker(vtkAbstractPicker*);
368  vtkGetObjectMacro(Picker, vtkAbstractPicker);
370 
375  virtual vtkAbstractPropPicker* CreateDefaultPicker();
376 
378 
384  virtual void SetPickingManager(vtkPickingManager*);
386  vtkGetObjectMacro(PickingManager, vtkPickingManager);
388 
390 
394  virtual void ExitCallback();
395  virtual void UserCallback();
396  virtual void StartPickCallback();
397  virtual void EndPickCallback();
399 
403  virtual void GetMousePosition(int* x, int* y)
404  {
405  *x = 0;
406  *y = 0;
407  }
408 
410 
414  void HideCursor();
415  void ShowCursor();
417 
422  virtual void Render();
423 
425 
430  void FlyTo(vtkRenderer* ren, double x, double y, double z);
431  void FlyTo(vtkRenderer* ren, double* x) { this->FlyTo(ren, x[0], x[1], x[2]); }
432  void FlyToImage(vtkRenderer* ren, double x, double y);
433  void FlyToImage(vtkRenderer* ren, double* x) { this->FlyToImage(ren, x[0], x[1]); }
435 
437 
440  vtkSetClampMacro(NumberOfFlyFrames, int, 1, VTK_INT_MAX);
441  vtkGetMacro(NumberOfFlyFrames, int);
443 
445 
449  vtkSetMacro(Dolly, double);
450  vtkGetMacro(Dolly, double);
452 
454 
463  vtkGetVector2Macro(EventPosition, int);
465  vtkGetVector2Macro(LastEventPosition, int);
467  vtkSetVector2Macro(LastEventPosition, int);
469  virtual void SetEventPosition(int x, int y)
470  {
471  vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting EventPosition to (" << x
472  << "," << y << ")");
473  if (this->EventPosition[0] != x || this->EventPosition[1] != y ||
474  this->LastEventPosition[0] != x || this->LastEventPosition[1] != y)
475  {
476  this->LastEventPosition[0] = this->EventPosition[0];
477  this->LastEventPosition[1] = this->EventPosition[1];
478  this->EventPosition[0] = x;
479  this->EventPosition[1] = y;
480  this->Modified();
481  }
482  }
484  virtual void SetEventPosition(int pos[2]) { this->SetEventPosition(pos[0], pos[1]); }
485  virtual void SetEventPositionFlipY(int x, int y)
486  {
487  this->SetEventPosition(x, this->Size[1] - y - 1);
488  }
489  virtual void SetEventPositionFlipY(int pos[2]) { this->SetEventPositionFlipY(pos[0], pos[1]); }
491 
492  virtual int* GetEventPositions(int pointerIndex)
493  {
494  if (pointerIndex >= VTKI_MAX_POINTERS)
495  {
496  return nullptr;
497  }
498  return this->EventPositions[pointerIndex];
499  }
500  virtual int* GetLastEventPositions(int pointerIndex)
501  {
502  if (pointerIndex >= VTKI_MAX_POINTERS)
503  {
504  return nullptr;
505  }
506  return this->LastEventPositions[pointerIndex];
507  }
508  virtual void SetEventPosition(int x, int y, int pointerIndex)
509  {
510  if (pointerIndex < 0 || pointerIndex >= VTKI_MAX_POINTERS)
511  {
512  return;
513  }
514  if (pointerIndex == 0)
515  {
516  this->LastEventPosition[0] = this->EventPosition[0];
517  this->LastEventPosition[1] = this->EventPosition[1];
518  this->EventPosition[0] = x;
519  this->EventPosition[1] = y;
520  }
521  vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting EventPosition to (" << x
522  << "," << y << ") for pointerIndex number " << pointerIndex);
523  if (this->EventPositions[pointerIndex][0] != x || this->EventPositions[pointerIndex][1] != y ||
524  this->LastEventPositions[pointerIndex][0] != x ||
525  this->LastEventPositions[pointerIndex][1] != y)
526  {
527  this->LastEventPositions[pointerIndex][0] = this->EventPositions[pointerIndex][0];
528  this->LastEventPositions[pointerIndex][1] = this->EventPositions[pointerIndex][1];
529  this->EventPositions[pointerIndex][0] = x;
530  this->EventPositions[pointerIndex][1] = y;
531  this->Modified();
532  }
533  }
534  virtual void SetEventPosition(int pos[2], int pointerIndex)
535  {
536  this->SetEventPosition(pos[0], pos[1], pointerIndex);
537  }
538  virtual void SetEventPositionFlipY(int x, int y, int pointerIndex)
539  {
540  this->SetEventPosition(x, this->Size[1] - y - 1, pointerIndex);
541  }
542  virtual void SetEventPositionFlipY(int pos[2], int pointerIndex)
543  {
544  this->SetEventPositionFlipY(pos[0], pos[1], pointerIndex);
545  }
546 
548 
555  vtkSetMacro(AltKey, int);
556  vtkGetMacro(AltKey, int);
558 
560 
565  vtkSetMacro(ControlKey, int);
566  vtkGetMacro(ControlKey, int);
568 
570 
573  vtkSetMacro(ShiftKey, int);
574  vtkGetMacro(ShiftKey, int);
576 
578 
601  vtkSetMacro(KeyCode, char);
602  vtkGetMacro(KeyCode, char);
604 
606 
610  vtkSetMacro(RepeatCount, int);
611  vtkGetMacro(RepeatCount, int);
613 
615 
635  vtkSetStringMacro(KeySym);
636  vtkGetStringMacro(KeySym);
638 
640 
643  vtkSetMacro(PointerIndex, int);
644  vtkGetMacro(PointerIndex, int);
646 
648 
651  void SetRotation(double rotation);
652  vtkGetMacro(Rotation, double);
653  vtkGetMacro(LastRotation, double);
655 
657 
660  void SetScale(double scale);
661  vtkGetMacro(Scale, double);
662  vtkGetMacro(LastScale, double);
664 
666 
669  void SetTranslation(double val[2]);
670  vtkGetVector2Macro(Translation, double);
671  vtkGetVector2Macro(LastTranslation, double);
673 
675 
678  void SetEventInformation(int x, int y, int ctrl, int shift, char keycode, int repeatcount,
679  const char* keysym, int pointerIndex)
680  {
681  this->SetEventPosition(x, y, pointerIndex);
682  this->ControlKey = ctrl;
683  this->ShiftKey = shift;
684  this->KeyCode = keycode;
685  this->RepeatCount = repeatcount;
686  this->PointerIndex = pointerIndex;
687  if (keysym)
688  {
689  this->SetKeySym(keysym);
690  }
691  this->Modified();
692  }
693  void SetEventInformation(int x, int y, int ctrl = 0, int shift = 0, char keycode = 0,
694  int repeatcount = 0, const char* keysym = nullptr)
695  {
696  this->SetEventInformation(x, y, ctrl, shift, keycode, repeatcount, keysym, 0);
697  }
699 
701 
705  void SetEventInformationFlipY(int x, int y, int ctrl, int shift, char keycode, int repeatcount,
706  const char* keysym, int pointerIndex)
707  {
708  this->SetEventInformation(
709  x, this->Size[1] - y - 1, ctrl, shift, keycode, repeatcount, keysym, pointerIndex);
710  }
711  void SetEventInformationFlipY(int x, int y, int ctrl = 0, int shift = 0, char keycode = 0,
712  int repeatcount = 0, const char* keysym = nullptr)
713  {
714  this->SetEventInformationFlipY(x, y, ctrl, shift, keycode, repeatcount, keysym, 0);
715  }
717 
719 
722  void SetKeyEventInformation(int ctrl = 0, int shift = 0, char keycode = 0, int repeatcount = 0,
723  const char* keysym = nullptr)
724  {
725  this->ControlKey = ctrl;
726  this->ShiftKey = shift;
727  this->KeyCode = keycode;
728  this->RepeatCount = repeatcount;
729  if (keysym)
730  {
731  this->SetKeySym(keysym);
732  }
733  this->Modified();
734  }
736 
738 
749  vtkSetVector2Macro(Size, int);
750  vtkGetVector2Macro(Size, int);
751  vtkSetVector2Macro(EventSize, int);
752  vtkGetVector2Macro(EventSize, int);
754 
760  virtual vtkRenderer* FindPokedRenderer(int, int);
761 
769  vtkObserverMediator* GetObserverMediator();
770 
772 
780  vtkSetMacro(UseTDx, bool);
781  vtkGetMacro(UseTDx, bool);
783 
785 
790  virtual void MouseMoveEvent();
791  virtual void RightButtonPressEvent();
792  virtual void RightButtonReleaseEvent();
793  virtual void LeftButtonPressEvent();
794  virtual void LeftButtonReleaseEvent();
795  virtual void MiddleButtonPressEvent();
796  virtual void MiddleButtonReleaseEvent();
797  virtual void MouseWheelForwardEvent();
798  virtual void MouseWheelBackwardEvent();
799  virtual void MouseWheelLeftEvent();
800  virtual void MouseWheelRightEvent();
801  virtual void ExposeEvent();
802  virtual void ConfigureEvent();
803  virtual void EnterEvent();
804  virtual void LeaveEvent();
805  virtual void KeyPressEvent();
806  virtual void KeyReleaseEvent();
807  virtual void CharEvent();
808  virtual void ExitEvent();
809  virtual void FourthButtonPressEvent();
810  virtual void FourthButtonReleaseEvent();
811  virtual void FifthButtonPressEvent();
812  virtual void FifthButtonReleaseEvent();
814 
816 
820  virtual void StartPinchEvent();
821  virtual void PinchEvent();
822  virtual void EndPinchEvent();
823  virtual void StartRotateEvent();
824  virtual void RotateEvent();
825  virtual void EndRotateEvent();
826  virtual void StartPanEvent();
827  virtual void PanEvent();
828  virtual void EndPanEvent();
829  virtual void TapEvent();
830  virtual void LongTapEvent();
831  virtual void SwipeEvent();
833 
835 
841  vtkSetMacro(RecognizeGestures, bool);
842  vtkGetMacro(RecognizeGestures, bool);
844 
846 
851  vtkGetMacro(PointersDownCount, int);
853 
855 
862  void ClearContact(size_t contactID);
863  int GetPointerIndexForContact(size_t contactID);
864  int GetPointerIndexForExistingContact(size_t contactID);
865  bool IsPointerIndexSet(int i);
866  void ClearPointerIndex(int i);
868 
870 
888  vtkBooleanMacro(TrackInteractorObserverInstances, bool);
889  vtkSetMacro(TrackInteractorObserverInstances, bool);
890  vtkGetMacro(TrackInteractorObserverInstances, bool);
892 
911  static bool InteractorManagesTheEventLoop;
912 
914 
920  virtual vtkCommand::EventIds GetCurrentGesture() const;
921  virtual void SetCurrentGesture(vtkCommand::EventIds eid);
923 
924 protected:
926  ~vtkRenderWindowInteractor() override;
927 
931 
932  // Used as a helper object to pick instances of vtkProp
935 
936  bool Done; // is the event loop done running
937 
942  virtual vtkPickingManager* CreateDefaultPickingManager();
943 
945  int Enabled;
947  int Style;
952 
953  // Event information
954  int AltKey;
956  int ShiftKey;
957  char KeyCode;
958  double Rotation;
959  double LastRotation;
960  double Scale;
961  double LastScale;
962  double Translation[2];
963  double LastTranslation[2];
965  char* KeySym;
966  int EventPosition[2];
967  int LastEventPosition[2];
968  int EventSize[2];
969  int Size[2];
974 
975  int EventPositions[VTKI_MAX_POINTERS][2];
976  int LastEventPositions[VTKI_MAX_POINTERS][2];
978 
979  size_t PointerIndexLookup[VTKI_MAX_POINTERS];
980 
981  // control the fly to
983  double Dolly;
984 
993  friend class vtkInteractorObserver;
994  void GrabFocus(vtkCommand* mouseEvents, vtkCommand* keypressEvents = nullptr)
995  {
996  this->Superclass::InternalGrabFocus(mouseEvents, keypressEvents);
997  }
999 
1004 
1005  // Timer related members
1006  friend struct vtkTimerStruct;
1007  vtkTimerIdMap* TimerMap; // An internal, PIMPLd map of timers and associated attributes
1008  unsigned long TimerDuration; // in milliseconds
1010 
1016  virtual int InternalCreateTimer(int timerId, int timerType, unsigned long duration);
1017  virtual int InternalDestroyTimer(int platformTimerId);
1018  int GetCurrentTimerId();
1020 
1021  // Force the interactor to handle the Start() event loop, ignoring any
1022  // overrides. (Overrides are registered by observing StartEvent on the
1023  // interactor.)
1025 
1029  virtual void StartEventLoop() {}
1030 
1031  bool UseTDx; // 3DConnexion device.
1032 
1033  // when recognizing gestures VTK will take multitouch events
1034  // if it receives them and convert them to gestures
1037  int PointersDown[VTKI_MAX_POINTERS];
1038  virtual void RecognizeGesture(vtkCommand::EventIds);
1039  int StartingEventPositions[VTKI_MAX_POINTERS][2];
1041  bool TrackInteractorObserverInstances = false;
1042 
1043 private:
1045  void operator=(const vtkRenderWindowInteractor&) = delete;
1046 
1047  void AddInteractorObserver(vtkInteractorObserver* interactorObserver);
1048  void RemoveInteractorObserver(vtkInteractorObserver* interactorObserver);
1049  // Internal collection of all vtkInteractorObserver instances which use this interactor.
1050  vtkNew<vtkCollection> InteractorObservers;
1051 };
1052 
1053 VTK_ABI_NAMESPACE_END
1054 #endif
create a window for renderers to draw into
virtual void SetEventPositionFlipY(int pos[2])
Set/Get information about the current event.
void SetKeyEventInformation(int ctrl=0, int shift=0, char keycode=0, int repeatcount=0, const char *keysym=nullptr)
Set all the keyboard-related event information in one call.
void InternalGrabFocus(vtkCommand *mouseEvents, vtkCommand *keypressEvents=nullptr)
These methods allow a command to exclusively grab all events.
abstract base class for most VTK objects
Definition: vtkObject.h:52
Class defines API to manage the picking process.
virtual void Enable()
Enable/Disable interactions.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void SetEventInformation(int x, int y, int ctrl, int shift, char keycode, int repeatcount, const char *keysym, int pointerIndex)
Set all the event information in one call.
virtual void SetEventPosition(int pos[2], int pointerIndex)
#define VTK_INT_MAX
Definition: vtkType.h:192
virtual void SetEventPositionFlipY(int pos[2], int pointerIndex)
abstract specification for renderers
Definition: vtkRenderer.h:63
void GrabFocus(vtkCommand *mouseEvents, vtkCommand *keypressEvents=nullptr)
virtual int * GetLastEventPositions(int pointerIndex)
virtual void SetEventPosition(int pos[2])
Set/Get information about the current event.
virtual int * GetEventPositions(int pointerIndex)
an abstract superclass for classes observing events invoked by vtkRenderWindowInteractor ...
static bool InteractorManagesTheEventLoop
This flag is useful when you are integrating VTK in a larger system.
void FlyTo(vtkRenderer *ren, double *x)
Given a position x, move the current camera's focal point to x.
int vtkTypeBool
Definition: vtkABI.h:64
platform-independent render window interaction including picking and frame rate control.
void InternalReleaseFocus()
These methods allow a command to exclusively grab all events.
void ReInitialize()
Prepare for handling events and set the Enabled flag to true.
superclass for callback/observer methods
Definition: vtkCommand.h:384
#define VTK_FLOAT_MAX
Definition: vtkType.h:200
virtual void UnRegister(vtkObjectBase *o)
Decrease the reference count (release by another object).
a list of nodes that form an assembly path
vtkObserverMediator * ObserverMediator
Widget mediators are used to resolve contention for cursors and other resources.
a simple class to control print indentation
Definition: vtkIndent.h:28
const char * GetClassName() const
Return the class name as a string.
virtual void StartEventLoop()
Run the event loop (does not return until TerminateApp is called).
void SetEventInformationFlipY(int x, int y, int ctrl, int shift, char keycode, int repeatcount, const char *keysym, int pointerIndex)
Calls SetEventInformation, but flips the Y based on the current Size[1] value (i.e.
virtual void Modified()
Update the modification time for this object.
record and play VTK events passing through a vtkRenderWindowInteractor
virtual void SetEventPosition(int x, int y, int pointerIndex)
vtkSmartPointer< vtkInteractorObserver > InteractorStyle
abstract base class for most VTK objects
Definition: vtkObjectBase.h:68
virtual void ProcessEvents()
Process all user-interaction, timer events and return.
#define VTK_MARSHALEXCLUDE(reason)
virtual void SetEventPositionFlipY(int x, int y, int pointerIndex)
abstract API for pickers that can pick an instance of vtkProp
create a window for renderers to draw into
create and manipulate ordered lists of objects
Definition: vtkCollection.h:39
#define VTKI_MAX_POINTERS
virtual void TerminateApp()
This function is called on 'q','e' keypress if exitmethod is not specified and should be overridden b...
define API for picking subclasses
#define VTK_MARSHALAUTO
#define VTK_MARSHAL_EXCLUDE_REASON_NOT_SUPPORTED
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
void FlyToImage(vtkRenderer *ren, double *x)
Given a position x, move the current camera's focal point to x.
void SetEventInformation(int x, int y, int ctrl=0, int shift=0, char keycode=0, int repeatcount=0, const char *keysym=nullptr)
Set all the event information in one call.
manage contention for cursors and other resources
void SetEventInformationFlipY(int x, int y, int ctrl=0, int shift=0, char keycode=0, int repeatcount=0, const char *keysym=nullptr)
Calls SetEventInformation, but flips the Y based on the current Size[1] value (i.e.
#define VTK_MARSHAL_EXCLUDE_REASON_IS_INTERNAL
virtual void SetEventPositionFlipY(int x, int y)
Set/Get information about the current event.