]> Creatis software - cpPlugins.git/commitdiff
vtkPolyData support added
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Mon, 2 Mar 2015 22:24:17 +0000 (17:24 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Mon, 2 Mar 2015 22:24:17 +0000 (17:24 -0500)
20 files changed:
appli/ImageMPR/ImageMPR.cxx
appli/ImageMPR/ImageMPR.h
appli/ImageMPR/ImageMPR.ui
appli/examples/example_ReadImageSeriesWriteImage.cxx
lib/cpPlugins/Extensions/Visualization/ImageSliceActors.cxx
lib/cpPlugins/Extensions/Visualization/ImageSliceActors.h
lib/cpPlugins/Extensions/Visualization/MPRActors.cxx
lib/cpPlugins/Extensions/Visualization/MPRActors.h
lib/cpPlugins/Extensions/Visualization/MPRWithDifferentWindows.cxx
lib/cpPlugins/Extensions/Visualization/MPRWithDifferentWindows.h
lib/cpPlugins/Interface/PolyData.cxx [new file with mode: 0644]
lib/cpPlugins/Interface/PolyData.h [new file with mode: 0644]
lib/cpPlugins/Interface/PolyDataSource.cxx [new file with mode: 0644]
lib/cpPlugins/Interface/PolyDataSource.h [new file with mode: 0644]
lib/cpPlugins/Plugins/CMakeLists.txt
lib/cpPlugins/Plugins/Host.cxx
lib/cpPlugins/Plugins/ImageReader.cxx
lib/cpPlugins/Plugins/ImageReader.h
lib/cpPlugins/Plugins/PolyDataReader.cxx [new file with mode: 0644]
lib/cpPlugins/Plugins/PolyDataReader.h [new file with mode: 0644]

index 76daaa514f58e8bb235b91dceb8b8f09ea9c34b1..71b8e9d765096f9248858b28392ac50575af6198 100644 (file)
@@ -1,6 +1,7 @@
 #include "ImageMPR.h"
 #include "ui_ImageMPR.h"
 
+#include <vtkProperty.h>
 #include <vtkRenderWindow.h>
 
 #include <QFileDialog>
@@ -39,6 +40,10 @@ ImageMPR::ImageMPR( QWidget* parent )
     this->m_UI->actionOpenInputImage, SIGNAL( triggered( ) ),
     this, SLOT( _triggered_actionOpenInputImage( ) )
     );
+  QObject::connect(
+    this->m_UI->actionOpenInputPolyData, SIGNAL( triggered( ) ),
+    this, SLOT( _triggered_actionOpenInputPolyData( ) )
+    );
 
   // Start: load all disponible plugins
   this->_triggered_actionOpenPlugins( );
@@ -85,8 +90,8 @@ _triggered_actionOpenPlugins( )
 
   this->m_BaseClasses[ "ImageReader" ] =
     "cpPlugins::Plugins::ImageReader";
-  this->m_BaseClasses[ "ImageSeriesReader" ] =
-    "cpPlugins::Plugins::ImageSeriesReader";
+  this->m_BaseClasses[ "PolyDataReader" ] =
+    "cpPlugins::Plugins::PolyDataReader";
 }
 
 // -------------------------------------------------------------------------
@@ -105,59 +110,98 @@ _triggered_actionOpenInputImage( )
     return;
   
   this->m_InputImage = NULL;
-  unsigned int nFiles = dialog.selectedFiles( ).size( );
-  if( nFiles == 1 )
+
+  // Get a reader from plugins
+  TPlugin::Pointer reader =
+    this->m_Plugins.CreateProcessObject(
+      this->m_BaseClasses[ "ImageReader" ]
+      );
+
+  // Configure plugins
+  TParameters reader_params = reader->GetDefaultParameters( );
+
+  // File names
+  QStringList q_fnames = dialog.selectedFiles( );
+  QStringList::const_iterator qIt = q_fnames.begin( );
+  for( ; qIt != q_fnames.end( ); ++qIt )
+    reader_params.AddValueToStringList( "FileNames", qIt->toStdString( ) );
+
+  // Other parameters
+  reader_params.SetValueAsString( "PixelType", "short" );
+  reader_params.SetValueAsUint( "ImageDimension", 3 );
+  reader_params.SetValueAsUint( "IsColorImage", 0 );
+  reader->SetParameters( reader_params );
+
+  // Execute and get error message, if any
+  std::string err = reader->Update( );
+
+  // Assign fresh image, if any
+  if( err == "" )
   {
-    std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( );
-
-    TPlugin::Pointer reader =
-      this->m_Plugins.CreateProcessObject(
-        this->m_BaseClasses[ "ImageReader" ]
-        );
-
-    TParameters reader_params = reader->GetDefaultParameters( );
-    reader_params.SetValueAsString( "FileName", fname );
-    reader_params.SetValueAsString( "PixelType", "short" );
-    reader_params.SetValueAsUint( "ImageDimension", 3 );
-    reader_params.SetValueAsUint( "IsColorImage", 0 );
-    reader->SetParameters( reader_params );
-    std::string err = reader->Update( );
-
-    if( err == "" )
-    {
-      this->m_InputImage =
-        dynamic_cast< TPluginImage* >( reader->GetOutput( 0 ) );
-      reader->DisconnectOutputs( );
-    }
-    else
-      QMessageBox::critical(
-        this,
-        tr( "Error reading single image" ),
-        tr( err.c_str( ) )
-        );
+    this->m_InputImage =
+      dynamic_cast< TPluginImage* >( reader->GetOutput( 0 ) );
+    reader->DisconnectOutputs( );
+    if( this->m_InputImage.IsNotNull( ) )
+      this->m_MPR->SetImage( this->m_InputImage->GetVTKImageData( ) );
   }
-  else if( nFiles > 1 )
-  {
-    /* TODO
-       if( this->m_ImageSeriesReaderClassName == "" )
-       {
-       QMessageBox::critical(
-       this,
-       tr( "No plugin to read an image series found!" ),
-       tr( "No plugin to read an image series found!" )
-       );
-       return( ret );
-
-       } // fi
-       std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( );
-       this->m_LastOpenedFile = fname;
-       return( ret );
-    */
+  else
+    QMessageBox::critical(
+      this,
+      tr( "Error reading single image" ),
+      tr( err.c_str( ) )
+      );
+}
 
-  } // fi
+// -------------------------------------------------------------------------
+void ImageMPR::
+_triggered_actionOpenInputPolyData( )
+{
+  // Show dialog and check if it was accepted
+  QFileDialog dialog( this );
+  dialog.setFileMode( QFileDialog::ExistingFile );
+  dialog.setDirectory( "." );
+  dialog.setNameFilter( tr( "VTK file (*.vtk);;All files (*)" ) );
+  dialog.setDefaultSuffix( tr( "vtk" ) );
+  if( !( dialog.exec( ) ) )
+    return;
+  
+  std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( );
+
+  this->m_InputPolyData = NULL;
+
+  // Get a reader from plugins
+  TPlugin::Pointer reader =
+    this->m_Plugins.CreateProcessObject(
+      this->m_BaseClasses[ "PolyDataReader" ]
+      );
 
-  if( this->m_InputImage.IsNotNull( ) )
-    this->m_MPR->SetImage( this->m_InputImage->GetVTKImageData( ) );
+  // Configure plugin
+  TParameters reader_params = reader->GetDefaultParameters( );
+  reader_params.SetValueAsString( "FileName", fname );
+  reader->SetParameters( reader_params );
+
+  // Execute and get error message, if any
+  std::string err = reader->Update( );
+
+  // Assign fresh image, if any
+  if( err == "" )
+  {
+    this->m_InputPolyData =
+      dynamic_cast< TPluginPolyData* >( reader->GetOutput( 0 ) );
+    reader->DisconnectOutputs( );
+    if( this->m_InputPolyData.IsNotNull( ) )
+    {
+      this->m_InputPolyData->GetActor( )->GetProperty( )->SetColor( 1, 0, 1 );
+      this->m_MPR->Add3DActor( this->m_InputPolyData->GetActor( ) );
+
+    } // fi
+  }
+  else
+    QMessageBox::critical(
+      this,
+      tr( "Error reading polydata" ),
+      tr( err.c_str( ) )
+      );
 }
 
 // eof - $RCSfile$
index 4f5144477fc1b695830fbcbcae54da7ee9591182..b8d91f12a60828cb4bd680e533a30f775b6318e9 100644 (file)
@@ -15,6 +15,7 @@
 #include <cpPlugins/Interface/Interface.h>
 #include <cpPlugins/Interface/ProcessObject.h>
 #include <cpPlugins/Interface/Image.h>
+#include <cpPlugins/Interface/PolyData.h>
 #include <cpPlugins/Interface/DataObject.h>
 #include <cpPlugins/Extensions/Visualization/MPRWithDifferentWindows.h>
 
@@ -38,6 +39,7 @@ public:
   typedef cpPlugins::Interface::Object        TPluginObject;
   typedef cpPlugins::Interface::DataObject    TPluginData;
   typedef cpPlugins::Interface::Image         TPluginImage;
+  typedef cpPlugins::Interface::PolyData      TPluginPolyData;
   typedef cpPlugins::Interface::ProcessObject TPlugin;
   typedef cpPlugins::Interface::Parameters    TParameters;
 
@@ -51,6 +53,7 @@ public:
 private slots:
   void _triggered_actionOpenPlugins( );
   void _triggered_actionOpenInputImage( );
+  void _triggered_actionOpenInputPolyData( );
 
 private:
   Ui::ImageMPR* m_UI;
@@ -62,7 +65,8 @@ private:
   TStringMap m_BaseClasses;
 
   // Real data
-  TPluginImage::Pointer m_InputImage;
+  TPluginImage::Pointer    m_InputImage;
+  TPluginPolyData::Pointer m_InputPolyData;
 
   // Visualization stuff
   TMPR* m_MPR;
index 928c027eb2b134caffe17c19d8540fe104680e1c..be08528b5f886d12f719078896ba5c84994978c5 100644 (file)
     <addaction name="actionOpenPlugins"/>
     <addaction name="separator"/>
     <addaction name="actionOpenInputImage"/>
+    <addaction name="actionOpenInputPolyData"/>
     <addaction name="separator"/>
     <addaction name="actionExit"/>
    </widget>
     <string>Exit</string>
    </property>
   </action>
+  <action name="actionOpenInputPolyData">
+   <property name="text">
+    <string>Open polydata</string>
+   </property>
+   <property name="shortcut">
+    <string>Ctrl+M</string>
+   </property>
+  </action>
  </widget>
  <layoutdefault spacing="6" margin="11"/>
  <customwidgets>
index fdd434124948cb268af436e2d9049bd6767c18f7..6825bd2b8c296f1b34ba195692ae590973061073 100644 (file)
@@ -55,7 +55,7 @@ int main( int argc, char* argv[] )
   // Configure reader
   TParameters reader_params = reader->GetDefaultParameters( );
   for( int i = 6; i < argc; ++i )
-    reader_params.AddValueToStringList( "FileNames", argv[ 1 ] );
+    reader_params.AddValueToStringList( "FileNames", argv[ i ] );
   reader_params.SetValueAsString( "PixelType", pixel_type );
   reader_params.SetValueAsUint( "ImageDimension", dimensions );
   reader_params.SetValueAsUint( "IsColorImage", ( is_color? 1: 0 ) );
index 0ec6bb85a1d2167d388bb3e58e9cd82745696520..2b52fb98827755edaa5c67a979e50178e26e2421 100644 (file)
@@ -2,6 +2,7 @@
 
 #include <vtkAlgorithmOutput.h>
 #include <vtkCellArray.h>
+#include <vtkImageData.h>
 #include <vtkInformation.h>
 #include <vtkPlane.h>
 #include <vtkPoints.h>
@@ -21,7 +22,6 @@ New( )
 void cpPlugins::Extensions::Visualization::ImageSliceActors::
 SetInputConnection( vtkAlgorithmOutput* aout, int axis )
 {
-  this->InputAlgorithm = aout;
   this->SliceMapper->SetInputConnection( aout );
   this->SliceMapper->SetOrientation( axis );
   this->SliceMapper->Update( );
@@ -33,16 +33,14 @@ SetInputConnection( vtkAlgorithmOutput* aout, int axis )
 
 // -------------------------------------------------------------------------
 void cpPlugins::Extensions::Visualization::ImageSliceActors::
-SetSegmentationConnection( vtkAlgorithmOutput* aout )
+SetInputData( vtkImageData* data, int axis )
 {
-  this->SegmentationAlgorithm = aout;
-  this->SegmentationSliceMapper->SetInputConnection( aout );
-  this->SegmentationSliceMapper->
-    SetOrientation( this->SliceMapper->GetOrientation( ) );
-  this->SegmentationSliceMapper->
-    SetSliceNumber( this->SliceMapper->GetSliceNumber( ) );
-  this->SegmentationActor->SetMapper( this->SegmentationSliceMapper );
-  this->SegmentationActor->Modified( );
+  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( );
 }
 
@@ -92,18 +90,9 @@ GetSliceNumberMaxValue( ) const
 void cpPlugins::Extensions::Visualization::ImageSliceActors::
 SetSliceNumber( const int& slice )
 {
-  if( this->InputAlgorithm == NULL )
-    return;
   this->SliceMapper->SetSliceNumber( slice );
   this->SliceMapper->Update( );
 
-  if( this->SegmentationAlgorithm != NULL )
-  {
-    this->SegmentationSliceMapper->SetSliceNumber( slice );
-    this->SegmentationSliceMapper->Update( );
-
-  } // fi
-
   // Compute plane
   vtkAlgorithm* algo = this->SliceMapper->GetInputAlgorithm( );
   vtkInformation* info = algo->GetOutputInformation( 0 );
@@ -190,7 +179,7 @@ SetSliceNumber( const int& slice )
 
 // -------------------------------------------------------------------------
 void cpPlugins::Extensions::Visualization::ImageSliceActors::
-UpdateText( const double& w, const double& l )
+UpdateText( )
 {
   char axis;
   int axId = this->SliceMapper->GetOrientation( );
@@ -199,8 +188,8 @@ UpdateText( const double& w, const double& l )
   else if( axId == 2 ) axis = 'Z';
 
   std::sprintf(
-    this->TextBuffer, "Axis: %c (%d)\nWin/Lev: %.2f/%.2f",
-    axis, this->SliceMapper->GetSliceNumber( ), w, l
+    this->TextBuffer, "Axis: %c (%d)",
+    axis, this->SliceMapper->GetSliceNumber( )
     );
   this->TextActor->SetInput( this->TextBuffer );
   this->TextActor->Modified( );
@@ -210,26 +199,19 @@ UpdateText( const double& w, const double& l )
 // -------------------------------------------------------------------------
 cpPlugins::Extensions::Visualization::ImageSliceActors::
 ImageSliceActors( )
-  : Superclass( ),
-    InputAlgorithm( NULL ),
-    SegmentationAlgorithm( NULL )
+  : Superclass( )
 {
   this->SliceMapper = vtkSmartPointer< vtkImageSliceMapper >::New( );
-  this->SegmentationSliceMapper =
-    vtkSmartPointer< vtkImageSliceMapper >::New( );
   this->PlaneSource = vtkSmartPointer< vtkPolyData >::New( );
   this->PlaneMapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
-  this->ImageActor = vtkSmartPointer< vtkImageActor >::New( );
-  this->SegmentationActor = vtkSmartPointer< vtkImageActor >::New( );
-  this->TextActor = vtkSmartPointer< vtkTextActor >::New( );
-  this->PlaneActor = vtkSmartPointer< vtkActor >::New( );
+  this->ImageActor  = vtkSmartPointer< vtkImageActor >::New( );
+  this->TextActor   = vtkSmartPointer< vtkTextActor >::New( );
+  this->PlaneActor  = vtkSmartPointer< vtkActor >::New( );
 
   this->ImageActorIndex = this->GetNumberOfItems( );
-  this->SegmentationActorIndex = this->ImageActorIndex + 1;
-  this->TextActorIndex = this->ImageActorIndex + 2;
-  this->PlaneActorIndex = this->ImageActorIndex + 3;
+  this->TextActorIndex = this->ImageActorIndex + 1;
+  this->PlaneActorIndex = this->ImageActorIndex + 2;
   this->AddItem( this->ImageActor );
-  this->AddItem( this->SegmentationActor );
   this->AddItem( this->TextActor );
   this->AddItem( this->PlaneActor );
 
@@ -268,7 +250,6 @@ ImageSliceActors( )
   vtkCoordinate* coord = this->TextActor->GetPositionCoordinate( );
   coord->SetCoordinateSystemToNormalizedViewport( );
   coord->SetValue( 0.01, 0.01 );
-
 }
 
 // -------------------------------------------------------------------------
index c086937e007fa381c8e140e00bd32422619e7986..3d050f38e336061978612bd904b04348e419f82f 100644 (file)
       );                                                                \
   }
 
+// -------------------------------------------------------------------------
 class vtkAlgorithmOutput;
+class vtkImageData;
 
+// -------------------------------------------------------------------------
 namespace cpPlugins
 {
   namespace Extensions
@@ -44,7 +47,6 @@ namespace cpPlugins
         vtkTypeMacro( ImageSliceActors, vtkPropCollection );
 
         cpPlugins_ImageSliceActors( Image, vtkImageActor );
-        cpPlugins_ImageSliceActors( Segmentation, vtkImageActor );
         cpPlugins_ImageSliceActors( Text, vtkTextActor );
         cpPlugins_ImageSliceActors( Plane, vtkActor );
 
@@ -53,7 +55,7 @@ namespace cpPlugins
         static ImageSliceActors* New( );
 
         void SetInputConnection( vtkAlgorithmOutput* aout, int axis );
-        void SetSegmentationConnection( vtkAlgorithmOutput* aout );
+        void SetInputData( vtkImageData* data, int axis );
 
         double* GetDisplayBounds( ) const;
         void GetDisplayBounds( double bounds[ 6 ] ) const;
@@ -63,7 +65,7 @@ namespace cpPlugins
         int GetSliceNumberMinValue( ) const;
         int GetSliceNumberMaxValue( ) const;
         void SetSliceNumber( const int& slice );
-        void UpdateText( const double& w, const double& l );
+        void UpdateText( );
 
       protected:
         ImageSliceActors( );
@@ -75,22 +77,16 @@ namespace cpPlugins
         Self& operator=( const Self& );
 
       protected:
-        vtkAlgorithmOutput* InputAlgorithm;
-        vtkAlgorithmOutput* SegmentationAlgorithm;
-
         vtkSmartPointer< vtkImageSliceMapper > SliceMapper;
-        vtkSmartPointer< vtkImageSliceMapper > SegmentationSliceMapper;
         vtkSmartPointer< vtkPolyData >         PlaneSource;
         vtkSmartPointer< vtkPolyDataMapper >   PlaneMapper;
-        char                                   TextBuffer[ 512 ];
+        char                                   TextBuffer[ 1024 ];
 
         vtkSmartPointer< vtkImageActor > ImageActor;
-        vtkSmartPointer< vtkImageActor > SegmentationActor;
         vtkSmartPointer< vtkTextActor >  TextActor;
         vtkSmartPointer< vtkActor >      PlaneActor;
 
         unsigned int ImageActorIndex;
-        unsigned int SegmentationActorIndex;
         unsigned int TextActorIndex;
         unsigned int PlaneActorIndex;
       };
index 9808111ad8a380b9ac88ae96f8fa82ed8114add3..c58cc5a21d709ea80be716ef0f44ffd920fa5db1 100644 (file)
@@ -1,11 +1,12 @@
 #include <cpPlugins/Extensions/Visualization/MPRActors.h>
 
 #include <vtkImageData.h>
-#include <vtkLookupTable.h>
+#include <vtkInformation.h>
 #include <vtkOutlineSource.h>
 #include <vtkPolyDataMapper.h>
 #include <vtkProperty.h>
 #include <vtkRenderer.h>
+#include <vtkWindowLevelLookupTable.h>
 
 // -------------------------------------------------------------------------
 cpPlugins::Extensions::Visualization::MPRActors*
@@ -28,137 +29,20 @@ GetSliceActors( const int& i ) const
 
 // -------------------------------------------------------------------------
 void cpPlugins::Extensions::Visualization::MPRActors::
-SetInputData( vtkImageData* image )
+SetInputConnection( vtkAlgorithmOutput* aout )
 {
-  if( image == NULL )
-    return;
-
-  this->Image = image;
-
-  this->ImageToWindowLevel->SetInputData( this->Image );
-  this->ResetWindowLevel( );
-  this->ImageToWindowLevel->Update( );
-
-  for( int i = 0; i < 3; ++i )
-  {
-    this->Slices[ i ]->SetInputConnection(
-      this->ImageToWindowLevel->GetOutputPort( ), i
-      );
-    this->Slices[ i ]->UpdateText( this->GetWindow( ), this->GetLevel( ) );
-
-  } // rof
-
-  // Create 3D outline
-  vtkSmartPointer< vtkOutlineSource > img_ol =
-    vtkSmartPointer< vtkOutlineSource >::New( );
-  img_ol->SetBounds( this->Image->GetBounds( ) );
-
-  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->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( );
-  */
+  this->ImageMapToColors->SetInputConnection( aout );
+  this->SetLookupTableToWindowLevel( );
+  this->_UpdateSlices( );
 }
 
 // -------------------------------------------------------------------------
 void cpPlugins::Extensions::Visualization::MPRActors::
-SetSegmentationData( vtkImageData* segmentation )
+SetInputData( vtkImageData* image )
 {
-  double range[ 2 ];
-  this->Segmentation = segmentation;
-  this->Segmentation->GetScalarRange( range );
-
-  vtkSmartPointer< vtkLookupTable > lut =
-    vtkSmartPointer< vtkLookupTable >::New( );
-  lut->SetNumberOfTableValues( 2 );
-  lut->SetTableRange( range );
-  lut->SetTableValue( 0, 0, 0, 0, 0 );
-  lut->SetTableValue( 1, 1, 0, 0, 0.4 );
-
-  this->SegmentationToColors->SetInputData( this->Segmentation );
-  this->SegmentationToColors->SetLookupTable( lut );
-  this->SegmentationToColors->Update( );
-
-  for( int i = 0; i < 3; ++i )
-    this->Slices[ i ]->SetSegmentationConnection(
-      this->SegmentationToColors->GetOutputPort( )
-      );
+  this->ImageMapToColors->SetInputData( image );
+  this->SetLookupTableToWindowLevel( );
+  this->_UpdateSlices( );
 }
 
 // -------------------------------------------------------------------------
@@ -174,11 +58,13 @@ PushDataInto( vtkRenderer* x, vtkRenderer* y, vtkRenderer* z, vtkRenderer* w )
       rends[ i ]->AddActor( this->Slices[ i ]->GetTextActor( ) );
       for( int j = 0; j < 3; ++j )
         rends[ i ]->AddActor( this->Slices[ j ]->GetPlaneActor( ) );
-      if( this->Segmentation != NULL )
-        rends[ i ]->AddActor( this->Slices[ i ]->GetSegmentationActor( ) );
       if( w != NULL )
+      {
+        w->AddActor( this->Slices[ i ]->GetImageActor( ) );
         w->AddActor( this->Slices[ i ]->GetPlaneActor( ) );
 
+      } // fi
+
     } // fi
 
   } // rof
@@ -194,6 +80,77 @@ PushDataInto( vtkRenderer* x, vtkRenderer* y, vtkRenderer* z, vtkRenderer* w )
 void cpPlugins::Extensions::Visualization::MPRActors::
 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[ i ]->GetImageActor( ) );
+      rends[ i ]->RemoveActor( this->Slices[ i ]->GetTextActor( ) );
+      for( int j = 0; j < 3; ++j )
+        rends[ i ]->RemoveActor( this->Slices[ j ]->GetPlaneActor( ) );
+      if( w != NULL )
+      {
+        w->RemoveActor( this->Slices[ i ]->GetImageActor( ) );
+        w->RemoveActor( this->Slices[ i ]->GetPlaneActor( ) );
+
+      } // fi
+
+    } // fi
+
+  } // rof
+
+  if( w != NULL )
+  {
+    w->RemoveActor( this->ImageOutlineActor );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+vtkScalarsToColors* cpPlugins::Extensions::Visualization::MPRActors::
+GetLookupTable( ) const
+{
+  return( this->ImageMapToColors->GetLookupTable( ) );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Extensions::Visualization::MPRActors::
+SetLookupTable( vtkScalarsToColors* lut )
+{
+  this->ImageMapToColors->SetLookupTable( lut );
+  this->ImageMapToColors->Update( );
+  this->Modified( );
+}
+
+// -------------------------------------------------------------------------
+vtkWindowLevelLookupTable* cpPlugins::Extensions::Visualization::MPRActors::
+GetLookupTableAsWindowLevel( ) const
+{
+  return(
+    dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( ) )
+    );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Extensions::Visualization::MPRActors::
+SetLookupTableToWindowLevel( )
+{
+  // Check if the input has been configured
+  vtkImageData* image = this->_InputImage( );
+  if( image == NULL )
+    return;
+
+  double r[ 2 ];
+  image->GetScalarRange( r );
+
+  vtkSmartPointer< vtkWindowLevelLookupTable > lut =
+    vtkSmartPointer< vtkWindowLevelLookupTable >::New( );
+  lut->SetScaleToLinear( );
+  lut->SetTableRange( r );
+  lut->Build( );
+
+  this->SetLookupTable( lut );
 }
 
 // -------------------------------------------------------------------------
@@ -207,101 +164,128 @@ GetMinWindow( ) const
 double cpPlugins::Extensions::Visualization::MPRActors::
 GetMaxWindow( ) const
 {
-  if( this->Image == NULL )
+  // Check if the input has been configured
+  vtkImageData* image = this->_InputImage( );
+  if( image == NULL )
     return( double( 0 ) );
 
-  double range[ 2 ];
-  this->Image->GetScalarRange( range );
-  return( range[ 1 ] - range[ 0 ] );
+  double r[ 2 ];
+  image->GetScalarRange( r );
+  return( r[ 1 ] - r[ 0 ] );
 }
 
 // -------------------------------------------------------------------------
 double cpPlugins::Extensions::Visualization::MPRActors::
 GetMinLevel( ) const
 {
-  if( this->Image == NULL )
+  // Check if the input has been configured
+  vtkImageData* image = this->_InputImage( );
+  if( image == NULL )
     return( double( 0 ) );
 
-  double range[ 2 ];
-  this->Image->GetScalarRange( range );
-  return( range[ 0 ] );
+  double r[ 2 ];
+  image->GetScalarRange( r );
+  return( r[ 0 ] );
 }
 
 // -------------------------------------------------------------------------
 double cpPlugins::Extensions::Visualization::MPRActors::
 GetMaxLevel( ) const
 {
-  if( this->Image == NULL )
+  // Check if the input has been configured
+  vtkImageData* image = this->_InputImage( );
+  if( image == NULL )
     return( double( 0 ) );
 
-  double range[ 2 ];
-  this->Image->GetScalarRange( range );
-  return( range[ 1 ] );
+  double r[ 2 ];
+  image->GetScalarRange( r );
+  return( r[ 1 ] );
 }
 
 // -------------------------------------------------------------------------
 double cpPlugins::Extensions::Visualization::MPRActors::
 GetWindow( ) const
 {
-  if( this->Image != NULL )
-    return( this->ImageToWindowLevel->GetWindow( ) );
+  vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
+  if( lut != NULL )
+    return( lut->GetWindow( ) );
   else
-    return( 0 );
+    return( double( 0 ) );
 }
 
 // -------------------------------------------------------------------------
 double cpPlugins::Extensions::Visualization::MPRActors::
 GetLevel( ) const
 {
-  if( this->Image != NULL )
-    return( this->ImageToWindowLevel->GetLevel( ) );
+  vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
+  if( lut != NULL )
+    return( lut->GetLevel( ) );
   else
-    return( 0 );
+    return( double( 0 ) );
 }
 
 // -------------------------------------------------------------------------
 void cpPlugins::Extensions::Visualization::MPRActors::
 SetWindow( const double& w )
 {
-  if( this->Image != NULL )
-    this->ImageToWindowLevel->SetWindow( w );
+  vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
+  if( lut != NULL )
+  {
+    lut->SetWindow( w );
+    lut->Build( );
+    this->ImageMapToColors->Modified( );
+    this->Modified( );
+
+  } // fi
 }
 
 // -------------------------------------------------------------------------
 void cpPlugins::Extensions::Visualization::MPRActors::
 SetLevel( const double& l )
 {
-  if( this->Image != NULL )
-    this->ImageToWindowLevel->SetLevel( l );
+  vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
+  if( lut != NULL )
+  {
+    lut->SetLevel( l );
+    lut->Build( );
+    this->ImageMapToColors->Modified( );
+    this->Modified( );
+
+  } // fi
 }
 
 // -------------------------------------------------------------------------
 void cpPlugins::Extensions::Visualization::MPRActors::
 SetWindowLevel( const double& w, const double& l )
 {
-  this->ImageToWindowLevel->SetWindow( w );
-  this->ImageToWindowLevel->SetLevel( l );
-  for( int i = 0; i < 3; ++i )
-    this->Slices[ i ]->UpdateText( w, l );
+  vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
+  if( lut != NULL )
+  {
+    lut->SetWindow( l );
+    lut->SetLevel( l );
+    lut->Build( );
+    this->ImageMapToColors->Modified( );
+    this->Modified( );
+
+  } // fi
 }
 
 // -------------------------------------------------------------------------
 void cpPlugins::Extensions::Visualization::MPRActors::
 ResetWindowLevel( )
 {
-  double range[ 2 ];
-  this->Image->GetScalarRange( range );
-  this->SetWindowLevel(
-    range[ 1 ] - range[ 0 ],
-    ( ( range[ 1 ] + range[ 0 ] ) / double( 2 ) ) + range[ 0 ]
-    );
-}
+  vtkImageData* image = this->_InputImage( );
+  vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
+  if( image != NULL && lut != NULL )
+  {
+    double r[ 2 ];
+    image->GetScalarRange( r );
+    lut->SetTableRange( r );
+    lut->Build( );
+    this->ImageMapToColors->Modified( );
+    this->Modified( );
 
-// -------------------------------------------------------------------------
-vtkPlane* cpPlugins::Extensions::Visualization::MPRActors::
-GetSlicePlane( const int& axis ) const
-{
-  return( NULL );
+  } // fi
 }
 
 // -------------------------------------------------------------------------
@@ -329,11 +313,13 @@ GetSlice( const int& axis ) const
 void cpPlugins::Extensions::Visualization::MPRActors::
 SetSlice( const int& axis, const int& slice )
 {
-  // Get image data extent
-  if( this->Image == NULL )
+  vtkImageData* image = this->_InputImage( );
+  if( image == NULL )
     return;
+
+  // Get image data extent
   int ext[ 6 ];
-  this->Image->GetExtent( ext );
+  image->GetExtent( ext );
 
   // Check if the slice is valid
   int real = slice;
@@ -351,15 +337,16 @@ SetSlice( const int& axis, const int& slice )
 void cpPlugins::Extensions::Visualization::MPRActors::
 SetSlice( const int& axis, const double& slice )
 {
-  if( this->Image == NULL )
+  vtkImageData* image = this->_InputImage( );
+  if( image == NULL )
     return;
-  
+
   double x[ 3 ] = { double( 0 ) };
   double pcoords[ 3 ];
   int ijk[ 3 ];
 
   x[ axis ] = slice;
-  this->Image->ComputeStructuredCoordinates( x, ijk, pcoords );
+  image->ComputeStructuredCoordinates( x, ijk, pcoords );
   this->SetSlice( axis, ijk[ axis ] );
 }
 
@@ -367,28 +354,28 @@ SetSlice( const int& axis, const double& slice )
 void cpPlugins::Extensions::Visualization::MPRActors::
 ResetSlices( )
 {
+  // TODO
 }
 
 // -------------------------------------------------------------------------
 void cpPlugins::Extensions::Visualization::MPRActors::
 GetImageBounds( double bounds[ 6 ] ) const
 {
+  vtkImageData* image = this->_InputImage( );
+  if( image != NULL )
+    image->GetBounds( bounds );
 }
 
 // -------------------------------------------------------------------------
 cpPlugins::Extensions::Visualization::MPRActors::
 MPRActors( )
-  : Superclass( ),
-    Image( NULL ),
-    Segmentation( NULL )
+  : Superclass( )
 {
-  this->ImageToWindowLevel =
-    vtkSmartPointer< vtkImageMapToWindowLevelColors >::New( );
-  this->SegmentationToColors = vtkSmartPointer< vtkImageMapToColors >::New( );
+  this->ImageMapToColors = vtkSmartPointer< vtkImageMapToColors >::New( );
   this->ImageOutlineActor = vtkSmartPointer< vtkActor >::New( );
-  this->Slices[ 0 ] = vtkSmartPointer< TSlice >::New( );
-  this->Slices[ 1 ] = vtkSmartPointer< TSlice >::New( );
-  this->Slices[ 2 ] = vtkSmartPointer< TSlice >::New( );
+  this->Slices[ 0 ] = vtkSmartPointer< _TSlice >::New( );
+  this->Slices[ 1 ] = vtkSmartPointer< _TSlice >::New( );
+  this->Slices[ 2 ] = vtkSmartPointer< _TSlice >::New( );
 }
 
 // -------------------------------------------------------------------------
@@ -397,4 +384,125 @@ cpPlugins::Extensions::Visualization::MPRActors::
 {
 }
 
+// -------------------------------------------------------------------------
+vtkImageData* cpPlugins::Extensions::Visualization::MPRActors::
+_InputImage( ) const
+{
+  vtkAlgorithm* algo = this->ImageMapToColors->GetInputAlgorithm( );
+  vtkInformation* info = algo->GetOutputInformation( 0 );
+  return(
+    vtkImageData::SafeDownCast( info->Get( vtkDataObject::DATA_OBJECT( ) ) )
+    );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Extensions::Visualization::MPRActors::
+_UpdateSlices( )
+{
+  // Check if the input has been configured
+  vtkImageData* image = this->_InputImage( );
+  if( image == NULL )
+    return;
+  this->ImageMapToColors->Update( );
+
+  for( int i = 0; i < 3; ++i )
+  {
+    this->Slices[ i ]->SetInputConnection(
+      this->ImageMapToColors->GetOutputPort( ), i
+      );
+    this->Slices[ i ]->UpdateText( );
+
+  } // rof
+
+  // 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->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( );
+  */
+}
+
 // eof - $RCSfile$
index d46fa48f68ba664699ca37d365a9c2cc0ec40aa4..e7af3ff3e4b957bcfc4c59a8186eee108e5682b1 100644 (file)
@@ -6,10 +6,15 @@
 
 #include <vtkActor.h>
 #include <vtkImageMapToColors.h>
-#include <vtkImageMapToWindowLevelColors.h>
 
+// -------------------------------------------------------------------------
+class vtkAlgorithmOutput;
+class vtkImageData;
 class vtkRenderer;
+class vtkScalarsToColors;
+class vtkWindowLevelLookupTable;
 
+// -------------------------------------------------------------------------
 namespace cpPlugins
 {
   namespace Extensions
@@ -34,8 +39,8 @@ namespace cpPlugins
         static MPRActors* New( );
 
         ImageSliceActors* GetSliceActors( const int& i ) const;
+        void SetInputConnection( vtkAlgorithmOutput* aout );
         void SetInputData( vtkImageData* image );
-        void SetSegmentationData( vtkImageData* segmentation );
 
         void PushDataInto(
           vtkRenderer* x,
@@ -50,7 +55,13 @@ namespace cpPlugins
           vtkRenderer* w
           );
 
-        // Window/Level
+        // Lookup table methods
+        vtkScalarsToColors* GetLookupTable( ) const;
+        void SetLookupTable( vtkScalarsToColors* lut );
+
+        // Grayscale window/level lookup
+        vtkWindowLevelLookupTable* GetLookupTableAsWindowLevel( ) const;
+        void SetLookupTableToWindowLevel( );
         double GetMinWindow( ) const;
         double GetMaxWindow( ) const;
         double GetMinLevel( ) const;
@@ -63,7 +74,6 @@ namespace cpPlugins
         void ResetWindowLevel( );
 
         // Slice access
-        vtkPlane* GetSlicePlane( const int& axis ) const;
         int GetSliceNumberMinValue( const int& axis ) const;
         int GetSliceNumberMaxValue( const int& axis ) const;
         int GetSlice( const int& axis ) const;
@@ -78,22 +88,22 @@ namespace cpPlugins
         MPRActors( );
         virtual ~MPRActors( );
 
+        vtkImageData* _InputImage( ) const;
+        void _UpdateSlices( );
+
       private:
         // Purposely not implemented
         MPRActors( const Self& );
         Self& operator=( const Self& );
 
       protected:
-        vtkImageData* Image;
-        vtkImageData* Segmentation;
-
-        vtkSmartPointer< vtkImageMapToWindowLevelColors > ImageToWindowLevel;
-        vtkSmartPointer< vtkImageMapToColors >            SegmentationToColors;
-
-        vtkSmartPointer< vtkActor > ImageOutlineActor;
+        vtkSmartPointer< vtkImageMapToColors > ImageMapToColors;
+        vtkSmartPointer< vtkActor >            ImageOutlineActor;
 
-        typedef cpPlugins::Extensions::Visualization::ImageSliceActors TSlice;
-        vtkSmartPointer< TSlice > Slices[ 3 ];
+        typedef
+          cpPlugins::Extensions::Visualization::ImageSliceActors
+          _TSlice;
+        vtkSmartPointer< _TSlice > Slices[ 3 ];
 
         unsigned int ImageOutlineActorIndex;
       };
index f8f86c60d141a4468ed0923f3559c78d4aaa8743..103d32136cb226aac62108a01c21b108c17612d6 100644 (file)
@@ -89,23 +89,6 @@ SetImage( vtkImageData* image )
   this->RenderAll( );
 }
 
-// -------------------------------------------------------------------------
-void cpPlugins::Extensions::Visualization::MPRWithDifferentWindows::
-SetSegmentation( vtkImageData* image )
-{
-  this->m_MPRActors->SetSegmentationData( image );
-  this->m_MPRActors->PushDataInto(
-    this->m_Renderers[ 0 ],
-    this->m_Renderers[ 1 ],
-    this->m_Renderers[ 2 ],
-    this->m_Renderers[ 3 ]
-    );
-
-  this->Render( 0 );
-  this->Render( 1 );
-  this->Render( 2 );
-}
-
 // -------------------------------------------------------------------------
 void cpPlugins::Extensions::Visualization::MPRWithDifferentWindows::
 SetModeToNavigation( )
@@ -166,4 +149,17 @@ RenderAll( )
       this->m_Windows[ i ]->Render( );
 }
 
+// -------------------------------------------------------------------------
+void cpPlugins::Extensions::Visualization::MPRWithDifferentWindows::
+Add3DActor( vtkProp3D* prop )
+{
+  if( this->m_Renderers[ 3 ] != NULL )
+  {
+    this->m_Renderers[ 3 ]->AddActor( prop );
+    this->ResetCamera( 3 );
+    this->Render( 3 );
+
+  } // fi
+}
+
 // eof - $RCSfile$
index 495e6bb4f85c0347e62641eb5ff5ff5a530c0028..aef8ebd9c64f652f76eae99ccb3df12cabc15024 100644 (file)
@@ -62,7 +62,6 @@ namespace cpPlugins
         virtual ~MPRWithDifferentWindows( );
 
         void SetImage( vtkImageData* image );
-        void SetSegmentation( vtkImageData* image );
         void SetModeToNavigation( );
         void SetModeToDeformation( );
 
@@ -71,6 +70,8 @@ namespace cpPlugins
         void Render( const int& id );
         void RenderAll( );
 
+        void Add3DActor( vtkProp3D* prop );
+
       protected:
         // Inputs
         vtkRenderWindow* m_Windows[ 4 ];
diff --git a/lib/cpPlugins/Interface/PolyData.cxx b/lib/cpPlugins/Interface/PolyData.cxx
new file mode 100644 (file)
index 0000000..5abcd19
--- /dev/null
@@ -0,0 +1,65 @@
+
+#include <cpPlugins/Interface/PolyData.h>
+
+// -------------------------------------------------------------------------
+std::string cpPlugins::Interface::PolyData::
+GetClassName( ) const
+{
+  return( "cpPlugins::Interface::PolyData" );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::PolyData::
+SetRealDataObject( itk::DataObject* dobj )
+{
+  // Nothing to be done here
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::PolyData::
+SetRealDataObject( vtkDataObject* dobj )
+{
+  this->m_Data = dynamic_cast< vtkPolyData* >( dobj );
+  if( this->m_Data == NULL )
+    return;
+  this->m_Mapper->SetInputData( this->m_Data );
+  this->m_Actor->SetMapper( this->m_Mapper );
+}
+
+// -------------------------------------------------------------------------
+vtkPolyData* cpPlugins::Interface::PolyData::
+GetData( ) const
+{
+  return( this->m_Data );
+}
+
+// -------------------------------------------------------------------------
+vtkPolyDataMapper* cpPlugins::Interface::PolyData::
+GetMapper( ) const
+{
+  return( this->m_Mapper );
+}
+
+// -------------------------------------------------------------------------
+vtkActor* cpPlugins::Interface::PolyData::
+GetActor( ) const
+{
+  return( this->m_Actor );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Interface::PolyData::
+PolyData( )
+  : Superclass( )
+{
+  this->m_Mapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
+  this->m_Actor = vtkSmartPointer< vtkActor >::New( );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Interface::PolyData::
+~PolyData( )
+{
+}
+
+// eof - $RCSfile$
diff --git a/lib/cpPlugins/Interface/PolyData.h b/lib/cpPlugins/Interface/PolyData.h
new file mode 100644 (file)
index 0000000..e5ead8c
--- /dev/null
@@ -0,0 +1,61 @@
+#ifndef __CPPLUGINS__INTERFACE__POLYDATA__H__
+#define __CPPLUGINS__INTERFACE__POLYDATA__H__
+
+#include <cpPlugins/Interface/cpPlugins_Interface_Export.h>
+#include <cpPlugins/Interface/DataObject.h>
+
+#include <vtkActor.h>
+#include <vtkPolyData.h>
+#include <vtkPolyDataMapper.h>
+#include <vtkSmartPointer.h>
+
+namespace cpPlugins
+{
+  namespace Interface
+  {
+    /**
+     */
+    class cpPlugins_Interface_EXPORT PolyData
+      : public DataObject
+    {
+    public:
+      typedef PolyData                        Self;
+      typedef DataObject                      Superclass;
+      typedef itk::SmartPointer< Self >       Pointer;
+      typedef itk::SmartPointer< const Self > ConstPointer;
+
+    public:
+      itkNewMacro( Self );
+      itkTypeMacro( PolyData, DataObject );
+
+    public:
+      virtual std::string GetClassName( ) const;
+      virtual void SetRealDataObject( itk::DataObject* dobj );
+      virtual void SetRealDataObject( vtkDataObject* dobj );
+
+      vtkPolyData* GetData( ) const;
+      vtkPolyDataMapper* GetMapper( ) const;
+      vtkActor* GetActor( ) const;
+
+    protected:
+      PolyData( );
+      virtual ~PolyData( );
+
+    private:
+      // Purposely not implemented
+      PolyData( const Self& );
+      Self& operator=( const Self& );
+
+    protected:
+      vtkSmartPointer< vtkPolyData >       m_Data;
+      vtkSmartPointer< vtkPolyDataMapper > m_Mapper;
+      vtkSmartPointer< vtkActor >          m_Actor;
+    };
+
+  } // ecapseman
+
+} // ecapseman
+
+#endif // __CPPLUGINS__INTERFACE__POLYDATA__H__
+
+// eof - $RCSfile$
diff --git a/lib/cpPlugins/Interface/PolyDataSource.cxx b/lib/cpPlugins/Interface/PolyDataSource.cxx
new file mode 100644 (file)
index 0000000..e8f32d8
--- /dev/null
@@ -0,0 +1,30 @@
+#include <cpPlugins/Interface/PolyDataSource.h>
+
+// -------------------------------------------------------------------------
+std::string cpPlugins::Interface::PolyDataSource::
+GetClassName( ) const
+{
+  return( "cpPlugins::Interface::PolyDataSource" );
+}
+
+// -------------------------------------------------------------------------
+std::string cpPlugins::Interface::PolyDataSource::
+GetClassType( ) const
+{
+  return( "PolyDataSource" );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Interface::PolyDataSource::
+PolyDataSource( )
+  : Superclass( )
+{
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Interface::PolyDataSource::
+~PolyDataSource( )
+{
+}
+
+// eof - $RCSfile$
diff --git a/lib/cpPlugins/Interface/PolyDataSource.h b/lib/cpPlugins/Interface/PolyDataSource.h
new file mode 100644 (file)
index 0000000..0022048
--- /dev/null
@@ -0,0 +1,45 @@
+#ifndef __CPPLUGINS__INTERFACE__POLYDATASOURCE__H__
+#define __CPPLUGINS__INTERFACE__POLYDATASOURCE__H__
+
+#include <cpPlugins/Interface/cpPlugins_Interface_Export.h>
+#include <cpPlugins/Interface/SourceObject.h>
+
+namespace cpPlugins
+{
+  namespace Interface
+  {
+    /**
+     */
+    class cpPlugins_Interface_EXPORT PolyDataSource
+      : public SourceObject
+    {
+    public:
+      typedef PolyDataSource                  Self;
+      typedef SourceObject                    Superclass;
+      typedef itk::SmartPointer< Self >       Pointer;
+      typedef itk::SmartPointer< const Self > ConstPointer;
+
+    public:
+      itkTypeMacro( PolyDataSource, SourceObject );
+
+    public:
+      virtual std::string GetClassName( ) const;
+      virtual std::string GetClassType( ) const;
+
+    protected:
+      PolyDataSource( );
+      virtual ~PolyDataSource( );
+
+    private:
+      // Purposely not implemented
+      PolyDataSource( const Self& );
+      Self& operator=( const Self& );
+    };
+
+  } // ecapseman
+
+} // ecapseman
+
+#endif // __CPPLUGINS__INTERFACE__POLYDATASOURCE__H__
+
+// eof - $RCSfile$
index 372b1504dbb12cfb3f07cc48392fff9958a773ea..7558bf41a9069f9b904169284df735cc9e37d39c 100644 (file)
@@ -33,6 +33,8 @@ TARGET_LINK_LIBRARIES(
   ${LIBRARY_NAME}
   cpPlugins_Interface
   ${ITK_LIBRARIES}
+  ${VTK_LIBRARIES}
+  vtkIOLegacy
   )
 
 ## eof - $RCSfile$
index b8477ce4d90262692dfb03c30e625e0680dc1080..8cffd6ca794d340a728605d26b2cf2ea61ffdb53 100644 (file)
@@ -4,6 +4,7 @@
 #include <cpPlugins/Plugins/ImageWriter.h>
 #include <cpPlugins/Plugins/MarchingCubes.h>
 #include <cpPlugins/Plugins/MeshReader.h>
+#include <cpPlugins/Plugins/PolyDataReader.h>
 #include <cpPlugins/Plugins/RGBImageToHSVChannelsFilter.h>
 
 /// TODO: doc
@@ -17,6 +18,7 @@ bool connect( pluma::Host& host )
   host.add( new ImageWriterProvider( ) );
   host.add( new MarchingCubesProvider( ) );
   host.add( new MeshReaderProvider( ) );
+  host.add( new PolyDataReaderProvider( ) );
   host.add( new RGBImageToHSVChannelsFilterProvider( ) );
   return( true );
 }
index aa7be8e6ce9c1d1c1f0b8b3cb55f3676d4d4f082..da7b949485bcb72e7bb9947b3a63df4dd88f1ea7 100644 (file)
@@ -2,6 +2,7 @@
 #include <cpPlugins/Interface/Image.h>
 
 #include <itkImageFileReader.h>
+#include <itkImageSeriesReader.h>
 
 #define ITK_MANUAL_INSTANTIATION
 #include <itkImage.h>
@@ -23,7 +24,7 @@ ImageReader( )
   this->_MakeOutput< cpPlugins::Interface::Image >( 0 );
 
   using namespace cpPlugins::Interface;
-  this->m_DefaultParameters.Configure( Parameters::String, "FileName" );
+  this->m_DefaultParameters.Configure( Parameters::StringList, "FileNames" );
   this->m_DefaultParameters.Configure( Parameters::String, "PixelType" );
   this->m_DefaultParameters.Configure( Parameters::Uint, "Dimension" );
   this->m_DefaultParameters.Configure( Parameters::Uint, "IsColorImage" );
@@ -118,35 +119,82 @@ template< class P, unsigned int D >
 std::string cpPlugins::Plugins::ImageReader::
 _GD1( )
 {
-  // Get filename
-  using namespace cpPlugins::Interface;
-  Parameters::TString fname =
-    this->m_Parameters.GetValueAsString( "FileName" );
-
   typedef itk::Image< P, D > _TImage;
-  typedef itk::ImageFileReader< _TImage > _TReader;
 
-  _TReader* reader =
-    dynamic_cast< _TReader* >( this->m_RealProcessObject.GetPointer( ) );
-  if( reader == NULL )
-  {
-    this->m_RealProcessObject = _TReader::New( );
-    reader =
-      dynamic_cast< _TReader* >( this->m_RealProcessObject.GetPointer( ) );
+  // Get filenames
+  using namespace cpPlugins::Interface;
+  std::vector< Parameters::TString > unordered_names;
+  this->m_Parameters.GetValueAsStringList( unordered_names, "FileNames" );
 
-  } // fi
-  reader->SetFileName( fname );
-  try
+  if( unordered_names.size( ) == 1 )
   {
-    reader->Update( );
+    // Read single image
+    typedef itk::ImageFileReader< _TImage > _TSingleReader;
+
+    _TSingleReader* singleReader =
+      dynamic_cast< _TSingleReader* >(
+        this->m_RealProcessObject.GetPointer( )
+        );
+    if( singleReader == NULL )
+    {
+      this->m_RealProcessObject = _TSingleReader::New( );
+      singleReader =
+        dynamic_cast< _TSingleReader* >(
+          this->m_RealProcessObject.GetPointer( )
+          );
+
+    } // fi
+    singleReader->SetFileName( unordered_names.front( ) );
+    try
+    {
+      singleReader->Update( );
+    }
+    catch( itk::ExceptionObject& err )
+    {
+      return( err.GetDescription( ) );
+
+    } // yrt
+    this->_SetOutput( 0, singleReader->GetOutput( ) );
+    return( "" );
   }
-  catch( itk::ExceptionObject& err )
+  else if( unordered_names.size( ) > 1 )
   {
-    return( err.GetDescription( ) );
-
-  } // yrt
-  this->_SetOutput( 0, reader->GetOutput( ) );
-  return( "" );
+    // Read image series
+    std::set< std::string > ordered_names;
+    for( unsigned int i = 0; i < unordered_names.size( ); ++i )
+      ordered_names.insert( unordered_names[ i ] );
+
+    typedef itk::ImageSeriesReader< _TImage > _TMultiReader;
+    _TMultiReader* multiReader =
+      dynamic_cast< _TMultiReader* >(
+        this->m_RealProcessObject.GetPointer( )
+        );
+    if( multiReader == NULL )
+    {
+      this->m_RealProcessObject = _TMultiReader::New( );
+      multiReader =
+        dynamic_cast< _TMultiReader* >(
+          this->m_RealProcessObject.GetPointer( )
+          );
+
+    } // fi
+    std::set< std::string >::const_iterator fnIt = ordered_names.begin( );
+    for( ; fnIt != ordered_names.end( ); ++fnIt )
+      multiReader->AddFileName( *fnIt );
+    try
+    {
+      multiReader->Update( );
+    }
+    catch( itk::ExceptionObject& err )
+    {
+      return( err.GetDescription( ) );
+
+    } // yrt
+    this->_SetOutput( 0, multiReader->GetOutput( ) );
+    return( "" );
+  }
+  else
+    return( "No image filename(s) given." );
 }
 
 // eof - $RCSfile$
index d89fd9aebba8b4fea69e86e16f7599ce6c493c26..61efe0d2858e556d11e2cce2c7a1fce009f35253 100644 (file)
@@ -34,10 +34,10 @@ namespace cpPlugins
       virtual std::string _GenerateData( );
 
       template< unsigned int D >
-      std::string _GD0( );
+        std::string _GD0( );
 
       template< class P, unsigned int D >
-      std::string _GD1( );
+        std::string _GD1( );
 
     private:
       // Purposely not implemented
diff --git a/lib/cpPlugins/Plugins/PolyDataReader.cxx b/lib/cpPlugins/Plugins/PolyDataReader.cxx
new file mode 100644 (file)
index 0000000..95576ac
--- /dev/null
@@ -0,0 +1,73 @@
+#include <cpPlugins/Plugins/PolyDataReader.h>
+#include <cpPlugins/Interface/PolyData.h>
+
+#include <vtkErrorCode.h>
+#include <vtkPolyDataReader.h>
+
+// -------------------------------------------------------------------------
+std::string cpPlugins::Plugins::PolyDataReader::
+GetClassName( ) const
+{
+  return( "cpPlugins::Plugins::PolyDataReader" );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Plugins::PolyDataReader::
+PolyDataReader( )
+  : Superclass( )
+{
+  this->SetNumberOfOutputs( 1 );
+  this->_MakeOutput< cpPlugins::Interface::PolyData >( 0 );
+
+  using namespace cpPlugins::Interface;
+  this->m_DefaultParameters.Configure( Parameters::String, "FileName" );
+  this->m_Parameters = this->m_DefaultParameters;
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Plugins::PolyDataReader::
+~PolyDataReader( )
+{
+}
+
+// -------------------------------------------------------------------------
+std::string cpPlugins::Plugins::PolyDataReader::
+_GenerateData( )
+{
+  // Get filename
+  using namespace cpPlugins::Interface;
+  Parameters::TString fname =
+    this->m_Parameters.GetValueAsString( "FileName" );
+
+  // Create a possible reader
+  vtkPolyDataReader* reader =
+    dynamic_cast< vtkPolyDataReader* >( this->m_Reader.GetPointer( ) );
+  if( reader == NULL )
+  {
+    this->m_Reader = vtkSmartPointer< vtkPolyDataReader >::New( );
+    reader =
+      dynamic_cast< vtkPolyDataReader* >( this->m_Reader.GetPointer( ) );
+
+  } // fi
+  reader->SetFileName( fname.c_str( ) );
+  reader->Update( );
+  unsigned long error = reader->GetErrorCode( );
+  if( error == vtkErrorCode::NoError )
+  {
+    if( this->m_Outputs[ 0 ].IsNotNull( ) )
+    {
+      cpPlugins::Interface::PolyData* pdata =
+        dynamic_cast< cpPlugins::Interface::PolyData* >(
+          this->m_Outputs[ 0 ].GetPointer( )
+          );
+      if( pdata != NULL )
+        pdata->SetRealDataObject( reader->GetOutput( ) );
+
+    } // fi
+    return( "" );
+  }
+  else
+    return( vtkErrorCode::GetStringFromErrorCode( error ) );
+}
+
+// eof - $RCSfile$
diff --git a/lib/cpPlugins/Plugins/PolyDataReader.h b/lib/cpPlugins/Plugins/PolyDataReader.h
new file mode 100644 (file)
index 0000000..106f9a6
--- /dev/null
@@ -0,0 +1,56 @@
+#ifndef __CPPLUGINS__PLUGINS__POLYDATAREADER__H__
+#define __CPPLUGINS__PLUGINS__POLYDATAREADER__H__
+
+#include <cpPlugins/Plugins/cpPlugins_Export.h>
+#include <cpPlugins/Interface/PolyDataSource.h>
+
+#include <vtkAlgorithm.h>
+#include <vtkSmartPointer.h>
+
+namespace cpPlugins
+{
+  namespace Plugins
+  {
+    /**
+     */
+    class cpPlugins_EXPORT PolyDataReader
+      : public cpPlugins::Interface::PolyDataSource
+    {
+    public:
+      typedef PolyDataReader                       Self;
+      typedef cpPlugins::Interface::PolyDataSource Superclass;
+      typedef itk::SmartPointer< Self >            Pointer;
+      typedef itk::SmartPointer< const Self >      ConstPointer;
+
+    public:
+      itkNewMacro( Self );
+      itkTypeMacro( PolyDataReader, cpPluginsInterfacePolyDataSource );
+
+    public:
+      virtual std::string GetClassName( ) const;
+
+    protected:
+      PolyDataReader( );
+      virtual ~PolyDataReader( );
+
+      virtual std::string _GenerateData( );
+
+    private:
+      // Purposely not implemented
+      PolyDataReader( const Self& );
+      Self& operator=( const Self& );
+
+    protected:
+      vtkSmartPointer< vtkAlgorithm > m_Reader;
+    };
+
+    // ---------------------------------------------------------------------
+    CPPLUGINS_INHERIT_PROVIDER( PolyDataReader );
+
+  } // ecapseman
+
+} // ecapseman
+
+#endif // __CPPLUGINS__PLUGINS__POLYDATAREADER__H__
+
+// eof - $RCSfile$