#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 ) { for( unsigned int i = 0; i < 2; ++i ) { for( unsigned int j = 0; j < 3; ++j ) { this->Slices[ i ][ j ]->SetInputConnection( aout ); this->Slices[ i ][ j ]->SetAxis( j ); } // rof } // rof this->_CreateBoundingBox( ); return( 0 ); } // ------------------------------------------------------------------------- int cpExtensions::Visualization::MPRActors:: AddInputData( vtkImageData* new_image ) { for( unsigned int i = 0; i < 2; ++i ) { for( unsigned int j = 0; j < 3; ++j ) { this->Slices[ i ][ j ]->SetInputImage( new_image ); this->Slices[ i ][ j ]->SetAxis( j ); } // rof } // rof this->_CreateBoundingBox( ); return( 0 ); } // ------------------------------------------------------------------------- unsigned int cpExtensions::Visualization::MPRActors:: GetNumberOfImages( ) const { return( this->Slices[ 0 ][ 0 ]->GetNumberOfImages( ) ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: PushActorsInto( vtkRenderWindow* x, vtkRenderWindow* y, vtkRenderWindow* z, vtkRenderWindow* w ) { this->Slices[ 0 ][ 0 ]->PushActorsInto( x, true ); this->Slices[ 0 ][ 1 ]->PushActorsInto( y, true ); this->Slices[ 0 ][ 2 ]->PushActorsInto( z, true ); this->Slices[ 1 ][ 0 ]->PushActorsInto( w, false ); this->Slices[ 1 ][ 1 ]->PushActorsInto( w, false ); this->Slices[ 1 ][ 2 ]->PushActorsInto( w, false ); vtkRenderer* wren = ( w != NULL )? w->GetRenderers( )->GetFirstRenderer( ): NULL; if( wren != NULL ) wren->AddActor( this->ImageOutlineActor ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: PopActorsFrom( vtkRenderWindow* x, vtkRenderWindow* y, vtkRenderWindow* z, vtkRenderWindow* w ) { this->Slices[ 0 ][ 0 ]->PopActorsFrom( x ); this->Slices[ 0 ][ 1 ]->PopActorsFrom( y ); this->Slices[ 0 ][ 2 ]->PopActorsFrom( z ); this->Slices[ 1 ][ 0 ]->PopActorsFrom( w ); this->Slices[ 1 ][ 1 ]->PopActorsFrom( w ); this->Slices[ 1 ][ 2 ]->PopActorsFrom( w ); vtkRenderer* wren = ( w != NULL )? w->GetRenderers( )->GetFirstRenderer( ): NULL; if( wren != NULL ) wren->RemoveActor( this->ImageOutlineActor ); this->Slices[ 0 ][ 0 ]->Clear( ); this->Slices[ 0 ][ 1 ]->Clear( ); this->Slices[ 0 ][ 2 ]->Clear( ); this->Slices[ 1 ][ 0 ]->Clear( ); this->Slices[ 1 ][ 1 ]->Clear( ); this->Slices[ 1 ][ 2 ]->Clear( ); } // ------------------------------------------------------------------------- double cpExtensions::Visualization::MPRActors:: GetWindow( ) { return( this->Slices[ 0 ][ 0 ]->GetWindow( ) ); } // ------------------------------------------------------------------------- double cpExtensions::Visualization::MPRActors:: GetLevel( ) { return( this->Slices[ 0 ][ 0 ]->GetLevel( ) ); } // ------------------------------------------------------------------------- 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 = dynamic_cast< vtkImageData* >( this->Slices[ 0 ][ 0 ]->GetInputImage( ) ); 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 = dynamic_cast< vtkImageData* >( this->Slices[ 0 ][ 0 ]->GetInputImage( ) ); 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( ); this->Slices[ 0 ][ 0 ]->AssociateSlice( this->Slices[ 1 ][ 0 ] ); this->Slices[ 0 ][ 1 ]->AssociateSlice( this->Slices[ 1 ][ 1 ] ); this->Slices[ 0 ][ 2 ]->AssociateSlice( this->Slices[ 1 ][ 2 ] ); for( unsigned int i = 0; i < 3; ++ i ) { this->Slices[ 0 ][ i ]->AddRenderCommand( Self::_RenderCommand, this ); this->Slices[ 0 ][ i ]->AddWindowLevelCommand( Self::_WindowLevelCommand, this ); this->Slices[ 0 ][ i ]->AddSlicesCommand( Self::_SlicesCommand, this ); } // rof } // ------------------------------------------------------------------------- cpExtensions::Visualization::MPRActors:: ~MPRActors( ) { } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: _CreateBoundingBox( ) { vtkImageData* image = dynamic_cast< vtkImageData* >( this->Slices[ 0 ][ 0 ]->GetInputImage( ) ); if( image == NULL ) return; // 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 ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: _SlicesCommand( double* pos, int axis, void* data ) { MPRActors* actors = reinterpret_cast< MPRActors* >( data ); if( actors == NULL ) return; for( unsigned int j = 0; j < 3; ++j ) { if( actors->Slices[ 0 ][ j ]->GetAxis( ) != axis ) { actors->Slices[ 0 ][ j ]->SetSlice( pos ); actors->Slices[ 1 ][ j ]->SetSlice( pos ); actors->Slices[ 0 ][ j ]->Render( 1e-3 ); actors->Slices[ 1 ][ j ]->Render( 1e-3 ); } // fi } // rof } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: _WindowLevelCommand( double window, double level, void* data ) { 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 ); actors->Slices[ 1 ][ 0 ]->Render( 1e-3 ); actors->Slices[ 1 ][ 1 ]->Render( 1e-3 ); actors->Slices[ 1 ][ 2 ]->Render( 1e-3 ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: _RenderCommand( void* data ) { MPRActors* actors = reinterpret_cast< MPRActors* >( data ); if( actors == NULL ) return; actors->Slices[ 0 ][ 0 ]->Render( 1e-3 ); actors->Slices[ 0 ][ 1 ]->Render( 1e-3 ); actors->Slices[ 0 ][ 2 ]->Render( 1e-3 ); actors->Slices[ 1 ][ 0 ]->Render( 1e-3 ); actors->Slices[ 1 ][ 1 ]->Render( 1e-3 ); actors->Slices[ 1 ][ 2 ]->Render( 1e-3 ); } // eof - $RCSfile$