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 =========================================================================*/
53 #ifndef vtkRenderWindowInteractor_h
54 #define vtkRenderWindowInteractor_h
55 
56 #include "vtkRenderingCoreModule.h" // For export macro
57 #include "vtkObject.h"
58 
59 class vtkTimerIdMap;
60 
61 // Timer flags for win32/X compatibility
62 #define VTKI_TIMER_FIRST 0
63 #define VTKI_TIMER_UPDATE 1
64 
65 // maximum pointers active at once
66 // for example in multitouch
67 #define VTKI_MAX_POINTERS 5
68 
69 class vtkAbstractPicker;
71 class vtkAssemblyPath;
73 class vtkRenderWindow;
74 class vtkRenderer;
77 class vtkPickingManager;
78 
80 {
81 //BTX
83 //ETX
84 public:
87  void PrintSelf(ostream& os, vtkIndent indent);
88 
90 
94  virtual void Initialize();
95  void ReInitialize() { this->Initialized = 0; this->Enabled = 0;
96  this->Initialize(); }
98 
101  virtual void UnRegister(vtkObjectBase *o);
102 
106  virtual void Start();
107 
109 
116  virtual void Enable() { this->Enabled = 1; this->Modified();}
117  virtual void Disable() { this->Enabled = 0; this->Modified();}
118  vtkGetMacro(Enabled, int);
120 
122 
124  vtkBooleanMacro(EnableRender, bool);
125  vtkSetMacro(EnableRender, bool);
126  vtkGetMacro(EnableRender, bool);
128 
130 
131  void SetRenderWindow(vtkRenderWindow *aren);
132  vtkGetObjectMacro(RenderWindow,vtkRenderWindow);
134 
137  virtual void UpdateSize(int x,int y);
138 
140 
155  virtual int CreateTimer(int timerType); //first group, for backward compatibility
156  virtual int DestroyTimer(); //first group, for backward compatibility
158 
161  int CreateRepeatingTimer(unsigned long duration);
162 
165  int CreateOneShotTimer(unsigned long duration);
166 
169  int IsOneShotTimer(int timerId);
170 
172  unsigned long GetTimerDuration(int timerId);
173 
175  int ResetTimer(int timerId);
176 
179  int DestroyTimer(int timerId);
180 
182  virtual int GetVTKTimerId(int platformTimerId);
183 
184  //BTX
185  // Moved into the public section of the class so that classless timer procs
186  // can access these enum members without being "friends"...
187  enum {OneShotTimer=1,RepeatingTimer};
188  //ETX
189 
191 
198  vtkSetClampMacro(TimerDuration,unsigned long,1,100000);
199  vtkGetMacro(TimerDuration,unsigned long);
201 
203 
213  vtkSetMacro(TimerEventId, int);
214  vtkGetMacro(TimerEventId, int);
215  vtkSetMacro(TimerEventType, int);
216  vtkGetMacro(TimerEventType, int);
217  vtkSetMacro(TimerEventDuration, int);
218  vtkGetMacro(TimerEventDuration, int);
219  vtkSetMacro(TimerEventPlatformId, int);
220  vtkGetMacro(TimerEventPlatformId, int);
222 
226  virtual void TerminateApp(void) {}
227 
229 
231  virtual void SetInteractorStyle(vtkInteractorObserver *);
232  vtkGetObjectMacro(InteractorStyle,vtkInteractorObserver);
234 
236 
238  vtkSetMacro(LightFollowCamera,int);
239  vtkGetMacro(LightFollowCamera,int);
240  vtkBooleanMacro(LightFollowCamera,int);
242 
244 
249  vtkSetClampMacro(DesiredUpdateRate,double,0.0001,VTK_FLOAT_MAX);
250  vtkGetMacro(DesiredUpdateRate,double);
252 
254 
257  vtkSetClampMacro(StillUpdateRate,double,0.0001,VTK_FLOAT_MAX);
258  vtkGetMacro(StillUpdateRate,double);
260 
262 
263  vtkGetMacro(Initialized,int);
265 
267 
271  virtual void SetPicker(vtkAbstractPicker*);
272  vtkGetObjectMacro(Picker,vtkAbstractPicker);
274 
277  virtual vtkAbstractPropPicker *CreateDefaultPicker();
278 
280 
283  virtual void SetPickingManager(vtkPickingManager*);
284  vtkGetObjectMacro(PickingManager,vtkPickingManager);
286 
288 
290  virtual void ExitCallback();
291  virtual void UserCallback();
292  virtual void StartPickCallback();
293  virtual void EndPickCallback();
295 
297  virtual void GetMousePosition(int *x, int *y) { *x = 0 ; *y = 0; }
298 
300 
302  void HideCursor();
303  void ShowCursor();
305 
308  virtual void Render();
309 
311 
314  void FlyTo(vtkRenderer *ren, double x, double y, double z);
315  void FlyTo(vtkRenderer *ren, double *x)
316  {this->FlyTo(ren, x[0], x[1], x[2]);}
317  void FlyToImage(vtkRenderer *ren, double x, double y);
318  void FlyToImage(vtkRenderer *ren, double *x)
319  {this->FlyToImage(ren, x[0], x[1]);}
321 
323 
324  vtkSetClampMacro(NumberOfFlyFrames,int,1,VTK_INT_MAX);
325  vtkGetMacro(NumberOfFlyFrames,int);
327 
329 
331  vtkSetMacro(Dolly,double);
332  vtkGetMacro(Dolly,double);
334 
336 
341  vtkGetVector2Macro(EventPosition,int);
342  vtkGetVector2Macro(LastEventPosition,int);
343  vtkSetVector2Macro(LastEventPosition,int);
344  virtual void SetEventPosition(int x, int y)
345  {
346  vtkDebugMacro(<< this->GetClassName() << " (" << this
347  << "): setting EventPosition to (" << x << "," << y << ")");
348  if (this->EventPosition[0] != x || this->EventPosition[1] != y ||
349  this->LastEventPosition[0] != x || this->LastEventPosition[1] != y)
350  {
351  this->LastEventPosition[0] = this->EventPosition[0];
352  this->LastEventPosition[1] = this->EventPosition[1];
353  this->EventPosition[0] = x;
354  this->EventPosition[1] = y;
355  this->Modified();
356  }
357  }
358  virtual void SetEventPosition(int pos[2])
359  {
360  this->SetEventPosition(pos[0], pos[1]);
361  }
362  virtual void SetEventPositionFlipY(int x, int y)
363  {
364  this->SetEventPosition(x, this->Size[1] - y - 1);
365  }
366  virtual void SetEventPositionFlipY(int pos[2])
367  {
368  this->SetEventPositionFlipY(pos[0], pos[1]);
369  }
371 
372  virtual int *GetEventPositions(int pointerIndex)
373  {
374  if (pointerIndex >= VTKI_MAX_POINTERS)
375  {
376  return NULL;
377  }
378  return this->EventPositions[pointerIndex];
379  }
380  virtual int *GetLastEventPositions(int pointerIndex)
381  {
382  if (pointerIndex >= VTKI_MAX_POINTERS)
383  {
384  return NULL;
385  }
386  return this->LastEventPositions[pointerIndex];
387  }
388  virtual void SetEventPosition(int x, int y, int pointerIndex)
389  {
390  if (pointerIndex < 0 || pointerIndex >= VTKI_MAX_POINTERS)
391  {
392  return;
393  }
394  if (pointerIndex == 0)
395  {
396  this->LastEventPosition[0] = this->EventPosition[0];
397  this->LastEventPosition[1] = this->EventPosition[1];
398  this->EventPosition[0] = x;
399  this->EventPosition[1] = y;
400  }
401  vtkDebugMacro(<< this->GetClassName() << " (" << this
402  << "): setting EventPosition to (" << x << "," << y << ") for pointerIndex number " << pointerIndex);
403  if (this->EventPositions[pointerIndex][0] != x || this->EventPositions[pointerIndex][1] != y ||
404  this->LastEventPositions[pointerIndex][0] != x || this->LastEventPositions[pointerIndex][1] != y)
405  {
406  this->LastEventPositions[pointerIndex][0] = this->EventPositions[pointerIndex][0];
407  this->LastEventPositions[pointerIndex][1] = this->EventPositions[pointerIndex][1];
408  this->EventPositions[pointerIndex][0] = x;
409  this->EventPositions[pointerIndex][1] = y;
410  this->Modified();
411  }
412  }
413  virtual void SetEventPosition(int pos[2], int pointerIndex)
414  {
415  this->SetEventPosition(pos[0], pos[1], pointerIndex);
416  }
417  virtual void SetEventPositionFlipY(int x, int y, int pointerIndex)
418  {
419  this->SetEventPosition(x, this->Size[1] - y - 1, pointerIndex);
420  }
421  virtual void SetEventPositionFlipY(int pos[2], int pointerIndex)
422  {
423  this->SetEventPositionFlipY(pos[0], pos[1], pointerIndex);
424  }
425 
427 
428  vtkSetMacro(AltKey, int);
429  vtkGetMacro(AltKey, int);
431 
433 
434  vtkSetMacro(ControlKey, int);
435  vtkGetMacro(ControlKey, int);
437 
439 
440  vtkSetMacro(ShiftKey, int);
441  vtkGetMacro(ShiftKey, int);
443 
445 
446  vtkSetMacro(KeyCode, char);
447  vtkGetMacro(KeyCode, char);
449 
451 
453  vtkSetMacro(RepeatCount, int);
454  vtkGetMacro(RepeatCount, int);
456 
458 
463  vtkSetStringMacro(KeySym);
464  vtkGetStringMacro(KeySym);
466 
468 
469  vtkSetMacro(PointerIndex, int);
470  vtkGetMacro(PointerIndex, int);
472 
474 
476  int y,
477  int ctrl,
478  int shift,
479  char keycode,
480  int repeatcount,
481  const char* keysym,
482  int pointerIndex)
483  {
484  this->SetEventPosition(x,y,pointerIndex);
485  this->ControlKey = ctrl;
486  this->ShiftKey = shift;
487  this->KeyCode = keycode;
488  this->RepeatCount = repeatcount;
489  this->PointerIndex = pointerIndex;
490  if(keysym)
491  {
492  this->SetKeySym(keysym);
493  }
494  this->Modified();
495  }
496  void SetEventInformation(int x, int y,
497  int ctrl=0, int shift=0,
498  char keycode=0,
499  int repeatcount=0,
500  const char* keysym=0)
501  {
502  this->SetEventInformation(x,y,ctrl,shift,keycode,repeatcount,keysym,0);
503  }
505 
507 
509  void SetEventInformationFlipY(int x, int y,
510  int ctrl, int shift,
511  char keycode,
512  int repeatcount,
513  const char* keysym,
514  int pointerIndex)
515  {
516  this->SetEventInformation(x,
517  this->Size[1] - y - 1,
518  ctrl,
519  shift,
520  keycode,
521  repeatcount,
522  keysym,
523  pointerIndex);
524  }
525  void SetEventInformationFlipY(int x, int y,
526  int ctrl=0, int shift=0,
527  char keycode=0,
528  int repeatcount=0,
529  const char* keysym=0)
530  {
531  this->SetEventInformationFlipY(x,y,ctrl,shift,keycode,repeatcount,keysym,0);
532  }
534 
536 
537  void SetKeyEventInformation(int ctrl=0,
538  int shift=0,
539  char keycode=0,
540  int repeatcount=0,
541  const char* keysym=0)
542  {
543  this->ControlKey = ctrl;
544  this->ShiftKey = shift;
545  this->KeyCode = keycode;
546  this->RepeatCount = repeatcount;
547  if(keysym)
548  {
549  this->SetKeySym(keysym);
550  }
551  this->Modified();
552  }
554 
556 
563  vtkSetVector2Macro(Size,int);
564  vtkGetVector2Macro(Size,int);
565  vtkSetVector2Macro(EventSize,int);
566  vtkGetVector2Macro(EventSize,int);
568 
572  virtual vtkRenderer *FindPokedRenderer(int,int);
573 
580  vtkObserverMediator *GetObserverMediator();
581 
583 
588  vtkSetMacro(UseTDx,bool);
589  vtkGetMacro(UseTDx,bool);
591 
593 
596  virtual void MouseMoveEvent();
597  virtual void RightButtonPressEvent();
598  virtual void RightButtonReleaseEvent();
599  virtual void LeftButtonPressEvent();
600  virtual void LeftButtonReleaseEvent();
601  virtual void MiddleButtonPressEvent();
602  virtual void MiddleButtonReleaseEvent();
603  virtual void MouseWheelForwardEvent();
604  virtual void MouseWheelBackwardEvent();
605  virtual void ExposeEvent();
606  virtual void ConfigureEvent();
607  virtual void EnterEvent();
608  virtual void LeaveEvent();
609  virtual void KeyPressEvent();
610  virtual void KeyReleaseEvent();
611  virtual void CharEvent();
612  virtual void ExitEvent();
614 
615 protected:
618 
621 
622  // Used as a helper object to pick instances of vtkProp
625 
628  virtual vtkPickingManager *CreateDefaultPickingManager();
629 
631  int Enabled;
633  int Style;
638 
639  // Event information
640  int AltKey;
642  int ShiftKey;
643  char KeyCode;
645  char* KeySym;
646  int EventPosition[2];
647  int LastEventPosition[2];
648  int EventSize[2];
649  int Size[2];
654 
655  int EventPositions[VTKI_MAX_POINTERS][2];
656  int LastEventPositions[VTKI_MAX_POINTERS][2];
658 
659  // control the fly to
661  double Dolly;
662 
663 //BTX
665 
672  friend class vtkInteractorObserver;
673  void GrabFocus(vtkCommand *mouseEvents, vtkCommand *keypressEvents=NULL)
674  {this->Superclass::InternalGrabFocus(mouseEvents,keypressEvents);}
677 //ETX
679 
683 
684 //BTX
685  // Timer related members
686  friend struct vtkTimerStruct;
687  vtkTimerIdMap *TimerMap; // An internal, PIMPLd map of timers and associated attributes
688  unsigned long TimerDuration; //in milliseconds
690 
694  virtual int InternalCreateTimer(int timerId, int timerType, unsigned long duration);
695  virtual int InternalDestroyTimer(int platformTimerId);
696  int GetCurrentTimerId();
697 //ETX
699 
700  // Force the interactor to handle the Start() event loop, ignoring any
701  // overrides. (Overrides are registered by observing StartEvent on the
702  // interactor.)
704 
706  virtual void StartEventLoop() {}
707 
708  bool UseTDx; // 3DConnexion device.
709 
710 private:
711  vtkRenderWindowInteractor(const vtkRenderWindowInteractor&); // Not implemented.
712  void operator=(const vtkRenderWindowInteractor&); // Not implemented.
713 };
714 
715 #endif
virtual void SetEventPositionFlipY(int pos[2])
virtual void GetMousePosition(int *x, int *y)
abstract base class for most VTK objects
Definition: vtkObject.h:61
void SetEventInformation(int x, int y, int ctrl=0, int shift=0, char keycode=0, int repeatcount=0, const char *keysym=0)
void SetEventInformationFlipY(int x, int y, int ctrl=0, int shift=0, char keycode=0, int repeatcount=0, const char *keysym=0)
void SetEventInformation(int x, int y, int ctrl, int shift, char keycode, int repeatcount, const char *keysym, int pointerIndex)
virtual void SetEventPosition(int pos[2], int pointerIndex)
#define VTK_INT_MAX
Definition: vtkType.h:132
virtual void SetRenderWindow(vtkRenderWindow *renwin)
vtkInteractorObserver * InteractorStyle
virtual void SetEventPositionFlipY(int pos[2], int pointerIndex)
abstract specification for renderers
Definition: vtkRenderer.h:63
void SetKeyEventInformation(int ctrl=0, int shift=0, char keycode=0, int repeatcount=0, const char *keysym=0)
virtual int * GetLastEventPositions(int pointerIndex)
virtual void SetEventPosition(int pos[2])
void GrabFocus(vtkCommand *mouseEvents, vtkCommand *keypressEvents=NULL)
virtual int * GetEventPositions(int pointerIndex)
an abstract superclass for classes observing events invoked by vtkRenderWindowInteractor ...
void FlyTo(vtkRenderer *ren, double *x)
platform-independent render window interaction including picking and frame rate control.
void InternalReleaseFocus()
void InternalGrabFocus(vtkCommand *mouseEvents, vtkCommand *keypressEvents=NULL)
superclass for callback/observer methods
Definition: vtkCommand.h:325
#define VTK_FLOAT_MAX
Definition: vtkType.h:140
virtual void PrintSelf(ostream &os, vtkIndent indent)
virtual void UnRegister(vtkObjectBase *o)
a list of nodes that form an assembly path
vtkObserverMediator * ObserverMediator
a simple class to control print indentation
Definition: vtkIndent.h:38
const char * GetClassName() const
void SetEventInformationFlipY(int x, int y, int ctrl, int shift, char keycode, int repeatcount, const char *keysym, int pointerIndex)
virtual void Modified()
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:59
virtual void SetEventPosition(int x, int y)
vtkWeakPointer< vtkRenderWindow > RenderWindow
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 VTKRENDERINGCORE_EXPORT
#define VTKI_MAX_POINTERS
define API for picking subclasses
static vtkObject * New()
void FlyToImage(vtkRenderer *ren, double *x)
manage contention for cursors and other resources
virtual void SetEventPositionFlipY(int x, int y)