X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpExtensions%2FVisualization%2FImageSliceActors.cxx;h=ee4947e834d4394463a547de1e958d4752e66f58;hb=106a56bfe6a48067380089ffd61a518e40d77933;hp=562179e2432ac109fcac6c572cc11f0e5391353c;hpb=dc72ea8ea52fc074566d9437048db24af6c0aaab;p=cpPlugins.git diff --git a/lib/cpExtensions/Visualization/ImageSliceActors.cxx b/lib/cpExtensions/Visualization/ImageSliceActors.cxx index 562179e..ee4947e 100644 --- a/lib/cpExtensions/Visualization/ImageSliceActors.cxx +++ b/lib/cpExtensions/Visualization/ImageSliceActors.cxx @@ -1,13 +1,17 @@ #include +#include + #include +#include #include #include -#include -#include #include #include -#include +#include +#include +#include +#include #include // ------------------------------------------------------------------------- @@ -18,91 +22,223 @@ New( ) return( new Self( ) ); } +// ------------------------------------------------------------------------- +cpExtensions::Visualization:: +ImageBlender* cpExtensions::Visualization::ImageSliceActors:: +GetBlender( ) +{ + return( this->m_ImageBlender ); +} + +// ------------------------------------------------------------------------- +const cpExtensions::Visualization:: +ImageBlender* cpExtensions::Visualization::ImageSliceActors:: +GetBlender( ) const +{ + return( this->m_ImageBlender ); +} + // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -AddInputConnection( vtkAlgorithmOutput* aout, int axis ) +SetBlender( ImageBlender* blender ) { - unsigned int nImages = this->SliceMappers.size( ); + this->m_ImageBlender = blender; - vtkSmartPointer< vtkImageSliceMapper > mapper = - vtkSmartPointer< vtkImageSliceMapper >::New( ); - this->SliceMappers.push_back( mapper ); - mapper->SetInputConnection( aout ); - mapper->SetOrientation( - ( nImages == 0 )? axis: this->SliceMappers[ 0 ]->GetOrientation( ) + // Create mapper and actors + this->m_ImageMapper = vtkSmartPointer< vtkImageSliceMapper >::New( ); + this->m_ImageMapper->SetInputConnection( + this->m_ImageBlender->GetOutputPort( ) ); - mapper->Update( ); - - this->SetSliceNumber( this->SliceMappers[ 0 ]->GetSliceNumber( ) ); + this->m_ImageMapper->SetOrientation( 0 ); + this->m_ImageMapper->Update( ); - vtkSmartPointer< vtkImageActor > actor = - vtkSmartPointer< vtkImageActor >::New( ); - this->ImageActors.push_back( actor ); - actor->SetMapper( mapper ); - actor->Modified( ); + // Create actor + this->m_ImageActor = vtkSmartPointer< vtkImageActor >::New( ); + this->m_ImageActor->SetMapper( this->m_ImageMapper ); + this->m_ImageActor->SetInterpolate( this->m_Interpolate ); + this->m_ImageActor->Modified( ); - if( nImages == 0 ) - { - this->AddItem( this->TextActor ); - this->AddItem( this->PlaneActor ); + if( this->m_Style.GetPointer( ) != NULL ) + this->m_Style->AssociateImageActor( this->m_ImageActor ); + this->AddItem( this->m_ImageActor ); - } // fi - this->AddItem( actor ); + this->SetSliceNumber( this->GetSliceNumberMinValue( ) ); + this->ResetCursor( ); this->Modified( ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -AddInputData( vtkImageData* data, int axis ) +SetAxis( int axis ) { - unsigned int nImages = this->SliceMappers.size( ); + this->m_ImageMapper->SetOrientation( axis ); + this->m_ImageMapper->Update( ); + this->SetSliceNumber( this->GetSliceNumberMinValue( ) ); + this->m_ImageActor->Modified( ); + this->Modified( ); + this->ResetCamera( ); +} - vtkSmartPointer< vtkImageSliceMapper > mapper = - vtkSmartPointer< vtkImageSliceMapper >::New( ); - this->SliceMappers.push_back( mapper ); - mapper->SetInputData( data ); - mapper->SetOrientation( - ( nImages == 0 )? axis: this->SliceMappers[ 0 ]->GetOrientation( ) - ); - mapper->Update( ); - - this->SetSliceNumber( this->SliceMappers[ 0 ]->GetSliceNumber( ) ); +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +AddInputConnection( vtkAlgorithmOutput* aout ) +{ + // Get input vtkImageData + if( aout == NULL ) + return; + + if( this->m_ImageBlender.GetPointer( ) == NULL ) + { + // Try to infere if input comes from a color mapping filter + vtkAlgorithm* producer = aout->GetProducer( ); + vtkSmartPointer< ImageBlender > blender = + dynamic_cast< ImageBlender* >( producer ); + if( blender.GetPointer( ) == NULL ) + { + // Ok, create a new blender with default window level + vtkImageData* data = dynamic_cast< vtkImageData* >( + producer->GetOutputDataObject( aout->GetIndex( ) ) + ); + double r[ 2 ]; + data->GetScalarRange( r ); + + blender = vtkSmartPointer< ImageBlender >::New( ); + blender->AddInputConnection( aout ); + blender->SetWindow( r[ 1 ] - r[ 0 ] ); + blender->SetLevel( ( r[ 1 ] + r[ 0 ] ) / double( 2 ) ); + + } // fi + this->SetBlender( blender ); + } + else + this->m_ImageBlender->AddInputConnection( aout ); +} - vtkSmartPointer< vtkImageActor > actor = - vtkSmartPointer< vtkImageActor >::New( ); - this->ImageActors.push_back( actor ); - actor->SetMapper( mapper ); - actor->Modified( ); +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +AddInputData( vtkImageData* data ) +{ + // Get input vtkImageData + if( data == NULL ) + return; - if( nImages == 0 ) + if( this->m_ImageBlender.GetPointer( ) == NULL ) { - this->AddItem( this->TextActor ); - this->AddItem( this->PlaneActor ); + // Create a new blender with default window level + double r[ 2 ]; + data->GetScalarRange( r ); - } // fi - this->AddItem( actor ); - this->Modified( ); + vtkSmartPointer< ImageBlender > blender = + vtkSmartPointer< ImageBlender >::New( ); + blender->AddInputData( data ); + blender->SetWindow( r[ 1 ] - r[ 0 ] ); + blender->SetLevel( ( r[ 1 ] + r[ 0 ] ) / double( 2 ) ); + this->SetBlender( blender ); + } + else + this->m_ImageBlender->AddInputData( data ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: Clear( ) { + // Reset values + this->m_VisibleExtent[ 0 ] = + this->m_VisibleExtent[ 2 ] = + this->m_VisibleExtent[ 4 ] = -1; + this->m_VisibleExtent[ 1 ] = + this->m_VisibleExtent[ 3 ] = + this->m_VisibleExtent[ 5 ] = 0; + this->m_VisibleBounds[ 0 ] = + this->m_VisibleBounds[ 2 ] = + this->m_VisibleBounds[ 4 ] = double( 0 ); + this->m_VisibleBounds[ 1 ] = + this->m_VisibleBounds[ 3 ] = + this->m_VisibleBounds[ 5 ] = double( 0 ); + // Unbind from container this->RemoveAllItems( ); // Delete all images - this->SliceMappers.clear( ); - this->ImageActors.clear( ); + this->m_ImageActor = NULL; + this->m_ImageMapper = NULL; + this->m_ImageBlender = NULL; // Reconfigure unique objects - this->PlaneSource = vtkSmartPointer< vtkPolyData >::New( ); - this->PlaneMapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); - this->TextActor = vtkSmartPointer< vtkTextActor >::New( ); - this->PlaneActor = vtkSmartPointer< vtkActor >::New( ); - this->TextBuffer[ 0 ] = '\0'; + this->m_Cursor = vtkSmartPointer< vtkPolyData >::New( ); + this->m_CursorMapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); + this->m_CursorActor = vtkSmartPointer< vtkActor >::New( ); + this->m_HorizontalLine = vtkSmartPointer< vtkPolyData >::New( ); + this->m_HorizontalLineMapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); + this->m_HorizontalLineActor = vtkSmartPointer< vtkActor >::New( ); + this->m_VerticalLine = vtkSmartPointer< vtkPolyData >::New( ); + this->m_VerticalLineMapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); + this->m_VerticalLineActor = vtkSmartPointer< vtkActor >::New( ); + this->m_Plane = vtkSmartPointer< vtkPolyData >::New( ); + this->m_PlaneMapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); + this->m_TextActor = vtkSmartPointer< vtkTextActor >::New( ); + this->m_PlaneActor = vtkSmartPointer< vtkActor >::New( ); + this->m_TextBuffer[ 0 ] = '\0'; // Unique objects configuration + vtkSmartPointer< vtkPoints > cursor_points = + vtkSmartPointer< vtkPoints >::New( ); + vtkSmartPointer< vtkCellArray > cursor_lines = + vtkSmartPointer< vtkCellArray >::New( ); + cursor_points->InsertNextPoint( 0, 0, 0 ); + cursor_points->InsertNextPoint( 0, 0, 0 ); + cursor_points->InsertNextPoint( 0, 0, 0 ); + cursor_points->InsertNextPoint( 0, 0, 0 ); + cursor_points->InsertNextPoint( 0, 0, 0 ); + cursor_points->InsertNextPoint( 0, 0, 0 ); + cursor_points->InsertNextPoint( 0, 0, 0 ); + cursor_points->InsertNextPoint( 0, 0, 0 ); + cursor_lines->InsertNextCell( 2 ); + cursor_lines->InsertCellPoint( 0 ); + cursor_lines->InsertCellPoint( 1 ); + cursor_lines->InsertNextCell( 2 ); + cursor_lines->InsertCellPoint( 2 ); + cursor_lines->InsertCellPoint( 3 ); + cursor_lines->InsertNextCell( 2 ); + cursor_lines->InsertCellPoint( 4 ); + cursor_lines->InsertCellPoint( 5 ); + cursor_lines->InsertNextCell( 2 ); + cursor_lines->InsertCellPoint( 6 ); + cursor_lines->InsertCellPoint( 7 ); + this->m_Cursor->SetPoints( cursor_points ); + this->m_Cursor->SetLines( cursor_lines ); + this->m_CursorMapper->SetInputData( this->m_Cursor ); + this->m_CursorActor->SetMapper( this->m_CursorMapper ); + + vtkSmartPointer< vtkPoints > h_points = + vtkSmartPointer< vtkPoints >::New( ); + vtkSmartPointer< vtkCellArray > h_lines = + vtkSmartPointer< vtkCellArray >::New( ); + h_points->InsertNextPoint( 0, 0, 0 ); + h_points->InsertNextPoint( 0, 0, 0 ); + h_lines->InsertNextCell( 2 ); + h_lines->InsertCellPoint( 0 ); + h_lines->InsertCellPoint( 1 ); + this->m_HorizontalLine->SetPoints( h_points ); + this->m_HorizontalLine->SetLines( h_lines ); + this->m_HorizontalLineMapper->SetInputData( this->m_HorizontalLine ); + this->m_HorizontalLineActor->SetMapper( this->m_HorizontalLineMapper ); + + vtkSmartPointer< vtkPoints > v_points = + vtkSmartPointer< vtkPoints >::New( ); + vtkSmartPointer< vtkCellArray > v_lines = + vtkSmartPointer< vtkCellArray >::New( ); + v_points->InsertNextPoint( 0, 0, 0 ); + v_points->InsertNextPoint( 0, 0, 0 ); + v_lines->InsertNextCell( 2 ); + v_lines->InsertCellPoint( 0 ); + v_lines->InsertCellPoint( 1 ); + this->m_VerticalLine->SetPoints( v_points ); + this->m_VerticalLine->SetLines( v_lines ); + this->m_VerticalLineMapper->SetInputData( this->m_VerticalLine ); + this->m_VerticalLineActor->SetMapper( this->m_VerticalLineMapper ); + vtkSmartPointer< vtkPoints > plane_points = vtkSmartPointer< vtkPoints >::New( ); vtkSmartPointer< vtkCellArray > plane_lines = @@ -118,14 +254,14 @@ Clear( ) plane_lines->InsertCellPoint( 2 ); plane_lines->InsertCellPoint( 3 ); plane_lines->InsertCellPoint( 0 ); - this->PlaneSource->SetPoints( plane_points ); - this->PlaneSource->SetLines( plane_lines ); + this->m_Plane->SetPoints( plane_points ); + this->m_Plane->SetLines( plane_lines ); - this->PlaneMapper->SetInputData( this->PlaneSource ); - this->PlaneActor->SetMapper( this->PlaneMapper ); + this->m_PlaneMapper->SetInputData( this->m_Plane ); + this->m_PlaneActor->SetMapper( this->m_PlaneMapper ); - this->TextActor->SetTextScaleModeToNone( ); - vtkTextProperty* textprop = this->TextActor->GetTextProperty( ); + this->m_TextActor->SetTextScaleModeToNone( ); + vtkTextProperty* textprop = this->m_TextActor->GetTextProperty( ); textprop->SetColor( 1, 1, 1 ); textprop->SetFontFamilyToCourier( ); textprop->SetFontSize( 18 ); @@ -134,72 +270,241 @@ Clear( ) textprop->ShadowOff( ); textprop->SetJustificationToLeft( ); textprop->SetVerticalJustificationToBottom( ); - vtkCoordinate* coord = this->TextActor->GetPositionCoordinate( ); + vtkCoordinate* coord = this->m_TextActor->GetPositionCoordinate( ); coord->SetCoordinateSystemToNormalizedViewport( ); coord->SetValue( 0.01, 0.01 ); + + // Update actor collection + this->AddItem( this->m_CursorActor ); + this->AddItem( this->m_HorizontalLineActor ); + this->AddItem( this->m_VerticalLineActor ); + this->AddItem( this->m_TextActor ); + this->AddItem( this->m_PlaneActor ); } // ------------------------------------------------------------------------- -unsigned int cpExtensions::Visualization::ImageSliceActors:: -GetNumberOfImageActors( ) const +void cpExtensions::Visualization::ImageSliceActors:: +AssociateSlice( Self* slice ) { - return( this->ImageActors.size( ) ); + this->m_AssociatedSlices.push_back( slice ); + this->Modified( ); } // ------------------------------------------------------------------------- -vtkImageActor* cpExtensions::Visualization::ImageSliceActors:: -GetImageActor( unsigned int id ) +vtkInteractorStyle* cpExtensions::Visualization::ImageSliceActors:: +GetStyle( ) +{ + return( this->m_Style.GetPointer( ) ); +} + +// ------------------------------------------------------------------------- +const vtkInteractorStyle* cpExtensions::Visualization::ImageSliceActors:: +GetStyle( ) const { - if( id < this->ImageActors.size( ) ) - return( this->ImageActors[ id ] ); + return( this->m_Style.GetPointer( ) ); +} + +// ------------------------------------------------------------------------- +vtkImageData* cpExtensions::Visualization::ImageSliceActors:: +GetInputImage( unsigned int id ) +{ + if( this->m_ImageBlender.GetPointer( ) != NULL ) + return( + dynamic_cast< vtkImageData* >( this->m_ImageBlender->GetInput( id ) ) + ); else return( NULL ); } // ------------------------------------------------------------------------- -const vtkImageActor* cpExtensions::Visualization::ImageSliceActors:: -GetImageActor( unsigned int id ) const +const vtkImageData* cpExtensions::Visualization::ImageSliceActors:: +GetInputImage( unsigned int id ) const { - if( id < this->ImageActors.size( ) ) - return( this->ImageActors[ id ] ); + if( this->m_ImageBlender.GetPointer( ) != NULL ) + return( + dynamic_cast< const vtkImageData* >( + this->m_ImageBlender->GetInput( ) + ) + ); else return( NULL ); } +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +PushActorsInto( vtkRenderWindow* window, bool force_style ) +{ + this->m_Window = window; + if( window == NULL ) + return; + vtkRenderWindowInteractor* rwi = window->GetInteractor( ); + vtkRenderer* renderer = window->GetRenderers( )->GetFirstRenderer( ); + if( rwi == NULL || renderer == NULL ) + return; + + // Update style + if( this->m_Style.GetPointer( ) != NULL && force_style ) + rwi->SetInteractorStyle( this->m_Style ); + + // Update actors + vtkProp* prop; + this->InitTraversal( ); + while( prop = this->GetNextProp( ) ) + renderer->AddViewProp( prop ); + renderer->Modified( ); + if( !force_style ) + { + renderer->RemoveViewProp( this->m_CursorActor ); + renderer->RemoveViewProp( this->m_TextActor ); + + } // fi + + // Configure camera + vtkCamera* camera = renderer->GetActiveCamera( ); + if( camera != NULL && force_style ) + { + // Parallel projections are better when displaying 2D images + int axis = this->GetAxis( ); + camera->ParallelProjectionOn( ); + camera->SetFocalPoint( double( 0 ), double( 0 ), double( 0 ) ); + if( axis == 0 ) + { + camera->SetPosition( double( 1 ), double( 0 ), double( 0 ) ); + camera->SetViewUp ( double( 0 ), double( 0 ), double( 1 ) ); + } + else if( axis == 1 ) + { + camera->SetPosition( double( 0 ), double( -1 ), double( 0 ) ); + camera->SetViewUp ( double( 0 ), double( 0 ), double( 1 ) ); + } + else // if( axis == 2 ) + { + camera->SetPosition( double( 0 ), double( 0 ), double( 1 ) ); + camera->SetViewUp ( double( 0 ), double( -1 ), double( 0 ) ); + + } // fi + + } // fi + this->ResetCamera( ); + rwi->Render( ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +PopActorsFrom( vtkRenderWindow* window ) +{ + vtkRenderWindowInteractor* rwi = window->GetInteractor( ); + vtkRenderer* renderer = window->GetRenderers( )->GetFirstRenderer( ); + + if( renderer != NULL ) + { + // Update actors + vtkProp* prop; + this->InitTraversal( ); + while( prop = this->GetNextProp( ) ) + renderer->RemoveViewProp( prop ); + renderer->Modified( ); + + } // fi + if( rwi != NULL ) + rwi->Render( ); +} + +// ------------------------------------------------------------------------- +vtkImageActor* cpExtensions::Visualization::ImageSliceActors:: +GetImageActor( ) +{ + return( this->m_ImageActor ); +} + +// ------------------------------------------------------------------------- +const vtkImageActor* cpExtensions::Visualization::ImageSliceActors:: +GetImageActor( ) const +{ + return( this->m_ImageActor ); +} + // ------------------------------------------------------------------------- vtkTextActor* cpExtensions::Visualization::ImageSliceActors:: GetTextActor( ) { - return( this->TextActor ); + return( this->m_TextActor ); } // ------------------------------------------------------------------------- const vtkTextActor* cpExtensions::Visualization::ImageSliceActors:: GetTextActor( ) const { - return( this->TextActor ); + return( this->m_TextActor ); } // ------------------------------------------------------------------------- vtkActor* cpExtensions::Visualization::ImageSliceActors:: GetPlaneActor( ) { - return( this->PlaneActor ); + return( this->m_PlaneActor ); } // ------------------------------------------------------------------------- const vtkActor* cpExtensions::Visualization::ImageSliceActors:: GetPlaneActor( ) const { - return( this->PlaneActor ); + return( this->m_PlaneActor ); +} + +// ------------------------------------------------------------------------- +vtkPlane* cpExtensions::Visualization::ImageSliceActors:: +GetPlaneFunction( ) +{ + if( this->m_ImageMapper.GetPointer( ) != NULL ) + return( this->m_ImageMapper->GetSlicePlane( ) ); + else + return( NULL ); +} + +// ------------------------------------------------------------------------- +const vtkPlane* cpExtensions::Visualization::ImageSliceActors:: +GetPlaneFunction( ) const +{ + if( this->m_ImageMapper.GetPointer( ) != NULL ) + return( this->m_ImageMapper->GetSlicePlane( ) ); + else + return( NULL ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +SetInterpolate( bool v ) +{ + if( this->m_Interpolate != v ) + { + this->m_ImageActor->SetInterpolate( v ); + this->m_Interpolate = v; + this->Modified( ); + + } // fi +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +InterpolateOn( ) +{ + this->SetInterpolate( true ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +InterpolateOff( ) +{ + this->SetInterpolate( false ); } // ------------------------------------------------------------------------- double* cpExtensions::Visualization::ImageSliceActors:: GetDisplayBounds( ) const { - if( this->ImageActors.size( ) > 0 ) - return( this->ImageActors[ 0 ]->GetDisplayBounds( ) ); + if( this->m_ImageActor.GetPointer( ) != NULL ) + return( this->m_ImageActor->GetDisplayBounds( ) ); else return( NULL ); } @@ -208,16 +513,204 @@ GetDisplayBounds( ) const void cpExtensions::Visualization::ImageSliceActors:: GetDisplayBounds( double bounds[ 6 ] ) const { - if( this->ImageActors.size( ) > 0 ) - this->ImageActors[ 0 ]->GetDisplayBounds( bounds ); + if( this->m_ImageActor.GetPointer( ) == NULL ) + { + bounds[ 0 ] = bounds[ 2 ] = bounds[ 4 ] = double( -1 ); + bounds[ 1 ] = bounds[ 3 ] = bounds[ 5 ] = double( -1 ); + } + else + this->m_ImageActor->GetDisplayBounds( bounds ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +ResetCursor( ) +{ + if( this->m_ImageMapper.GetPointer( ) != NULL ) + { + double bounds[ 6 ]; + this->m_ImageMapper->GetInput( )->GetBounds( bounds ); + double pos[] = + { + this->m_VisibleBounds[ 0 ], + this->m_VisibleBounds[ 2 ], + this->m_VisibleBounds[ 4 ] + }; + this->SetCursor( pos ); + } + else + { + vtkPoints* points = this->m_Cursor->GetPoints( ); + points->SetPoint( 0, 0, 0, 0 ); + points->SetPoint( 1, 0, 0, 0 ); + points->SetPoint( 2, 0, 0, 0 ); + points->SetPoint( 3, 0, 0, 0 ); + points->SetPoint( 4, 0, 0, 0 ); + points->SetPoint( 5, 0, 0, 0 ); + points->SetPoint( 6, 0, 0, 0 ); + points->SetPoint( 7, 0, 0, 0 ); + this->m_Cursor->Modified( ); + this->m_CursorMapper->Modified( ); + this->m_CursorActor->Modified( ); + + } // fi +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +SetCursor( double pos[ 3 ] ) +{ + if( this->m_ImageMapper.GetPointer( ) == NULL ) + return; + + // Get ordered axes + int a0 = this->GetAxis( ); + int a1 = ( a0 + 1 ) % 3; + int a2 = ( a0 + 2 ) % 3; + int ma0 = a0 << 1; + int ma1 = a1 << 1; + int ma2 = a2 << 1; + + // Update cross + double* bounds = this->m_VisibleBounds; + double + p0[ 3 ], p1[ 3 ], p2[ 3 ], p3[ 3 ], + p4[ 3 ], p5[ 3 ], p6[ 3 ], p7[ 3 ]; + + p0[ a2 ] = p1[ a2 ] = p4[ a2 ] = p5[ a2 ] = pos[ a2 ]; + p2[ a1 ] = p3[ a1 ] = p6[ a1 ] = p7[ a1 ] = pos[ a1 ]; + p0[ a0 ] = p1[ a0 ] = p2[ a0 ] = p3[ a0 ] = bounds[ ma0 ]; + p4[ a0 ] = p5[ a0 ] = p6[ a0 ] = p7[ a0 ] = bounds[ ma0 + 1 ]; + p0[ a1 ] = p4[ a1 ] = bounds[ ma1 ]; + p1[ a1 ] = p5[ a1 ] = bounds[ ma1 + 1 ]; + p2[ a2 ] = p6[ a2 ] = bounds[ ma2 ]; + p3[ a2 ] = p7[ a2 ] = bounds[ ma2 + 1 ]; + + vtkPoints* points = this->m_Cursor->GetPoints( ); + points->SetPoint( 0, p0 ); + points->SetPoint( 1, p1 ); + points->SetPoint( 2, p2 ); + points->SetPoint( 3, p3 ); + points->SetPoint( 4, p4 ); + points->SetPoint( 5, p5 ); + points->SetPoint( 6, p6 ); + points->SetPoint( 7, p7 ); + this->m_Cursor->Modified( ); + this->m_CursorMapper->Modified( ); + this->m_CursorActor->Modified( ); +} + +// ------------------------------------------------------------------------- +double cpExtensions::Visualization::ImageSliceActors:: +GetMinWindow( ) const +{ + if( this->m_ImageBlender.GetPointer( ) != NULL ) + return( this->m_ImageBlender->GetMinWindow( ) ); + else + return( double( 0 ) ); +} + +// ------------------------------------------------------------------------- +double cpExtensions::Visualization::ImageSliceActors:: +GetMaxWindow( ) const +{ + if( this->m_ImageBlender.GetPointer( ) != NULL ) + return( this->m_ImageBlender->GetMaxWindow( ) ); + else + return( double( 0 ) ); +} + +// ------------------------------------------------------------------------- +double cpExtensions::Visualization::ImageSliceActors:: +GetMinLevel( ) const +{ + if( this->m_ImageBlender.GetPointer( ) != NULL ) + return( this->m_ImageBlender->GetMinLevel( ) ); + else + return( double( 0 ) ); +} + +// ------------------------------------------------------------------------- +double cpExtensions::Visualization::ImageSliceActors:: +GetMaxLevel( ) const +{ + if( this->m_ImageBlender.GetPointer( ) != NULL ) + return( this->m_ImageBlender->GetMaxLevel( ) ); + else + return( double( 0 ) ); +} + +// ------------------------------------------------------------------------- +double cpExtensions::Visualization::ImageSliceActors:: +GetWindow( ) const +{ + if( this->m_ImageBlender.GetPointer( ) != NULL ) + return( this->m_ImageBlender->GetWindow( ) ); + else + return( double( 0 ) ); +} + +// ------------------------------------------------------------------------- +double cpExtensions::Visualization::ImageSliceActors:: +GetLevel( ) const +{ + if( this->m_ImageBlender.GetPointer( ) != NULL ) + return( this->m_ImageBlender->GetLevel( ) ); + else + return( double( 0 ) ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +SetWindow( double w ) +{ + if( this->m_ImageBlender.GetPointer( ) != NULL ) + { + this->m_ImageBlender->SetWindow( w ); + this->Modified( ); + + } // fi +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +SetLevel( double l ) +{ + if( this->m_ImageBlender.GetPointer( ) != NULL ) + { + this->m_ImageBlender->SetLevel( l ); + this->Modified( ); + + } // fi +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +SetWindowLevel( double w, double l ) +{ + if( this->m_ImageBlender.GetPointer( ) != NULL ) + { + this->m_ImageBlender->SetWindowLevel( w, l ); + this->UpdateText( w, l ); + this->Modified( ); + + } // fi +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +ResetWindowLevel( ) +{ + std::cerr << "ACA Resetear" << std::endl; + std::exit( 1 ); } // ------------------------------------------------------------------------- int cpExtensions::Visualization::ImageSliceActors:: GetAxis( ) const { - if( this->SliceMappers.size( ) > 0 ) - return( this->SliceMappers[ 0 ]->GetOrientation( ) ); + if( this->m_ImageMapper.GetPointer( ) != NULL ) + return( this->m_ImageMapper->GetOrientation( ) ); else return( -1 ); } @@ -226,8 +719,8 @@ GetAxis( ) const int cpExtensions::Visualization::ImageSliceActors:: GetSliceNumber( ) const { - if( this->SliceMappers.size( ) > 0 ) - return( this->SliceMappers[ 0 ]->GetSliceNumber( ) ); + if( this->m_ImageMapper.GetPointer( ) != NULL ) + return( this->m_ImageMapper->GetSliceNumber( ) ); else return( -1 ); } @@ -236,8 +729,8 @@ GetSliceNumber( ) const int cpExtensions::Visualization::ImageSliceActors:: GetSliceNumberMinValue( ) const { - if( this->SliceMappers.size( ) > 0 ) - return( this->SliceMappers[ 0 ]->GetSliceNumberMinValue( ) ); + if( this->m_ImageMapper.GetPointer( ) != NULL ) + return( this->m_ImageMapper->GetSliceNumberMinValue( ) ); else return( -1 ); } @@ -246,8 +739,8 @@ GetSliceNumberMinValue( ) const int cpExtensions::Visualization::ImageSliceActors:: GetSliceNumberMaxValue( ) const { - if( this->SliceMappers.size( ) > 0 ) - return( this->SliceMappers[ 0 ]->GetSliceNumberMaxValue( ) ); + if( this->m_ImageMapper.GetPointer( ) != NULL ) + return( this->m_ImageMapper->GetSliceNumberMaxValue( ) ); else return( -1 ); } @@ -256,134 +749,271 @@ GetSliceNumberMaxValue( ) const void cpExtensions::Visualization::ImageSliceActors:: SetSliceNumber( const int& slice ) { - unsigned int nImages = this->SliceMappers.size( ); - if( nImages == 0 ) + if( this->m_ImageMapper.GetPointer( ) == NULL ) return; - // Change visualization extent - for( unsigned int i = 0; i < nImages; ++i ) - { - this->SliceMappers[ i ]->SetSliceNumber( slice ); - this->SliceMappers[ i ]->Modified( ); - this->ImageActors[ i ]->Modified( ); - this->SliceMappers[ i ]->Update( ); - - } // rof - - // Compute plane - vtkAlgorithm* algo = this->SliceMappers[ 0 ]->GetInputAlgorithm( ); - vtkInformation* info = algo->GetOutputInformation( 0 ); - int ext[ 6 ]; - double ori[ 3 ], spac[ 3 ], pos[ 3 ]; - info->Get( vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT( ), ext ); - info->Get( vtkDataObject::ORIGIN( ), ori ); - info->Get( vtkDataObject::SPACING( ), spac ); - this->SliceMappers[ 0 ]->GetSlicePlane( )->GetOrigin( pos ); - - // Prevent obscuring voxels by offsetting the plane geometry - double xbnds[ ] = - { - ori[ 0 ] + ( spac[ 0 ] * double( ext[ 0 ] ) ), - ori[ 0 ] + ( spac[ 0 ] * double( ext[ 1 ] ) ) - }; - double ybnds[ ] = - { - ori[ 1 ] + ( spac[ 1 ] * double( ext[ 2 ] ) ), - ori[ 1 ] + ( spac[ 1 ] * double( ext[ 3 ] ) ) - }; - double zbnds[ ] = + int axis = this->GetAxis( ); + double prev_pos = this->m_VisibleBounds[ axis << 1 ]; + + // Update mappers and display bounds + this->m_ImageMapper->SetSliceNumber( slice ); + this->m_ImageMapper->Modified( ); + this->m_ImageActor->Modified( ); + this->m_ImageMapper->Update( ); + + // Update display extent (this isn't done automatically) + this->m_ImageMapper->GetInput( )->GetExtent( this->m_VisibleExtent ); + this->m_VisibleExtent[ axis << 1 ] = slice; + this->m_VisibleExtent[ ( axis << 1 ) + 1 ] = slice; + this->m_ImageActor->SetDisplayExtent( this->m_VisibleExtent ); + + // Prepare plane data + this->m_ImageMapper->GetBounds( this->m_VisibleBounds ); + double x0[][ 3 ] = { - ori[ 2 ] + ( spac[ 2 ] * double( ext[ 4 ] ) ), - ori[ 2 ] + ( spac[ 2 ] * double( ext[ 5 ] ) ) + { + this->m_VisibleBounds[ 0 ], + this->m_VisibleBounds[ 2 ], + this->m_VisibleBounds[ 4 ] + }, + { + this->m_VisibleBounds[ 1 ], + this->m_VisibleBounds[ 3 ], + this->m_VisibleBounds[ 5 ] + } }; + double p0[ 2 ][ 3 ]; - if( spac[ 0 ] < double( 0 ) ) - { - double t = xbnds[ 0 ]; - xbnds[ 0 ] = xbnds[ 1 ]; - xbnds[ 1 ] = t; + vtkPlane* plane = this->m_ImageMapper->GetSlicePlane( ); + plane->GeneralizedProjectPoint( x0[ 0 ], p0[ 0 ] ); + plane->GeneralizedProjectPoint( x0[ 1 ], p0[ 1 ] ); - } // fi - if( spac[ 1 ] < double( 0 ) ) - { - double t = ybnds[ 0 ]; - ybnds[ 0 ] = ybnds[ 1 ]; - ybnds[ 1 ] = t; + this->m_VisibleBounds[ 0 ] = p0[ 0 ][ 0 ]; + this->m_VisibleBounds[ 1 ] = p0[ 1 ][ 0 ]; + this->m_VisibleBounds[ 2 ] = p0[ 0 ][ 1 ]; + this->m_VisibleBounds[ 3 ] = p0[ 1 ][ 1 ]; + this->m_VisibleBounds[ 4 ] = p0[ 0 ][ 2 ]; + this->m_VisibleBounds[ 5 ] = p0[ 1 ][ 2 ]; + double* bnds = this->m_VisibleBounds; - } // fi - if( spac[ 2 ] < double( 0 ) ) + // Configure visualization and implicit plane orientation + this->m_PlaneActor->GetProperty( )->SetRepresentationToWireframe( ); + this->m_PlaneActor->GetProperty( )->SetLineWidth( 3 ); + vtkPoints* plane_points = this->m_Plane->GetPoints( ); + plane_points->SetPoint( 0, bnds[ 0 ], bnds[ 2 ], bnds[ 4 ] ); + plane_points->SetPoint( 2, bnds[ 1 ], bnds[ 3 ], bnds[ 5 ] ); + if( axis == 0 || axis == 2 ) // YZ, x-normal { - double t = zbnds[ 0 ]; - zbnds[ 0 ] = zbnds[ 1 ]; - zbnds[ 1 ] = t; + plane_points->SetPoint( 1, bnds[ 1 ], bnds[ 2 ], bnds[ 5 ] ); + plane_points->SetPoint( 3, bnds[ 0 ], bnds[ 3 ], bnds[ 4 ] ); + if( axis == 0 ) + this->m_PlaneActor->GetProperty( )->SetColor( 1, 0, 0 ); + else + this->m_PlaneActor->GetProperty( )->SetColor( 0, 0, 1 ); + } + else if( axis == 1 ) // ZX, y-normal + { + plane_points->SetPoint( 1, bnds[ 0 ], bnds[ 2 ], bnds[ 5 ] ); + plane_points->SetPoint( 3, bnds[ 1 ], bnds[ 3 ], bnds[ 4 ] ); + this->m_PlaneActor->GetProperty( )->SetColor( 0, 1, 0 ); } // fi + this->m_Plane->Modified( ); + this->m_PlaneMapper->Modified( ); + this->m_PlaneActor->Modified( ); - 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 - { - 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 ] ); - plane_points->SetPoint( 3, pos[ 0 ], ybnds[ 0 ], zbnds[ 1 ] ); - this->PlaneActor->GetProperty( )->SetColor( 1, 0, 0 ); - } - else if( axis == 1 ) // ZX, y-normal + // Update text + this->UpdateText( ); + + // Update lines from associated slices + /* TODO + auto sIt = this->m_AssociatedSlices.begin( ); + for( ; sIt != this->m_AssociatedSlices.end( ); ++sIt ) + { + Self* slice = *sIt; + for( unsigned int id = 0; id < slice->m_AssociatedSlices.size( ); ++id ) + { + std::cout << id << std::endl; + if( slice->m_AssociatedSlices[ id ] != this ) + continue; + + std::cout << "id : " << id << std::endl; + + } // rof + + } // rof + */ + + // Update camera position + if( this->m_Window == NULL ) + return; + vtkRenderer* renderer = + this->m_Window->GetRenderers( )->GetFirstRenderer( ); + if( renderer == NULL ) + return; + vtkCamera* camera = renderer->GetActiveCamera( ); + if( camera == NULL ) + return; + double cam_pos[ 3 ]; + camera->GetPosition( cam_pos ); + cam_pos[ axis ] += this->m_VisibleBounds[ axis << 1 ] - prev_pos; + camera->SetPosition( cam_pos ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +SetSlice( double* pos ) +{ + vtkImageData* image = this->GetInputImage( 0 ); + if( image == NULL ) + return; + + int ijk[ 3 ]; + double pcoords[ 3 ]; + image->ComputeStructuredCoordinates( pos, ijk, pcoords ); + this->SetSliceNumber( ijk[ this->GetAxis( ) ] ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +UpdateText( ) +{ + if( this->m_ImageMapper.GetPointer( ) != NULL ) { - 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 ] ); - plane_points->SetPoint( 3, xbnds[ 1 ], pos[ 1 ], zbnds[ 0 ] ); - this->PlaneActor->GetProperty( )->SetColor( 0, 1, 0 ); + char axis; + int axId = this->m_ImageMapper->GetOrientation( ); + if ( axId == 0 ) axis = 'X'; + else if( axId == 1 ) axis = 'Y'; + else if( axId == 2 ) axis = 'Z'; + + std::sprintf( + this->m_TextBuffer, "Axis: %c (%d)", + axis, this->m_ImageMapper->GetSliceNumber( ) + ); } - else // XY, z-normal + else + this->m_TextBuffer[ 0 ] = '\0'; + this->m_TextActor->SetInput( this->m_TextBuffer ); + this->m_TextActor->Modified( ); + this->Modified( ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +UpdateText( double pos[ 3 ] ) +{ + if( this->m_ImageMapper.GetPointer( ) != NULL ) { - 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 ] ); - plane_points->SetPoint( 3, xbnds[ 0 ], ybnds[ 1 ], pos[ 2 ] ); - this->PlaneActor->GetProperty( )->SetColor( 0, 0, 1 ); + char axis; + int axId = this->m_ImageMapper->GetOrientation( ); + if ( axId == 0 ) axis = 'X'; + else if( axId == 1 ) axis = 'Y'; + else if( axId == 2 ) axis = 'Z'; + int slice = this->GetSliceNumber( ); - } // fi - this->PlaneSource->Modified( ); - this->PlaneMapper->Modified( ); - this->PlaneActor->Modified( ); + vtkImageData* image = this->GetInputImage( 0 ); + int ijk[ 3 ]; + double pcoords[ 3 ]; + image->ComputeStructuredCoordinates( pos, ijk, pcoords ); + ijk[ axId ] = slice; + + int ext[ 6 ]; + image->GetExtent( ext ); + if( + ext[ 0 ] <= ijk[ 0 ] && ijk[ 0 ] <= ext[ 1 ] && + ext[ 2 ] <= ijk[ 1 ] && ijk[ 1 ] <= ext[ 3 ] && + ext[ 4 ] <= ijk[ 2 ] && ijk[ 2 ] <= ext[ 5 ] + ) + { + 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->m_TextBuffer, "Axis: %c (%d)\nPixel %s", + axis, slice, str.str( ).c_str( ) + ); + + } // fi + } + else + this->m_TextBuffer[ 0 ] = '\0'; + this->m_TextActor->SetInput( this->m_TextBuffer ); + this->m_TextActor->Modified( ); this->Modified( ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -UpdateText( ) +UpdateText( const double& w, const double& l ) { - if( this->SliceMappers.size( ) > 0 ) + if( this->m_ImageMapper.GetPointer( ) != NULL ) { char axis; - int axId = this->SliceMappers[ 0 ]->GetOrientation( ); + int axId = this->m_ImageMapper->GetOrientation( ); if ( axId == 0 ) axis = 'X'; else if( axId == 1 ) axis = 'Y'; else if( axId == 2 ) axis = 'Z'; std::sprintf( - this->TextBuffer, "Axis: %c (%d)", - axis, this->SliceMappers[ 0 ]->GetSliceNumber( ) + this->m_TextBuffer, "Axis: %c (%d)\nW/L (%.2f/%.2f)", + axis, this->m_ImageMapper->GetSliceNumber( ), w, l ); } else - this->TextBuffer[ 0 ] = '\0'; - this->TextActor->SetInput( this->TextBuffer ); - this->TextActor->Modified( ); + this->m_TextBuffer[ 0 ] = '\0'; + this->m_TextActor->SetInput( this->m_TextBuffer ); + this->m_TextActor->Modified( ); this->Modified( ); } +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +Render( const double& t ) +{ + if( this->m_Window != NULL ) + { + vtkRenderer* renderer = + this->m_Window->GetRenderers( )->GetFirstRenderer( ); + if( renderer != NULL ) + renderer->SetAllocatedRenderTime( t ); + this->m_Window->Render( ); + + } // fi +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +ResetCamera( ) +{ + if( this->m_Window == NULL ) + return; + vtkRenderer* renderer = + this->m_Window->GetRenderers( )->GetFirstRenderer( ); + if( renderer != NULL ) + renderer->ResetCamera( this->m_VisibleBounds ); +} + // ------------------------------------------------------------------------- cpExtensions::Visualization::ImageSliceActors:: ImageSliceActors( ) - : Superclass( ) + : Superclass( ), + m_Window( NULL ), + m_Interpolate( false ) { this->Clear( ); + this->_ConfigureStyle( ); } // ------------------------------------------------------------------------- @@ -392,4 +1022,199 @@ cpExtensions::Visualization::ImageSliceActors:: { } +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +_ConfigureStyle( ) +{ + // Connect this view with a controller + this->m_Style = vtkSmartPointer< TStyle >::New( ); + this->m_Style->AddMouseMoveCommand( Self::_MouseMoveCommand, this ); + this->m_Style->AddMouseClickCommand( Self::_MouseClickCommand, this ); + this->m_Style->AddMouseWheelCommand( Self::_MouseWheelCommand, this ); + this->m_Style->AddKeyCommand( Self::_KeyCommand, this ); + this->m_Style->AddEnterCommand( Self::_EnterCommand, this ); + this->m_Style->AddLeaveCommand( Self::_LeaveCommand, this ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +_MouseMoveCommand( + void* data, const TStyle::ButtonID& btn, int* idx, double* pos, + bool alt, bool ctr, bool sft + ) +{ + ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data ); + if( actors == NULL ) + return; + + if( btn == TStyle::ButtonID_None ) + { + // Just show the pixel information + actors->SetCursor( pos ); + actors->UpdateText( pos ); + actors->Render( 1e-3 ); + } + else if( btn == TStyle::ButtonID_Left ) + { + if( !alt && ctr && !sft ) + { + // Interactively move slices + auto i = actors->m_SlicesCommands.begin( ); + for( ; i != actors->m_SlicesCommands.end( ); ++i ) + i->first( pos, actors->GetAxis( ), i->second ); + actors->Render( 1e-3 ); + + } // fi + } + else if( btn == TStyle::ButtonID_Right ) + { + if( !alt && !ctr && sft ) + { + // Change image window level + double bounds[ 6 ]; + actors->m_ImageMapper->GetBounds( bounds ); + + int a0 = actors->GetAxis( ); + int a1 = ( a0 + 1 ) % 3; + int a2 = ( a0 + 2 ) % 3; + double dx = pos[ a1 ] - actors->m_StartWindowLevelPos[ a1 ]; + double dy = pos[ a2 ] - actors->m_StartWindowLevelPos[ a2 ]; + dx /= bounds[ ( a1 << 1 ) + 1 ] - bounds[ a1 << 1 ]; + dy /= bounds[ ( a2 << 1 ) + 1 ] - bounds[ a2 << 1 ]; + + dx *= actors->m_StartWindowLevel[ 0 ]; + dy *= actors->m_StartWindowLevel[ 1 ]; + dx += actors->m_StartWindowLevel[ 0 ]; + dy += actors->m_StartWindowLevel[ 1 ]; + actors->SetWindowLevel( dx, dy ); + actors->Render( 1e-3 ); + + // Associate objects + auto i = actors->m_WindowLevelCommands.begin( ); + for( ; i != actors->m_WindowLevelCommands.end( ); ++i ) + i->first( dx, dy, i->second ); + + } // fi + + } // fi +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +_MouseClickCommand( + void* data, const TStyle::ButtonID& btn, int* idx, double* pos, + bool alt, bool ctr, bool sft + ) +{ + ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data ); + if( actors == NULL ) + return; + + actors->m_StartWindowLevelPos[ 0 ] = pos[ 0 ]; + actors->m_StartWindowLevelPos[ 1 ] = pos[ 1 ]; + actors->m_StartWindowLevelPos[ 2 ] = pos[ 2 ]; + actors->m_StartWindowLevel[ 0 ] = actors->GetWindow( ); + actors->m_StartWindowLevel[ 1 ] = actors->GetLevel( ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +_MouseWheelCommand( + void* data, const int& dir, + bool alt, bool ctr, bool sft + ) +{ + ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data ); + if( actors == NULL ) + return; + + if( !alt && !ctr ) + { + int slice = actors->GetSliceNumber( ) + ( dir * ( ( sft )? 10: 1 ) ); + if( slice < actors->GetSliceNumberMinValue( ) ) + slice = actors->GetSliceNumberMinValue( ); + if( slice > actors->GetSliceNumberMaxValue( ) ) + slice = actors->GetSliceNumberMaxValue( ); + actors->SetSliceNumber( slice ); + + auto a = actors->m_AssociatedSlices.begin( ); + for( ; a != actors->m_AssociatedSlices.end( ); ++a ) + { + ( *a )->SetSliceNumber( slice ); + ( *a )->Render( 1e-3 ); + + } // rof + actors->Render( 1e-3 ); + + // Associate objects + auto i = actors->m_RenderCommands.begin( ); + for( ; i != actors->m_RenderCommands.end( ); ++i ) + i->first( i->second ); + + } // fi +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +_KeyCommand( void* data, const char& key ) +{ + ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data ); + if( actors == NULL ) + return; + + switch( key ) + { + case 'r': case 'R': + { + actors->ResetCamera( ); + actors->Render( 1e-3 ); + + // Associate objects + auto i = actors->m_RenderCommands.begin( ); + for( ; i != actors->m_RenderCommands.end( ); ++i ) + i->first( i->second ); + } + break; + case 'w': case 'W': + { + actors->ResetWindowLevel( ); + actors->Render( 1e-3 ); + + // Associate objects + auto i = actors->m_RenderCommands.begin( ); + for( ; i != actors->m_RenderCommands.end( ); ++i ) + i->first( i->second ); + } + break; + default: + break; + } // hctiws +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +_EnterCommand( void* data ) +{ + ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data ); + if( actors == NULL ) + return; + + actors->ResetCursor( ); + actors->m_CursorActor->VisibilityOn( ); + actors->Render( 1e-3 ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +_LeaveCommand( void* data ) +{ + ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data ); + if( actors == NULL ) + return; + + actors->ResetCursor( ); + actors->m_CursorActor->VisibilityOff( ); + actors->Render( 1e-3 ); +} + // eof - $RCSfile$