]> Creatis software - cpPlugins.git/commitdiff
...
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Tue, 22 Sep 2015 08:23:23 +0000 (10:23 +0200)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Tue, 22 Sep 2015 08:23:23 +0000 (10:23 +0200)
appli/CMakeLists.txt
appli/ImageMPR/CMakeLists.txt
appli/ImageMPR/ImageMPR.cxx
appli/ImageMPR/ImageMPR.h
lib/cpPlugins/Interface/CMakeLists.txt
lib/cpPlugins/Interface/ParametersQtDialog.cxx [new file with mode: 0644]
lib/cpPlugins/Interface/ParametersQtDialog.h [new file with mode: 0644]
lib/cpPlugins/Plugins/MarchingCubes.cxx

index 6e05dedf3580c6a8613cd437877bcdf2ce731868..7ca64d43ccc1308a2fce1060d3c872859574e387 100644 (file)
@@ -1,7 +1,7 @@
 IF(BUILD_EXAMPLES)
   SUBDIRS(
     examples
-    #ImageMPR
+    ImageMPR
     )
 ENDIF(BUILD_EXAMPLES)
 
index 7d5ad93fbb504388024e397a94abcea298180d83..a35c436fd54ac5780571ed8efebc289f23e1729d 100644 (file)
@@ -58,8 +58,8 @@ IF(USE_QT4)
   TARGET_LINK_LIBRARIES(
     ${App_NAME}
     ${QT_LIBRARIES}
-       cpExtensions
-    ##vtkGUISupportQt
+    cpExtensions
+    cpPlugins_Interface
     )
 ENDIF(USE_QT4)
 
index c4729f65cc2efeeab9d18bdc90521b939147f8c9..def9fc4dd3d94a94dfab50d58ea094210acbafcc 100644 (file)
@@ -1,13 +1,12 @@
 #include "ImageMPR.h"
 #include "ui_ImageMPR.h"
 
+#include <cpPlugins/Interface/ParametersQtDialog.h>
+
 #include <vtkProperty.h>
 #include <vtkRenderWindow.h>
 
-#include <QDialogButtonBox>
-#include <QDoubleSpinBox>
 #include <QFileDialog>
-#include <QLabel>
 #include <QMessageBox>
 
 #ifdef _WIN32
@@ -26,8 +25,7 @@ ImageMPR::ImageMPR( QWidget* parent )
     m_UI( new Ui::ImageMPR ),
     m_ImageReaderClass( "" ),
     m_ImageWriterClass( "" ),
-    m_InputImage( NULL ),
-    m_ParametersDlg( NULL )
+    m_InputImage( NULL )
 {
   this->m_UI->setupUi( this );
 
@@ -71,12 +69,6 @@ ImageMPR::
   // Delete objects
   delete this->m_UI;
   delete this->m_MPR;
-  if( this->m_ParametersDlg != NULL )
-  {
-    this->m_ParametersDlg->close( );
-    delete this->m_ParametersDlg;
-
-  } // fi
 }
 
 // -------------------------------------------------------------------------
@@ -140,159 +132,6 @@ _LoadPlugins( const std::string& filename )
   return( true );
 }
 
-// -------------------------------------------------------------------------
-bool ImageMPR::
-_ParametersDialog( TPluginFilter* filter )
-{
-  if( this->m_ParametersDlg != NULL )
-  { 
-    this->m_ParametersDlg->close( );
-    delete this->m_ParametersDlg;
-
-  } // fi
-  this->m_ParametersDlg = new QDialog( NULL );
-  this->m_ParametersDlg->setWindowFlags( Qt::FramelessWindowHint ); 
-  this->m_ParametersDlg->setWindowFlags( Qt::WindowTitleHint );
-
-  QGridLayout* gridLayout = new QGridLayout( this->m_ParametersDlg );
-  QVBoxLayout* verticalLayout = new QVBoxLayout( );
-
-  // Put a title
-  QLabel* title = new QLabel( this->m_ParametersDlg );
-  title->setText( filter->GetClassName( ).c_str( ) );
-  verticalLayout->addWidget( title );
-
-  // Put values
-  TParameters parameters = filter->GetDefaultParameters( );
-  std::vector< std::string > names = parameters.GetParameters( );
-  std::vector< std::string >::const_iterator nIt = names.begin( );
-  for( ; nIt != names.end( ); ++nIt )
-  {
-    std::string par_name = *nIt;
-    TParameters::Type par_type = parameters.GetParameterType( par_name );
-
-    /* TODO
-       enum Type
-       {
-       String = 0,
-       Bool,
-       Int,
-       Uint,
-       Real,
-       Index,
-       Point,
-       StringList,
-       BoolList,
-       IntList,
-       UintList,
-       RealList,
-       IndexList,
-       PointList,
-       NoType
-       };
-    */
-    QHBoxLayout* horizontalLayout = new QHBoxLayout( );
-    QLabel* label = new QLabel( this->m_ParametersDlg );
-    label->setText( QString( par_name.c_str( ) ) );
-    horizontalLayout->addWidget( label );
-
-    QWidget* w_input = NULL;
-    if( par_type == TParameters::Uint )
-    {
-      QSpinBox* v_uint =
-        new QSpinBox( this->m_ParametersDlg );
-      v_uint->setMinimum( -100 );
-      v_uint->setMaximum( std::numeric_limits< int >::max( ) );
-      v_uint->setValue( parameters.GetValueAsUint( par_name ) );
-      v_uint->setObjectName( QString( par_name.c_str( ) ) );
-      w_input = v_uint;
-    }
-    else if( par_type == TParameters::Int )
-    {
-      QSpinBox* v_int =
-        new QSpinBox( this->m_ParametersDlg );
-      v_int->setMinimum( -std::numeric_limits< int >::max( ) );
-      v_int->setMaximum( std::numeric_limits< int >::max( ) );
-      v_int->setValue( parameters.GetValueAsInt( par_name ) );
-      v_int->setObjectName( QString( par_name.c_str( ) ) );
-      w_input = v_int;
-    }
-    else if( par_type == TParameters::Real )
-    {
-      QDoubleSpinBox* v_double =
-        new QDoubleSpinBox( this->m_ParametersDlg );
-      v_double->setDecimals( 3 );
-      v_double->setMinimum( -( std::numeric_limits< double >::max( ) ) );
-      v_double->setMaximum( std::numeric_limits< double >::max( ) );
-      v_double->setValue( parameters.GetValueAsReal( par_name ) );
-      v_double->setObjectName( QString( par_name.c_str( ) ) );
-      w_input = v_double;
-
-    } // fi
-
-    if( w_input != NULL )
-    {
-      horizontalLayout->addWidget( w_input );
-      verticalLayout->addLayout( horizontalLayout );
-
-    } // fi
-
-  } // rof
-
-  // Add buttons
-  QDialogButtonBox* bb = new QDialogButtonBox(
-    QDialogButtonBox::Ok | QDialogButtonBox::Cancel
-    );
-  QObject::connect(
-    bb, SIGNAL( accepted( ) ), this->m_ParametersDlg, SLOT( accept( ) )
-    );
-  QObject::connect(
-    bb, SIGNAL( rejected( ) ), this->m_ParametersDlg, SLOT( reject( ) )
-    );
-  verticalLayout->addWidget( bb );
-  gridLayout->addLayout( verticalLayout, 0, 0, 1, 1 );
-
-  // Execute
-  QMetaObject::connectSlotsByName( this->m_ParametersDlg );
-  if( !( this->m_ParametersDlg->exec( ) ) )
-    return( false );
-
-  // Get values back
-  nIt = names.begin( );
-  for( ; nIt != names.end( ); ++nIt )
-  {
-    std::string par_name = *nIt;
-    TParameters::Type par_type = parameters.GetParameterType( par_name );
-    if( par_type == TParameters::Uint )
-    {
-      QSpinBox* v_uint =
-        this->m_ParametersDlg->findChild< QSpinBox* >( par_name.c_str( ) );
-      if( v_uint != NULL )
-        parameters.SetValueAsUint( par_name, v_uint->value( ) );
-    }
-    else if( par_type == TParameters::Int )
-    {
-      QSpinBox* v_int =
-        this->m_ParametersDlg->findChild< QSpinBox* >( par_name.c_str( ) );
-      if( v_int != NULL )
-        parameters.SetValueAsInt( par_name, v_int->value( ) );
-    }
-    else if( par_type == TParameters::Real )
-    {
-      QDoubleSpinBox* v_double =
-        this->m_ParametersDlg->findChild< QDoubleSpinBox* >(
-          par_name.c_str( )
-          );
-      if( v_double != NULL )
-        parameters.SetValueAsReal( par_name, v_double->value( ) );
-
-    } // fi
-
-  } // rof
-  filter->SetParameters( parameters );
-  return( true );
-}
-
 // -------------------------------------------------------------------------
 void ImageMPR::
 _triggered_actionOpenPlugins( )
@@ -437,20 +276,35 @@ _triggered_actionImageToImage( )
   // Configure filter
   TPluginFilter::Pointer filter =
     this->m_Plugins.CreateProcessObject( name );
-  if( !( this->_ParametersDialog( filter ) ) )
+  TParameters parameters = filter->GetDefaultParameters( );
+  bool dlg_ok =
+    cpPlugins::Interface::ParametersQtDialog(
+      parameters, filter->GetClassName( )
+      );
+  if( !dlg_ok )
     return;
 
   // Execute filter
+  filter->SetParameters( parameters );
   filter->SetInput( 0, this->m_InputImage );
-  filter->Update( );
+  std::string err = filter->Update( );
 
   // Update image
-  TPluginImage* result =
-    dynamic_cast< TPluginImage* >( filter->GetOutput( 0 ) );
-  result->DisconnectPipeline( );
-  this->m_InputImage = result;
-  if( this->m_InputImage.IsNotNull( ) )
-    this->m_MPR->SetImage( this->m_InputImage->GetVTKImageData( ) );
+  if( err == "" )
+  {
+    TPluginImage* result =
+      dynamic_cast< TPluginImage* >( filter->GetOutput( 0 ) );
+    result->DisconnectPipeline( );
+    this->m_InputImage = result;
+    if( this->m_InputImage.IsNotNull( ) )
+      this->m_MPR->SetImage( this->m_InputImage->GetVTKImageData( ) );
+  }
+  else
+    QMessageBox::critical(
+      this,
+      tr( "Error executing filter" ),
+      tr( err.c_str( ) )
+      );
 }
 
 // -------------------------------------------------------------------------
@@ -465,6 +319,41 @@ _triggered_actionImageToMesh( )
   if( action == NULL )
     return;
   std::string name = action->text( ).toStdString( );
+
+  // Configure filter
+  TPluginFilter::Pointer filter =
+    this->m_Plugins.CreateProcessObject( name );
+  TParameters parameters = filter->GetDefaultParameters( );
+  bool dlg_ok =
+    cpPlugins::Interface::ParametersQtDialog(
+      parameters, filter->GetClassName( )
+      );
+  if( !dlg_ok )
+    return;
+
+  // Execute filter
+  filter->SetParameters( parameters );
+  filter->SetInput( 0, this->m_InputImage );
+  std::string err = filter->Update( );
+
+  // Update image
+  if( err == "" )
+  {
+    /* TODO
+       TPluginImage* result =
+       dynamic_cast< TPluginImage* >( filter->GetOutput( 0 ) );
+       result->DisconnectPipeline( );
+       this->m_InputImage = result;
+       if( this->m_InputImage.IsNotNull( ) )
+       this->m_MPR->SetImage( this->m_InputImage->GetVTKImageData( ) );
+    */
+  }
+  else
+    QMessageBox::critical(
+      this,
+      tr( "Error executing filter" ),
+      tr( err.c_str( ) )
+      );
 }
 
 // eof - $RCSfile$
index b0ba3c4268480963dfd1de33c239fbd4e711ab4c..1418bf6eae97263e969e78e740e0394030ccb272 100644 (file)
@@ -6,7 +6,6 @@
 #include <set>
 
 // Qt stuff
-#include <QDialog>
 #include <QMainWindow>
 
 // vtk stuff
@@ -52,7 +51,6 @@ public:
 
 protected:
   bool _LoadPlugins( const std::string& filename );
-  bool _ParametersDialog( TPluginFilter* filter );
 
 private slots:
   void _triggered_actionOpenPlugins( );
@@ -84,8 +82,6 @@ private:
   vtkSmartPointer< vtkPolyDataMapper > m_InputMeshMapper;
   vtkSmartPointer< vtkActor >          m_InputMeshActor;
 
-  QDialog* m_ParametersDlg;
-
   /* TODO
      vtkSmartPointer< vtkOrientationMarkerWidget > m_3DOrientationWidget;
   */
index f8a6ff7e336fff5b3846f02ca716991f1f1a4ed1..36dc3f8ae3cabfcf1458b65d030ae0eadc00217f 100644 (file)
@@ -4,12 +4,64 @@ SET(LIBRARY_NAME cpPlugins_Interface)
 ## = Source code =
 ## ===============
 
-FILE(GLOB LIB_HEADERS_H   "*.h")
-FILE(GLOB LIB_HEADERS_HPP "*.hpp")
-FILE(GLOB LIB_HEADERS_HXX "*.hxx")
-FILE(GLOB LIB_SOURCES_C   "*.c")
-FILE(GLOB LIB_SOURCES_CPP "*.cpp")
-FILE(GLOB LIB_SOURCES_CXX "*.cxx")
+SET(
+  LIB_HEADERS_H
+  BaseProcessObjects.h
+  DataObject.h
+  Image.h
+  Interface.h
+  Macros.h
+  Mesh.h
+  Object.h
+  Parameters.h
+  ProcessObject.h
+  )
+
+SET(
+  LIB_HEADERS_HPP
+  )
+
+SET(
+  LIB_HEADERS_HXX
+  Image.hxx
+  Mesh.hxx
+  Parameters.hxx
+  ProcessObject.hxx
+  )
+
+SET(
+  LIB_SOURCES_C
+  )
+SET(
+  LIB_SOURCES_CPP
+  )
+
+SET(
+  LIB_SOURCES_CXX
+  BaseProcessObjects.cxx
+  DataObject.cxx
+  Image.cxx
+  Instances_itkImage.cxx
+  Instances_itkMesh.cxx
+  Interface.cxx
+  Mesh.cxx
+  Object.cxx
+  Parameters.cxx
+  ProcessObject.cxx
+  )
+
+IF(USE_QT4)
+  SET(
+    LIB_HEADERS_H
+    ${LIB_HEADERS_H}
+    ParametersQtDialog.h
+    )
+  SET(
+    LIB_SOURCES_CXX
+    ${LIB_SOURCES_CXX}
+    ParametersQtDialog.cxx
+    )
+ENDIF(USE_QT4)
 
 ## =====================
 ## = Compilation rules =
@@ -32,6 +84,7 @@ GENERATE_EXPORT_HEADER(
 TARGET_LINK_LIBRARIES(
   ${LIBRARY_NAME}
   cpPlugins_Pluma
+  ${QT_LIBRARIES}
   ${ITK_LIBRARIES}
   ${VTK_LIBRARIES}
   )
diff --git a/lib/cpPlugins/Interface/ParametersQtDialog.cxx b/lib/cpPlugins/Interface/ParametersQtDialog.cxx
new file mode 100644 (file)
index 0000000..819abd3
--- /dev/null
@@ -0,0 +1,169 @@
+#include <cpPlugins/Interface/ParametersQtDialog.h>
+
+#include <limits>
+#include <vector>
+
+#include <QCheckBox>
+#include <QDialog>
+#include <QDialogButtonBox>
+#include <QDoubleSpinBox>
+#include <QHBoxLayout>
+#include <QLabel>
+#include <QLineEdit>
+#include <QWidget>
+
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::
+ParametersQtDialog(
+  Parameters& parameters, const std::string& title, QWidget* parent
+  )
+{
+  // Create dialog with a simple layout
+  QDialog* dlg = new QDialog( parent );
+  dlg->setWindowFlags( Qt::FramelessWindowHint ); 
+  dlg->setWindowFlags( Qt::WindowTitleHint );
+  QGridLayout* gridLayout = new QGridLayout( dlg );
+  QVBoxLayout* verticalLayout = new QVBoxLayout( );
+
+  // Put a title
+  QLabel* dlg_title = new QLabel( dlg );
+  dlg_title->setText( title.c_str( ) );
+  verticalLayout->addWidget( dlg_title );
+
+  // Put values
+  std::vector< std::string > names = parameters.GetParameters( );
+  std::vector< std::string >::const_iterator nIt = names.begin( );
+  for( ; nIt != names.end( ); ++nIt )
+  {
+    Parameters::Type pt = parameters.GetParameterType( *nIt );
+
+    /* TODO
+       enum Type
+       {
+       Bool,
+       Index,
+       Point,
+       StringList,
+       BoolList,
+       IntList,
+       UintList,
+       RealList,
+       IndexList,
+       PointList,
+       NoType
+       };
+    */
+    QWidget* w_input = NULL;
+    if( pt == Parameters::String )
+    {
+      QLineEdit* v_string = new QLineEdit( dlg );
+      v_string->setText( "Enter some text!!!" );
+      w_input = v_string;
+    }
+    else if( pt == Parameters::Bool )
+    {
+      QCheckBox* v_bool = new QCheckBox( dlg );
+      v_bool->setText( "[ON/OFF]" );
+      v_bool->setChecked( parameters.GetValueAsBool( *nIt ) );
+      w_input = v_bool;
+    }
+    else if( pt == Parameters::Uint )
+    {
+      QSpinBox* v_uint = new QSpinBox( dlg );
+      v_uint->setMinimum( 0 );
+      v_uint->setMaximum( std::numeric_limits< int >::max( ) );
+      v_uint->setValue( parameters.GetValueAsUint( *nIt ) );
+      w_input = v_uint;
+    }
+    else if( pt == Parameters::Int )
+    {
+      QSpinBox* v_int = new QSpinBox( dlg );
+      v_int->setMinimum( -std::numeric_limits< int >::max( ) );
+      v_int->setMaximum(  std::numeric_limits< int >::max( ) );
+      v_int->setValue( parameters.GetValueAsInt( *nIt ) );
+      w_input = v_int;
+    }
+    else if( pt == Parameters::Real )
+    {
+      QDoubleSpinBox* v_double = new QDoubleSpinBox( dlg );
+      v_double->setDecimals( 3 );
+      v_double->setMinimum( -std::numeric_limits< double >::max( ) );
+      v_double->setMaximum(  std::numeric_limits< double >::max( ) );
+      v_double->setValue( parameters.GetValueAsReal( *nIt ) );
+      w_input = v_double;
+
+    } // fi
+
+    // Ok, a representation was created
+    if( w_input != NULL )
+    {
+      w_input->setObjectName( QString( nIt->c_str( ) ) );
+
+      QHBoxLayout* horizontalLayout = new QHBoxLayout( );
+      QLabel* label = new QLabel( dlg );
+      label->setText( QString( nIt->c_str( ) ) );
+      horizontalLayout->addWidget( label );
+      horizontalLayout->addWidget( w_input );
+      verticalLayout->addLayout( horizontalLayout );
+
+    } // fi
+
+  } // rof
+
+  // Add buttons
+  QDialogButtonBox* bb = new QDialogButtonBox(
+    QDialogButtonBox::Ok | QDialogButtonBox::Cancel
+    );
+  QObject::connect( bb, SIGNAL( accepted( ) ), dlg, SLOT( accept( ) ) );
+  QObject::connect( bb, SIGNAL( rejected( ) ), dlg, SLOT( reject( ) ) );
+  verticalLayout->addWidget( bb );
+  gridLayout->addLayout( verticalLayout, 0, 0, 1, 1 );
+
+  // Execute
+  QMetaObject::connectSlotsByName( dlg );
+  if( !( dlg->exec( ) ) )
+    return( false );
+
+  // Get values back
+  nIt = names.begin( );
+  for( ; nIt != names.end( ); ++nIt )
+  {
+    Parameters::Type pt = parameters.GetParameterType( *nIt );
+    if( pt == Parameters::String )
+    {
+      QLineEdit* v_string = dlg->findChild< QLineEdit* >( nIt->c_str( ) );
+      if( v_string != NULL )
+        parameters.SetValueAsString( *nIt, v_string->text( ).toStdString( ) );
+    }
+    else if( pt == Parameters::Bool )
+    {
+      QCheckBox* v_bool = dlg->findChild< QCheckBox* >( nIt->c_str( ) );
+      if( v_bool != NULL )
+        parameters.SetValueAsBool( *nIt, v_bool->isChecked( ) );
+    }
+    else if( pt == Parameters::Uint )
+    {
+      QSpinBox* v_uint = dlg->findChild< QSpinBox* >( nIt->c_str( ) );
+      if( v_uint != NULL )
+        parameters.SetValueAsUint( *nIt, v_uint->value( ) );
+    }
+    else if( pt == Parameters::Int )
+    {
+      QSpinBox* v_int = dlg->findChild< QSpinBox* >( nIt->c_str( ) );
+      if( v_int != NULL )
+        parameters.SetValueAsInt( *nIt, v_int->value( ) );
+    }
+    else if( pt == Parameters::Real )
+    {
+      QDoubleSpinBox* v_double =
+        dlg->findChild< QDoubleSpinBox* >( nIt->c_str( ) );
+      if( v_double != NULL )
+        parameters.SetValueAsReal( *nIt, v_double->value( ) );
+
+    } // fi
+
+  } // rof
+  return( true );
+}
+
+// eof - $RCSfile$
diff --git a/lib/cpPlugins/Interface/ParametersQtDialog.h b/lib/cpPlugins/Interface/ParametersQtDialog.h
new file mode 100644 (file)
index 0000000..daf2517
--- /dev/null
@@ -0,0 +1,25 @@
+#ifndef __CPPLUGINS__INTERFACE__PARAMETERSQTDIALOG__H__
+#define __CPPLUGINS__INTERFACE__PARAMETERSQTDIALOG__H__
+
+#include <cpPlugins/Interface/cpPlugins_Interface_Export.h>
+#include <cpPlugins/Interface/Parameters.h>
+
+class QWidget;
+
+namespace cpPlugins
+{
+  namespace Interface
+  {
+    bool cpPlugins_Interface_EXPORT ParametersQtDialog(
+      Parameters& parameters,
+      const std::string& title,
+      QWidget* parent = NULL
+      );
+
+  } // ecapseman
+
+} // ecapseman
+
+#endif // __CPPLUGINS__INTERFACE__PARAMETERSQTDIALOG__H__
+
+// eof - $RCSfile$
index 8187b42d0cdb51d743523ae28f9c7452a254f5b9..ca6e5bf5d7c0b1eb2ac963ff22bf84db56890ae0 100644 (file)
@@ -13,6 +13,7 @@ MarchingCubes( )
     m_Algorithm( NULL )
 {
   this->m_ClassName = "cpPlugins::MarchingCubes";
+  this->m_ClassCategory = "ImageToMeshFilter";
 
   this->SetNumberOfInputs( 1 );
   this->SetNumberOfOutputs( 1 );