]> Creatis software - cpPlugins.git/commitdiff
Widget integration (step 1/6)
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Fri, 2 Oct 2015 15:59:23 +0000 (10:59 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Fri, 2 Oct 2015 15:59:23 +0000 (10:59 -0500)
CMakeLists.txt
appli/ImageMPR/ImageMPR.cxx
appli/ImageMPR/ImageMPR.h
cmake/cpPluginsConfig.cmake.in
lib/cpPlugins/Plugins/BasicFilters/CMakeLists.txt
lib/cpPlugins/Plugins/IO/CMakeLists.txt
lib/cpPlugins/Plugins/IO/ImageReader.cxx
lib/cpPlugins/Plugins/IO/ImageReader.h
lib/cpPlugins/Plugins/IO/MeshReader.cxx
lib/cpPlugins/Plugins/IO/MeshReader.h

index 83c4b843c7568a621d7a3c7fb8228d59d2cd736c..797b910181a8bb3916e337d60f784520e85b3cf7 100644 (file)
@@ -123,6 +123,22 @@ IF(WIN32 OR APPLE)
     )
 ENDIF(WIN32 OR APPLE)
 
+## =======================
+## = Local bash commands =
+## =======================
+SET(
+  bash_PROGRAMS
+  cpPlugins_createHost
+  )
+
+FOREACH(prog ${bash_PROGRAMS})
+  IF(MSVC)
+    SET(${prog}_APP ${PROJECT_BINARY_DIR}/$(ConfigurationName)/${prog})
+  ELSE(MSVC)
+    SET(${prog}_APP ${PROJECT_BINARY_DIR}/${prog})
+  ENDIF(MSVC)
+ENDFOREACH(prog)
+
 ## ===========================
 ## = Subdirs containing code =
 ## ===========================
index 5951d1fd1872acffdd35b4278d5275b93f6b93c5..6cc4ed1ccb1c85980acd0f4757286b16fec94a34 100644 (file)
@@ -135,12 +135,8 @@ _LoadPlugins( const std::string& filename )
 
 // -------------------------------------------------------------------------
 std::string ImageMPR::
-_LoadImage( TPluginImage::Pointer& image, const QStringList& names )
+_LoadImage( TPluginImage::Pointer& image )
 {
-  // Block application
-  QApplication::setOverrideCursor( Qt::WaitCursor );
-  this->setEnabled( false );
-
   std::string ret = "";
   image = NULL;
 
@@ -149,31 +145,32 @@ _LoadImage( TPluginImage::Pointer& image, const QStringList& names )
     this->m_Plugins.CreateProcessObject( this->m_ImageReaderClass );
   if( reader.IsNotNull( ) )
   {
-    // Configure reader
-    TParameters params = reader->GetDefaultParameters( );
-    QStringList::const_iterator qIt = names.begin( );
-    for( ; qIt != names.end( ); ++qIt )
-      params.AddValueToStringList( "FileNames", qIt->toStdString( ) );
-    params.SetValueAsBool( "VectorType", false );
-    reader->SetParameters( params );
-
-    // Execute and get error message, if any
-    ret = reader->Update( );
-
-    // Assign fresh image, if any
-    if( ret == "" )
+    if( reader->ExecConfigurationDialog( this ) )
     {
-      image = reader->GetOutput< TPluginImage >( 0 );
-      reader->DisconnectOutputs( );
+      // Block application
+      QApplication::setOverrideCursor( Qt::WaitCursor );
+      this->setEnabled( false );
+
+      // Execute and get error message, if any
+      ret = reader->Update( );
+
+      // Assign fresh image, if any
+      if( ret == "" )
+      {
+        image = reader->GetOutput< TPluginImage >( 0 );
+        reader->DisconnectOutputs( );
+
+      } // fi
+
+      // Unblock application
+      QApplication::restoreOverrideCursor( );
+      this->setEnabled( true );
 
     } // fi
   }
   else
     ret = "No suitable reader object found in loaded plugins.";
   
-  // Finish reading
-  QApplication::restoreOverrideCursor( );
-  this->setEnabled( true );
   return( ret );
 }
 
@@ -203,20 +200,8 @@ _triggered_actionOpenPlugins( )
 void ImageMPR::
 _triggered_actionOpenInputImage( )
 {
-  // Show dialog and check if it was accepted
-  QFileDialog dialog( this );
-  dialog.setFileMode( QFileDialog::ExistingFiles );
-  dialog.setDirectory( tr( "." ) );
-  dialog.setNameFilter(
-    tr( "Medical image files (*.mhd *.bin *.dcm);;All files (*)" )
-    );
-  dialog.setDefaultSuffix( tr( "mhd" ) );
-  if( !( dialog.exec( ) ) )
-    return;
-  
   // Read image
-  std::string err =
-    this->_LoadImage( this->m_InputImage, dialog.selectedFiles( ) );
+  std::string err = this->_LoadImage( this->m_InputImage );
   if( err == "" )
   {
     vtkImageData* vtk_id = this->m_InputImage->GetVTKImageData( );
@@ -257,20 +242,8 @@ _triggered_actionOpenSegmentation( )
 
   } // fi
 
-  // Show dialog and check if it was accepted
-  QFileDialog dialog( this );
-  dialog.setFileMode( QFileDialog::ExistingFiles );
-  dialog.setDirectory( tr( "." ) );
-  dialog.setNameFilter(
-    tr( "Medical image files (*.mhd *.bin *.dcm);;All files (*)" )
-    );
-  dialog.setDefaultSuffix( tr( "mhd" ) );
-  if( !( dialog.exec( ) ) )
-    return;
-  
   // Read image
-  std::string err =
-    this->_LoadImage( this->m_InputSegmentation, dialog.selectedFiles( ) );
+  std::string err = this->_LoadImage( this->m_InputSegmentation );
   if( err == "" )
   {
     vtkImageData* vtk_id = this->m_InputSegmentation->GetVTKImageData( );
@@ -298,57 +271,51 @@ _triggered_actionOpenSegmentation( )
 void ImageMPR::
 _triggered_actionOpenInputPolyData( )
 {
-  // Show dialog and check if it was accepted
-  QFileDialog dialog( this );
-  dialog.setFileMode( QFileDialog::ExistingFile );
-  dialog.setDirectory( tr( "." ) );
-  dialog.setNameFilter(
-    tr( "Mesh files (*.vtk *.obj);;All files (*)" )
-    );
-  dialog.setDefaultSuffix( tr( "vtk" ) );
-  if( !( dialog.exec( ) ) )
-    return;
-  
   this->m_InputMesh = NULL;
 
   // Get a reader from plugins
   TPluginFilter::Pointer reader =
     this->m_Plugins.CreateProcessObject( this->m_MeshReaderClass );
 
-  // Configure reader
-  TParameters reader_params = reader->GetDefaultParameters( );
-  QStringList q_fnames = dialog.selectedFiles( );
-  QStringList::const_iterator qIt = q_fnames.begin( );
-  for( ; qIt != q_fnames.end( ); ++qIt )
-    reader_params.SetValueAsString( "FileName", qIt->toStdString( ) );
-  reader->SetParameters( reader_params );
-
-  // Execute and get error message, if any
-  QApplication::setOverrideCursor( Qt::WaitCursor );
-  this->setEnabled( false );
-  std::string err = reader->Update( );
-  QApplication::restoreOverrideCursor( );
-  this->setEnabled( true );
-
-
-  // Assign fresh image, if any
-  if( err == "" )
+  if( reader.IsNotNull( ) )
   {
-    this->m_InputMesh = reader->GetOutput< TPluginMesh >( 0 );
-    reader->DisconnectOutputs( );
-    if( this->m_InputMesh.IsNotNull( ) )
+    // Configure reader
+    if( reader->ExecConfigurationDialog( this ) )
     {
-      vtkActor* vtk_actor = this->m_InputMesh->GetVTKActor( );
-      if( vtk_actor != NULL )
+      // Execute and get error message, if any
+      QApplication::setOverrideCursor( Qt::WaitCursor );
+      this->setEnabled( false );
+      std::string err = reader->Update( );
+      QApplication::restoreOverrideCursor( );
+      this->setEnabled( true );
+
+      // Assign fresh mesh, if any
+      if( err == "" )
       {
-        this->m_MPRObjects->Get3DRenderer( )->AddActor( vtk_actor );
-        this->m_MPRObjects->Render( 4 );
+        this->m_InputMesh = reader->GetOutput< TPluginMesh >( 0 );
+        reader->DisconnectOutputs( );
+        if( this->m_InputMesh.IsNotNull( ) )
+        {
+          vtkActor* vtk_actor = this->m_InputMesh->GetVTKActor( );
+          if( vtk_actor != NULL )
+          {
+            this->m_MPRObjects->Get3DRenderer( )->AddActor( vtk_actor );
+            this->m_MPRObjects->Render( 4 );
+          }
+          else
+            QMessageBox::critical(
+              this,
+              tr( "Error message" ),
+              tr( "Read mesh does not have a valid vtkActor." )
+              );
+
+        } // fi
       }
       else
         QMessageBox::critical(
           this,
-          tr( "Error message" ),
-          tr( "Read mesh does not have a valid vtkActor." )
+          tr( "Error reading mesh" ),
+          tr( err.c_str( ) )
           );
 
     } // fi
@@ -356,8 +323,8 @@ _triggered_actionOpenInputPolyData( )
   else
     QMessageBox::critical(
       this,
-      tr( "Error reading mesh" ),
-      tr( err.c_str( ) )
+      tr( "Error reading single mesh" ),
+      tr( "No suitable mesh reader found in loaded plugins." )
       );
 }
 
index cf3e5c1b5f3695955396cb7ad45331a8f1fec5a6..d82f026f7b108393568c3e2709f10753e58824a5 100644 (file)
@@ -48,9 +48,7 @@ public:
 
 protected:
   bool _LoadPlugins( const std::string& filename );
-  std::string _LoadImage(
-    TPluginImage::Pointer& image, const QStringList& names
-    );
+  std::string _LoadImage( TPluginImage::Pointer& image );
 
 private slots:
   void _triggered_actionOpenPlugins( );
index 6cd79041721f193332f3e8d34466fa5599329842..d5e0f39e39925851fc7ac0ddbc3ec9d428c86326 100644 (file)
@@ -90,13 +90,24 @@ SET(cpPlugins_LIBRARY cpPlugins)
 # -- Executable names --
 # ======================
 
-FIND_PROGRAM(
-  cpPlugins_createHost_APP
-  NAMES cpPlugins_createHost
-  HINTS /usr /usr/local
-  PATHS @CMAKE_INSTALL_PREFIX@/bin @PROJECT_BINARY_DIR@
-  PATH_SUFFIXES bin sbin
-  DOC "Where is cpPlugins_createHost?"
-  )
+IF(MSVC)
+  FIND_PROGRAM(
+    cpPlugins_createHost_APP
+    NAMES cpPlugins_createHost
+    HINTS /usr /usr/local
+    PATHS @CMAKE_INSTALL_PREFIX@/bin @PROJECT_BINARY_DIR@/Debug @PROJECT_BINARY_DIR@/Release @PROJECT_BINARY_DIR@/MinSizeRel @PROJECT_BINARY_DIR@/RelWithDebInfo
+    PATH_SUFFIXES bin sbin
+    DOC "Where is cpPlugins_createHost?"
+    )
+ELSE(MSVC)
+  FIND_PROGRAM(
+    cpPlugins_createHost_APP
+    NAMES cpPlugins_createHost
+    HINTS /usr /usr/local
+    PATHS @CMAKE_INSTALL_PREFIX@/bin @PROJECT_BINARY_DIR@
+    PATH_SUFFIXES bin sbin
+    DOC "Where is cpPlugins_createHost?"
+    )
+ENDIF(MSVC)
 
 ## eof - $RCSfile$
index ebc07793356798288991a00ee23158401e431b4e..361ba1018a212dff9ee8569d95cbaf5a4f4bdb6e 100644 (file)
@@ -17,8 +17,8 @@ FILE(GLOB LIB_SOURCES_CXX "*.cxx")
 
 ADD_CUSTOM_COMMAND(
   OUTPUT ${LIBRARY_NAME}_Host.cxx
-  DEPENDS ${PROJECT_BINARY_DIR}/$(ConfigurationName)/cpPlugins_createHost ${LIB_HEADERS_H} ${LIB_HEADERS_HPP} ${LIB_HEADERS_HXX}
-  COMMAND ${PROJECT_BINARY_DIR}/$(ConfigurationName)/cpPlugins_createHost ${LIBRARY_NAME}_Host.cxx cpPlugins::BasicFilters ${LIB_HEADERS_H}
+  DEPENDS ${cpPlugins_createHost_APP} ${LIB_HEADERS_H}
+  COMMAND ${cpPlugins_createHost_APP} ${LIBRARY_NAME}_Host.cxx cpPlugins::BasicFilters ${LIB_HEADERS_H}
   )
 
 ADD_LIBRARY(
index 243e4c00ccd6d365cf91baca54d60745047b37c3..98dca496a2c3455c7af51b6cba8b8bf15d685bd0 100644 (file)
@@ -17,8 +17,8 @@ FILE(GLOB LIB_SOURCES_CXX "*.cxx")
 
 ADD_CUSTOM_COMMAND(
   OUTPUT ${LIBRARY_NAME}_Host.cxx
-  DEPENDS ${PROJECT_BINARY_DIR}/$(ConfigurationName)/cpPlugins_createHost ${LIB_HEADERS_H} ${LIB_HEADERS_HPP} ${LIB_HEADERS_HXX}
-  COMMAND ${PROJECT_BINARY_DIR}/$(ConfigurationName)/cpPlugins_createHost ${LIBRARY_NAME}_Host.cxx cpPlugins::IO ${LIB_HEADERS_H}
+  DEPENDS ${cpPlugins_createHost_APP} ${LIB_HEADERS_H}
+  COMMAND ${cpPlugins_createHost_APP} ${LIBRARY_NAME}_Host.cxx cpPlugins::IO ${LIB_HEADERS_H}
   )
 
 ADD_LIBRARY(
index 38739df3807d90b273cea6bad1a9a79b76f7211b..4b1d365f59e9c96729b7eb826c5631914e42e633 100644 (file)
@@ -6,6 +6,42 @@
 #include <itkImageFileReader.h>
 #include <itkImageSeriesReader.h>
 
+#ifdef cpPlugins_Interface_QT4
+#include <QFileDialog>
+#endif // cpPlugins_Interface_QT4
+
+// -------------------------------------------------------------------------
+bool cpPlugins::IO::ImageReader::
+ExecConfigurationDialog( QWidget* parent )
+{
+  bool r = false;
+
+#ifdef cpPlugins_Interface_QT4
+
+  // Show dialog and check if it was accepted
+  QFileDialog dialog( parent );
+  dialog.setFileMode( QFileDialog::ExistingFiles );
+  dialog.setDirectory( QFileDialog::tr( "." ) );
+  dialog.setNameFilter( QFileDialog::tr( "All files (*)" ) );
+  if( dialog.exec( ) )
+  {
+    this->m_Parameters = this->m_DefaultParameters;
+    QStringList names = dialog.selectedFiles( );
+    QStringList::const_iterator qIt = names.begin( );
+    for( ; qIt != names.end( ); ++qIt )
+      this->m_Parameters.AddValueToStringList(
+        "FileNames", qIt->toStdString( )
+        );
+    this->m_Parameters.SetValueAsBool( "VectorType", false );
+    r = true;
+
+  } // fi
+
+#endif // cpPlugins_Interface_QT4
+
+  return( r );
+}
+
 // -------------------------------------------------------------------------
 cpPlugins::IO::ImageReader::
 ImageReader( )
index 803e5f81189ef745767708e121d707893c802c41..aeee9fa5007c2cb187181303a9d74d270f4bdc41 100644 (file)
@@ -34,6 +34,9 @@ namespace cpPlugins
       itkNewMacro( Self );
       itkTypeMacro( ImageReader, cpPluginsInterfaceImageSource );
 
+    public:
+      virtual bool ExecConfigurationDialog( QWidget* parent );
+
     protected:
       ImageReader( );
       virtual ~ImageReader( );
index 67069046163d768395fc55d2e23c5b8a871f6497..b8da8a36f1e582502cb5d07bbaea85327ee6529b 100644 (file)
@@ -4,6 +4,45 @@
 #include <vtkPolyData.h>
 #include <vtkPolyDataReader.h>
 
+#ifdef cpPlugins_Interface_QT4
+#include <QFileDialog>
+#endif // cpPlugins_Interface_QT4
+
+// -------------------------------------------------------------------------
+bool cpPlugins::IO::MeshReader::
+ExecConfigurationDialog( QWidget* parent )
+{
+  bool r = false;
+
+#ifdef cpPlugins_Interface_QT4
+
+  // Show dialog and check if it was accepted
+  QFileDialog dialog( parent );
+  dialog.setFileMode( QFileDialog::ExistingFile );
+  dialog.setDirectory( QFileDialog::tr( "." ) );
+  dialog.setNameFilter( QFileDialog::tr( "All files (*)" ) );
+  if( dialog.exec( ) )
+  {
+    this->m_Parameters = this->m_DefaultParameters;
+    QStringList names = dialog.selectedFiles( );
+    this->m_Parameters.AddValueToStringList(
+      "FileNames", names[ 0 ].toStdString( )
+      );
+
+    /* TODO
+       this->m_Parameters.SetValueAsString( "PixelType", "float" );
+       this->m_Parameters.SetValueAsUint( "Dimension", 3 );
+    */
+
+    r = true;
+
+  } // fi
+
+#endif // cpPlugins_Interface_QT4
+
+  return( r );
+}
+
 // -------------------------------------------------------------------------
 cpPlugins::IO::MeshReader::
 MeshReader( )
index 224cc039d935f7704b7545592c4e57e138b8ac5c..f66e07cf0449ddeb912b02acbab8c98956f663d0 100644 (file)
@@ -25,6 +25,9 @@ namespace cpPlugins
       itkNewMacro( Self );
       itkTypeMacro( MeshReader, cpPluginsInterfaceMeshSource );
 
+    public:
+      virtual bool ExecConfigurationDialog( QWidget* parent );
+
     protected:
       MeshReader( );
       virtual ~MeshReader( );