#include #include #include #include #include #include #include #include #include #include // ------------------------------------------------------------------------- /* TODO cpExtensions::Interaction::ImageInteractorStyle::TSeedWidget:: TSeedWidget( vtkRenderWindowInteractor* interactor, vtkImageActor* actor ) { this->Placer = vtkSmartPointer< vtkImageActorPointPlacer >::New( ); this->Handle = vtkSmartPointer< vtkPointHandleRepresentation3D >::New( ); this->Representation = vtkSmartPointer< vtkSeedRepresentation >::New( ); this->Widget = vtkSmartPointer< SeedWidget >::New( ); this->Placer->SetImageActor( actor ); this->Handle->GetProperty( )->SetColor( 1, 0, 0 ); this->Handle->SetPointPlacer( this->Placer ); this->Representation->SetHandleRepresentation( this->Handle ); this->Widget->SetRepresentation( this->Representation ); this->Widget->SetInteractor( interactor ); } // ------------------------------------------------------------------------- void cpExtensions::Interaction::ImageInteractorStyle::TSeedWidget:: On( ) { this->Widget->On( ); } // ------------------------------------------------------------------------- void cpExtensions::Interaction::ImageInteractorStyle::TSeedWidget:: Off( ) { this->Widget->Off( ); } */ // ------------------------------------------------------------------------- cpExtensions::Interaction::ImageInteractorStyle:: Self* cpExtensions::Interaction::ImageInteractorStyle:: New( ) { return( new Self ); } // ------------------------------------------------------------------------- void cpExtensions::Interaction::ImageInteractorStyle:: SetCurrentRenderer( vtkRenderer* r ) { this->Superclass::SetCurrentRenderer( r ); if( !( this->m_Configured ) ) { auto lst = this->m_PropPicker->GetPickList( ); if( lst == NULL ) return; if( lst->GetNumberOfItems( ) == 1 ) { auto actor = dynamic_cast< vtkImageActor* >( lst->GetItemAsObject( 0 ) ); if( actor != NULL ) { this->_ConfigureCamera( actor ); this->Modified( ); } // fi } // fi } // fi } // ------------------------------------------------------------------------- void cpExtensions::Interaction::ImageInteractorStyle:: AssociateImageActor( vtkImageActor* actor ) { if( actor != NULL ) { // Update picker this->m_PropPicker->GetPickList( )->RemoveAllItems( ); this->m_PropPicker->AddPickList( actor ); this->m_Configured = false; this->_ConfigureCamera( actor ); // Ok, done this->Modified( ); } // fi } // ------------------------------------------------------------------------- /* void cpExtensions::Interaction::ImageInteractorStyle:: SeedWidgetOn( ) { if( this->m_SeedWidget != NULL ) delete this->m_SeedWidget; this->m_PropPicker->GetPickList( )->InitTraversal( ); this->m_SeedWidget = new TSeedWidget( this->Interactor, dynamic_cast< vtkImageActor* >( this->m_PropPicker->GetPickList( )->GetNextProp( ) ) ); this->m_SeedWidget->On( ); } // ------------------------------------------------------------------------- void cpExtensions::Interaction::ImageInteractorStyle:: SeedWidgetOff( ) { if( this->m_SeedWidget != NULL ) { this->m_SeedWidget->Off( ); delete this->m_SeedWidget; this->m_SeedWidget = NULL; } // fi } */ // ------------------------------------------------------------------------- /* void cpExtensions::Interaction::ImageInteractorStyle:: SetSeedWidgetCommand( vtkCommand* cmd ) { if( cmd == NULL || this->m_SeedWidget == NULL ) return; this->m_SeedWidget->Widget-> AddObserver( vtkCommand::PlacePointEvent, cmd ); } // ------------------------------------------------------------------------- unsigned int cpExtensions::Interaction::ImageInteractorStyle:: GetNumberOfSeeds( ) const { if( this->m_SeedWidget != NULL ) return( this->m_SeedWidget->Representation->GetNumberOfSeeds( ) ); else return( 0 ); } // ------------------------------------------------------------------------- void cpExtensions::Interaction::ImageInteractorStyle:: GetSeedAsPoint( unsigned int id, double pos[ 3 ] ) const { if( this->m_SeedWidget != NULL ) this->m_SeedWidget->Representation->GetSeedWorldPosition( id, pos ); } // ------------------------------------------------------------------------- void cpExtensions::Interaction::ImageInteractorStyle:: GetSeedAsIndex( unsigned int id, int idx[ 3 ] ) const { if( this->m_SeedWidget != NULL ) this->m_SeedWidget->Representation->GetSeedWorldPosition( id, pos ); } */ // ------------------------------------------------------------------------- cpExtensions::Interaction::ImageInteractorStyle:: ImageInteractorStyle( ) : Superclass( ), m_Configured( false ) /* , m_SeedWidget( NULL ) */ { this->m_PropPicker = vtkSmartPointer< vtkPropPicker >::New( ); this->m_PropPicker->PickFromListOn( ); } // ------------------------------------------------------------------------- cpExtensions::Interaction::ImageInteractorStyle:: ~ImageInteractorStyle( ) { // if( this->m_SeedWidget != NULL ) delete this->m_SeedWidget; } // ------------------------------------------------------------------------- void cpExtensions::Interaction::ImageInteractorStyle:: _ConfigureCamera( vtkImageActor* actor ) { if( this->CurrentRenderer != NULL ) { // Update camera auto camera = this->CurrentRenderer->GetActiveCamera( ); auto mapper = dynamic_cast< vtkImageSliceMapper* >( actor->GetMapper( ) ); if( mapper != NULL && camera != NULL ) { double bounds[ 6 ]; actor->GetBounds( bounds ); camera->ParallelProjectionOn( ); camera->SetFocalPoint( double( 0 ), double( 0 ), double( 0 ) ); int orientation = mapper->GetOrientation( ); switch( orientation ) { case 0: { camera->SetPosition( double( 1 ), double( 0 ), double( 0 ) ); camera->SetViewUp ( double( 0 ), double( 1 ), double( 0 ) ); } break; case 1: { camera->SetPosition( double( 0 ), double( 1 ), double( 0 ) ); camera->SetViewUp ( double( 0 ), double( 0 ), double( -1 ) ); } break; case 2: { camera->SetPosition( double( 0 ), double( 0 ), double( 1 ) ); camera->SetViewUp ( double( 0 ), double( 1 ), double( 0 ) ); } break; default: break; } // hctiws this->CurrentRenderer->ResetCamera( ); this->m_Configured = true; } // fi } // fi } // ------------------------------------------------------------------------- bool cpExtensions::Interaction::ImageInteractorStyle:: _PickPosition( int idx[ 2 ], double pos[ 3 ] ) { vtkRenderWindowInteractor* rwi = this->GetInteractor( ); if( rwi == NULL ) return( false ); // Find the renderer where the event has been raised idx[ 0 ] = rwi->GetEventPosition( )[ 0 ]; idx[ 1 ] = rwi->GetEventPosition( )[ 1 ]; this->FindPokedRenderer( double( idx[ 0 ] ), double( idx[ 1 ] ) ); // 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( pos ); return( true ); } // eof - $RCSfile$