]> Creatis software - cpPlugins.git/blobdiff - lib/cpExtensions/Interaction/ImageInteractorStyle.cxx
MPR objects updated
[cpPlugins.git] / lib / cpExtensions / Interaction / ImageInteractorStyle.cxx
index c037193fe97097b0d960316109a6dd0ae477f0aa..f2781dcfb6f2e633915c4a2a73d2899c0ca2d866 100644 (file)
@@ -1,41 +1,47 @@
 #include <cpExtensions/Interaction/ImageInteractorStyle.h>
 
+#include <vtkCamera.h>
 #include <vtkCommand.h>
 #include <vtkImageActor.h>
+#include <vtkImageMapper3D.h>
+#include <vtkImageSliceMapper.h>
 #include <vtkPropCollection.h>
 #include <vtkProperty.h>
 #include <vtkRenderWindowInteractor.h>
+#include <vtkRenderer.h>
 
 // -------------------------------------------------------------------------
-cpExtensions::Interaction::ImageInteractorStyle::TSeedWidget::
-TSeedWidget( vtkRenderWindowInteractor* interactor, vtkImageActor* actor )
-{
-  this->Placer = vtkSmartPointer< vtkImageActorPointPlacer >::New( );
-  this->Handle = vtkSmartPointer< vtkPointHandleRepresentation3D >::New( );
-  this->Representation = vtkSmartPointer< vtkSeedRepresentation >::New( );
-  this->Widget = vtkSmartPointer< SeedWidget >::New( );
-
-  this->Placer->SetImageActor( actor );
-  this->Handle->GetProperty( )->SetColor( 1, 0, 0 );
-  this->Handle->SetPointPlacer( this->Placer );
-  this->Representation->SetHandleRepresentation( this->Handle );
-  this->Widget->SetRepresentation( this->Representation );
-  this->Widget->SetInteractor( interactor );
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::Interaction::ImageInteractorStyle::TSeedWidget::
-On( )
-{
-  this->Widget->On( );
-}
+/* TODO
+   cpExtensions::Interaction::ImageInteractorStyle::TSeedWidget::
+   TSeedWidget( vtkRenderWindowInteractor* interactor, vtkImageActor* actor )
+   {
+   this->Placer = vtkSmartPointer< vtkImageActorPointPlacer >::New( );
+   this->Handle = vtkSmartPointer< vtkPointHandleRepresentation3D >::New( );
+   this->Representation = vtkSmartPointer< vtkSeedRepresentation >::New( );
+   this->Widget = vtkSmartPointer< SeedWidget >::New( );
 
-// -------------------------------------------------------------------------
-void cpExtensions::Interaction::ImageInteractorStyle::TSeedWidget::
-Off( )
-{
-  this->Widget->Off( );
-}
+   this->Placer->SetImageActor( actor );
+   this->Handle->GetProperty( )->SetColor( 1, 0, 0 );
+   this->Handle->SetPointPlacer( this->Placer );
+   this->Representation->SetHandleRepresentation( this->Handle );
+   this->Widget->SetRepresentation( this->Representation );
+   this->Widget->SetInteractor( interactor );
+   }
+   
+   // -------------------------------------------------------------------------
+   void cpExtensions::Interaction::ImageInteractorStyle::TSeedWidget::
+   On( )
+   {
+   this->Widget->On( );
+   }
+   
+   // -------------------------------------------------------------------------
+   void cpExtensions::Interaction::ImageInteractorStyle::TSeedWidget::
+   Off( )
+   {
+   this->Widget->Off( );
+   }
+*/
 
 // -------------------------------------------------------------------------
 cpExtensions::Interaction::ImageInteractorStyle::
@@ -45,19 +51,52 @@ New( )
   return( new Self );
 }
 
+// -------------------------------------------------------------------------
+void cpExtensions::Interaction::ImageInteractorStyle::
+SetCurrentRenderer( vtkRenderer* r )
+{
+  this->Superclass::SetCurrentRenderer( r );
+
+  if( !( this->m_Configured ) )
+  {
+    auto lst = this->m_PropPicker->GetPickList( );
+    if( lst == NULL )
+      return;
+    if( lst->GetNumberOfItems( ) == 1 )
+    {
+      auto actor = dynamic_cast< vtkImageActor* >( lst->GetItemAsObject( 0 ) );
+      if( actor != NULL )
+      {
+        this->_ConfigureCamera( actor );
+        this->Modified( );
+
+      } // fi
+
+    } // fi
+
+  } // fi
+}
+
 // -------------------------------------------------------------------------
 void cpExtensions::Interaction::ImageInteractorStyle::
 AssociateImageActor( vtkImageActor* actor )
 {
   if( actor != NULL )
   {
+    // Update picker
+    this->m_PropPicker->GetPickList( )->RemoveAllItems( );
     this->m_PropPicker->AddPickList( actor );
+    this->m_Configured = false;
+    this->_ConfigureCamera( actor );
+
+    // Ok, done
     this->Modified( );
 
   } // fi
 }
 
 // -------------------------------------------------------------------------
+/*
 void cpExtensions::Interaction::ImageInteractorStyle::
 SeedWidgetOn( )
 {
@@ -85,8 +124,10 @@ SeedWidgetOff( )
 
   } // fi
 }
+*/
 
 // -------------------------------------------------------------------------
+/*
 void cpExtensions::Interaction::ImageInteractorStyle::
 SetSeedWidgetCommand( vtkCommand* cmd )
 {
@@ -118,17 +159,20 @@ GetSeedAsPoint( unsigned int id, double pos[ 3 ] ) const
 void cpExtensions::Interaction::ImageInteractorStyle::
 GetSeedAsIndex( unsigned int id, int idx[ 3 ] ) const
 {
-  /* TODO
      if( this->m_SeedWidget != NULL )
      this->m_SeedWidget->Representation->GetSeedWorldPosition( id, pos );
-  */
 }
+*/
 
 // -------------------------------------------------------------------------
 cpExtensions::Interaction::ImageInteractorStyle::
 ImageInteractorStyle( )
   : Superclass( ),
-    m_SeedWidget( NULL )
+    m_Configured( false )
+    /*
+      ,
+      m_SeedWidget( NULL )
+    */
 {
   this->m_PropPicker = vtkSmartPointer< vtkPropPicker >::New( );
   this->m_PropPicker->PickFromListOn( );
@@ -138,7 +182,54 @@ ImageInteractorStyle( )
 cpExtensions::Interaction::ImageInteractorStyle::
 ~ImageInteractorStyle( )
 {
-  if( this->m_SeedWidget != NULL ) delete this->m_SeedWidget;
+  // if( this->m_SeedWidget != NULL ) delete this->m_SeedWidget;
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Interaction::ImageInteractorStyle::
+_ConfigureCamera( vtkImageActor* actor )
+{
+  if( this->CurrentRenderer != NULL )
+  {
+    // Update camera
+    auto camera = this->CurrentRenderer->GetActiveCamera( );
+    auto mapper = dynamic_cast< vtkImageSliceMapper* >( actor->GetMapper( ) );
+    if( mapper != NULL && camera != NULL )
+    {
+      double bounds[ 6 ];
+      actor->GetBounds( bounds );
+      camera->ParallelProjectionOn( );
+      camera->SetFocalPoint( double( 0 ), double( 0 ), double( 0 ) );
+      int orientation = mapper->GetOrientation( );
+      switch( orientation )
+      {
+      case 0:
+      {
+        camera->SetPosition( double( 1 ), double( 0 ), double( 0 ) );
+        camera->SetViewUp  ( double( 0 ), double( 1 ), double( 0 ) );
+      }
+      break;
+      case 1:
+      {
+        camera->SetPosition( double( 0 ), double( 1 ), double( 0 ) );
+        camera->SetViewUp  ( double( 0 ), double( 0 ), double( -1 ) );
+      }
+      break;
+      case 2:
+      {
+        camera->SetPosition( double( 0 ), double( 0 ), double( 1 ) );
+        camera->SetViewUp  ( double( 0 ), double( 1 ), double( 0 ) );
+      }
+      break;
+      default:
+        break;
+      } // hctiws
+      this->CurrentRenderer->ResetCamera( );
+      this->m_Configured = true;
+
+    } // fi
+
+  } // fi
 }
 
 // -------------------------------------------------------------------------