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 =========================================================================*/
51 #ifndef vtkRenderWindowInteractor_h
52 #define vtkRenderWindowInteractor_h
53 
54 #include "vtkRenderingCoreModule.h" // For export macro
55 #include "vtkObject.h"
56 #include "vtkCommand.h" // for method sig
57 
58 class vtkTimerIdMap;
59 
60 // Timer flags for win32/X compatibility
61 #define VTKI_TIMER_FIRST 0
62 #define VTKI_TIMER_UPDATE 1
63 
64 // maximum pointers active at once
65 // for example in multitouch
66 #define VTKI_MAX_POINTERS 5
67 
68 class vtkAbstractPicker;
70 class vtkAssemblyPath;
72 class vtkRenderWindow;
73 class vtkRenderer;
76 class vtkPickingManager;
77 
78 class VTKRENDERINGCORE_EXPORT vtkRenderWindowInteractor : public vtkObject
79 {
80 
82 
83 public:
86  void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
87 
89 
96  virtual void Initialize();
97  void ReInitialize() { this->Initialized = 0; this->Enabled = 0;
98  this->Initialize(); }
100 
105  void UnRegister(vtkObjectBase *o) VTK_OVERRIDE;
106 
112  virtual void Start();
113 
123  virtual void Enable() { this->Enabled = 1; this->Modified();}
124  virtual void Disable() { this->Enabled = 0; this->Modified();}
125  vtkGetMacro(Enabled, int);
126 
128 
132  vtkBooleanMacro(EnableRender, bool);
133  vtkSetMacro(EnableRender, bool);
134  vtkGetMacro(EnableRender, bool);
136 
138 
141  void SetRenderWindow(vtkRenderWindow *aren);
142  vtkGetObjectMacro(RenderWindow,vtkRenderWindow);
144 
149  virtual void UpdateSize(int x,int y);
150 
167  virtual int CreateTimer(int timerType); //first group, for backward compatibility
168  virtual int DestroyTimer(); //first group, for backward compatibility
169 
174  int CreateRepeatingTimer(unsigned long duration);
175 
180  int CreateOneShotTimer(unsigned long duration);
181 
186  int IsOneShotTimer(int timerId);
187 
191  unsigned long GetTimerDuration(int timerId);
192 
196  int ResetTimer(int timerId);
197 
202  int DestroyTimer(int timerId);
203 
207  virtual int GetVTKTimerId(int platformTimerId);
208 
209  // Moved into the public section of the class so that classless timer procs
210  // can access these enum members without being "friends"...
211  enum {OneShotTimer=1,RepeatingTimer};
212 
214 
223  vtkSetClampMacro(TimerDuration,unsigned long,1,100000);
224  vtkGetMacro(TimerDuration,unsigned long);
226 
228 
240  vtkSetMacro(TimerEventId, int);
241  vtkGetMacro(TimerEventId, int);
242  vtkSetMacro(TimerEventType, int);
243  vtkGetMacro(TimerEventType, int);
244  vtkSetMacro(TimerEventDuration, int);
245  vtkGetMacro(TimerEventDuration, int);
246  vtkSetMacro(TimerEventPlatformId, int);
247  vtkGetMacro(TimerEventPlatformId, int);
249 
255  virtual void TerminateApp(void) {}
256 
258 
262  virtual void SetInteractorStyle(vtkInteractorObserver *);
263  vtkGetObjectMacro(InteractorStyle,vtkInteractorObserver);
265 
267 
271  vtkSetMacro(LightFollowCamera,int);
272  vtkGetMacro(LightFollowCamera,int);
273  vtkBooleanMacro(LightFollowCamera,int);
275 
277 
284  vtkSetClampMacro(DesiredUpdateRate,double,0.0001,VTK_FLOAT_MAX);
285  vtkGetMacro(DesiredUpdateRate,double);
287 
289 
294  vtkSetClampMacro(StillUpdateRate,double,0.0001,VTK_FLOAT_MAX);
295  vtkGetMacro(StillUpdateRate,double);
297 
299 
303  vtkGetMacro(Initialized,int);
305 
307 
313  virtual void SetPicker(vtkAbstractPicker*);
314  vtkGetObjectMacro(Picker,vtkAbstractPicker);
316 
321  virtual vtkAbstractPropPicker *CreateDefaultPicker();
322 
324 
329  virtual void SetPickingManager(vtkPickingManager*);
330  vtkGetObjectMacro(PickingManager,vtkPickingManager);
332 
334 
338  virtual void ExitCallback();
339  virtual void UserCallback();
340  virtual void StartPickCallback();
341  virtual void EndPickCallback();
343 
347  virtual void GetMousePosition(int *x, int *y) { *x = 0 ; *y = 0; }
348 
350 
354  void HideCursor();
355  void ShowCursor();
357 
362  virtual void Render();
363 
365 
370  void FlyTo(vtkRenderer *ren, double x, double y, double z);
371  void FlyTo(vtkRenderer *ren, double *x)
372  {this->FlyTo(ren, x[0], x[1], x[2]);}
373  void FlyToImage(vtkRenderer *ren, double x, double y);
374  void FlyToImage(vtkRenderer *ren, double *x)
375  {this->FlyToImage(ren, x[0], x[1]);}
377 
379 
382  vtkSetClampMacro(NumberOfFlyFrames,int,1,VTK_INT_MAX);
383  vtkGetMacro(NumberOfFlyFrames,int);
385 
387 
391  vtkSetMacro(Dolly,double);
392  vtkGetMacro(Dolly,double);
394 
396 
404  vtkGetVector2Macro(EventPosition,int);
405  vtkGetVector2Macro(LastEventPosition,int);
406  vtkSetVector2Macro(LastEventPosition,int);
407  virtual void SetEventPosition(int x, int y)
408  {
409  vtkDebugMacro(<< this->GetClassName() << " (" << this
410  << "): setting EventPosition to (" << x << "," << y << ")");
411  if (this->EventPosition[0] != x || this->EventPosition[1] != y ||
412  this->LastEventPosition[0] != x || this->LastEventPosition[1] != y)
413  {
414  this->LastEventPosition[0] = this->EventPosition[0];
415  this->LastEventPosition[1] = this->EventPosition[1];
416  this->EventPosition[0] = x;
417  this->EventPosition[1] = y;
418  this->Modified();
419  }
420  }
421  virtual void SetEventPosition(int pos[2])
422  {
423  this->SetEventPosition(pos[0], pos[1]);
424  }
425  virtual void SetEventPositionFlipY(int x, int y)
426  {
427  this->SetEventPosition(x, this->Size[1] - y - 1);
428  }
429  virtual void SetEventPositionFlipY(int pos[2])
430  {
431  this->SetEventPositionFlipY(pos[0], pos[1]);
432  }
434 
435  virtual int *GetEventPositions(int pointerIndex)
436  {
437  if (pointerIndex >= VTKI_MAX_POINTERS)
438  {
439  return nullptr;
440  }
441  return this->EventPositions[pointerIndex];
442  }
443  virtual int *GetLastEventPositions(int pointerIndex)
444  {
445  if (pointerIndex >= VTKI_MAX_POINTERS)
446  {
447  return nullptr;
448  }
449  return this->LastEventPositions[pointerIndex];
450  }
451  virtual void SetEventPosition(int x, int y, int pointerIndex)
452  {
453  if (pointerIndex < 0 || pointerIndex >= VTKI_MAX_POINTERS)
454  {
455  return;
456  }
457  if (pointerIndex == 0)
458  {
459  this->LastEventPosition[0] = this->EventPosition[0];
460  this->LastEventPosition[1] = this->EventPosition[1];
461  this->EventPosition[0] = x;
462  this->EventPosition[1] = y;
463  }
464  vtkDebugMacro(<< this->GetClassName() << " (" << this
465  << "): setting EventPosition to (" << x << "," << y << ") for pointerIndex number " << pointerIndex);
466  if (this->EventPositions[pointerIndex][0] != x || this->EventPositions[pointerIndex][1] != y ||
467  this->LastEventPositions[pointerIndex][0] != x || this->LastEventPositions[pointerIndex][1] != y)
468  {
469  this->LastEventPositions[pointerIndex][0] = this->EventPositions[pointerIndex][0];
470  this->LastEventPositions[pointerIndex][1] = this->EventPositions[pointerIndex][1];
471  this->EventPositions[pointerIndex][0] = x;
472  this->EventPositions[pointerIndex][1] = y;
473  this->Modified();
474  }
475  }
476  virtual void SetEventPosition(int pos[2], int pointerIndex)
477  {
478  this->SetEventPosition(pos[0], pos[1], pointerIndex);
479  }
480  virtual void SetEventPositionFlipY(int x, int y, int pointerIndex)
481  {
482  this->SetEventPosition(x, this->Size[1] - y - 1, pointerIndex);
483  }
484  virtual void SetEventPositionFlipY(int pos[2], int pointerIndex)
485  {
486  this->SetEventPositionFlipY(pos[0], pos[1], pointerIndex);
487  }
488 
490 
493  vtkSetMacro(AltKey, int);
494  vtkGetMacro(AltKey, int);
496 
498 
501  vtkSetMacro(ControlKey, int);
502  vtkGetMacro(ControlKey, int);
504 
506 
509  vtkSetMacro(ShiftKey, int);
510  vtkGetMacro(ShiftKey, int);
512 
514 
517  vtkSetMacro(KeyCode, char);
518  vtkGetMacro(KeyCode, char);
520 
522 
526  vtkSetMacro(RepeatCount, int);
527  vtkGetMacro(RepeatCount, int);
529 
531 
537  vtkSetStringMacro(KeySym);
538  vtkGetStringMacro(KeySym);
540 
542 
545  vtkSetMacro(PointerIndex, int);
546  vtkGetMacro(PointerIndex, int);
548 
550 
553  void SetRotation(double val);
554  vtkGetMacro(Rotation, double);
555  vtkGetMacro(LastRotation, double);
557 
559 
562  void SetScale(double val);
563  vtkGetMacro(Scale, double);
564  vtkGetMacro(LastScale, double);
566 
568 
571  void SetTranslation(double val[2]);
572  vtkGetVector2Macro(Translation, double);
573  vtkGetVector2Macro(LastTranslation, double);
575 
577 
581  int y,
582  int ctrl,
583  int shift,
584  char keycode,
585  int repeatcount,
586  const char* keysym,
587  int pointerIndex)
588  {
589  this->SetEventPosition(x,y,pointerIndex);
590  this->ControlKey = ctrl;
591  this->ShiftKey = shift;
592  this->KeyCode = keycode;
593  this->RepeatCount = repeatcount;
594  this->PointerIndex = pointerIndex;
595  if(keysym)
596  {
597  this->SetKeySym(keysym);
598  }
599  this->Modified();
600  }
601  void SetEventInformation(int x, int y,
602  int ctrl=0, int shift=0,
603  char keycode=0,
604  int repeatcount=0,
605  const char* keysym=nullptr)
606  {
607  this->SetEventInformation(x,y,ctrl,shift,keycode,repeatcount,keysym,0);
608  }
610 
612 
616  void SetEventInformationFlipY(int x, int y,
617  int ctrl, int shift,
618  char keycode,
619  int repeatcount,
620  const char* keysym,
621  int pointerIndex)
622  {
623  this->SetEventInformation(x,
624  this->Size[1] - y - 1,
625  ctrl,
626  shift,
627  keycode,
628  repeatcount,
629  keysym,
630  pointerIndex);
631  }
632  void SetEventInformationFlipY(int x, int y,
633  int ctrl=0, int shift=0,
634  char keycode=0,
635  int repeatcount=0,
636  const char* keysym=nullptr)
637  {
638  this->SetEventInformationFlipY(x,y,ctrl,shift,keycode,repeatcount,keysym,0);
639  }
641 
643 
646  void SetKeyEventInformation(int ctrl=0,
647  int shift=0,
648  char keycode=0,
649  int repeatcount=0,
650  const char* keysym=nullptr)
651  {
652  this->ControlKey = ctrl;
653  this->ShiftKey = shift;
654  this->KeyCode = keycode;
655  this->RepeatCount = repeatcount;
656  if(keysym)
657  {
658  this->SetKeySym(keysym);
659  }
660  this->Modified();
661  }
663 
665 
676  vtkSetVector2Macro(Size,int);
677  vtkGetVector2Macro(Size,int);
678  vtkSetVector2Macro(EventSize,int);
679  vtkGetVector2Macro(EventSize,int);
681 
687  virtual vtkRenderer *FindPokedRenderer(int,int);
688 
696  vtkObserverMediator *GetObserverMediator();
697 
699 
707  vtkSetMacro(UseTDx,bool);
708  vtkGetMacro(UseTDx,bool);
710 
712 
717  virtual void MouseMoveEvent();
718  virtual void RightButtonPressEvent();
719  virtual void RightButtonReleaseEvent();
720  virtual void LeftButtonPressEvent();
721  virtual void LeftButtonReleaseEvent();
722  virtual void MiddleButtonPressEvent();
723  virtual void MiddleButtonReleaseEvent();
724  virtual void MouseWheelForwardEvent();
725  virtual void MouseWheelBackwardEvent();
726  virtual void ExposeEvent();
727  virtual void ConfigureEvent();
728  virtual void EnterEvent();
729  virtual void LeaveEvent();
730  virtual void KeyPressEvent();
731  virtual void KeyReleaseEvent();
732  virtual void CharEvent();
733  virtual void ExitEvent();
734  virtual void FourthButtonPressEvent();
735  virtual void FourthButtonReleaseEvent();
736  virtual void FifthButtonPressEvent();
737  virtual void FifthButtonReleaseEvent();
739 
741 
745  virtual void StartPinchEvent();
746  virtual void PinchEvent();
747  virtual void EndPinchEvent();
748  virtual void StartRotateEvent();
749  virtual void RotateEvent();
750  virtual void EndRotateEvent();
751  virtual void StartPanEvent();
752  virtual void PanEvent();
753  virtual void EndPanEvent();
754  virtual void TapEvent();
755  virtual void LongTapEvent();
756  virtual void SwipeEvent();
758 
760 
766  vtkSetMacro(RecognizeGestures,bool);
767  vtkGetMacro(RecognizeGestures,bool);
769 
771 
776  vtkGetMacro(PointersDownCount,int);
778 
780 
787  void ClearContact(size_t contactID);
788  int GetPointerIndexForContact(size_t contactID);
789  int GetPointerIndexForExistingContact(size_t contactID);
790  bool IsPointerIndexSet(int i);
791  void ClearPointerIndex(int i);
793 
794 protected:
796  ~vtkRenderWindowInteractor() VTK_OVERRIDE;
797 
800 
801  // Used as a helper object to pick instances of vtkProp
804 
809  virtual vtkPickingManager *CreateDefaultPickingManager();
810 
812  int Enabled;
814  int Style;
819 
820  // Event information
821  int AltKey;
823  int ShiftKey;
824  char KeyCode;
825  double Rotation;
826  double LastRotation;
827  double Scale;
828  double LastScale;
829  double Translation[2];
830  double LastTranslation[2];
832  char* KeySym;
833  int EventPosition[2];
834  int LastEventPosition[2];
835  int EventSize[2];
836  int Size[2];
841 
842  int EventPositions[VTKI_MAX_POINTERS][2];
843  int LastEventPositions[VTKI_MAX_POINTERS][2];
845 
846  size_t PointerIndexLookup[VTKI_MAX_POINTERS];
847 
848  // control the fly to
850  double Dolly;
851 
860  friend class vtkInteractorObserver;
861  void GrabFocus(vtkCommand *mouseEvents, vtkCommand *keypressEvents=nullptr)
862  {this->Superclass::InternalGrabFocus(mouseEvents,keypressEvents);}
865 
870 
871  // Timer related members
872  friend struct vtkTimerStruct;
873  vtkTimerIdMap *TimerMap; // An internal, PIMPLd map of timers and associated attributes
874  unsigned long TimerDuration; //in milliseconds
876 
882  virtual int InternalCreateTimer(int timerId, int timerType, unsigned long duration);
883  virtual int InternalDestroyTimer(int platformTimerId);
884  int GetCurrentTimerId();
886 
887  // Force the interactor to handle the Start() event loop, ignoring any
888  // overrides. (Overrides are registered by observing StartEvent on the
889  // interactor.)
891 
895  virtual void StartEventLoop() {}
896 
897  bool UseTDx; // 3DConnexion device.
898 
899  // when recognizing gestures VTK will take multitouch events
900  // if it receives them and convert them to gestures
903  int PointersDown[VTKI_MAX_POINTERS];
904  virtual void RecognizeGesture(vtkCommand::EventIds);
905  int StartingEventPositions[VTKI_MAX_POINTERS][2];
906  vtkCommand::EventIds CurrentGesture;
907 
908 private:
909  vtkRenderWindowInteractor(const vtkRenderWindowInteractor&) VTK_DELETE_FUNCTION;
910  void operator=(const vtkRenderWindowInteractor&) VTK_DELETE_FUNCTION;
911 };
912 
913 #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:59
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:157
virtual void SetRenderWindow(vtkRenderWindow *renwin)
vtkInteractorObserver * InteractorStyle
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 ...
void FlyTo(vtkRenderer *ren, double *x)
Given a position x, move the current camera&#39;s focal point to x.
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:356
#define VTK_FLOAT_MAX
Definition: vtkType.h:165
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 &#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.
vtkGetStringMacro(ExtensionsString)
Returns a string listing all available extensions.
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:65
virtual void SetEventPosition(int x, int y)
Set/Get information about the current event.
vtkSetMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
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
vtkBooleanMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
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.