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);
87 
89 
96  virtual void Initialize();
97  void ReInitialize() { this->Initialized = 0; this->Enabled = 0;
98  this->Initialize(); }
100 
105  virtual void UnRegister(vtkObjectBase *o);
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 
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 
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 
322 
324 
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 NULL;
440  }
441  return this->EventPositions[pointerIndex];
442  }
443  virtual int *GetLastEventPositions(int pointerIndex)
444  {
445  if (pointerIndex >= VTKI_MAX_POINTERS)
446  {
447  return NULL;
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);
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=0)
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=0)
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=0)
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 
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();
735 
737 
741  virtual void StartPinchEvent();
742  virtual void PinchEvent();
743  virtual void EndPinchEvent();
744  virtual void StartRotateEvent();
745  virtual void RotateEvent();
746  virtual void EndRotateEvent();
747  virtual void StartPanEvent();
748  virtual void PanEvent();
749  virtual void EndPanEvent();
750  virtual void TapEvent();
751  virtual void LongTapEvent();
752  virtual void SwipeEvent();
754 
756 
762  vtkSetMacro(RecognizeGestures,bool);
763  vtkGetMacro(RecognizeGestures,bool);
765 
767 
772  vtkGetMacro(PointersDownCount,int);
774 
776 
783  void ClearContact(size_t contactID);
784  int GetPointerIndexForContact(size_t contactID);
785  int GetPointerIndexForExistingContact(size_t contactID);
786  bool IsPointerIndexSet(int i);
787  void ClearPointerIndex(int i);
789 
790 protected:
793 
796 
797  // Used as a helper object to pick instances of vtkProp
800 
806 
808  int Enabled;
810  int Style;
815 
816  // Event information
817  int AltKey;
819  int ShiftKey;
820  char KeyCode;
821  double Rotation;
822  double LastRotation;
823  double Scale;
824  double LastScale;
825  double Translation[2];
826  double LastTranslation[2];
828  char* KeySym;
829  int EventPosition[2];
830  int LastEventPosition[2];
831  int EventSize[2];
832  int Size[2];
837 
838  int EventPositions[VTKI_MAX_POINTERS][2];
839  int LastEventPositions[VTKI_MAX_POINTERS][2];
841 
842  size_t PointerIndexLookup[VTKI_MAX_POINTERS];
843 
844  // control the fly to
846  double Dolly;
847 
856  friend class vtkInteractorObserver;
857  void GrabFocus(vtkCommand *mouseEvents, vtkCommand *keypressEvents=NULL)
858  {this->Superclass::InternalGrabFocus(mouseEvents,keypressEvents);}
861 
866 
867  // Timer related members
868  friend struct vtkTimerStruct;
869  vtkTimerIdMap *TimerMap; // An internal, PIMPLd map of timers and associated attributes
870  unsigned long TimerDuration; //in milliseconds
872 
878  virtual int InternalCreateTimer(int timerId, int timerType, unsigned long duration);
879  virtual int InternalDestroyTimer(int platformTimerId);
882 
883  // Force the interactor to handle the Start() event loop, ignoring any
884  // overrides. (Overrides are registered by observing StartEvent on the
885  // interactor.)
887 
891  virtual void StartEventLoop() {}
892 
893  bool UseTDx; // 3DConnexion device.
894 
895  // when recognizing gestures VTK will take multitouch events
896  // if it receives them and convert them to gestures
899  int PointersDown[VTKI_MAX_POINTERS];
900  virtual void RecognizeGesture(vtkCommand::EventIds);
901  int StartingEventPositions[VTKI_MAX_POINTERS][2];
902  vtkCommand::EventIds CurrentGesture;
903 
904 private:
905  vtkRenderWindowInteractor(const vtkRenderWindowInteractor&) VTK_DELETE_FUNCTION;
906  void operator=(const vtkRenderWindowInteractor&) VTK_DELETE_FUNCTION;
907 };
908 
909 #endif
define API for picking subclasses
abstract API for pickers that can pick an instance of vtkProp
a list of nodes that form an assembly path
superclass for callback/observer methods
Definition: vtkCommand.h:342
a simple class to control print indentation
Definition: vtkIndent.h:40
record and play VTK events passing through a vtkRenderWindowInteractor
an abstract superclass for classes observing events invoked by vtkRenderWindowInteractor
abstract base class for most VTK objects
Definition: vtkObjectBase.h:66
const char * GetClassName() const
Return the class name as a string.
abstract base class for most VTK objects
Definition: vtkObject.h:60
void InternalReleaseFocus()
void InternalGrabFocus(vtkCommand *mouseEvents, vtkCommand *keypressEvents=NULL)
These methods allow a command to exclusively grab all events.
virtual void Modified()
Update the modification time for this object.
manage contention for cursors and other resources
Class defines API to manage the picking process.
platform-independent render window interaction including picking and frame rate control.
unsigned long GetTimerDuration(int timerId)
Get the duration (in milliseconds) for the specified timerId.
void HideCursor()
Hide or show the mouse cursor, it is nice to be able to hide the default cursor if you want VTK to di...
virtual void StartEventLoop()
Run the event loop (does not return until TerminateApp is called).
virtual void PinchEvent()
virtual void SwipeEvent()
virtual void StartRotateEvent()
void SetRenderWindow(vtkRenderWindow *aren)
Set/Get the rendering window being controlled by this object.
virtual void SetEventPositionFlipY(int pos[2], int pointerIndex)
virtual void EndPinchEvent()
virtual void KeyReleaseEvent()
virtual void EndPickCallback()
virtual void Enable()
Enable/Disable interactions.
virtual int InternalDestroyTimer(int platformTimerId)
int CreateRepeatingTimer(unsigned long duration)
Create a repeating timer, with the specified duration (in milliseconds).
virtual vtkAbstractPropPicker * CreateDefaultPicker()
Create default picker.
vtkObserverMediator * ObserverMediator
Widget mediators are used to resolve contention for cursors and other resources.
virtual void EndRotateEvent()
virtual void ExitEvent()
void FlyToImage(vtkRenderer *ren, double x, double y)
virtual void ExposeEvent()
virtual void EndPanEvent()
virtual void Render()
Render the scene.
virtual void MouseWheelForwardEvent()
virtual void SetEventPosition(int x, int y)
virtual void UserCallback()
void SetKeyEventInformation(int ctrl=0, int shift=0, char keycode=0, int repeatcount=0, const char *keysym=0)
Set all the keyboard-related event information in one call.
virtual void LeftButtonReleaseEvent()
virtual void CharEvent()
virtual int DestroyTimer()
int IsOneShotTimer(int timerId)
Query whether the specified timerId is a one shot timer.
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.
vtkObserverMediator * GetObserverMediator()
Return the object used to mediate between vtkInteractorObservers contending for resources.
virtual void TerminateApp(void)
This function is called on 'q','e' keypress if exitmethod is not specified and should be overridden b...
virtual void UpdateSize(int x, int y)
Event loop notification member for window size change.
void SetEventInformation(int x, int y, int ctrl=0, int shift=0, char keycode=0, int repeatcount=0, const char *keysym=0)
virtual int * GetEventPositions(int pointerIndex)
virtual void LeaveEvent()
virtual void EnterEvent()
virtual int InternalCreateTimer(int timerId, int timerType, unsigned long duration)
Internal methods for creating and destroying timers that must be implemented by subclasses.
static vtkRenderWindowInteractor * New()
virtual void RightButtonPressEvent()
virtual void Start()
Start the event loop.
virtual vtkPickingManager * CreateDefaultPickingManager()
Create default pickingManager.
virtual void ConfigureEvent()
virtual vtkRenderer * FindPokedRenderer(int, int)
When an event occurs, we must determine which Renderer the event occurred within, since one RenderWin...
virtual void StartPanEvent()
virtual int CreateTimer(int timerType)
This class provides two groups of methods for manipulating timers.
virtual void UnRegister(vtkObjectBase *o)
This Method detects loops of RenderWindow-Interactor, so objects are freed properly.
int ResetTimer(int timerId)
Reset the specified timer.
virtual void MouseWheelBackwardEvent()
virtual void SetInteractorStyle(vtkInteractorObserver *)
External switching between joystick/trackball/new? modes.
void ClearContact(size_t contactID)
Most multitouch systems use persistent contact/pointer ids to track events/motion during multitouch e...
void SetRotation(double val)
Set/get the rotation for the gesture in degrees, update LastRotation.
void FlyTo(vtkRenderer *ren, double x, double y, double z)
Given a position x, move the current camera's focal point to x.
int CreateOneShotTimer(unsigned long duration)
Create a one shot timer, with the specified duretion (in milliseconds).
virtual void ExitCallback()
These methods correspond to the the Exit, User and Pick callbacks.
void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
int DestroyTimer(int timerId)
Destroy the timer specified by timerId.
void SetTranslation(double val[2])
Set/get the tranlation for pan/swipe gestures, update LastTranslation.
void FlyToImage(vtkRenderer *ren, double *x)
virtual void RightButtonReleaseEvent()
virtual void SetEventPositionFlipY(int x, int y, int pointerIndex)
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 GetMousePosition(int *x, int *y)
Get the current position of the mouse.
virtual void SetEventPositionFlipY(int x, int y)
int GetPointerIndexForContact(size_t contactID)
virtual void LeftButtonPressEvent()
virtual void MiddleButtonPressEvent()
virtual int * GetLastEventPositions(int pointerIndex)
virtual void StartPickCallback()
int GetPointerIndexForExistingContact(size_t contactID)
virtual void MouseMoveEvent()
Fire various events.
void FlyTo(vtkRenderer *ren, double *x)
vtkInteractorObserver * InteractorStyle
virtual void StartPinchEvent()
Fire various gesture based events.
virtual void SetEventPosition(int pos[2])
virtual void SetPicker(vtkAbstractPicker *)
Set/Get the object used to perform pick operations.
virtual int GetVTKTimerId(int platformTimerId)
Get the VTK timer ID that corresponds to the supplied platform ID.
virtual void Initialize()
Prepare for handling events and set the Enabled flag to true.
virtual void RotateEvent()
void SetEventInformationFlipY(int x, int y, int ctrl=0, int shift=0, char keycode=0, int repeatcount=0, const char *keysym=0)
virtual void SetEventPositionFlipY(int pos[2])
virtual void SetEventPosition(int x, int y, int pointerIndex)
virtual void LongTapEvent()
void SetScale(double val)
Set/get the scale for the gesture, updates LastScale.
virtual void MiddleButtonReleaseEvent()
virtual void RecognizeGesture(vtkCommand::EventIds)
void GrabFocus(vtkCommand *mouseEvents, vtkCommand *keypressEvents=NULL)
virtual void SetEventPosition(int pos[2], int pointerIndex)
virtual void SetPickingManager(vtkPickingManager *)
Set the picking manager.
virtual void KeyPressEvent()
create a window for renderers to draw into
abstract specification for renderers
Definition: vtkRenderer.h:64
vtkSetMacro(IgnoreDriverBugs, bool)
Updates the extensions string.
vtkBooleanMacro(IgnoreDriverBugs, bool)
Updates the extensions string.
vtkGetStringMacro(ExtensionsString)
Returns a string listing all available extensions.
#define VTKI_MAX_POINTERS
#define VTK_INT_MAX
Definition: vtkType.h:153
#define VTK_FLOAT_MAX
Definition: vtkType.h:161