#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[ i ] ); else return( NULL ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: SetInputConnection( vtkAlgorithmOutput* aout ) { this->ImageMapToColors->SetInputConnection( aout ); this->SetLookupTableToWindowLevel( ); this->_UpdateSlices( ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: SetInputData( vtkImageData* image ) { this->ImageMapToColors->SetInputData( image ); this->SetLookupTableToWindowLevel( ); this->_UpdateSlices( ); } // ------------------------------------------------------------------------- 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 ) { rends[ i ]->AddActor( this->Slices[ i ]->GetImageActor( ) ); rends[ i ]->AddActor( this->Slices[ i ]->GetTextActor( ) ); for( int j = 0; j < 3; ++j ) rends[ i ]->AddActor( this->Slices[ j ]->GetPlaneActor( ) ); if( w != NULL ) { w->AddActor( this->Slices[ i ]->GetImageActor( ) ); w->AddActor( this->Slices[ i ]->GetPlaneActor( ) ); } // fi } // 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 ) { rends[ i ]->RemoveActor( this->Slices[ i ]->GetImageActor( ) ); rends[ i ]->RemoveActor( this->Slices[ i ]->GetTextActor( ) ); for( int j = 0; j < 3; ++j ) rends[ i ]->RemoveActor( this->Slices[ j ]->GetPlaneActor( ) ); if( w != NULL ) { w->RemoveActor( this->Slices[ i ]->GetImageActor( ) ); w->RemoveActor( this->Slices[ i ]->GetPlaneActor( ) ); } // fi } // fi } // rof if( w != NULL ) { w->RemoveActor( this->ImageOutlineActor ); } // fi } // ------------------------------------------------------------------------- vtkScalarsToColors* cpExtensions::Visualization::MPRActors:: GetLookupTable( ) const { return( this->ImageMapToColors->GetLookupTable( ) ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: SetLookupTable( vtkScalarsToColors* lut ) { this->ImageMapToColors->SetLookupTable( lut ); this->ImageMapToColors->Update( ); this->Modified( ); } // ------------------------------------------------------------------------- vtkWindowLevelLookupTable* cpExtensions::Visualization::MPRActors:: GetLookupTableAsWindowLevel( ) const { return( dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( ) ) ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: SetLookupTableToWindowLevel( ) { // Check if the input has been configured vtkImageData* image = this->_InputImage( ); 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( lut ); } // ------------------------------------------------------------------------- double cpExtensions::Visualization::MPRActors:: GetMinWindow( ) const { return( double( 0 ) ); } // ------------------------------------------------------------------------- double cpExtensions::Visualization::MPRActors:: GetMaxWindow( ) const { // Check if the input has been configured vtkImageData* image = this->_InputImage( ); if( image == NULL ) return( double( 0 ) ); double r[ 2 ]; image->GetScalarRange( r ); return( r[ 1 ] - r[ 0 ] ); } // ------------------------------------------------------------------------- double cpExtensions::Visualization::MPRActors:: GetMinLevel( ) const { // Check if the input has been configured vtkImageData* image = this->_InputImage( ); if( image == NULL ) return( double( 0 ) ); double r[ 2 ]; image->GetScalarRange( r ); return( r[ 0 ] ); } // ------------------------------------------------------------------------- double cpExtensions::Visualization::MPRActors:: GetMaxLevel( ) const { // Check if the input has been configured vtkImageData* image = this->_InputImage( ); if( image == NULL ) return( double( 0 ) ); double r[ 2 ]; image->GetScalarRange( r ); return( r[ 1 ] ); } // ------------------------------------------------------------------------- double cpExtensions::Visualization::MPRActors:: GetWindow( ) const { vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( ); if( lut != NULL ) return( lut->GetWindow( ) ); else return( double( 0 ) ); } // ------------------------------------------------------------------------- double cpExtensions::Visualization::MPRActors:: GetLevel( ) const { vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( ); if( lut != NULL ) return( lut->GetLevel( ) ); else return( double( 0 ) ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: SetWindow( const double& w ) { vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( ); if( lut != NULL ) { lut->SetWindow( w ); lut->Build( ); this->ImageMapToColors->Modified( ); this->Modified( ); } // fi } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: SetLevel( const double& l ) { vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( ); if( lut != NULL ) { lut->SetLevel( l ); lut->Build( ); this->ImageMapToColors->Modified( ); this->Modified( ); } // fi } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: SetWindowLevel( const double& w, const double& l ) { vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( ); if( lut != NULL ) { lut->SetWindow( l ); lut->SetLevel( l ); lut->Build( ); this->ImageMapToColors->Modified( ); this->Modified( ); } // fi } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: ResetWindowLevel( ) { vtkImageData* image = this->_InputImage( ); vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( ); if( image != NULL && lut != NULL ) { double r[ 2 ]; image->GetScalarRange( r ); lut->SetTableRange( r ); lut->Build( ); this->ImageMapToColors->Modified( ); this->Modified( ); } // fi } // ------------------------------------------------------------------------- int cpExtensions::Visualization::MPRActors:: GetSliceNumberMinValue( const int& axis ) const { return( this->Slices[ axis ]->GetSliceNumberMinValue( ) ); } // ------------------------------------------------------------------------- int cpExtensions::Visualization::MPRActors:: GetSliceNumberMaxValue( const int& axis ) const { return( this->Slices[ axis ]->GetSliceNumberMaxValue( ) ); } // ------------------------------------------------------------------------- int cpExtensions::Visualization::MPRActors:: GetSlice( const int& axis ) const { return( this->Slices[ axis ]->GetSliceNumber( ) ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: SetSlice( const int& axis, const int& slice ) { vtkImageData* image = this->_InputImage( ); 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[ axis ]->SetSliceNumber( real ); this->Modified( ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: SetSlice( const int& axis, const double& slice ) { vtkImageData* image = this->_InputImage( ); 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( ) { // TODO } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: GetImageBounds( double bounds[ 6 ] ) const { vtkImageData* image = this->_InputImage( ); if( image != NULL ) image->GetBounds( bounds ); } // ------------------------------------------------------------------------- cpExtensions::Visualization::MPRActors:: MPRActors( ) : Superclass( ) { this->ImageMapToColors = vtkSmartPointer< vtkImageMapToColors >::New( ); this->ImageOutlineActor = vtkSmartPointer< vtkActor >::New( ); this->Slices[ 0 ] = vtkSmartPointer< _TSlice >::New( ); this->Slices[ 1 ] = vtkSmartPointer< _TSlice >::New( ); this->Slices[ 2 ] = vtkSmartPointer< _TSlice >::New( ); } // ------------------------------------------------------------------------- cpExtensions::Visualization::MPRActors:: ~MPRActors( ) { } // ------------------------------------------------------------------------- vtkImageData* cpExtensions::Visualization::MPRActors:: _InputImage( ) const { vtkAlgorithm* algo = this->ImageMapToColors->GetInputAlgorithm( ); vtkInformation* info = algo->GetOutputInformation( 0 ); return( vtkImageData::SafeDownCast( info->Get( vtkDataObject::DATA_OBJECT( ) ) ) ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: _UpdateSlices( ) { // Check if the input has been configured vtkImageData* image = this->_InputImage( ); if( image == NULL ) return; this->ImageMapToColors->Update( ); for( int i = 0; i < 3; ++i ) { this->Slices[ i ]->SetInputConnection( this->ImageMapToColors->GetOutputPort( ), i ); this->Slices[ i ]->UpdateText( ); } // rof // 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->ImageOutlineActorIndex = this->GetNumberOfItems( ); this->AddItem( this->ImageOutlineActor ); // Cursor radius /* double spac[ 3 ]; image->GetSpacing( spac ); double radius = spac[ 0 ]; radius = ( spac[ 1 ] < radius )? spac[ 1 ]: radius; radius = ( spac[ 2 ] < radius )? spac[ 2 ]: radius; radius *= double( 6 ); this->Cursor->SetRadius( radius ); this->CursorMapper->Modified( ); this->CursorActor->Modified( ); // Plane actors for( int a = 0; a < 3; ++a ) { // Configure actors this->Planes[ a ].Configure( this->ImageToWindowLevel->GetOutputPort( ), a ); this->Planes[ a ].ConfigureRegion( this->Region->GetOutputPort( ) ); this->Planes[ a ].UpdateText( this->GetWindow( ), this->GetLevel( ) ); // Add them to renderer vtkRenderer* ren = this->Interactors[ a ]->GetRenderWindow( )-> GetRenderers( )->GetFirstRenderer( ); if( ren == NULL ) vtkErrorMacro( "At least one interactor doesn't have a valid renderer" ); ren->AddActor( this->Planes[ a ].ImageActor ); ren->AddActor( this->Planes[ a ].TextActor ); for( int i = 0; i < 3; ++i ) this->Interactors[ a ]->GetRenderWindow( )-> GetRenderers( )->GetFirstRenderer( )-> AddActor( this->Planes[ i ].PlaneActor ); } // rof */ // Keep track into collection /* this->XPlaneIndex = this->GetNumberOfItems( ); this->AddItem( this->Planes[ 0 ].ImageActor.GetPointer( ) ); this->XTextIndex = this->GetNumberOfItems( ); this->AddItem( this->Planes[ 0 ].TextActor.GetPointer( ) ); this->XBoundsIndex = this->GetNumberOfItems( ); this->AddItem( this->Planes[ 0 ].PlaneActor.GetPointer( ) ); this->YPlaneIndex = this->GetNumberOfItems( ); this->AddItem( this->Planes[ 1 ].ImageActor.GetPointer( ) ); this->YTextIndex = this->GetNumberOfItems( ); this->AddItem( this->Planes[ 1 ].TextActor.GetPointer( ) ); this->YBoundsIndex = this->GetNumberOfItems( ); this->AddItem( this->Planes[ 1 ].PlaneActor.GetPointer( ) ); this->ZPlaneIndex = this->GetNumberOfItems( ); this->AddItem( this->Planes[ 2 ].ImageActor.GetPointer( ) ); this->ZTextIndex = this->GetNumberOfItems( ); this->AddItem( this->Planes[ 2 ].TextActor.GetPointer( ) ); this->ZBoundsIndex = this->GetNumberOfItems( ); this->AddItem( this->Planes[ 2 ].PlaneActor.GetPointer( ) ); */ // Initialize slice visualization // this->ResetSlices( ); /* #error CONTOUR_WIDGET <- ACA VOY static vtkSmartPointer contourRep = vtkSmartPointer::New(); static vtkSmartPointer contourWidget = vtkSmartPointer::New(); contourWidget->SetInteractor( zi ); contourWidget->SetRepresentation( contourRep ); contourWidget->On( ); */ } // eof - $RCSfile$