X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpExtensions%2FVisualization%2FImageSliceActors.cxx;h=88a0a4bc7d8a3c6cb47c0bd31239bec3781ced68;hb=dbc5b32e13cf4a299ce29a5666a8e0a2ff5e62a8;hp=17dc4c45035be5b973135d00e93a81f6266d6ac6;hpb=fdd4f2cec18107de380ebd350cb1019eed7c294c;p=cpPlugins.git diff --git a/lib/cpExtensions/Visualization/ImageSliceActors.cxx b/lib/cpExtensions/Visualization/ImageSliceActors.cxx index 17dc4c4..88a0a4b 100644 --- a/lib/cpExtensions/Visualization/ImageSliceActors.cxx +++ b/lib/cpExtensions/Visualization/ImageSliceActors.cxx @@ -1,23 +1,29 @@ #include -#include +#include #include #include #include #include #include -#include -#include +#include #include #include #include #include #include #include -#include #include -#include + +// ------------------------------------------------------------------------- +double cpExtensions::Visualization::ImageSliceActors:: +m_PlaneColors[ 3 ][ 3 ] = +{ + { 1, 0, 0 }, + { 0, 1, 0 }, + { 0, 0, 1 } +}; // ------------------------------------------------------------------------- cpExtensions::Visualization::ImageSliceActors* @@ -29,145 +35,70 @@ New( ) // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -AddSlicesCommand( TSlicesCommand command, void* data ) -{ - if( command != NULL ) - { - this->m_SlicesCommands[ command ] = data; - this->Modified( ); - - } // fi -} - -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::ImageSliceActors:: -AddWindowLevelCommand( TWindowLevelCommand command, void* data ) -{ - if( command != NULL ) - { - this->m_WindowLevelCommands[ command ] = data; - this->Modified( ); - - } // fi -} - -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::ImageSliceActors:: -AddRenderCommand( TVoidCommand command, void* data ) -{ - if( command != NULL ) - { - this->m_RenderCommands[ command ] = data; - this->Modified( ); - - } // fi -} - -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::ImageSliceActors:: -RemoveSlicesCommand( TSlicesCommand command ) -{ - auto i = this->m_SlicesCommands.find( command ); - if( i != this->m_SlicesCommands.end( ) ) - { - this->m_SlicesCommands.erase( i ); - this->Modified( ); - - } // fi -} - -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::ImageSliceActors:: -RemoveWindowLevelCommand( TWindowLevelCommand command ) -{ - auto i = this->m_WindowLevelCommands.find( command ); - if( i != this->m_WindowLevelCommands.end( ) ) - { - this->m_WindowLevelCommands.erase( i ); - this->Modified( ); - - } // fi +SetAxis( int axis ) +{ + this->m_ImageMapper->SetOrientation( axis ); + this->m_BlenderMapper->SetOrientation( axis ); + this->m_ImageMapper->Update( ); + this->m_BlenderMapper->Update( ); + this->SetSliceNumber( this->GetSliceNumberMinValue( ) ); + this->m_ImageActor->Modified( ); + this->m_BlenderActor->Modified( ); + this->Modified( ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -RemoveRenderCommand( TVoidCommand command ) +SetInputConnection( vtkAlgorithmOutput* aout ) { - auto i = this->m_RenderCommands.find( command ); - if( i != this->m_RenderCommands.end( ) ) - { - this->m_RenderCommands.erase( i ); - this->Modified( ); + // Get input vtkImageData + if( aout == NULL ) + return; - } // fi + // Create mapper and actors + this->m_ImageMapper->SetInputConnection( aout ); + this->_ConfigureInputImage( ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -AddInputConnection( vtkAlgorithmOutput* aout, int axis ) +SetInputImage( vtkImageData* data ) { // Get input vtkImageData - if( aout == NULL ) - return; - vtkAlgorithm* producer = aout->GetProducer( ); - vtkImageData* data = dynamic_cast< vtkImageData* >( - producer->GetOutputDataObject( aout->GetIndex( ) ) - ); if( data == NULL ) return; - // Try to infere if input comes from a color mapping filter - vtkImageMapToColors* new_map = - dynamic_cast< vtkImageMapToColors* >( producer ); - if( new_map == NULL ) - { - // Configure LUT, if possible (NULL is returned if not) - this->_ConfigureNewLUT( data ); - new_map = *( this->m_ImageMaps.rbegin( ) ); - if( new_map != NULL ) - { - new_map->SetInputConnection( aout ); - new_map->Update( ); - - } // fi - } - else - this->m_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->m_SliceMappers.push_back( mapper ); - this->_ConfigureNewInput( axis ); + this->m_ImageMapper->SetInputData( data ); + this->_ConfigureInputImage( ); } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::ImageSliceActors:: -AddInputData( vtkImageData* data, int axis ) +int cpExtensions::Visualization::ImageSliceActors:: +AddBinaryConnection( + vtkAlgorithmOutput* aout, + const double& r, const double& g, const double& b + ) { - // Configure LUT, if possible (NULL is returned if not) - this->_ConfigureNewLUT( data ); - vtkImageMapToColors* new_map = *( this->m_ImageMaps.rbegin( ) ); - if( new_map != NULL ) - { - new_map->SetInputData( data ); - new_map->Update( ); - - } // fi + if( aout == NULL ) + return( -1 ); + this->m_Blender->AddInputConnection( aout ); + this->_ConfigureBinaryImage( r, g, b ); + return( this->m_Blender->GetNumberOfInputs( ) - 1 ); +} - // Create mapper and actors - vtkSmartPointer< vtkImageSliceMapper > mapper = - vtkSmartPointer< vtkImageSliceMapper >::New( ); - if( new_map != NULL ) - mapper->SetInputConnection( new_map->GetOutputPort( ) ); - else - mapper->SetInputData( data ); - this->m_SliceMappers.push_back( mapper ); - this->_ConfigureNewInput( axis ); +// ------------------------------------------------------------------------- +int cpExtensions::Visualization::ImageSliceActors:: +AddBinaryImage( + vtkImageData* data, + const double& r, const double& g, const double& b + ) +{ + if( data == NULL ) + return( -1 ); + this->m_Blender->AddInputData( data ); + this->_ConfigureBinaryImage( r, g, b ); + return( this->m_Blender->GetNumberOfInputs( ) - 1 ); } // ------------------------------------------------------------------------- @@ -177,23 +108,28 @@ Clear( ) // Unbind from container this->RemoveAllItems( ); - // Delete all images - this->m_ImageMaps.clear( ); - this->m_SliceMappers.clear( ); - this->m_ImageActors.clear( ); - - // Reconfigure unique objects - this->m_Cursor = vtkSmartPointer< vtkPolyData >::New( ); - this->m_CursorMapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); - this->m_CursorActor = vtkSmartPointer< vtkActor >::New( ); - this->m_PlaneFunction = vtkSmartPointer< vtkPlane >::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'; + // Filters and mappers + this->m_ImageMapper = vtkSmartPointer< vtkImageSliceMapper >::New( ); + this->m_ImageActor = vtkSmartPointer< vtkImageActor >::New( ); + this->m_Blender = vtkSmartPointer< TBlender >::New( ); + this->m_BlenderMapper = vtkSmartPointer< vtkImageSliceMapper >::New( ); + this->m_BlenderLUT = vtkSmartPointer< vtkLookupTable >::New( ); + this->m_BlenderActor = vtkSmartPointer< vtkImageActor >::New( ); - // Unique objects configuration + this->m_ImageActor->SetMapper( this->m_ImageMapper ); + this->m_BlenderMapper-> + SetInputConnection( this->m_Blender->GetOutputPort( ) ); + + this->m_BlenderLUT->SetNumberOfTableValues( 1 ); + this->m_BlenderLUT->SetTableRange( 0, 1 ); + this->m_BlenderLUT->SetTableValue( 0, 0, 0, 0, 0 ); + this->m_BlenderLUT->Build( ); + + this->m_BlenderActor->SetMapper( this->m_BlenderMapper ); + this->m_BlenderActor->GetProperty( )->SetLookupTable( this->m_BlenderLUT ); + this->m_BlenderActor->GetProperty( )->UseLookupTableScalarRangeOn( ); + + // White cursor vtkSmartPointer< vtkPoints > cursor_points = vtkSmartPointer< vtkPoints >::New( ); vtkSmartPointer< vtkCellArray > cursor_lines = @@ -202,32 +138,70 @@ Clear( ) 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 = vtkSmartPointer< vtkPolyData >::New( ); + this->m_CursorMapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); + this->m_CursorActor = vtkSmartPointer< vtkActor >::New( ); + 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 ); + this->m_CursorActor->GetProperty( )->SetColor( 1, 1, 0 ); + this->m_CursorActor->GetProperty( )->SetLineWidth( 2 ); + + // Plane intersections + this->m_Axis1 = vtkSmartPointer< vtkPolyData >::New( ); + this->m_Axis1Mapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); + this->m_Axis1Actor = vtkSmartPointer< vtkActor >::New( ); + + 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_Axis1->SetPoints( h_points ); + this->m_Axis1->SetLines( h_lines ); + this->m_Axis1Mapper->SetInputData( this->m_Axis1 ); + this->m_Axis1Actor->SetMapper( this->m_Axis1Mapper ); + + this->m_Axis2 = vtkSmartPointer< vtkPolyData >::New( ); + this->m_Axis2Mapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); + this->m_Axis2Actor = vtkSmartPointer< vtkActor >::New( ); + + 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_Axis2->SetPoints( v_points ); + this->m_Axis2->SetLines( v_lines ); + this->m_Axis2Mapper->SetInputData( this->m_Axis2 ); + this->m_Axis2Actor->SetMapper( this->m_Axis2Mapper ); + + // Plane + this->m_Plane = vtkSmartPointer< vtkPolyData >::New( ); + this->m_PlaneMapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); + this->m_PlaneActor = vtkSmartPointer< vtkActor >::New( ); vtkSmartPointer< vtkPoints > plane_points = vtkSmartPointer< vtkPoints >::New( ); vtkSmartPointer< vtkCellArray > plane_lines = vtkSmartPointer< vtkCellArray >::New( ); - plane_points->InsertNextPoint( 0, 0, 0 ); plane_points->InsertNextPoint( 0, 1, 0 ); plane_points->InsertNextPoint( 1, 1, 0 ); @@ -244,9 +218,12 @@ Clear( ) this->m_PlaneMapper->SetInputData( this->m_Plane ); this->m_PlaneActor->SetMapper( this->m_PlaneMapper ); + // Text actor + this->m_TextActor = vtkSmartPointer< vtkTextActor >::New( ); + this->m_TextBuffer[ 0 ] = '\0'; this->m_TextActor->SetTextScaleModeToNone( ); vtkTextProperty* textprop = this->m_TextActor->GetTextProperty( ); - textprop->SetColor( 1, 1, 1 ); + textprop->SetColor( 1, 1, 0 ); textprop->SetFontFamilyToCourier( ); textprop->SetFontSize( 18 ); textprop->BoldOff( ); @@ -257,11 +234,14 @@ Clear( ) 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_TextActor ); - this->AddItem( this->m_PlaneActor ); +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +AssociateSlice( Self* slice ) +{ + this->m_AssociatedSlices.push_back( slice ); + this->Modified( ); } // ------------------------------------------------------------------------- @@ -278,27 +258,54 @@ GetStyle( ) const return( this->m_Style.GetPointer( ) ); } +// ------------------------------------------------------------------------- +vtkImageData* cpExtensions::Visualization::ImageSliceActors:: +GetInputImage( ) +{ + if( this->m_ImageMapper.GetPointer( ) != NULL ) + return( this->m_ImageMapper->GetInput( ) ); + else + return( NULL ); +} + +// ------------------------------------------------------------------------- +const vtkImageData* cpExtensions::Visualization::ImageSliceActors:: +GetInputImage( ) const +{ + if( this->m_ImageMapper.GetPointer( ) != NULL ) + return( this->m_ImageMapper->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( ); + renderer->AddViewProp( this->m_ImageActor ); + renderer->AddViewProp( this->m_BlenderActor ); + if( force_style ) + { + renderer->AddViewProp( this->m_CursorActor ); + renderer->AddViewProp( this->m_PlaneActor ); + renderer->AddViewProp( this->m_TextActor ); + renderer->AddViewProp( this->m_Axis1Actor ); + renderer->AddViewProp( this->m_Axis2Actor ); + + } // fi // Configure camera vtkCamera* camera = renderer->GetActiveCamera( ); @@ -311,23 +318,22 @@ PushActorsInto( vtkRenderWindow* window, bool force_style ) if( axis == 0 ) { camera->SetPosition( double( 1 ), double( 0 ), double( 0 ) ); - camera->SetViewUp ( double( 0 ), double( 1 ), 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 ) ); + 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 ) ); + camera->SetPosition( double( 0 ), double( 0 ), double( -1 ) ); + camera->SetViewUp ( double( 0 ), double( -1 ), double( 0 ) ); } // fi } // fi renderer->ResetCamera( ); - rwi->Render( ); } // ------------------------------------------------------------------------- @@ -336,46 +342,52 @@ 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( ); + renderer->RemoveViewProp( this->m_ImageActor ); + renderer->RemoveViewProp( this->m_BlenderActor ); + renderer->RemoveViewProp( this->m_CursorActor ); + renderer->RemoveViewProp( this->m_PlaneActor ); + renderer->RemoveViewProp( this->m_TextActor ); + renderer->RemoveViewProp( this->m_Axis1Actor ); + renderer->RemoveViewProp( this->m_Axis2Actor ); } // fi - if( rwi != NULL ) - rwi->Render( ); } // ------------------------------------------------------------------------- unsigned int cpExtensions::Visualization::ImageSliceActors:: -GetNumberOfImageActors( ) const +GetNumberOfImages( ) const { - return( this->m_ImageActors.size( ) ); + return( this->m_Blender->GetNumberOfInputs( ) ); } // ------------------------------------------------------------------------- vtkImageActor* cpExtensions::Visualization::ImageSliceActors:: -GetImageActor( unsigned int id ) +GetImageActor( ) { - if( id < this->m_ImageActors.size( ) ) - return( this->m_ImageActors[ id ] ); - else - return( NULL ); + return( this->m_ImageActor ); } // ------------------------------------------------------------------------- const vtkImageActor* cpExtensions::Visualization::ImageSliceActors:: -GetImageActor( unsigned int id ) const +GetImageActor( ) const { - if( id < this->m_ImageActors.size( ) ) - return( this->m_ImageActors[ id ] ); - else - return( NULL ); + return( this->m_ImageActor ); +} + +// ------------------------------------------------------------------------- +vtkImageActor* cpExtensions::Visualization::ImageSliceActors:: +GetBinaryActor( ) +{ + return( this->m_BlenderActor ); +} + +// ------------------------------------------------------------------------- +const vtkImageActor* cpExtensions::Visualization::ImageSliceActors:: +GetBinaryActor( ) const +{ + return( this->m_BlenderActor ); } // ------------------------------------------------------------------------- @@ -410,14 +422,20 @@ GetPlaneActor( ) const vtkPlane* cpExtensions::Visualization::ImageSliceActors:: GetPlaneFunction( ) { - return( this->m_PlaneFunction ); + if( this->m_ImageMapper.GetPointer( ) != NULL ) + return( this->m_ImageMapper->GetSlicePlane( ) ); + else + return( NULL ); } // ------------------------------------------------------------------------- const vtkPlane* cpExtensions::Visualization::ImageSliceActors:: GetPlaneFunction( ) const { - return( this->m_PlaneFunction ); + if( this->m_ImageMapper.GetPointer( ) != NULL ) + return( this->m_ImageMapper->GetSlicePlane( ) ); + else + return( NULL ); } // ------------------------------------------------------------------------- @@ -426,8 +444,8 @@ SetInterpolate( bool v ) { if( this->m_Interpolate != v ) { - for( unsigned int i = 0; i < this->m_ImageActors.size( ); ++i ) - this->m_ImageActors[ i ]->SetInterpolate( v ); + this->m_ImageActor->SetInterpolate( v ); + this->m_BlenderActor->SetInterpolate( v ); this->m_Interpolate = v; this->Modified( ); @@ -452,8 +470,8 @@ InterpolateOff( ) double* cpExtensions::Visualization::ImageSliceActors:: GetDisplayBounds( ) const { - if( this->m_ImageActors.size( ) > 0 ) - return( this->m_ImageActors[ 0 ]->GetDisplayBounds( ) ); + if( this->m_ImageActor.GetPointer( ) != NULL ) + return( this->m_ImageActor->GetDisplayBounds( ) ); else return( NULL ); } @@ -462,38 +480,48 @@ GetDisplayBounds( ) const void cpExtensions::Visualization::ImageSliceActors:: GetDisplayBounds( double bounds[ 6 ] ) const { - if( this->m_ImageActors.size( ) == 0 ) + if( this->m_ImageActor.GetPointer( ) == NULL ) { - bounds[ 0 ] = bounds[ 2 ] = bounds[ 4 ] = double( -1 ); + bounds[ 0 ] = bounds[ 2 ] = bounds[ 4 ] = double( 0 ); bounds[ 1 ] = bounds[ 3 ] = bounds[ 5 ] = double( -1 ); } else - this->m_ImageActors[ 0 ]->GetDisplayBounds( bounds ); + this->m_ImageActor->GetDisplayBounds( bounds ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: ResetCursor( ) { - 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( ); + if( this->m_ImageMapper.GetPointer( ) != NULL ) + { + 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 ); + this->m_Cursor->Modified( ); + this->m_CursorMapper->Modified( ); + this->m_CursorActor->Modified( ); + + } // fi } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: SetCursor( double pos[ 3 ] ) { - if( this->m_SliceMappers.size( ) == 0 ) + if( this->m_ImageMapper.GetPointer( ) == NULL ) return; // Get ordered axes @@ -504,99 +532,139 @@ SetCursor( double pos[ 3 ] ) int ma1 = a1 << 1; int ma2 = a2 << 1; - double bounds[ 6 ]; - this->m_SliceMappers[ 0 ]->GetInput( )->GetBounds( bounds ); - - double - p0[ 3 ], p1[ 3 ], p2[ 3 ], p3[ 3 ], - p4[ 3 ], p5[ 3 ], p6[ 3 ], p7[ 3 ]; + // Update cross + double* bounds = this->m_VisibleBounds; + double p0[ 3 ], p1[ 3 ], p2[ 3 ], p3[ 3 ]; - p0[ a2 ] = p1[ a2 ] = p4[ a2 ] = p5[ a2 ] = pos[ a2 ]; - p2[ a1 ] = p3[ a1 ] = p6[ a1 ] = p7[ a1 ] = pos[ a1 ]; + p0[ a2 ] = p1[ a2 ] = pos[ a2 ]; + p2[ a1 ] = p3[ 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 ]; + p0[ a1 ] = bounds[ ma1 ]; + p1[ a1 ] = bounds[ ma1 + 1 ]; + p2[ a2 ] = bounds[ ma2 ]; + p3[ 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( ); } // ------------------------------------------------------------------------- -vtkImageMapToColors* cpExtensions::Visualization::ImageSliceActors:: -GetImageMap( unsigned int id ) +void cpExtensions::Visualization::ImageSliceActors:: +ResetAxesCursor( ) { - if( id < this->m_ImageMaps.size( ) ) - return( this->m_ImageMaps[ id ].GetPointer( ) ); + if( this->m_ImageMapper.GetPointer( ) != NULL ) + { + double pos[] = + { + this->m_VisibleBounds[ 0 ], + this->m_VisibleBounds[ 2 ], + this->m_VisibleBounds[ 4 ] + }; + this->SetAxesCursor( pos ); + } else - return( NULL ); + { + vtkPoints* points = this->m_Axis1->GetPoints( ); + points->SetPoint( 0, 0, 0, 0 ); + points->SetPoint( 1, 0, 0, 0 ); + this->m_Axis1->Modified( ); + this->m_Axis1Mapper->Modified( ); + this->m_Axis1Actor->Modified( ); + + points = this->m_Axis2->GetPoints( ); + points->SetPoint( 0, 0, 0, 0 ); + points->SetPoint( 1, 0, 0, 0 ); + this->m_Axis2->Modified( ); + this->m_Axis2Mapper->Modified( ); + this->m_Axis2Actor->Modified( ); + + } // fi } // ------------------------------------------------------------------------- -const vtkImageMapToColors* cpExtensions::Visualization::ImageSliceActors:: -GetImageMap( unsigned int id ) const +void cpExtensions::Visualization::ImageSliceActors:: +SetAxesCursor( double pos[ 3 ] ) { - if( id < this->m_ImageMaps.size( ) ) - return( this->m_ImageMaps[ id ].GetPointer( ) ); - else - return( NULL ); + 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 ]; + + p0[ a2 ] = p1[ a2 ] = pos[ a2 ]; + p2[ a1 ] = p3[ a1 ] = pos[ a1 ]; + p0[ a0 ] = p1[ a0 ] = p2[ a0 ] = p3[ a0 ] = bounds[ ma0 ]; + p0[ a1 ] = bounds[ ma1 ]; + p1[ a1 ] = bounds[ ma1 + 1 ]; + p2[ a2 ] = bounds[ ma2 ]; + p3[ a2 ] = bounds[ ma2 + 1 ]; + + vtkPoints* points1 = this->m_Axis1->GetPoints( ); + points1->SetPoint( 0, p2 ); + points1->SetPoint( 1, p3 ); + + vtkPoints* points2 = this->m_Axis2->GetPoints( ); + points2->SetPoint( 0, p0 ); + points2->SetPoint( 1, p1 ); + + this->m_Axis1->Modified( ); + this->m_Axis1Mapper->Modified( ); + this->m_Axis1Actor->Modified( ); + + this->m_Axis2->Modified( ); + this->m_Axis2Mapper->Modified( ); + this->m_Axis2Actor->Modified( ); } // ------------------------------------------------------------------------- double cpExtensions::Visualization::ImageSliceActors:: GetMinWindow( ) const { - return( this->m_MinWindow ); + return( this->m_WLRange[ 0 ] ); } // ------------------------------------------------------------------------- double cpExtensions::Visualization::ImageSliceActors:: GetMaxWindow( ) const { - return( this->m_MaxWindow ); + return( this->m_WLRange[ 1 ] ); } // ------------------------------------------------------------------------- double cpExtensions::Visualization::ImageSliceActors:: GetMinLevel( ) const { - return( this->m_MinLevel ); + return( this->m_WLRange[ 2 ] ); } // ------------------------------------------------------------------------- double cpExtensions::Visualization::ImageSliceActors:: GetMaxLevel( ) const { - return( this->m_MaxLevel ); + return( this->m_WLRange[ 3 ] ); } // ------------------------------------------------------------------------- double cpExtensions::Visualization::ImageSliceActors:: GetWindow( ) const { - if( this->m_ImageMaps.size( ) == 0 ) - return( double( 0 ) ); - if( this->m_ImageMaps[ 0 ].GetPointer( ) == NULL ) - return( double( 0 ) ); - - vtkWindowLevelLookupTable* lut = - dynamic_cast< vtkWindowLevelLookupTable* >( - this->m_ImageMaps[ 0 ]->GetLookupTable( ) - ); - if( lut != NULL ) - return( lut->GetWindow( ) ); + if( this->m_ImageActor.GetPointer( ) != NULL ) + return( this->m_ImageActor->GetProperty( )->GetColorWindow( ) ); else return( double( 0 ) ); } @@ -605,17 +673,8 @@ GetWindow( ) const double cpExtensions::Visualization::ImageSliceActors:: GetLevel( ) const { - if( this->m_ImageMaps.size( ) == 0 ) - return( double( 0 ) ); - if( this->m_ImageMaps[ 0 ].GetPointer( ) == NULL ) - return( double( 0 ) ); - - vtkWindowLevelLookupTable* lut = - dynamic_cast< vtkWindowLevelLookupTable* >( - this->m_ImageMaps[ 0 ]->GetLookupTable( ) - ); - if( lut != NULL ) - return( lut->GetLevel( ) ); + if( this->m_ImageActor.GetPointer( ) != NULL ) + return( this->m_ImageActor->GetProperty( )->GetColorLevel( ) ); else return( double( 0 ) ); } @@ -624,178 +683,55 @@ GetLevel( ) const void cpExtensions::Visualization::ImageSliceActors:: SetWindow( double w ) { - if( this->m_ImageMaps.size( ) == 0 ) + if( this->m_ImageActor.GetPointer( ) == NULL ) return; - if( this->m_ImageMaps[ 0 ].GetPointer( ) == NULL ) - return; - vtkWindowLevelLookupTable* lut = - dynamic_cast< vtkWindowLevelLookupTable* >( - this->m_ImageMaps[ 0 ]->GetLookupTable( ) - ); - if( lut == NULL ) - return; - - /* TODO: Min and Max values are assigned 0!!! - if( w < this->MinWindow ) - w = this->MinWindow; - if( w > this->MaxWindow ) - w = this->MaxWindow; - */ - lut->SetWindow( w ); - lut->Build( ); - this->m_ImageMaps[ 0 ]->Modified( ); - this->Modified( ); + double v = ( w < this->m_WLRange[ 0 ] )? this->m_WLRange[ 0 ]: w; + v = ( v > this->m_WLRange[ 1 ] )? this->m_WLRange[ 1 ]: v; + this->m_ImageActor->GetProperty( )->SetColorWindow( v ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: SetLevel( double l ) { - if( this->m_ImageMaps.size( ) == 0 ) - return; - if( this->m_ImageMaps[ 0 ].GetPointer( ) == NULL ) + if( this->m_ImageActor.GetPointer( ) == NULL ) return; - vtkWindowLevelLookupTable* lut = - dynamic_cast< vtkWindowLevelLookupTable* >( - this->m_ImageMaps[ 0 ]->GetLookupTable( ) - ); - if( lut == NULL ) - return; - - /* TODO: Min and Max values are assigned 0!!! - if( l < this->MinLevel ) - l = this->MinLevel; - if( l > this->MaxLevel ) - l = this->MaxLevel; - */ - lut->SetLevel( l ); - lut->Build( ); - this->m_ImageMaps[ 0 ]->Modified( ); - this->Modified( ); + double v = ( l < this->m_WLRange[ 2 ] )? this->m_WLRange[ 2 ]: l; + v = ( v > this->m_WLRange[ 3 ] )? this->m_WLRange[ 3 ]: v; + this->m_ImageActor->GetProperty( )->SetColorLevel( v ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: SetWindowLevel( double w, double l ) { - if( this->m_ImageMaps.size( ) == 0 ) - return; - if( this->m_ImageMaps[ 0 ].GetPointer( ) == NULL ) + if( this->m_ImageActor.GetPointer( ) == NULL ) return; - vtkWindowLevelLookupTable* lut = - dynamic_cast< vtkWindowLevelLookupTable* >( - this->m_ImageMaps[ 0 ]->GetLookupTable( ) - ); - if( lut == NULL ) - return; - - /* TODO: Min and Max values are assigned 0!!! - if( w < this->MinWindow ) - w = this->MinWindow; - if( w > this->MaxWindow ) - w = this->MaxWindow; - if( l < this->MinLevel ) - l = this->MinLevel; - if( l > this->MaxLevel ) - l = this->MaxLevel; - */ - lut->SetWindow( w ); - lut->SetLevel( l ); - lut->Build( ); - this->m_ImageMaps[ 0 ]->Modified( ); - this->UpdateText( w, l ); - this->Modified( ); + double a = ( w < this->m_WLRange[ 0 ] )? this->m_WLRange[ 0 ]: w; + a = ( a > this->m_WLRange[ 1 ] )? this->m_WLRange[ 1 ]: a; + double b = ( l < this->m_WLRange[ 2 ] )? this->m_WLRange[ 2 ]: l; + b = ( b > this->m_WLRange[ 3 ] )? this->m_WLRange[ 3 ]: b; + this->m_ImageActor->GetProperty( )->SetColorWindow( a ); + this->m_ImageActor->GetProperty( )->SetColorLevel( b ); + this->UpdateText( a, b ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: ResetWindowLevel( ) { - static const double _2 = double( 2 ); this->SetWindowLevel( - this->m_MaxWindow, ( this->m_MaxLevel + this->m_MinLevel ) / _2 - ); -} - -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::ImageSliceActors:: -SetLookupTable( unsigned int id, vtkLookupTable* lut ) -{ - if( id < this->m_ImageMaps.size( ) && id > 0 ) - { - if( this->m_ImageMaps[ id ].GetPointer( ) != NULL ) - { - this->m_ImageMaps[ id ]->SetLookupTable( lut ); - this->m_ImageMaps[ id ]->Modified( ); - this->Modified( ); - - } // fi - - } // fi -} - -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::ImageSliceActors:: -SetLookupTableAsColor( unsigned int id, double r, double g, double b ) -{ - static const double _0 = double( 0 ); - 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 ); - - // Check ID consistency - if( id == 0 || id >= this->m_ImageMaps.size( ) ) - return; - - // Get image scalar range - vtkAlgorithmOutput* aout = this->m_ImageMaps[ id ]->GetOutputPort( ); - vtkImageData* image = dynamic_cast< vtkImageData* >( - aout->GetProducer( )->GetOutputDataObject( aout->GetIndex( ) ) + this->m_WLRange[ 1 ] * double( 0.5 ), + ( this->m_WLRange[ 3 ] + this->m_WLRange[ 2 ] ) * double( 0.5 ) ); - double range[ 2 ]; - image->GetScalarRange( range ); - - // Get HSV from display color - 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 /= _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( ); - this->SetLookupTable( id, lut ); } // ------------------------------------------------------------------------- int cpExtensions::Visualization::ImageSliceActors:: GetAxis( ) const { - if( this->m_SliceMappers.size( ) > 0 ) - return( this->m_SliceMappers[ 0 ]->GetOrientation( ) ); + if( this->m_ImageMapper.GetPointer( ) != NULL ) + return( this->m_ImageMapper->GetOrientation( ) ); else return( -1 ); } @@ -804,8 +740,8 @@ GetAxis( ) const int cpExtensions::Visualization::ImageSliceActors:: GetSliceNumber( ) const { - if( this->m_SliceMappers.size( ) > 0 ) - return( this->m_SliceMappers[ 0 ]->GetSliceNumber( ) ); + if( this->m_ImageMapper.GetPointer( ) != NULL ) + return( this->m_ImageMapper->GetSliceNumber( ) ); else return( -1 ); } @@ -814,8 +750,8 @@ GetSliceNumber( ) const int cpExtensions::Visualization::ImageSliceActors:: GetSliceNumberMinValue( ) const { - if( this->m_SliceMappers.size( ) > 0 ) - return( this->m_SliceMappers[ 0 ]->GetSliceNumberMinValue( ) ); + if( this->m_ImageMapper.GetPointer( ) != NULL ) + return( this->m_ImageMapper->GetSliceNumberMinValue( ) ); else return( -1 ); } @@ -824,8 +760,8 @@ GetSliceNumberMinValue( ) const int cpExtensions::Visualization::ImageSliceActors:: GetSliceNumberMaxValue( ) const { - if( this->m_SliceMappers.size( ) > 0 ) - return( this->m_SliceMappers[ 0 ]->GetSliceNumberMaxValue( ) ); + if( this->m_ImageMapper.GetPointer( ) != NULL ) + return( this->m_ImageMapper->GetSliceNumberMaxValue( ) ); else return( -1 ); } @@ -834,135 +770,119 @@ GetSliceNumberMaxValue( ) const void cpExtensions::Visualization::ImageSliceActors:: SetSliceNumber( const int& slice ) { - unsigned int nImages = this->m_SliceMappers.size( ); - if( nImages == 0 ) + if( this->m_ImageMapper.GetPointer( ) == NULL ) return; - // Compute plane properties - int axis = this->m_SliceMappers[ 0 ]->GetOrientation( ); - vtkAlgorithm* algo = this->m_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->m_SliceMappers[ 0 ]->GetSlicePlane( )->GetOrigin( pos ); - - // Update display extent - int d_ext[ 6 ] = + int axis = this->GetAxis( ); + double prev_pos = this->m_VisibleBounds[ axis << 1 ]; + + // Update mappers and display bounds + this->m_ImageMapper->SetSliceNumber( slice ); + this->m_BlenderMapper->SetSliceNumber( slice ); + this->m_ImageMapper->Modified( ); + this->m_BlenderMapper->Modified( ); + this->m_ImageActor->Modified( ); + this->m_BlenderActor->Modified( ); + + // 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 ] = { - ext[ 0 ], ext[ 1 ], - ext[ 2 ], ext[ 3 ], - ext[ 4 ], 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 ] + } }; - d_ext[ axis << 1 ] = slice; - d_ext[ ( axis << 1 ) + 1 ] = slice; + double p0[ 2 ][ 3 ]; - // Change visualization extent - for( unsigned int i = 0; i < nImages; ++i ) - { - this->m_SliceMappers[ i ]->SetSliceNumber( slice ); - this->m_ImageActors[ i ]->SetDisplayExtent( d_ext ); - this->m_SliceMappers[ i ]->Modified( ); - this->m_ImageActors[ i ]->Modified( ); - this->m_SliceMappers[ i ]->Update( ); + vtkPlane* plane = this->m_ImageMapper->GetSlicePlane( ); + plane->GeneralizedProjectPoint( x0[ 0 ], p0[ 0 ] ); + plane->GeneralizedProjectPoint( x0[ 1 ], p0[ 1 ] ); - } // rof - - // 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[ ] = - { - ori[ 2 ] + ( spac[ 2 ] * double( ext[ 4 ] ) ), - ori[ 2 ] + ( spac[ 2 ] * double( ext[ 5 ] ) ) - }; - - if( spac[ 0 ] < double( 0 ) ) - { - double t = xbnds[ 0 ]; - xbnds[ 0 ] = xbnds[ 1 ]; - xbnds[ 1 ] = t; - - } // fi - if( spac[ 1 ] < double( 0 ) ) - { - double t = ybnds[ 0 ]; - ybnds[ 0 ] = ybnds[ 1 ]; - ybnds[ 1 ] = t; - - } // fi - if( spac[ 2 ] < double( 0 ) ) - { - double t = zbnds[ 0 ]; - zbnds[ 0 ] = zbnds[ 1 ]; - zbnds[ 1 ] = t; - - } // fi - - // Plane function origin - this->m_PlaneFunction->SetOrigin( pos ); + 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; // Configure visualization and implicit plane orientation this->m_PlaneActor->GetProperty( )->SetRepresentationToWireframe( ); - this->m_PlaneActor->GetProperty( )->SetLineWidth( 2 ); + this->m_PlaneActor->GetProperty( )->SetLineWidth( 3 ); vtkPoints* plane_points = this->m_Plane->GetPoints( ); - if( axis == 0 ) // YZ, x-normal + 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 { - this->m_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 ] ); - plane_points->SetPoint( 3, pos[ 0 ], ybnds[ 0 ], zbnds[ 1 ] ); - this->m_PlaneActor->GetProperty( )->SetColor( 1, 0, 0 ); + plane_points->SetPoint( 1, bnds[ 1 ], bnds[ 2 ], bnds[ 5 ] ); + plane_points->SetPoint( 3, bnds[ 0 ], bnds[ 3 ], bnds[ 4 ] ); } else if( axis == 1 ) // ZX, y-normal { - this->m_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 ] ); - plane_points->SetPoint( 3, xbnds[ 1 ], pos[ 1 ], zbnds[ 0 ] ); - this->m_PlaneActor->GetProperty( )->SetColor( 0, 1, 0 ); - } - else // XY, z-normal - { - this->m_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 ] ); - plane_points->SetPoint( 3, xbnds[ 0 ], ybnds[ 1 ], pos[ 2 ] ); - this->m_PlaneActor->GetProperty( )->SetColor( 0, 0, 1 ); + plane_points->SetPoint( 1, bnds[ 0 ], bnds[ 2 ], bnds[ 5 ] ); + plane_points->SetPoint( 3, bnds[ 1 ], bnds[ 3 ], bnds[ 4 ] ); } // fi - this->m_PlaneFunction->Modified( ); + + // Set plane colors + this->m_PlaneActor->GetProperty( )-> + SetColor( this->m_PlaneColors[ axis ] ); + this->m_Axis1Actor->GetProperty( )-> + SetColor( this->m_PlaneColors[ ( axis + 1 ) % 3 ] ); + this->m_Axis2Actor->GetProperty( )-> + SetColor( this->m_PlaneColors[ ( axis + 2 ) % 3 ] ); + this->m_Plane->Modified( ); this->m_PlaneMapper->Modified( ); this->m_PlaneActor->Modified( ); + this->m_Axis1->Modified( ); + this->m_Axis1Mapper->Modified( ); + this->m_Axis1Actor->Modified( ); + + this->m_Axis2->Modified( ); + this->m_Axis2Mapper->Modified( ); + this->m_Axis2Actor->Modified( ); + // Update text this->UpdateText( ); + + // 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; - if( this->m_ImageMaps[ 0 ] != NULL ) - image = - dynamic_cast< vtkImageData* >( this->m_ImageMaps[ 0 ]->GetInput( ) ); - else - image = this->m_SliceMappers[ 0 ]->GetInput( ); + vtkImageData* image = this->GetInputImage( ); + if( image == NULL ) + return; int ijk[ 3 ]; double pcoords[ 3 ]; @@ -974,17 +894,17 @@ SetSlice( double* pos ) void cpExtensions::Visualization::ImageSliceActors:: UpdateText( ) { - if( this->m_SliceMappers.size( ) > 0 ) + if( this->m_ImageMapper.GetPointer( ) != NULL ) { char axis; - int axId = this->m_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->m_TextBuffer, "Axis: %c (%d)", - axis, this->m_SliceMappers[ 0 ]->GetSliceNumber( ) + axis, this->m_ImageMapper->GetSliceNumber( ) ); } else @@ -998,22 +918,16 @@ UpdateText( ) void cpExtensions::Visualization::ImageSliceActors:: UpdateText( double pos[ 3 ] ) { - if( this->m_SliceMappers.size( ) > 0 ) + if( this->m_ImageMapper.GetPointer( ) != NULL ) { char axis; - int axId = this->m_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'; int slice = this->GetSliceNumber( ); - vtkImageData* image; - if( this->m_ImageMaps[ 0 ] != NULL ) - image = - dynamic_cast< vtkImageData* >( this->m_ImageMaps[ 0 ]->GetInput( ) ); - else - image = this->m_SliceMappers[ 0 ]->GetInput( ); - + vtkImageData* image = this->GetInputImage( ); int ijk[ 3 ]; double pcoords[ 3 ]; image->ComputeStructuredCoordinates( pos, ijk, pcoords ); @@ -1060,17 +974,17 @@ UpdateText( double pos[ 3 ] ) void cpExtensions::Visualization::ImageSliceActors:: UpdateText( const double& w, const double& l ) { - if( this->m_SliceMappers.size( ) > 0 ) + if( this->m_ImageMapper.GetPointer( ) != NULL ) { char axis; - int axId = this->m_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->m_TextBuffer, "Axis: %c (%d)\nW/L (%.2f/%.2f)", - axis, this->m_SliceMappers[ 0 ]->GetSliceNumber( ), w, l + axis, this->m_ImageMapper->GetSliceNumber( ), w, l ); } else @@ -1084,36 +998,34 @@ UpdateText( const double& w, const double& l ) void cpExtensions::Visualization::ImageSliceActors:: Render( ) { - vtkInteractorStyle* style = this->GetStyle( ); - if( style == NULL ) + if( this->m_Window == NULL ) + return; + vtkRenderer* renderer = + this->m_Window->GetRenderers( )->GetFirstRenderer( ); + if( renderer == NULL ) return; - vtkRenderWindowInteractor* rwi = style->GetInteractor( ); - if( rwi != NULL ) - rwi->Render( ); + renderer->SetAllocatedRenderTime( 1e-3 ); + this->m_Window->Render( ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: ResetCamera( ) { - vtkInteractorStyle* style = this->GetStyle( ); - if( style == NULL ) - return; - vtkRenderWindowInteractor* rwi = style->GetInteractor( ); - if( rwi == NULL ) + if( this->m_Window == NULL ) return; - vtkRenderWindow* rw = rwi->GetRenderWindow( ); - if( rw == NULL ) + vtkRenderer* renderer = + this->m_Window->GetRenderers( )->GetFirstRenderer( ); + if( renderer == NULL ) return; - vtkRenderer* renderer = rw->GetRenderers( )->GetFirstRenderer( ); - if( renderer != NULL ) - renderer->ResetCamera( ); + renderer->ResetCamera( ); } // ------------------------------------------------------------------------- cpExtensions::Visualization::ImageSliceActors:: ImageSliceActors( ) : Superclass( ), + m_Window( NULL ), m_Interpolate( false ) { this->Clear( ); @@ -1132,82 +1044,79 @@ _ConfigureStyle( ) { // Connect this view with a controller this->m_Style = vtkSmartPointer< TStyle >::New( ); + this->m_Style->SetAssociatedObject( this ); 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:: -_ConfigureNewLUT( vtkImageData* data ) +_ConfigureInputImage( ) { - // Does the new LUT is a window-level one? - unsigned int nImgs = this->m_ImageMaps.size( ); - unsigned int nCmps = data->GetNumberOfScalarComponents( ); + this->m_ImageMapper->SetOrientation( 0 ); + this->m_ImageMapper->Update( ); - if( nCmps > 1 ) - { - this->m_ImageMaps.push_back( NULL ); - return; + // Create actor + this->m_ImageActor->SetInterpolate( this->m_Interpolate ); + this->m_ImageActor->Modified( ); - } // fi + if( this->m_Style.GetPointer( ) != NULL ) + this->m_Style->AssociateImageActor( this->m_ImageActor ); + this->AddItem( this->m_ImageActor ); - // Create LUT filter - this->m_ImageMaps.push_back( vtkSmartPointer< vtkImageMapToColors >::New( ) ); - if( nImgs == 0 ) + this->SetSliceNumber( this->GetSliceNumberMinValue( ) ); + this->ResetCursor( ); + this->Modified( ); + + // Reset cursors + this->ResetCursor( ); + this->ResetAxesCursor( ); + + // Update window/level ranges + vtkImageData* data = this->GetInputImage( ); + if( data != NULL ) { - double range[ 2 ]; - data->GetScalarRange( range ); - 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( ); - this->m_ImageMaps[ 0 ]->SetLookupTable( lut ); - - this->m_MinWindow = double( 0 ); - this->m_MaxWindow = range[ 1 ] - range[ 0 ]; - this->m_MinLevel = range[ 0 ]; - this->m_MaxLevel = range[ 1 ]; - } - else - this->SetLookupTableAsColor( nImgs, 1, 0, 0 ); + double r[ 2 ]; + data->GetScalarRange( r ); + this->m_WLRange[ 0 ] = double( 0 ); + this->m_WLRange[ 1 ] = r[ 1 ] - r[ 0 ]; + this->m_WLRange[ 2 ] = r[ 0 ]; + this->m_WLRange[ 3 ] = r[ 1 ]; + this->ResetWindowLevel( ); + + // Configure blender + this->m_BlenderBase = vtkSmartPointer< vtkImageData >::New( ); + this->m_BlenderBase->ShallowCopy( data ); + this->m_BlenderBase->AllocateScalars( VTK_UNSIGNED_CHAR, 1 ); + std::memset( + this->m_BlenderBase->GetScalarPointer( ), 0, + this->m_BlenderBase->GetActualMemorySize( ) + ); + this->m_Blender->AddInputData( this->m_BlenderBase ); + + } // fi } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -_ConfigureNewInput( int axis ) +_ConfigureBinaryImage( const double& r, const double& g, const double& b ) { - unsigned int nImages = this->m_ImageActors.size( ); + unsigned int nValues = this->m_BlenderLUT->GetNumberOfTableValues( ); + this->m_BlenderLUT->SetNumberOfTableValues( nValues + 1 ); + this->m_BlenderLUT->SetTableRange( 0, nValues ); + this->m_BlenderLUT->SetTableValue( nValues, r, g, b, 0.5 ); + this->m_BlenderLUT->Build( ); - // Configure mapper - vtkImageSliceMapper* mapper = this->m_SliceMappers[ nImages ]; - if( nImages == 0 ) - mapper->SetOrientation( axis ); - else - mapper->SetOrientation( this->m_SliceMappers[ 0 ]->GetOrientation( ) ); - mapper->Update( ); + this->m_BlenderLUT->Modified( ); + this->m_Blender->Modified( ); + this->m_Blender->Update( ); - // Create actor - vtkSmartPointer< vtkImageActor > actor = - vtkSmartPointer< vtkImageActor >::New( ); - this->m_ImageActors.push_back( actor ); - actor->SetMapper( mapper ); - actor->SetInterpolate( this->m_Interpolate ); - actor->Modified( ); - - if( nImages == 0 ) - this->m_Style->AssociateImageActor( actor ); - this->AddItem( actor ); - - if( nImages > 1 ) - this->SetSliceNumber( this->GetSliceNumber( ) ); - else - this->SetSliceNumber( this->GetSliceNumberMaxValue( ) ); - this->Modified( ); + this->m_BlenderMapper->Modified( ); + this->m_BlenderActor->Modified( ); } // ------------------------------------------------------------------------- @@ -1230,18 +1139,18 @@ _MouseMoveCommand( } else if( btn == TStyle::ButtonID_Left ) { - /* TODO - unsigned int nC = actors->m_SlicesCommands.size( ); - if( !alt && ctr && !sft && nC > 0 ) - { - for( unsigned int i = 0; i < nC; ++i ) - actors->m_SlicesCommands[ i ].first( - pos, actors->GetAxis( ), actors->m_SlicesCommands[ i ].second - ); - actors->Render( ); - - } // fi - */ + if( !alt && ctr && !sft ) + { + // Show axes in current renderer + actors->SetAxesCursor( pos ); + actors->Render( ); + + // Interactively move slices + auto i = actors->m_SlicesCommands.begin( ); + for( ; i != actors->m_SlicesCommands.end( ); ++i ) + i->first( pos, actors->GetAxis( ), i->second ); + + } // fi } else if( btn == TStyle::ButtonID_Right ) { @@ -1249,7 +1158,7 @@ _MouseMoveCommand( { // Change image window level double bounds[ 6 ]; - actors->m_SliceMappers[ 0 ]->GetBounds( bounds ); + actors->m_ImageMapper->GetBounds( bounds ); int a0 = actors->GetAxis( ); int a1 = ( a0 + 1 ) % 3; @@ -1270,7 +1179,7 @@ _MouseMoveCommand( auto i = actors->m_WindowLevelCommands.begin( ); for( ; i != actors->m_WindowLevelCommands.end( ); ++i ) i->first( dx, dy, i->second ); - + } // fi } // fi @@ -1315,6 +1224,10 @@ _MouseWheelCommand( actors->SetSliceNumber( slice ); actors->Render( ); + auto a = actors->m_AssociatedSlices.begin( ); + for( ; a != actors->m_AssociatedSlices.end( ); ++a ) + ( *a )->SetSliceNumber( slice ); + // Associate objects auto i = actors->m_RenderCommands.begin( ); for( ; i != actors->m_RenderCommands.end( ); ++i ) @@ -1360,4 +1273,30 @@ _KeyCommand( void* data, const char& key ) } // 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( ); +} + +// ------------------------------------------------------------------------- +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( ); +} + // eof - $RCSfile$