]> Creatis software - cpPlugins.git/blobdiff - lib/cpExtensions/Visualization/ImageInteractorStyle.cxx
Widget integration (step 5/6): generic widget controller finished and tested on linux...
[cpPlugins.git] / lib / cpExtensions / Visualization / ImageInteractorStyle.cxx
index b784808ede8fbff1b1a0ff37e3402a7018724748..aa688bff93ddfbc1e54ab54e6615c50bec858b43 100644 (file)
@@ -1,5 +1,304 @@
 #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>
 
@@ -682,5 +981,6 @@ _UpdateRadius( )
 
   this->Interactor->Render( );
 }
+*/
 
 // eof - $RCSfile$