]> Creatis software - cpPlugins.git/blobdiff - lib/cpExtensions/Visualization/ImageInteractorStyle.cxx
Intermediary commit
[cpPlugins.git] / lib / cpExtensions / Visualization / ImageInteractorStyle.cxx
index 9dec0321ce99ff83cbd02a1a5756a9473326f27b..f0f01b1fe76d9739026f8a246a273ec3bd3b5264 100644 (file)
@@ -1,5 +1,332 @@
 #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>
 
@@ -42,7 +369,7 @@ Configure( ImageSliceActors* slice_actors, MPRActors* mpr_actors )
   this->m_SliceActors = slice_actors;
   this->m_MPRActors = mpr_actors;
   this->SetModeToNavigation( );
-  this->PropPicker->AddPickList( slice_actors->GetImageActor( ) );
+  this->PropPicker->AddPickList( slice_actors->GetImageActor( ) );
   this->Modified( );
 }
 
@@ -363,7 +690,7 @@ OnChar( )
   {
     if( this->m_MPRActors != NULL )
     {
-      this->m_MPRActors->ResetWindowLevel( );
+      this->m_MPRActors->ResetWindowLevel( );
       this->Interactor->Render( );
       this->_RenderAssociateInteractors( );
 
@@ -402,19 +729,19 @@ WindowLevel( )
       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( );
+    double maxw = this->m_MPRActors->GetMaxWindow( );
+    double minl = this->m_MPRActors->GetMinLevel( );
+    double maxl = this->m_MPRActors->GetMaxLevel( );
 
     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( );
   }
@@ -435,8 +762,8 @@ StartWindowLevel( )
   {
     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( );
+    this->WindowLevelInitial[ 1 ] = this->m_MPRActors->GetLevel( );
   }
   else if( this->Mode == Self::DeformationMode )
   {
@@ -682,5 +1009,6 @@ _UpdateRadius( )
 
   this->Interactor->Render( );
 }
+*/
 
 // eof - $RCSfile$