]> Creatis software - cpPlugins.git/blobdiff - lib/cpExtensions/Visualization/MPRActors.cxx
Merge branch 'master' of ssh://git.creatis.insa-lyon.fr/cpPlugins
[cpPlugins.git] / lib / cpExtensions / Visualization / MPRActors.cxx
index a02c8bc28d52ad37ff20848e333a3a5d4f1606a8..00d27dc6e8411c62388b6f29a4487f2719cc1a5d 100644 (file)
@@ -211,50 +211,39 @@ PushActorsInto(
   this->Slices[ 0 ][ 0 ]->PushActorsInto( x, true );
   this->Slices[ 0 ][ 1 ]->PushActorsInto( y, true );
   this->Slices[ 0 ][ 2 ]->PushActorsInto( z, true );
-
+  this->Slices[ 1 ][ 0 ]->PushActorsInto( w, false );
+  this->Slices[ 1 ][ 1 ]->PushActorsInto( w, false );
+  this->Slices[ 1 ][ 2 ]->PushActorsInto( w, false );
+
+  vtkRenderer* xren =
+    ( x != NULL )? x->GetRenderers( )->GetFirstRenderer( ): NULL;
+  vtkRenderer* yren =
+    ( y != NULL )? y->GetRenderers( )->GetFirstRenderer( ): NULL;
+  vtkRenderer* zren =
+    ( z != NULL )? z->GetRenderers( )->GetFirstRenderer( ): NULL;
   vtkRenderer* wren =
     ( w != NULL )? w->GetRenderers( )->GetFirstRenderer( ): NULL;
-  vtkRenderer* rends[ ] =
-    {
-      ( x != NULL )? x->GetRenderers( )->GetFirstRenderer( ): NULL,
-      ( y != NULL )? y->GetRenderers( )->GetFirstRenderer( ): NULL,
-      ( z != NULL )? z->GetRenderers( )->GetFirstRenderer( ): NULL
-    };
-  for( int i = 0; i < 3; ++i )
-  {
-    if( rends[ i ] != NULL )
-      for( int j = 0; j < 3; ++j )
-        if( i != j )
-          rends[ i ]->AddActor( this->Slices[ 0 ][ j ]->GetPlaneActor( ) );
-    if( wren != NULL )
-    {
-      for(
-        unsigned int k = 0;
-        k < this->Slices[ 1 ][ i ]->GetNumberOfImageActors( );
-        ++k
-        )
-        wren->AddActor( this->Slices[ 1 ][ i ]->GetImageActor( k ) );
-      wren->AddActor( this->Slices[ 1 ][ i ]->GetPlaneActor( ) );
 
-    } // fi
+  if( xren != NULL )
+  {
+    xren->AddActor( this->Slices[ 0 ][ 1 ]->GetPlaneActor( ) );
+    xren->AddActor( this->Slices[ 0 ][ 2 ]->GetPlaneActor( ) );
 
-  } // rof
-  if( wren != NULL )
-    wren->AddActor( this->ImageOutlineActor );
+  } // fi
+  if( yren != NULL )
+  {
+    yren->AddActor( this->Slices[ 0 ][ 0 ]->GetPlaneActor( ) );
+    yren->AddActor( this->Slices[ 0 ][ 2 ]->GetPlaneActor( ) );
 
-  for( unsigned int j = 0; j < 3; ++j )
+  } // fi
+  if( zren != NULL )
   {
-    ImageInteractorStyle* st =
-      dynamic_cast< ImageInteractorStyle* >( this->Slices[ 0 ][ j ]->GetStyle( ) );
-    if( w != NULL )
-      st->AssociateInteractor( w->GetInteractor( ) );
-    for( unsigned int l = 0; l < 3; ++l )
-      if( j != l )
-        st->AssociateInteractor(
-          this->Slices[ 0 ][ l ]->GetStyle( )->GetInteractor( )
-          );
+    zren->AddActor( this->Slices[ 0 ][ 0 ]->GetPlaneActor( ) );
+    zren->AddActor( this->Slices[ 0 ][ 1 ]->GetPlaneActor( ) );
 
-  } // rof
+  } // fi
+  if( wren != NULL )
+    wren->AddActor( this->ImageOutlineActor );
 }
 
 // -------------------------------------------------------------------------
@@ -267,34 +256,12 @@ PopActorsFrom(
   this->Slices[ 0 ][ 0 ]->PopActorsFrom( x );
   this->Slices[ 0 ][ 1 ]->PopActorsFrom( y );
   this->Slices[ 0 ][ 2 ]->PopActorsFrom( z );
+  this->Slices[ 1 ][ 0 ]->PopActorsFrom( w );
+  this->Slices[ 1 ][ 1 ]->PopActorsFrom( w );
+  this->Slices[ 1 ][ 2 ]->PopActorsFrom( w );
 
   vtkRenderer* wren =
     ( w != NULL )? w->GetRenderers( )->GetFirstRenderer( ): NULL;
-  vtkRenderer* rends[ ] =
-    {
-      ( x != NULL )? x->GetRenderers( )->GetFirstRenderer( ): NULL,
-      ( y != NULL )? y->GetRenderers( )->GetFirstRenderer( ): NULL,
-      ( z != NULL )? z->GetRenderers( )->GetFirstRenderer( ): NULL
-    };
-  for( int i = 0; i < 3; ++i )
-  {
-    if( rends[ i ] != NULL )
-      for( int j = 0; j < 3; ++j )
-        if( i != j )
-          rends[ i ]->RemoveActor( this->Slices[ 0 ][ j ]->GetPlaneActor( ) );
-    if( wren != NULL )
-    {
-      for(
-        unsigned int k = 0;
-        k < this->Slices[ 1 ][ i ]->GetNumberOfImageActors( );
-        ++k
-        )
-        wren->RemoveActor( this->Slices[ 1 ][ i ]->GetImageActor( k ) );
-      wren->RemoveActor( this->Slices[ 1 ][ i ]->GetPlaneActor( ) );
-
-    } // fi
-
-  } // rof
   if( wren != NULL )
     wren->RemoveActor( this->ImageOutlineActor );
 
@@ -319,6 +286,20 @@ SetLookupTableAsColor( unsigned int i, double r, double g, double b )
   this->Modified( );
 }
 
+// -------------------------------------------------------------------------
+double cpExtensions::Visualization::MPRActors::
+GetWindow( )
+{
+  return( this->Slices[ 0 ][ 0 ]->GetWindow( ) );
+}
+
+// -------------------------------------------------------------------------
+double cpExtensions::Visualization::MPRActors::
+GetLevel( )
+{
+  return( this->Slices[ 0 ][ 0 ]->GetLevel( ) );
+}
+
 // -------------------------------------------------------------------------
 int cpExtensions::Visualization::MPRActors::
 GetSliceNumberMinValue( const int& axis ) const
@@ -344,7 +325,7 @@ GetSlice( const int& axis ) const
 void cpExtensions::Visualization::MPRActors::
 SetSlice( const int& axis, const int& slice )
 {
-  vtkImageData* image = this->_Image( 0 );
+  vtkImageData* image = this->Slices[ 0 ][ 0 ]->GetInputImage( 0 );
   if( image == NULL )
     return;
 
@@ -369,7 +350,7 @@ SetSlice( const int& axis, const int& slice )
 void cpExtensions::Visualization::MPRActors::
 SetSlice( const int& axis, const double& slice )
 {
-  vtkImageData* image = this->_Image( 0 );
+  vtkImageData* image = this->Slices[ 0 ][ 0 ]->GetInputImage( 0 );
   if( image == NULL )
     return;
 
@@ -389,7 +370,7 @@ ResetSlices( )
   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( )
+        this->Slices[ i ][ j ]->GetSliceNumberMaxValue( )
         );
 }
 
@@ -407,9 +388,17 @@ MPRActors( )
   this->Slices[ 0 ][ 1 ]->AssociateSlice( this->Slices[ 1 ][ 1 ] );
   this->Slices[ 0 ][ 2 ]->AssociateSlice( this->Slices[ 1 ][ 2 ] );
 
-  this->Slices[ 0 ][ 0 ]->SetSlicesCommand( Self::_SetSlices, this );
-  this->Slices[ 0 ][ 1 ]->SetSlicesCommand( Self::_SetSlices, this );
-  this->Slices[ 0 ][ 2 ]->SetSlicesCommand( Self::_SetSlices, this );
+  for( unsigned int i = 0; i < 3; ++ i )
+  {
+    this->Slices[ 0 ][ i ]->AddRenderCommand(
+      Self::_RenderCommand, this
+      );
+    this->Slices[ 0 ][ i ]->AddWindowLevelCommand(
+      Self::_WindowLevelCommand, this
+      );
+    this->Slices[ 0 ][ i ]->AddSlicesCommand( Self::_SlicesCommand, this );
+
+  } // rof
 }
 
 // -------------------------------------------------------------------------
@@ -418,94 +407,55 @@ cpExtensions::Visualization::MPRActors::
 {
 }
 
-// -------------------------------------------------------------------------
-vtkImageData* cpExtensions::Visualization::MPRActors::
-_Image( unsigned int i ) const
-{
-  /*
-  if( i < this->ImageMaps.size( ) )
-  {
-    vtkAlgorithm* algo = this->ImageMaps[ i ]->GetInputAlgorithm( );
-    vtkInformation* info = algo->GetOutputInformation( 0 );
-    return(
-      vtkImageData::SafeDownCast(
-        info->Get( vtkDataObject::DATA_OBJECT( ) )
-        )
-      );
-  }
-  else
-  */
-  return( NULL );
-}
-
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::MPRActors::
-_Update( unsigned int i )
+_SlicesCommand( double* pos, int axis, void* data )
 {
-  /*
-  // Check if the input has been configured
-  vtkImageData* image = this->_Image( i );
-  if( image == NULL )
+  MPRActors* actors = reinterpret_cast< MPRActors* >( data );
+  if( actors == NULL )
     return;
-  this->ImageMaps[ i ]->Update( );
-
-  for( int j = 0; j < 2; ++j )
+  for( unsigned int j = 0; j < 3; ++j )
   {
-    for( int k = 0; k < 3; ++k )
+    if( actors->Slices[ 0 ][ j ]->GetAxis( ) != axis )
     {
-      this->Slices[ j ][ k ]->AddInputConnection(
-        this->ImageMaps[ i ]->GetOutputPort( ), k
-        );
-      this->Slices[ j ][ k ]->UpdateText( );
-
-      // Add all of slice's props
-      this->Slices[ j ][ k ]->InitTraversal( );
-      vtkProp* prop = this->Slices[ j ][ k ]->GetNextProp( );
-      while( prop != NULL )
-      {
-        this->AddItem( prop );
-        prop = this->Slices[ j ][ k ]->GetNextProp( );
-
-      } // elihw
+      actors->Slices[ 0 ][ j ]->SetSlice( pos );
+      actors->Slices[ 1 ][ j ]->SetSlice( pos );
+      actors->Slices[ 0 ][ j ]->Render( 1e-3 );
+      actors->Slices[ 1 ][ j ]->Render( 1e-3 );
 
-    } // rof
+    } // fi
 
   } // rof
+}
 
-  if( i == 0 )
-  {
-    // Create 3D outline
-    double bb[ 6 ];
-    image->GetBounds( 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 );
-
-    this->AddItem( this->ImageOutlineActor );
-
-  } // fi
-  */
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::MPRActors::
+_WindowLevelCommand( double window, double level, void* data )
+{
+  MPRActors* actors = reinterpret_cast< MPRActors* >( data );
+  if( actors == NULL )
+    return;
+  actors->Slices[ 0 ][ 0 ]->Render( 1e-3 );
+  actors->Slices[ 0 ][ 1 ]->Render( 1e-3 );
+  actors->Slices[ 0 ][ 2 ]->Render( 1e-3 );
+  actors->Slices[ 1 ][ 0 ]->Render( 1e-3 );
+  actors->Slices[ 1 ][ 1 ]->Render( 1e-3 );
+  actors->Slices[ 1 ][ 2 ]->Render( 1e-3 );
 }
 
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::MPRActors::
-_SetSlices( double* pos, int axis, void* data )
+_RenderCommand( void* data )
 {
   MPRActors* actors = reinterpret_cast< MPRActors* >( data );
   if( actors == NULL )
     return;
-  for( unsigned int j = 0; j < 3; ++j )
-    if( actors->Slices[ 0 ][ j ]->GetAxis( ) != axis )
-      actors->Slices[ 0 ][ j ]->SetSlice( pos );
-  actors->Modified( );
+  actors->Slices[ 0 ][ 0 ]->Render( 1e-3 );
+  actors->Slices[ 0 ][ 1 ]->Render( 1e-3 );
+  actors->Slices[ 0 ][ 2 ]->Render( 1e-3 );
+  actors->Slices[ 1 ][ 0 ]->Render( 1e-3 );
+  actors->Slices[ 1 ][ 1 ]->Render( 1e-3 );
+  actors->Slices[ 1 ][ 2 ]->Render( 1e-3 );
 }
 
 // eof - $RCSfile$