#include <vtkCamera.h>
#include <vtkCellArray.h>
#include <vtkImageData.h>
+#include <vtkImageProperty.h>
#include <vtkPoints.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
}
// -------------------------------------------------------------------------
-cpExtensions::Visualization::
-ImageBlender* cpExtensions::Visualization::ImageSliceActors::
-GetBlender( )
-{
- return( this->m_ImageBlender );
-}
-
-// -------------------------------------------------------------------------
-const cpExtensions::Visualization::
-ImageBlender* cpExtensions::Visualization::ImageSliceActors::
-GetBlender( ) const
+void cpExtensions::Visualization::ImageSliceActors::
+SetAxis( int axis )
{
- return( this->m_ImageBlender );
+ this->m_ImageMapper->SetOrientation( axis );
+ this->m_ImageMapper->Update( );
+ this->SetSliceNumber( this->GetSliceNumberMinValue( ) );
+ this->m_ImageActor->Modified( );
+ this->Modified( );
+ this->ResetCamera( );
}
// -------------------------------------------------------------------------
void cpExtensions::Visualization::ImageSliceActors::
-SetBlender( ImageBlender* blender )
+AddInputConnection( vtkAlgorithmOutput* aout )
{
- this->m_ImageBlender = blender;
+ // Get input vtkImageData
+ if( aout == NULL )
+ return;
// Create mapper and actors
this->m_ImageMapper = vtkSmartPointer< vtkImageSliceMapper >::New( );
- this->m_ImageMapper->SetInputConnection(
- this->m_ImageBlender->GetOutputPort( )
- );
+ this->m_ImageMapper->SetInputConnection( aout );
this->m_ImageMapper->SetOrientation( 0 );
this->m_ImageMapper->Update( );
this->SetSliceNumber( this->GetSliceNumberMinValue( ) );
this->ResetCursor( );
this->Modified( );
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::Visualization::ImageSliceActors::
-SetAxis( int axis )
-{
- this->m_ImageMapper->SetOrientation( axis );
- this->m_ImageMapper->Update( );
- this->SetSliceNumber( this->GetSliceNumberMinValue( ) );
- this->m_ImageActor->Modified( );
- this->Modified( );
- this->ResetCamera( );
-}
-// -------------------------------------------------------------------------
-void cpExtensions::Visualization::ImageSliceActors::
-AddInputConnection( vtkAlgorithmOutput* aout )
-{
- // Get input vtkImageData
- if( aout == NULL )
- return;
-
- if( this->m_ImageBlender.GetPointer( ) == NULL )
+ // Update window/level ranges
+ vtkImageData* data = this->GetInputImage( );
+ if( data != NULL )
{
- // Try to infere if input comes from a color mapping filter
- vtkAlgorithm* producer = aout->GetProducer( );
- vtkSmartPointer< ImageBlender > blender =
- dynamic_cast< ImageBlender* >( producer );
- if( blender.GetPointer( ) == NULL )
- {
- // Ok, create a new blender with default window level
- vtkImageData* data = dynamic_cast< vtkImageData* >(
- producer->GetOutputDataObject( aout->GetIndex( ) )
- );
- double r[ 2 ];
- data->GetScalarRange( r );
-
- blender = vtkSmartPointer< ImageBlender >::New( );
- blender->AddInputConnection( aout );
- blender->SetWindow( r[ 1 ] - r[ 0 ] );
- blender->SetLevel( ( r[ 1 ] + r[ 0 ] ) / double( 2 ) );
+ 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( );
- } // fi
- this->SetBlender( blender );
- }
- else
- this->m_ImageBlender->AddInputConnection( aout );
+ } // fi
}
// -------------------------------------------------------------------------
if( data == NULL )
return;
- if( this->m_ImageBlender.GetPointer( ) == NULL )
- {
- // Create a new blender with default window level
- double r[ 2 ];
- data->GetScalarRange( r );
+ // Create mapper and actors
+ this->m_ImageMapper = vtkSmartPointer< vtkImageSliceMapper >::New( );
+ this->m_ImageMapper->SetInputData( data );
+ this->m_ImageMapper->SetOrientation( 0 );
+ this->m_ImageMapper->Update( );
- vtkSmartPointer< ImageBlender > blender =
- vtkSmartPointer< ImageBlender >::New( );
- blender->AddInputData( data );
- blender->SetWindow( r[ 1 ] - r[ 0 ] );
- blender->SetLevel( ( r[ 1 ] + r[ 0 ] ) / double( 2 ) );
- this->SetBlender( blender );
- }
- else
- this->m_ImageBlender->AddInputData( data );
+ // Create actor
+ this->m_ImageActor = vtkSmartPointer< vtkImageActor >::New( );
+ this->m_ImageActor->SetMapper( this->m_ImageMapper );
+ this->m_ImageActor->SetInterpolate( this->m_Interpolate );
+ this->m_ImageActor->Modified( );
+
+ if( this->m_Style.GetPointer( ) != NULL )
+ this->m_Style->AssociateImageActor( this->m_ImageActor );
+ this->AddItem( this->m_ImageActor );
+
+ this->SetSliceNumber( this->GetSliceNumberMinValue( ) );
+ this->ResetCursor( );
+ this->Modified( );
+
+ // Update window/level ranges
+ 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( );
}
// -------------------------------------------------------------------------
this->RemoveAllItems( );
// Delete all images
- this->m_ImageActor = NULL;
- this->m_ImageMapper = NULL;
- this->m_ImageBlender = NULL;
+ this->m_ImageActor = NULL;
+ this->m_ImageMapper = NULL;
// Reconfigure unique objects
this->m_Cursor = vtkSmartPointer< vtkPolyData >::New( );
// -------------------------------------------------------------------------
vtkImageData* cpExtensions::Visualization::ImageSliceActors::
-GetInputImage( unsigned int id )
+GetInputImage( )
{
- if( this->m_ImageBlender.GetPointer( ) != NULL )
+ if( this->m_ImageMapper.GetPointer( ) != NULL )
return(
- dynamic_cast< vtkImageData* >( this->m_ImageBlender->GetInput( id ) )
+ dynamic_cast< vtkImageData* >( this->m_ImageMapper->GetInput( ) )
);
else
return( NULL );
// -------------------------------------------------------------------------
const vtkImageData* cpExtensions::Visualization::ImageSliceActors::
-GetInputImage( unsigned int id ) const
+GetInputImage( ) const
{
- if( this->m_ImageBlender.GetPointer( ) != NULL )
+ if( this->m_ImageMapper.GetPointer( ) != NULL )
return(
dynamic_cast< const vtkImageData* >(
- this->m_ImageBlender->GetInput( )
+ this->m_ImageMapper->GetInput( )
)
);
else
double cpExtensions::Visualization::ImageSliceActors::
GetMinWindow( ) const
{
- if( this->m_ImageBlender.GetPointer( ) != NULL )
- return( this->m_ImageBlender->GetMinWindow( ) );
- else
- return( double( 0 ) );
+ return( this->m_WLRange[ 0 ] );
}
// -------------------------------------------------------------------------
double cpExtensions::Visualization::ImageSliceActors::
GetMaxWindow( ) const
{
- if( this->m_ImageBlender.GetPointer( ) != NULL )
- return( this->m_ImageBlender->GetMaxWindow( ) );
- else
- return( double( 0 ) );
+ return( this->m_WLRange[ 1 ] );
}
// -------------------------------------------------------------------------
double cpExtensions::Visualization::ImageSliceActors::
GetMinLevel( ) const
{
- if( this->m_ImageBlender.GetPointer( ) != NULL )
- return( this->m_ImageBlender->GetMinLevel( ) );
- else
- return( double( 0 ) );
+ return( this->m_WLRange[ 2 ] );
}
// -------------------------------------------------------------------------
double cpExtensions::Visualization::ImageSliceActors::
GetMaxLevel( ) const
{
- if( this->m_ImageBlender.GetPointer( ) != NULL )
- return( this->m_ImageBlender->GetMaxLevel( ) );
- else
- return( double( 0 ) );
+ return( this->m_WLRange[ 3 ] );
}
// -------------------------------------------------------------------------
double cpExtensions::Visualization::ImageSliceActors::
GetWindow( ) const
{
- if( this->m_ImageBlender.GetPointer( ) != NULL )
- return( this->m_ImageBlender->GetWindow( ) );
+ if( this->m_ImageActor.GetPointer( ) != NULL )
+ return( this->m_ImageActor->GetProperty( )->GetColorWindow( ) );
else
return( double( 0 ) );
}
double cpExtensions::Visualization::ImageSliceActors::
GetLevel( ) const
{
- if( this->m_ImageBlender.GetPointer( ) != NULL )
- return( this->m_ImageBlender->GetLevel( ) );
+ if( this->m_ImageActor.GetPointer( ) != NULL )
+ return( this->m_ImageActor->GetProperty( )->GetColorLevel( ) );
else
return( double( 0 ) );
}
void cpExtensions::Visualization::ImageSliceActors::
SetWindow( double w )
{
- if( this->m_ImageBlender.GetPointer( ) != NULL )
- {
- this->m_ImageBlender->SetWindow( w );
- this->Modified( );
-
- } // fi
+ if( this->m_ImageActor.GetPointer( ) == NULL )
+ return;
+ 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_ImageBlender.GetPointer( ) != NULL )
- {
- this->m_ImageBlender->SetLevel( l );
- this->Modified( );
-
- } // fi
+ if( this->m_ImageActor.GetPointer( ) == NULL )
+ return;
+ 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_ImageBlender.GetPointer( ) != NULL )
- {
- this->m_ImageBlender->SetWindowLevel( w, l );
- this->UpdateText( w, l );
- this->Modified( );
-
- } // fi
+ if( this->m_ImageActor.GetPointer( ) == NULL )
+ return;
+ 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 );
}
// -------------------------------------------------------------------------
void cpExtensions::Visualization::ImageSliceActors::
ResetWindowLevel( )
{
- std::cerr << "ACA Resetear" << std::endl;
- std::exit( 1 );
+ this->SetWindowLevel(
+ this->m_WLRange[ 1 ] * double( 0.5 ),
+ ( this->m_WLRange[ 3 ] + this->m_WLRange[ 2 ] ) * double( 0.5 )
+ );
}
// -------------------------------------------------------------------------
void cpExtensions::Visualization::ImageSliceActors::
SetSlice( double* pos )
{
- vtkImageData* image = this->GetInputImage( 0 );
+ vtkImageData* image = this->GetInputImage( );
if( image == NULL )
return;
else if( axId == 2 ) axis = 'Z';
int slice = this->GetSliceNumber( );
- vtkImageData* image = this->GetInputImage( 0 );
+ vtkImageData* image = this->GetInputImage( );
int ijk[ 3 ];
double pcoords[ 3 ];
image->ComputeStructuredCoordinates( pos, ijk, pcoords );
auto i = actors->m_WindowLevelCommands.begin( );
for( ; i != actors->m_WindowLevelCommands.end( ); ++i )
i->first( dx, dy, i->second );
-
+
} // fi
} // fi
} // rof
actors->Render( 1e-3 );
-
+
// Associate objects
auto i = actors->m_RenderCommands.begin( );
for( ; i != actors->m_RenderCommands.end( ); ++i )
int cpExtensions::Visualization::MPRActors::
AddInputConnection( vtkAlgorithmOutput* aout )
{
- ImageBlender* blender = this->Slices[ 0 ][ 0 ]->GetBlender( );
- if( blender == NULL )
+ for( unsigned int i = 0; i < 2; ++i )
{
- this->Slices[ 0 ][ 0 ]->AddInputConnection( aout );
- blender = this->Slices[ 0 ][ 0 ]->GetBlender( );
- for( unsigned int i = 0; i < 2; ++i )
+ for( unsigned int j = 0; j < 3; ++j )
{
- for( unsigned int j = 0; j < 3; ++j )
- {
- if( i != 0 || j != 0 )
- this->Slices[ i ][ j ]->SetBlender( blender );
- this->Slices[ i ][ j ]->SetAxis( j );
-
- } // rof
+ this->Slices[ i ][ j ]->AddInputConnection( aout );
+ this->Slices[ i ][ j ]->SetAxis( j );
} // rof
- this->_CreateBoundingBox( );
- }
- else
- blender->AddInputConnection( aout );
- return( blender->GetNumberOfImages( ) - 1 );
+
+ } // rof
+ this->_CreateBoundingBox( );
+ return( 0 );
}
// -------------------------------------------------------------------------
int cpExtensions::Visualization::MPRActors::
AddInputData( vtkImageData* new_image )
{
- ImageBlender* blender = this->Slices[ 0 ][ 0 ]->GetBlender( );
- if( blender == NULL )
+ for( unsigned int i = 0; i < 2; ++i )
{
- this->Slices[ 0 ][ 0 ]->AddInputData( new_image );
- blender = this->Slices[ 0 ][ 0 ]->GetBlender( );
- for( unsigned int i = 0; i < 2; ++i )
+ for( unsigned int j = 0; j < 3; ++j )
{
- for( unsigned int j = 0; j < 3; ++j )
- {
- if( i != 0 || j != 0 )
- this->Slices[ i ][ j ]->SetBlender( blender );
- this->Slices[ i ][ j ]->SetAxis( j );
-
- } // rof
+ this->Slices[ i ][ j ]->AddInputData( new_image );
+ this->Slices[ i ][ j ]->SetAxis( j );
} // rof
- this->_CreateBoundingBox( );
- }
- else
- blender->AddInputData( new_image );
- return( blender->GetNumberOfImages( ) - 1 );
+
+ } // rof
+ this->_CreateBoundingBox( );
+ return( 0 );
}
// -------------------------------------------------------------------------
unsigned int cpExtensions::Visualization::MPRActors::
GetNumberOfImages( ) const
{
- ImageBlender* blender = this->Slices[ 0 ][ 0 ]->GetBlender( );
- if( blender != NULL )
- return( blender->GetNumberOfImages( ) );
- else
- return( 0 );
+ /* TODO
+ ImageBlender* blender = this->Slices[ 0 ][ 0 ]->GetBlender( );
+ if( blender != NULL )
+ return( blender->GetNumberOfImages( ) );
+ else
+ */
+ return( 0 );
}
// -------------------------------------------------------------------------
vtkRenderer* wren =
( w != NULL )? w->GetRenderers( )->GetFirstRenderer( ): NULL;
- if( xren != NULL )
- {
- xren->AddActor( this->Slices[ 0 ][ 1 ]->GetPlaneActor( ) );
- xren->AddActor( this->Slices[ 0 ][ 2 ]->GetPlaneActor( ) );
-
- } // fi
- if( yren != NULL )
- {
- yren->AddActor( this->Slices[ 0 ][ 0 ]->GetPlaneActor( ) );
- yren->AddActor( this->Slices[ 0 ][ 2 ]->GetPlaneActor( ) );
-
- } // fi
- if( zren != NULL )
- {
- zren->AddActor( this->Slices[ 0 ][ 0 ]->GetPlaneActor( ) );
- zren->AddActor( this->Slices[ 0 ][ 1 ]->GetPlaneActor( ) );
-
- } // fi
+ /* TODO
+ if( xren != NULL )
+ {
+ xren->AddActor( this->Slices[ 0 ][ 1 ]->GetPlaneActor( ) );
+ xren->AddActor( this->Slices[ 0 ][ 2 ]->GetPlaneActor( ) );
+
+ } // fi
+ if( yren != NULL )
+ {
+ yren->AddActor( this->Slices[ 0 ][ 0 ]->GetPlaneActor( ) );
+ yren->AddActor( this->Slices[ 0 ][ 2 ]->GetPlaneActor( ) );
+
+ } // fi
+ if( zren != NULL )
+ {
+ zren->AddActor( this->Slices[ 0 ][ 0 ]->GetPlaneActor( ) );
+ zren->AddActor( this->Slices[ 0 ][ 1 ]->GetPlaneActor( ) );
+
+ } // fi
+ */
if( wren != NULL )
wren->AddActor( this->ImageOutlineActor );
}
void cpExtensions::Visualization::MPRActors::
SetSlice( const int& axis, const int& slice )
{
- ImageBlender* blender = this->Slices[ 0 ][ 0 ]->GetBlender( );
- if( blender == NULL )
- return;
vtkImageData* image =
- dynamic_cast< vtkImageData* >( blender->GetInput( ) );
+ dynamic_cast< vtkImageData* >( this->Slices[ 0 ][ 0 ]->GetInputImage( ) );
if( image == NULL )
return;
void cpExtensions::Visualization::MPRActors::
SetSlice( const int& axis, const double& slice )
{
- ImageBlender* blender = this->Slices[ 0 ][ 0 ]->GetBlender( );
- if( blender == NULL )
- return;
vtkImageData* image =
- dynamic_cast< vtkImageData* >( blender->GetInput( ) );
+ dynamic_cast< vtkImageData* >( this->Slices[ 0 ][ 0 ]->GetInputImage( ) );
if( image == NULL )
return;
void cpExtensions::Visualization::MPRActors::
_CreateBoundingBox( )
{
- ImageBlender* blender = this->Slices[ 0 ][ 0 ]->GetBlender( );
- if( blender == NULL )
+ vtkImageData* image =
+ dynamic_cast< vtkImageData* >( this->Slices[ 0 ][ 0 ]->GetInputImage( ) );
+ if( image == NULL )
return;
- if( blender->GetNumberOfImages( ) == 1 )
- {
- vtkImageData* image =
- dynamic_cast< vtkImageData* >( blender->GetInput( ) );
- // Create 3D outline
- double bb[ 6 ];
- image->GetBounds( bb );
+ // Create 3D outline
+ double bb[ 6 ];
+ image->GetBounds( bb );
- vtkSmartPointer< vtkOutlineSource > img_ol =
- vtkSmartPointer< vtkOutlineSource >::New( );
- img_ol->SetBounds( bb );
+ vtkSmartPointer< vtkOutlineSource > img_ol =
+ vtkSmartPointer< vtkOutlineSource >::New( );
+ img_ol->SetBounds( bb );
- vtkSmartPointer< vtkPolyDataMapper > img_ol_mapper =
- vtkSmartPointer< vtkPolyDataMapper >::New( );
- img_ol_mapper->SetInputConnection( img_ol->GetOutputPort( ) );
- this->ImageOutlineActor->SetMapper( img_ol_mapper );
- this->ImageOutlineActor->GetProperty( )->SetColor( 1, 1, 1 );
- this->ImageOutlineActor->GetProperty( )->SetLineWidth( 1 );
+ vtkSmartPointer< vtkPolyDataMapper > img_ol_mapper =
+ vtkSmartPointer< vtkPolyDataMapper >::New( );
+ img_ol_mapper->SetInputConnection( img_ol->GetOutputPort( ) );
+ this->ImageOutlineActor->SetMapper( img_ol_mapper );
+ this->ImageOutlineActor->GetProperty( )->SetColor( 1, 1, 1 );
+ this->ImageOutlineActor->GetProperty( )->SetLineWidth( 1 );
- this->AddItem( this->ImageOutlineActor );
-
- } // fi
+ this->AddItem( this->ImageOutlineActor );
}
// -------------------------------------------------------------------------
MPRActors* actors = reinterpret_cast< MPRActors* >( data );
if( actors == NULL )
return;
+
+ actors->Slices[ 0 ][ 0 ]->SetWindowLevel( window, level );
+ actors->Slices[ 0 ][ 1 ]->SetWindowLevel( window, level );
+ actors->Slices[ 0 ][ 2 ]->SetWindowLevel( window, level );
+ actors->Slices[ 1 ][ 0 ]->SetWindowLevel( window, level );
+ actors->Slices[ 1 ][ 1 ]->SetWindowLevel( window, level );
+ actors->Slices[ 1 ][ 2 ]->SetWindowLevel( window, level );
+
actors->Slices[ 0 ][ 0 ]->Render( 1e-3 );
actors->Slices[ 0 ][ 1 ]->Render( 1e-3 );
actors->Slices[ 0 ][ 2 ]->Render( 1e-3 );