VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkRenderWindowInteractor.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00053 #ifndef vtkRenderWindowInteractor_h 00054 #define vtkRenderWindowInteractor_h 00055 00056 #include "vtkRenderingCoreModule.h" // For export macro 00057 #include "vtkObject.h" 00058 00059 class vtkTimerIdMap; 00060 00061 // Timer flags for win32/X compatibility 00062 #define VTKI_TIMER_FIRST 0 00063 #define VTKI_TIMER_UPDATE 1 00064 00065 // maximum pointers active at once 00066 // for example in multitouch 00067 #define VTKI_MAX_POINTERS 5 00068 00069 class vtkAbstractPicker; 00070 class vtkAbstractPropPicker; 00071 class vtkAssemblyPath; 00072 class vtkInteractorObserver; 00073 class vtkRenderWindow; 00074 class vtkRenderer; 00075 class vtkObserverMediator; 00076 class vtkInteractorEventRecorder; 00077 class vtkPickingManager; 00078 00079 class VTKRENDERINGCORE_EXPORT vtkRenderWindowInteractor : public vtkObject 00080 { 00081 //BTX 00082 friend class vtkInteractorEventRecorder; 00083 //ETX 00084 public: 00085 static vtkRenderWindowInteractor *New(); 00086 vtkTypeMacro(vtkRenderWindowInteractor,vtkObject); 00087 void PrintSelf(ostream& os, vtkIndent indent); 00088 00090 00094 virtual void Initialize(); 00095 void ReInitialize() { this->Initialized = 0; this->Enabled = 0; 00096 this->Initialize(); } 00098 00101 virtual void UnRegister(vtkObjectBase *o); 00102 00106 virtual void Start(); 00107 00109 00116 virtual void Enable() { this->Enabled = 1; this->Modified();} 00117 virtual void Disable() { this->Enabled = 0; this->Modified();} 00118 vtkGetMacro(Enabled, int); 00120 00122 00124 vtkBooleanMacro(EnableRender, bool); 00125 vtkSetMacro(EnableRender, bool); 00126 vtkGetMacro(EnableRender, bool); 00128 00130 00131 void SetRenderWindow(vtkRenderWindow *aren); 00132 vtkGetObjectMacro(RenderWindow,vtkRenderWindow); 00134 00137 virtual void UpdateSize(int x,int y); 00138 00140 00155 virtual int CreateTimer(int timerType); //first group, for backward compatibility 00156 virtual int DestroyTimer(); //first group, for backward compatibility 00158 00161 int CreateRepeatingTimer(unsigned long duration); 00162 00165 int CreateOneShotTimer(unsigned long duration); 00166 00169 int IsOneShotTimer(int timerId); 00170 00172 unsigned long GetTimerDuration(int timerId); 00173 00175 int ResetTimer(int timerId); 00176 00179 int DestroyTimer(int timerId); 00180 00182 virtual int GetVTKTimerId(int platformTimerId); 00183 00184 //BTX 00185 // Moved into the public section of the class so that classless timer procs 00186 // can access these enum members without being "friends"... 00187 enum {OneShotTimer=1,RepeatingTimer}; 00188 //ETX 00189 00191 00198 vtkSetClampMacro(TimerDuration,unsigned long,1,100000); 00199 vtkGetMacro(TimerDuration,unsigned long); 00201 00203 00213 vtkSetMacro(TimerEventId, int); 00214 vtkGetMacro(TimerEventId, int); 00215 vtkSetMacro(TimerEventType, int); 00216 vtkGetMacro(TimerEventType, int); 00217 vtkSetMacro(TimerEventDuration, int); 00218 vtkGetMacro(TimerEventDuration, int); 00219 vtkSetMacro(TimerEventPlatformId, int); 00220 vtkGetMacro(TimerEventPlatformId, int); 00222 00226 virtual void TerminateApp(void) {} 00227 00229 00231 virtual void SetInteractorStyle(vtkInteractorObserver *); 00232 vtkGetObjectMacro(InteractorStyle,vtkInteractorObserver); 00234 00236 00238 vtkSetMacro(LightFollowCamera,int); 00239 vtkGetMacro(LightFollowCamera,int); 00240 vtkBooleanMacro(LightFollowCamera,int); 00242 00244 00249 vtkSetClampMacro(DesiredUpdateRate,double,0.0001,VTK_FLOAT_MAX); 00250 vtkGetMacro(DesiredUpdateRate,double); 00252 00254 00257 vtkSetClampMacro(StillUpdateRate,double,0.0001,VTK_FLOAT_MAX); 00258 vtkGetMacro(StillUpdateRate,double); 00260 00262 00263 vtkGetMacro(Initialized,int); 00265 00267 00271 virtual void SetPicker(vtkAbstractPicker*); 00272 vtkGetObjectMacro(Picker,vtkAbstractPicker); 00274 00277 virtual vtkAbstractPropPicker *CreateDefaultPicker(); 00278 00280 00283 virtual void SetPickingManager(vtkPickingManager*); 00284 vtkGetObjectMacro(PickingManager,vtkPickingManager); 00286 00288 00290 virtual void ExitCallback(); 00291 virtual void UserCallback(); 00292 virtual void StartPickCallback(); 00293 virtual void EndPickCallback(); 00295 00297 virtual void GetMousePosition(int *x, int *y) { *x = 0 ; *y = 0; } 00298 00300 00302 void HideCursor(); 00303 void ShowCursor(); 00305 00308 virtual void Render(); 00309 00311 00314 void FlyTo(vtkRenderer *ren, double x, double y, double z); 00315 void FlyTo(vtkRenderer *ren, double *x) 00316 {this->FlyTo(ren, x[0], x[1], x[2]);} 00317 void FlyToImage(vtkRenderer *ren, double x, double y); 00318 void FlyToImage(vtkRenderer *ren, double *x) 00319 {this->FlyToImage(ren, x[0], x[1]);} 00321 00323 00324 vtkSetClampMacro(NumberOfFlyFrames,int,1,VTK_INT_MAX); 00325 vtkGetMacro(NumberOfFlyFrames,int); 00327 00329 00331 vtkSetMacro(Dolly,double); 00332 vtkGetMacro(Dolly,double); 00334 00336 00341 vtkGetVector2Macro(EventPosition,int); 00342 vtkGetVector2Macro(LastEventPosition,int); 00343 vtkSetVector2Macro(LastEventPosition,int); 00344 virtual void SetEventPosition(int x, int y) 00345 { 00346 vtkDebugMacro(<< this->GetClassName() << " (" << this 00347 << "): setting EventPosition to (" << x << "," << y << ")"); 00348 if (this->EventPosition[0] != x || this->EventPosition[1] != y || 00349 this->LastEventPosition[0] != x || this->LastEventPosition[1] != y) 00350 { 00351 this->LastEventPosition[0] = this->EventPosition[0]; 00352 this->LastEventPosition[1] = this->EventPosition[1]; 00353 this->EventPosition[0] = x; 00354 this->EventPosition[1] = y; 00355 this->Modified(); 00356 } 00357 } 00358 virtual void SetEventPosition(int pos[2]) 00359 { 00360 this->SetEventPosition(pos[0], pos[1]); 00361 } 00362 virtual void SetEventPositionFlipY(int x, int y) 00363 { 00364 this->SetEventPosition(x, this->Size[1] - y - 1); 00365 } 00366 virtual void SetEventPositionFlipY(int pos[2]) 00367 { 00368 this->SetEventPositionFlipY(pos[0], pos[1]); 00369 } 00371 00372 virtual int *GetEventPositions(int pointerIndex) 00373 { 00374 if (pointerIndex >= VTKI_MAX_POINTERS) 00375 { 00376 return NULL; 00377 } 00378 return this->EventPositions[pointerIndex]; 00379 } 00380 virtual int *GetLastEventPositions(int pointerIndex) 00381 { 00382 if (pointerIndex >= VTKI_MAX_POINTERS) 00383 { 00384 return NULL; 00385 } 00386 return this->LastEventPositions[pointerIndex]; 00387 } 00388 virtual void SetEventPosition(int x, int y, int pointerIndex) 00389 { 00390 if (pointerIndex < 0 || pointerIndex >= VTKI_MAX_POINTERS) 00391 { 00392 return; 00393 } 00394 if (pointerIndex == 0) 00395 { 00396 this->LastEventPosition[0] = this->EventPosition[0]; 00397 this->LastEventPosition[1] = this->EventPosition[1]; 00398 this->EventPosition[0] = x; 00399 this->EventPosition[1] = y; 00400 } 00401 vtkDebugMacro(<< this->GetClassName() << " (" << this 00402 << "): setting EventPosition to (" << x << "," << y << ") for pointerIndex number " << pointerIndex); 00403 if (this->EventPositions[pointerIndex][0] != x || this->EventPositions[pointerIndex][1] != y || 00404 this->LastEventPositions[pointerIndex][0] != x || this->LastEventPositions[pointerIndex][1] != y) 00405 { 00406 this->LastEventPositions[pointerIndex][0] = this->EventPositions[pointerIndex][0]; 00407 this->LastEventPositions[pointerIndex][1] = this->EventPositions[pointerIndex][1]; 00408 this->EventPositions[pointerIndex][0] = x; 00409 this->EventPositions[pointerIndex][1] = y; 00410 this->Modified(); 00411 } 00412 } 00413 virtual void SetEventPosition(int pos[2], int pointerIndex) 00414 { 00415 this->SetEventPosition(pos[0], pos[1], pointerIndex); 00416 } 00417 virtual void SetEventPositionFlipY(int x, int y, int pointerIndex) 00418 { 00419 this->SetEventPosition(x, this->Size[1] - y - 1, pointerIndex); 00420 } 00421 virtual void SetEventPositionFlipY(int pos[2], int pointerIndex) 00422 { 00423 this->SetEventPositionFlipY(pos[0], pos[1], pointerIndex); 00424 } 00425 00427 00428 vtkSetMacro(AltKey, int); 00429 vtkGetMacro(AltKey, int); 00431 00433 00434 vtkSetMacro(ControlKey, int); 00435 vtkGetMacro(ControlKey, int); 00437 00439 00440 vtkSetMacro(ShiftKey, int); 00441 vtkGetMacro(ShiftKey, int); 00443 00445 00446 vtkSetMacro(KeyCode, char); 00447 vtkGetMacro(KeyCode, char); 00449 00451 00453 vtkSetMacro(RepeatCount, int); 00454 vtkGetMacro(RepeatCount, int); 00456 00458 00463 vtkSetStringMacro(KeySym); 00464 vtkGetStringMacro(KeySym); 00466 00468 00469 vtkSetMacro(PointerIndex, int); 00470 vtkGetMacro(PointerIndex, int); 00472 00474 00475 void SetEventInformation(int x, 00476 int y, 00477 int ctrl, 00478 int shift, 00479 char keycode, 00480 int repeatcount, 00481 const char* keysym, 00482 int pointerIndex) 00483 { 00484 this->SetEventPosition(x,y,pointerIndex); 00485 this->ControlKey = ctrl; 00486 this->ShiftKey = shift; 00487 this->KeyCode = keycode; 00488 this->RepeatCount = repeatcount; 00489 this->PointerIndex = pointerIndex; 00490 if(keysym) 00491 { 00492 this->SetKeySym(keysym); 00493 } 00494 this->Modified(); 00495 } 00496 void SetEventInformation(int x, int y, 00497 int ctrl=0, int shift=0, 00498 char keycode=0, 00499 int repeatcount=0, 00500 const char* keysym=0) 00501 { 00502 this->SetEventInformation(x,y,ctrl,shift,keycode,repeatcount,keysym,0); 00503 } 00505 00507 00509 void SetEventInformationFlipY(int x, int y, 00510 int ctrl, int shift, 00511 char keycode, 00512 int repeatcount, 00513 const char* keysym, 00514 int pointerIndex) 00515 { 00516 this->SetEventInformation(x, 00517 this->Size[1] - y - 1, 00518 ctrl, 00519 shift, 00520 keycode, 00521 repeatcount, 00522 keysym, 00523 pointerIndex); 00524 } 00525 void SetEventInformationFlipY(int x, int y, 00526 int ctrl=0, int shift=0, 00527 char keycode=0, 00528 int repeatcount=0, 00529 const char* keysym=0) 00530 { 00531 this->SetEventInformationFlipY(x,y,ctrl,shift,keycode,repeatcount,keysym,0); 00532 } 00534 00536 00537 void SetKeyEventInformation(int ctrl=0, 00538 int shift=0, 00539 char keycode=0, 00540 int repeatcount=0, 00541 const char* keysym=0) 00542 { 00543 this->ControlKey = ctrl; 00544 this->ShiftKey = shift; 00545 this->KeyCode = keycode; 00546 this->RepeatCount = repeatcount; 00547 if(keysym) 00548 { 00549 this->SetKeySym(keysym); 00550 } 00551 this->Modified(); 00552 } 00554 00556 00563 vtkSetVector2Macro(Size,int); 00564 vtkGetVector2Macro(Size,int); 00565 vtkSetVector2Macro(EventSize,int); 00566 vtkGetVector2Macro(EventSize,int); 00568 00572 virtual vtkRenderer *FindPokedRenderer(int,int); 00573 00580 vtkObserverMediator *GetObserverMediator(); 00581 00583 00588 vtkSetMacro(UseTDx,bool); 00589 vtkGetMacro(UseTDx,bool); 00591 00593 00596 virtual void MouseMoveEvent(); 00597 virtual void RightButtonPressEvent(); 00598 virtual void RightButtonReleaseEvent(); 00599 virtual void LeftButtonPressEvent(); 00600 virtual void LeftButtonReleaseEvent(); 00601 virtual void MiddleButtonPressEvent(); 00602 virtual void MiddleButtonReleaseEvent(); 00603 virtual void MouseWheelForwardEvent(); 00604 virtual void MouseWheelBackwardEvent(); 00605 virtual void ExposeEvent(); 00606 virtual void ConfigureEvent(); 00607 virtual void EnterEvent(); 00608 virtual void LeaveEvent(); 00609 virtual void KeyPressEvent(); 00610 virtual void KeyReleaseEvent(); 00611 virtual void CharEvent(); 00612 virtual void ExitEvent(); 00614 00615 protected: 00616 vtkRenderWindowInteractor(); 00617 ~vtkRenderWindowInteractor(); 00618 00619 vtkRenderWindow *RenderWindow; 00620 vtkInteractorObserver *InteractorStyle; 00621 00622 // Used as a helper object to pick instances of vtkProp 00623 vtkAbstractPicker *Picker; 00624 vtkPickingManager *PickingManager; 00625 00628 virtual vtkPickingManager *CreateDefaultPickingManager(); 00629 00630 int Initialized; 00631 int Enabled; 00632 bool EnableRender; 00633 int Style; 00634 int LightFollowCamera; 00635 int ActorMode; 00636 double DesiredUpdateRate; 00637 double StillUpdateRate; 00638 00639 // Event information 00640 int AltKey; 00641 int ControlKey; 00642 int ShiftKey; 00643 char KeyCode; 00644 int RepeatCount; 00645 char* KeySym; 00646 int EventPosition[2]; 00647 int LastEventPosition[2]; 00648 int EventSize[2]; 00649 int Size[2]; 00650 int TimerEventId; 00651 int TimerEventType; 00652 int TimerEventDuration; 00653 int TimerEventPlatformId; 00654 00655 int EventPositions[VTKI_MAX_POINTERS][2]; 00656 int LastEventPositions[VTKI_MAX_POINTERS][2]; 00657 int PointerIndex; 00658 00659 // control the fly to 00660 int NumberOfFlyFrames; 00661 double Dolly; 00662 00663 //BTX 00665 00672 friend class vtkInteractorObserver; 00673 void GrabFocus(vtkCommand *mouseEvents, vtkCommand *keypressEvents=NULL) 00674 {this->Superclass::InternalGrabFocus(mouseEvents,keypressEvents);} 00675 void ReleaseFocus() 00676 {this->Superclass::InternalReleaseFocus();} 00677 //ETX 00679 00682 vtkObserverMediator *ObserverMediator; 00683 00684 //BTX 00685 // Timer related members 00686 friend struct vtkTimerStruct; 00687 vtkTimerIdMap *TimerMap; // An internal, PIMPLd map of timers and associated attributes 00688 unsigned long TimerDuration; //in milliseconds 00690 00694 virtual int InternalCreateTimer(int timerId, int timerType, unsigned long duration); 00695 virtual int InternalDestroyTimer(int platformTimerId); 00696 int GetCurrentTimerId(); 00697 //ETX 00699 00700 // Force the interactor to handle the Start() event loop, ignoring any 00701 // overrides. (Overrides are registered by observing StartEvent on the 00702 // interactor.) 00703 int HandleEventLoop; 00704 00706 virtual void StartEventLoop() {} 00707 00708 bool UseTDx; // 3DConnexion device. 00709 00710 private: 00711 vtkRenderWindowInteractor(const vtkRenderWindowInteractor&); // Not implemented. 00712 void operator=(const vtkRenderWindowInteractor&); // Not implemented. 00713 }; 00714 00715 #endif