]> Creatis software - cpPlugins.git/commitdiff
It does not compile, Mr Pepe
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Fri, 25 Sep 2015 16:00:40 +0000 (18:00 +0200)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Fri, 25 Sep 2015 16:00:40 +0000 (18:00 +0200)
lib/cpExtensions/Visualization/ImageSliceActors.cxx
lib/cpExtensions/Visualization/ImageSliceActors.h
lib/cpExtensions/Visualization/MPRActors.cxx
lib/cpExtensions/Visualization/MPRActors.h

index 5536ab120e6c41a61b0c4c832d76bea071fb7456..562179e2432ac109fcac6c572cc11f0e5391353c 100644 (file)
@@ -20,88 +20,265 @@ New( )
 
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::ImageSliceActors::
-SetInputConnection( vtkAlgorithmOutput* aout, int axis )
+AddInputConnection( vtkAlgorithmOutput* aout, int axis )
 {
-  this->SliceMapper->SetInputConnection( aout );
-  this->SliceMapper->SetOrientation( axis );
-  this->SliceMapper->Update( );
-  this->SetSliceNumber( this->SliceMapper->GetSliceNumber( ) );
-  this->ImageActor->SetMapper( this->SliceMapper );
-  this->ImageActor->Modified( );
+  unsigned int nImages = this->SliceMappers.size( );
+
+  vtkSmartPointer< vtkImageSliceMapper > mapper =
+    vtkSmartPointer< vtkImageSliceMapper >::New( );
+  this->SliceMappers.push_back( mapper );
+  mapper->SetInputConnection( aout );
+  mapper->SetOrientation(
+    ( nImages == 0 )? axis: this->SliceMappers[ 0 ]->GetOrientation( )
+    );
+  mapper->Update( );
+  
+  this->SetSliceNumber( this->SliceMappers[ 0 ]->GetSliceNumber( ) );
+
+  vtkSmartPointer< vtkImageActor > actor =
+    vtkSmartPointer< vtkImageActor >::New( );
+  this->ImageActors.push_back( actor );
+  actor->SetMapper( mapper );
+  actor->Modified( );
+
+  if( nImages == 0 )
+  {
+    this->AddItem( this->TextActor );
+    this->AddItem( this->PlaneActor );
+
+  } // fi
+  this->AddItem( actor );
   this->Modified( );
 }
 
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::ImageSliceActors::
-SetInputData( vtkImageData* data, int axis )
+AddInputData( vtkImageData* data, int axis )
 {
-  this->SliceMapper->SetInputData( data );
-  this->SliceMapper->SetOrientation( axis );
-  this->SliceMapper->Update( );
-  this->SetSliceNumber( this->SliceMapper->GetSliceNumber( ) );
-  this->ImageActor->SetMapper( this->SliceMapper );
-  this->ImageActor->Modified( );
+  unsigned int nImages = this->SliceMappers.size( );
+
+  vtkSmartPointer< vtkImageSliceMapper > mapper =
+    vtkSmartPointer< vtkImageSliceMapper >::New( );
+  this->SliceMappers.push_back( mapper );
+  mapper->SetInputData( data );
+  mapper->SetOrientation(
+    ( nImages == 0 )? axis: this->SliceMappers[ 0 ]->GetOrientation( )
+    );
+  mapper->Update( );
+  
+  this->SetSliceNumber( this->SliceMappers[ 0 ]->GetSliceNumber( ) );
+
+  vtkSmartPointer< vtkImageActor > actor =
+    vtkSmartPointer< vtkImageActor >::New( );
+  this->ImageActors.push_back( actor );
+  actor->SetMapper( mapper );
+  actor->Modified( );
+
+  if( nImages == 0 )
+  {
+    this->AddItem( this->TextActor );
+    this->AddItem( this->PlaneActor );
+
+  } // fi
+  this->AddItem( actor );
   this->Modified( );
 }
 
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+Clear( )
+{
+  // Unbind from container
+  this->RemoveAllItems( );
+
+  // Delete all images
+  this->SliceMappers.clear( );
+  this->ImageActors.clear( );
+
+  // Reconfigure unique objects
+  this->PlaneSource = vtkSmartPointer< vtkPolyData >::New( );
+  this->PlaneMapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
+  this->TextActor   = vtkSmartPointer< vtkTextActor >::New( );
+  this->PlaneActor  = vtkSmartPointer< vtkActor >::New( );
+  this->TextBuffer[ 0 ] = '\0';
+
+  // Unique objects 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 );
+}
+
+// -------------------------------------------------------------------------
+unsigned int cpExtensions::Visualization::ImageSliceActors::
+GetNumberOfImageActors( ) const
+{
+  return( this->ImageActors.size( ) );
+}
+
+// -------------------------------------------------------------------------
+vtkImageActor* cpExtensions::Visualization::ImageSliceActors::
+GetImageActor( unsigned int id )
+{
+  if( id < this->ImageActors.size( ) )
+    return( this->ImageActors[ id ] );
+  else
+    return( NULL );
+}
+
+// -------------------------------------------------------------------------
+const vtkImageActor* cpExtensions::Visualization::ImageSliceActors::
+GetImageActor( unsigned int id ) const
+{
+  if( id < this->ImageActors.size( ) )
+    return( this->ImageActors[ id ] );
+  else
+    return( NULL );
+}
+
+// -------------------------------------------------------------------------
+vtkTextActor* cpExtensions::Visualization::ImageSliceActors::
+GetTextActor( )
+{
+  return( this->TextActor );
+}
+
+// -------------------------------------------------------------------------
+const vtkTextActor* cpExtensions::Visualization::ImageSliceActors::
+GetTextActor( ) const
+{
+  return( this->TextActor );
+}
+
+// -------------------------------------------------------------------------
+vtkActor* cpExtensions::Visualization::ImageSliceActors::
+GetPlaneActor( )
+{
+  return( this->PlaneActor );
+}
+
+// -------------------------------------------------------------------------
+const vtkActor* cpExtensions::Visualization::ImageSliceActors::
+GetPlaneActor( ) const
+{
+  return( this->PlaneActor );
+}
+
 // -------------------------------------------------------------------------
 double* cpExtensions::Visualization::ImageSliceActors::
 GetDisplayBounds( ) const
 {
-  return( this->ImageActor->GetDisplayBounds( ) );
+  if( this->ImageActors.size( ) > 0 )
+    return( this->ImageActors[ 0 ]->GetDisplayBounds( ) );
+  else
+    return( NULL );
 }
 
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::ImageSliceActors::
 GetDisplayBounds( double bounds[ 6 ] ) const
 {
-  this->ImageActor->GetDisplayBounds( bounds );
+  if( this->ImageActors.size( ) > 0 )
+    this->ImageActors[ 0 ]->GetDisplayBounds( bounds );
 }
 
 // -------------------------------------------------------------------------
 int cpExtensions::Visualization::ImageSliceActors::
 GetAxis( ) const
 {
-  return( this->SliceMapper->GetOrientation( ) );
+  if( this->SliceMappers.size( ) > 0 )
+    return( this->SliceMappers[ 0 ]->GetOrientation( ) );
+  else
+    return( -1 );
 }
 
 // -------------------------------------------------------------------------
 int cpExtensions::Visualization::ImageSliceActors::
 GetSliceNumber( ) const
 {
-  return( this->SliceMapper->GetSliceNumber( ) );
+  if( this->SliceMappers.size( ) > 0 )
+    return( this->SliceMappers[ 0 ]->GetSliceNumber( ) );
+  else
+    return( -1 );
 }
 
 // -------------------------------------------------------------------------
 int cpExtensions::Visualization::ImageSliceActors::
 GetSliceNumberMinValue( ) const
 {
-  return( this->SliceMapper->GetSliceNumberMinValue( ) );
+  if( this->SliceMappers.size( ) > 0 )
+    return( this->SliceMappers[ 0 ]->GetSliceNumberMinValue( ) );
+  else
+    return( -1 );
 }
 
 // -------------------------------------------------------------------------
 int cpExtensions::Visualization::ImageSliceActors::
 GetSliceNumberMaxValue( ) const
 {
-  return( this->SliceMapper->GetSliceNumberMaxValue( ) );
+  if( this->SliceMappers.size( ) > 0 )
+    return( this->SliceMappers[ 0 ]->GetSliceNumberMaxValue( ) );
+  else
+    return( -1 );
 }
 
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::ImageSliceActors::
 SetSliceNumber( const int& slice )
 {
-  this->SliceMapper->SetSliceNumber( slice );
-  this->SliceMapper->Update( );
+  unsigned int nImages = this->SliceMappers.size( );
+  if( nImages == 0 )
+    return;
+
+  // Change visualization extent
+  for( unsigned int i = 0; i < nImages; ++i )
+  {
+    this->SliceMappers[ i ]->SetSliceNumber( slice );
+    this->SliceMappers[ i ]->Modified( );
+    this->ImageActors[ i ]->Modified( );
+    this->SliceMappers[ i ]->Update( );
+
+  } // rof
 
   // Compute plane
-  vtkAlgorithm* algo = this->SliceMapper->GetInputAlgorithm( );
+  vtkAlgorithm* algo = this->SliceMappers[ 0 ]->GetInputAlgorithm( );
   vtkInformation* info = algo->GetOutputInformation( 0 );
   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 );
+  this->SliceMappers[ 0 ]->GetSlicePlane( )->GetOrigin( pos );
 
   // Prevent obscuring voxels by offsetting the plane geometry
   double xbnds[ ] =
@@ -142,7 +319,7 @@ SetSliceNumber( const int& slice )
 
   } // fi
 
-  int axis = this->SliceMapper->GetOrientation( );
+  int axis = this->SliceMappers[ 0 ]->GetOrientation( );
   this->PlaneActor->GetProperty( )->SetRepresentationToWireframe( );
   this->PlaneActor->GetProperty( )->SetLineWidth( 2 );
   vtkPoints* plane_points = this->PlaneSource->GetPoints( );
@@ -181,16 +358,21 @@ SetSliceNumber( const int& slice )
 void cpExtensions::Visualization::ImageSliceActors::
 UpdateText( )
 {
-  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( )
-    );
+  if( this->SliceMappers.size( ) > 0 )
+  {
+    char axis;
+    int axId = this->SliceMappers[ 0 ]->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->SliceMappers[ 0 ]->GetSliceNumber( )
+      );
+  }
+  else
+    this->TextBuffer[ 0 ] = '\0';
   this->TextActor->SetInput( this->TextBuffer );
   this->TextActor->Modified( );
   this->Modified( );
@@ -201,55 +383,7 @@ 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 );
+  this->Clear( );
 }
 
 // -------------------------------------------------------------------------
index 37aeac402cef79579d23b0bbab961fbb209b162c..0e1fdae463622b857a0c655b4da8ca9ee0919df8 100644 (file)
@@ -3,6 +3,8 @@
 
 #include <cpExtensions/cpExtensions_Export.h>
 
+#include <vector>
+
 #include <vtkActor.h>
 #include <vtkImageActor.h>
 #include <vtkImageSliceMapper.h>
 #include <vtkSmartPointer.h>
 #include <vtkTextActor.h>
 
-// -------------------------------------------------------------------------
-#define cpPlugins_ImageSliceActors( name, type )        \
-  inline type* Get##name##Actor( ) const                \
-  {                                                     \
-    return(                                             \
-      dynamic_cast< type* >(                            \
-        const_cast< Self* >( this )->                   \
-        GetItemAsObject( this->name##ActorIndex )       \
-        )                                               \
-      );                                                \
-  }
-
 // -------------------------------------------------------------------------
 class vtkAlgorithmOutput;
 class vtkImageData;
@@ -44,16 +34,21 @@ namespace cpExtensions
     public:
       vtkTypeMacro( ImageSliceActors, vtkPropCollection );
 
-      cpPlugins_ImageSliceActors( Image, vtkImageActor );
-      cpPlugins_ImageSliceActors( Text, vtkTextActor );
-      cpPlugins_ImageSliceActors( Plane, vtkActor );
-
     public:
       // Creation
       static ImageSliceActors* New( );
 
-      void SetInputConnection( vtkAlgorithmOutput* aout, int axis );
-      void SetInputData( vtkImageData* data, int axis );
+      void AddInputConnection( vtkAlgorithmOutput* aout, int axis = 0 );
+      void AddInputData( vtkImageData* data, int axis = 0 );
+      void Clear( );
+
+      unsigned int GetNumberOfImageActors( ) const;
+      vtkImageActor* GetImageActor( unsigned int id );
+      const vtkImageActor* GetImageActor( unsigned int id ) const;
+      vtkTextActor* GetTextActor( );
+      const vtkTextActor* GetTextActor( ) const;
+      vtkActor* GetPlaneActor( );
+      const vtkActor* GetPlaneActor( ) const;
 
       double* GetDisplayBounds( ) const;
       void GetDisplayBounds( double bounds[ 6 ] ) const;
@@ -75,18 +70,16 @@ namespace cpExtensions
       Self& operator=( const Self& );
 
     protected:
-      vtkSmartPointer< vtkImageSliceMapper > SliceMapper;
-      vtkSmartPointer< vtkPolyData >         PlaneSource;
-      vtkSmartPointer< vtkPolyDataMapper >   PlaneMapper;
-      char                                   TextBuffer[ 1024 ];
-
-      vtkSmartPointer< vtkImageActor > ImageActor;
-      vtkSmartPointer< vtkTextActor >  TextActor;
-      vtkSmartPointer< vtkActor >      PlaneActor;
-
-      unsigned int ImageActorIndex;
-      unsigned int TextActorIndex;
-      unsigned int PlaneActorIndex;
+      // Multiple actors
+      std::vector< vtkSmartPointer< vtkImageSliceMapper > > SliceMappers;
+      std::vector< vtkSmartPointer< vtkImageActor > >       ImageActors;
+
+      // Unique objects
+      vtkSmartPointer< vtkPolyData >       PlaneSource;
+      vtkSmartPointer< vtkPolyDataMapper > PlaneMapper;
+      char                                 TextBuffer[ 1024 ];
+      vtkSmartPointer< vtkTextActor >      TextActor;
+      vtkSmartPointer< vtkActor >          PlaneActor;
     };
 
   } // ecapseman
index 2f7ce682a97e80585589e6a01a14873b52b3636a..eea3b64550154d4f11c77a276e9615924e57f4f7 100644 (file)
@@ -1,10 +1,8 @@
 #include <cpExtensions/Visualization/MPRActors.h>
 
+#include <vtkAlgorithmOutput.h>
 #include <vtkImageData.h>
 #include <vtkInformation.h>
-#include <vtkOutlineSource.h>
-#include <vtkPolyDataMapper.h>
-#include <vtkProperty.h>
 #include <vtkRenderer.h>
 #include <vtkWindowLevelLookupTable.h>
 
@@ -17,46 +15,110 @@ New( )
 }
 
 // -------------------------------------------------------------------------
-cpExtensions::Visualization::
-ImageSliceActors* cpExtensions::Visualization::MPRActors::
-GetSliceActors( const int& i ) const
+int cpExtensions::Visualization::MPRActors::
+AddInputConnection( vtkAlgorithmOutput* aout )
 {
-  if( i < 3 )
-    return( this->Slices[ 0 ][ i ] );
+  int N = this->ImageMaps.size( );
+  if( N == 0 )
+  {
+    this->ImageMaps.push_back(
+      vtkSmartPointer< vtkImageMapToColors >::New( )
+      );
+    this->ImageMaps[ 0 ]->SetInputConnection( aout );
+    this->SetLookupTableToWindowLevel( 0 );
+    this->_Update( 0 );
+    return( 0 );
+  }
   else
-    return( NULL );
-}
+  {
+    // Check if the image share the same space
+    vtkImageData* ref_image = this->_Image( 0 );
+    vtkImageData* new_image =
+      vtkImageData::SafeDownCast(
+        aout->GetProducer( )->GetOutputInformation( 0 )->
+        Get( vtkDataObject::DATA_OBJECT( ) )
+        );
+    int ref_ext[ 6 ], new_ext[ 6 ];
+    ref_image->GetExtent( ref_ext );
+    new_image->GetExtent( new_ext );
+    if(
+      ref_ext[ 0 ] == new_ext[ 0 ] && ref_ext[ 1 ] == new_ext[ 1 ] &&
+      ref_ext[ 2 ] == new_ext[ 2 ] && ref_ext[ 3 ] == new_ext[ 3 ] &&
+      ref_ext[ 4 ] == new_ext[ 4 ] && ref_ext[ 5 ] == new_ext[ 5 ]
+      )
+    {
+      this->ImageMaps.push_back(
+        vtkSmartPointer< vtkImageMapToColors >::New( )
+        );
+      this->ImageMaps[ N ]->SetInputConnection( aout );
+      this->SetLookupTableToWindowLevel( N );
+      this->_Update( N );
+      return( N );
+    }
+    else
+      return( -1 );
 
-// -------------------------------------------------------------------------
-void cpExtensions::Visualization::MPRActors::
-SetInputConnection( vtkAlgorithmOutput* aout )
-{
-  this->ImageMapToColors->SetInputConnection( aout );
-  this->SetLookupTableToWindowLevel( );
-  this->_UpdateSlices( );
+  } // fi
 }
 
 // -------------------------------------------------------------------------
-void cpExtensions::Visualization::MPRActors::
-SetInputData( vtkImageData* image )
+int cpExtensions::Visualization::MPRActors::
+AddInputData( vtkImageData* image )
 {
-  this->ImageMapToColors->SetInputData( image );
-  this->SetLookupTableToWindowLevel( );
-  this->_UpdateSlices( );
+  int N = this->ImageMaps.size( );
+  if( N == 0 )
+  {
+    this->ImageMaps.push_back(
+      vtkSmartPointer< vtkImageMapToColors >::New( )
+      );
+    this->ImageMaps[ 0 ]->SetInputData( image );
+    this->SetLookupTableToWindowLevel( 0 );
+    this->_Update( 0 );
+    return( 0 );
+  }
+  else
+  {
+    // Check if the image share the same space
+    vtkImageData* ref_image = this->_Image( 0 );
+    vtkImageData* new_image = image;
+    int ref_ext[ 6 ], new_ext[ 6 ];
+    ref_image->GetExtent( ref_ext );
+    new_image->GetExtent( new_ext );
+    if(
+      ref_ext[ 0 ] == new_ext[ 0 ] && ref_ext[ 1 ] == new_ext[ 1 ] &&
+      ref_ext[ 2 ] == new_ext[ 2 ] && ref_ext[ 3 ] == new_ext[ 3 ] &&
+      ref_ext[ 4 ] == new_ext[ 4 ] && ref_ext[ 5 ] == new_ext[ 5 ]
+      )
+    {
+      this->ImageMaps.push_back(
+        vtkSmartPointer< vtkImageMapToColors >::New( )
+        );
+      this->ImageMaps[ N ]->SetInputData( image );
+      this->SetLookupTableToWindowLevel( N );
+      this->_Update( N );
+      return( N );
+    }
+    else
+      return( -1 );
+
+  } // fi
 }
 
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::MPRActors::
-PushDataInto(
-  vtkRenderer* x, vtkRenderer* y, vtkRenderer* z, vtkRenderer* w
-  )
+PushDataInto( vtkRenderer* x, vtkRenderer* y, vtkRenderer* z, vtkRenderer* w )
 {
   vtkRenderer* rends[] = { x, y, z };
   for( int i = 0; i < 3; ++i )
   {
     if( rends[ i ] != NULL )
     {
-      rends[ i ]->AddActor( this->Slices[ 0 ][ i ]->GetImageActor( ) );
+      for(
+        unsigned int k = 0;
+        k < this->Slices[ 0 ][ i ]->GetNumberOfImageActors( );
+        ++k
+        )
+        rends[ i ]->AddActor( this->Slices[ 0 ][ i ]->GetImageActor( k ) );
       rends[ i ]->AddActor( this->Slices[ 0 ][ i ]->GetTextActor( ) );
       for( int j = 0; j < 3; ++j )
         rends[ i ]->AddActor( this->Slices[ 0 ][ j ]->GetPlaneActor( ) );
@@ -64,7 +126,12 @@ PushDataInto(
     } // fi
     if( w != NULL )
     {
-      w->AddActor( this->Slices[ 1 ][ i ]->GetImageActor( ) );
+      for(
+        unsigned int k = 0;
+        k < this->Slices[ 1 ][ i ]->GetNumberOfImageActors( );
+        ++k
+        )
+        w->AddActor( this->Slices[ 1 ][ i ]->GetImageActor( k ) );
       w->AddActor( this->Slices[ 1 ][ i ]->GetPlaneActor( ) );
 
     } // fi
@@ -76,63 +143,75 @@ PushDataInto(
 
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::MPRActors::
-PopDataFrom( vtkRenderer* x, vtkRenderer* y, vtkRenderer* z, vtkRenderer* w )
+PopDataFrom(
+  vtkRenderer* x,
+  vtkRenderer* y,
+  vtkRenderer* z,
+  vtkRenderer* w
+  )
 {
   vtkRenderer* rends[] = { x, y, z };
   for( int i = 0; i < 3; ++i )
   {
     if( rends[ i ] != NULL )
     {
-      rends[ i ]->RemoveActor( this->Slices[ 0 ][ i ]->GetImageActor( ) );
+      for(
+        unsigned int k = 0;
+        k < this->Slices[ 0 ][ i ]->GetNumberOfImageActors( );
+        ++k
+        )
+        rends[ i ]->RemoveActor( this->Slices[ 0 ][ i ]->GetImageActor( k ) );
       rends[ i ]->RemoveActor( this->Slices[ 0 ][ i ]->GetTextActor( ) );
       for( int j = 0; j < 3; ++j )
         rends[ i ]->RemoveActor( this->Slices[ 0 ][ j ]->GetPlaneActor( ) );
-      if( w != NULL )
-      {
-        w->RemoveActor( this->Slices[ 1 ][ i ]->GetImageActor( ) );
-        w->RemoveActor( this->Slices[ 1 ][ i ]->GetPlaneActor( ) );
 
-      } // fi
+    } // fi
+    if( w != NULL )
+    {
+      for(
+        unsigned int k = 0;
+        k < this->Slices[ 1 ][ i ]->GetNumberOfImageActors( );
+        ++k
+        )
+        w->RemoveActor( this->Slices[ 1 ][ i ]->GetImageActor( k ) );
+      w->RemoveActor( this->Slices[ 1 ][ i ]->GetPlaneActor( ) );
 
     } // fi
 
   } // rof
-
   if( w != NULL )
     w->RemoveActor( this->ImageOutlineActor );
 }
 
-// -------------------------------------------------------------------------
-vtkScalarsToColors* cpExtensions::Visualization::MPRActors::
-GetLookupTable( ) const
-{
-  return( this->ImageMapToColors->GetLookupTable( ) );
-}
-
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::MPRActors::
-SetLookupTable( vtkScalarsToColors* lut )
+SetLookupTable( unsigned int i, vtkScalarsToColors* lut )
 {
-  this->ImageMapToColors->SetLookupTable( lut );
-  this->ImageMapToColors->Update( );
-  this->Modified( );
+  if( i < this->ImageMaps.size( ) )
+  {
+    this->ImageMaps[ i ]->SetLookupTable( lut );
+    this->ImageMaps[ i ]->Update( );
+    this->Modified( );
+
+  } // fi
 }
 
 // -------------------------------------------------------------------------
-vtkWindowLevelLookupTable* cpExtensions::Visualization::MPRActors::
-GetLookupTableAsWindowLevel( ) const
+vtkScalarsToColors* cpExtensions::Visualization::MPRActors::
+GetLookupTable( unsigned int i ) const
 {
-  return(
-    dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( ) )
-    );
+  if( i < this->ImageMaps.size( ) )
+    return( this->ImageMaps[ i ]->GetLookupTable( ) );
+  else
+    return( NULL );
 }
 
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::MPRActors::
-SetLookupTableToWindowLevel( )
+SetLookupTableToWindowLevel( unsigned int i )
 {
   // Check if the input has been configured
-  vtkImageData* image = this->_InputImage( );
+  vtkImageData* image = this->_Image( i );
   if( image == NULL )
     return;
 
@@ -145,22 +224,22 @@ SetLookupTableToWindowLevel( )
   lut->SetTableRange( r );
   lut->Build( );
 
-  this->SetLookupTable( lut );
+  this->SetLookupTable( i, lut );
 }
 
 // -------------------------------------------------------------------------
 double cpExtensions::Visualization::MPRActors::
-GetMinWindow( ) const
+GetMinWindow( unsigned int i ) const
 {
-  return( double( 0 ) );
+  return( 0 );
 }
 
 // -------------------------------------------------------------------------
 double cpExtensions::Visualization::MPRActors::
-GetMaxWindow( ) const
+GetMaxWindow( unsigned int i ) const
 {
   // Check if the input has been configured
-  vtkImageData* image = this->_InputImage( );
+  vtkImageData* image = this->_Image( i );
   if( image == NULL )
     return( double( 0 ) );
 
@@ -171,10 +250,10 @@ GetMaxWindow( ) const
 
 // -------------------------------------------------------------------------
 double cpExtensions::Visualization::MPRActors::
-GetMinLevel( ) const
+GetMinLevel( unsigned int i ) const
 {
   // Check if the input has been configured
-  vtkImageData* image = this->_InputImage( );
+  vtkImageData* image = this->_Image( i );
   if( image == NULL )
     return( double( 0 ) );
 
@@ -185,10 +264,10 @@ GetMinLevel( ) const
 
 // -------------------------------------------------------------------------
 double cpExtensions::Visualization::MPRActors::
-GetMaxLevel( ) const
+GetMaxLevel( unsigned int i ) const
 {
   // Check if the input has been configured
-  vtkImageData* image = this->_InputImage( );
+  vtkImageData* image = this->_Image( i );
   if( image == NULL )
     return( double( 0 ) );
 
@@ -199,9 +278,10 @@ GetMaxLevel( ) const
 
 // -------------------------------------------------------------------------
 double cpExtensions::Visualization::MPRActors::
-GetWindow( ) const
+GetWindow( unsigned int i ) const
 {
-  vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
+  vtkWindowLevelLookupTable* lut =
+    dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( i ) );
   if( lut != NULL )
     return( lut->GetWindow( ) );
   else
@@ -210,9 +290,10 @@ GetWindow( ) const
 
 // -------------------------------------------------------------------------
 double cpExtensions::Visualization::MPRActors::
-GetLevel( ) const
+GetLevel( unsigned int i ) const
 {
-  vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
+  vtkWindowLevelLookupTable* lut =
+    dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( i ) );
   if( lut != NULL )
     return( lut->GetLevel( ) );
   else
@@ -221,14 +302,15 @@ GetLevel( ) const
 
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::MPRActors::
-SetWindow( const double& w )
+SetWindow( unsigned int i, const double& w )
 {
-  vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
+  vtkWindowLevelLookupTable* lut =
+    dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( i ) );
   if( lut != NULL )
   {
     lut->SetWindow( w );
     lut->Build( );
-    this->ImageMapToColors->Modified( );
+    this->ImageMaps[ i ]->Modified( );
     this->Modified( );
 
   } // fi
@@ -236,14 +318,15 @@ SetWindow( const double& w )
 
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::MPRActors::
-SetLevel( const double& l )
+SetLevel( unsigned int i, const double& l )
 {
-  vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
+  vtkWindowLevelLookupTable* lut =
+    dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( i ) );
   if( lut != NULL )
   {
     lut->SetLevel( l );
     lut->Build( );
-    this->ImageMapToColors->Modified( );
+    this->ImageMaps[ i ]->Modified( );
     this->Modified( );
 
   } // fi
@@ -251,33 +334,18 @@ SetLevel( const double& l )
 
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::MPRActors::
-SetWindowLevel( const double& w, const double& l )
+ResetWindowLevel( unsigned int i )
 {
-  vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
-  if( lut != NULL )
-  {
-    lut->SetWindow( l );
-    lut->SetLevel( l );
-    lut->Build( );
-    this->ImageMapToColors->Modified( );
-    this->Modified( );
-
-  } // fi
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::Visualization::MPRActors::
-ResetWindowLevel( )
-{
-  vtkImageData* image = this->_InputImage( );
-  vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
+  vtkImageData* image = this->_Image( i );
+  vtkWindowLevelLookupTable* lut =
+    dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( i ) );
   if( image != NULL && lut != NULL )
   {
     double r[ 2 ];
     image->GetScalarRange( r );
     lut->SetTableRange( r );
     lut->Build( );
-    this->ImageMapToColors->Modified( );
+    this->ImageMaps[ i ]->Modified( );
     this->Modified( );
 
   } // fi
@@ -308,7 +376,7 @@ GetSlice( const int& axis ) const
 void cpExtensions::Visualization::MPRActors::
 SetSlice( const int& axis, const int& slice )
 {
-  vtkImageData* image = this->_InputImage( );
+  vtkImageData* image = this->_Image( 0 );
   if( image == NULL )
     return;
 
@@ -333,7 +401,7 @@ SetSlice( const int& axis, const int& slice )
 void cpExtensions::Visualization::MPRActors::
 SetSlice( const int& axis, const double& slice )
 {
-  vtkImageData* image = this->_InputImage( );
+  vtkImageData* image = this->_Image( 0 );
   if( image == NULL )
     return;
 
@@ -353,28 +421,15 @@ ResetSlices( )
   // TODO
 }
 
-// -------------------------------------------------------------------------
-void cpExtensions::Visualization::MPRActors::
-GetImageBounds( double bounds[ 6 ] ) const
-{
-  vtkImageData* image = this->_InputImage( );
-  if( image != NULL )
-    image->GetBounds( bounds );
-}
-
 // -------------------------------------------------------------------------
 cpExtensions::Visualization::MPRActors::
 MPRActors( )
   : Superclass( )
 {
-  this->ImageMapToColors = vtkSmartPointer< vtkImageMapToColors >::New( );
   this->ImageOutlineActor = vtkSmartPointer< vtkActor >::New( );
-  this->Slices[ 0 ][ 0 ] = vtkSmartPointer< _TSlice >::New( );
-  this->Slices[ 0 ][ 1 ] = vtkSmartPointer< _TSlice >::New( );
-  this->Slices[ 0 ][ 2 ] = vtkSmartPointer< _TSlice >::New( );
-  this->Slices[ 1 ][ 0 ] = vtkSmartPointer< _TSlice >::New( );
-  this->Slices[ 1 ][ 1 ] = vtkSmartPointer< _TSlice >::New( );
-  this->Slices[ 1 ][ 2 ] = vtkSmartPointer< _TSlice >::New( );
+  for( unsigned int i = 0; i < 2; ++i )
+    for( unsigned int j = 0; j < 3; ++j )
+      this->Slices[ i ][ j ] = vtkSmartPointer< ImageSliceActors >::New( );
 }
 
 // -------------------------------------------------------------------------
@@ -385,19 +440,25 @@ cpExtensions::Visualization::MPRActors::
 
 // -------------------------------------------------------------------------
 vtkImageData* cpExtensions::Visualization::MPRActors::
-_InputImage( ) const
+_Image( unsigned int i ) const
 {
-  vtkAlgorithm* algo = this->ImageMapToColors->GetInputAlgorithm( );
-  vtkInformation* info = algo->GetOutputInformation( 0 );
-  return(
-    vtkImageData::SafeDownCast( info->Get( vtkDataObject::DATA_OBJECT( ) ) )
-    );
+  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::
-_UpdateSlices( )
+_Update( unsigned int i )
 {
+  /*
   // Check if the input has been configured
   vtkImageData* image = this->_InputImage( );
   if( image == NULL )
@@ -408,7 +469,7 @@ _UpdateSlices( )
   {
     for( int i = 0; i < 3; ++i )
     {
-      this->Slices[ j ][ i ]->SetInputConnection(
+      this->Slices[ j ][ i ]->AddInputConnection(
         this->ImageMapToColors->GetOutputPort( ), i
         );
       this->Slices[ j ][ i ]->UpdateText( );
@@ -432,79 +493,7 @@ _UpdateSlices( )
   this->ImageOutlineActor->GetProperty( )->SetColor( 1, 1, 1 );
   this->ImageOutlineActor->GetProperty( )->SetLineWidth( 1 );
 
-  this->ImageOutlineActorIndex = this->GetNumberOfItems( );
   this->AddItem( this->ImageOutlineActor );
-
-  // Cursor radius
-  /*
-    double spac[ 3 ];
-    image->GetSpacing( spac );
-    double radius = spac[ 0 ];
-    radius = ( spac[ 1 ] < radius )? spac[ 1 ]: radius;
-    radius = ( spac[ 2 ] < radius )? spac[ 2 ]: radius;
-    radius *= double( 6 );
-    this->Cursor->SetRadius( radius );
-    this->CursorMapper->Modified( );
-    this->CursorActor->Modified( );
-
-    // Plane actors
-    for( int a = 0; a < 3; ++a )
-    {
-    // Configure actors
-    this->Planes[ a ].Configure( this->ImageToWindowLevel->GetOutputPort( ), a );
-    this->Planes[ a ].ConfigureRegion( this->Region->GetOutputPort( ) );
-    this->Planes[ a ].UpdateText( this->GetWindow( ), this->GetLevel( ) );
-
-    // Add them to renderer
-    vtkRenderer* ren = this->Interactors[ a ]->GetRenderWindow( )->
-    GetRenderers( )->GetFirstRenderer( );
-    if( ren == NULL )
-    vtkErrorMacro( "At least one interactor doesn't have a valid renderer" );
-    ren->AddActor( this->Planes[ a ].ImageActor );
-    ren->AddActor( this->Planes[ a ].TextActor );
-
-    for( int i = 0; i < 3; ++i )
-    this->Interactors[ a ]->GetRenderWindow( )->
-    GetRenderers( )->GetFirstRenderer( )->
-    AddActor( this->Planes[ i ].PlaneActor );
-
-    } // rof
-  */
-  // Keep track into collection
-  /*
-    this->XPlaneIndex = this->GetNumberOfItems( );
-    this->AddItem( this->Planes[ 0 ].ImageActor.GetPointer( ) );
-    this->XTextIndex = this->GetNumberOfItems( );
-    this->AddItem( this->Planes[ 0 ].TextActor.GetPointer( ) );
-    this->XBoundsIndex = this->GetNumberOfItems( );
-    this->AddItem( this->Planes[ 0 ].PlaneActor.GetPointer( ) );
-
-    this->YPlaneIndex = this->GetNumberOfItems( );
-    this->AddItem( this->Planes[ 1 ].ImageActor.GetPointer( ) );
-    this->YTextIndex = this->GetNumberOfItems( );
-    this->AddItem( this->Planes[ 1 ].TextActor.GetPointer( ) );
-    this->YBoundsIndex = this->GetNumberOfItems( );
-    this->AddItem( this->Planes[ 1 ].PlaneActor.GetPointer( ) );
-
-    this->ZPlaneIndex = this->GetNumberOfItems( );
-    this->AddItem( this->Planes[ 2 ].ImageActor.GetPointer( ) );
-    this->ZTextIndex = this->GetNumberOfItems( );
-    this->AddItem( this->Planes[ 2 ].TextActor.GetPointer( ) );
-    this->ZBoundsIndex = this->GetNumberOfItems( );
-    this->AddItem( this->Planes[ 2 ].PlaneActor.GetPointer( ) );
-  */
-  // Initialize slice visualization
-  // this->ResetSlices( );
-
-  /*
-    #error CONTOUR_WIDGET <- ACA VOY
-    static vtkSmartPointer<vtkOrientedGlyphContourRepresentation> contourRep =
-    vtkSmartPointer<vtkOrientedGlyphContourRepresentation>::New();
-    static vtkSmartPointer<vtkContourWidget> contourWidget =
-    vtkSmartPointer<vtkContourWidget>::New();
-    contourWidget->SetInteractor( zi );
-    contourWidget->SetRepresentation( contourRep );
-    contourWidget->On( );
   */
 }
 
index c8718a31b231cb3f9505fb55f099ec504bdf7d3f..2566c1dff8ede3c65b3a84dbe8613ef16b858be6 100644 (file)
@@ -1,9 +1,12 @@
 #ifndef __CPEXTENSIONS__VISUALIZATION__MPRACTORS__H__
 #define __CPEXTENSIONS__VISUALIZATION__MPRACTORS__H__
 
+#include <vector>
+
 #include <cpExtensions/cpExtensions_Export.h>
 #include <cpExtensions/Visualization/ImageSliceActors.h>
 
+#include <vtkSmartPointer.h>
 #include <vtkActor.h>
 #include <vtkImageMapToColors.h>
 
@@ -12,7 +15,6 @@ class vtkAlgorithmOutput;
 class vtkImageData;
 class vtkRenderer;
 class vtkScalarsToColors;
-class vtkWindowLevelLookupTable;
 
 // -------------------------------------------------------------------------
 namespace cpExtensions
@@ -30,15 +32,19 @@ namespace cpExtensions
     public:
       vtkTypeMacro( MPRActors, vtkPropCollection );
 
-      cpPlugins_ImageSliceActors( ImageOutline, vtkImageActor );
-
     public:
       // Creation
       static MPRActors* New( );
 
-      ImageSliceActors* GetSliceActors( const int& i ) const;
-      void SetInputConnection( vtkAlgorithmOutput* aout );
-      void SetInputData( vtkImageData* image );
+      // TODO: ImageSliceActors* GetSliceActors( const int& i ) const;
+
+      int AddInputConnection( vtkAlgorithmOutput* aout );
+      int AddInputData( vtkImageData* image );
+
+      /*
+        void SetInputConnection( vtkAlgorithmOutput* aout );
+        void SetInputData( vtkImageData* image );
+      */
 
       void PushDataInto(
         vtkRenderer* x,
@@ -54,22 +60,20 @@ namespace cpExtensions
         );
 
       // Lookup table methods
-      vtkScalarsToColors* GetLookupTable( ) const;
-      void SetLookupTable( vtkScalarsToColors* lut );
+      void SetLookupTable( unsigned int i, vtkScalarsToColors* lut );
+      vtkScalarsToColors* GetLookupTable( unsigned int i ) const;
 
       // Grayscale window/level lookup
-      vtkWindowLevelLookupTable* GetLookupTableAsWindowLevel( ) const;
-      void SetLookupTableToWindowLevel( );
-      double GetMinWindow( ) const;
-      double GetMaxWindow( ) const;
-      double GetMinLevel( ) const;
-      double GetMaxLevel( ) const;
-      double GetWindow( ) const;
-      double GetLevel( ) const;
-      void SetWindow( const double& w );
-      void SetLevel( const double& l );
-      void SetWindowLevel( const double& w, const double& l );
-      void ResetWindowLevel( );
+      void SetLookupTableToWindowLevel( unsigned int i );
+      double GetMinWindow( unsigned int i ) const;
+      double GetMaxWindow( unsigned int i ) const;
+      double GetMinLevel( unsigned int i ) const;
+      double GetMaxLevel( unsigned int i ) const;
+      double GetWindow( unsigned int i ) const;
+      double GetLevel( unsigned int i ) const;
+      void SetWindow( unsigned int i, const double& w );
+      void SetLevel( unsigned int i, const double& l );
+      void ResetWindowLevel( unsigned int i );
 
       // Slice access
       int GetSliceNumberMinValue( const int& axis ) const;
@@ -79,15 +83,12 @@ namespace cpExtensions
       void SetSlice( const int& axis, const double& slice );
       void ResetSlices( );
 
-      // General accessors
-      void GetImageBounds( double bounds[ 6 ] ) const;
-
     protected:
       MPRActors( );
       virtual ~MPRActors( );
 
-      vtkImageData* _InputImage( ) const;
-      void _UpdateSlices( );
+      vtkImageData* _Image( unsigned int i ) const;
+      void _Update( unsigned int i );
 
     private:
       // Purposely not implemented
@@ -95,15 +96,9 @@ namespace cpExtensions
       Self& operator=( const Self& );
 
     protected:
-      vtkSmartPointer< vtkImageMapToColors > ImageMapToColors;
-      vtkSmartPointer< vtkActor >            ImageOutlineActor;
-
-      typedef
-        cpExtensions::Visualization::ImageSliceActors
-        _TSlice;
-      vtkSmartPointer< _TSlice > Slices[ 2 ][ 3 ];
-
-      unsigned int ImageOutlineActorIndex;
+      std::vector< vtkSmartPointer< vtkImageMapToColors > > ImageMaps;
+      vtkSmartPointer< vtkActor >         ImageOutlineActor;
+      vtkSmartPointer< ImageSliceActors > Slices[ 2 ][ 3 ];
     };
 
   } // ecapseman