]> Creatis software - cpPlugins.git/commitdiff
MPR almost working with multiple images
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Sat, 26 Sep 2015 23:07:01 +0000 (01:07 +0200)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Sat, 26 Sep 2015 23:07:01 +0000 (01:07 +0200)
appli/ImageMPR/ImageMPR.cxx
lib/cpExtensions/Visualization/ImageSliceActors.cxx
lib/cpExtensions/Visualization/MPRActors.cxx
lib/cpExtensions/Visualization/MPRActors.h
lib/cpExtensions/Visualization/MPRObjects.cxx
lib/cpExtensions/Visualization/MPRObjects.h

index 24cfd389fe26e4882db063a79f1c76ded0e89b39..f9a7934562c921846f4aea4cc7ba7a3010997c9b 100644 (file)
@@ -211,6 +211,7 @@ _triggered_actionOpenInputImage( )
       if( vtk_id != NULL )
       {
         this->m_MPRObjects->SetImage( vtk_id );
+        this->m_MPRObjects->ActivateInteractors( );
         this->m_MPRObjects->ResetCameras( );
         this->m_MPRObjects->RenderAll( );
       }
index 562179e2432ac109fcac6c572cc11f0e5391353c..52be1f1ddeb099e82990b032f4e002038356c40b 100644 (file)
@@ -33,8 +33,6 @@ AddInputConnection( vtkAlgorithmOutput* aout, int axis )
     );
   mapper->Update( );
   
-  this->SetSliceNumber( this->SliceMappers[ 0 ]->GetSliceNumber( ) );
-
   vtkSmartPointer< vtkImageActor > actor =
     vtkSmartPointer< vtkImageActor >::New( );
   this->ImageActors.push_back( actor );
@@ -65,8 +63,6 @@ AddInputData( vtkImageData* data, int axis )
     ( nImages == 0 )? axis: this->SliceMappers[ 0 ]->GetOrientation( )
     );
   mapper->Update( );
-  
-  this->SetSliceNumber( this->SliceMappers[ 0 ]->GetSliceNumber( ) );
 
   vtkSmartPointer< vtkImageActor > actor =
     vtkSmartPointer< vtkImageActor >::New( );
index 4be68644800a8301c35262277d1b07be7b39654b..90fdb7d83c7f68842d4d356191b61bdeedbe03c0 100644 (file)
@@ -3,6 +3,8 @@
 #include <vtkAlgorithmOutput.h>
 #include <vtkImageData.h>
 #include <vtkInformation.h>
+#include <vtkOutlineSource.h>
+#include <vtkProperty.h>
 #include <vtkRenderer.h>
 #include <vtkWindowLevelLookupTable.h>
 
@@ -429,7 +431,11 @@ SetSlice( const int& axis, const double& slice )
 void cpExtensions::Visualization::MPRActors::
 ResetSlices( )
 {
-  // TODO
+  for( unsigned int i = 0; i < 2; ++i )
+    for( unsigned int j = 0; j < 3; ++j )
+      this->Slices[ i ][ j ]->SetSliceNumber(
+        this->Slices[ i ][ j ]->GetSliceNumberMinValue( )
+        );
 }
 
 // -------------------------------------------------------------------------
@@ -469,43 +475,45 @@ _Image( unsigned int i ) const
 void cpExtensions::Visualization::MPRActors::
 _Update( unsigned int i )
 {
-  /*
   // Check if the input has been configured
-  vtkImageData* image = this->_InputImage( );
+  vtkImageData* image = this->_Image( i );
   if( image == NULL )
     return;
-  this->ImageMapToColors->Update( );
+  this->ImageMaps[ i ]->Update( );
 
   for( int j = 0; j < 2; ++j )
   {
-    for( int i = 0; i < 3; ++i )
+    for( int k = 0; k < 3; ++k )
     {
-      this->Slices[ j ][ i ]->AddInputConnection(
-        this->ImageMapToColors->GetOutputPort( ), i
+      this->Slices[ j ][ k ]->AddInputConnection(
+        this->ImageMaps[ i ]->GetOutputPort( ), k
         );
-      this->Slices[ j ][ i ]->UpdateText( );
+      this->Slices[ j ][ k ]->UpdateText( );
 
     } // rof
 
   } // rof
 
-  // Create 3D outline
-  double bb[ 6 ];
-  image->GetBounds( bb );
+  if( i == 0 )
+  {
+    // Create 3D outline
+    double bb[ 6 ];
+    image->GetBounds( bb );
+
+    vtkSmartPointer< vtkOutlineSource > img_ol =
+      vtkSmartPointer< vtkOutlineSource >::New( );
+    img_ol->SetBounds( bb );
 
-  vtkSmartPointer< vtkOutlineSource > img_ol =
-    vtkSmartPointer< vtkOutlineSource >::New( );
-  img_ol->SetBounds( bb );
+    vtkSmartPointer< vtkPolyDataMapper > img_ol_mapper =
+      vtkSmartPointer< vtkPolyDataMapper >::New( );
+    img_ol_mapper->SetInputConnection( img_ol->GetOutputPort( ) );
+    this->ImageOutlineActor->SetMapper( img_ol_mapper );
+    this->ImageOutlineActor->GetProperty( )->SetColor( 1, 1, 1 );
+    this->ImageOutlineActor->GetProperty( )->SetLineWidth( 1 );
 
-  vtkSmartPointer< vtkPolyDataMapper > img_ol_mapper =
-    vtkSmartPointer< vtkPolyDataMapper >::New( );
-  img_ol_mapper->SetInputConnection( img_ol->GetOutputPort( ) );
-  this->ImageOutlineActor->SetMapper( img_ol_mapper );
-  this->ImageOutlineActor->GetProperty( )->SetColor( 1, 1, 1 );
-  this->ImageOutlineActor->GetProperty( )->SetLineWidth( 1 );
+    this->AddItem( this->ImageOutlineActor );
 
-  this->AddItem( this->ImageOutlineActor );
-  */
+  } // fi
 }
 
 // eof - $RCSfile$
index 72389be28af55b86d94c96ddc11d503d2aee0103..0aafebef6f5ab227410ac9b594e32dfdda72edde 100644 (file)
@@ -58,6 +58,12 @@ namespace cpExtensions
         vtkRenderer* z,
         vtkRenderer* w
         );
+      void LinkInteractors( )
+        {
+          this->_Update( 0 );
+          this->_Update( 1 );
+          this->_Update( 2 );
+        }
 
       // Lookup table methods
       void SetLookupTable( unsigned int i, vtkScalarsToColors* lut );
index 96e646a78f11bbf46c2e44991edb084c2934c266..aaadf31b1b61ede9daff48099bb27613b232f87f 100644 (file)
@@ -20,7 +20,7 @@ SetRenderWindows(
   this->m_Windows[ 2 ] = wz;
   this->m_Windows[ 3 ] = w3D;
 
-  // Prepare renderers
+  // Prepare 2D renderers
   for( int i = 0; i < 4; ++i )
   {
     if( this->m_Windows[ i ] == NULL )
@@ -30,29 +30,76 @@ SetRenderWindows(
 
     } // fi
 
-    // Renderers
+    // Create renderer, if render window exists
     this->m_Renderers[ i ] = vtkSmartPointer< vtkRenderer >::New( );
     this->m_Renderers[ i ]->SetBackground( 0.1, 0.3, 0.8 );
     this->m_Windows[ i ]->AddRenderer( this->m_Renderers[ i ] );
 
-    // Image styles (just for 2D windows)
-    if( i < 3 )
+  } // rof
+
+  // Create 3D renderer
+  if( this->m_Windows[ 3 ] != NULL )
+    this->m_Renderers[ 3 ]->SetBackground( 0.2, 0.2, 0.2 );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::MPRObjects::
+SetImage( vtkImageData* image )
+{
+  this->m_MPRActors->AddInputData( image );
+  this->m_MPRActors->PushDataInto(
+    this->m_Renderers[ 0 ],
+    this->m_Renderers[ 1 ],
+    this->m_Renderers[ 2 ],
+    this->m_Renderers[ 3 ]
+    );
+
+  // Correct cameras positions
+  /* TODO
+     vtkCamera* zCam = this->m_Renderers[ 2 ]->GetActiveCamera( );
+     zCam->SetViewUp( 0, -1, 0 );
+     zCam->SetPosition( 0, 0, -1 );
+     zCam->SetFocalPoint( 0, 0, 0 );
+  */
+
+  // First rendering
+  this->m_MPRActors->ResetSlices( );
+  this->ResetCameras( );
+  this->RenderAll( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::MPRObjects::
+ActivateInteractors( )
+{
+  // Prepare renderers
+  for( int i = 0; i < 3; ++i )
+  {
+    // Check prerrequisites
+    if( this->m_Windows[ i ] == NULL || this->m_Renderers[ i ] == NULL )
     {
-      this->m_Styles[ i ] = vtkSmartPointer< TStyle >::New( );
-      this->m_Styles[ i ]->Configure(
-        this->m_MPRActors->GetSliceActors( i ), this->m_MPRActors
-        );
+      this->m_Styles[ i ] = NULL;
+      continue;
 
-      this->m_Styles[ i ]->
-        SetInteractor( this->m_Windows[ i ]->GetInteractor( ), i );
-      this->m_Styles[ i ]->SetModeToNavigation( );
+    } // fi
+
+    ImageSliceActors* actors = this->m_MPRActors->GetSliceActors( i );
+    if( actors == NULL )
+    {
+      this->m_Styles[ i ] = NULL;
+      continue;
 
     } // fi
 
+    this->m_Styles[ i ] = vtkSmartPointer< TStyle >::New( );
+    this->m_Styles[ i ]->Configure( actors, this->m_MPRActors );
+    this->m_Styles[ i ]->
+      SetInteractor( this->m_Windows[ i ]->GetInteractor( ), i );
+    this->m_Styles[ i ]->SetModeToNavigation( );
+
   } // rof
-  if( this->m_Windows[ 3 ] != NULL )
-    this->m_Renderers[ 3 ]->SetBackground( 0.2, 0.2, 0.2 );
 
+  // Synch 2D and 3D renderers
   for( int i = 0; i < 3; ++i )
   {
     for( int j = 0; j < 3; ++j )
@@ -71,29 +118,11 @@ SetRenderWindows(
         AssociateInteractor( this->m_Windows[ 3 ]->GetInteractor( ) );
 
   } // rof
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::Visualization::MPRObjects::
-SetImage( vtkImageData* image )
-{
-  this->m_MPRActors->AddInputData( image );
-  this->m_MPRActors->PushDataInto(
-    this->m_Renderers[ 0 ],
-    this->m_Renderers[ 1 ],
-    this->m_Renderers[ 2 ],
-    this->m_Renderers[ 3 ]
-    );
 
-  // Correct cameras positions
-  /* TODO
-     vtkCamera* zCam = this->m_Renderers[ 2 ]->GetActiveCamera( );
-     zCam->SetViewUp( 0, -1, 0 );
-     zCam->SetPosition( 0, 0, -1 );
-     zCam->SetFocalPoint( 0, 0, 0 );
-  */
+  // Finish interactor linking
+  this->m_MPRActors->LinkInteractors( );
 
-  // First rendering
+  // Restart rendering
   this->ResetCameras( );
   this->RenderAll( );
 }
index 84db5d29cff2ce045b08a3ed5fde2555113a05a5..a348e91513d15c4379091677f4621ee48f3041f1 100644 (file)
@@ -34,8 +34,9 @@ namespace cpExtensions
         vtkRenderWindow* wx, vtkRenderWindow* wy,
         vtkRenderWindow* wz, vtkRenderWindow* w3D
         );
-
       void SetImage( vtkImageData* image );
+      void ActivateInteractors( );
+
       void ResetCamera( const int& id );
       void ResetCameras( );
       void Render( const int& id );