#include #include #include #include #include #include // ------------------------------------------------------------------------- const long cpExtensions::Visualization::BaseInteractorStyle::MouseButtonEvent:: MAX_DOUBLE_CLICK = 200; // ms // ------------------------------------------------------------------------- cpExtensions::Visualization::BaseInteractorStyle:: Self* cpExtensions::Visualization::BaseInteractorStyle:: New( ) { return( new Self ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::BaseInteractorStyle:: DelegateTDxEvent( unsigned long event, void* calldata ) { // TODO std::cerr << "No TDx support at this time!" << std::endl; std::exit( 1 ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::BaseInteractorStyle:: OnMouseMove( ) { // Get current position on the associated actors vtkRenderWindowInteractor* rwi = this->GetInteractor( ); if( rwi == NULL ) return; // Get modifiers bool alt = ( rwi->GetAltKey( ) == 1 ); bool ctr = ( rwi->GetControlKey( ) == 1 ); bool sft = ( rwi->GetShiftKey( ) == 1 ); ButtonID button = this->GetButtonID( ); // Invoke possible generic events if( button == Self::ButtonID_Right ) { if( !alt && !ctr && !sft ) { this->FindPokedRenderer( rwi->GetEventPosition( )[ 0 ], rwi->GetEventPosition( )[ 1 ] ); this->Dolly( ); } // fi } else if( button == Self::ButtonID_Middle ) { if( !alt && !ctr && !sft ) { this->FindPokedRenderer( rwi->GetEventPosition( )[ 0 ], rwi->GetEventPosition( )[ 1 ] ); this->Pan( ); } // fi } // fi } // ------------------------------------------------------------------------- void cpExtensions::Visualization::BaseInteractorStyle:: OnLeftButtonDown( ) { this->ActiveButton = Self::ButtonID_Left; } // ------------------------------------------------------------------------- void cpExtensions::Visualization::BaseInteractorStyle:: OnLeftButtonUp( ) { this->ActiveButton = Self::ButtonID_None; } // ------------------------------------------------------------------------- void cpExtensions::Visualization::BaseInteractorStyle:: OnMiddleButtonDown( ) { this->ActiveButton = Self::ButtonID_Middle; // Get current position on the associated actors vtkRenderWindowInteractor* rwi = this->GetInteractor( ); if( rwi == NULL ) return; // Get modifiers bool alt = ( rwi->GetAltKey( ) == 1 ); bool ctr = ( rwi->GetControlKey( ) == 1 ); bool sft = ( rwi->GetShiftKey( ) == 1 ); if( !alt && !ctr && !sft ) this->StartPan( ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::BaseInteractorStyle:: OnMiddleButtonUp( ) { this->ActiveButton = Self::ButtonID_None; // Get current position on the associated actors vtkRenderWindowInteractor* rwi = this->GetInteractor( ); if( rwi == NULL ) return; // Get modifiers bool alt = ( rwi->GetAltKey( ) == 1 ); bool ctr = ( rwi->GetControlKey( ) == 1 ); bool sft = ( rwi->GetShiftKey( ) == 1 ); switch( this->State ) { case VTKIS_PAN: this->EndPan( ); break; default: break; } // hctiws } // ------------------------------------------------------------------------- void cpExtensions::Visualization::BaseInteractorStyle:: OnRightButtonDown( ) { this->ActiveButton = Self::ButtonID_Right; // Get current position on the associated actors vtkRenderWindowInteractor* rwi = this->GetInteractor( ); if( rwi == NULL ) return; // Get modifiers bool alt = ( rwi->GetAltKey( ) == 1 ); bool ctr = ( rwi->GetControlKey( ) == 1 ); bool sft = ( rwi->GetShiftKey( ) == 1 ); if( !alt && !ctr && !sft ) this->StartDolly( ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::BaseInteractorStyle:: OnRightButtonUp( ) { this->ActiveButton = Self::ButtonID_None; // Get current position on the associated actors vtkRenderWindowInteractor* rwi = this->GetInteractor( ); if( rwi == NULL ) return; // Get modifiers bool alt = ( rwi->GetAltKey( ) == 1 ); bool ctr = ( rwi->GetControlKey( ) == 1 ); bool sft = ( rwi->GetShiftKey( ) == 1 ); switch( this->State ) { case VTKIS_DOLLY: this->EndDolly( ); break; default: break; } // hctiws } // ------------------------------------------------------------------------- void cpExtensions::Visualization::BaseInteractorStyle:: Dolly( ) { if( this->CurrentRenderer == NULL ) return; vtkRenderWindowInteractor* rwi = this->GetInteractor( ); double *center = this->CurrentRenderer->GetCenter( ); int dy = rwi->GetEventPosition( )[ 1 ] - rwi->GetLastEventPosition( )[ 1 ]; double dyf = this->MotionFactor * dy / center[ 1 ]; this->_Dolly( std::pow( 1.1, dyf ) ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::BaseInteractorStyle:: Pan( ) { if( this->CurrentRenderer == NULL ) return; vtkRenderWindowInteractor* rwi = this->Interactor; double viewFocus[ 4 ], focalDepth, viewPoint[ 3 ]; double newPickPoint[ 4 ], oldPickPoint[ 4 ], motionVector[ 3 ]; // Calculate the focal depth since we'll be using it a lot vtkCamera* camera = this->CurrentRenderer->GetActiveCamera( ); camera->GetFocalPoint( viewFocus ); this->ComputeWorldToDisplay( viewFocus[ 0 ], viewFocus[ 1 ], viewFocus[ 2 ], viewFocus ); focalDepth = viewFocus[ 2 ]; this->ComputeDisplayToWorld( rwi->GetEventPosition( )[ 0 ], rwi->GetEventPosition( )[ 1 ], focalDepth, newPickPoint ); // Has to recalc old mouse point since the viewport has moved, // so can't move it outside the loop this->ComputeDisplayToWorld( rwi->GetLastEventPosition( )[ 0 ], rwi->GetLastEventPosition( )[ 1 ], focalDepth, oldPickPoint ); // Camera motion is reversed motionVector[ 0 ] = oldPickPoint[ 0 ] - newPickPoint[ 0 ]; motionVector[ 1 ] = oldPickPoint[ 1 ] - newPickPoint[ 1 ]; motionVector[ 2 ] = oldPickPoint[ 2 ] - newPickPoint[ 2 ]; camera->GetFocalPoint( viewFocus ); camera->GetPosition( viewPoint ); camera->SetFocalPoint( motionVector[ 0 ] + viewFocus[ 0 ], motionVector[ 1 ] + viewFocus[ 1 ], motionVector[ 2 ] + viewFocus[ 2 ] ); camera->SetPosition( motionVector[ 0 ] + viewPoint[ 0 ], motionVector[ 1 ] + viewPoint[ 1 ], motionVector[ 2 ] + viewPoint[ 2 ] ); if( rwi->GetLightFollowCamera( ) ) this->CurrentRenderer->UpdateLightsGeometryToFollowCamera( ); rwi->Render( ); } // ------------------------------------------------------------------------- cpExtensions::Visualization::BaseInteractorStyle:: BaseInteractorStyle( ) : Superclass( ), MotionFactor( double( 10 ) ) { this->LeftButtonEvent.Reset( ); this->MiddleButtonEvent.Reset( ); this->RightButtonEvent.Reset( ); this->ActiveButton = Self::ButtonID_None; this->EventCallbackCommand->SetCallback( Self::_ProcessEvents ); } // ------------------------------------------------------------------------- cpExtensions::Visualization::BaseInteractorStyle:: ~BaseInteractorStyle( ) { } // ------------------------------------------------------------------------- void cpExtensions::Visualization::BaseInteractorStyle:: _Dolly( double factor ) { if( this->CurrentRenderer == NULL ) return; vtkCamera* camera = this->CurrentRenderer->GetActiveCamera( ); if( camera->GetParallelProjection( ) == 0 ) { camera->Dolly( factor ); if( this->AutoAdjustCameraClippingRange ) this->CurrentRenderer->ResetCameraClippingRange( ); } else camera->SetParallelScale( camera->GetParallelScale( ) / factor ); if( this->Interactor->GetLightFollowCamera( ) ) this->CurrentRenderer->UpdateLightsGeometryToFollowCamera( ); this->Interactor->Render( ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::BaseInteractorStyle:: _ProcessEvents( vtkObject* object, unsigned long event, void* clientdata, void* calldata ) { // Get active style and interactor Self* s = reinterpret_cast< Self* >( clientdata ); if( s == NULL ) return; // Process events switch( event ) { case vtkCommand::MouseMoveEvent: { s->OnMouseMove( ); } break; case vtkCommand::LeftButtonPressEvent: { unsigned char nc = s->LeftButtonEvent.Clicks( ); if( nc == 2 ) s->OnLeftDoubleClick( ); else if( nc == 1 ) s->OnLeftClick( ); s->OnLeftButtonDown( ); } break; case vtkCommand::LeftButtonReleaseEvent: { s->LeftButtonEvent.Release( ); s->OnLeftButtonUp( ); } break; case vtkCommand::MiddleButtonPressEvent: { unsigned char nc = s->MiddleButtonEvent.Clicks( ); if( nc == 2 ) s->OnMiddleDoubleClick( ); else if( nc == 1 ) s->OnMiddleClick( ); s->OnMiddleButtonDown( ); } break; case vtkCommand::MiddleButtonReleaseEvent: { s->MiddleButtonEvent.Release( ); s->OnMiddleButtonUp( ); } break; case vtkCommand::RightButtonPressEvent: { unsigned char nc = s->RightButtonEvent.Clicks( ); if( nc == 2 ) s->OnRightDoubleClick( ); else if( nc == 1 ) s->OnRightClick( ); s->OnRightButtonDown( ); } break; case vtkCommand::RightButtonReleaseEvent: { s->RightButtonEvent.Release( ); s->OnRightButtonUp( ); } break; case vtkCommand::MouseWheelForwardEvent: { s->OnMouseWheelForward( ); } break; case vtkCommand::MouseWheelBackwardEvent: { s->OnMouseWheelBackward( ); } break; case vtkCommand::KeyPressEvent: { s->OnKeyDown( ); s->OnKeyPress( ); } break; case vtkCommand::KeyReleaseEvent: { s->OnKeyUp( ); s->OnKeyRelease( ); } break; case vtkCommand::CharEvent: { s->OnChar( ); } break; case vtkCommand::ExposeEvent: { s->OnExpose( ); } break; case vtkCommand::ConfigureEvent: { s->OnConfigure( ); } break; case vtkCommand::EnterEvent: { s->OnEnter( ); } break; case vtkCommand::LeaveEvent: { s->OnLeave( ); } break; case vtkCommand::TimerEvent: { // Do nothing } break; case vtkCommand::DeleteEvent: { s->SetInteractor( 0 ); } break; case vtkCommand::TDxMotionEvent: case vtkCommand::TDxButtonPressEvent: case vtkCommand::TDxButtonReleaseEvent: { s->DelegateTDxEvent( event, calldata ); } break; default: break; } // hctiws } // eof - $RCSfile$