#include <cpExtensions/Visualization/ImageInteractorStyle.h>
+#include <vtkImageActor.h>
+#include <vtkRenderWindowInteractor.h>
+
+// -------------------------------------------------------------------------
+cpExtensions::Visualization::ImageInteractorStyle::
+Self* cpExtensions::Visualization::ImageInteractorStyle::
+New( )
+{
+ return( new Self );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageInteractorStyle::
+AssociateView( void* data )
+{
+ this->Data = data;
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageInteractorStyle::
+AssociateImageActor( vtkImageActor* actor )
+{
+ this->PropPicker->AddPickList( actor );
+ this->Modified( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageInteractorStyle::
+OnMouseMove( )
+{
+ this->Superclass::OnMouseMove( );
+
+ // Get current position on the associated actors
+ vtkRenderWindowInteractor* rwi = this->GetInteractor( );
+ if( rwi == NULL || this->MouseMoveCommand == NULL )
+ return;
+
+ // Get modifiers
+ bool alt = ( rwi->GetAltKey( ) == 1 );
+ bool ctr = ( rwi->GetControlKey( ) == 1 );
+ bool sft = ( rwi->GetShiftKey( ) == 1 );
+ ButtonID button = this->GetButtonID( );
+
+ double pos[ 3 ];
+ if( !( this->_PickPosition( pos ) ) )
+ return;
+
+ // Invoke possible events
+ this->MouseMoveCommand( this->Data, button, pos, alt, ctr, sft );
+ rwi->Render( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageInteractorStyle::
+OnMouseWheelForward( )
+{
+ vtkRenderWindowInteractor* rwi = this->GetInteractor( );
+ if( rwi == NULL || this->MouseWheelCommand == NULL )
+ return;
+
+ // Get modifiers
+ bool alt = ( rwi->GetAltKey( ) == 1 );
+ bool ctr = ( rwi->GetControlKey( ) == 1 );
+ bool sft = ( rwi->GetShiftKey( ) == 1 );
+
+ // Invoke possible events
+ this->MouseWheelCommand( this->Data, 1, alt, ctr, sft );
+ rwi->Render( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageInteractorStyle::
+OnMouseWheelBackward( )
+{
+ vtkRenderWindowInteractor* rwi = this->GetInteractor( );
+ if( rwi == NULL || this->MouseWheelCommand == NULL )
+ return;
+
+ // Get modifiers
+ bool alt = ( rwi->GetAltKey( ) == 1 );
+ bool ctr = ( rwi->GetControlKey( ) == 1 );
+ bool sft = ( rwi->GetShiftKey( ) == 1 );
+
+ // Invoke possible events
+ this->MouseWheelCommand( this->Data, -1, alt, ctr, sft );
+ rwi->Render( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageInteractorStyle::
+OnLeftClick( )
+{
+ // Get current position on the associated actors
+ vtkRenderWindowInteractor* rwi = this->GetInteractor( );
+ if( rwi == NULL || this->MouseClickCommand == NULL )
+ return;
+ double pos[ 3 ];
+ if( !( this->_PickPosition( pos ) ) )
+ return;
+
+ // Get modifiers
+ bool alt = ( rwi->GetAltKey( ) == 1 );
+ bool ctr = ( rwi->GetControlKey( ) == 1 );
+ bool sft = ( rwi->GetShiftKey( ) == 1 );
+
+ // Invoke possible events
+ this->MouseClickCommand(
+ this->Data, Self::ButtonID_Left, pos, alt, ctr, sft
+ );
+ rwi->Render( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageInteractorStyle::
+OnLeftDoubleClick( )
+{
+ // Get current position on the associated actors
+ vtkRenderWindowInteractor* rwi = this->GetInteractor( );
+ if( rwi == NULL || this->MouseDoubleClickCommand == NULL )
+ return;
+ double pos[ 3 ];
+ if( !( this->_PickPosition( pos ) ) )
+ return;
+
+ // Get modifiers
+ bool alt = ( rwi->GetAltKey( ) == 1 );
+ bool ctr = ( rwi->GetControlKey( ) == 1 );
+ bool sft = ( rwi->GetShiftKey( ) == 1 );
+
+ // Invoke possible events
+ this->MouseDoubleClickCommand(
+ this->Data, Self::ButtonID_Left, pos, alt, ctr, sft
+ );
+ rwi->Render( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageInteractorStyle::
+OnMiddleClick( )
+{
+ // Get current position on the associated actors
+ vtkRenderWindowInteractor* rwi = this->GetInteractor( );
+ if( rwi == NULL || this->MouseClickCommand == NULL )
+ return;
+ double pos[ 3 ];
+ if( !( this->_PickPosition( pos ) ) )
+ return;
+
+ // Get modifiers
+ bool alt = ( rwi->GetAltKey( ) == 1 );
+ bool ctr = ( rwi->GetControlKey( ) == 1 );
+ bool sft = ( rwi->GetShiftKey( ) == 1 );
+
+ // Invoke possible events
+ this->MouseClickCommand(
+ this->Data, Self::ButtonID_Middle, pos, alt, ctr, sft
+ );
+ rwi->Render( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageInteractorStyle::
+OnMiddleDoubleClick( )
+{
+ // Get current position on the associated actors
+ vtkRenderWindowInteractor* rwi = this->GetInteractor( );
+ if( rwi == NULL || this->MouseDoubleClickCommand == NULL )
+ return;
+ double pos[ 3 ];
+ if( !( this->_PickPosition( pos ) ) )
+ return;
+
+ // Get modifiers
+ bool alt = ( rwi->GetAltKey( ) == 1 );
+ bool ctr = ( rwi->GetControlKey( ) == 1 );
+ bool sft = ( rwi->GetShiftKey( ) == 1 );
+
+ // Invoke possible events
+ this->MouseDoubleClickCommand(
+ this->Data, Self::ButtonID_Middle, pos, alt, ctr, sft
+ );
+ rwi->Render( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageInteractorStyle::
+OnRightClick( )
+{
+ // Get current position on the associated actors
+ vtkRenderWindowInteractor* rwi = this->GetInteractor( );
+ if( rwi == NULL || this->MouseClickCommand == NULL )
+ return;
+ double pos[ 3 ];
+ if( !( this->_PickPosition( pos ) ) )
+ return;
+
+ // Get modifiers
+ bool alt = ( rwi->GetAltKey( ) == 1 );
+ bool ctr = ( rwi->GetControlKey( ) == 1 );
+ bool sft = ( rwi->GetShiftKey( ) == 1 );
+
+ // Invoke possible events
+ this->MouseClickCommand(
+ this->Data, Self::ButtonID_Right, pos, alt, ctr, sft
+ );
+ rwi->Render( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageInteractorStyle::
+OnRightDoubleClick( )
+{
+ // Get current position on the associated actors
+ vtkRenderWindowInteractor* rwi = this->GetInteractor( );
+ if( rwi == NULL || this->MouseDoubleClickCommand == NULL )
+ return;
+ double pos[ 3 ];
+ if( !( this->_PickPosition( pos ) ) )
+ return;
+
+ // Get modifiers
+ bool alt = ( rwi->GetAltKey( ) == 1 );
+ bool ctr = ( rwi->GetControlKey( ) == 1 );
+ bool sft = ( rwi->GetShiftKey( ) == 1 );
+
+ // Invoke possible events
+ this->MouseDoubleClickCommand(
+ this->Data, Self::ButtonID_Right, pos, alt, ctr, sft
+ );
+ rwi->Render( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageInteractorStyle::
+OnChar( )
+{
+ vtkRenderWindowInteractor* rwi = this->GetInteractor( );
+ if( rwi == NULL || this->KeyCommand == NULL )
+ return;
+ this->KeyCommand( this->Data, rwi->GetKeyCode( ) );
+ rwi->Render( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageInteractorStyle::
+OnExpose( )
+{
+ vtkRenderWindowInteractor* rwi = this->GetInteractor( );
+ if( rwi == NULL )
+ return;
+ rwi->Render( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageInteractorStyle::
+OnConfigure( )
+{
+ vtkRenderWindowInteractor* rwi = this->GetInteractor( );
+ if( rwi == NULL )
+ return;
+ rwi->Render( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageInteractorStyle::
+OnEnter( )
+{
+ vtkRenderWindowInteractor* rwi = this->GetInteractor( );
+ if( rwi == NULL )
+ return;
+ rwi->Render( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageInteractorStyle::
+OnLeave( )
+{
+ vtkRenderWindowInteractor* rwi = this->GetInteractor( );
+ if( rwi == NULL )
+ return;
+ rwi->Render( );
+}
+
+// -------------------------------------------------------------------------
+cpExtensions::Visualization::ImageInteractorStyle::
+ImageInteractorStyle( )
+ : Superclass( ),
+ Data( NULL ),
+ MouseMoveCommand( NULL ),
+ MouseClickCommand( NULL ),
+ MouseDoubleClickCommand( NULL ),
+ MouseWheelCommand( NULL ),
+ KeyCommand( NULL )
+{
+ this->PropPicker = vtkSmartPointer< vtkPropPicker >::New( );
+ this->PropPicker->PickFromListOn( );
+}
+
+// -------------------------------------------------------------------------
+cpExtensions::Visualization::ImageInteractorStyle::
+~ImageInteractorStyle( )
+{
+}
+
+// -------------------------------------------------------------------------
+bool cpExtensions::Visualization::ImageInteractorStyle::
+_PickPosition( double pos[ 3 ] )
+{
+ vtkRenderWindowInteractor* rwi = this->GetInteractor( );
+ if( rwi == NULL )
+ return( false );
+
+ // Find the renderer where the event has been raised
+ double x = double( rwi->GetEventPosition( )[ 0 ] );
+ double y = double( rwi->GetEventPosition( )[ 1 ] );
+ this->FindPokedRenderer( x, y );
+
+ // Pick a 3D position
+ int r = this->PropPicker->Pick( x, y, double( 0 ), this->CurrentRenderer );
+ if( r == 0 )
+ return( false );
+ this->PropPicker->GetPickPosition( pos );
+
+ return( true );
+}
+
+/*
#include <cmath>
#include <ctime>
this->m_SliceActors = slice_actors;
this->m_MPRActors = mpr_actors;
this->SetModeToNavigation( );
- this->PropPicker->AddPickList( slice_actors->GetImageActor( ) );
+ this->PropPicker->AddPickList( slice_actors->GetImageActor( 0 ) );
this->Modified( );
}
{
if( this->m_MPRActors != NULL )
{
- this->m_MPRActors->ResetWindowLevel( );
+ this->m_MPRActors->ResetWindowLevel( 0 );
this->Interactor->Render( );
this->_RenderAssociateInteractors( );
this->WindowLevelCurrentPosition[ 1 ]
) / double( size[ 1 ] );
- double w = this->WindowLevelInitial[ 0 ] * ( double( 1 ) + sw );
- double l = this->WindowLevelInitial[ 1 ] * ( double( 1 ) + sl );
- double minw = this->m_MPRActors->GetMinWindow( );
- double maxw = this->m_MPRActors->GetMaxWindow( );
- double minl = this->m_MPRActors->GetMinLevel( );
- double maxl = this->m_MPRActors->GetMaxLevel( );
+ double w = this->WindowLevelInitial[ 0 ] + ( sw * 1000.0 );
+ double l = this->WindowLevelInitial[ 1 ] + ( sl * 1000.0 );
+ double minw = this->m_MPRActors->GetMinWindow( 0 );
+ double maxw = this->m_MPRActors->GetMaxWindow( 0 );
+ double minl = this->m_MPRActors->GetMinLevel( 0 );
+ double maxl = this->m_MPRActors->GetMaxLevel( 0 );
if( w < minw ) w = minw;
if( maxw < w ) w = maxw;
if( l < minl ) l = minl;
if( maxl < l ) l = maxl;
- this->m_MPRActors->SetWindowLevel( w, l );
+ this->m_MPRActors->SetWindowLevel( 0, w, l );
this->Interactor->Render( );
this->_RenderAssociateInteractors( );
}
{
this->StartState( VTKIS_WINDOW_LEVEL );
- this->WindowLevelInitial[ 0 ] = this->m_MPRActors->GetWindow( );
- this->WindowLevelInitial[ 1 ] = this->m_MPRActors->GetLevel( );
+ this->WindowLevelInitial[ 0 ] = this->m_MPRActors->GetWindow( 0 );
+ this->WindowLevelInitial[ 1 ] = this->m_MPRActors->GetLevel( 0 );
}
else if( this->Mode == Self::DeformationMode )
{
this->Interactor->Render( );
}
+*/
// eof - $RCSfile$