#include #include #include #include #include #include #include #include #include #include // ------------------------------------------------------------------------- cpExtensions::Visualization::ImageSliceActors* cpExtensions::Visualization::ImageSliceActors:: New( ) { return( new Self( ) ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: SetInputConnection( vtkAlgorithmOutput* aout, int axis ) { this->SliceMapper->SetInputConnection( aout ); this->SliceMapper->SetOrientation( axis ); this->SliceMapper->Update( ); this->SetSliceNumber( this->SliceMapper->GetSliceNumber( ) ); this->ImageActor->SetMapper( this->SliceMapper ); this->ImageActor->Modified( ); this->Modified( ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: SetInputData( vtkImageData* data, int axis ) { this->SliceMapper->SetInputData( data ); this->SliceMapper->SetOrientation( axis ); this->SliceMapper->Update( ); this->SetSliceNumber( this->SliceMapper->GetSliceNumber( ) ); this->ImageActor->SetMapper( this->SliceMapper ); this->ImageActor->Modified( ); this->Modified( ); } // ------------------------------------------------------------------------- double* cpExtensions::Visualization::ImageSliceActors:: GetDisplayBounds( ) const { return( this->ImageActor->GetDisplayBounds( ) ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: GetDisplayBounds( double bounds[ 6 ] ) const { this->ImageActor->GetDisplayBounds( bounds ); } // ------------------------------------------------------------------------- int cpExtensions::Visualization::ImageSliceActors:: GetAxis( ) const { return( this->SliceMapper->GetOrientation( ) ); } // ------------------------------------------------------------------------- int cpExtensions::Visualization::ImageSliceActors:: GetSliceNumber( ) const { return( this->SliceMapper->GetSliceNumber( ) ); } // ------------------------------------------------------------------------- int cpExtensions::Visualization::ImageSliceActors:: GetSliceNumberMinValue( ) const { return( this->SliceMapper->GetSliceNumberMinValue( ) ); } // ------------------------------------------------------------------------- int cpExtensions::Visualization::ImageSliceActors:: GetSliceNumberMaxValue( ) const { return( this->SliceMapper->GetSliceNumberMaxValue( ) ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: SetSliceNumber( const int& slice ) { this->SliceMapper->SetSliceNumber( slice ); this->SliceMapper->Update( ); // Compute plane vtkAlgorithm* algo = this->SliceMapper->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->SliceMapper->GetSlicePlane( )->GetOrigin( pos ); // Prevent obscuring voxels by offsetting the plane geometry double xbnds[ ] = { ori[ 0 ] + ( spac[ 0 ] * double( ext[ 0 ] ) ), ori[ 0 ] + ( spac[ 0 ] * double( ext[ 1 ] ) ) }; double ybnds[ ] = { ori[ 1 ] + ( spac[ 1 ] * double( ext[ 2 ] ) ), ori[ 1 ] + ( spac[ 1 ] * double( ext[ 3 ] ) ) }; double zbnds[ ] = { ori[ 2 ] + ( spac[ 2 ] * double( ext[ 4 ] ) ), ori[ 2 ] + ( spac[ 2 ] * double( 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 int axis = this->SliceMapper->GetOrientation( ); this->PlaneActor->GetProperty( )->SetRepresentationToWireframe( ); this->PlaneActor->GetProperty( )->SetLineWidth( 2 ); vtkPoints* plane_points = this->PlaneSource->GetPoints( ); if( axis == 0 ) // YZ, x-normal { 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->PlaneActor->GetProperty( )->SetColor( 1, 0, 0 ); } else if( axis == 1 ) // ZX, y-normal { 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->PlaneActor->GetProperty( )->SetColor( 0, 1, 0 ); } else // XY, z-normal { 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->PlaneActor->GetProperty( )->SetColor( 0, 0, 1 ); } // fi this->PlaneSource->Modified( ); this->PlaneMapper->Modified( ); this->PlaneActor->Modified( ); this->Modified( ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: UpdateText( ) { char axis; int axId = this->SliceMapper->GetOrientation( ); if ( axId == 0 ) axis = 'X'; else if( axId == 1 ) axis = 'Y'; else if( axId == 2 ) axis = 'Z'; std::sprintf( this->TextBuffer, "Axis: %c (%d)", axis, this->SliceMapper->GetSliceNumber( ) ); this->TextActor->SetInput( this->TextBuffer ); this->TextActor->Modified( ); this->Modified( ); } // ------------------------------------------------------------------------- cpExtensions::Visualization::ImageSliceActors:: ImageSliceActors( ) : Superclass( ) { this->SliceMapper = vtkSmartPointer< vtkImageSliceMapper >::New( ); this->PlaneSource = vtkSmartPointer< vtkPolyData >::New( ); this->PlaneMapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); this->ImageActor = vtkSmartPointer< vtkImageActor >::New( ); this->TextActor = vtkSmartPointer< vtkTextActor >::New( ); this->PlaneActor = vtkSmartPointer< vtkActor >::New( ); this->ImageActorIndex = this->GetNumberOfItems( ); this->TextActorIndex = this->ImageActorIndex + 1; this->PlaneActorIndex = this->ImageActorIndex + 2; this->AddItem( this->ImageActor ); this->AddItem( this->TextActor ); this->AddItem( this->PlaneActor ); // Configuration 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->PlaneSource->SetPoints( plane_points ); this->PlaneSource->SetLines( plane_lines ); this->PlaneMapper->SetInputData( this->PlaneSource ); this->PlaneActor->SetMapper( this->PlaneMapper ); this->TextActor->SetTextScaleModeToNone( ); vtkTextProperty* textprop = this->TextActor->GetTextProperty( ); textprop->SetColor( 1, 1, 1 ); textprop->SetFontFamilyToCourier( ); textprop->SetFontSize( 18 ); textprop->BoldOff( ); textprop->ItalicOff( ); textprop->ShadowOff( ); textprop->SetJustificationToLeft( ); textprop->SetVerticalJustificationToBottom( ); vtkCoordinate* coord = this->TextActor->GetPositionCoordinate( ); coord->SetCoordinateSystemToNormalizedViewport( ); coord->SetValue( 0.01, 0.01 ); } // ------------------------------------------------------------------------- cpExtensions::Visualization::ImageSliceActors:: ~ImageSliceActors( ) { } // eof - $RCSfile$