]> Creatis software - cpPlugins.git/blobdiff - lib/cpExtensions/Visualization/ImageSliceActors.cxx
...
[cpPlugins.git] / lib / cpExtensions / Visualization / ImageSliceActors.cxx
index 5536ab120e6c41a61b0c4c832d76bea071fb7456..6d67a66c62ee64f05e8bbaf8c020b5840c4dc463 100644 (file)
 #include <cpExtensions/Visualization/ImageSliceActors.h>
+#include <cpExtensions/Visualization/ImageOutlineActor.h>
+#include <cpExtensions/Visualization/LUTImageActor.h>
+#include <cpExtensions/Visualization/WindowLevelImageActor.h>
 
-#include <vtkAlgorithmOutput.h>
-#include <vtkCellArray.h>
 #include <vtkImageData.h>
-#include <vtkInformation.h>
 #include <vtkPlane.h>
-#include <vtkPoints.h>
-#include <vtkProperty.h>
-#include <vtkStreamingDemandDrivenPipeline.h>
-#include <vtkTextProperty.h>
 
 // -------------------------------------------------------------------------
-cpExtensions::Visualization::ImageSliceActors*
 cpExtensions::Visualization::ImageSliceActors::
+Self* cpExtensions::Visualization::ImageSliceActors::
 New( )
 {
   return( new Self( ) );
 }
 
 // -------------------------------------------------------------------------
-void cpExtensions::Visualization::ImageSliceActors::
-SetInputConnection( vtkAlgorithmOutput* aout, int axis )
+vtkImageData* cpExtensions::Visualization::ImageSliceActors::
+GetImage( )
 {
-  this->SliceMapper->SetInputConnection( aout );
-  this->SliceMapper->SetOrientation( axis );
-  this->SliceMapper->Update( );
-  this->SetSliceNumber( this->SliceMapper->GetSliceNumber( ) );
-  this->ImageActor->SetMapper( this->SliceMapper );
-  this->ImageActor->Modified( );
-  this->Modified( );
+  if( this->m_WindowLevelImageActor.GetPointer( ) != NULL )
+    return( this->m_WindowLevelImageActor->GetImage( ) );
+  else
+    return( NULL );
 }
 
 // -------------------------------------------------------------------------
-void cpExtensions::Visualization::ImageSliceActors::
-SetInputData( vtkImageData* data, int axis )
+const vtkImageData* cpExtensions::Visualization::ImageSliceActors::
+GetImage( ) const
 {
-  this->SliceMapper->SetInputData( data );
-  this->SliceMapper->SetOrientation( axis );
-  this->SliceMapper->Update( );
-  this->SetSliceNumber( this->SliceMapper->GetSliceNumber( ) );
-  this->ImageActor->SetMapper( this->SliceMapper );
-  this->ImageActor->Modified( );
-  this->Modified( );
+  if( this->m_WindowLevelImageActor.GetPointer( ) != NULL )
+    return( this->m_WindowLevelImageActor->GetImage( ) );
+  else
+    return( NULL );
 }
 
 // -------------------------------------------------------------------------
-double* cpExtensions::Visualization::ImageSliceActors::
-GetDisplayBounds( ) const
+cpExtensions::Visualization::
+WindowLevelImageActor* cpExtensions::Visualization::ImageSliceActors::
+GetWindowLevelImageActor( )
 {
-  return( this->ImageActor->GetDisplayBounds( ) );
+  return( this->m_WindowLevelImageActor.GetPointer( ) );
 }
 
 // -------------------------------------------------------------------------
-void cpExtensions::Visualization::ImageSliceActors::
-GetDisplayBounds( double bounds[ 6 ] ) const
+const cpExtensions::Visualization::
+WindowLevelImageActor* cpExtensions::Visualization::ImageSliceActors::
+GetWindowLevelImageActor( ) const
 {
-  this->ImageActor->GetDisplayBounds( bounds );
+  return( this->m_WindowLevelImageActor.GetPointer( ) );
 }
 
 // -------------------------------------------------------------------------
-int cpExtensions::Visualization::ImageSliceActors::
-GetAxis( ) const
+cpExtensions::Visualization::
+LUTImageActor* cpExtensions::Visualization::ImageSliceActors::
+GetLUTImageActor( )
 {
-  return( this->SliceMapper->GetOrientation( ) );
+  return( this->m_LUTImageActor.GetPointer( ) );
 }
 
 // -------------------------------------------------------------------------
-int cpExtensions::Visualization::ImageSliceActors::
-GetSliceNumber( ) const
+const cpExtensions::Visualization::
+LUTImageActor* cpExtensions::Visualization::ImageSliceActors::
+GetLUTImageActor( ) const
 {
-  return( this->SliceMapper->GetSliceNumber( ) );
+  return( this->m_LUTImageActor.GetPointer( ) );
 }
 
 // -------------------------------------------------------------------------
-int cpExtensions::Visualization::ImageSliceActors::
-GetSliceNumberMinValue( ) const
+cpExtensions::Visualization::
+ImageOutlineActor* cpExtensions::Visualization::ImageSliceActors::
+GetImageOutlineActor( )
+{
+  return( this->m_ImageOutlineActor.GetPointer( ) );
+}
+
+// -------------------------------------------------------------------------
+const cpExtensions::Visualization::
+ImageOutlineActor* cpExtensions::Visualization::ImageSliceActors::
+GetImageOutlineActor( ) const
 {
-  return( this->SliceMapper->GetSliceNumberMinValue( ) );
+  return( this->m_ImageOutlineActor.GetPointer( ) );
 }
 
 // -------------------------------------------------------------------------
 int cpExtensions::Visualization::ImageSliceActors::
-GetSliceNumberMaxValue( ) const
+GetOrientation( ) const
 {
-  return( this->SliceMapper->GetSliceNumberMaxValue( ) );
+  if( this->m_WindowLevelImageActor.GetPointer( ) != NULL )
+    return( this->m_WindowLevelImageActor->GetOrientation( ) );
+  else
+    return( 0 );
 }
 
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::ImageSliceActors::
-SetSliceNumber( const int& slice )
+SetImage( vtkImageData* image, int orientation )
 {
-  this->SliceMapper->SetSliceNumber( slice );
-  this->SliceMapper->Update( );
-
-  // Compute plane
-  vtkAlgorithm* algo = this->SliceMapper->GetInputAlgorithm( );
-  vtkInformation* info = algo->GetOutputInformation( 0 );
+  this->m_WindowLevelImageActor =
+    vtkSmartPointer< WindowLevelImageActor >::New( );
+  this->m_WindowLevelImageActor->SetImage( image );
+  this->m_WindowLevelImageActor->SetOrientation( orientation );
+  this->m_ImageOutlineActor = vtkSmartPointer< ImageOutlineActor >::New( );
+  this->m_LUTImageActor = NULL;
+
+  // Put an initial slice
   int ext[ 6 ];
-  double ori[ 3 ], spac[ 3 ], pos[ 3 ];
-  info->Get( vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT( ), ext );
-  info->Get( vtkDataObject::ORIGIN( ), ori );
-  info->Get( vtkDataObject::SPACING( ), spac );
-  this->SliceMapper->GetSlicePlane( )->GetOrigin( pos );
-
-  // Prevent obscuring voxels by offsetting the plane geometry
-  double xbnds[ ] =
-    {
-      ori[ 0 ] + ( spac[ 0 ] * double( ext[ 0 ] ) ),
-      ori[ 0 ] + ( spac[ 0 ] * double( ext[ 1 ] ) )
-    };
-  double ybnds[ ] =
-    {
-      ori[ 1 ] + ( spac[ 1 ] * double( ext[ 2 ] ) ),
-      ori[ 1 ] + ( spac[ 1 ] * double( ext[ 3 ] ) )
-    };
-  double zbnds[ ] =
-    {
-      ori[ 2 ] + ( spac[ 2 ] * double( ext[ 4 ] ) ),
-      ori[ 2 ] + ( spac[ 2 ] * double( ext[ 5 ] ) )
-    };
-
-  if( spac[ 0 ] < double( 0 ) )
-  {
-    double t = xbnds[ 0 ];
-    xbnds[ 0 ] = xbnds[ 1 ];
-    xbnds[ 1 ] = t;
+  image->GetExtent( ext );
+  this->SetSliceNumber(
+    ext[ this->m_WindowLevelImageActor->GetOrientation( ) << 1 ]
+    );
 
-  } // fi
-  if( spac[ 1 ] < double( 0 ) )
-  {
-    double t = ybnds[ 0 ];
-    ybnds[ 0 ] = ybnds[ 1 ];
-    ybnds[ 1 ] = t;
+  // Update collection
+  this->RemoveAllItems( );
+  this->AddItem( this->m_ImageOutlineActor );
+  this->AddItem( this->m_WindowLevelImageActor );
+}
 
-  } // fi
-  if( spac[ 2 ] < double( 0 ) )
+// -------------------------------------------------------------------------
+unsigned int cpExtensions::Visualization::ImageSliceActors::
+AddLUTImage( vtkImageData* image )
+{
+  if( this->GetImage( ) != NULL )
   {
-    double t = zbnds[ 0 ];
-    zbnds[ 0 ] = zbnds[ 1 ];
-    zbnds[ 1 ] = t;
-
-  } // fi
+    if( this->m_LUTImageActor.GetPointer( ) == NULL )
+    {
+      this->m_LUTImageActor = vtkSmartPointer< LUTImageActor >::New( );
+      this->m_LUTImageActor->SetOrientation( this->GetOrientation( ) );
+      this->AddItem( this->m_LUTImageActor );
 
-  int axis = this->SliceMapper->GetOrientation( );
-  this->PlaneActor->GetProperty( )->SetRepresentationToWireframe( );
-  this->PlaneActor->GetProperty( )->SetLineWidth( 2 );
-  vtkPoints* plane_points = this->PlaneSource->GetPoints( );
-  if( axis == 0 ) // YZ, x-normal
-  {
-    plane_points->SetPoint( 0, pos[ 0 ], ybnds[ 0 ], zbnds[ 0 ] );
-    plane_points->SetPoint( 1, pos[ 0 ], ybnds[ 1 ], zbnds[ 0 ] );
-    plane_points->SetPoint( 2, pos[ 0 ], ybnds[ 1 ], zbnds[ 1 ] );
-    plane_points->SetPoint( 3, pos[ 0 ], ybnds[ 0 ], zbnds[ 1 ] );
-    this->PlaneActor->GetProperty( )->SetColor( 1, 0, 0 );
+    } // fi
+    this->m_LUTImageActor->AddImage( image );
+    return( this->m_LUTImageActor->GetNumberOfImages( ) );
   }
-  else if( axis == 1 ) // ZX, y-normal
-  {
-    plane_points->SetPoint( 0, xbnds[ 0 ], pos[ 1 ], zbnds[ 0 ] );
-    plane_points->SetPoint( 1, xbnds[ 0 ], pos[ 1 ], zbnds[ 1 ] );
-    plane_points->SetPoint( 2, xbnds[ 1 ], pos[ 1 ], zbnds[ 1 ] );
-    plane_points->SetPoint( 3, xbnds[ 1 ], pos[ 1 ], zbnds[ 0 ] );
-    this->PlaneActor->GetProperty( )->SetColor( 0, 1, 0 );
-  }
-  else // XY, z-normal
-  {
-    plane_points->SetPoint( 0, xbnds[ 0 ], ybnds[ 0 ], pos[ 2 ] );
-    plane_points->SetPoint( 1, xbnds[ 1 ], ybnds[ 0 ], pos[ 2 ] );
-    plane_points->SetPoint( 2, xbnds[ 1 ], ybnds[ 1 ], pos[ 2 ] );
-    plane_points->SetPoint( 3, xbnds[ 0 ], ybnds[ 1 ], pos[ 2 ] );
-    this->PlaneActor->GetProperty( )->SetColor( 0, 0, 1 );
+  else
+    return( 0 );
+}
 
-  } // fi
-  this->PlaneSource->Modified( );
-  this->PlaneMapper->Modified( );
-  this->PlaneActor->Modified( );
-  this->Modified( );
+// -------------------------------------------------------------------------
+int cpExtensions::Visualization::ImageSliceActors::
+GetSliceNumber( ) const
+{
+  return( this->m_WindowLevelImageActor->GetSliceNumber( ) );
 }
 
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::ImageSliceActors::
-UpdateText( )
+SetSliceNumber( int slice )
 {
-  char axis;
-  int axId = this->SliceMapper->GetOrientation( );
-  if     ( axId == 0 ) axis = 'X';
-  else if( axId == 1 ) axis = 'Y';
-  else if( axId == 2 ) axis = 'Z';
-
-  std::sprintf(
-    this->TextBuffer, "Axis: %c (%d)",
-    axis, this->SliceMapper->GetSliceNumber( )
-    );
-  this->TextActor->SetInput( this->TextBuffer );
-  this->TextActor->Modified( );
-  this->Modified( );
+  this->m_WindowLevelImageActor->SetSliceNumber( slice );
+  if( this->m_LUTImageActor.GetPointer( ) != NULL )
+    this->m_LUTImageActor->SetSliceNumber( slice );
+
+  double bounds[ 6 ];
+  this->m_WindowLevelImageActor->GetImage( )->GetBounds( bounds );
+  int o = this->m_WindowLevelImageActor->GetOrientation( );
+  double p = this->m_WindowLevelImageActor->GetSlicePlane( )->GetOrigin( )[ o ];
+  this->m_ImageOutlineActor->SetBounds( o, p, bounds );
 }
 
 // -------------------------------------------------------------------------
@@ -201,55 +163,6 @@ cpExtensions::Visualization::ImageSliceActors::
 ImageSliceActors( )
   : Superclass( )
 {
-  this->SliceMapper = vtkSmartPointer< vtkImageSliceMapper >::New( );
-  this->PlaneSource = vtkSmartPointer< vtkPolyData >::New( );
-  this->PlaneMapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
-  this->ImageActor  = vtkSmartPointer< vtkImageActor >::New( );
-  this->TextActor   = vtkSmartPointer< vtkTextActor >::New( );
-  this->PlaneActor  = vtkSmartPointer< vtkActor >::New( );
-
-  this->ImageActorIndex = this->GetNumberOfItems( );
-  this->TextActorIndex = this->ImageActorIndex + 1;
-  this->PlaneActorIndex = this->ImageActorIndex + 2;
-  this->AddItem( this->ImageActor );
-  this->AddItem( this->TextActor );
-  this->AddItem( this->PlaneActor );
-
-  // Configuration
-  vtkSmartPointer< vtkPoints > plane_points =
-    vtkSmartPointer< vtkPoints >::New( );
-  vtkSmartPointer< vtkCellArray > plane_lines =
-    vtkSmartPointer< vtkCellArray >::New( );
-
-  plane_points->InsertNextPoint( 0, 0, 0 );
-  plane_points->InsertNextPoint( 0, 1, 0 );
-  plane_points->InsertNextPoint( 1, 1, 0 );
-  plane_points->InsertNextPoint( 1, 0, 0 );
-  plane_lines->InsertNextCell( 5 );
-  plane_lines->InsertCellPoint( 0 );
-  plane_lines->InsertCellPoint( 1 );
-  plane_lines->InsertCellPoint( 2 );
-  plane_lines->InsertCellPoint( 3 );
-  plane_lines->InsertCellPoint( 0 );
-  this->PlaneSource->SetPoints( plane_points );
-  this->PlaneSource->SetLines( plane_lines );
-
-  this->PlaneMapper->SetInputData( this->PlaneSource );
-  this->PlaneActor->SetMapper( this->PlaneMapper );
-
-  this->TextActor->SetTextScaleModeToNone( );
-  vtkTextProperty* textprop = this->TextActor->GetTextProperty( );
-  textprop->SetColor( 1, 1, 1 );
-  textprop->SetFontFamilyToCourier( );
-  textprop->SetFontSize( 18 );
-  textprop->BoldOff( );
-  textprop->ItalicOff( );
-  textprop->ShadowOff( );
-  textprop->SetJustificationToLeft( );
-  textprop->SetVerticalJustificationToBottom( );
-  vtkCoordinate* coord = this->TextActor->GetPositionCoordinate( );
-  coord->SetCoordinateSystemToNormalizedViewport( );
-  coord->SetValue( 0.01, 0.01 );
 }
 
 // -------------------------------------------------------------------------