#include <cpExtensions/Visualization/ImageSliceActors.h>
-#include <cmath>
#include <sstream>
-
-#include <vtkAlgorithmOutput.h>
#include <vtkCamera.h>
-#include <vtkCellArray.h>
#include <vtkImageData.h>
-#include <vtkInformation.h>
+#include <vtkImageProperty.h>
#include <vtkPlane.h>
-#include <vtkPoints.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
-#include <vtkRendererCollection.h>
#include <vtkRenderWindow.h>
-#include <vtkRenderWindowInteractor.h>
-#include <vtkStreamingDemandDrivenPipeline.h>
#include <vtkTextProperty.h>
-#include <vtkWindowLevelLookupTable.h>
// -------------------------------------------------------------------------
-cpExtensions::Visualization::ImageSliceActors*
cpExtensions::Visualization::ImageSliceActors::
+Self* cpExtensions::Visualization::ImageSliceActors::
New( )
{
return( new Self( ) );
}
-// -------------------------------------------------------------------------
-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
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::Visualization::ImageSliceActors::
-RemoveRenderCommand( TVoidCommand command )
-{
- auto i = this->m_RenderCommands.find( command );
- if( i != this->m_RenderCommands.end( ) )
- {
- this->m_RenderCommands.erase( i );
- this->Modified( );
-
- } // fi
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::Visualization::ImageSliceActors::
-AddInputConnection( vtkAlgorithmOutput* aout, int axis )
-{
- // 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 );
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::Visualization::ImageSliceActors::
-AddInputData( vtkImageData* data, int axis )
-{
- // 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
-
- // 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 );
-}
-
// -------------------------------------------------------------------------
void cpExtensions::Visualization::ImageSliceActors::
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';
+ // Main image
+ this->m_Mapper = vtkSmartPointer< vtkImageSliceMapper >::New( );
+ this->m_Actor = vtkSmartPointer< vtkImageActor >::New( );
+ this->m_Actor->SetMapper( this->m_Mapper );
- // 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 > 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 );
- plane_points->InsertNextPoint( 1, 0, 0 );
- plane_lines->InsertNextCell( 5 );
- plane_lines->InsertCellPoint( 0 );
- plane_lines->InsertCellPoint( 1 );
- plane_lines->InsertCellPoint( 2 );
- plane_lines->InsertCellPoint( 3 );
- plane_lines->InsertCellPoint( 0 );
- this->m_Plane->SetPoints( plane_points );
- this->m_Plane->SetLines( plane_lines );
-
- this->m_PlaneMapper->SetInputData( this->m_Plane );
- this->m_PlaneActor->SetMapper( this->m_PlaneMapper );
+ // Cursor
+ this->m_Cursor.Create( );
+ this->m_Cursor.Actor->GetProperty( )->SetColor( 1, 1, 0 );
+ // Text
+ this->m_TextBuffer[ 0 ] = '\0';
+ this->m_TextActor = vtkSmartPointer< vtkTextActor >::New( );
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( );
textprop->SetVerticalJustificationToBottom( );
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( );
-}
-
-// -------------------------------------------------------------------------
-vtkInteractorStyle* cpExtensions::Visualization::ImageSliceActors::
-GetStyle( )
-{
- return( this->m_Style.GetPointer( ) );
-}
+ coord->SetValue( 0.01, 0.05 );
-// -------------------------------------------------------------------------
-const vtkInteractorStyle* cpExtensions::Visualization::ImageSliceActors::
-GetStyle( ) const
-{
- return( this->m_Style.GetPointer( ) );
-}
-
-// -------------------------------------------------------------------------
-vtkImageData* cpExtensions::Visualization::ImageSliceActors::
-GetInputImage( unsigned int id )
-{
- vtkAlgorithmOutput* aout = this->m_ImageMaps[ id ]->GetOutputPort( );
- vtkImageData* image = dynamic_cast< vtkImageData* >(
- aout->GetProducer( )->GetOutputDataObject( aout->GetIndex( ) )
- );
- return( image );
-}
-
-// -------------------------------------------------------------------------
-const vtkImageData* cpExtensions::Visualization::ImageSliceActors::
-GetInputImage( unsigned int id ) const
-{
- vtkAlgorithmOutput* aout = this->m_ImageMaps[ id ]->GetOutputPort( );
- const vtkImageData* image = dynamic_cast< const vtkImageData* >(
- aout->GetProducer( )->GetOutputDataObject( aout->GetIndex( ) )
- );
- return( image );
+ // Configure style
+ vtkSmartPointer< TStyle > st = vtkSmartPointer< TStyle >::New( );
+ st->SetAssociatedObject( this );
+ st->AddMouseMoveCommand( Self::_MouseMoveCommand, this );
+ st->AddMouseClickCommand( Self::_MouseClickCommand, this );
+ st->AddMouseWheelCommand( Self::_MouseWheelCommand, this );
+ st->AddKeyCommand( Self::_KeyCommand, this );
+ st->AddEnterCommand( Self::_EnterCommand, this );
+ st->AddLeaveCommand( Self::_LeaveCommand, this );
+ this->m_Style = st;
}
// -------------------------------------------------------------------------
void cpExtensions::Visualization::ImageSliceActors::
-PushActorsInto( vtkRenderWindow* window, bool force_style )
+SetInputConnection( vtkAlgorithmOutput* aout, int orientation )
{
- this->m_Window = window;
- if( window == NULL )
- return;
- vtkRenderWindowInteractor* rwi = window->GetInteractor( );
- vtkRenderer* renderer = window->GetRenderers( )->GetFirstRenderer( );
- if( rwi == NULL || renderer == NULL )
+ if( aout == 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( 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( );
-}
-
-// -------------------------------------------------------------------------
-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( );
-}
-
-// -------------------------------------------------------------------------
-unsigned int cpExtensions::Visualization::ImageSliceActors::
-GetNumberOfImageActors( ) const
-{
- return( this->m_ImageActors.size( ) );
-}
-
-// -------------------------------------------------------------------------
-vtkImageActor* cpExtensions::Visualization::ImageSliceActors::
-GetImageActor( unsigned int id )
-{
- if( id < this->m_ImageActors.size( ) )
- return( this->m_ImageActors[ id ] );
- else
- return( NULL );
-}
-
-// -------------------------------------------------------------------------
-const vtkImageActor* cpExtensions::Visualization::ImageSliceActors::
-GetImageActor( unsigned int id ) const
-{
- if( id < this->m_ImageActors.size( ) )
- return( this->m_ImageActors[ id ] );
- else
- return( NULL );
-}
-
-// -------------------------------------------------------------------------
-vtkTextActor* cpExtensions::Visualization::ImageSliceActors::
-GetTextActor( )
-{
- return( this->m_TextActor );
-}
-
-// -------------------------------------------------------------------------
-const vtkTextActor* cpExtensions::Visualization::ImageSliceActors::
-GetTextActor( ) const
-{
- return( this->m_TextActor );
-}
-
-// -------------------------------------------------------------------------
-vtkActor* cpExtensions::Visualization::ImageSliceActors::
-GetPlaneActor( )
-{
- return( this->m_PlaneActor );
-}
-
-// -------------------------------------------------------------------------
-const vtkActor* cpExtensions::Visualization::ImageSliceActors::
-GetPlaneActor( ) const
-{
- return( this->m_PlaneActor );
-}
-
-// -------------------------------------------------------------------------
-vtkPlane* cpExtensions::Visualization::ImageSliceActors::
-GetPlaneFunction( )
-{
- return( this->m_PlaneFunction );
-}
-
-// -------------------------------------------------------------------------
-const vtkPlane* cpExtensions::Visualization::ImageSliceActors::
-GetPlaneFunction( ) const
-{
- return( this->m_PlaneFunction );
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::Visualization::ImageSliceActors::
-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_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->m_ImageActors.size( ) > 0 )
- return( this->m_ImageActors[ 0 ]->GetDisplayBounds( ) );
- else
- return( NULL );
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::Visualization::ImageSliceActors::
-GetDisplayBounds( double bounds[ 6 ] ) const
-{
- if( this->m_ImageActors.size( ) == 0 )
- {
- bounds[ 0 ] = bounds[ 2 ] = bounds[ 4 ] = double( -1 );
- bounds[ 1 ] = bounds[ 3 ] = bounds[ 5 ] = double( -1 );
- }
- else
- this->m_ImageActors[ 0 ]->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( );
+ this->m_Mapper->SetInputConnection( aout );
+ this->_ConfigureInput( orientation );
}
// -------------------------------------------------------------------------
void cpExtensions::Visualization::ImageSliceActors::
-SetCursor( double pos[ 3 ] )
+SetInputData( vtkImageData* data, int orientation )
{
- if( this->m_SliceMappers.size( ) == 0 )
+ if( data == 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;
-
- 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 ];
-
- 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( );
-}
-
-// -------------------------------------------------------------------------
-vtkImageMapToColors* cpExtensions::Visualization::ImageSliceActors::
-GetImageMap( unsigned int id )
-{
- if( id < this->m_ImageMaps.size( ) )
- return( this->m_ImageMaps[ id ].GetPointer( ) );
- else
- return( NULL );
+ this->m_Mapper->SetInputData( data );
+ this->_ConfigureInput( orientation );
}
// -------------------------------------------------------------------------
-const vtkImageMapToColors* cpExtensions::Visualization::ImageSliceActors::
-GetImageMap( unsigned int id ) const
+vtkImageData* cpExtensions::Visualization::ImageSliceActors::
+GetInputData( )
{
- if( id < this->m_ImageMaps.size( ) )
- return( this->m_ImageMaps[ id ].GetPointer( ) );
+ if( this->m_Mapper.GetPointer( ) != NULL )
+ return( this->m_Mapper->GetInput( ) );
else
return( NULL );
}
-// -------------------------------------------------------------------------
-double cpExtensions::Visualization::ImageSliceActors::
-GetMinWindow( ) const
-{
- return( this->m_MinWindow );
-}
-
-// -------------------------------------------------------------------------
-double cpExtensions::Visualization::ImageSliceActors::
-GetMaxWindow( ) const
-{
- return( this->m_MaxWindow );
-}
-
-// -------------------------------------------------------------------------
-double cpExtensions::Visualization::ImageSliceActors::
-GetMinLevel( ) const
-{
- return( this->m_MinLevel );
-}
-
-// -------------------------------------------------------------------------
-double cpExtensions::Visualization::ImageSliceActors::
-GetMaxLevel( ) const
-{
- return( this->m_MaxLevel );
-}
-
-// -------------------------------------------------------------------------
-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( ) );
- else
- return( double( 0 ) );
-}
-
-// -------------------------------------------------------------------------
-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( ) );
- else
- return( double( 0 ) );
-}
-
// -------------------------------------------------------------------------
void cpExtensions::Visualization::ImageSliceActors::
-SetWindow( double w )
+AddMesh( vtkPolyData* mesh )
{
- if( this->m_ImageMaps.size( ) == 0 )
- return;
- if( this->m_ImageMaps[ 0 ].GetPointer( ) == NULL )
- return;
- vtkWindowLevelLookupTable* lut =
- dynamic_cast< vtkWindowLevelLookupTable* >(
- this->m_ImageMaps[ 0 ]->GetLookupTable( )
- );
- if( lut == NULL )
- return;
+ SourceActor< vtkCutter > a;
+ a.Create( );
+ a.Source->SetInputData( mesh );
+ a.Source->SetCutFunction( this->m_Mapper->GetSlicePlane( ) );
+ a.Source->SetValue( 0, 0 );
+ a.Source->GenerateTrianglesOff( );
+ a.Source->Update( );
+ a.Modified( );
+ this->m_Meshes[ mesh ] = a;
+ this->AddItem( a.Actor );
- /* 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( );
+ auto ren = this->m_Style->GetCurrentRenderer( );
+ if( ren != NULL )
+ if( ren->HasViewProp( this->m_Actor ) )
+ ren->AddViewProp( a.Actor );
}
// -------------------------------------------------------------------------
void cpExtensions::Visualization::ImageSliceActors::
-SetLevel( double l )
+AssociateSlice( Self* slice )
{
- if( this->m_ImageMaps.size( ) == 0 )
- 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( l < this->MinLevel )
- l = this->MinLevel;
- if( l > this->MaxLevel )
- l = this->MaxLevel;
- */
- lut->SetLevel( l );
- lut->Build( );
- this->m_ImageMaps[ 0 ]->Modified( );
+ this->m_AssociatedSlices.push_back( slice );
this->Modified( );
}
// -------------------------------------------------------------------------
void cpExtensions::Visualization::ImageSliceActors::
-SetWindowLevel( double w, double l )
+CleanAssociatedSlices( )
{
- if( this->m_ImageMaps.size( ) == 0 )
- 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;
- 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->m_AssociatedSlices.clear( );
this->Modified( );
}
// -------------------------------------------------------------------------
-void cpExtensions::Visualization::ImageSliceActors::
-ResetWindowLevel( )
+cpExtensions::Interaction::ImageInteractorStyle*
+cpExtensions::Visualization::ImageSliceActors::
+GetStyle( )
{
- static const double _2 = double( 2 );
- this->SetWindowLevel(
- this->m_MaxWindow, ( this->m_MaxLevel + this->m_MinLevel ) / _2
- );
+ return( dynamic_cast< TStyle* >( this->m_Style.GetPointer( ) ) );
}
// -------------------------------------------------------------------------
void cpExtensions::Visualization::ImageSliceActors::
-SetLookupTable( unsigned int id, vtkLookupTable* lut )
+SetStyle( vtkInteractorStyle* st )
{
- 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
+ this->m_Style = st;
+ this->Modified( );
}
// -------------------------------------------------------------------------
void cpExtensions::Visualization::ImageSliceActors::
-SetLookupTableAsColor( unsigned int id, double r, double g, double b )
+PushInto( vtkRenderer* ren )
{
- 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( ) )
- );
- 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 );
+ this->InitTraversal( );
+ vtkProp* prop;
+ while( ( prop = this->GetNextProp( ) ) != NULL )
+ ren->AddViewProp( prop );
}
// -------------------------------------------------------------------------
-int cpExtensions::Visualization::ImageSliceActors::
-GetAxis( ) const
+void cpExtensions::Visualization::ImageSliceActors::
+PopFrom( vtkRenderer* ren )
{
- if( this->m_SliceMappers.size( ) > 0 )
- return( this->m_SliceMappers[ 0 ]->GetOrientation( ) );
- else
- return( -1 );
+ this->InitTraversal( );
+ vtkProp* prop;
+ while( ( prop = this->GetNextProp( ) ) != NULL )
+ ren->RemoveViewProp( prop );
}
// -------------------------------------------------------------------------
-int cpExtensions::Visualization::ImageSliceActors::
+long cpExtensions::Visualization::ImageSliceActors::
GetSliceNumber( ) const
{
- if( this->m_SliceMappers.size( ) > 0 )
- return( this->m_SliceMappers[ 0 ]->GetSliceNumber( ) );
- else
- return( -1 );
-}
-
-// -------------------------------------------------------------------------
-int cpExtensions::Visualization::ImageSliceActors::
-GetSliceNumberMinValue( ) const
-{
- if( this->m_SliceMappers.size( ) > 0 )
- return( this->m_SliceMappers[ 0 ]->GetSliceNumberMinValue( ) );
- else
- return( -1 );
-}
-
-// -------------------------------------------------------------------------
-int cpExtensions::Visualization::ImageSliceActors::
-GetSliceNumberMaxValue( ) const
-{
- if( this->m_SliceMappers.size( ) > 0 )
- return( this->m_SliceMappers[ 0 ]->GetSliceNumberMaxValue( ) );
+ if( this->m_Mapper.GetPointer( ) != NULL )
+ return( this->m_Mapper->GetSliceNumber( ) );
else
return( -1 );
}
// -------------------------------------------------------------------------
void cpExtensions::Visualization::ImageSliceActors::
-SetSliceNumber( const int& slice )
+SetSliceNumber( long slice )
{
- unsigned int nImages = this->m_SliceMappers.size( );
- if( nImages == 0 )
+ if( this->m_Mapper.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 ] =
- {
- ext[ 0 ], ext[ 1 ],
- ext[ 2 ], ext[ 3 ],
- ext[ 4 ], ext[ 5 ]
- };
- d_ext[ axis << 1 ] = slice;
- d_ext[ ( axis << 1 ) + 1 ] = slice;
-
- std::cout
- << d_ext[ 0 ] << " "
- << d_ext[ 1 ] << " "
- << d_ext[ 2 ] << " "
- << d_ext[ 3 ] << " "
- << d_ext[ 4 ] << " "
- << d_ext[ 5 ] << " : "
- << axis << std::endl;
-
- // 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( );
-
- } // rof
-
- // Prevent obscuring voxels by offsetting the plane geometry
- double xbnds[ ] =
- {
- ori[ 0 ] + ( spac[ 0 ] * double( d_ext[ 0 ] ) ),
- ori[ 0 ] + ( spac[ 0 ] * double( d_ext[ 1 ] ) )
- };
- double ybnds[ ] =
- {
- ori[ 1 ] + ( spac[ 1 ] * double( d_ext[ 2 ] ) ),
- ori[ 1 ] + ( spac[ 1 ] * double( d_ext[ 3 ] ) )
- };
- double zbnds[ ] =
- {
- ori[ 2 ] + ( spac[ 2 ] * double( d_ext[ 4 ] ) ),
- ori[ 2 ] + ( spac[ 2 ] * double( d_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 );
-
- // Configure visualization and implicit plane orientation
- this->m_PlaneActor->GetProperty( )->SetRepresentationToWireframe( );
- this->m_PlaneActor->GetProperty( )->SetLineWidth( 2 );
- vtkPoints* plane_points = this->m_Plane->GetPoints( );
- if( axis == 0 ) // 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 );
- }
- 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 );
-
- } // fi
- this->m_PlaneFunction->Modified( );
- this->m_Plane->Modified( );
- this->m_PlaneMapper->Modified( );
- this->m_PlaneActor->Modified( );
+ // Get orientation
+ int a = this->m_Mapper->GetOrientation( );
- // Update text
- this->UpdateText( );
-}
-
-// -------------------------------------------------------------------------
-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( );
+ // Check extent
+ int ext[ 6 ];
+ this->m_Mapper->GetInput( )->GetExtent( ext );
+ long rs = slice;
+ rs = ( rs > ext[ a << 1 ] )? rs: ext[ a << 1 ];
+ rs = ( rs < ext[ ( a << 1 ) + 1 ] )? rs: ext[ ( a << 1 ) + 1 ];
- int ijk[ 3 ];
- double pcoords[ 3 ];
- image->ComputeStructuredCoordinates( pos, ijk, pcoords );
- this->SetSliceNumber( ijk[ this->GetAxis( ) ] );
-}
+ // Update pipeline
+ this->m_Mapper->SetSliceNumber( rs );
-// -------------------------------------------------------------------------
-void cpExtensions::Visualization::ImageSliceActors::
-UpdateText( )
-{
- if( this->m_SliceMappers.size( ) > 0 )
- {
- char axis;
- int axId = this->m_SliceMappers[ 0 ]->GetOrientation( );
- if ( axId == 0 ) axis = 'X';
- else if( axId == 1 ) axis = 'Y';
- else if( axId == 2 ) axis = 'Z';
+ // Update display extent (this isn't done automatically)
+ ext[ a << 1 ] = ext[ ( a << 1 ) + 1 ] = rs;
+ this->m_Actor->SetDisplayExtent( ext );
- std::sprintf(
- this->m_TextBuffer, "Axis: %c (%d)",
- axis, this->m_SliceMappers[ 0 ]->GetSliceNumber( )
- );
- }
- else
- this->m_TextBuffer[ 0 ] = '\0';
- this->m_TextActor->SetInput( this->m_TextBuffer );
- this->m_TextActor->Modified( );
+ this->m_Mapper->Modified( );
+ this->m_Actor->Modified( );
+ this->_ConfigureCursor( );
this->Modified( );
}
// -------------------------------------------------------------------------
void cpExtensions::Visualization::ImageSliceActors::
-UpdateText( double pos[ 3 ] )
+ShowPixelText( double* pos )
{
- if( this->m_SliceMappers.size( ) > 0 )
+ if( this->m_Mapper.GetPointer( ) != NULL )
{
char axis;
- int axId = this->m_SliceMappers[ 0 ]->GetOrientation( );
+ int axId = this->m_Mapper->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( );
+ long slice = this->GetSliceNumber( );
+ vtkImageData* image = this->m_Actor->GetInput( );
int ijk[ 3 ];
double pcoords[ 3 ];
image->ComputeStructuredCoordinates( pos, ijk, pcoords );
ijk[ 0 ], ijk[ 1 ], ijk[ 2 ], n
);
str << ")";
+
+#if defined(WIN32)
+ sprintf_s(
+ this->m_TextBuffer, MAX_TEXT_BUFFER, "Axis: %c (%d)\nPixel %s",
+ axis, slice, str.str( ).c_str( )
+ );
+#else // defined(WIN32)
std::sprintf(
- this->m_TextBuffer, "Axis: %c (%d)\nPixel %s",
+ this->m_TextBuffer, "Axis: %c (%ld)\nPixel %s",
axis, slice, str.str( ).c_str( )
);
-
+#endif // defined(WIN32)
} // fi
}
else
// -------------------------------------------------------------------------
void cpExtensions::Visualization::ImageSliceActors::
-UpdateText( const double& w, const double& l )
+GetScalarRange( double r[ 2 ] ) const
+{
+ r[ 0 ] = this->m_ScalarRange[ 0 ];
+ r[ 1 ] = this->m_ScalarRange[ 1 ];
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+SetScalarRange( const double& a, const double& b )
{
- if( this->m_SliceMappers.size( ) > 0 )
+ this->m_ManualScalarRange = true;
+ this->m_ScalarRange[ 0 ] = a;
+ this->m_ScalarRange[ 1 ] = b;
+ this->SetWindowLevel( 1, 0.5 );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+UnsetScalarRange( )
+{
+ auto image = this->m_Actor->GetInput( );
+ if( image != NULL )
{
- char axis;
- int axId = this->m_SliceMappers[ 0 ]->GetOrientation( );
- if ( axId == 0 ) axis = 'X';
- else if( axId == 1 ) axis = 'Y';
- else if( axId == 2 ) axis = 'Z';
+ double r[ 2 ];
+ image->GetScalarRange( r );
+ this->SetScalarRange( r[ 0 ], r[ 1 ] );
- std::sprintf(
- this->m_TextBuffer, "Axis: %c (%d)\nW/L (%.2f/%.2f)",
- axis, this->m_SliceMappers[ 0 ]->GetSliceNumber( ), w, l
- );
- }
- else
- this->m_TextBuffer[ 0 ] = '\0';
- this->m_TextActor->SetInput( this->m_TextBuffer );
- this->m_TextActor->Modified( );
- this->Modified( );
+ } // fi
+ this->m_ManualScalarRange = false;
}
// -------------------------------------------------------------------------
void cpExtensions::Visualization::ImageSliceActors::
-Render( )
+SetWindowLevel( const double& w, const double& l )
{
- if( this->m_Window != NULL )
- this->m_Window->Render( );
+ static const double _0 = double( 0 );
+ static const double _1 = double( 1 );
+
+ double rw = ( w < _0 )? _0: ( ( w > _1 )? _1: w );
+ double rl = ( l < _0 )? _0: ( ( l > _1 )? _1: l );
+
+ double d = this->m_ScalarRange[ 1 ] - this->m_ScalarRange[ 0 ];
+ rw *= d;
+ rl *= d;
+ rl += this->m_ScalarRange[ 0 ];
+
+ if( this->m_Actor.GetPointer( ) != NULL )
+ {
+ this->m_Actor->GetProperty( )->SetColorWindow( rw );
+ this->m_Actor->GetProperty( )->SetColorLevel( rl );
+ this->Modified( );
+
+ } // fi
+}
+
+// -------------------------------------------------------------------------
+double cpExtensions::Visualization::ImageSliceActors::
+GetWindow( ) const
+{
+ if( this->m_Actor.GetPointer( ) != NULL )
+ return( this->m_Actor->GetProperty( )->GetColorWindow( ) );
+ else
+ return( double( 0 ) );
+}
+
+// -------------------------------------------------------------------------
+double cpExtensions::Visualization::ImageSliceActors::
+GetLevel( ) const
+{
+ if( this->m_Actor.GetPointer( ) != NULL )
+ return( this->m_Actor->GetProperty( )->GetColorLevel( ) );
+ else
+ return( double( 0 ) );
}
// -------------------------------------------------------------------------
void cpExtensions::Visualization::ImageSliceActors::
-ResetCamera( )
+Render( )
{
- if( this->m_Window == NULL )
+ auto ren = this->m_Style->GetCurrentRenderer( );
+ if( ren == NULL )
return;
- vtkRenderer* renderer =
- this->m_Window->GetRenderers( )->GetFirstRenderer( );
- if( renderer != NULL )
- renderer->ResetCamera( );
+ auto win = ren->GetRenderWindow( );
+ if( win == NULL )
+ return;
+ win->Render( );
}
// -------------------------------------------------------------------------
cpExtensions::Visualization::ImageSliceActors::
ImageSliceActors( )
: Superclass( ),
- m_Window( NULL ),
- m_Interpolate( false )
+ m_ManualScalarRange( false )
{
this->Clear( );
- this->_ConfigureStyle( );
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
void cpExtensions::Visualization::ImageSliceActors::
-_ConfigureStyle( )
+_ConfigureInput( int orientation )
{
- // 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 );
-}
+ // Prepare main image
+ this->m_Mapper->SetOrientation( orientation );
+ this->m_Mapper->Update( );
+ this->m_Actor->GetProperty( )->SetOpacity( 0.8 );
+ this->m_Actor->Modified( );
+ auto st = this->GetStyle( );
+ if( st != NULL )
+ st->AssociateImageActor( this->m_Actor );
+ this->AddItem( this->m_Actor );
-// -------------------------------------------------------------------------
-void cpExtensions::Visualization::ImageSliceActors::
-_ConfigureNewLUT( vtkImageData* data )
-{
- // Does the new LUT is a window-level one?
- unsigned int nImgs = this->m_ImageMaps.size( );
- unsigned int nCmps = data->GetNumberOfScalarComponents( );
+ // Prepare main cursor
+ this->_ConfigureCursor( );
+ this->AddItem( this->m_Cursor.Actor );
- if( nCmps > 1 )
- {
- this->m_ImageMaps.push_back( NULL );
- return;
+ // Prepare window/level
+ if( !( this->m_ManualScalarRange ) )
+ this->UnsetScalarRange( );
- } // fi
+ // Add all other actors
+ this->AddItem( this->m_TextActor );
- // Create LUT filter
- this->m_ImageMaps.push_back( vtkSmartPointer< vtkImageMapToColors >::New( ) );
- if( nImgs == 0 )
- {
- 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 );
+ // Put it in the first slice
+ auto image = this->m_Mapper->GetInput( );
+ int ext[ 6 ];
+ image->GetExtent( ext );
+ this->SetSliceNumber( ext[ orientation << 1 ] );
+
+ /*
+ if( this->m_Style.GetPointer( ) != NULL )
+ this->AddItem( this->m_Actor );
+
+ 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 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 )
+_ConfigureCursor( )
{
- unsigned int nImages = this->m_ImageActors.size( );
+ int a = this->m_Mapper->GetOrientation( );
+ double bounds[ 6 ];
+ this->m_Actor->GetBounds( bounds );
+ bounds[ a << 1 ] += 1e-5;
+ bounds[ ( a << 1 ) + 1 ] += 1e-5;
- // Configure mapper
- vtkImageSliceMapper* mapper = this->m_SliceMappers[ nImages ];
- if( nImages == 0 )
- mapper->SetOrientation( axis );
- else
- mapper->SetOrientation( this->m_SliceMappers[ 0 ]->GetOrientation( ) );
- mapper->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_Cursor.Source->SetModelBounds( bounds );
+ this->m_Cursor.Source->AllOn( );
+ this->m_Cursor.Actor->GetProperty( )->SetOpacity( 1 );
+ this->m_Cursor.Actor->GetProperty( )->SetLineWidth( 3 );
+ this->m_Cursor.Modified( );
}
// -------------------------------------------------------------------------
void cpExtensions::Visualization::ImageSliceActors::
_MouseMoveCommand(
- void* data, const TStyle::ButtonID& btn, int* idx, double* pos,
+ 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 )
+ ImageSliceActors* self = reinterpret_cast< ImageSliceActors* >( data );
+ if( self == NULL )
return;
if( btn == TStyle::ButtonID_None )
{
- // Just show the pixel information
- actors->SetCursor( pos );
- actors->UpdateText( pos );
- actors->Render( );
- }
- 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
- */
+ self->ShowPixelText( pos );
+ self->m_Cursor.Source->SetFocalPoint( pos );
+ self->m_Cursor.Source->Modified( );
+ self->m_Cursor.Modified( );
+ self->Render( );
}
else if( btn == TStyle::ButtonID_Right )
{
if( !alt && !ctr && sft )
{
- // Change image window level
- double bounds[ 6 ];
- actors->m_SliceMappers[ 0 ]->GetBounds( bounds );
-
- int a0 = actors->GetAxis( );
+ int a0 = self->m_Mapper->GetOrientation( );
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 ];
+ double dx = pos[ a1 ] - self->m_StartMouseEvent[ a1 ];
+ double dy = pos[ a2 ] - self->m_StartMouseEvent[ a2 ];
+ double bounds[ 6 ];
+ self->m_Actor->GetBounds( bounds );
dx /= bounds[ ( a1 << 1 ) + 1 ] - bounds[ a1 << 1 ];
dy /= bounds[ ( a2 << 1 ) + 1 ] - bounds[ a2 << 1 ];
+ double w = self->m_StartWindow + dx;
+ double l = self->m_StartLevel + dy;
+
+ self->SetWindowLevel( w, l );
+ self->Render( );
+ for(
+ auto aIt = self->m_AssociatedSlices.begin( );
+ aIt != self->m_AssociatedSlices.end( );
+ ++aIt
+ )
+ {
+ ( *aIt )->SetWindowLevel( w, l );
+ ( *aIt )->Render( );
+
+ } // rof
- 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( );
-
- // 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,
+ 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 )
+ ImageSliceActors* self = reinterpret_cast< ImageSliceActors* >( data );
+ if( self == 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( );
+ self->m_StartMouseEvent[ 0 ] = pos[ 0 ];
+ self->m_StartMouseEvent[ 1 ] = pos[ 1 ];
+ self->m_StartMouseEvent[ 2 ] = pos[ 2 ];
+
+ if( btn == TStyle::ButtonID_Right )
+ {
+ if( !alt && !ctr && sft )
+ {
+ double r[ 2 ];
+ self->GetScalarRange( r );
+ double d = r[ 1 ] - r[ 0 ];
+ self->m_StartWindow = self->GetWindow( ) / d;
+ self->m_StartLevel = ( self->GetLevel( ) - r[ 0 ] ) / d;
+
+ } // fi
+
+ } // fi
}
// -------------------------------------------------------------------------
void cpExtensions::Visualization::ImageSliceActors::
_MouseWheelCommand(
- void* data, const int& dir,
- bool alt, bool ctr, bool sft
+ void* data,
+ const int& dir, bool alt, bool ctr, bool sft
)
{
- ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data );
- if( actors == NULL )
+ ImageSliceActors* self = reinterpret_cast< ImageSliceActors* >( data );
+ if( self == NULL )
+ return;
+ auto ren = self->m_Style->GetCurrentRenderer( );
+ if( ren == NULL )
+ return;
+ auto cam = ren->GetActiveCamera( );
+ if( cam == NULL )
+ return;
+ auto win = ren->GetRenderWindow( );
+ if( win == NULL )
return;
- if( !alt && !ctr )
+ // Get previous values
+ int a = self->m_Mapper->GetOrientation( );
+ double bounds[ 6 ];
+ self->m_Actor->GetBounds( bounds );
+ double prev_pos = bounds[ a << 1 ];
+
+ // Move slice
+ long slice = self->GetSliceNumber( ) + dir * ( ( sft )? 10: 1 );
+ self->SetSliceNumber( slice );
+ self->m_Actor->GetBounds( bounds );
+
+ // Reset camera
+ double cam_pos[ 3 ];
+ cam->GetPosition( cam_pos );
+ cam_pos[ a ] += bounds[ a << 1 ] - prev_pos;
+ cam->SetPosition( cam_pos );
+
+ // Update text
+ self->ShowPixelText( self->m_Cursor.Source->GetFocalPoint( ) );
+
+ // Update all
+ win->Render( );
+ for(
+ auto aIt = self->m_AssociatedSlices.begin( );
+ aIt != self->m_AssociatedSlices.end( );
+ ++aIt
+ )
{
- 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 )
+ if( ( *aIt )->m_Mapper->GetOrientation( ) == a )
{
- ( *a )->SetSliceNumber( slice );
- ( *a )->Render( );
+ ( *aIt )->SetSliceNumber( slice );
+ ( *aIt )->Render( );
- } // rof
- actors->Render( );
-
- // Associate objects
- auto i = actors->m_RenderCommands.begin( );
- for( ; i != actors->m_RenderCommands.end( ); ++i )
- i->first( i->second );
+ } // fi
} // fi
}
// -------------------------------------------------------------------------
void cpExtensions::Visualization::ImageSliceActors::
-_KeyCommand( void* data, const char& key )
+_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( );
+}
- // 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( );
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+_EnterCommand( void* data )
+{
+}
- // 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::
+_LeaveCommand( void* data )
+{
}
// eof - $RCSfile$