#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( )
+{
+ // Get current position on the associated actors
+ vtkRenderWindowInteractor* rwi = this->GetInteractor( );
+ if( rwi == NULL || this->MouseMoveCommand == 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 );
+ ButtonID button = this->GetButtonID( );
+
+ // 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 );
+}
+
+// -------------------------------------------------------------------------
+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 );
+}
+
+// -------------------------------------------------------------------------
+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 );
+}
+
+// -------------------------------------------------------------------------
+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 );
+}
+
+// -------------------------------------------------------------------------
+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 );
+}
+
+// -------------------------------------------------------------------------
+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 );
+}
+
+// -------------------------------------------------------------------------
+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 );
+}
+
+// -------------------------------------------------------------------------
+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 );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageInteractorStyle::
+OnChar( )
+{
+ vtkRenderWindowInteractor* rwi = this->GetInteractor( );
+ if( rwi == NULL || this->KeyCommand == NULL )
+ return;
+ this->KeyCommand( this->Data, rwi->GetKeyCode( ) );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageInteractorStyle::
+OnExpose( )
+{
+ vtkRenderWindowInteractor* rwi = this->GetInteractor( );
+ if( rwi == NULL )
+ return;
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageInteractorStyle::
+OnConfigure( )
+{
+ vtkRenderWindowInteractor* rwi = this->GetInteractor( );
+ if( rwi == NULL )
+ return;
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageInteractorStyle::
+OnEnter( )
+{
+ vtkRenderWindowInteractor* rwi = this->GetInteractor( );
+ if( rwi == NULL )
+ return;
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageInteractorStyle::
+OnLeave( )
+{
+ vtkRenderWindowInteractor* rwi = this->GetInteractor( );
+ if( rwi == NULL )
+ return;
+}
+
+// -------------------------------------------------------------------------
+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->Interactor->Render( );
}
+*/
// eof - $RCSfile$