#include #include #include #include #include #include #include #include #include #include /* TODO #include */ // ------------------------------------------------------------------------- cpExtensions::Interaction::ImageSliceStyle:: Self* cpExtensions::Interaction::ImageSliceStyle:: New( ) { return( new Self( ) ); } // ------------------------------------------------------------------------- void cpExtensions::Interaction::ImageSliceStyle:: OnMouseMove( ) { static bool cursor_visible = false; int idx[ 2 ]; double pnt[ 3 ]; if( this->_PickPointOnImageActor( idx, pnt ) ) { this->m_Cursor->SetCursor( pnt, false ); if( !cursor_visible ) { this->m_Cursor->VisibilityOn( ); cursor_visible = true; } // fi this->Interactor->Render( ); } else { if( cursor_visible ) { this->m_Cursor->VisibilityOff( ); cursor_visible = false; this->Interactor->Render( ); } // fi } // fi this->Superclass::OnMouseMove( ); } /* TODO cpExtensions::Visualization::ImageViewerActors* cpExtensions::Interaction::ImageSliceStyle:: GetActors( ) { return( this->m_Actors ); } // ------------------------------------------------------------------------- const cpExtensions::Visualization::ImageViewerActors* cpExtensions::Interaction::ImageSliceStyle:: GetActors( ) const { return( this->m_Actors ); } // ------------------------------------------------------------------------- void cpExtensions::Interaction::ImageSliceStyle:: SetActors( cpExtensions::Visualization::ImageViewerActors* actors ) { this->m_Actors = actors; if( actors != NULL ) { this->m_PropPicker = vtkSmartPointer< vtkPropPicker >::New( ); this->m_PropPicker->PickFromListOn( ); this->m_PropPicker->GetPickList( )->RemoveAllItems( ); this->m_PropPicker-> AddPickList( this->m_Actors->GetWindowLevelImageActor( ) ); } else this->m_PropPicker = NULL; } // ------------------------------------------------------------------------- void cpExtensions::Interaction::ImageSliceStyle:: OnMouseMove( ) { this->Superclass::OnMouseMove( ); if( this->m_Actors.GetPointer( ) == NULL ) return; // Slice synch static int idx[ 2 ]; static double pos[ 3 ]; if( this->_PickPosition( idx, pos ) ) { if( this->Interactor->GetControlKey( ) == 1 && this->GetButtonID( ) == Self::ButtonID_Left ) { this->m_Actors->SetSuperCursor( pos, this->m_Actors->GetOrientation( ) == 2 ); this->InvokeEvent( vtkCommand::UserEvent + 1, pos ); } else this->m_Actors->SetCursor( pos, this->m_Actors->GetOrientation( ) == 2 ); } else this->m_Actors->HideViewerActors( ); this->Interactor->Render( ); } // ------------------------------------------------------------------------- void cpExtensions::Interaction::ImageSliceStyle:: OnMouseWheelForward( ) { static int s = 0; if( this->m_Actors.GetPointer( ) == NULL ) return; s = this->m_Actors->GetSliceNumber( ); s += ( this->Interactor->GetShiftKey( ) == 1 )? 10: 1; this->m_Actors->SetSliceNumber( s ); s = this->m_Actors->GetSliceNumber( ); this->InvokeEvent( vtkCommand::UserEvent + 2, &s ); this->Interactor->Render( ); this->OnMouseMove( ); } // ------------------------------------------------------------------------- void cpExtensions::Interaction::ImageSliceStyle:: OnMouseWheelBackward( ) { static int s = 0; if( this->m_Actors.GetPointer( ) == NULL ) return; s = this->m_Actors->GetSliceNumber( ); s -= ( this->Interactor->GetShiftKey( ) == 1 )? 10: 1; this->m_Actors->SetSliceNumber( s ); s = this->m_Actors->GetSliceNumber( ); this->InvokeEvent( vtkCommand::UserEvent + 2, &s ); this->Interactor->Render( ); this->OnMouseMove( ); } // ------------------------------------------------------------------------- void cpExtensions::Interaction::ImageSliceStyle:: OnChar( ) { } */ // ------------------------------------------------------------------------- cpExtensions::Interaction::ImageSliceStyle:: ImageSliceStyle( ) : Superclass( ) { this->SetInteractionModeToImage2D( ); this->m_PropPicker = vtkSmartPointer< vtkPropPicker >::New( ); this->m_PropPicker->PickFromListOn( ); this->m_Cursor = vtkSmartPointer< TCursor >::New( ); this->m_Cursor->VisibilityOff( ); this->m_Cursor->GetProperty( 0 )->SetColor( 1, 1, 0 ); this->m_Cursor->GetProperty( 1 )->SetColor( 1, 1, 0 ); } // ------------------------------------------------------------------------- cpExtensions::Interaction::ImageSliceStyle:: ~ImageSliceStyle( ) { } // ------------------------------------------------------------------------- vtkProp* cpExtensions::Interaction::ImageSliceStyle:: _ImageActor( int i ) { if( !this->CurrentRenderer ) return( NULL ); vtkPropCollection* props = this->CurrentRenderer->GetViewProps( ); vtkProp* prop = 0; vtkAssemblyPath* path; vtkImageSlice* imageProp = NULL; vtkCollectionSimpleIterator pit; for( int k = 0; k < 2; k++ ) { int j = 0; for( props->InitTraversal( pit ); ( prop = props->GetNextProp( pit ) ); ) { bool foundImageProp = false; for( prop->InitPathTraversal( ); ( path = prop->GetNextPath( ) ); ) { vtkProp* tryProp = path->GetLastNode( )->GetViewProp( ); if( ( imageProp = vtkImageSlice::SafeDownCast( tryProp ) ) != 0 ) { if( j == i ) { foundImageProp = true; break; } // fi imageProp = 0; j++; } // fi } // rof if( foundImageProp ) break; } // rof if( i < 0 ) i += j; } // rof return( imageProp ); } // ------------------------------------------------------------------------- bool cpExtensions::Interaction::ImageSliceStyle:: _PickPointOnImageActor( int idx[ 2 ], double pnt[ 3 ] ) { // Check if data is valid if( this->Interactor == NULL || this->CurrentRenderer == NULL || this->m_PropPicker.GetPointer( ) == NULL ) return( false ); // Find the renderer where the event has been raised idx[ 0 ] = this->Interactor->GetEventPosition( )[ 0 ]; idx[ 1 ] = this->Interactor->GetEventPosition( )[ 1 ]; this->FindPokedRenderer( double( idx[ 0 ] ), double( idx[ 1 ] ) ); // Check if the image has changed this->Interactor->GetPicker( )-> Pick( idx[ 0 ], idx[ 1 ], 0.0, this->CurrentRenderer ); auto picker = vtkAbstractPropPicker::SafeDownCast( this->Interactor->GetPicker( ) ); if( picker == NULL ) return( false ); TWLActor* curr_actor = dynamic_cast< TWLActor* >( picker->GetProp3D( ) ); if( curr_actor != this->m_WLActor.GetPointer( ) && curr_actor != NULL ) { this->m_WLActor = curr_actor; this->m_PropPicker->GetPickList( )->RemoveAllItems( ); this->m_PropPicker->AddPickList( curr_actor ); this->m_Cursor->SetImageBounds( curr_actor->GetImage( )->GetBounds( ) ); this->m_Cursor->SetImageOrientation( curr_actor->GetOrientation( ) ); this->m_Cursor->InitTraversal( ); while( vtkProp* prop = this->m_Cursor->GetNextProp( ) ) this->CurrentRenderer->AddViewProp( prop ); } // fi if( this->m_WLActor.GetPointer( ) == NULL ) { this->m_PropPicker->GetPickList( )->RemoveAllItems( ); return( false ); } // fi // Pick a 3D position int r = this->m_PropPicker->Pick( double( idx[ 0 ] ), double( idx[ 1 ] ), double( 0 ), this->CurrentRenderer ); if( r == 0 ) return( false ); this->m_PropPicker->GetPickPosition( pnt ); return( true ); } // eof - $RCSfile$