]> Creatis software - cpPlugins.git/commitdiff
Generic MPR+Plugins application base updated.
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Sun, 25 Oct 2015 02:08:03 +0000 (21:08 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Sun, 25 Oct 2015 02:08:03 +0000 (21:08 -0500)
15 files changed:
appli/ImageMPR/ImageMPR.cxx
appli/ImageMPR/ImageMPR.h
lib/cpPlugins/Interface/BaseMPRWindow.cxx
lib/cpPlugins/Interface/BaseMPRWindow.h
lib/cpPlugins/Interface/ParametersQtDialog.cxx
lib/cpPlugins/Interface/Plugins.cxx [new file with mode: 0644]
lib/cpPlugins/Interface/Plugins.h [new file with mode: 0644]
lib/cpPlugins/Interface/ProcessObject.cxx
lib/cpPlugins/Plugins/BasicFilters/MarchingCubes.cxx
lib/cpPlugins/Plugins/IO/DicomSeriesReader.cxx
lib/cpPlugins/Plugins/IO/ImageReader.cxx
lib/cpPlugins/Plugins/IO/ImageWriter.cxx
lib/cpPlugins/Plugins/IO/ImageWriter.h
lib/cpPlugins/Plugins/IO/MeshWriter.cxx
lib/cpPlugins/Plugins/IO/MeshWriter.h

index 4b1a4c92156b593a97c10d48a91bbe7b7a0b5093..133060315c0ef51e7334e63ae97aa6b8ed23625d 100644 (file)
@@ -1,6 +1,8 @@
 #include "ImageMPR.h"
 #include "ui_ImageMPR.h"
 
+#include <QMessageBox>
+
 // -------------------------------------------------------------------------
 #define ImageMPR_ConnectAction( ACTION )                \
   QObject::connect(                                     \
@@ -13,10 +15,11 @@ ImageMPR::
 ImageMPR( QWidget* parent )
   : QMainWindow( parent ),
     m_UI( new Ui::ImageMPR ),
-    m_ImageLoaded( "" ),
-    m_Flooding( false )
+    m_Plugins( new TPlugins ),
+    m_MainImage( NULL )
 {
   this->m_UI->setupUi( this );
+  this->m_Plugins->SetWidget( this );
 
   // Connect actions
   ImageMPR_ConnectAction( OpenImage );
@@ -32,8 +35,8 @@ ImageMPR( QWidget* parent )
   ImageMPR_ConnectAction( ShowPlugins );
 
   // Try to load default plugins
-  this->m_UI->MPR->LoadPlugins( );
-  this->m_UI->MPR->AssociatePluginsToMenu(
+  this->m_Plugins->LoadPluginsConfigurationFile( "Plugins.cfg" );
+  this->m_Plugins->AssociatePluginsToMenu(
     this->m_UI->MenuFilters, this, SLOT( _execPlugin( ) )
     );
 }
@@ -43,32 +46,63 @@ ImageMPR::
 ~ImageMPR( )
 {
   delete this->m_UI;
+  delete this->m_Plugins;
 }
 
 // -------------------------------------------------------------------------
 void ImageMPR::
 _aOpenImage( )
 {
-  if( this->m_ImageLoaded != "" )
+  if( this->m_MainImage.IsNotNull( ) )
     this->m_UI->MPR->ClearAll( );
-  this->m_ImageLoaded = this->m_UI->MPR->LoadImage( );
+  if( this->m_Plugins->ReadImage( this->m_MainImage, true ) )
+  {
+    vtkImageData* vimage = this->m_MainImage->GetVTK< vtkImageData >( );
+    if( vimage == NULL )
+      QMessageBox::critical(
+        this,
+        QMessageBox::tr( "Error showing image." ),
+        QMessageBox::tr(
+          "Image was read, but no valid VTK conversion was found."
+          )
+        );
+    else
+      this->m_UI->MPR->ShowImage( vimage );
+
+  } // fi
 }
 
 // -------------------------------------------------------------------------
 void ImageMPR::
 _aOpenDICOMSeries( )
 {
-  if( this->m_ImageLoaded != "" )
+  if( this->m_MainImage.IsNotNull( ) )
     this->m_UI->MPR->ClearAll( );
-  this->m_ImageLoaded = this->m_UI->MPR->LoadDicomSeries( );
+  if( this->m_Plugins->ReadDicomSeries( this->m_MainImage ) )
+  {
+    vtkImageData* vimage = this->m_MainImage->GetVTK< vtkImageData >( );
+    if( vimage == NULL )
+      QMessageBox::critical(
+        this,
+        QMessageBox::tr( "Error showing image." ),
+        QMessageBox::tr(
+          "Image was read, but no valid VTK conversion was found."
+          )
+        );
+    else
+      this->m_UI->MPR->ShowImage( vimage );
+
+  } // fi
 }
 
 // -------------------------------------------------------------------------
 void ImageMPR::
 _aOpenSegmentation( )
 {
-  if( this->m_ImageLoaded != "" )
+  /*
+    if( this->m_ImageLoaded != "" )
     this->m_ImageLoaded = this->m_UI->MPR->LoadImage( );
+  */
 }
 
 // -------------------------------------------------------------------------
@@ -81,6 +115,8 @@ _aOpenPolyData( )
 void ImageMPR::
 _aSaveImage( )
 {
+  if( this->m_MainImage.IsNotNull( ) )
+    this->m_Plugins->WriteImage( this->m_MainImage, true );
 }
 
 // -------------------------------------------------------------------------
@@ -111,8 +147,8 @@ _aRedo( )
 void ImageMPR::
 _aLoadPlugins( )
 {
-  this->m_UI->MPR->DialogLoadPlugins( );
-  this->m_UI->MPR->AssociatePluginsToMenu(
+  this->m_Plugins->DialogLoadPlugins( );
+  this->m_Plugins->AssociatePluginsToMenu(
     this->m_UI->MenuFilters, this, SLOT( _execPlugin( ) )
     );
 }
@@ -131,21 +167,54 @@ _execPlugin( )
   QAction* action = dynamic_cast< QAction* >( this->sender( ) );
   if( action == NULL )
     return;
+  QMenu* menu = dynamic_cast< QMenu* >( action->parentWidget( ) );
+  if( menu == NULL )
+    return;
+  std::string cate = menu->title( ).toStdString( );
   std::string name = action->text( ).toStdString( );
+  std::string err = "";
 
-  if( name == "cpPlugins::BasicFilters::FloodFillImageFilter" )
+  TPlugins::TProcessObject::Pointer filter;
+  if( this->m_Plugins->CreateFilter( filter, name ) )
   {
-    this->m_Flooding = true;
+    if( cate == "ImageToMeshFilter" )
+    {
+      if( filter->ExecConfigurationDialog( this ) )
+      {
+        filter->SetInput( "Input", this->m_MainImage );
+        this->_Block( );
+        err = filter->Update( );
+        this->_Unblock( );
+        TPlugins::TMesh::Pointer mesh =
+          filter->GetOutput< TPlugins::TMesh >( "Input" );
+        mesh->Print( std::cout );
+
+      } // fi
+
+    } // fi
   }
   else
-  {
-    this->m_Flooding = false;
-    this->m_UI->MPR->ExecuteFilter(
-      name, this->m_ImageLoaded, "SegmentedImage"
+    QMessageBox::critical(
+      this,
+      tr( "Error creating filter" ),
+      tr( "No valid filter defined." )
       );
 
-  } // fi
-
+  /*
+    if( name == "cpPlugins::BasicFilters::FloodFillImageFilter" )
+    {
+    this->m_Flooding = true;
+    }
+    else
+    {
+    this->m_Flooding = false;
+    this->m_UI->MPR->ExecuteFilter(
+    name, this->m_ImageLoaded, "SegmentedImage"
+    );
+    
+    } // fi
+  */
+  
   // Configure filter
   /*
     TPluginFilter::Pointer filter =
index b1d43fff0c560c1a6c20bd270855da25d2536bb2..56b4623e1771ae71db61ea52844be193cbfaf1c9 100644 (file)
@@ -4,6 +4,7 @@
 #include <vector>
 
 // Qt stuff
+#include <QApplication>
 #include <QMainWindow>
 
 // vtk stuff
 #include <cpExtensions/Visualization/MPRObjects.h>
 
 // Plugins interface
-#include <cpPlugins/Interface/Interface.h>
-#include <cpPlugins/Interface/ProcessObject.h>
-#include <cpPlugins/Interface/Image.h>
-#include <cpPlugins/Interface/ImplicitFunction.h>
-#include <cpPlugins/Interface/Mesh.h>
-#include <vtkMetaImageWriter.h>
-#include <vtkMetaImageReader.h>
-
+#include <cpPlugins/Interface/Plugins.h>
 
 // -------------------------------------------------------------------------
 namespace Ui
@@ -123,6 +117,7 @@ public:
   typedef QMainWindow Superclass;
 
   typedef cpExtensions::Visualization::MPRObjects TMPRObjects;
+  typedef cpPlugins::Interface::Plugins           TPlugins;
 
   // Plugins types
   /*
@@ -141,6 +136,18 @@ public:
   explicit ImageMPR( QWidget* parent = 0 );
   virtual ~ImageMPR( );
 
+protected:
+  inline void _Block( )
+    {
+      QApplication::setOverrideCursor( Qt::WaitCursor );
+      this->setEnabled( false );
+    }
+  inline void _Unblock( )
+    {
+      QApplication::restoreOverrideCursor( );
+      this->setEnabled( true );
+    }
+
   /*
     protected:
     bool _LoadPlugins( const std::string& filename );
@@ -165,10 +172,11 @@ private slots:
 
 private:
   Ui::ImageMPR* m_UI;
+  TPlugins*     m_Plugins;
 
-  // Some state flags
-  std::string m_ImageLoaded;
-  bool m_Flooding;
+  // Objects
+  TPlugins::TImage::Pointer m_MainImage;
+  std::vector< TPlugins::TMesh::Pointer > m_Meshes;
 
   // Plugins objects
   /*
index 4cf552c356248086f525fdb9330b4fc3561ab40f..90100a110419e5b6b5b9c09695f4fd2f77411fe7 100644 (file)
@@ -2,27 +2,10 @@
 
 #ifdef cpPlugins_Interface_QT4
 
-#ifdef _WIN32
-#  define PLUGIN_PREFIX ""
-#  define PLUGIN_EXT "dll"
-#  define PLUGIN_REGEX "Plugins file (*.dll);;All files (*)"
-#else // Linux
-#  define PLUGIN_PREFIX "lib"
-#  define PLUGIN_EXT "so"
-#  define PLUGIN_REGEX "Plugins file (*.so);;All files (*)"
-#endif // _WIN32
-
-#include <fstream>
-#include <sstream>
-
-#include <QFileDialog>
-#include <QMessageBox>
-
 // -------------------------------------------------------------------------
 cpPlugins::Interface::BaseMPRWindow::
 BaseMPRWindow( QWidget* parent )
-  : cpExtensions::QT::QuadSplitter( parent ),
-    m_LastLoadedPlugin( "." )
+  : cpExtensions::QT::QuadSplitter( parent )
 {
   // Configure splitter
   this->m_XVTK = new QVTKWidget( this );
@@ -45,352 +28,72 @@ BaseMPRWindow( QWidget* parent )
 cpPlugins::Interface::BaseMPRWindow::
 ~BaseMPRWindow( )
 {
-  if( this->m_WVTK != NULL )
-    delete this->m_WVTK;
-  if( this->m_ZVTK != NULL )
-    delete this->m_ZVTK;
-  if( this->m_YVTK != NULL )
-    delete this->m_YVTK;
-  if( this->m_XVTK != NULL )
-    delete this->m_XVTK;
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::Interface::BaseMPRWindow::
-DialogLoadPlugins( )
-{
-  // Show dialog and check if it was accepted
-  QFileDialog dialog( this );
-  dialog.setFileMode( QFileDialog::ExistingFile );
-  dialog.setDirectory( this->m_LastLoadedPlugin.c_str( ) );
-  dialog.setNameFilter( tr( PLUGIN_REGEX ) );
-  dialog.setDefaultSuffix( tr( PLUGIN_EXT ) );
-  if( !( dialog.exec( ) ) )
-    return;
-
-  std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( );
-  if( !( this->LoadPlugins( fname ) ) )
-    QMessageBox::critical(
-      this, tr( "Ignoring plugin" ), tr( fname.c_str( ) )
-      );
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::Interface::BaseMPRWindow::
-AssociatePluginsToMenu( QMenu* menu, QObject* obj, const char* slot )
-{
-  std::map< std::string, std::set< std::string > >::const_iterator i;
-  std::set< std::string >::const_iterator j;
-
-  menu->clear( );
-  for( i = this->m_Filters.begin( ); i != this->m_Filters.end( ); i++ )
-  {
-    QMenu* newMenu = menu->addMenu( i->first.c_str( ) );
-    for( j = i->second.begin( ); j != i->second.end( ); ++j )
-    {
-      QAction* a = newMenu->addAction( j->c_str( ) );
-      QObject::connect( a, SIGNAL( triggered( ) ), obj, slot );
-
-    } // rof
-
-  } // rof
+  if( this->m_WVTK != NULL ) delete this->m_WVTK;
+  if( this->m_ZVTK != NULL ) delete this->m_ZVTK;
+  if( this->m_YVTK != NULL ) delete this->m_YVTK;
+  if( this->m_XVTK != NULL ) delete this->m_XVTK;
 }
 
 // -------------------------------------------------------------------------
 bool cpPlugins::Interface::BaseMPRWindow::
-LoadPlugins( const std::string& fname )
+ShowImage( vtkImageData* image )
 {
-  this->Block( );
-
-  // Is it already loaded?
-  if( this->m_LoadedPlugins.find( fname ) != this->m_LoadedPlugins.end( ) )
-  {
-    this->Unblock( );
-    return( true );
-
-  } // fi
-
-  // Was it succesfully loaded?
-  if( !( this->m_Interface.Load( fname ) ) )
-  {
-    this->Unblock( );
-    return( false );
-
-  } // fi
-
-  // Update a simple track
-  this->m_LoadedPlugins.insert( fname );
-  this->m_LastLoadedPlugin = fname;
-  this->_UpdatePlugins( );
-
-  this->Unblock( );
-  return( true );
+  bool r = ( image != NULL );
+  if( r )
+    this->m_MPRObjects->AddImage( image );
+  return( r );
 }
 
 // -------------------------------------------------------------------------
-void cpPlugins::Interface::BaseMPRWindow::
-LoadPlugins( )
+bool cpPlugins::Interface::BaseMPRWindow::
+ShowImage( vtkImageData* image, double r, double g, double b )
 {
-  // Load file into a char buffer
-  std::ifstream in(
-    "Plugins.cfg", std::ios::in | std::ios::binary | std::ios::ate
-    );
-  if( !in.is_open( ) )
-    return;
-  std::streampos size = in.tellg( );
-  char* buffer = new char[ size ];
-  in.seekg( 0, std::ios::beg );
-  in.read( buffer, size );
-  in.close( );
-
-  // Read stream
-  std::stringstream in_stream( buffer );
-  while( in_stream )
-  {
-    char line[ 2048 ];
-    in_stream.getline( line, 2048 );
-    this->LoadPlugins( line );
-
-  } // elihw
-
-  // Finish
-  delete buffer;
+  return( false );
 }
 
 // -------------------------------------------------------------------------
-std::string cpPlugins::Interface::BaseMPRWindow::
-LoadImage( )
+bool cpPlugins::Interface::BaseMPRWindow::
+ShowMesh( vtkPolyData* mesh )
 {
-  std::string msg = "";
-  std::string ret = "";
-  if( this->m_ImageReader.IsNull( ) )
-    msg = "No valid image reader. Please load a valid plugin file.";
-
-  if( this->m_ImageReader->ExecConfigurationDialog( this ) )
-  {
-    this->Block( );
-    msg = this->m_ImageReader->Update( );
-    if( msg == "" )
-    {
-      TImage::Pointer image =
-        this->m_ImageReader->GetOutput< TImage >( "Output" );
-      if( this->m_Images.size( ) == 0 )
-        ret = image->GetName( );
-      else
-        ret = "Segmentation";
-      this->m_Images[ ret ] = image;
-      this->m_ImageReader->DisconnectOutputs( );
-      this->m_ImageReader->GetParameters( )->ClearStringList( "FileNames" );
-      vtkImageData* vtk_id = image->GetVTK< vtkImageData >( );
-      if( vtk_id != NULL )
-      {
-        this->m_MPRObjects->AddImage( vtk_id );
-        /*
-          MementoState(m_state, this->m_Image);         
-          this->m_state++;
-        */
-      }
-      else
-        msg = "Read image does not have a valid VTK converter.";
-    }
-    else
-      ret = "";
-
-  } // fi
-
-  // Show errors and return
-  this->Unblock( );
-  if( msg != "" )
-    QMessageBox::critical(
-      this, tr( "Error reading image." ), tr( msg.c_str( ) )
-      );
-  return( ret );
+  return( false );
 }
 
 // -------------------------------------------------------------------------
-std::string cpPlugins::Interface::BaseMPRWindow::
-LoadDicomSeries( )
-{
-  std::string msg = "";
-  std::string ret = "";
-  if( this->m_DicomSeriesReader.IsNull( ) )
-    msg = "No valid DICOM series reader. Please load a valid plugin file.";
-
-  if( this->m_DicomSeriesReader->ExecConfigurationDialog( this ) )
+/*
+  void cpPlugins::Interface::BaseMPRWindow::
+  AddImage( const std::string& name, TImage* image )
   {
-    this->Block( );
-    msg = this->m_DicomSeriesReader->Update( );
-    if( msg == "" )
-    {
-      TImage::Pointer image =
-        this->m_DicomSeriesReader->GetOutput< TImage >( "Output" );
-      if( this->m_Images.size( ) == 0 )
-        ret = image->GetName( );
-      else
-        ret = "Segmentation";
-      this->m_Images[ ret ] = image;
-      this->m_DicomSeriesReader->DisconnectOutputs( );
-      this->m_DicomSeriesReader->GetParameters( )->
-        ClearStringList( "FileNames" );
-      vtkImageData* vtk_id = image->GetVTK< vtkImageData >( );
-      if( vtk_id != NULL )
-      {
-        this->m_MPRObjects->AddImage( vtk_id );
-        /*
-          MementoState(m_state, this->m_Image);         
-          this->m_state++;
-        */
-      }
-      else
-        msg = "Read dicom series does not have a valid VTK converter.";
-    }
-    else
-      ret = "";
-
-  } // fi
-
-  // Show errors and return
-  this->Unblock( );
-  if( msg != "" )
-    QMessageBox::critical(
-      this, tr( "Error reading dicom series." ), tr( msg.c_str( ) )
-      );
-  return( ret );
-}
+  this->m_Images[ name ] = image;
+  vtkImageData* vtk_id =
+  this->m_Images[ name ]->GetVTK< vtkImageData >( );
+  if( vtk_id != NULL )
+  this->m_MPRObjects->AddImage( vtk_id );
+  }
+*/
 
 // -------------------------------------------------------------------------
-std::string cpPlugins::Interface::BaseMPRWindow::
-LoadMesh( )
+double cpPlugins::Interface::BaseMPRWindow::
+GetWindow( ) const
 {
-  return( "" );
+  return( this->m_MPRObjects->GetWindow( ) );
 }
 
 // -------------------------------------------------------------------------
-void cpPlugins::Interface::BaseMPRWindow::
-ExecuteFilter(
-  const std::string& name,
-  const std::string& input_id,
-  const std::string& output_id
-  )
+double cpPlugins::Interface::BaseMPRWindow::
+GetLevel( ) const
 {
-  TProcessObject::Pointer filter =
-    this->m_Interface.CreateProcessObject( name );
-  std::string category = filter->GetClassCategory( );
-  if( category == "ImageToBinaryImageFilter" )
-  {
-    TImages::iterator iIt = this->m_Images.find( input_id );
-    if( iIt != this->m_Images.end( ) )
-    {
-      filter->SetInput( "Input", this->m_Images[ input_id ] );
-      bool dlg_ok = filter->ExecConfigurationDialog( NULL );
-      if( !dlg_ok )
-        return;
-
-      std::string err = filter->Update( );
-      if( err == "" )
-      {
-        this->m_Images[ "Segmentation" ] =
-          filter->GetOutput< TImage >( "Output" );
-        filter->DisconnectOutputs( );
-
-        vtkImageData* vtk_id =
-          this->m_Images[ "Segmentation" ]->GetVTK< vtkImageData >( );
-        if( vtk_id != NULL )
-          this->m_MPRObjects->AddImage( vtk_id );
-      }
-      else
-        QMessageBox::critical(
-          this, tr( "Error with plugin" ), tr( err.c_str( ) )
-          );
-
-    } // fi
-
-  } // fi
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::Interface::BaseMPRWindow::
-AddImage( const std::string& name, TImage* image )
-{
-  this->m_Images[ name ] = image;
-  vtkImageData* vtk_id =
-    this->m_Images[ name ]->GetVTK< vtkImageData >( );
-  if( vtk_id != NULL )
-    this->m_MPRObjects->AddImage( vtk_id );
+  return( this->m_MPRObjects->GetLevel( ) );
 }
 
 // -------------------------------------------------------------------------
 void cpPlugins::Interface::BaseMPRWindow::
 ClearAll( )
 {
-  this->m_MPRObjects->ClearAll( );
-  this->m_Images.clear( );
-  this->m_Meshes.clear( );
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::Interface::BaseMPRWindow::
-_UpdatePlugins( )
-{
-  typedef TInterface::TClasses _C;
-
-  this->m_Filters.clear( );
-  _C& classes = this->m_Interface.GetClasses( );
-  for( _C::const_iterator i = classes.begin( ); i != classes.end( ); ++i )
-  {
-    TProcessObject::Pointer o =
-      this->m_Interface.CreateProcessObject( i->first );
-    std::string name = o->GetClassName( );
-    std::string category = o->GetClassCategory( );
-    if( category == "ImageReader" )
-      this->m_ImageReader = o;
-    else if( category == "ImageWriter" )
-      this->m_ImageWriter = o;
-    else if( category == "MeshReader" )
-      this->m_MeshReader = o;
-    else if( category == "MeshWriter" )
-      this->m_MeshWriter = o;
-    else if( category == "DicomSeriesReader" )
-      this->m_DicomSeriesReader = o;
-    else
-      this->m_Filters[ category ].insert( name );
-
-    /*
-      if( category == "ImageReader" )
-      this->m_ImageReaderClass = name;
-      else if( category == "ImageWriter" )
-      this->m_ImageWriterClass = name;
-      else if( category == "MeshReader" )
-      this->m_MeshReaderClass = name;
-      else if( category == "MeshWriter" )
-      this->m_MeshWriterClass = name;
-      else if( category == "MeshToMeshFilter" )
-      {
-      if( name.find_last_of( "Cutter" ) != std::string::npos )
-      this->m_MeshCutterClass = name;
-      }
-      else if( category == "ImageToImageFilter" )
-      {
-      QAction* action =
-      this->m_UI->MenuImageToImage->addAction( QString( name.c_str( ) ) );
-      QObject::connect(
-      action, SIGNAL( triggered( ) ),
-      this, SLOT( _triggered_actionImageToImage( ) )
-      );
-      }
-      else if( category == "ImageToMeshFilter" )
-      {
-      QAction* action =
-      this->m_UI->MenuImageToMesh->addAction( QString( name.c_str( ) ) );
-      QObject::connect(
-      action, SIGNAL( triggered( ) ),
-      this, SLOT( _triggered_actionImageToMesh( ) )
-      );
-
-      } // fi
-    */
-
-  } // rof
+  /*
+    this->m_MPRObjects->ClearAll( );
+    this->m_Images.clear( );
+    this->m_Meshes.clear( );
+  */
 }
 
 #endif // cpPlugins_Interface_QT4
index 94c5341d48b9b9ce7871876bbec758cd1132cc49..877e4c74c61a264754ae62383effcddc25075075 100644 (file)
@@ -4,26 +4,15 @@
 #include <cpPlugins/Interface/cpPlugins_Interface_Export.h>
 #include <cpPlugins/Interface/Config.h>
 
-#error ACA VOY
-
 #ifdef cpPlugins_Interface_QT4
 
-#include <map>
-#include <set>
-#include <string>
-
 #include <QApplication>
 #include <QMenu>
 #include <QVTKWidget.h>
 
 #include <vtkSmartPointer.h>
-
 #include <cpExtensions/QT/QuadSplitter.h>
 #include <cpExtensions/Visualization/MPRObjects.h>
-#include <cpPlugins/Interface/Interface.h>
-#include <cpPlugins/Interface/ProcessObject.h>
-#include <cpPlugins/Interface/Image.h>
-#include <cpPlugins/Interface/Mesh.h>
 
 namespace cpPlugins
 {
@@ -37,12 +26,6 @@ namespace cpPlugins
       Q_OBJECT;
 
     public:
-      typedef cpPlugins::Interface::Interface     TInterface;
-      typedef cpPlugins::Interface::ProcessObject TProcessObject;
-      typedef cpPlugins::Interface::DataObject    TDataObject;
-      typedef cpPlugins::Interface::Image         TImage;
-      typedef cpPlugins::Interface::Mesh          TMesh;
-
       typedef cpExtensions::Visualization::MPRObjects TMPRObjects;
 
       typedef TMPRObjects::TBaseStyle          TBaseStyle;
@@ -54,75 +37,17 @@ namespace cpPlugins
       typedef TMPRObjects::TKeyCommand         TKeyCommand;
       typedef TMPRObjects::TVoidCommand        TVoidCommand;
 
-      typedef std::set< std::string >           TOrderedStringContainer;
-      typedef std::map< std::string, std::set< std::string > > TFilters;
-
     public:
       explicit BaseMPRWindow( QWidget* parent = 0 );
       virtual ~BaseMPRWindow( );
 
-      void DialogLoadPlugins( );
-      void AssociatePluginsToMenu(
-        QMenu* menu, QObject* obj, const char* slot
-        );
-
-      inline void Block( )
-      {
-        QApplication::setOverrideCursor( Qt::WaitCursor );
-        this->setEnabled( false );
-      }
-      inline void Unblock( )
-      {
-        QApplication::restoreOverrideCursor( );
-        this->setEnabled( true );
-      }
-
-      bool LoadPlugins( const std::string& fname );
-      void LoadPlugins( );
-
-      // Data IO
-      std::string ReadImage( TImage::Pointer& image );
-      std::string ReadDicomSeries( TImage::Pointer& image );
-      std::string ReadMesh( TMesh::Pointer& mesh );
-
-      std::string WriteImage( TImage* image );
-      std::string WriteMesh( TMesh* mesh );
-
-      /* TODO
-         void ExecuteFilter(
-         const std::string& name,
-         const std::string& input_id,
-         const std::string& output_id
-         );
-      */
-
-      // Filter acces
-      bool CreateFilter(
-        TProcessObject::Pointer& filter, const std::string& name
-        )
-      {
-        return( this->m_Interface.CreateProcessObject( name ) );
-      }
-
-      
       // Somme visualization accessors
-      bool ShowImage( TImage* image, bool is_primal = true );
-      bool ShowMesh( TMesh* mesh );
-      double GetWindow( ) const
-      {
-        return( this->m_MPRObjects->GetWindow( ) );
-      }
-      double GetLevel( ) const
-      {
-        return( this->m_MPRObjects->GetLevel( ) );
-      }
-
-      /* TODO
-         void ClearAll( );
-      */
-
-    protected:
-      void _UpdatePlugins( );
+      bool ShowImage( vtkImageData* image );
+      bool ShowImage( vtkImageData* image, double r, double g, double b );
+      bool ShowMesh( vtkPolyData* mesh );
+      double GetWindow( ) const;
+      double GetLevel( ) const;
+      void ClearAll( );
 
     protected:
       vtkSmartPointer< TMPRObjects > m_MPRObjects;
@@ -131,17 +56,6 @@ namespace cpPlugins
       QVTKWidget* m_YVTK;
       QVTKWidget* m_ZVTK;
       QVTKWidget* m_WVTK;
-
-      TInterface m_Interface;
-      TOrderedStringContainer m_LoadedPlugins;
-      std::string m_LastLoadedPlugin;
-
-      TProcessObject::Pointer m_ImageReader;
-      TProcessObject::Pointer m_ImageWriter;
-      TProcessObject::Pointer m_MeshReader;
-      TProcessObject::Pointer m_MeshWriter;
-      TProcessObject::Pointer m_DicomSeriesReader;
-      TFilters m_Filters;
     };
 
   } // ecapseman
index 5a669832393aa1cf8321e1d8fc576244383ebabb..e28a086e2e1f069bf9c017e8851da56040ffdca5 100644 (file)
@@ -202,7 +202,9 @@ exec( )
   QObject::connect( bb, SIGNAL( rejected( ) ), this, SLOT( reject( ) ) );
   this->m_ToolsLayout->addWidget( bb );
 
-  return( this->QDialog::exec( ) );
+  int ret = this->QDialog::exec( );
+  this->syncParameters( );
+  return( ret );
 }
 
 // -------------------------------------------------------------------------
diff --git a/lib/cpPlugins/Interface/Plugins.cxx b/lib/cpPlugins/Interface/Plugins.cxx
new file mode 100644 (file)
index 0000000..30378c2
--- /dev/null
@@ -0,0 +1,525 @@
+#include <cpPlugins/Interface/Plugins.h>
+#include <cpPlugins/Interface/Config.h>
+
+#include <fstream>
+#include <sstream>
+
+#ifdef cpPlugins_Interface_QT4
+
+#include <QApplication>
+#include <QFileDialog>
+#include <QMenu>
+#include <QMessageBox>
+#include <QWidget>
+
+#ifdef _WIN32
+#  define PLUGIN_PREFIX ""
+#  define PLUGIN_EXT "dll"
+#  define PLUGIN_REGEX "Plugins file (*.dll);;All files (*)"
+#else // Linux
+#  define PLUGIN_PREFIX "lib"
+#  define PLUGIN_EXT "so"
+#  define PLUGIN_REGEX "Plugins file (*.so);;All files (*)"
+#endif // _WIN32
+
+#endif // cpPlugins_Interface_QT4
+
+// -------------------------------------------------------------------------
+cpPlugins::Interface::Plugins::
+Plugins( QWidget* widget )
+  : m_Widget( widget ),
+    m_LastLoadedPlugin( "." )
+{
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Interface::Plugins::
+~Plugins( )
+{
+  this->m_Interface.UnloadAll( );
+}
+
+// -------------------------------------------------------------------------
+QWidget* cpPlugins::Interface::Plugins::
+GetWidget( )
+{
+  return( this->m_Widget );
+}
+
+// -------------------------------------------------------------------------
+const QWidget* cpPlugins::Interface::Plugins::
+GetWidget( ) const
+{
+  return( this->m_Widget );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::Plugins::
+SetWidget( QWidget* widget )
+{
+  this->m_Widget = widget;
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::Plugins::
+BlockWidget( )
+{
+#ifdef cpPlugins_Interface_QT4
+  if( this->m_Widget != NULL )
+  {
+    QApplication::setOverrideCursor( Qt::WaitCursor );
+    this->m_Widget->setEnabled( false );
+
+  } // fi
+#endif // cpPlugins_Interface_QT4
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::Plugins::
+UnblockWidget( )
+{
+#ifdef cpPlugins_Interface_QT4
+  if( this->m_Widget != NULL )
+  {
+    QApplication::restoreOverrideCursor( );
+    this->m_Widget->setEnabled( true );
+
+  } // fi
+#endif // cpPlugins_Interface_QT4
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::Plugins::
+DialogLoadPlugins( )
+{
+#ifdef cpPlugins_Interface_QT4
+  if( this->m_Widget != NULL )
+  {
+    QFileDialog dialog( this->m_Widget );
+    dialog.setFileMode( QFileDialog::ExistingFile );
+    dialog.setDirectory( this->m_LastLoadedPlugin.c_str( ) );
+    dialog.setNameFilter( QFileDialog::tr( PLUGIN_REGEX ) );
+    dialog.setDefaultSuffix( QFileDialog::tr( PLUGIN_EXT ) );
+    if( !( dialog.exec( ) ) )
+      return;
+
+    std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( );
+    if( !( this->LoadPlugins( fname ) ) )
+      QMessageBox::critical(
+        this->m_Widget,
+        QMessageBox::tr( "Ignoring plugin" ),
+        QMessageBox::tr( fname.c_str( ) )
+        );
+
+  } // fi
+#endif // cpPlugins_Interface_QT4
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::Plugins::
+AssociatePluginsToMenu( QMenu* menu, QObject* obj, const char* slot )
+{
+#ifdef cpPlugins_Interface_QT4
+  std::map< std::string, std::set< std::string > >::const_iterator i;
+  std::set< std::string >::const_iterator j;
+
+  menu->clear( );
+  for( i = this->m_Filters.begin( ); i != this->m_Filters.end( ); i++ )
+  {
+    QMenu* newMenu = menu->addMenu( i->first.c_str( ) );
+    for( j = i->second.begin( ); j != i->second.end( ); ++j )
+    {
+      QAction* a = newMenu->addAction( j->c_str( ) );
+      QObject::connect( a, SIGNAL( triggered( ) ), obj, slot );
+
+    } // rof
+
+  } // rof
+#endif // cpPlugins_Interface_QT4
+}
+
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::Plugins::
+LoadPlugins( const std::string& fname )
+{
+  this->BlockWidget( );
+
+  // Is it already loaded?
+  bool ret = true;
+  if( this->m_LoadedPlugins.find( fname ) == this->m_LoadedPlugins.end( ) )
+  {
+    // Was it succesfully loaded?
+    ret = this->m_Interface.Load( fname );
+
+    // Update a simple track
+    if( ret )
+    {
+      this->m_LoadedPlugins.insert( fname );
+      this->m_LastLoadedPlugin = fname;
+      this->_Update( );
+
+    } // fi
+
+  } // fi
+
+  this->UnblockWidget( );
+  return( ret );
+}
+
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::Plugins::
+LoadPluginsConfigurationFile( const std::string& fname )
+{
+  // Load file into a char buffer
+  std::ifstream in(
+    fname.c_str( ), std::ios::in | std::ios::binary | std::ios::ate
+    );
+  if( !in.is_open( ) )
+    return( false );
+
+  std::streampos size = in.tellg( );
+  char* buffer = new char[ size ];
+  in.seekg( 0, std::ios::beg );
+  in.read( buffer, size );
+  in.close( );
+
+  // Read stream
+  std::stringstream in_stream( buffer );
+  char line[ 4096 ];
+  while( in_stream )
+  {
+    in_stream.getline( line, 4096 );
+    this->LoadPlugins( line );
+
+  } // elihw
+  delete buffer;
+
+  return( true );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Interface::Plugins::
+TParameters* cpPlugins::Interface::Plugins::
+GetImageReaderParameters( )
+{
+  return( this->m_ImageReader->GetParameters( ) );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Interface::Plugins::
+TParameters* cpPlugins::Interface::Plugins::
+GetMeshReaderParameters( )
+{
+  return( this->m_MeshReader->GetParameters( ) );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Interface::Plugins::
+TParameters* cpPlugins::Interface::Plugins::
+GetImageWriterParameters( )
+{
+  return( this->m_ImageWriter->GetParameters( ) );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Interface::Plugins::
+TParameters* cpPlugins::Interface::Plugins::
+GetMeshWriterParameters( )
+{
+  return( this->m_MeshWriter->GetParameters( ) );
+}
+
+// -------------------------------------------------------------------------
+const cpPlugins::Interface::Plugins::
+TParameters* cpPlugins::Interface::Plugins::
+GetImageReaderParameters( ) const
+{
+  return( this->m_ImageReader->GetParameters( ) );
+}
+
+// -------------------------------------------------------------------------
+const cpPlugins::Interface::Plugins::
+TParameters* cpPlugins::Interface::Plugins::
+GetMeshReaderParameters( ) const
+{
+  return( this->m_MeshReader->GetParameters( ) );
+}
+
+// -------------------------------------------------------------------------
+const cpPlugins::Interface::Plugins::
+TParameters* cpPlugins::Interface::Plugins::
+GetImageWriterParameters( ) const
+{
+  return( this->m_ImageWriter->GetParameters( ) );
+}
+
+// -------------------------------------------------------------------------
+const cpPlugins::Interface::Plugins::
+TParameters* cpPlugins::Interface::Plugins::
+GetMeshWriterParameters( ) const
+{
+  return( this->m_MeshWriter->GetParameters( ) );
+}
+
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::Plugins::
+ReadImage( TImage::Pointer& image, bool exec_qt )
+{
+  std::string ret = "";
+  if( this->m_ImageReader.IsNull( ) )
+    ret = "Plugins: No valid image reader. Please load a valid plugin.";
+
+  if( ret == "" )
+  {
+    bool execute = true;
+    if( exec_qt )
+      execute = this->m_ImageReader->ExecConfigurationDialog( this->m_Widget );
+    if( execute )
+    {
+      this->BlockWidget( );
+      ret = this->m_ImageReader->Update( );
+      this->UnblockWidget( );
+      if( ret == "" )
+      {
+        image = this->m_ImageReader->GetOutput< TImage >( "Output" );
+        this->m_ImageReader->DisconnectOutputs( );
+        this->m_ImageReader->GetParameters( )->ClearStringList( "FileNames" );
+      }
+      else
+        image = NULL;
+
+    } // fi
+
+  } // fi
+
+  // Show an error message and return
+  if( ret != "" )
+  {
+#ifdef cpPlugins_Interface_QT4
+    if( this->m_Widget != NULL )
+      QMessageBox::critical(
+        this->m_Widget,
+        QMessageBox::tr( "Error reading image." ),
+        QMessageBox::tr( ret.c_str( ) )
+        );
+#endif // cpPlugins_Interface_QT4
+    return( false );
+  }
+  else
+    return( true );
+}
+
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::Plugins::
+ReadDicomSeries( TImage::Pointer& image )
+{
+  std::string ret = "";
+  if( this->m_DicomSeriesReader.IsNull( ) )
+    ret = "Plugins: No valid dicom series reader. Please load a valid plugin.";
+
+  if( ret == "" )
+  {
+    if( this->m_DicomSeriesReader->ExecConfigurationDialog( this->m_Widget ) )
+    {
+      this->BlockWidget( );
+      ret = this->m_DicomSeriesReader->Update( );
+      this->UnblockWidget( );
+      if( ret == "" )
+      {
+        image = this->m_DicomSeriesReader->GetOutput< TImage >( "Output" );
+        this->m_DicomSeriesReader->DisconnectOutputs( );
+        this->m_DicomSeriesReader->GetParameters( )->
+          ClearStringList( "FileNames" );
+      }
+      else
+        image = NULL;
+
+    } // fi
+
+  } // fi
+
+  // Show an error message and return
+  if( ret != "" )
+  {
+#ifdef cpPlugins_Interface_QT4
+    if( this->m_Widget != NULL )
+      QMessageBox::critical(
+        this->m_Widget,
+        QMessageBox::tr( "Error reading dicom series." ),
+        QMessageBox::tr( ret.c_str( ) )
+        );
+#endif // cpPlugins_Interface_QT4
+    return( false );
+  }
+  else
+    return( true );
+}
+
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::Plugins::
+ReadMesh( TMesh::Pointer& mesh, bool exec_qt )
+{
+  std::string ret = "";
+  if( this->m_MeshReader.IsNull( ) )
+    ret = "Plugins: No valid mesh reader. Please load a valid plugin.";
+
+  if( ret == "" )
+  {
+    bool execute = true;
+    if( exec_qt )
+      execute = this->m_MeshReader->ExecConfigurationDialog( this->m_Widget );
+    if( execute )
+    {
+      this->BlockWidget( );
+      ret = this->m_MeshReader->Update( );
+      this->UnblockWidget( );
+      if( ret == "" )
+      {
+        mesh = this->m_MeshReader->GetOutput< TMesh >( "Output" );
+        this->m_MeshReader->DisconnectOutputs( );
+      }
+      else
+        mesh = NULL;
+
+    } // fi
+
+  } // fi
+
+  // Show an error message and return
+  if( ret != "" )
+  {
+#ifdef cpPlugins_Interface_QT4
+    if( this->m_Widget != NULL )
+      QMessageBox::critical(
+        this->m_Widget,
+        QMessageBox::tr( "Error reading image." ),
+        QMessageBox::tr( ret.c_str( ) )
+        );
+#endif // cpPlugins_Interface_QT4
+    return( false );
+  }
+  else
+    return( true );
+}
+
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::Plugins::
+WriteImage( TImage* image, bool exec_qt )
+{
+  std::string ret = "";
+  if( this->m_ImageWriter.IsNull( ) )
+    ret = "Plugins: No valid image writer. Please load a valid plugin.";
+
+  if( ret == "" )
+  {
+    bool execute = true;
+    if( exec_qt )
+      execute = this->m_ImageWriter->ExecConfigurationDialog( this->m_Widget );
+    if( execute )
+    {
+      this->m_ImageWriter->SetInput( "Input", image );
+      this->BlockWidget( );
+      ret = this->m_ImageWriter->Update( );
+      this->UnblockWidget( );
+
+    } // fi
+
+  } // fi
+
+  // Show an error message and return
+  if( ret != "" )
+  {
+#ifdef cpPlugins_Interface_QT4
+    if( this->m_Widget != NULL )
+      QMessageBox::critical(
+        this->m_Widget,
+        QMessageBox::tr( "Error reading image." ),
+        QMessageBox::tr( ret.c_str( ) )
+        );
+#endif // cpPlugins_Interface_QT4
+    return( false );
+  }
+  else
+    return( true );
+}
+
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::Plugins::
+WriteMesh( TMesh* mesh, bool exec_qt )
+{
+  std::string ret = "";
+  if( this->m_MeshWriter.IsNull( ) )
+    ret = "Plugins: No valid mesh writer. Please load a valid plugin.";
+
+  if( ret == "" )
+  {
+    bool execute = true;
+    if( exec_qt )
+      execute = this->m_MeshReader->ExecConfigurationDialog( this->m_Widget );
+    if( execute )
+    {
+      this->m_MeshWriter->SetInput( 0, mesh );
+      this->BlockWidget( );
+      ret = this->m_MeshWriter->Update( );
+      this->UnblockWidget( );
+
+    } // fi
+
+  } // fi
+
+  // Show an error message and return
+  if( ret != "" )
+  {
+#ifdef cpPlugins_Interface_QT4
+    if( this->m_Widget != NULL )
+      QMessageBox::critical(
+        this->m_Widget,
+        QMessageBox::tr( "Error reading image." ),
+        QMessageBox::tr( ret.c_str( ) )
+        );
+#endif // cpPlugins_Interface_QT4
+    return( false );
+  }
+  else
+    return( true );
+}
+
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::Plugins::
+CreateFilter( TProcessObject::Pointer& filter, const std::string& name )
+{
+  filter = this->m_Interface.CreateProcessObject( name );
+  return( filter.IsNotNull( ) );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::Plugins::
+_Update( )
+{
+  typedef TInterface::TClasses _C;
+
+  this->m_Filters.clear( );
+  _C& classes = this->m_Interface.GetClasses( );
+  for( _C::const_iterator i = classes.begin( ); i != classes.end( ); ++i )
+  {
+    TProcessObject::Pointer o =
+      this->m_Interface.CreateProcessObject( i->first );
+    std::string name = o->GetClassName( );
+    std::string category = o->GetClassCategory( );
+    if( category == "ImageReader" )
+      this->m_ImageReader = o;
+    else if( category == "ImageWriter" )
+      this->m_ImageWriter = o;
+    else if( category == "MeshReader" )
+      this->m_MeshReader = o;
+    else if( category == "MeshWriter" )
+      this->m_MeshWriter = o;
+    else if( category == "DicomSeriesReader" )
+      this->m_DicomSeriesReader = o;
+    else
+      this->m_Filters[ category ].insert( name );
+
+  } // rof
+}
+
+// eof - $RCSfile$
diff --git a/lib/cpPlugins/Interface/Plugins.h b/lib/cpPlugins/Interface/Plugins.h
new file mode 100644 (file)
index 0000000..847b7e8
--- /dev/null
@@ -0,0 +1,102 @@
+#ifndef __CPPLUGINS__INTERFACE__PLUGINS__H__
+#define __CPPLUGINS__INTERFACE__PLUGINS__H__
+
+#include <cpPlugins/Interface/cpPlugins_Interface_Export.h>
+
+#include <map>
+#include <set>
+#include <string>
+
+#include <cpPlugins/Interface/Interface.h>
+#include <cpPlugins/Interface/ProcessObject.h>
+#include <cpPlugins/Interface/Image.h>
+#include <cpPlugins/Interface/Mesh.h>
+
+class QObject;
+class QMenu;
+class QWidget;
+
+namespace cpPlugins
+{
+  namespace Interface
+  {
+    /**
+     */
+    class cpPlugins_Interface_EXPORT Plugins
+    {
+    public:
+      typedef cpPlugins::Interface::Interface     TInterface;
+      typedef cpPlugins::Interface::ProcessObject TProcessObject;
+      typedef cpPlugins::Interface::DataObject    TDataObject;
+      typedef cpPlugins::Interface::Image         TImage;
+      typedef cpPlugins::Interface::Mesh          TMesh;
+      typedef TProcessObject::TParameters         TParameters;
+
+      typedef std::set< std::string >           TOrderedStringContainer;
+      typedef std::map< std::string, std::set< std::string > > TFilters;
+
+    public:
+      Plugins( QWidget* widget = NULL );
+      virtual ~Plugins( );
+
+      QWidget* GetWidget( );
+      const QWidget* GetWidget( ) const;
+      void SetWidget( QWidget* widget );
+      void BlockWidget( );
+      void UnblockWidget( );
+      void DialogLoadPlugins( );
+      void AssociatePluginsToMenu(
+        QMenu* menu, QObject* obj, const char* slot
+        );
+
+      bool LoadPlugins( const std::string& fname );
+      bool LoadPluginsConfigurationFile( const std::string& fname );
+
+      TParameters* GetImageReaderParameters( );
+      TParameters* GetMeshReaderParameters( );
+      TParameters* GetImageWriterParameters( );
+      TParameters* GetMeshWriterParameters( );
+
+      const TParameters* GetImageReaderParameters( ) const;
+      const TParameters* GetMeshReaderParameters( ) const;
+      const TParameters* GetImageWriterParameters( ) const;
+      const TParameters* GetMeshWriterParameters( ) const;
+
+      // Data IO
+      bool ReadImage( TImage::Pointer& image, bool exec_qt = false );
+      bool ReadDicomSeries( TImage::Pointer& image );
+      bool ReadMesh( TMesh::Pointer& mesh, bool exec_qt = false );
+
+      bool WriteImage( TImage* image, bool exec_qt = false );
+      bool WriteMesh( TMesh* mesh, bool exec_qt = false );
+
+      // Filter acces
+      bool CreateFilter(
+        TProcessObject::Pointer& filter, const std::string& name
+        );
+
+    protected:
+      void _Update( );
+
+    protected:
+      QWidget* m_Widget;
+
+      TInterface m_Interface;
+      TOrderedStringContainer m_LoadedPlugins;
+      std::string m_LastLoadedPlugin;
+
+      TProcessObject::Pointer m_ImageReader;
+      TProcessObject::Pointer m_ImageWriter;
+      TProcessObject::Pointer m_MeshReader;
+      TProcessObject::Pointer m_MeshWriter;
+      TProcessObject::Pointer m_DicomSeriesReader;
+      TFilters m_Filters;
+    };
+
+  } // ecapseman
+
+} // ecapseman
+
+#endif // __CPPLUGINS__INTERFACE__PLUGINS__H__
+
+// eof - $RCSfile$
index a4a123755f80e6afcee30170693bc1770c7e5bb0..9fb4ea71598e27f46131db062507b84d1709204a 100644 (file)
@@ -110,7 +110,6 @@ ExecConfigurationDialog( QWidget* parent )
 
   } // fi
 
-  std::cout << "ok" << std::endl;
   if( !( this->m_ParametersDialog->IsModal( ) ) )
   {
     this->m_ParametersDialog->show( );
@@ -118,6 +117,7 @@ ExecConfigurationDialog( QWidget* parent )
   }
   else
     r = ( this->m_ParametersDialog->exec( ) == 1 );
+
   /*
     r = cpPlugins::Interface::ParametersQtDialog(
     this->m_Parameters,
index 625838c08f6d8d353e139069e713a9b230d98586..22ed81efd955f7a6bb888c33ab379521daf8b3f0 100644 (file)
@@ -54,7 +54,10 @@ _GenerateData( )
     mc->ComputeNormalsOff( );
     mc->SetInputData( vtk_image );
     for( unsigned int i = 0; i < values.size( ); ++i )
+    {
+      std::cout << i << " " << values[ i ] << std::endl;
       mc->SetValue( i, values[ i ] );
+    }
     mc->Update( );
     pd = mc->GetOutput( );
   }
index 913190f1f5f73b288650026c4c0d1c5e1e8fa2ca..e915fcf58e4c746881cd0a655e929309ad4c8e04 100644 (file)
@@ -6,6 +6,7 @@
 #include <sstream>
 #include <vector>
 
+#include <QApplication>
 #include <QDialogButtonBox>
 #include <QDir>
 #include <QFileDialog>
@@ -39,6 +40,10 @@ ExecConfigurationDialog( QWidget* parent )
     return( false );
 
   // Prepare dialog
+  QApplication::setOverrideCursor( Qt::WaitCursor );
+  if( parent != NULL )
+    parent->setEnabled( false );
+
   QDialog* tree_dialog = new QDialog( parent );
   QTreeWidget* tree_widget = new QTreeWidget( tree_dialog );
   QList< QTreeWidgetItem* > tree_items;
@@ -139,6 +144,10 @@ ExecConfigurationDialog( QWidget* parent )
     );
   toolsLayout->addWidget( bb );
 
+  QApplication::restoreOverrideCursor( );
+  if( parent != NULL )
+    parent->setEnabled( true );
+
   if( tree_dialog->exec( ) == 0 )
     return( false );
 
@@ -148,6 +157,10 @@ ExecConfigurationDialog( QWidget* parent )
     QTreeWidgetItem* item_parent = item->parent( );
     if( item_parent != NULL )
     {
+      QApplication::setOverrideCursor( Qt::WaitCursor );
+      if( parent != NULL )
+        parent->setEnabled( false );
+
       std::string serie_dir = item_parent->text( 0 ).toStdString( );
       std::string serie_id = item->text( 0 ).toStdString( );
       serie_id = serie_id.substr( serie_id.find_first_of( " " ) + 1 );
@@ -158,6 +171,10 @@ ExecConfigurationDialog( QWidget* parent )
 
       r = true;
 
+      QApplication::restoreOverrideCursor( );
+      if( parent != NULL )
+        parent->setEnabled( true );
+
     } // fi
 
   } // fi
index d28b129dec2ebfa4bbac4598d9dec6fd39f25453..fc747eb7348f910d36a04f936a10a9f8ee43fce4 100644 (file)
@@ -30,6 +30,7 @@ ExecConfigurationDialog( QWidget* parent )
   dialog.setFileMode( QFileDialog::ExistingFiles );
   dialog.setDirectory( QFileDialog::tr( name.c_str( ) ) );
   dialog.setNameFilters( filters );
+  dialog.setAcceptMode( QFileDialog::AcceptOpen );
   if( dialog.exec( ) )
   {
     QStringList names = dialog.selectedFiles( );
index a6549793232a24096f5c42d61384982ea8dfdb39..63080e27adcece1d9622fbfec2390c659a78d910 100644 (file)
@@ -3,6 +3,43 @@
 
 #include <itkImageFileWriter.h>
 
+#ifdef cpPlugins_Interface_QT4
+#include <QFileDialog>
+#endif // cpPlugins_Interface_QT4
+
+// -------------------------------------------------------------------------
+bool cpPlugins::IO::ImageWriter::
+ExecConfigurationDialog( QWidget* parent )
+{
+  bool r = false;
+
+#ifdef cpPlugins_Interface_QT4
+
+  std::string name = this->m_Parameters->GetString( "FileName" );
+  if( name == "" )
+    name = "save.mhd";
+
+  // Show dialog and check if it was accepted
+  QString qname =
+    QFileDialog::getSaveFileName(
+      parent,
+      QFileDialog::tr( "Save File" ),
+      QFileDialog::tr( name.c_str( ) ),
+      QFileDialog::tr( "Image files (*.bmp *.png *.jpg *.jpeg *.dcm *.mhd *.nhdr *.nrrd *.tiff);;Any file (*)")
+      );
+  name = qname.toStdString( );
+  if( name != "" )
+  {
+    this->m_Parameters->SetString( "FileName", name );
+    r = true;
+
+  } // fi
+
+#endif // cpPlugins_Interface_QT4
+
+  return( r );
+}
+
 // -------------------------------------------------------------------------
 cpPlugins::IO::ImageWriter::
 ImageWriter( )
index 2c97de9beb04da3e58b0a3d021a0cd6a497e1885..849fc4745f3edde9370f8676e97a15b704c2a86c 100644 (file)
@@ -26,6 +26,9 @@ namespace cpPlugins
         cpPlugins::IO::ImageWriter, "ImageWriter"
         );
 
+    public:
+      virtual bool ExecConfigurationDialog( QWidget* parent );
+
     protected:
       ImageWriter( );
       virtual ~ImageWriter( );
index 94af3cca29c4e9be44fc7fd92cbde430bee96aa2..4aae3a3d5553fe3fdf8ba7a1f0dd1cb33813edd8 100644 (file)
@@ -5,6 +5,43 @@
 #include <vtkPolyData.h>
 #include <vtkPolyDataWriter.h>
 
+#ifdef cpPlugins_Interface_QT4
+#include <QFileDialog>
+#endif // cpPlugins_Interface_QT4
+
+// -------------------------------------------------------------------------
+bool cpPlugins::IO::MeshWriter::
+ExecConfigurationDialog( QWidget* parent )
+{
+  bool r = false;
+
+#ifdef cpPlugins_Interface_QT4
+
+  std::string name = this->m_Parameters->GetString( "FileName" );
+  if( name == "" )
+    name = "save.vtk";
+
+  // Show dialog and check if it was accepted
+  QString qname =
+    QFileDialog::getSaveFileName(
+      parent,
+      QFileDialog::tr( "Save File" ),
+      QFileDialog::tr( name.c_str( ) ),
+      QFileDialog::tr( "Mesh files (*.vtk *.stl *.obj);;Any file (*)")
+      );
+  name = qname.toStdString( );
+  if( name != "" )
+  {
+    this->m_Parameters->SetString( "FileName", name );
+    r = true;
+
+  } // fi
+
+#endif // cpPlugins_Interface_QT4
+
+  return( r );
+}
+
 // -------------------------------------------------------------------------
 cpPlugins::IO::MeshWriter::
 MeshWriter( )
index 9def1356b31c11b7f2ae7ad3f08093a45d485489..c97509df79eb2b20d5d100a9a9a661d2da9691f9 100644 (file)
@@ -28,6 +28,9 @@ namespace cpPlugins
         cpPlugins::IO::MeshWriter, "MeshWriter"
         );
 
+    public:
+      virtual bool ExecConfigurationDialog( QWidget* parent );
+
     protected:
       MeshWriter( );
       virtual ~MeshWriter( );