X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpExtensions%2FVisualization%2FImageSliceActors.cxx;h=5722c583d608b0159ebe9537e61ca5fcbcb84909;hb=f2f39f66027a98bd8dac50bade5618e0136bbefa;hp=ef55f5463bacf96bb4475edb98d6b1679178ade3;hpb=c3c3da5217b6eb255db9c0424f22d4e01250901e;p=cpPlugins.git diff --git a/lib/cpExtensions/Visualization/ImageSliceActors.cxx b/lib/cpExtensions/Visualization/ImageSliceActors.cxx index ef55f54..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,12 +53,14 @@ Clear( ) // Delete all images this->SliceMappers.clear( ); this->ImageActors.clear( ); + this->AssociatedActors.clear( ); // Reconfigure unique objects - this->PlaneSource = vtkSmartPointer< vtkPolyData >::New( ); - this->PlaneMapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); - this->TextActor = vtkSmartPointer< vtkTextActor >::New( ); - this->PlaneActor = vtkSmartPointer< vtkActor >::New( ); + this->PlaneFunction = vtkSmartPointer< vtkPlane >::New( ); + this->PlaneSource = vtkSmartPointer< vtkPolyData >::New( ); + this->PlaneMapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); + this->TextActor = vtkSmartPointer< vtkTextActor >::New( ); + this->PlaneActor = vtkSmartPointer< vtkActor >::New( ); this->TextBuffer[ 0 ] = '\0'; // Unique objects configuration @@ -95,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 @@ -150,6 +193,35 @@ GetPlaneActor( ) const return( this->PlaneActor ); } +// ------------------------------------------------------------------------- +vtkPlane* cpExtensions::Visualization::ImageSliceActors:: +GetPlaneFunction( ) +{ + return( this->PlaneFunction ); +} + +// ------------------------------------------------------------------------- +const vtkPlane* cpExtensions::Visualization::ImageSliceActors:: +GetPlaneFunction( ) const +{ + return( this->PlaneFunction ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +AddActor( vtkAlgorithm* algorithm, vtkActor* actor ) +{ + this->AssociatedActors.push_back( TAssociatedActor( algorithm, actor ) ); + this->AddItem( actor ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +AddActor( vtkActor* actor ) +{ + this->AddActor( NULL, actor ); +} + // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: SetInterpolate( bool v ) @@ -308,12 +380,17 @@ SetSliceNumber( const int& slice ) } // fi + // Plane function origin + this->PlaneFunction->SetOrigin( pos ); + + // Configure visualization and implicit plane orientation int axis = this->SliceMappers[ 0 ]->GetOrientation( ); this->PlaneActor->GetProperty( )->SetRepresentationToWireframe( ); this->PlaneActor->GetProperty( )->SetLineWidth( 2 ); vtkPoints* plane_points = this->PlaneSource->GetPoints( ); if( axis == 0 ) // YZ, x-normal { + this->PlaneFunction->SetNormal( 1, 0, 0 ); plane_points->SetPoint( 0, pos[ 0 ], ybnds[ 0 ], zbnds[ 0 ] ); plane_points->SetPoint( 1, pos[ 0 ], ybnds[ 1 ], zbnds[ 0 ] ); plane_points->SetPoint( 2, pos[ 0 ], ybnds[ 1 ], zbnds[ 1 ] ); @@ -322,6 +399,7 @@ SetSliceNumber( const int& slice ) } else if( axis == 1 ) // ZX, y-normal { + this->PlaneFunction->SetNormal( 0, 1, 0 ); plane_points->SetPoint( 0, xbnds[ 0 ], pos[ 1 ], zbnds[ 0 ] ); plane_points->SetPoint( 1, xbnds[ 0 ], pos[ 1 ], zbnds[ 1 ] ); plane_points->SetPoint( 2, xbnds[ 1 ], pos[ 1 ], zbnds[ 1 ] ); @@ -330,6 +408,7 @@ SetSliceNumber( const int& slice ) } else // XY, z-normal { + this->PlaneFunction->SetNormal( 0, 0, 1 ); plane_points->SetPoint( 0, xbnds[ 0 ], ybnds[ 0 ], pos[ 2 ] ); plane_points->SetPoint( 1, xbnds[ 1 ], ybnds[ 0 ], pos[ 2 ] ); plane_points->SetPoint( 2, xbnds[ 1 ], ybnds[ 1 ], pos[ 2 ] ); @@ -337,9 +416,36 @@ SetSliceNumber( const int& slice ) this->PlaneActor->GetProperty( )->SetColor( 0, 0, 1 ); } // fi + this->PlaneFunction->Modified( ); this->PlaneSource->Modified( ); this->PlaneMapper->Modified( ); this->PlaneActor->Modified( ); + + // Prepare other actors to 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 + + if( this->OtherActors[ i ].second.GetPointer( ) != NULL ) + { + this->OtherActors[ i ].second->GetMapper( )->Modified( ); + this->OtherActors[ i ].second->Modified( ); + + } // fi + + } // rof + + if( this->m_UpdateCommand != NULL ) + this->m_UpdateCommand( this->m_UpdateData ); + */ + + // Update text this->UpdateText( ); } @@ -367,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 ) @@ -397,6 +554,15 @@ ImageSliceActors( ) : Superclass( ), 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( ); } @@ -432,6 +598,7 @@ _ConfigureNewInput( int axis ) { this->AddItem( this->TextActor ); this->AddItem( this->PlaneActor ); + this->Style->AssociateImageActor( actor ); } // fi this->AddItem( actor ); @@ -441,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$