#include <cpExtensions/Interaction/ImageSliceStyle.h>
#include <cpExtensions/Visualization/CursorActors.h>
+#include <cpExtensions/Visualization/LUTImageActor.h>
#include <cpExtensions/Visualization/WindowLevelImageActor.h>
#include <vtkAssemblyPath.h>
+#include <vtkCommand.h>
#include <vtkImageData.h>
#include <vtkImageSlice.h>
#include <vtkProperty.h>
#include <vtkPropCollection.h>
#include <vtkPropPicker.h>
#include <vtkRenderer.h>
-/* TODO
- #include <cpExtensions/Visualization/ImageViewerActors.h>
-*/
+#include <vtkRenderWindowInteractor.h>
+#include <vtkTextActor.h>
+#include <vtkTextProperty.h>
+#include <sstream>
// -------------------------------------------------------------------------
cpExtensions::Interaction::ImageSliceStyle::
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( )
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
if( cursor_visible )
{
this->m_Cursor->VisibilityOff( );
+ this->m_Text->VisibilityOff( );
cursor_visible = false;
this->Interactor->Render( );
} // 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( );
+ if( this->m_LUTActor.GetPointer( ) != NULL )
+ this->m_LUTActor->SetSliceNumber( s );
+ 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( );
+ if( this->m_LUTActor.GetPointer( ) != NULL )
+ this->m_LUTActor->SetSliceNumber( s );
+ 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
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( );
}
// -------------------------------------------------------------------------
{
}
-// -------------------------------------------------------------------------
-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 ] )
this->m_PropPicker->GetPickList( )->RemoveAllItems( );
this->m_PropPicker->AddPickList( curr_actor );
+ auto props = this->CurrentRenderer->GetViewProps( );
+ this->m_LUTActor = NULL;
+ props->InitTraversal( );
+ vtkProp* prop;
+ while( ( ( prop = props->GetNextProp( ) ) != NULL ) && ( this->m_LUTActor.GetPointer( ) == NULL ) )
+ this->m_LUTActor = dynamic_cast< TLUTActor* >( prop );
+
this->m_Cursor->SetImageBounds( curr_actor->GetImage( )->GetBounds( ) );
this->m_Cursor->SetImageOrientation( curr_actor->GetOrientation( ) );
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 )
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$