X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpExtensions%2FVisualization%2FImageSliceActors.cxx;h=5722c583d608b0159ebe9537e61ca5fcbcb84909;hb=f2f39f66027a98bd8dac50bade5618e0136bbefa;hp=469f270f6b7df5886232ed7601f339c857579110;hpb=58cd905dfd2cb77ebaef6857ca558dad4df02093;p=cpPlugins.git diff --git a/lib/cpExtensions/Visualization/ImageSliceActors.cxx b/lib/cpExtensions/Visualization/ImageSliceActors.cxx index 469f270..5722c58 100644 --- a/lib/cpExtensions/Visualization/ImageSliceActors.cxx +++ b/lib/cpExtensions/Visualization/ImageSliceActors.cxx @@ -1,5 +1,7 @@ #include +#include + #include #include #include @@ -7,6 +9,7 @@ #include #include #include +#include #include #include @@ -50,7 +53,7 @@ Clear( ) // Delete all images this->SliceMappers.clear( ); this->ImageActors.clear( ); - this->OtherActors.clear( ); + this->AssociatedActors.clear( ); // Reconfigure unique objects this->PlaneFunction = vtkSmartPointer< vtkPlane >::New( ); @@ -97,6 +100,44 @@ Clear( ) coord->SetValue( 0.01, 0.01 ); } +// ------------------------------------------------------------------------- +vtkInteractorStyle* cpExtensions::Visualization::ImageSliceActors:: +GetStyle( ) +{ + return( this->Style.GetPointer( ) ); +} + +// ------------------------------------------------------------------------- +const vtkInteractorStyle* cpExtensions::Visualization::ImageSliceActors:: +GetStyle( ) const +{ + return( this->Style.GetPointer( ) ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +PushActorsInto( vtkRenderer* renderer ) +{ + unsigned int N = this->GetNumberOfImageActors( ); + for( unsigned int n = 0; n < N; ++n ) + renderer->AddActor( this->GetImageActor( n ) ); + renderer->AddActor( this->GetTextActor( ) ); + renderer->AddActor( this->GetPlaneActor( ) ); + renderer->Modified( ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +PopActorsFrom( vtkRenderer* renderer ) +{ + unsigned int N = this->GetNumberOfImageActors( ); + for( unsigned int n = 0; n < N; ++n ) + renderer->RemoveActor( this->GetImageActor( n ) ); + renderer->RemoveActor( this->GetTextActor( ) ); + renderer->RemoveActor( this->GetPlaneActor( ) ); + renderer->Modified( ); +} + // ------------------------------------------------------------------------- unsigned int cpExtensions::Visualization::ImageSliceActors:: GetNumberOfImageActors( ) const @@ -170,7 +211,7 @@ GetPlaneFunction( ) const void cpExtensions::Visualization::ImageSliceActors:: AddActor( vtkAlgorithm* algorithm, vtkActor* actor ) { - this->OtherActors.push_back( TActorPair( algorithm, actor ) ); + this->AssociatedActors.push_back( TAssociatedActor( algorithm, actor ) ); this->AddItem( actor ); } @@ -381,26 +422,28 @@ SetSliceNumber( const int& slice ) this->PlaneActor->Modified( ); // Prepare other actors to update - for( unsigned int i = 0; i < this->OtherActors.size( ); ++i ) - { - if( this->OtherActors[ i ].first.GetPointer( ) != NULL ) - { - this->OtherActors[ i ].first->Modified( ); - this->OtherActors[ i ].first->Update( ); + /* TODO + for( unsigned int i = 0; i < this->OtherActors.size( ); ++i ) + { + if( this->OtherActors[ i ].first.GetPointer( ) != NULL ) + { + this->OtherActors[ i ].first->Modified( ); + this->OtherActors[ i ].first->Update( ); - } // fi + } // fi - if( this->OtherActors[ i ].second.GetPointer( ) != NULL ) - { - this->OtherActors[ i ].second->GetMapper( )->Modified( ); - this->OtherActors[ i ].second->Modified( ); + if( this->OtherActors[ i ].second.GetPointer( ) != NULL ) + { + this->OtherActors[ i ].second->GetMapper( )->Modified( ); + this->OtherActors[ i ].second->Modified( ); - } // fi + } // fi - } // rof + } // rof - if( this->m_UpdateCommand != NULL ) - this->m_UpdateCommand( this->m_UpdateData ); + if( this->m_UpdateCommand != NULL ) + this->m_UpdateCommand( this->m_UpdateData ); + */ // Update text this->UpdateText( ); @@ -430,6 +473,57 @@ UpdateText( ) this->Modified( ); } +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +UpdateText( double pos[ 3 ] ) +{ + if( this->SliceMappers.size( ) > 0 ) + { + char axis; + int axId = this->SliceMappers[ 0 ]->GetOrientation( ); + if ( axId == 0 ) axis = 'X'; + else if( axId == 1 ) axis = 'Y'; + else if( axId == 2 ) axis = 'Z'; + + vtkImageData* image = this->SliceMappers[ 0 ]->GetInput( ); + + int ijk[ 3 ]; + double pcoords[ 3 ]; + image->ComputeStructuredCoordinates( pos, ijk, pcoords ); + { + int nScl = image->GetNumberOfScalarComponents( ); + std::stringstream str; + str + << "[" << ijk[ 0 ] + << "," << ijk[ 1 ] + << "," << ijk[ 2 ] << "]=("; + str << + image->GetScalarComponentAsFloat( + ijk[ 0 ], ijk[ 1 ], ijk[ 2 ], 0 + ); + for( int n = 1; n < nScl; ++n ) + str + << " " + << image->GetScalarComponentAsFloat( + ijk[ 0 ], ijk[ 1 ], ijk[ 2 ], n + ); + str << ")"; + std::sprintf( + this->TextBuffer, "Axis: %c (%d) | Pixel %s", + axis, + this->SliceMappers[ 0 ]->GetSliceNumber( ), + str.str( ).c_str( ) + ); + + } // fi + } + else + this->TextBuffer[ 0 ] = '\0'; + this->TextActor->SetInput( this->TextBuffer ); + this->TextActor->Modified( ); + this->Modified( ); +} + // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: UpdateText( const double& w, const double& l ) @@ -458,10 +552,17 @@ UpdateText( const double& w, const double& l ) cpExtensions::Visualization::ImageSliceActors:: ImageSliceActors( ) : Superclass( ), - Interpolate( false ), - m_UpdateCommand( NULL ), - m_UpdateData( NULL ) + Interpolate( false ) { + // Connect this view with a controller + this->Style = vtkSmartPointer< ImageInteractorStyle >::New( ); + this->Style->AssociateView( this ); + this->Style->SetMouseMoveCommand( Self::_MouseMoveCommand ); + this->Style->SetMouseClickCommand( Self::_MouseClickCommand ); + this->Style->SetMouseDoubleClickCommand( Self::_MouseDoubleClickCommand ); + this->Style->SetMouseWheelCommand( Self::_MouseWheelCommand ); + this->Style->SetKeyCommand( Self::_KeyCommand ); + this->Clear( ); } @@ -497,6 +598,7 @@ _ConfigureNewInput( int axis ) { this->AddItem( this->TextActor ); this->AddItem( this->PlaneActor ); + this->Style->AssociateImageActor( actor ); } // fi this->AddItem( actor ); @@ -506,4 +608,69 @@ _ConfigureNewInput( int axis ) this->Modified( ); } +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +_MouseMoveCommand( + void* data, + const ImageInteractorStyle::ButtonID& btn, double* pos, + bool alt, bool ctr, bool sft + ) +{ + ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data ); + if( actors == NULL ) + return; + + if( btn == ImageInteractorStyle::ButtonID_None ) + { + actors->UpdateText( pos ); + } + else if( btn == ImageInteractorStyle::ButtonID_Left ) + { + } + else if( btn == ImageInteractorStyle::ButtonID_Middle ) + { + } + else if( btn == ImageInteractorStyle::ButtonID_Right ) + { + } // fi +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +_MouseClickCommand( + void* data, + const ImageInteractorStyle::ButtonID& btn, double* pos, + bool alt, bool ctr, bool sft + ) +{ +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +_MouseDoubleClickCommand( + void* data, + const ImageInteractorStyle::ButtonID& btn, double* pos, + bool alt, bool ctr, bool sft + ) +{ +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +_MouseWheelCommand( + void* data, + const int& dir, bool alt, bool ctr, bool sft + ) +{ +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +_KeyCommand( + void* data, + const char& key + ) +{ +} + // eof - $RCSfile$