#include #include #include #include #include #include #include #include // ------------------------------------------------------------------------- cpExtensions::Visualization::MPRActors* cpExtensions::Visualization::MPRActors:: New( ) { return( new Self( ) ); } // ------------------------------------------------------------------------- cpExtensions::Visualization:: ImageSliceActors* cpExtensions::Visualization::MPRActors:: GetSliceActors( const int& i ) const { if( i < 3 ) return( this->Slices[ 0 ][ i ] ); else return( NULL ); } // ------------------------------------------------------------------------- int cpExtensions::Visualization::MPRActors:: AddInputConnection( vtkAlgorithmOutput* aout ) { int N = this->ImageMaps.size( ); if( N == 0 ) { this->ImageMaps.push_back( vtkSmartPointer< vtkImageMapToColors >::New( ) ); this->ImageMaps[ 0 ]->SetInputConnection( aout ); this->SetLookupTableToWindowLevel( 0 ); this->_Update( 0 ); return( 0 ); } else { // Check if the image share the same space vtkImageData* ref_image = this->_Image( 0 ); vtkImageData* new_image = vtkImageData::SafeDownCast( aout->GetProducer( )->GetOutputInformation( 0 )-> Get( vtkDataObject::DATA_OBJECT( ) ) ); int ref_ext[ 6 ], new_ext[ 6 ]; ref_image->GetExtent( ref_ext ); new_image->GetExtent( new_ext ); if( ref_ext[ 0 ] == new_ext[ 0 ] && ref_ext[ 1 ] == new_ext[ 1 ] && ref_ext[ 2 ] == new_ext[ 2 ] && ref_ext[ 3 ] == new_ext[ 3 ] && ref_ext[ 4 ] == new_ext[ 4 ] && ref_ext[ 5 ] == new_ext[ 5 ] ) { this->ImageMaps.push_back( vtkSmartPointer< vtkImageMapToColors >::New( ) ); this->ImageMaps[ N ]->SetInputConnection( aout ); this->SetLookupTableToWindowLevel( N ); this->_Update( N ); return( N ); } else return( -1 ); } // fi } // ------------------------------------------------------------------------- int cpExtensions::Visualization::MPRActors:: AddInputData( vtkImageData* image ) { int N = this->ImageMaps.size( ); if( N == 0 ) { this->ImageMaps.push_back( vtkSmartPointer< vtkImageMapToColors >::New( ) ); this->ImageMaps[ 0 ]->SetInputData( image ); this->SetLookupTableToWindowLevel( 0 ); this->_Update( 0 ); return( 0 ); } else { // Check if the image share the same space vtkImageData* ref_image = this->_Image( 0 ); vtkImageData* new_image = image; int ref_ext[ 6 ], new_ext[ 6 ]; ref_image->GetExtent( ref_ext ); new_image->GetExtent( new_ext ); if( ref_ext[ 0 ] == new_ext[ 0 ] && ref_ext[ 1 ] == new_ext[ 1 ] && ref_ext[ 2 ] == new_ext[ 2 ] && ref_ext[ 3 ] == new_ext[ 3 ] && ref_ext[ 4 ] == new_ext[ 4 ] && ref_ext[ 5 ] == new_ext[ 5 ] ) { this->ImageMaps.push_back( vtkSmartPointer< vtkImageMapToColors >::New( ) ); this->ImageMaps[ N ]->SetInputData( image ); this->SetLookupTableToWindowLevel( N ); this->_Update( N ); return( N ); } else return( -1 ); } // fi } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: PushDataInto( vtkRenderer* x, vtkRenderer* y, vtkRenderer* z, vtkRenderer* w ) { vtkRenderer* rends[] = { x, y, z }; for( int i = 0; i < 3; ++i ) { if( rends[ i ] != NULL ) { for( unsigned int k = 0; k < this->Slices[ 0 ][ i ]->GetNumberOfImageActors( ); ++k ) rends[ i ]->AddActor( this->Slices[ 0 ][ i ]->GetImageActor( k ) ); rends[ i ]->AddActor( this->Slices[ 0 ][ i ]->GetTextActor( ) ); for( int j = 0; j < 3; ++j ) rends[ i ]->AddActor( this->Slices[ 0 ][ j ]->GetPlaneActor( ) ); } // fi if( w != NULL ) { for( unsigned int k = 0; k < this->Slices[ 1 ][ i ]->GetNumberOfImageActors( ); ++k ) w->AddActor( this->Slices[ 1 ][ i ]->GetImageActor( k ) ); w->AddActor( this->Slices[ 1 ][ i ]->GetPlaneActor( ) ); } // fi } // rof if( w != NULL ) w->AddActor( this->ImageOutlineActor ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: PopDataFrom( vtkRenderer* x, vtkRenderer* y, vtkRenderer* z, vtkRenderer* w ) { vtkRenderer* rends[] = { x, y, z }; for( int i = 0; i < 3; ++i ) { if( rends[ i ] != NULL ) { for( unsigned int k = 0; k < this->Slices[ 0 ][ i ]->GetNumberOfImageActors( ); ++k ) rends[ i ]->RemoveActor( this->Slices[ 0 ][ i ]->GetImageActor( k ) ); rends[ i ]->RemoveActor( this->Slices[ 0 ][ i ]->GetTextActor( ) ); for( int j = 0; j < 3; ++j ) rends[ i ]->RemoveActor( this->Slices[ 0 ][ j ]->GetPlaneActor( ) ); } // fi if( w != NULL ) { for( unsigned int k = 0; k < this->Slices[ 1 ][ i ]->GetNumberOfImageActors( ); ++k ) w->RemoveActor( this->Slices[ 1 ][ i ]->GetImageActor( k ) ); w->RemoveActor( this->Slices[ 1 ][ i ]->GetPlaneActor( ) ); } // fi } // rof if( w != NULL ) w->RemoveActor( this->ImageOutlineActor ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: SetLookupTable( unsigned int i, vtkScalarsToColors* lut ) { if( i < this->ImageMaps.size( ) ) { this->ImageMaps[ i ]->SetLookupTable( lut ); this->ImageMaps[ i ]->Update( ); this->Modified( ); } // fi } // ------------------------------------------------------------------------- vtkScalarsToColors* cpExtensions::Visualization::MPRActors:: GetLookupTable( unsigned int i ) const { if( i < this->ImageMaps.size( ) ) return( this->ImageMaps[ i ]->GetLookupTable( ) ); else return( NULL ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: SetLookupTableToWindowLevel( unsigned int i ) { // Check if the input has been configured vtkImageData* image = this->_Image( i ); if( image == NULL ) return; double r[ 2 ]; image->GetScalarRange( r ); vtkSmartPointer< vtkWindowLevelLookupTable > lut = vtkSmartPointer< vtkWindowLevelLookupTable >::New( ); lut->SetScaleToLinear( ); lut->SetTableRange( r ); lut->Build( ); this->SetLookupTable( i, lut ); } // ------------------------------------------------------------------------- double cpExtensions::Visualization::MPRActors:: GetMinWindow( unsigned int i ) const { return( 0 ); } // ------------------------------------------------------------------------- double cpExtensions::Visualization::MPRActors:: GetMaxWindow( unsigned int i ) const { // Check if the input has been configured vtkImageData* image = this->_Image( i ); if( image == NULL ) return( double( 0 ) ); double r[ 2 ]; image->GetScalarRange( r ); return( r[ 1 ] - r[ 0 ] ); } // ------------------------------------------------------------------------- double cpExtensions::Visualization::MPRActors:: GetMinLevel( unsigned int i ) const { // Check if the input has been configured vtkImageData* image = this->_Image( i ); if( image == NULL ) return( double( 0 ) ); double r[ 2 ]; image->GetScalarRange( r ); return( r[ 0 ] ); } // ------------------------------------------------------------------------- double cpExtensions::Visualization::MPRActors:: GetMaxLevel( unsigned int i ) const { // Check if the input has been configured vtkImageData* image = this->_Image( i ); if( image == NULL ) return( double( 0 ) ); double r[ 2 ]; image->GetScalarRange( r ); return( r[ 1 ] ); } // ------------------------------------------------------------------------- double cpExtensions::Visualization::MPRActors:: GetWindow( unsigned int i ) const { vtkWindowLevelLookupTable* lut = dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( i ) ); if( lut != NULL ) return( lut->GetWindow( ) ); else return( double( 0 ) ); } // ------------------------------------------------------------------------- double cpExtensions::Visualization::MPRActors:: GetLevel( unsigned int i ) const { vtkWindowLevelLookupTable* lut = dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( i ) ); if( lut != NULL ) return( lut->GetLevel( ) ); else return( double( 0 ) ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: SetWindow( unsigned int i, const double& w ) { vtkWindowLevelLookupTable* lut = dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( i ) ); if( lut != NULL ) { lut->SetWindow( w ); lut->Build( ); this->ImageMaps[ i ]->Modified( ); this->Modified( ); } // fi } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: SetLevel( unsigned int i, const double& l ) { vtkWindowLevelLookupTable* lut = dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( i ) ); if( lut != NULL ) { lut->SetLevel( l ); lut->Build( ); this->ImageMaps[ i ]->Modified( ); this->Modified( ); } // fi } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: ResetWindowLevel( unsigned int i ) { vtkImageData* image = this->_Image( i ); vtkWindowLevelLookupTable* lut = dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( i ) ); if( image != NULL && lut != NULL ) { double r[ 2 ]; image->GetScalarRange( r ); lut->SetTableRange( r ); lut->Build( ); this->ImageMaps[ i ]->Modified( ); this->Modified( ); } // fi } // ------------------------------------------------------------------------- int cpExtensions::Visualization::MPRActors:: GetSliceNumberMinValue( const int& axis ) const { return( this->Slices[ 0 ][ axis ]->GetSliceNumberMinValue( ) ); } // ------------------------------------------------------------------------- int cpExtensions::Visualization::MPRActors:: GetSliceNumberMaxValue( const int& axis ) const { return( this->Slices[ 0 ][ axis ]->GetSliceNumberMaxValue( ) ); } // ------------------------------------------------------------------------- int cpExtensions::Visualization::MPRActors:: GetSlice( const int& axis ) const { return( this->Slices[ 0 ][ axis ]->GetSliceNumber( ) ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: SetSlice( const int& axis, const int& slice ) { vtkImageData* image = this->_Image( 0 ); if( image == NULL ) return; // Get image data extent int ext[ 6 ]; image->GetExtent( ext ); // Check if the slice is valid int real = slice; if( slice < ext[ axis << 1 ] ) real = ext[ axis << 1 ]; if( ext[ ( axis << 1 ) + 1 ] < slice ) real = ext[ ( axis << 1 ) + 1 ]; // Change slice this->Slices[ 0 ][ axis ]->SetSliceNumber( real ); this->Slices[ 1 ][ axis ]->SetSliceNumber( real ); this->Modified( ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: SetSlice( const int& axis, const double& slice ) { vtkImageData* image = this->_Image( 0 ); if( image == NULL ) return; double x[ 3 ] = { double( 0 ) }; double pcoords[ 3 ]; int ijk[ 3 ]; x[ axis ] = slice; image->ComputeStructuredCoordinates( x, ijk, pcoords ); this->SetSlice( axis, ijk[ axis ] ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: ResetSlices( ) { for( unsigned int i = 0; i < 2; ++i ) for( unsigned int j = 0; j < 3; ++j ) this->Slices[ i ][ j ]->SetSliceNumber( this->Slices[ i ][ j ]->GetSliceNumberMinValue( ) ); } // ------------------------------------------------------------------------- cpExtensions::Visualization::MPRActors:: MPRActors( ) : Superclass( ) { this->ImageOutlineActor = vtkSmartPointer< vtkActor >::New( ); for( unsigned int i = 0; i < 2; ++i ) for( unsigned int j = 0; j < 3; ++j ) this->Slices[ i ][ j ] = vtkSmartPointer< ImageSliceActors >::New( ); } // ------------------------------------------------------------------------- cpExtensions::Visualization::MPRActors:: ~MPRActors( ) { } // ------------------------------------------------------------------------- vtkImageData* cpExtensions::Visualization::MPRActors:: _Image( unsigned int i ) const { if( i < this->ImageMaps.size( ) ) { vtkAlgorithm* algo = this->ImageMaps[ i ]->GetInputAlgorithm( ); vtkInformation* info = algo->GetOutputInformation( 0 ); return( vtkImageData::SafeDownCast( info->Get( vtkDataObject::DATA_OBJECT( ) ) ) ); } else return( NULL ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: _Update( unsigned int i ) { // Check if the input has been configured vtkImageData* image = this->_Image( i ); if( image == NULL ) return; this->ImageMaps[ i ]->Update( ); for( int j = 0; j < 2; ++j ) { for( int k = 0; k < 3; ++k ) { this->Slices[ j ][ k ]->AddInputConnection( this->ImageMaps[ i ]->GetOutputPort( ), k ); this->Slices[ j ][ k ]->UpdateText( ); } // rof } // rof if( i == 0 ) { // Create 3D outline double bb[ 6 ]; image->GetBounds( 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 ); this->AddItem( this->ImageOutlineActor ); } // fi } // eof - $RCSfile$