#include #include #include #include #include #include #include #include #include #include #include #include #include // ------------------------------------------------------------------------- const int cpPlugins::Extensions::Visualization:: ImageInteractorStyle::SliceEvent = vtkCommand::UserEvent + 1; // ------------------------------------------------------------------------- cpPlugins::Extensions::Visualization::ImageInteractorStyle:: Self* cpPlugins::Extensions::Visualization::ImageInteractorStyle:: New( ) { return( new Self( ) ); } // ------------------------------------------------------------------------- void cpPlugins::Extensions::Visualization::ImageInteractorStyle:: Configure( ImageSliceActors* slice_actors, MPRActors* mpr_actors ) { this->m_SliceActors = slice_actors; this->m_MPRActors = mpr_actors; this->SetModeToNavigation( ); this->PropPicker->AddPickList( slice_actors->GetImageActor( ) ); this->Modified( ); } // ------------------------------------------------------------------------- void cpPlugins::Extensions::Visualization::ImageInteractorStyle:: AssociateInteractor( vtkRenderWindowInteractor* interactor ) { if( interactor != NULL ) { this->AssociatedInteractors.push_back( interactor ); this->Modified( ); } // fi } // ------------------------------------------------------------------------- void cpPlugins::Extensions::Visualization::ImageInteractorStyle:: SetModeToNavigation( ) { this->Mode = Self::NavigationMode; } // ------------------------------------------------------------------------- void cpPlugins::Extensions::Visualization::ImageInteractorStyle:: SetModeToDeformation( ) { this->Mode = Self::DeformationMode; } // ------------------------------------------------------------------------- void cpPlugins::Extensions::Visualization::ImageInteractorStyle:: SetInteractor( vtkRenderWindowInteractor* interactor, const int& axis ) { this->Superclass::SetInteractor( interactor ); this->OrientationWidget->SetInteractor( interactor ); interactor->SetInteractorStyle( this ); if( interactor == NULL ) return; // TODO: interactor->SetPicker( this->PropPicker ); // Get camera, avoiding segfaults vtkRenderer* ren = interactor->GetRenderWindow( )->GetRenderers( )->GetFirstRenderer( ); if( ren == NULL ) return; vtkCamera* cam = ren->GetActiveCamera( ); if( cam == NULL ) return; // Parallel projections are better when displaying 2D images cam->ParallelProjectionOn( ); cam->SetFocalPoint( double( 0 ), double( 0 ), double( 0 ) ); if( axis == 0 ) { cam->SetPosition( double( 1 ), double( 0 ), double( 0 ) ); cam->SetViewUp ( double( 0 ), double( 1 ), double( 0 ) ); } else if( axis == 1 ) { cam->SetPosition( double( 0 ), double( 1 ), double( 0 ) ); cam->SetViewUp ( double( 0 ), double( 0 ), double( -1 ) ); } else // if( axis == 2 ) { cam->SetPosition( double( 0 ), double( 0 ), double( 1 ) ); cam->SetViewUp ( double( 0 ), double( 1 ), double( 0 ) ); } // fi ren->ResetCamera( ); // Enable 2D orientation widget this->OrientationWidget->SetEnabled( 1 ); this->OrientationWidget->InteractiveOff( ); } // ------------------------------------------------------------------------- void cpPlugins::Extensions::Visualization::ImageInteractorStyle:: OnMouseMove( ) { double pos[ 3 ]; if( this->CursorMoving && this->m_MPRActors != NULL ) { bool picked = this->_PickPosition( pos ); if( picked ) { for( int i = 0; i < 3; ++i ) if( this->m_SliceActors->GetAxis( ) != i ) this->m_MPRActors->SetSlice( i, pos[ i ] ); this->Interactor->Render( ); this->_RenderAssociateInteractors( ); } // fi } // fi } // ------------------------------------------------------------------------- void cpPlugins::Extensions::Visualization::ImageInteractorStyle:: OnLeftButtonDown( ) { int x = this->Interactor->GetEventPosition( )[ 0 ]; int y = this->Interactor->GetEventPosition( )[ 1 ]; this->FindPokedRenderer( x, y ); if( this->CurrentRenderer == NULL ) return; // Redefine this button to handle window/level this->GrabFocus( this->EventCallbackCommand ); if( this->Interactor->GetControlKey( ) ) this->StartCursorMoving( ); /* TODO if (!this->Interactor->GetShiftKey() && !this->Interactor->GetControlKey()) { this->WindowLevelStartPosition[0] = x; this->WindowLevelStartPosition[1] = y; this->StartWindowLevel(); } // If shift is held down, do a rotation else if (this->InteractionMode == VTKIS_IMAGE3D && this->Interactor->GetShiftKey()) { this->StartRotate(); } // If ctrl is held down in slicing mode, slice the image else if (this->InteractionMode == VTKIS_IMAGE_SLICING && this->Interactor->GetControlKey()) { this->StartSlice(); } // The rest of the button + key combinations remain the same else { this->Superclass::OnLeftButtonDown(); } */ } // ------------------------------------------------------------------------- void cpPlugins::Extensions::Visualization::ImageInteractorStyle:: OnLeftButtonUp( ) { if( this->CursorMoving ) this->EndCursorMoving( ); } // ------------------------------------------------------------------------- void cpPlugins::Extensions::Visualization::ImageInteractorStyle:: OnMiddleButtonDown( ) { std::cout << "middown" << std::endl; } // ------------------------------------------------------------------------- void cpPlugins::Extensions::Visualization::ImageInteractorStyle:: OnMiddleButtonUp( ) { std::cout << "midup" << std::endl; } // ------------------------------------------------------------------------- void cpPlugins::Extensions::Visualization::ImageInteractorStyle:: OnRightButtonDown( ) { std::cout << "ridown" << std::endl; } // ------------------------------------------------------------------------- void cpPlugins::Extensions::Visualization::ImageInteractorStyle:: OnRightButtonUp( ) { std::cout << "riup" << std::endl; } // ------------------------------------------------------------------------- void cpPlugins::Extensions::Visualization::ImageInteractorStyle:: OnMouseWheelForward( ) { if( this->m_SliceActors == NULL || this->Interactor == NULL ) return; int off = 1; if( this->Interactor->GetShiftKey( ) == 1 ) off *= 10; int s = this->m_SliceActors->GetSliceNumber( ) + off; int maxs = this->m_SliceActors->GetSliceNumberMaxValue( ); this->m_SliceActors->SetSliceNumber( ( s < maxs )? s: maxs ); this->Interactor->Render( ); this->_RenderAssociateInteractors( ); } // ------------------------------------------------------------------------- void cpPlugins::Extensions::Visualization::ImageInteractorStyle:: OnMouseWheelBackward( ) { if( this->m_SliceActors == NULL || this->Interactor == NULL ) return; int off = 1; if( this->Interactor->GetShiftKey( ) == 1 ) off *= 10; int s = this->m_SliceActors->GetSliceNumber( ) - off; int mins = this->m_SliceActors->GetSliceNumberMinValue( ); this->m_SliceActors->SetSliceNumber( ( mins < s )? s: mins ); this->Interactor->Render( ); this->_RenderAssociateInteractors( ); } // ------------------------------------------------------------------------- void cpPlugins::Extensions::Visualization::ImageInteractorStyle:: OnChar( ) { std::cout << "char" << std::endl; } // ------------------------------------------------------------------------- void cpPlugins::Extensions::Visualization::ImageInteractorStyle:: Rotate( ) { std::cout << "Rotate" << std::endl; } // ------------------------------------------------------------------------- void cpPlugins::Extensions::Visualization::ImageInteractorStyle:: Pan( ) { std::cout << "pan" << std::endl; } // ------------------------------------------------------------------------- void cpPlugins::Extensions::Visualization::ImageInteractorStyle:: Spin( ) { std::cout << "spin" << std::endl; } // ------------------------------------------------------------------------- void cpPlugins::Extensions::Visualization::ImageInteractorStyle:: Zoom( ) { std::cout << "Zoom" << std::endl; } // ------------------------------------------------------------------------- void cpPlugins::Extensions::Visualization::ImageInteractorStyle:: WindowLevel( ) { std::cout << "wl" << std::endl; } // ------------------------------------------------------------------------- void cpPlugins::Extensions::Visualization::ImageInteractorStyle:: Pick( ) { std::cout << "Pick" << std::endl; } // ------------------------------------------------------------------------- void cpPlugins::Extensions::Visualization::ImageInteractorStyle:: Slice( ) { std::cout << "Slice" << std::endl; } // ------------------------------------------------------------------------- void cpPlugins::Extensions::Visualization::ImageInteractorStyle:: StartWindowLevel( ) { std::cout << "swl" << std::endl; } // ------------------------------------------------------------------------- void cpPlugins::Extensions::Visualization::ImageInteractorStyle:: EndWindowLevel( ) { std::cout << "ewl" << std::endl; } // ------------------------------------------------------------------------- void cpPlugins::Extensions::Visualization::ImageInteractorStyle:: StartPick( ) { std::cout << "sp" << std::endl; } // ------------------------------------------------------------------------- void cpPlugins::Extensions::Visualization::ImageInteractorStyle:: EndPick( ) { std::cout << "ep" << std::endl; } // ------------------------------------------------------------------------- void cpPlugins::Extensions::Visualization::ImageInteractorStyle:: StartSlice( ) { std::cout << "ss" << std::endl; } // ------------------------------------------------------------------------- void cpPlugins::Extensions::Visualization::ImageInteractorStyle:: EndSlice( ) { std::cout << "es" << std::endl; } // ------------------------------------------------------------------------- void cpPlugins::Extensions::Visualization::ImageInteractorStyle:: StartCursorMoving( ) { if( this->CursorMoving ) return; this->CursorMoving = true; } // ------------------------------------------------------------------------- void cpPlugins::Extensions::Visualization::ImageInteractorStyle:: EndCursorMoving( ) { if( !( this->CursorMoving ) ) return; this->CursorMoving = false; } // ------------------------------------------------------------------------- cpPlugins::Extensions::Visualization::ImageInteractorStyle:: ImageInteractorStyle( ) : Superclass( ), Mode( Self::NavigationMode ), m_SliceActors( NULL ), m_MPRActors( NULL ), CursorMoving( false ) { // Orientation marks vtkSmartPointer< vtkAnnotatedCubeActor > cube = vtkSmartPointer< vtkAnnotatedCubeActor >::New( ); cube->GetCubeProperty( )->SetColor( 0.9, 0.7, 0.2 ); cube->GetTextEdgesProperty( )->SetLineWidth( 1 ); cube->GetTextEdgesProperty( )->SetDiffuse( 0 ); cube->GetTextEdgesProperty( )->SetAmbient( 1 ); cube->GetTextEdgesProperty( )->SetColor( 0.18, 0.28, 0.23 ); cube->GetXPlusFaceProperty( )->SetColor( 1, 0, 0 ); cube->GetXPlusFaceProperty( )->SetInterpolationToFlat( ); cube->GetXMinusFaceProperty( )->SetColor( 1, 0, 0 ); cube->GetXMinusFaceProperty( )->SetInterpolationToFlat( ); cube->GetYPlusFaceProperty( )->SetColor( 0, 1, 0 ); cube->GetYPlusFaceProperty( )->SetInterpolationToFlat( ); cube->GetYMinusFaceProperty( )->SetColor( 0, 1, 0 ); cube->GetYMinusFaceProperty( )->SetInterpolationToFlat( ); cube->GetZPlusFaceProperty( )->SetColor( 0, 0, 1 ); cube->GetZPlusFaceProperty( )->SetInterpolationToFlat( ); cube->GetZMinusFaceProperty( )->SetColor( 0, 0, 1 ); cube->GetZMinusFaceProperty( )->SetInterpolationToFlat( ); vtkSmartPointer< vtkAxesActor > axes = vtkSmartPointer< vtkAxesActor >::New( ); axes->AxisLabelsOff( ); axes->SetShaftTypeToCylinder( ); axes->SetTotalLength( 2, 2, 2 ); vtkSmartPointer< vtkPropAssembly > actors = vtkSmartPointer< vtkPropAssembly >::New( ); actors->AddPart( cube ); actors->AddPart( axes ); this->OrientationWidget = vtkSmartPointer< vtkOrientationMarkerWidget >::New( ); this->OrientationWidget->SetOutlineColor( 0.93, 0.57, 0.13 ); this->OrientationWidget->SetOrientationMarker( actors ); this->OrientationWidget->SetViewport( 0.0, 0.0, 0.2, 0.2 ); this->PropPicker = vtkSmartPointer< vtkPropPicker >::New( ); this->PropPicker->PickFromListOn( ); } // ------------------------------------------------------------------------- cpPlugins::Extensions::Visualization::ImageInteractorStyle:: ~ImageInteractorStyle( ) { } // ------------------------------------------------------------------------- void cpPlugins::Extensions::Visualization::ImageInteractorStyle:: _RenderAssociateInteractors( ) { std::vector< vtkRenderWindowInteractor* >::iterator rIt = this->AssociatedInteractors.begin( ); for( ; rIt != this->AssociatedInteractors.end( ); ++rIt ) ( *rIt )->Render( ); } // ------------------------------------------------------------------------- bool cpPlugins::Extensions::Visualization::ImageInteractorStyle:: _PickPosition( double pos[ 3 ] ) { if( this->m_SliceActors == NULL ) return( false ); double x = double( this->Interactor->GetEventPosition( )[ 0 ] ); double y = double( this->Interactor->GetEventPosition( )[ 1 ] ); this->FindPokedRenderer( x, y ); int success = this->PropPicker->Pick( x, y, double( 0 ), this->CurrentRenderer ); if( success == 0 ) return( false ); this->PropPicker->GetPickPosition( pos ); return( true ); } // ------------------------------------------------------------------------- void cpPlugins::Extensions::Visualization::ImageInteractorStyle:: _UpdateCursor( ) { std::cout << "upcur" << std::endl; } // eof - $RCSfile$