#include #include #include #include #include #include #include #include // ------------------------------------------------------------------------- cpExtensions::Visualization::ImageViewerActors:: Self* cpExtensions::Visualization::ImageViewerActors:: New( ) { return( new Self( ) ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageViewerActors:: SetImage( vtkImageData* image, int orientation ) { this->Superclass::SetImage( image, orientation ); this->m_Cursor = vtkSmartPointer< CursorActors >::New( ); this->m_Cursor->SetImageBounds( image->GetBounds( ) ); this->m_Cursor->SetImageOrientation( orientation ); this->m_Cursor->GetProperty( 0 )->SetColor( 1, 1, 0 ); this->m_Cursor->GetProperty( 1 )->SetColor( 1, 1, 0 ); this->m_Cursor->GetProperty( 0 )->SetLineWidth( 1.5 ); this->m_Cursor->GetProperty( 1 )->SetLineWidth( 1.5 ); this->m_Cursor->VisibilityOff( ); this->m_SuperCursor = vtkSmartPointer< CursorActors >::New( ); this->m_SuperCursor->SetImageBounds( image->GetBounds( ) ); this->m_SuperCursor->SetImageOrientation( orientation ); this->m_SuperCursor->GetProperty( 0 )->SetColor( 0, 1, 1 ); this->m_SuperCursor->GetProperty( 1 )->SetColor( 0, 1, 1 ); this->m_SuperCursor->GetProperty( 0 )->SetLineWidth( 1.5 ); this->m_SuperCursor->GetProperty( 1 )->SetLineWidth( 1.5 ); this->m_SuperCursor->VisibilityOff( ); // Prepare text this->m_TextBuffer[ 0 ] = '\0'; this->m_Text = vtkSmartPointer< vtkTextActor >::New( ); this->m_Text->SetTextScaleModeToNone( ); auto textprop = this->m_Text->GetTextProperty( ); textprop->SetColor( 1, 1, 0 ); textprop->SetFontFamilyToCourier( ); textprop->SetFontSize( 18 ); textprop->BoldOff( ); textprop->ItalicOff( ); textprop->ShadowOff( ); textprop->SetJustificationToLeft( ); textprop->SetVerticalJustificationToBottom( ); auto coord = this->m_Text->GetPositionCoordinate( ); coord->SetCoordinateSystemToNormalizedViewport( ); coord->SetValue( 0.01, 0.05 ); this->m_Text->VisibilityOff( ); // Update actor list this->m_Cursor->InitTraversal( ); while( vtkProp* prop = this->m_Cursor->GetNextProp( ) ) this->AddItem( prop ); this->m_SuperCursor->InitTraversal( ); while( vtkProp* prop = this->m_SuperCursor->GetNextProp( ) ) this->AddItem( prop ); this->AddItem( this->m_Text ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageViewerActors:: SetCursor( double* pos, bool neg ) { this->m_Cursor->SetCursor( pos, neg ); this->_ShowText( pos ); this->m_Cursor->VisibilityOn( ); this->m_Text->VisibilityOn( ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageViewerActors:: SetSuperCursor( double* pos, bool neg ) { this->SetCursor( pos, neg ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageViewerActors:: HideViewerActors( ) { this->m_Cursor->VisibilityOff( ); this->m_Text->VisibilityOff( ); } // ------------------------------------------------------------------------- cpExtensions::Visualization::ImageViewerActors:: ImageViewerActors( ) : Superclass( ) { } // ------------------------------------------------------------------------- cpExtensions::Visualization::ImageViewerActors:: ~ImageViewerActors( ) { } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageViewerActors:: _CorrectPosition( double* pos, int* ijk ) { auto image = this->GetImage( ); if( image == NULL ) return; // Approximate image index double pcoords[ 3 ]; image->ComputeStructuredCoordinates( pos, ijk, pcoords ); // Manually correct index int ext[ 6 ]; image->GetExtent( ext ); for( int i = 0; i < 3; ++i ) { if( ijk[ i ] < ext[ i << 1 ] ) ijk[ i ] = ext[ i << 1 ]; if( ext[ ( i << 1 ) + 1 ] < ijk[ i ] ) ijk[ i ] = ext[ ( i << 1 ) + 1 ]; } // rof // Get real coordinates int o = this->GetOrientation( ); ijk[ o ] = this->GetSliceNumber( ); image->GetPoint( image->ComputePointId( ijk ), pos ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageViewerActors:: _ShowText( double* pos ) { auto image = this->GetImage( ); if( image == NULL ) return; int ijk[ 3 ]; this->_CorrectPosition( pos, ijk ); int o = this->GetOrientation( ); std::stringstream buffer; buffer << "Axis: " << char( 'X' + char( o ) ) << std::endl; int nScl = image->GetNumberOfScalarComponents( ); buffer << "Pixel: [" << ijk[ 0 ] << "," << ijk[ 1 ] << "," << ijk[ 2 ] << "]=(" << image->GetScalarComponentAsFloat( ijk[ 0 ], ijk[ 1 ], ijk[ 2 ], 0 ); for( int n = 1; n < nScl; ++n ) buffer << " : " << image->GetScalarComponentAsFloat( ijk[ 0 ], ijk[ 1 ], ijk[ 2 ], n ); buffer << ")"; cpExtensions_SPRINTF( this->m_TextBuffer, 1024, buffer.str( ).c_str( ) ); this->m_Text->SetInput( this->m_TextBuffer ); this->m_Text->VisibilityOn( ); this->m_Text->Modified( ); } // eof - $RCSfile$