X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpExtensions%2FVisualization%2FImageSliceActors.cxx;h=558fed75946f826b64e4d84f472022cf68a5ac0e;hb=9586180ab9da1ba2778099482b0231b933192719;hp=5722c583d608b0159ebe9537e61ca5fcbcb84909;hpb=f2f39f66027a98bd8dac50bade5618e0136bbefa;p=cpPlugins.git diff --git a/lib/cpExtensions/Visualization/ImageSliceActors.cxx b/lib/cpExtensions/Visualization/ImageSliceActors.cxx index 5722c58..558fed7 100644 --- a/lib/cpExtensions/Visualization/ImageSliceActors.cxx +++ b/lib/cpExtensions/Visualization/ImageSliceActors.cxx @@ -1,8 +1,10 @@ #include +#include #include #include +#include #include #include #include @@ -10,8 +12,12 @@ #include #include #include +#include +#include +#include #include #include +#include // ------------------------------------------------------------------------- cpExtensions::Visualization::ImageSliceActors* @@ -23,23 +29,64 @@ New( ) // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -AddInputConnection( vtkAlgorithmOutput* aout, int axis ) +AddInputConnection( vtkAlgorithmOutput* aout, int axis, LUTType lut ) { + vtkImageData* data = dynamic_cast< vtkImageData* >( + aout->GetProducer( )->GetOutputDataObject( aout->GetIndex( ) ) + ); + if( data == NULL ) + return; + + vtkImageMapToColors* new_map = + dynamic_cast< vtkImageMapToColors* >( aout->GetProducer( ) ); + if( new_map == NULL ) + { + // Configure LUT + this->_ConfigureNewLUT( data, lut ); + new_map = *( this->ImageMaps.rbegin( ) ); + if( new_map != NULL ) + { + new_map->SetInputConnection( aout ); + new_map->Update( ); + + } // fi + } + else + this->ImageMaps.push_back( new_map ); + + // Create mapper and actors vtkSmartPointer< vtkImageSliceMapper > mapper = vtkSmartPointer< vtkImageSliceMapper >::New( ); + if( new_map != NULL ) + mapper->SetInputConnection( new_map->GetOutputPort( ) ); + else + mapper->SetInputConnection( aout ); this->SliceMappers.push_back( mapper ); - mapper->SetInputConnection( aout ); this->_ConfigureNewInput( axis ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -AddInputData( vtkImageData* data, int axis ) +AddInputData( vtkImageData* data, int axis, LUTType lut ) { + // Configure LUT + this->_ConfigureNewLUT( data, lut ); + vtkImageMapToColors* new_map = *( this->ImageMaps.rbegin( ) ); + if( new_map != NULL ) + { + new_map->SetInputData( data ); + new_map->Update( ); + + } // fi + + // Create mapper and actors vtkSmartPointer< vtkImageSliceMapper > mapper = vtkSmartPointer< vtkImageSliceMapper >::New( ); + if( new_map != NULL ) + mapper->SetInputConnection( new_map->GetOutputPort( ) ); + else + mapper->SetInputData( data ); this->SliceMappers.push_back( mapper ); - mapper->SetInputData( data ); this->_ConfigureNewInput( axis ); } @@ -51,11 +98,16 @@ Clear( ) this->RemoveAllItems( ); // Delete all images + this->ImageMaps.clear( ); this->SliceMappers.clear( ); this->ImageActors.clear( ); + this->AssociatedSlices.clear( ); this->AssociatedActors.clear( ); // Reconfigure unique objects + this->Cursor = vtkSmartPointer< vtkPolyData >::New( ); + this->CursorMapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); + this->CursorActor = vtkSmartPointer< vtkActor >::New( ); this->PlaneFunction = vtkSmartPointer< vtkPlane >::New( ); this->PlaneSource = vtkSmartPointer< vtkPolyData >::New( ); this->PlaneMapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); @@ -64,6 +116,35 @@ Clear( ) this->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->Cursor->SetPoints( cursor_points ); + this->Cursor->SetLines( cursor_lines ); + this->CursorMapper->SetInputData( this->Cursor ); + this->CursorActor->SetMapper( this->CursorMapper ); + vtkSmartPointer< vtkPoints > plane_points = vtkSmartPointer< vtkPoints >::New( ); vtkSmartPointer< vtkCellArray > plane_lines = @@ -100,6 +181,23 @@ Clear( ) coord->SetValue( 0.01, 0.01 ); } +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +AssociateSlice( Self* other ) +{ + this->AssociatedSlices.push_back( other ); + this->Modified( ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +SetSlicesCommand( TCursorCommand cmd, void* data ) +{ + this->SlicesCommand = cmd; + this->SlicesData = data; + this->Modified( ); +} + // ------------------------------------------------------------------------- vtkInteractorStyle* cpExtensions::Visualization::ImageSliceActors:: GetStyle( ) @@ -116,26 +214,87 @@ GetStyle( ) const // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -PushActorsInto( vtkRenderer* renderer ) +PushActorsInto( vtkRenderWindow* window, bool force_style ) { - 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( ); + vtkRenderWindowInteractor* rwi = window->GetInteractor( ); + vtkRenderer* renderer = window->GetRenderers( )->GetFirstRenderer( ); + + // Update style + if( rwi != NULL && force_style ) + { + if( rwi->GetInteractorStyle( ) != this->Style.GetPointer( ) ) + { + rwi->SetInteractorStyle( this->Style ); + + } // fi + + } // fi + + if( renderer != NULL ) + { + // Update actors + unsigned int N = this->GetNumberOfImageActors( ); + for( unsigned int n = 0; n < N; ++n ) + renderer->AddActor( this->GetImageActor( n ) ); + renderer->AddActor( this->CursorActor ); + renderer->AddActor( this->PlaneActor ); + renderer->AddActor( this->TextActor ); + renderer->Modified( ); + + // Configure camera + vtkCamera* camera = renderer->GetActiveCamera( ); + if( camera == NULL ) + return; + + // Parallel projections are better when displaying 2D images + if( force_style ) + { + 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( 1 ), double( 0 ) ); + } + 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 + renderer->ResetCamera( ); + rwi->Render( ); + + } // fi } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -PopActorsFrom( vtkRenderer* renderer ) +PopActorsFrom( vtkRenderWindow* window ) { - 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( ); + vtkRenderWindowInteractor* rwi = window->GetInteractor( ); + vtkRenderer* renderer = window->GetRenderers( )->GetFirstRenderer( ); + + if( renderer != NULL ) + { + // Update actors + unsigned int N = this->GetNumberOfImageActors( ); + for( unsigned int n = 0; n < N; ++n ) + renderer->RemoveActor( this->GetImageActor( n ) ); + renderer->RemoveActor( this->CursorActor ); + renderer->RemoveActor( this->PlaneActor ); + renderer->RemoveActor( this->TextActor ); + renderer->Modified( ); + + } // fi } // ------------------------------------------------------------------------- @@ -273,6 +432,201 @@ GetDisplayBounds( double bounds[ 6 ] ) const this->ImageActors[ 0 ]->GetDisplayBounds( bounds ); } +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +ResetCursor( ) +{ + vtkPoints* points = this->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->Cursor->Modified( ); + this->CursorMapper->Modified( ); + this->CursorActor->Modified( ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +SetCursor( double pos[ 3 ] ) +{ + if( this->SliceMappers.size( ) == 0 ) + 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; + + double bounds[ 6 ]; + this->SliceMappers[ 0 ]->GetInput( )->GetBounds( bounds ); + + 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->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->Cursor->Modified( ); + this->CursorMapper->Modified( ); + this->CursorActor->Modified( ); +} + +// ------------------------------------------------------------------------- +vtkImageMapToColors* cpExtensions::Visualization::ImageSliceActors:: +GetImageMap( unsigned int id ) +{ + if( id < this->ImageMaps.size( ) ) + return( this->ImageMaps[ id ].GetPointer( ) ); + else + return( NULL ); +} + +// ------------------------------------------------------------------------- +const vtkImageMapToColors* cpExtensions::Visualization::ImageSliceActors:: +GetImageMap( unsigned int id ) const +{ + if( id < this->ImageMaps.size( ) ) + return( this->ImageMaps[ id ].GetPointer( ) ); + else + return( NULL ); +} + +// ------------------------------------------------------------------------- +double cpExtensions::Visualization::ImageSliceActors:: +GetWindow( unsigned int id ) const +{ + if( this->ImageMaps[ id ].GetPointer( ) != NULL ) + { + vtkWindowLevelLookupTable* lut = + dynamic_cast< vtkWindowLevelLookupTable* >( + this->ImageMaps[ id ]->GetLookupTable( ) + ); + if( lut != NULL ) + return( lut->GetWindow( ) ); + else + return( double( 0 ) ); + } + else + return( double( 0 ) ); +} + +// ------------------------------------------------------------------------- +double cpExtensions::Visualization::ImageSliceActors:: +GetLevel( unsigned int id ) const +{ + if( this->ImageMaps[ id ].GetPointer( ) != NULL ) + { + vtkWindowLevelLookupTable* lut = + dynamic_cast< vtkWindowLevelLookupTable* >( + this->ImageMaps[ id ]->GetLookupTable( ) + ); + if( lut != NULL ) + return( lut->GetLevel( ) ); + else + return( double( 0 ) ); + } + else + return( double( 0 ) ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +SetWindow( unsigned int id, double w ) +{ + if( this->ImageMaps[ id ].GetPointer( ) != NULL ) + { + vtkWindowLevelLookupTable* lut = + dynamic_cast< vtkWindowLevelLookupTable* >( + this->ImageMaps[ id ]->GetLookupTable( ) + ); + if( lut != NULL ) + { + lut->SetWindow( w ); + lut->Build( ); + this->ImageMaps[ id ]->Modified( ); + this->Modified( ); + + } // fi + + } // fi +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +SetLevel( unsigned int id, double l ) +{ + if( this->ImageMaps[ id ].GetPointer( ) != NULL ) + { + vtkWindowLevelLookupTable* lut = + dynamic_cast< vtkWindowLevelLookupTable* >( + this->ImageMaps[ id ]->GetLookupTable( ) + ); + if( lut != NULL ) + { + lut->SetLevel( l ); + lut->Build( ); + this->ImageMaps[ id ]->Modified( ); + this->Modified( ); + + } // fi + + } // fi +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +SetWindowLevel( unsigned int id, double w, double l ) +{ + if( this->ImageMaps[ id ].GetPointer( ) != NULL ) + { + vtkWindowLevelLookupTable* lut = + dynamic_cast< vtkWindowLevelLookupTable* >( + this->ImageMaps[ id ]->GetLookupTable( ) + ); + if( lut != NULL ) + { + lut->SetWindow( w ); + lut->SetLevel( l ); + lut->Build( ); + this->ImageMaps[ id ]->Modified( ); + this->UpdateText( w, l ); + this->Modified( ); + + } // fi + + } // fi +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +ResetWindowLevel( unsigned int id ) +{ +} + // ------------------------------------------------------------------------- int cpExtensions::Visualization::ImageSliceActors:: GetAxis( ) const @@ -447,8 +801,38 @@ SetSliceNumber( const int& slice ) // Update text this->UpdateText( ); + + // Associated slices + for( unsigned int i = 0; i < this->AssociatedSlices.size( ); ++i ) + if( this->AssociatedSlices[ i ]->GetAxis( ) == this->GetAxis( ) ) + this->AssociatedSlices[ i ]->SetSliceNumber( slice ); } +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +SetSlice( double* pos ) +{ + vtkImageData* image; + if( this->ImageMaps[ 0 ] != NULL ) + image = + dynamic_cast< vtkImageData* >( this->ImageMaps[ 0 ]->GetInput( ) ); + else + image = this->SliceMappers[ 0 ]->GetInput( ); + + int ijk[ 3 ]; + double pcoords[ 3 ]; + image->ComputeStructuredCoordinates( pos, ijk, pcoords ); + this->SetSliceNumber( ijk[ this->GetAxis( ) ] ); +} + +// ------------------------------------------------------------------------- +/* TODO + void cpExtensions::Visualization::ImageSliceActors:: + SetSlices( double pos[ 3 ] ) + { + } +*/ + // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: UpdateText( ) @@ -484,12 +868,27 @@ UpdateText( double pos[ 3 ] ) if ( axId == 0 ) axis = 'X'; else if( axId == 1 ) axis = 'Y'; else if( axId == 2 ) axis = 'Z'; + int slice = this->GetSliceNumber( ); - vtkImageData* image = this->SliceMappers[ 0 ]->GetInput( ); + vtkImageData* image; + if( this->ImageMaps[ 0 ] != NULL ) + image = + dynamic_cast< vtkImageData* >( this->ImageMaps[ 0 ]->GetInput( ) ); + else + image = this->SliceMappers[ 0 ]->GetInput( ); 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; @@ -498,9 +897,7 @@ UpdateText( double pos[ 3 ] ) << "," << ijk[ 1 ] << "," << ijk[ 2 ] << "]=("; str << - image->GetScalarComponentAsFloat( - ijk[ 0 ], ijk[ 1 ], ijk[ 2 ], 0 - ); + image->GetScalarComponentAsFloat( ijk[ 0 ], ijk[ 1 ], ijk[ 2 ], 0 ); for( int n = 1; n < nScl; ++n ) str << " " @@ -510,9 +907,7 @@ UpdateText( double pos[ 3 ] ) str << ")"; std::sprintf( this->TextBuffer, "Axis: %c (%d) | Pixel %s", - axis, - this->SliceMappers[ 0 ]->GetSliceNumber( ), - str.str( ).c_str( ) + axis, slice, str.str( ).c_str( ) ); } // fi @@ -554,6 +949,10 @@ ImageSliceActors( ) : Superclass( ), Interpolate( false ) { + this->Clear( ); + + this->SlicesCommand = NULL; + // Connect this view with a controller this->Style = vtkSmartPointer< ImageInteractorStyle >::New( ); this->Style->AssociateView( this ); @@ -562,8 +961,6 @@ ImageSliceActors( ) this->Style->SetMouseDoubleClickCommand( Self::_MouseDoubleClickCommand ); this->Style->SetMouseWheelCommand( Self::_MouseWheelCommand ); this->Style->SetKeyCommand( Self::_KeyCommand ); - - this->Clear( ); } // ------------------------------------------------------------------------- @@ -572,6 +969,80 @@ cpExtensions::Visualization::ImageSliceActors:: { } +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +_ConfigureNewLUT( vtkImageData* data, LUTType lut_t ) +{ + static const double _0 = double( 0 ); + static const double _1 = double( 1 ); + static const double _2 = double( 2 ); + static const double _4 = double( 4 ); + static const double _6 = double( 6 ); + static const double _OPACITY = double( 0.6 ); + + // Configure LUT + vtkSmartPointer< vtkImageMapToColors > new_map( NULL ); + if( data->GetNumberOfScalarComponents( ) == 1 ) + { + double range[ 2 ]; + data->GetScalarRange( range ); + if( lut_t == Self::LUTType_WindowLevel ) + { + vtkSmartPointer< vtkWindowLevelLookupTable > lut = + vtkSmartPointer< vtkWindowLevelLookupTable >::New( ); + lut->SetScaleToLinear( ); + lut->SetTableRange( range ); + lut->SetWindow( range[ 1 ] - range[ 0 ] ); + lut->SetLevel( ( range[ 1 ] + range[ 0 ] ) / double( 2 ) ); + lut->Build( ); + + new_map = vtkSmartPointer< vtkImageMapToColors >::New( ); + new_map->SetLookupTable( lut ); + } + else if( lut_t == LUTType_Colors ) + { + // Get HSV from display color + double r = 1, g = 0, b = 0; + double cmax = ( r > g )? r: g; cmax = ( b > cmax )? b: cmax; + double cmin = ( r < g )? r: g; cmin = ( b < cmin )? b: cmin; + double d = cmax - cmin; + + double saturation = ( std::fabs( cmax ) > _0 )? d / cmax: _0; + double value = cmax; + double hue = _0; + if( d > _0 ) + { + if( r == cmax ) + hue = std::fmod( ( g - b ) / d, _6 ); + else if( g == cmax ) + hue = ( ( b - r ) / d ) + _2; + else if( b == cmax ) + hue = ( ( r - g ) / d ) + _4; + hue *= _1 / _6; + + } // fi + + // Define new lookup table + vtkSmartPointer< vtkLookupTable > lut = + vtkSmartPointer< vtkLookupTable >::New( ); + lut->SetScaleToLinear( ); + lut->SetNanColor( _0, _0, _0, _0 ); + lut->SetTableRange( range[ 0 ], range[ 1 ] ); + lut->SetAlphaRange( _0, _OPACITY ); + lut->SetHueRange( _0, hue ); + lut->SetSaturationRange( _0, saturation ); + lut->SetValueRange( _0, value ); + lut->Build( ); + + new_map = vtkSmartPointer< vtkImageMapToColors >::New( ); + new_map->SetLookupTable( lut ); + + } // fi + + } // fi + this->ImageMaps.push_back( new_map ); +} + // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: _ConfigureNewInput( int axis ) @@ -596,8 +1067,9 @@ _ConfigureNewInput( int axis ) if( nImages == 0 ) { - this->AddItem( this->TextActor ); + this->AddItem( this->CursorActor ); this->AddItem( this->PlaneActor ); + this->AddItem( this->TextActor ); this->Style->AssociateImageActor( actor ); } // fi @@ -626,12 +1098,37 @@ _MouseMoveCommand( } else if( btn == ImageInteractorStyle::ButtonID_Left ) { + if( !alt && ctr && !sft && actors->SlicesCommand != NULL ) + actors->SlicesCommand( pos, actors->GetAxis( ), actors->SlicesData ); } else if( btn == ImageInteractorStyle::ButtonID_Middle ) { } else if( btn == ImageInteractorStyle::ButtonID_Right ) { + if( !alt && !ctr && sft ) + { + double bounds[ 6 ]; + actors->SliceMappers[ 0 ]->GetBounds( bounds ); + + int a0 = actors->GetAxis( ); + int a1 = ( a0 + 1 ) % 3; + int a2 = ( a0 + 2 ) % 3; + double dx = pos[ a1 ] - actors->StartWindowLevelPos[ a1 ]; + double dy = pos[ a2 ] - actors->StartWindowLevelPos[ a2 ]; + dx /= bounds[ ( a1 << 1 ) + 1 ] - bounds[ a1 << 1 ]; + dy /= bounds[ ( a2 << 1 ) + 1 ] - bounds[ a2 << 1 ]; + + dx *= actors->StartWindowLevel[ 0 ]; + dy *= actors->StartWindowLevel[ 1 ]; + actors->SetWindowLevel( + 0, + actors->StartWindowLevel[ 0 ] + dx, + actors->StartWindowLevel[ 1 ] + dy + ); + + } // fi + } // fi } @@ -643,6 +1140,15 @@ _MouseClickCommand( bool alt, bool ctr, bool sft ) { + ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data ); + if( actors == NULL ) + return; + + actors->StartWindowLevelPos[ 0 ] = pos[ 0 ]; + actors->StartWindowLevelPos[ 1 ] = pos[ 1 ]; + actors->StartWindowLevelPos[ 2 ] = pos[ 2 ]; + actors->StartWindowLevel[ 0 ] = actors->GetWindow( 0 ); + actors->StartWindowLevel[ 1 ] = actors->GetLevel( 0 ); } // ------------------------------------------------------------------------- @@ -653,6 +1159,23 @@ _MouseDoubleClickCommand( bool alt, bool ctr, bool sft ) { + ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data ); + if( actors == NULL ) + return; + + if( btn == ImageInteractorStyle::ButtonID_Left ) + { + if( !alt && !ctr && !sft ) + actors->SetCursor( pos ); + else if( !alt && ctr && !sft && actors->SlicesCommand != NULL ) + actors->SlicesCommand( pos, actors->GetAxis( ), actors->SlicesData ); + } + else if( btn == ImageInteractorStyle::ButtonID_Middle ) + { + } + else if( btn == ImageInteractorStyle::ButtonID_Right ) + { + } // fi } // ------------------------------------------------------------------------- @@ -662,6 +1185,19 @@ _MouseWheelCommand( const int& dir, bool alt, bool ctr, bool sft ) { + ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data ); + if( actors == NULL ) + return; + + if( !alt && !ctr && !sft ) + { + actors->SetSliceNumber( actors->GetSliceNumber( ) + dir ); + } + else if( !alt && !ctr && sft ) + { + actors->SetSliceNumber( actors->GetSliceNumber( ) + ( dir * 10 ) ); + + } // fi } // -------------------------------------------------------------------------