VTK  9.0.1
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 =========================================================================*/
48 #ifndef vtkRenderWindowInteractor_h
49 #define vtkRenderWindowInteractor_h
50 
51 #include "vtkCommand.h" // for method sig
52 #include "vtkObject.h"
53 #include "vtkRenderingCoreModule.h" // For export macro
54 
55 class vtkTimerIdMap;
56 
57 // Timer flags for win32/X compatibility
58 #define VTKI_TIMER_FIRST 0
59 #define VTKI_TIMER_UPDATE 1
60 
61 // maximum pointers active at once
62 // for example in multitouch
63 #define VTKI_MAX_POINTERS 5
64 
65 class vtkAbstractPicker;
67 class vtkAssemblyPath;
68 class vtkHardwareWindow;
70 class vtkRenderWindow;
71 class vtkRenderer;
74 class vtkPickingManager;
75 
76 class VTKRENDERINGCORE_EXPORT vtkRenderWindowInteractor : public vtkObject
77 {
78 
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 
121  virtual void ProcessEvents() {}
122 
126  vtkGetMacro(Done, bool);
127  vtkSetMacro(Done, bool);
128 
138  virtual void Enable()
139  {
140  this->Enabled = 1;
141  this->Modified();
142  }
143  virtual void Disable()
144  {
145  this->Enabled = 0;
146  this->Modified();
147  }
148  vtkGetMacro(Enabled, int);
149 
151 
155  vtkBooleanMacro(EnableRender, bool);
156  vtkSetMacro(EnableRender, bool);
157  vtkGetMacro(EnableRender, bool);
159 
161 
164  void SetRenderWindow(vtkRenderWindow* aren);
165  vtkGetObjectMacro(RenderWindow, vtkRenderWindow);
167 
169 
174  void SetHardwareWindow(vtkHardwareWindow* aren);
175  vtkGetObjectMacro(HardwareWindow, vtkHardwareWindow);
177 
185  virtual void UpdateSize(int x, int y);
186 
203  virtual int CreateTimer(int timerType); // first group, for backward compatibility
204  virtual int DestroyTimer(); // first group, for backward compatibility
205 
210  int CreateRepeatingTimer(unsigned long duration);
211 
216  int CreateOneShotTimer(unsigned long duration);
217 
222  int IsOneShotTimer(int timerId);
223 
227  unsigned long GetTimerDuration(int timerId);
228 
232  int ResetTimer(int timerId);
233 
238  int DestroyTimer(int timerId);
239 
243  virtual int GetVTKTimerId(int platformTimerId);
244 
245  // Moved into the public section of the class so that classless timer procs
246  // can access these enum members without being "friends"...
247  enum
248  {
249  OneShotTimer = 1,
250  RepeatingTimer
251  };
252 
254 
263  vtkSetClampMacro(TimerDuration, unsigned long, 1, 100000);
264  vtkGetMacro(TimerDuration, unsigned long);
266 
268 
280  vtkSetMacro(TimerEventId, int);
281  vtkGetMacro(TimerEventId, int);
282  vtkSetMacro(TimerEventType, int);
283  vtkGetMacro(TimerEventType, int);
284  vtkSetMacro(TimerEventDuration, int);
285  vtkGetMacro(TimerEventDuration, int);
286  vtkSetMacro(TimerEventPlatformId, int);
287  vtkGetMacro(TimerEventPlatformId, int);
289 
295  virtual void TerminateApp(void) { this->Done = true; }
296 
298 
302  virtual void SetInteractorStyle(vtkInteractorObserver*);
303  vtkGetObjectMacro(InteractorStyle, vtkInteractorObserver);
305 
307 
311  vtkSetMacro(LightFollowCamera, vtkTypeBool);
312  vtkGetMacro(LightFollowCamera, vtkTypeBool);
313  vtkBooleanMacro(LightFollowCamera, vtkTypeBool);
315 
317 
324  vtkSetClampMacro(DesiredUpdateRate, double, 0.0001, VTK_FLOAT_MAX);
325  vtkGetMacro(DesiredUpdateRate, double);
327 
329 
334  vtkSetClampMacro(StillUpdateRate, double, 0.0001, VTK_FLOAT_MAX);
335  vtkGetMacro(StillUpdateRate, double);
337 
339 
343  vtkGetMacro(Initialized, int);
345 
347 
353  virtual void SetPicker(vtkAbstractPicker*);
354  vtkGetObjectMacro(Picker, vtkAbstractPicker);
356 
361  virtual vtkAbstractPropPicker* CreateDefaultPicker();
362 
364 
369  virtual void SetPickingManager(vtkPickingManager*);
370  vtkGetObjectMacro(PickingManager, vtkPickingManager);
372 
374 
378  virtual void ExitCallback();
379  virtual void UserCallback();
380  virtual void StartPickCallback();
381  virtual void EndPickCallback();
383 
387  virtual void GetMousePosition(int* x, int* y)
388  {
389  *x = 0;
390  *y = 0;
391  }
392 
394 
398  void HideCursor();
399  void ShowCursor();
401 
406  virtual void Render();
407 
409 
414  void FlyTo(vtkRenderer* ren, double x, double y, double z);
415  void FlyTo(vtkRenderer* ren, double* x) { this->FlyTo(ren, x[0], x[1], x[2]); }
416  void FlyToImage(vtkRenderer* ren, double x, double y);
417  void FlyToImage(vtkRenderer* ren, double* x) { this->FlyToImage(ren, x[0], x[1]); }
419 
421 
424  vtkSetClampMacro(NumberOfFlyFrames, int, 1, VTK_INT_MAX);
425  vtkGetMacro(NumberOfFlyFrames, int);
427 
429 
433  vtkSetMacro(Dolly, double);
434  vtkGetMacro(Dolly, double);
436 
438 
446  vtkGetVector2Macro(EventPosition, int);
447  vtkGetVector2Macro(LastEventPosition, int);
448  vtkSetVector2Macro(LastEventPosition, int);
449  virtual void SetEventPosition(int x, int y)
450  {
451  vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting EventPosition to (" << x
452  << "," << y << ")");
453  if (this->EventPosition[0] != x || this->EventPosition[1] != y ||
454  this->LastEventPosition[0] != x || this->LastEventPosition[1] != y)
455  {
456  this->LastEventPosition[0] = this->EventPosition[0];
457  this->LastEventPosition[1] = this->EventPosition[1];
458  this->EventPosition[0] = x;
459  this->EventPosition[1] = y;
460  this->Modified();
461  }
462  }
463  virtual void SetEventPosition(int pos[2]) { this->SetEventPosition(pos[0], pos[1]); }
464  virtual void SetEventPositionFlipY(int x, int y)
465  {
466  this->SetEventPosition(x, this->Size[1] - y - 1);
467  }
468  virtual void SetEventPositionFlipY(int pos[2]) { this->SetEventPositionFlipY(pos[0], pos[1]); }
470 
471  virtual int* GetEventPositions(int pointerIndex)
472  {
473  if (pointerIndex >= VTKI_MAX_POINTERS)
474  {
475  return nullptr;
476  }
477  return this->EventPositions[pointerIndex];
478  }
479  virtual int* GetLastEventPositions(int pointerIndex)
480  {
481  if (pointerIndex >= VTKI_MAX_POINTERS)
482  {
483  return nullptr;
484  }
485  return this->LastEventPositions[pointerIndex];
486  }
487  virtual void SetEventPosition(int x, int y, int pointerIndex)
488  {
489  if (pointerIndex < 0 || pointerIndex >= VTKI_MAX_POINTERS)
490  {
491  return;
492  }
493  if (pointerIndex == 0)
494  {
495  this->LastEventPosition[0] = this->EventPosition[0];
496  this->LastEventPosition[1] = this->EventPosition[1];
497  this->EventPosition[0] = x;
498  this->EventPosition[1] = y;
499  }
500  vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting EventPosition to (" << x
501  << "," << y << ") for pointerIndex number " << pointerIndex);
502  if (this->EventPositions[pointerIndex][0] != x || this->EventPositions[pointerIndex][1] != y ||
503  this->LastEventPositions[pointerIndex][0] != x ||
504  this->LastEventPositions[pointerIndex][1] != y)
505  {
506  this->LastEventPositions[pointerIndex][0] = this->EventPositions[pointerIndex][0];
507  this->LastEventPositions[pointerIndex][1] = this->EventPositions[pointerIndex][1];
508  this->EventPositions[pointerIndex][0] = x;
509  this->EventPositions[pointerIndex][1] = y;
510  this->Modified();
511  }
512  }
513  virtual void SetEventPosition(int pos[2], int pointerIndex)
514  {
515  this->SetEventPosition(pos[0], pos[1], pointerIndex);
516  }
517  virtual void SetEventPositionFlipY(int x, int y, int pointerIndex)
518  {
519  this->SetEventPosition(x, this->Size[1] - y - 1, pointerIndex);
520  }
521  virtual void SetEventPositionFlipY(int pos[2], int pointerIndex)
522  {
523  this->SetEventPositionFlipY(pos[0], pos[1], pointerIndex);
524  }
525 
527 
530  vtkSetMacro(AltKey, int);
531  vtkGetMacro(AltKey, int);
533 
535 
538  vtkSetMacro(ControlKey, int);
539  vtkGetMacro(ControlKey, int);
541 
543 
546  vtkSetMacro(ShiftKey, int);
547  vtkGetMacro(ShiftKey, int);
549 
551 
554  vtkSetMacro(KeyCode, char);
555  vtkGetMacro(KeyCode, char);
557 
559 
563  vtkSetMacro(RepeatCount, int);
564  vtkGetMacro(RepeatCount, int);
566 
568 
574  vtkSetStringMacro(KeySym);
575  vtkGetStringMacro(KeySym);
577 
579 
582  vtkSetMacro(PointerIndex, int);
583  vtkGetMacro(PointerIndex, int);
585 
587 
590  void SetRotation(double val);
591  vtkGetMacro(Rotation, double);
592  vtkGetMacro(LastRotation, double);
594 
596 
599  void SetScale(double val);
600  vtkGetMacro(Scale, double);
601  vtkGetMacro(LastScale, double);
603 
605 
608  void SetTranslation(double val[2]);
609  vtkGetVector2Macro(Translation, double);
610  vtkGetVector2Macro(LastTranslation, double);
612 
614 
617  void SetEventInformation(int x, int y, int ctrl, int shift, char keycode, int repeatcount,
618  const char* keysym, int pointerIndex)
619  {
620  this->SetEventPosition(x, y, pointerIndex);
621  this->ControlKey = ctrl;
622  this->ShiftKey = shift;
623  this->KeyCode = keycode;
624  this->RepeatCount = repeatcount;
625  this->PointerIndex = pointerIndex;
626  if (keysym)
627  {
628  this->SetKeySym(keysym);
629  }
630  this->Modified();
631  }
632  void SetEventInformation(int x, int y, int ctrl = 0, int shift = 0, char keycode = 0,
633  int repeatcount = 0, const char* keysym = nullptr)
634  {
635  this->SetEventInformation(x, y, ctrl, shift, keycode, repeatcount, keysym, 0);
636  }
638 
640 
644  void SetEventInformationFlipY(int x, int y, int ctrl, int shift, char keycode, int repeatcount,
645  const char* keysym, int pointerIndex)
646  {
647  this->SetEventInformation(
648  x, this->Size[1] - y - 1, ctrl, shift, keycode, repeatcount, keysym, pointerIndex);
649  }
650  void SetEventInformationFlipY(int x, int y, int ctrl = 0, int shift = 0, char keycode = 0,
651  int repeatcount = 0, const char* keysym = nullptr)
652  {
653  this->SetEventInformationFlipY(x, y, ctrl, shift, keycode, repeatcount, keysym, 0);
654  }
656 
658 
661  void SetKeyEventInformation(int ctrl = 0, int shift = 0, char keycode = 0, int repeatcount = 0,
662  const char* keysym = nullptr)
663  {
664  this->ControlKey = ctrl;
665  this->ShiftKey = shift;
666  this->KeyCode = keycode;
667  this->RepeatCount = repeatcount;
668  if (keysym)
669  {
670  this->SetKeySym(keysym);
671  }
672  this->Modified();
673  }
675 
677 
688  vtkSetVector2Macro(Size, int);
689  vtkGetVector2Macro(Size, int);
690  vtkSetVector2Macro(EventSize, int);
691  vtkGetVector2Macro(EventSize, int);
693 
699  virtual vtkRenderer* FindPokedRenderer(int, int);
700 
708  vtkObserverMediator* GetObserverMediator();
709 
711 
719  vtkSetMacro(UseTDx, bool);
720  vtkGetMacro(UseTDx, bool);
722 
724 
729  virtual void MouseMoveEvent();
730  virtual void RightButtonPressEvent();
731  virtual void RightButtonReleaseEvent();
732  virtual void LeftButtonPressEvent();
733  virtual void LeftButtonReleaseEvent();
734  virtual void MiddleButtonPressEvent();
735  virtual void MiddleButtonReleaseEvent();
736  virtual void MouseWheelForwardEvent();
737  virtual void MouseWheelBackwardEvent();
738  virtual void ExposeEvent();
739  virtual void ConfigureEvent();
740  virtual void EnterEvent();
741  virtual void LeaveEvent();
742  virtual void KeyPressEvent();
743  virtual void KeyReleaseEvent();
744  virtual void CharEvent();
745  virtual void ExitEvent();
746  virtual void FourthButtonPressEvent();
747  virtual void FourthButtonReleaseEvent();
748  virtual void FifthButtonPressEvent();
749  virtual void FifthButtonReleaseEvent();
751 
753 
757  virtual void StartPinchEvent();
758  virtual void PinchEvent();
759  virtual void EndPinchEvent();
760  virtual void StartRotateEvent();
761  virtual void RotateEvent();
762  virtual void EndRotateEvent();
763  virtual void StartPanEvent();
764  virtual void PanEvent();
765  virtual void EndPanEvent();
766  virtual void TapEvent();
767  virtual void LongTapEvent();
768  virtual void SwipeEvent();
770 
772 
778  vtkSetMacro(RecognizeGestures, bool);
779  vtkGetMacro(RecognizeGestures, bool);
781 
783 
788  vtkGetMacro(PointersDownCount, int);
790 
792 
799  void ClearContact(size_t contactID);
800  int GetPointerIndexForContact(size_t contactID);
801  int GetPointerIndexForExistingContact(size_t contactID);
802  bool IsPointerIndexSet(int i);
803  void ClearPointerIndex(int i);
805 
806 protected:
808  ~vtkRenderWindowInteractor() override;
809 
813 
814  // Used as a helper object to pick instances of vtkProp
817 
818  bool Done; // is the event loop done running
819 
824  virtual vtkPickingManager* CreateDefaultPickingManager();
825 
827  int Enabled;
829  int Style;
834 
835  // Event information
836  int AltKey;
838  int ShiftKey;
839  char KeyCode;
840  double Rotation;
841  double LastRotation;
842  double Scale;
843  double LastScale;
844  double Translation[2];
845  double LastTranslation[2];
847  char* KeySym;
848  int EventPosition[2];
849  int LastEventPosition[2];
850  int EventSize[2];
851  int Size[2];
856 
857  int EventPositions[VTKI_MAX_POINTERS][2];
858  int LastEventPositions[VTKI_MAX_POINTERS][2];
860 
861  size_t PointerIndexLookup[VTKI_MAX_POINTERS];
862 
863  // control the fly to
865  double Dolly;
866 
875  friend class vtkInteractorObserver;
876  void GrabFocus(vtkCommand* mouseEvents, vtkCommand* keypressEvents = nullptr)
877  {
878  this->Superclass::InternalGrabFocus(mouseEvents, keypressEvents);
879  }
881 
886 
887  // Timer related members
888  friend struct vtkTimerStruct;
889  vtkTimerIdMap* TimerMap; // An internal, PIMPLd map of timers and associated attributes
890  unsigned long TimerDuration; // in milliseconds
892 
898  virtual int InternalCreateTimer(int timerId, int timerType, unsigned long duration);
899  virtual int InternalDestroyTimer(int platformTimerId);
900  int GetCurrentTimerId();
902 
903  // Force the interactor to handle the Start() event loop, ignoring any
904  // overrides. (Overrides are registered by observing StartEvent on the
905  // interactor.)
907 
911  virtual void StartEventLoop() {}
912 
913  bool UseTDx; // 3DConnexion device.
914 
915  // when recognizing gestures VTK will take multitouch events
916  // if it receives them and convert them to gestures
919  int PointersDown[VTKI_MAX_POINTERS];
920  virtual void RecognizeGesture(vtkCommand::EventIds);
921  int StartingEventPositions[VTKI_MAX_POINTERS][2];
923 
924 private:
926  void operator=(const vtkRenderWindowInteractor&) = delete;
927 };
928 
929 #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:56
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
vtkInteractorObserver * InteractorStyle
virtual void SetEventPositionFlipY(int pos[2], int pointerIndex)
abstract specification for renderers
Definition: vtkRenderer.h:61
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&#39;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:377
#define VTK_FLOAT_MAX
Definition: vtkType.h:163
const char * GetClassName() const
Return the class name as a string.
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:33
virtual void StartEventLoop()
Run the event loop (does not return until TerminateApp is called).
virtual void TerminateApp(void)
This function is called on &#39;q&#39;,&#39;e&#39; 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)
abstract base class for most VTK objects
Definition: vtkObjectBase.h:63
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&#39;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.