VTK  9.2.6
vtkRenderWindowInteractor.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkRenderWindowInteractor.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://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 =========================================================================*/
54 #ifndef vtkRenderWindowInteractor_h
55 #define vtkRenderWindowInteractor_h
56 
57 #include "vtkCommand.h" // for method sig
58 #include "vtkObject.h"
59 #include "vtkRenderingCoreModule.h" // For export macro
60 #include "vtkSmartPointer.h" // For InteractorStyle
61 
62 class vtkTimerIdMap;
63 
64 // Timer flags for win32/X compatibility
65 #define VTKI_TIMER_FIRST 0
66 #define VTKI_TIMER_UPDATE 1
67 
68 // maximum pointers active at once
69 // for example in multitouch
70 #define VTKI_MAX_POINTERS 5
71 
72 class vtkAbstractPicker;
74 class vtkAssemblyPath;
75 class vtkHardwareWindow;
77 class vtkRenderWindow;
78 class vtkRenderer;
81 class vtkPickingManager;
82 
83 class VTKRENDERINGCORE_EXPORT vtkRenderWindowInteractor : public vtkObject
84 {
85 
87 
88 public:
91  void PrintSelf(ostream& os, vtkIndent indent) override;
92 
94 
101  virtual void Initialize();
103  {
104  this->Initialized = 0;
105  this->Enabled = 0;
106  this->Initialize();
107  }
109 
114  void UnRegister(vtkObjectBase* o) override;
115 
121  virtual void Start();
122 
128  virtual void ProcessEvents() {}
129 
133  vtkGetMacro(Done, bool);
134  vtkSetMacro(Done, bool);
135 
145  virtual void Enable()
146  {
147  this->Enabled = 1;
148  this->Modified();
149  }
150  virtual void Disable()
151  {
152  this->Enabled = 0;
153  this->Modified();
154  }
155  vtkGetMacro(Enabled, int);
156 
158 
162  vtkBooleanMacro(EnableRender, bool);
163  vtkSetMacro(EnableRender, bool);
164  vtkGetMacro(EnableRender, bool);
166 
168 
171  void SetRenderWindow(vtkRenderWindow* aren);
172  vtkGetObjectMacro(RenderWindow, vtkRenderWindow);
174 
176 
181  void SetHardwareWindow(vtkHardwareWindow* aren);
182  vtkGetObjectMacro(HardwareWindow, vtkHardwareWindow);
184 
192  virtual void UpdateSize(int x, int y);
193 
210  virtual int CreateTimer(int timerType); // first group, for backward compatibility
211  virtual int DestroyTimer(); // first group, for backward compatibility
212 
217  int CreateRepeatingTimer(unsigned long duration);
218 
223  int CreateOneShotTimer(unsigned long duration);
224 
229  int IsOneShotTimer(int timerId);
230 
234  unsigned long GetTimerDuration(int timerId);
235 
239  int ResetTimer(int timerId);
240 
245  int DestroyTimer(int timerId);
246 
250  virtual int GetVTKTimerId(int platformTimerId);
251 
252  // Moved into the public section of the class so that classless timer procs
253  // can access these enum members without being "friends"...
254  enum
255  {
256  OneShotTimer = 1,
257  RepeatingTimer
258  };
259 
261 
270  vtkSetClampMacro(TimerDuration, unsigned long, 1, 100000);
271  vtkGetMacro(TimerDuration, unsigned long);
273 
275 
287  vtkSetMacro(TimerEventId, int);
288  vtkGetMacro(TimerEventId, int);
289  vtkSetMacro(TimerEventType, int);
290  vtkGetMacro(TimerEventType, int);
291  vtkSetMacro(TimerEventDuration, int);
292  vtkGetMacro(TimerEventDuration, int);
293  vtkSetMacro(TimerEventPlatformId, int);
294  vtkGetMacro(TimerEventPlatformId, int);
296 
302  virtual void TerminateApp(void) { this->Done = true; }
303 
305 
309  virtual void SetInteractorStyle(vtkInteractorObserver*);
310  virtual vtkInteractorObserver* GetInteractorStyle();
312 
314 
318  vtkSetMacro(LightFollowCamera, vtkTypeBool);
319  vtkGetMacro(LightFollowCamera, vtkTypeBool);
320  vtkBooleanMacro(LightFollowCamera, vtkTypeBool);
322 
324 
331  vtkSetClampMacro(DesiredUpdateRate, double, 0.0001, VTK_FLOAT_MAX);
332  vtkGetMacro(DesiredUpdateRate, double);
334 
336 
341  vtkSetClampMacro(StillUpdateRate, double, 0.0001, VTK_FLOAT_MAX);
342  vtkGetMacro(StillUpdateRate, double);
344 
346 
350  vtkGetMacro(Initialized, int);
352 
354 
360  virtual void SetPicker(vtkAbstractPicker*);
361  vtkGetObjectMacro(Picker, vtkAbstractPicker);
363 
368  virtual vtkAbstractPropPicker* CreateDefaultPicker();
369 
371 
376  virtual void SetPickingManager(vtkPickingManager*);
377  vtkGetObjectMacro(PickingManager, vtkPickingManager);
379 
381 
385  virtual void ExitCallback();
386  virtual void UserCallback();
387  virtual void StartPickCallback();
388  virtual void EndPickCallback();
390 
394  virtual void GetMousePosition(int* x, int* y)
395  {
396  *x = 0;
397  *y = 0;
398  }
399 
401 
405  void HideCursor();
406  void ShowCursor();
408 
413  virtual void Render();
414 
416 
421  void FlyTo(vtkRenderer* ren, double x, double y, double z);
422  void FlyTo(vtkRenderer* ren, double* x) { this->FlyTo(ren, x[0], x[1], x[2]); }
423  void FlyToImage(vtkRenderer* ren, double x, double y);
424  void FlyToImage(vtkRenderer* ren, double* x) { this->FlyToImage(ren, x[0], x[1]); }
426 
428 
431  vtkSetClampMacro(NumberOfFlyFrames, int, 1, VTK_INT_MAX);
432  vtkGetMacro(NumberOfFlyFrames, int);
434 
436 
440  vtkSetMacro(Dolly, double);
441  vtkGetMacro(Dolly, double);
443 
445 
453  vtkGetVector2Macro(EventPosition, int);
454  vtkGetVector2Macro(LastEventPosition, int);
455  vtkSetVector2Macro(LastEventPosition, int);
456  virtual void SetEventPosition(int x, int y)
457  {
458  vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting EventPosition to (" << x
459  << "," << y << ")");
460  if (this->EventPosition[0] != x || this->EventPosition[1] != y ||
461  this->LastEventPosition[0] != x || this->LastEventPosition[1] != y)
462  {
463  this->LastEventPosition[0] = this->EventPosition[0];
464  this->LastEventPosition[1] = this->EventPosition[1];
465  this->EventPosition[0] = x;
466  this->EventPosition[1] = y;
467  this->Modified();
468  }
469  }
470  virtual void SetEventPosition(int pos[2]) { this->SetEventPosition(pos[0], pos[1]); }
471  virtual void SetEventPositionFlipY(int x, int y)
472  {
473  this->SetEventPosition(x, this->Size[1] - y - 1);
474  }
475  virtual void SetEventPositionFlipY(int pos[2]) { this->SetEventPositionFlipY(pos[0], pos[1]); }
477 
478  virtual int* GetEventPositions(int pointerIndex)
479  {
480  if (pointerIndex >= VTKI_MAX_POINTERS)
481  {
482  return nullptr;
483  }
484  return this->EventPositions[pointerIndex];
485  }
486  virtual int* GetLastEventPositions(int pointerIndex)
487  {
488  if (pointerIndex >= VTKI_MAX_POINTERS)
489  {
490  return nullptr;
491  }
492  return this->LastEventPositions[pointerIndex];
493  }
494  virtual void SetEventPosition(int x, int y, int pointerIndex)
495  {
496  if (pointerIndex < 0 || pointerIndex >= VTKI_MAX_POINTERS)
497  {
498  return;
499  }
500  if (pointerIndex == 0)
501  {
502  this->LastEventPosition[0] = this->EventPosition[0];
503  this->LastEventPosition[1] = this->EventPosition[1];
504  this->EventPosition[0] = x;
505  this->EventPosition[1] = y;
506  }
507  vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting EventPosition to (" << x
508  << "," << y << ") for pointerIndex number " << pointerIndex);
509  if (this->EventPositions[pointerIndex][0] != x || this->EventPositions[pointerIndex][1] != y ||
510  this->LastEventPositions[pointerIndex][0] != x ||
511  this->LastEventPositions[pointerIndex][1] != y)
512  {
513  this->LastEventPositions[pointerIndex][0] = this->EventPositions[pointerIndex][0];
514  this->LastEventPositions[pointerIndex][1] = this->EventPositions[pointerIndex][1];
515  this->EventPositions[pointerIndex][0] = x;
516  this->EventPositions[pointerIndex][1] = y;
517  this->Modified();
518  }
519  }
520  virtual void SetEventPosition(int pos[2], int pointerIndex)
521  {
522  this->SetEventPosition(pos[0], pos[1], pointerIndex);
523  }
524  virtual void SetEventPositionFlipY(int x, int y, int pointerIndex)
525  {
526  this->SetEventPosition(x, this->Size[1] - y - 1, pointerIndex);
527  }
528  virtual void SetEventPositionFlipY(int pos[2], int pointerIndex)
529  {
530  this->SetEventPositionFlipY(pos[0], pos[1], pointerIndex);
531  }
532 
534 
537  vtkSetMacro(AltKey, int);
538  vtkGetMacro(AltKey, int);
540 
542 
545  vtkSetMacro(ControlKey, int);
546  vtkGetMacro(ControlKey, int);
548 
550 
553  vtkSetMacro(ShiftKey, int);
554  vtkGetMacro(ShiftKey, int);
556 
558 
561  vtkSetMacro(KeyCode, char);
562  vtkGetMacro(KeyCode, char);
564 
566 
570  vtkSetMacro(RepeatCount, int);
571  vtkGetMacro(RepeatCount, int);
573 
575 
581  vtkSetStringMacro(KeySym);
582  vtkGetStringMacro(KeySym);
584 
586 
589  vtkSetMacro(PointerIndex, int);
590  vtkGetMacro(PointerIndex, int);
592 
594 
597  void SetRotation(double rotation);
598  vtkGetMacro(Rotation, double);
599  vtkGetMacro(LastRotation, double);
601 
603 
606  void SetScale(double scale);
607  vtkGetMacro(Scale, double);
608  vtkGetMacro(LastScale, double);
610 
612 
615  void SetTranslation(double val[2]);
616  vtkGetVector2Macro(Translation, double);
617  vtkGetVector2Macro(LastTranslation, double);
619 
621 
624  void SetEventInformation(int x, int y, int ctrl, int shift, char keycode, int repeatcount,
625  const char* keysym, int pointerIndex)
626  {
627  this->SetEventPosition(x, y, pointerIndex);
628  this->ControlKey = ctrl;
629  this->ShiftKey = shift;
630  this->KeyCode = keycode;
631  this->RepeatCount = repeatcount;
632  this->PointerIndex = pointerIndex;
633  if (keysym)
634  {
635  this->SetKeySym(keysym);
636  }
637  this->Modified();
638  }
639  void SetEventInformation(int x, int y, int ctrl = 0, int shift = 0, char keycode = 0,
640  int repeatcount = 0, const char* keysym = nullptr)
641  {
642  this->SetEventInformation(x, y, ctrl, shift, keycode, repeatcount, keysym, 0);
643  }
645 
647 
651  void SetEventInformationFlipY(int x, int y, int ctrl, int shift, char keycode, int repeatcount,
652  const char* keysym, int pointerIndex)
653  {
654  this->SetEventInformation(
655  x, this->Size[1] - y - 1, ctrl, shift, keycode, repeatcount, keysym, pointerIndex);
656  }
657  void SetEventInformationFlipY(int x, int y, int ctrl = 0, int shift = 0, char keycode = 0,
658  int repeatcount = 0, const char* keysym = nullptr)
659  {
660  this->SetEventInformationFlipY(x, y, ctrl, shift, keycode, repeatcount, keysym, 0);
661  }
663 
665 
668  void SetKeyEventInformation(int ctrl = 0, int shift = 0, char keycode = 0, int repeatcount = 0,
669  const char* keysym = nullptr)
670  {
671  this->ControlKey = ctrl;
672  this->ShiftKey = shift;
673  this->KeyCode = keycode;
674  this->RepeatCount = repeatcount;
675  if (keysym)
676  {
677  this->SetKeySym(keysym);
678  }
679  this->Modified();
680  }
682 
684 
695  vtkSetVector2Macro(Size, int);
696  vtkGetVector2Macro(Size, int);
697  vtkSetVector2Macro(EventSize, int);
698  vtkGetVector2Macro(EventSize, int);
700 
706  virtual vtkRenderer* FindPokedRenderer(int, int);
707 
715  vtkObserverMediator* GetObserverMediator();
716 
718 
726  vtkSetMacro(UseTDx, bool);
727  vtkGetMacro(UseTDx, bool);
729 
731 
736  virtual void MouseMoveEvent();
737  virtual void RightButtonPressEvent();
738  virtual void RightButtonReleaseEvent();
739  virtual void LeftButtonPressEvent();
740  virtual void LeftButtonReleaseEvent();
741  virtual void MiddleButtonPressEvent();
742  virtual void MiddleButtonReleaseEvent();
743  virtual void MouseWheelForwardEvent();
744  virtual void MouseWheelBackwardEvent();
745  virtual void MouseWheelLeftEvent();
746  virtual void MouseWheelRightEvent();
747  virtual void ExposeEvent();
748  virtual void ConfigureEvent();
749  virtual void EnterEvent();
750  virtual void LeaveEvent();
751  virtual void KeyPressEvent();
752  virtual void KeyReleaseEvent();
753  virtual void CharEvent();
754  virtual void ExitEvent();
755  virtual void FourthButtonPressEvent();
756  virtual void FourthButtonReleaseEvent();
757  virtual void FifthButtonPressEvent();
758  virtual void FifthButtonReleaseEvent();
760 
762 
766  virtual void StartPinchEvent();
767  virtual void PinchEvent();
768  virtual void EndPinchEvent();
769  virtual void StartRotateEvent();
770  virtual void RotateEvent();
771  virtual void EndRotateEvent();
772  virtual void StartPanEvent();
773  virtual void PanEvent();
774  virtual void EndPanEvent();
775  virtual void TapEvent();
776  virtual void LongTapEvent();
777  virtual void SwipeEvent();
779 
781 
787  vtkSetMacro(RecognizeGestures, bool);
788  vtkGetMacro(RecognizeGestures, bool);
790 
792 
797  vtkGetMacro(PointersDownCount, int);
799 
801 
808  void ClearContact(size_t contactID);
809  int GetPointerIndexForContact(size_t contactID);
810  int GetPointerIndexForExistingContact(size_t contactID);
811  bool IsPointerIndexSet(int i);
812  void ClearPointerIndex(int i);
814 
815 protected:
817  ~vtkRenderWindowInteractor() override;
818 
822 
823  // Used as a helper object to pick instances of vtkProp
826 
827  bool Done; // is the event loop done running
828 
833  virtual vtkPickingManager* CreateDefaultPickingManager();
834 
836  int Enabled;
838  int Style;
843 
844  // Event information
845  int AltKey;
847  int ShiftKey;
848  char KeyCode;
849  double Rotation;
850  double LastRotation;
851  double Scale;
852  double LastScale;
853  double Translation[2];
854  double LastTranslation[2];
856  char* KeySym;
857  int EventPosition[2];
858  int LastEventPosition[2];
859  int EventSize[2];
860  int Size[2];
865 
866  int EventPositions[VTKI_MAX_POINTERS][2];
867  int LastEventPositions[VTKI_MAX_POINTERS][2];
869 
870  size_t PointerIndexLookup[VTKI_MAX_POINTERS];
871 
872  // control the fly to
874  double Dolly;
875 
884  friend class vtkInteractorObserver;
885  void GrabFocus(vtkCommand* mouseEvents, vtkCommand* keypressEvents = nullptr)
886  {
887  this->Superclass::InternalGrabFocus(mouseEvents, keypressEvents);
888  }
890 
895 
896  // Timer related members
897  friend struct vtkTimerStruct;
898  vtkTimerIdMap* TimerMap; // An internal, PIMPLd map of timers and associated attributes
899  unsigned long TimerDuration; // in milliseconds
901 
907  virtual int InternalCreateTimer(int timerId, int timerType, unsigned long duration);
908  virtual int InternalDestroyTimer(int platformTimerId);
909  int GetCurrentTimerId();
911 
912  // Force the interactor to handle the Start() event loop, ignoring any
913  // overrides. (Overrides are registered by observing StartEvent on the
914  // interactor.)
916 
920  virtual void StartEventLoop() {}
921 
922  bool UseTDx; // 3DConnexion device.
923 
924  // when recognizing gestures VTK will take multitouch events
925  // if it receives them and convert them to gestures
928  int PointersDown[VTKI_MAX_POINTERS];
929  virtual void RecognizeGesture(vtkCommand::EventIds);
930  int StartingEventPositions[VTKI_MAX_POINTERS][2];
932 
933 private:
935  void operator=(const vtkRenderWindowInteractor&) = delete;
936 };
937 
938 #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.
virtual void GetMousePosition(int *x, int *y)
Get the current position of the mouse.
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:62
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:155
virtual void SetEventPositionFlipY(int pos[2], int pointerIndex)
abstract specification for renderers
Definition: vtkRenderer.h:72
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 ...
void FlyTo(vtkRenderer *ren, double *x)
Given a position x, move the current camera's focal point to x.
int vtkTypeBool
Definition: vtkABI.h:69
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:394
#define VTK_FLOAT_MAX
Definition: vtkType.h:163
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:39
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).
virtual void TerminateApp(void)
This function is called on 'q','e' keypress if exitmethod is not specified and should be overridden b...
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:73
virtual void SetEventPosition(int x, int y)
Set/Get information about the current event.
virtual void ProcessEvents()
Run the event loop and return.
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
#define VTKI_MAX_POINTERS
define API for picking subclasses
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.
virtual void SetEventPositionFlipY(int x, int y)
Set/Get information about the current event.