]> Creatis software - cpPlugins.git/commitdiff
...
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Thu, 17 Sep 2015 09:15:43 +0000 (11:15 +0200)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Thu, 17 Sep 2015 09:15:43 +0000 (11:15 +0200)
appli/ImageMPR/ImageMPR.cxx
appli/ImageMPR/ImageMPR.h
lib/cpPlugins/Interface/DataObject.cxx
lib/cpPlugins/Interface/Parameters.h
lib/cpPlugins/Interface/ProcessObject.cxx

index 8074f7ea3f8c920938376525e5f82f54a73ae679..c4729f65cc2efeeab9d18bdc90521b939147f8c9 100644 (file)
@@ -4,6 +4,7 @@
 #include <vtkProperty.h>
 #include <vtkRenderWindow.h>
 
+#include <QDialogButtonBox>
 #include <QDoubleSpinBox>
 #include <QFileDialog>
 #include <QLabel>
@@ -143,9 +144,13 @@ _LoadPlugins( const std::string& filename )
 bool ImageMPR::
 _ParametersDialog( TPluginFilter* filter )
 {
-  if( this->m_ParametersDlg != NULL ) 
+  if( this->m_ParametersDlg != NULL )
+  { 
     this->m_ParametersDlg->close( );
-  this->m_ParametersDlg = new QWidget( NULL );
+    delete this->m_ParametersDlg;
+
+  } // fi
+  this->m_ParametersDlg = new QDialog( NULL );
   this->m_ParametersDlg->setWindowFlags( Qt::FramelessWindowHint ); 
   this->m_ParametersDlg->setWindowFlags( Qt::WindowTitleHint );
 
@@ -166,53 +171,51 @@ _ParametersDialog( TPluginFilter* filter )
     std::string par_name = *nIt;
     TParameters::Type par_type = parameters.GetParameterType( par_name );
 
-    /*
-      enum Type
-      {
-      String = 0,
-      Bool,
-      Int,
-      Uint,
-      Real,
-      Index,
-      Point,
-      StringList,
-      BoolList,
-      IntList,
-      UintList,
-      RealList,
-      IndexList,
-      PointList,
-      NoType
-      };
+    /* 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( 0 );
-      v_uint->setMaximum( std::numeric_limits< unsigned long >::max( ) );
+      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( ) ) );
-      horizontalLayout->addWidget( v_uint );
-      verticalLayout->addLayout( horizontalLayout );
+      w_input = v_uint;
     }
     else if( par_type == TParameters::Int )
     {
       QSpinBox* v_int =
         new QSpinBox( this->m_ParametersDlg );
-      v_int->setMinimum( -std::numeric_limits< long >::max( ) );
-      v_int->setMaximum( std::numeric_limits< long >::max( ) );
+      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( ) ) );
-      horizontalLayout->addWidget( v_int );
-      verticalLayout->addLayout( horizontalLayout );
+      w_input = v_int;
     }
     else if( par_type == TParameters::Real )
     {
@@ -223,33 +226,71 @@ _ParametersDialog( TPluginFilter* filter )
       v_double->setMaximum( std::numeric_limits< double >::max( ) );
       v_double->setValue( parameters.GetValueAsReal( par_name ) );
       v_double->setObjectName( QString( par_name.c_str( ) ) );
-      horizontalLayout->addWidget( v_double );
+      w_input = v_double;
+
+    } // fi
+
+    if( w_input != NULL )
+    {
+      horizontalLayout->addWidget( w_input );
       verticalLayout->addLayout( horizontalLayout );
 
     } // fi
 
   } // rof
-  gridLayout->addLayout( verticalLayout, 0, 0, 1, 1 );
 
-  // Infere plugin type
-  /* TODO
-     TParameters::const_iterator seedIt = parameters.find( "Seed" );
-     TParameters::const_iterator radiusIt = parameters.find( "Radius" );
-     TParameters::const_iterator endIt = parameters.end( );
-     if( seedIt == endIt && radiusIt == endIt )
-     this->m_ActivePluginType = Self::GlobalPluginType;
-     else if( seedIt != endIt && radiusIt == endIt )
-     this->m_ActivePluginType = Self::DoubleClickPluginType;
-     else if( seedIt != endIt && radiusIt != endIt )
-     this->m_ActivePluginType = Self::SpherePluginType;
-     else
-     this->m_ActivePluginType = Self::NonePluginType;
-  */
+  // 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 );
-  this->m_ParametersDlg->show( );
+  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
 
-  return( false );
+  } // rof
+  filter->SetParameters( parameters );
+  return( true );
 }
 
 // -------------------------------------------------------------------------
@@ -396,7 +437,20 @@ _triggered_actionImageToImage( )
   // Configure filter
   TPluginFilter::Pointer filter =
     this->m_Plugins.CreateProcessObject( name );
-  this->_ParametersDialog( filter );
+  if( !( this->_ParametersDialog( filter ) ) )
+    return;
+
+  // Execute filter
+  filter->SetInput( 0, this->m_InputImage );
+  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( ) );
 }
 
 // -------------------------------------------------------------------------
index 9e3f80147b18779e01a0a7e07ba3fa46b4b9c213..5fdf07a45f171c30841a5981d23d0dd7ae8b2af8 100644 (file)
@@ -6,6 +6,7 @@
 #include <set>
 
 // Qt stuff
+#include <QDialog>
 #include <QMainWindow>
 
 // vtk stuff
@@ -83,7 +84,7 @@ private:
   vtkSmartPointer< vtkPolyDataMapper > m_InputMeshMapper;
   vtkSmartPointer< vtkActor >          m_InputMeshActor;
 
-  QWidget* m_ParametersDlg;
+  QDialog* m_ParametersDlg;
 
   /* TODO
      vtkSmartPointer< vtkOrientationMarkerWidget > m_3DOrientationWidget;
index 73ff662f9c423c0891e26a965dc034120d18b57c..808aa2bc9cc0939542fbb5480ac397f4948272c9 100644 (file)
@@ -84,12 +84,10 @@ DisconnectPipeline( )
 
     } // fi
 
-    // Unbind source
-    if( this->m_Source.IsNotNull( ) )
-      this->m_Source->Delete( );
-    this->Register( );
-
   } // fi
+
+  // Unbind source
+  this->m_Source = NULL;
 }
 
 // -------------------------------------------------------------------------
index dbcf98c68a16c4c62073e95f19026f745dff582f..0e54f0f7fdfae594e9fd9a55cb7042fde4a22a10 100644 (file)
@@ -2,6 +2,7 @@
 #define __CPPLUGINS__INTERFACE__PARAMETERS__H__
 
 #include <map>
+#include <ostream>
 #include <string>
 #include <vector>
 #include <cpPlugins/Interface/cpPlugins_Interface_Export.h>
@@ -14,26 +15,35 @@ namespace cpPlugins
      */
     class cpPlugins_Interface_EXPORT Parameters
     {
+      // -------------------------------------------------------------------
+      friend std::ostream& operator<<(
+        std::ostream& os, const Parameters& p
+        )
+      {
+        Parameters::TParameters::const_iterator pIt =
+          p.m_Parameters.begin( );
+        for( ; pIt != p.m_Parameters.end( ); ++pIt )
+        {
+          os
+            << pIt->first << ": ("
+            << pIt->second.first << ", "
+            << pIt->second.second << ")"
+            << std::endl;
+
+        } // rof
+        return( os );
+      }
+
     public:
       typedef Parameters Self;
 
       enum Type
       {
-        String = 0,
-        Bool,
-        Int,
-        Uint,
-        Real,
-        Index,
-        Point,
-        StringList,
-        BoolList,
-        IntList,
-        UintList,
-        RealList,
-        IndexList,
-        PointList,
-        NoType
+        String    , Bool       , Int      ,
+        Uint      , Real       , Index    ,
+        Point     , StringList , BoolList ,
+        IntList   , UintList   , RealList ,
+        IndexList , PointList  , NoType
       };
 
       typedef bool          TBool;
index c6271ca6635e1f3421669be85ddc46dfb050baf3..0f8f2885bfb9b9aac979ade6093decb6006b4b1c 100644 (file)
@@ -117,25 +117,4 @@ cpPlugins::Interface::ProcessObject::
 {
 }
 
-// -------------------------------------------------------------------------
-/* TODO
-   itk::DataObject* cpPlugins::Interface::ProcessObject::
-   _GetInput( unsigned int idx )
-   {
-   if( idx < this->m_Inputs.size( ) )
-   return( this->m_Inputs[ idx ]->GetRealDataObject( ) );
-   else
-   return( NULL );
-   }
-
-   // -------------------------------------------------------------------------
-   void cpPlugins::Interface::ProcessObject::
-   _SetOutput( unsigned int idx, itk::DataObject* dobj )
-   {
-   if( idx < this->m_Outputs.size( ) )
-   if( this->m_Outputs[ idx ].IsNotNull( ) )
-   this->m_Outputs[ idx ]->SetRealDataObject( dobj );
-   }
-*/
-
 // eof - $RCSfile$