VTK
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 =========================================================================*/
45 #ifndef vtkRenderWindowInteractor_h
46 #define vtkRenderWindowInteractor_h
47 
48 #include "vtkRenderingCoreModule.h" // For export macro
49 #include "vtkObject.h"
50 #include "vtkCommand.h" // for method sig
51 
52 class vtkTimerIdMap;
53 
54 // Timer flags for win32/X compatibility
55 #define VTKI_TIMER_FIRST 0
56 #define VTKI_TIMER_UPDATE 1
57 
58 // maximum pointers active at once
59 // for example in multitouch
60 #define VTKI_MAX_POINTERS 5
61 
62 class vtkAbstractPicker;
64 class vtkAssemblyPath;
66 class vtkRenderWindow;
67 class vtkRenderer;
70 class vtkPickingManager;
71 
72 class VTKRENDERINGCORE_EXPORT vtkRenderWindowInteractor : public vtkObject
73 {
74 
76 
77 public:
80  void PrintSelf(ostream& os, vtkIndent indent) override;
81 
83 
90  virtual void Initialize();
91  void ReInitialize() { this->Initialized = 0; this->Enabled = 0;
92  this->Initialize(); }
94 
99  void UnRegister(vtkObjectBase *o) override;
100 
106  virtual void Start();
107 
117  virtual void Enable() { this->Enabled = 1; this->Modified();}
118  virtual void Disable() { this->Enabled = 0; this->Modified();}
119  vtkGetMacro(Enabled, int);
120 
122 
126  vtkBooleanMacro(EnableRender, bool);
127  vtkSetMacro(EnableRender, bool);
128  vtkGetMacro(EnableRender, bool);
130 
132 
135  void SetRenderWindow(vtkRenderWindow *aren);
136  vtkGetObjectMacro(RenderWindow,vtkRenderWindow);
138 
143  virtual void UpdateSize(int x,int y);
144 
161  virtual int CreateTimer(int timerType); //first group, for backward compatibility
162  virtual int DestroyTimer(); //first group, for backward compatibility
163 
168  int CreateRepeatingTimer(unsigned long duration);
169 
174  int CreateOneShotTimer(unsigned long duration);
175 
180  int IsOneShotTimer(int timerId);
181 
185  unsigned long GetTimerDuration(int timerId);
186 
190  int ResetTimer(int timerId);
191 
196  int DestroyTimer(int timerId);
197 
201  virtual int GetVTKTimerId(int platformTimerId);
202 
203  // Moved into the public section of the class so that classless timer procs
204  // can access these enum members without being "friends"...
205  enum {OneShotTimer=1,RepeatingTimer};
206 
208 
217  vtkSetClampMacro(TimerDuration,unsigned long,1,100000);
218  vtkGetMacro(TimerDuration,unsigned long);
220 
222 
234  vtkSetMacro(TimerEventId, int);
235  vtkGetMacro(TimerEventId, int);
236  vtkSetMacro(TimerEventType, int);
237  vtkGetMacro(TimerEventType, int);
238  vtkSetMacro(TimerEventDuration, int);
239  vtkGetMacro(TimerEventDuration, int);
240  vtkSetMacro(TimerEventPlatformId, int);
241  vtkGetMacro(TimerEventPlatformId, int);
243 
249  virtual void TerminateApp(void) {}
250 
252 
256  virtual void SetInteractorStyle(vtkInteractorObserver *);
257  vtkGetObjectMacro(InteractorStyle,vtkInteractorObserver);
259 
261 
265  vtkSetMacro(LightFollowCamera,vtkTypeBool);
266  vtkGetMacro(LightFollowCamera,vtkTypeBool);
267  vtkBooleanMacro(LightFollowCamera,vtkTypeBool);
269 
271 
278  vtkSetClampMacro(DesiredUpdateRate,double,0.0001,VTK_FLOAT_MAX);
279  vtkGetMacro(DesiredUpdateRate,double);
281 
283 
288  vtkSetClampMacro(StillUpdateRate,double,0.0001,VTK_FLOAT_MAX);
289  vtkGetMacro(StillUpdateRate,double);
291 
293 
297  vtkGetMacro(Initialized,int);
299 
301 
307  virtual void SetPicker(vtkAbstractPicker*);
308  vtkGetObjectMacro(Picker,vtkAbstractPicker);
310 
315  virtual vtkAbstractPropPicker *CreateDefaultPicker();
316 
318 
323  virtual void SetPickingManager(vtkPickingManager*);
324  vtkGetObjectMacro(PickingManager,vtkPickingManager);
326 
328 
332  virtual void ExitCallback();
333  virtual void UserCallback();
334  virtual void StartPickCallback();
335  virtual void EndPickCallback();
337 
341  virtual void GetMousePosition(int *x, int *y) { *x = 0 ; *y = 0; }
342 
344 
348  void HideCursor();
349  void ShowCursor();
351 
356  virtual void Render();
357 
359 
364  void FlyTo(vtkRenderer *ren, double x, double y, double z);
365  void FlyTo(vtkRenderer *ren, double *x)
366  {this->FlyTo(ren, x[0], x[1], x[2]);}
367  void FlyToImage(vtkRenderer *ren, double x, double y);
368  void FlyToImage(vtkRenderer *ren, double *x)
369  {this->FlyToImage(ren, x[0], x[1]);}
371 
373 
376  vtkSetClampMacro(NumberOfFlyFrames,int,1,VTK_INT_MAX);
377  vtkGetMacro(NumberOfFlyFrames,int);
379 
381 
385  vtkSetMacro(Dolly,double);
386  vtkGetMacro(Dolly,double);
388 
390 
398  vtkGetVector2Macro(EventPosition,int);
399  vtkGetVector2Macro(LastEventPosition,int);
400  vtkSetVector2Macro(LastEventPosition,int);
401  virtual void SetEventPosition(int x, int y)
402  {
403  vtkDebugMacro(<< this->GetClassName() << " (" << this
404  << "): setting EventPosition to (" << x << "," << y << ")");
405  if (this->EventPosition[0] != x || this->EventPosition[1] != y ||
406  this->LastEventPosition[0] != x || this->LastEventPosition[1] != y)
407  {
408  this->LastEventPosition[0] = this->EventPosition[0];
409  this->LastEventPosition[1] = this->EventPosition[1];
410  this->EventPosition[0] = x;
411  this->EventPosition[1] = y;
412  this->Modified();
413  }
414  }
415  virtual void SetEventPosition(int pos[2])
416  {
417  this->SetEventPosition(pos[0], pos[1]);
418  }
419  virtual void SetEventPositionFlipY(int x, int y)
420  {
421  this->SetEventPosition(x, this->Size[1] - y - 1);
422  }
423  virtual void SetEventPositionFlipY(int pos[2])
424  {
425  this->SetEventPositionFlipY(pos[0], pos[1]);
426  }
428 
429  virtual int *GetEventPositions(int pointerIndex)
430  {
431  if (pointerIndex >= VTKI_MAX_POINTERS)
432  {
433  return nullptr;
434  }
435  return this->EventPositions[pointerIndex];
436  }
437  virtual int *GetLastEventPositions(int pointerIndex)
438  {
439  if (pointerIndex >= VTKI_MAX_POINTERS)
440  {
441  return nullptr;
442  }
443  return this->LastEventPositions[pointerIndex];
444  }
445  virtual void SetEventPosition(int x, int y, int pointerIndex)
446  {
447  if (pointerIndex < 0 || pointerIndex >= VTKI_MAX_POINTERS)
448  {
449  return;
450  }
451  if (pointerIndex == 0)
452  {
453  this->LastEventPosition[0] = this->EventPosition[0];
454  this->LastEventPosition[1] = this->EventPosition[1];
455  this->EventPosition[0] = x;
456  this->EventPosition[1] = y;
457  }
458  vtkDebugMacro(<< this->GetClassName() << " (" << this
459  << "): setting EventPosition to (" << x << "," << y << ") for pointerIndex number " << pointerIndex);
460  if (this->EventPositions[pointerIndex][0] != x || this->EventPositions[pointerIndex][1] != y ||
461  this->LastEventPositions[pointerIndex][0] != x || this->LastEventPositions[pointerIndex][1] != y)
462  {
463  this->LastEventPositions[pointerIndex][0] = this->EventPositions[pointerIndex][0];
464  this->LastEventPositions[pointerIndex][1] = this->EventPositions[pointerIndex][1];
465  this->EventPositions[pointerIndex][0] = x;
466  this->EventPositions[pointerIndex][1] = y;
467  this->Modified();
468  }
469  }
470  virtual void SetEventPosition(int pos[2], int pointerIndex)
471  {
472  this->SetEventPosition(pos[0], pos[1], pointerIndex);
473  }
474  virtual void SetEventPositionFlipY(int x, int y, int pointerIndex)
475  {
476  this->SetEventPosition(x, this->Size[1] - y - 1, pointerIndex);
477  }
478  virtual void SetEventPositionFlipY(int pos[2], int pointerIndex)
479  {
480  this->SetEventPositionFlipY(pos[0], pos[1], pointerIndex);
481  }
482 
484 
487  vtkSetMacro(AltKey, int);
488  vtkGetMacro(AltKey, int);
490 
492 
495  vtkSetMacro(ControlKey, int);
496  vtkGetMacro(ControlKey, int);
498 
500 
503  vtkSetMacro(ShiftKey, int);
504  vtkGetMacro(ShiftKey, int);
506 
508 
511  vtkSetMacro(KeyCode, char);
512  vtkGetMacro(KeyCode, char);
514 
516 
520  vtkSetMacro(RepeatCount, int);
521  vtkGetMacro(RepeatCount, int);
523 
525 
531  vtkSetStringMacro(KeySym);
532  vtkGetStringMacro(KeySym);
534 
536 
539  vtkSetMacro(PointerIndex, int);
540  vtkGetMacro(PointerIndex, int);
542 
544 
547  void SetRotation(double val);
548  vtkGetMacro(Rotation, double);
549  vtkGetMacro(LastRotation, double);
551 
553 
556  void SetScale(double val);
557  vtkGetMacro(Scale, double);
558  vtkGetMacro(LastScale, double);
560 
562 
565  void SetTranslation(double val[2]);
566  vtkGetVector2Macro(Translation, double);
567  vtkGetVector2Macro(LastTranslation, double);
569 
571 
575  int y,
576  int ctrl,
577  int shift,
578  char keycode,
579  int repeatcount,
580  const char* keysym,
581  int pointerIndex)
582  {
583  this->SetEventPosition(x,y,pointerIndex);
584  this->ControlKey = ctrl;
585  this->ShiftKey = shift;
586  this->KeyCode = keycode;
587  this->RepeatCount = repeatcount;
588  this->PointerIndex = pointerIndex;
589  if(keysym)
590  {
591  this->SetKeySym(keysym);
592  }
593  this->Modified();
594  }
595  void SetEventInformation(int x, int y,
596  int ctrl=0, int shift=0,
597  char keycode=0,
598  int repeatcount=0,
599  const char* keysym=nullptr)
600  {
601  this->SetEventInformation(x,y,ctrl,shift,keycode,repeatcount,keysym,0);
602  }
604 
606 
610  void SetEventInformationFlipY(int x, int y,
611  int ctrl, int shift,
612  char keycode,
613  int repeatcount,
614  const char* keysym,
615  int pointerIndex)
616  {
617  this->SetEventInformation(x,
618  this->Size[1] - y - 1,
619  ctrl,
620  shift,
621  keycode,
622  repeatcount,
623  keysym,
624  pointerIndex);
625  }
626  void SetEventInformationFlipY(int x, int y,
627  int ctrl=0, int shift=0,
628  char keycode=0,
629  int repeatcount=0,
630  const char* keysym=nullptr)
631  {
632  this->SetEventInformationFlipY(x,y,ctrl,shift,keycode,repeatcount,keysym,0);
633  }
635 
637 
640  void SetKeyEventInformation(int ctrl=0,
641  int shift=0,
642  char keycode=0,
643  int repeatcount=0,
644  const char* keysym=nullptr)
645  {
646  this->ControlKey = ctrl;
647  this->ShiftKey = shift;
648  this->KeyCode = keycode;
649  this->RepeatCount = repeatcount;
650  if(keysym)
651  {
652  this->SetKeySym(keysym);
653  }
654  this->Modified();
655  }
657 
659 
670  vtkSetVector2Macro(Size,int);
671  vtkGetVector2Macro(Size,int);
672  vtkSetVector2Macro(EventSize,int);
673  vtkGetVector2Macro(EventSize,int);
675 
681  virtual vtkRenderer *FindPokedRenderer(int,int);
682 
690  vtkObserverMediator *GetObserverMediator();
691 
693 
701  vtkSetMacro(UseTDx,bool);
702  vtkGetMacro(UseTDx,bool);
704 
706 
711  virtual void MouseMoveEvent();
712  virtual void RightButtonPressEvent();
713  virtual void RightButtonReleaseEvent();
714  virtual void LeftButtonPressEvent();
715  virtual void LeftButtonReleaseEvent();
716  virtual void MiddleButtonPressEvent();
717  virtual void MiddleButtonReleaseEvent();
718  virtual void MouseWheelForwardEvent();
719  virtual void MouseWheelBackwardEvent();
720  virtual void ExposeEvent();
721  virtual void ConfigureEvent();
722  virtual void EnterEvent();
723  virtual void LeaveEvent();
724  virtual void KeyPressEvent();
725  virtual void KeyReleaseEvent();
726  virtual void CharEvent();
727  virtual void ExitEvent();
728  virtual void FourthButtonPressEvent();
729  virtual void FourthButtonReleaseEvent();
730  virtual void FifthButtonPressEvent();
731  virtual void FifthButtonReleaseEvent();
733 
735 
739  virtual void StartPinchEvent();
740  virtual void PinchEvent();
741  virtual void EndPinchEvent();
742  virtual void StartRotateEvent();
743  virtual void RotateEvent();
744  virtual void EndRotateEvent();
745  virtual void StartPanEvent();
746  virtual void PanEvent();
747  virtual void EndPanEvent();
748  virtual void TapEvent();
749  virtual void LongTapEvent();
750  virtual void SwipeEvent();
752 
754 
760  vtkSetMacro(RecognizeGestures,bool);
761  vtkGetMacro(RecognizeGestures,bool);
763 
765 
770  vtkGetMacro(PointersDownCount,int);
772 
774 
781  void ClearContact(size_t contactID);
782  int GetPointerIndexForContact(size_t contactID);
783  int GetPointerIndexForExistingContact(size_t contactID);
784  bool IsPointerIndexSet(int i);
785  void ClearPointerIndex(int i);
787 
788 protected:
790  ~vtkRenderWindowInteractor() override;
791 
794 
795  // Used as a helper object to pick instances of vtkProp
798 
803  virtual vtkPickingManager *CreateDefaultPickingManager();
804 
806  int Enabled;
808  int Style;
813 
814  // Event information
815  int AltKey;
817  int ShiftKey;
818  char KeyCode;
819  double Rotation;
820  double LastRotation;
821  double Scale;
822  double LastScale;
823  double Translation[2];
824  double LastTranslation[2];
826  char* KeySym;
827  int EventPosition[2];
828  int LastEventPosition[2];
829  int EventSize[2];
830  int Size[2];
835 
836  int EventPositions[VTKI_MAX_POINTERS][2];
837  int LastEventPositions[VTKI_MAX_POINTERS][2];
839 
840  size_t PointerIndexLookup[VTKI_MAX_POINTERS];
841 
842  // control the fly to
844  double Dolly;
845 
854  friend class vtkInteractorObserver;
855  void GrabFocus(vtkCommand *mouseEvents, vtkCommand *keypressEvents=nullptr)
856  {this->Superclass::InternalGrabFocus(mouseEvents,keypressEvents);}
859 
864 
865  // Timer related members
866  friend struct vtkTimerStruct;
867  vtkTimerIdMap *TimerMap; // An internal, PIMPLd map of timers and associated attributes
868  unsigned long TimerDuration; //in milliseconds
870 
876  virtual int InternalCreateTimer(int timerId, int timerType, unsigned long duration);
877  virtual int InternalDestroyTimer(int platformTimerId);
878  int GetCurrentTimerId();
880 
881  // Force the interactor to handle the Start() event loop, ignoring any
882  // overrides. (Overrides are registered by observing StartEvent on the
883  // interactor.)
885 
889  virtual void StartEventLoop() {}
890 
891  bool UseTDx; // 3DConnexion device.
892 
893  // when recognizing gestures VTK will take multitouch events
894  // if it receives them and convert them to gestures
897  int PointersDown[VTKI_MAX_POINTERS];
898  virtual void RecognizeGesture(vtkCommand::EventIds);
899  int StartingEventPositions[VTKI_MAX_POINTERS][2];
901 
902 private:
904  void operator=(const vtkRenderWindowInteractor&) = delete;
905 };
906 
907 #endif
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:53
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:159
vtkInteractorObserver * InteractorStyle
virtual void SetEventPositionFlipY(int pos[2], int pointerIndex)
abstract specification for renderers
Definition: vtkRenderer.h:57
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:370
#define VTK_FLOAT_MAX
Definition: vtkType.h:167
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 '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)
abstract base class for most VTK objects
Definition: vtkObjectBase.h:62
virtual void SetEventPosition(int x, int y)
Set/Get information about the current event.
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.