X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpExtensions%2FInteraction%2FImageSliceStyle.cxx;h=a4770c08a0288ae8bce8d8735d8f898bbfe7a513;hb=4e55e875e42fe56e3fb92a38015ffa035ac9d0bb;hp=079903646511135f62ae4c5e661ae3a14bf5d92b;hpb=a422d88602e9b49085ccfab0ef0f9f2d93fb6a1e;p=cpPlugins.git diff --git a/lib/cpExtensions/Interaction/ImageSliceStyle.cxx b/lib/cpExtensions/Interaction/ImageSliceStyle.cxx index 0799036..a4770c0 100644 --- a/lib/cpExtensions/Interaction/ImageSliceStyle.cxx +++ b/lib/cpExtensions/Interaction/ImageSliceStyle.cxx @@ -1,3 +1,4 @@ +#include #include #include #include @@ -8,6 +9,10 @@ #include #include #include +#include +#include +#include + /* TODO #include */ @@ -20,6 +25,26 @@ New( ) return( new Self( ) ); } +// ------------------------------------------------------------------------- +int cpExtensions::Interaction::ImageSliceStyle:: +GetSliceNumber( ) const +{ + if( this->m_WLActor.GetPointer( ) != NULL ) + return( this->m_WLActor->GetSliceNumber( ) ); + else + return( -1 ); +} + +// ------------------------------------------------------------------------- +int cpExtensions::Interaction::ImageSliceStyle:: +GetOrientation( ) const +{ + if( this->m_WLActor.GetPointer( ) != NULL ) + return( this->m_WLActor->GetOrientation( ) ); + else + return( -1 ); +} + // ------------------------------------------------------------------------- void cpExtensions::Interaction::ImageSliceStyle:: OnMouseMove( ) @@ -31,9 +56,11 @@ OnMouseMove( ) if( this->_PickPointOnImageActor( idx, pnt ) ) { this->m_Cursor->SetCursor( pnt, false ); + this->_ShowText( pnt ); if( !cursor_visible ) { this->m_Cursor->VisibilityOn( ); + this->m_Text->VisibilityOn( ); cursor_visible = true; } // fi @@ -44,6 +71,7 @@ OnMouseMove( ) if( cursor_visible ) { this->m_Cursor->VisibilityOff( ); + this->m_Text->VisibilityOff( ); cursor_visible = false; this->Interactor->Render( ); @@ -51,7 +79,61 @@ OnMouseMove( ) } // fi - this->Superclass::OnMouseMove( ); + this->Overclass::OnMouseMove( ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::ImageSliceStyle:: +OnMouseWheelForward( ) +{ + static int s = 0; + if( this->m_WLActor.GetPointer( ) == NULL ) + return; + s = this->m_WLActor->GetSliceNumber( ); + s += ( this->Interactor->GetShiftKey( ) == 1 )? 10: 1; + this->m_WLActor->SetSliceNumber( s ); + s = this->m_WLActor->GetSliceNumber( ); + this->InvokeEvent( vtkCommand::UserEvent + 2, &s ); + this->Interactor->Render( ); + this->OnMouseMove( ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::ImageSliceStyle:: +OnMouseWheelBackward( ) +{ + static int s = 0; + if( this->m_WLActor.GetPointer( ) == NULL ) + return; + s = this->m_WLActor->GetSliceNumber( ); + s -= ( this->Interactor->GetShiftKey( ) == 1 )? 10: 1; + this->m_WLActor->SetSliceNumber( s ); + s = this->m_WLActor->GetSliceNumber( ); + this->InvokeEvent( vtkCommand::UserEvent + 2, &s ); + this->Interactor->Render( ); + this->OnMouseMove( ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::ImageSliceStyle:: +OnChar( ) +{ + switch( this->Interactor->GetKeyCode( ) ) + { + case 'r': case 'R': + { + this->FindPokedRenderer( + this->Interactor->GetEventPosition( )[ 0 ], + this->Interactor->GetEventPosition( )[ 1 ] + ); + this->CurrentRenderer->ResetCamera( ); + this->Interactor->Render( ); + } + break; + default: + break; + + } // hctiws } /* TODO @@ -168,6 +250,24 @@ ImageSliceStyle( ) this->m_Cursor->VisibilityOff( ); this->m_Cursor->GetProperty( 0 )->SetColor( 1, 1, 0 ); this->m_Cursor->GetProperty( 1 )->SetColor( 1, 1, 0 ); + + // 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( 12 ); + textprop->BoldOff( ); + textprop->ItalicOff( ); + textprop->ShadowOff( ); + textprop->SetJustificationToLeft( ); + textprop->SetVerticalJustificationToBottom( ); + auto coord = this->m_Text->GetPositionCoordinate( ); + coord->SetCoordinateSystemToNormalizedViewport( ); + coord->SetValue( 0.01, 0.02 ); + this->m_Text->VisibilityOff( ); } // ------------------------------------------------------------------------- @@ -176,52 +276,6 @@ cpExtensions::Interaction::ImageSliceStyle:: { } -// ------------------------------------------------------------------------- -vtkProp* cpExtensions::Interaction::ImageSliceStyle:: -_ImageActor( int i ) -{ - if( !this->CurrentRenderer ) - return( NULL ); - - vtkPropCollection* props = this->CurrentRenderer->GetViewProps( ); - vtkProp* prop = 0; - vtkAssemblyPath* path; - vtkImageSlice* imageProp = NULL; - vtkCollectionSimpleIterator pit; - - for( int k = 0; k < 2; k++ ) - { - int j = 0; - for( props->InitTraversal( pit ); ( prop = props->GetNextProp( pit ) ); ) - { - bool foundImageProp = false; - for( prop->InitPathTraversal( ); ( path = prop->GetNextPath( ) ); ) - { - vtkProp* tryProp = path->GetLastNode( )->GetViewProp( ); - if( ( imageProp = vtkImageSlice::SafeDownCast( tryProp ) ) != 0 ) - { - if( j == i ) - { - foundImageProp = true; - break; - - } // fi - imageProp = 0; - j++; - - } // fi - - } // rof - if( foundImageProp ) - break; - } // rof - if( i < 0 ) - i += j; - - } // rof - return( imageProp ); -} - // ------------------------------------------------------------------------- bool cpExtensions::Interaction::ImageSliceStyle:: _PickPointOnImageActor( int idx[ 2 ], double pnt[ 3 ] ) @@ -258,6 +312,7 @@ _PickPointOnImageActor( int idx[ 2 ], double pnt[ 3 ] ) this->m_Cursor->InitTraversal( ); while( vtkProp* prop = this->m_Cursor->GetNextProp( ) ) this->CurrentRenderer->AddViewProp( prop ); + this->CurrentRenderer->AddViewProp( this->m_Text ); } // fi if( this->m_WLActor.GetPointer( ) == NULL ) @@ -278,4 +333,73 @@ _PickPointOnImageActor( int idx[ 2 ], double pnt[ 3 ] ) return( true ); } +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::ImageSliceStyle:: +_CorrectPosition( double pos[ 3 ], int ijk[ 3 ] ) +{ + if( this->m_WLActor.GetPointer( ) == NULL ) + return; + auto image = this->m_WLActor->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->m_WLActor->GetOrientation( ); + ijk[ o ] = this->m_WLActor->GetSliceNumber( ); + image->GetPoint( image->ComputePointId( ijk ), pos ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::ImageSliceStyle:: +_ShowText( double pos[ 3 ] ) +{ + if( this->m_WLActor.GetPointer( ) == NULL ) + return; + auto image = this->m_WLActor->GetImage( ); + if( image == NULL ) + return; + + int ijk[ 3 ]; + this->_CorrectPosition( pos, ijk ); + int o = this->m_WLActor->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 << " >" << std::endl; + buffer + << "Point: (" + << pos[ 0 ] << ", " << pos[ 1 ] << ", " << pos[ 2 ] + << ")"; + 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$