]> Creatis software - cpPlugins.git/commitdiff
Interaction improved: cursor
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Fri, 12 Dec 2014 17:29:02 +0000 (18:29 +0100)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Fri, 12 Dec 2014 17:29:02 +0000 (18:29 +0100)
appli/ImageMPR/ImageMPR.cxx
lib/cpPlugins/Extensions/Visualization/ImageInteractorStyle.cxx
lib/cpPlugins/Extensions/Visualization/ImageInteractorStyle.h
lib/cpPlugins/Extensions/Visualization/MPRActors.cxx

index 6181dc673940ca9e2e6e26a735bf5d34b65fabbb..6ee1fb02454f29fc0780cda1142d1690d6f08d18 100644 (file)
@@ -75,6 +75,34 @@ ImageMPR::ImageMPR( QWidget* parent )
   this->m_YStyle->SetModeToNavigation( );
   this->m_ZStyle->SetModeToNavigation( );
 
+  this->m_XStyle->AssociateInteractor(
+    this->m_UI->m_YPlaneVTK->GetInteractor( )
+    );
+  this->m_XStyle->AssociateInteractor(
+    this->m_UI->m_ZPlaneVTK->GetInteractor( )
+    );
+  this->m_XStyle->AssociateInteractor(
+    this->m_UI->m_3DVTK->GetInteractor( )
+    );
+  this->m_YStyle->AssociateInteractor(
+    this->m_UI->m_XPlaneVTK->GetInteractor( )
+    );
+  this->m_YStyle->AssociateInteractor(
+    this->m_UI->m_ZPlaneVTK->GetInteractor( )
+    );
+  this->m_YStyle->AssociateInteractor(
+    this->m_UI->m_3DVTK->GetInteractor( )
+    );
+  this->m_ZStyle->AssociateInteractor(
+    this->m_UI->m_XPlaneVTK->GetInteractor( )
+    );
+  this->m_ZStyle->AssociateInteractor(
+    this->m_UI->m_YPlaneVTK->GetInteractor( )
+    );
+  this->m_ZStyle->AssociateInteractor(
+    this->m_UI->m_3DVTK->GetInteractor( )
+    );
+
   QObject::connect(
     this->m_UI->actionOpenPlugins, SIGNAL( triggered( ) ),
     this, SLOT( _triggered_actionOpenPlugins( ) )
index 0c44df1743c95c1ddd3d1d92a9768976fb72ef56..d017cb2c3a8148f1aac4b43eed5def93db266643 100644 (file)
@@ -2,6 +2,7 @@
 
 #include <vtkAnnotatedCubeActor.h>
 #include <vtkAxesActor.h>
+#include <vtkCallbackCommand.h>
 #include <vtkCamera.h>
 #include <vtkCommand.h>
 #include <vtkPropAssembly.h>
@@ -36,6 +37,18 @@ Configure( ImageSliceActors* slice_actors, MPRActors* mpr_actors )
   this->Modified( );
 }
 
+// -------------------------------------------------------------------------
+void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
+AssociateInteractor( vtkRenderWindowInteractor* interactor )
+{
+  if( interactor != NULL )
+  {
+    this->AssociatedInteractors.push_back( interactor );
+    this->Modified( );
+
+  } // fi
+}
+
 // -------------------------------------------------------------------------
 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
 SetModeToNavigation( )
@@ -101,21 +114,77 @@ SetInteractor( vtkRenderWindowInteractor* interactor, const int& axis )
 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
 OnMouseMove( )
 {
-  std::cout << "moumov" << std::endl;
+  double pos[ 3 ];
+  if( this->CursorMoving && this->m_MPRActors != NULL )
+  {
+    bool picked = this->_PickPosition( pos );
+    if( picked )
+    {
+      for( int i = 0; i < 3; ++i )
+        if( this->m_SliceActors->GetAxis( ) != i )
+          this->m_MPRActors->SetSlice( i, pos[ i ] );
+      this->Interactor->Render( );
+      this->_RenderAssociateInteractors( );
+
+    } // fi
+
+  } // fi
 }
 
 // -------------------------------------------------------------------------
 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
 OnLeftButtonDown( )
 {
-  std::cout << "leftdown" << std::endl;
+  int x = this->Interactor->GetEventPosition( )[ 0 ];
+  int y = this->Interactor->GetEventPosition( )[ 1 ];
+
+  this->FindPokedRenderer( x, y );
+  if( this->CurrentRenderer == NULL )
+    return;
+
+  // Redefine this button to handle window/level
+  this->GrabFocus( this->EventCallbackCommand );
+
+  if( this->Interactor->GetControlKey( ) )
+    this->StartCursorMoving( );
+
+  /* TODO
+     if (!this->Interactor->GetShiftKey() && !this->Interactor->GetControlKey())
+     {
+     this->WindowLevelStartPosition[0] = x;
+     this->WindowLevelStartPosition[1] = y;
+     this->StartWindowLevel();
+     }
+
+     // If shift is held down, do a rotation
+     else if (this->InteractionMode == VTKIS_IMAGE3D &&
+     this->Interactor->GetShiftKey())
+     {
+     this->StartRotate();
+     }
+
+     // If ctrl is held down in slicing mode, slice the image
+     else if (this->InteractionMode == VTKIS_IMAGE_SLICING &&
+     this->Interactor->GetControlKey())
+     {
+     this->StartSlice();
+     }
+
+     // The rest of the button + key combinations remain the same
+
+     else
+     {
+     this->Superclass::OnLeftButtonDown();
+     }
+  */
 }
 
 // -------------------------------------------------------------------------
 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
 OnLeftButtonUp( )
 {
-  std::cout << "leftup" << std::endl;
+  if( this->CursorMoving )
+    this->EndCursorMoving( );
 }
 
 // -------------------------------------------------------------------------
@@ -150,14 +219,32 @@ OnRightButtonUp( )
 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
 OnMouseWheelForward( )
 {
-  std::cout << "whfwd" << std::endl;
+  if( this->m_SliceActors == NULL || this->Interactor == NULL )
+    return;
+  int off = 1;
+  if( this->Interactor->GetShiftKey( ) == 1 )
+    off *= 10;
+  int s = this->m_SliceActors->GetSliceNumber( ) + off;
+  int maxs = this->m_SliceActors->GetSliceNumberMaxValue( );
+  this->m_SliceActors->SetSliceNumber( ( s < maxs )? s: maxs );
+  this->Interactor->Render( );
+  this->_RenderAssociateInteractors( );
 }
 
 // -------------------------------------------------------------------------
 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
 OnMouseWheelBackward( )
 {
-  std::cout << "whbwd" << std::endl;
+  if( this->m_SliceActors == NULL || this->Interactor == NULL )
+    return;
+  int off = 1;
+  if( this->Interactor->GetShiftKey( ) == 1 )
+    off *= 10;
+  int s = this->m_SliceActors->GetSliceNumber( ) - off;
+  int mins = this->m_SliceActors->GetSliceNumberMinValue( );
+  this->m_SliceActors->SetSliceNumber( ( mins < s )? s: mins );
+  this->Interactor->Render( );
+  this->_RenderAssociateInteractors( );
 }
 
 // -------------------------------------------------------------------------
@@ -258,13 +345,32 @@ EndSlice( )
   std::cout << "es" << std::endl;
 }
 
+// -------------------------------------------------------------------------
+void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
+StartCursorMoving( )
+{
+  if( this->CursorMoving )
+    return;
+  this->CursorMoving = true;
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
+EndCursorMoving( )
+{
+  if( !( this->CursorMoving ) )
+    return;
+  this->CursorMoving = false;
+}
+
 // -------------------------------------------------------------------------
 cpPlugins::Extensions::Visualization::ImageInteractorStyle::
 ImageInteractorStyle( )
   : Superclass( ),
     Mode( Self::NavigationMode ),
     m_SliceActors( NULL ),
-    m_MPRActors( NULL )
+    m_MPRActors( NULL ),
+    CursorMoving( false )
 {
   // Orientation marks
   vtkSmartPointer< vtkAnnotatedCubeActor > cube =
@@ -312,14 +418,34 @@ ImageInteractorStyle( )
 cpPlugins::Extensions::Visualization::ImageInteractorStyle::
 ~ImageInteractorStyle( )
 {
-  std::cout << "destructor" << std::endl;
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
+_RenderAssociateInteractors( )
+{
+  std::vector< vtkRenderWindowInteractor* >::iterator rIt =
+    this->AssociatedInteractors.begin( );
+  for( ; rIt != this->AssociatedInteractors.end( ); ++rIt )
+    ( *rIt )->Render( );
 }
 
 // -------------------------------------------------------------------------
 bool cpPlugins::Extensions::Visualization::ImageInteractorStyle::
 _PickPosition( double pos[ 3 ] )
 {
-  std::cout << "pickpos" << std::endl;
+  if( this->m_SliceActors == NULL )
+    return( false );
+
+  double x = double( this->Interactor->GetEventPosition( )[ 0 ] );
+  double y = double( this->Interactor->GetEventPosition( )[ 1 ] );
+  this->FindPokedRenderer( x, y );
+  int success =
+    this->PropPicker->Pick( x, y, double( 0 ), this->CurrentRenderer );
+  if( success == 0 )
+    return( false );
+  this->PropPicker->GetPickPosition( pos );
+  return( true );
 }
 
 // -------------------------------------------------------------------------
index b618f5e47931056a8da9582e4d106ac5f7a4b04f..2eb6f12390013b2bb3bb2bc5fb6026bf4b12c722 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef __CPPLUGINS__EXTENSIONS__VISUALIZATION__IMAGEINTERACTORSTYLE__H__
 #define __CPPLUGINS__EXTENSIONS__VISUALIZATION__IMAGEINTERACTORSTYLE__H__
 
+#include <vector>
+
 #include <vtkInteractorStyleImage.h>
 #include <vtkOrientationMarkerWidget.h>
 #include <vtkPropPicker.h>
@@ -47,6 +49,7 @@ namespace cpPlugins
           ImageSliceActors* slice_actors,
           MPRActors* mpr_actors = NULL
           );
+        void AssociateInteractor( vtkRenderWindowInteractor* interactor );
 
         void SetModeToNavigation( );
         void SetModeToDeformation( );
@@ -92,10 +95,15 @@ namespace cpPlugins
         virtual void StartSlice( );
         virtual void EndSlice( );
 
+        // New events
+        virtual void StartCursorMoving( );
+        virtual void EndCursorMoving( );
+
       protected:
         ImageInteractorStyle( );
         virtual ~ImageInteractorStyle( );
 
+        void _RenderAssociateInteractors( );
         bool _PickPosition( double pos[ 3 ] );
         void _UpdateCursor( );
 
@@ -113,6 +121,10 @@ namespace cpPlugins
         vtkSmartPointer< vtkOrientationMarkerWidget > OrientationWidget;
         vtkSmartPointer< vtkPropPicker > PropPicker;
 
+        std::vector< vtkRenderWindowInteractor* > AssociatedInteractors;
+
+        bool CursorMoving;
+
       public:
         static const int SliceEvent;
       };
index 1843fb17cbb0882b4831455db8c5392f109f4fca..b8332786b7ad36d2afcdfc381c1b594554bf559b 100644 (file)
@@ -287,30 +287,59 @@ GetSlicePlane( const int& axis ) const
 int cpPlugins::Extensions::Visualization::MPRActors::
 GetSliceNumberMinValue( const int& axis ) const
 {
+  return( this->Slices[ axis ]->GetSliceNumberMinValue( ) );
 }
 
 // -------------------------------------------------------------------------
 int cpPlugins::Extensions::Visualization::MPRActors::
 GetSliceNumberMaxValue( const int& axis ) const
 {
+  return( this->Slices[ axis ]->GetSliceNumberMaxValue( ) );
 }
 
 // -------------------------------------------------------------------------
 int cpPlugins::Extensions::Visualization::MPRActors::
 GetSlice( const int& axis ) const
 {
+  return( this->Slices[ axis ]->GetSliceNumber( ) );
 }
 
 // -------------------------------------------------------------------------
 void cpPlugins::Extensions::Visualization::MPRActors::
 SetSlice( const int& axis, const int& slice )
 {
+  // Get image data extent
+  if( this->Image == NULL )
+    return;
+  int ext[ 6 ];
+  this->Image->GetExtent( ext );
+
+  // Check if the slice is valid
+  int real = slice;
+  if( slice < ext[ axis << 1 ] )
+    real = ext[ axis << 1 ];
+  if( ext[ ( axis << 1 ) + 1 ] < slice )
+    real = ext[ ( axis << 1 ) + 1 ];
+
+  // Change slice
+  this->Slices[ axis ]->SetSliceNumber( real );
+  this->Modified( );
 }
 
 // -------------------------------------------------------------------------
 void cpPlugins::Extensions::Visualization::MPRActors::
 SetSlice( const int& axis, const double& slice )
 {
+  if( this->Image == NULL )
+    return;
+  
+  double x[ 3 ] = { double( 0 ) };
+  double pcoords[ 3 ];
+  int ijk[ 3 ];
+
+  x[ axis ] = slice;
+  this->Image->ComputeStructuredCoordinates( x, ijk, pcoords );
+  this->SetSlice( axis, ijk[ axis ] );
 }
 
 // -------------------------------------------------------------------------