]> Creatis software - cpMesh.git/blobdiff - appli/InteractiveDeformableMeshSegmentation/MainWnd_ExecutePlugins.cxx
...
[cpMesh.git] / appli / InteractiveDeformableMeshSegmentation / MainWnd_ExecutePlugins.cxx
index 8429a818d38ceb7c41dfa1f792359d1e30801dc4..a22dd626232f627f6bf9c2a1015a4bb3e94f3185 100644 (file)
 #include "ui_MainWnd.h"
 
 #include <cstdlib>
+#include <sstream>
 
 #include <QDoubleSpinBox>
 #include <QLabel>
+#include <QMessageBox>
+
+#include <itkImageRegionIterator.h>
+#include <itkImageRegionConstIterator.h>
+#define ITK_MANUAL_INSTANTIATION
+#include <itkImage.h>
 
 // -------------------------------------------------------------------------
 bool MainWnd::
 _ParametersDialog( const TParameters& parameters )
 {
-  if( this->m_ActiveParameters != NULL ) 
-    this->m_ActiveParameters->close( );
-  this->m_ActiveParameters = new QWidget( NULL );
-  this->m_ActiveParameters->setWindowFlags( Qt::FramelessWindowHint ); 
-  this->m_ActiveParameters->setWindowFlags( Qt::WindowTitleHint );
-
-  QGridLayout* gridLayout = new QGridLayout( this->m_ActiveParameters );
-  QVBoxLayout* verticalLayout = new QVBoxLayout( );
-
-  // Put values
-  QLabel* title = new QLabel( this->m_ActiveParameters );
-  title->setText( this->m_ActivePlugin->GetClassName( ).c_str( ) );
-  verticalLayout->addWidget( title );
-
-  TParameters::const_iterator pIt = parameters.begin( );
-  for( ; pIt != parameters.end( ); ++pIt )
-  {
-    std::string par_name = pIt->first;
-    std::string par_type = pIt->second.first;
-    std::string par_value = pIt->second.second;
-
-    if( par_type == "double" )
-    {
-      QHBoxLayout* horizontalLayout = new QHBoxLayout( );
-      QLabel* label = new QLabel( this->m_ActiveParameters );
-      label->setText( QString( par_name.c_str( ) ) );
-      horizontalLayout->addWidget( label );
-
-      QDoubleSpinBox* v_double =
-        new QDoubleSpinBox( this->m_ActiveParameters );
-      v_double->setDecimals( 3 );
-      v_double->setMinimum( -( std::numeric_limits< double >::max( ) ) );
-      v_double->setMaximum( std::numeric_limits< double >::max( ) );
-      v_double->setValue( std::atof( par_value.c_str( ) ) );
-      v_double->setObjectName( QString( par_name.c_str( ) ) );
-      horizontalLayout->addWidget( v_double );
-      verticalLayout->addLayout( horizontalLayout );
-
-    } // fi
-
-  } // rof
-  gridLayout->addLayout( verticalLayout, 0, 0, 1, 1 );
-  QMetaObject::connectSlotsByName( this->m_ActiveParameters );
-  this->m_ActiveParameters->show( );
-
-  /*
-    typedef std::map< std::string, QWidget* > _TWidgets;
-    _TWidgets widgets;
-    TParameters::const_iterator pIt = parameters.begin( );
-    for( ; pIt != parameters.end( ); ++pIt )
-    {
-    unsigned long pos = pIt->first.find_last_of( ":" );
-    std::string v_name = pIt->first.substr( 0, pos );
-    std::string v_type = pIt->first.substr( pos + 1 );
-    QHBoxLayout* horizontalLayout = new QHBoxLayout( );
-    QLabel* label = new QLabel( this->m_ActiveParameters );
-    label->setText( QString( v_name.c_str( ) ) );
-    horizontalLayout->addWidget( label );
-    if( v_type == "real" )
-    {
-    QDoubleSpinBox* v_double = new QDoubleSpinBox( this->m_ActiveParameters );
-    v_double->setDecimals( 3 );
-    v_double->setMinimum( -( std::numeric_limits< double >::max( ) ) );
-    v_double->setMaximum( std::numeric_limits< double >::max( ) );
-    v_double->setValue( std::atof( pIt->second.c_str( ) ) );
-    horizontalLayout->addWidget( v_double );
-    widgets[ pIt->first ] = v_double;
-    }
-    else if( v_type == "atomic_real" )
-    {
-    if( v_name == "MeshType" )
-    {
-    QLabel* info = new QLabel( this->m_ActiveParameters );
-    if( typeid( TScalar ) == typeid( float ) )
-    info->setText( QString( "float" ) );
-    else if( typeid( TScalar ) == typeid( double ) )
-    info->setText( QString( "double" ) );
-    horizontalLayout->addWidget( info );
-    widgets[ pIt->first ] = info;
-    } // fi
-    } // fi
-    verticalLayout.addLayout( horizontalLayout );
-    } // rof
-    gridLayout.addLayout( &verticalLayout, 0, 0, 1, 1 );
-    // Buttons box
-    QDialogButtonBox buttonBox( this->m_ActiveParameters );
-    buttonBox.setOrientation( Qt::Horizontal );
-    buttonBox.setStandardButtons(
-    QDialogButtonBox::Cancel | QDialogButtonBox::Ok
-    );
-    gridLayout.addWidget( &buttonBox, 1, 0, 1, 1 );
-    QObject::connect(
-    &buttonBox, SIGNAL( accepted( ) ),
-    this->m_ActiveParameters, SLOT( accept( ) )
-    );
-    QObject::connect(
-    &buttonBox, SIGNAL( rejected( ) ),
-    this->m_ActiveParameters, SLOT( reject( ) )
-    );
-    QMetaObject::connectSlotsByName( this->m_ActiveParameters );
-
-    // Execute dialog
-    if( dlg.exec( ) == QDialog::Accepted )
-    {
-    _TWidgets::const_iterator wIt = widgets.begin( );
-    for( ; wIt != widgets.end( ); ++wIt )
-    {
-    unsigned long pos = wIt->first.find_last_of( ":" );
-    std::string v_name = wIt->first.substr( 0, pos );
-    std::string v_type = wIt->first.substr( pos + 1 );
-    std::stringstream sstr;
-    if( v_type == "real" )
-    {
-    QDoubleSpinBox* v_double =
-    dynamic_cast< QDoubleSpinBox* >( wIt->second );
-    if( v_double != NULL )
-    sstr << v_double->value( );
-    }
-    else if( v_type == "atomic_real" )
-    {
-    if( v_name == "MeshType" )
-    {
-    QLabel* info = dynamic_cast< QLabel* >( wIt->second );
-    if( info != NULL )
-    sstr << info->text( ).toStdString( );
-
-    } // fi
-
-    } // fi
-    parameters[ wIt->first ] = sstr.str( );
-
-    } // rof
-    return( true );
-    }
-  */
-  return( false );
+//   if( this->m_ActiveParameters != NULL ) 
+//     this->m_ActiveParameters->close( );
+//   this->m_ActiveParameters = new QWidget( NULL );
+//   this->m_ActiveParameters->setWindowFlags( Qt::FramelessWindowHint ); 
+//   this->m_ActiveParameters->setWindowFlags( Qt::WindowTitleHint );
+
+//   QGridLayout* gridLayout = new QGridLayout( this->m_ActiveParameters );
+//   QVBoxLayout* verticalLayout = new QVBoxLayout( );
+
+//   // Put values
+//   QLabel* title = new QLabel( this->m_ActiveParameters );
+//   title->setText( this->m_ActivePlugin->GetClassName( ).c_str( ) );
+//   verticalLayout->addWidget( title );
+
+//   TParameters::const_iterator pIt = parameters.begin( );
+//   for( ; pIt != parameters.end( ); ++pIt )
+//   {
+//     std::string par_name = pIt->first;
+//     std::string par_type = pIt->second.first;
+//     std::string par_value = pIt->second.second;
+
+//     if( par_type == "double" )
+//     {
+//       QHBoxLayout* horizontalLayout = new QHBoxLayout( );
+//       QLabel* label = new QLabel( this->m_ActiveParameters );
+//       label->setText( QString( par_name.c_str( ) ) );
+//       horizontalLayout->addWidget( label );
+
+//       QDoubleSpinBox* v_double =
+//         new QDoubleSpinBox( this->m_ActiveParameters );
+//       v_double->setDecimals( 3 );
+//       v_double->setMinimum( -( std::numeric_limits< double >::max( ) ) );
+//       v_double->setMaximum( std::numeric_limits< double >::max( ) );
+//       v_double->setValue( std::atof( par_value.c_str( ) ) );
+//       v_double->setObjectName( QString( par_name.c_str( ) ) );
+//       horizontalLayout->addWidget( v_double );
+//       verticalLayout->addLayout( horizontalLayout );
+
+//     } // fi
+
+//   } // rof
+//   gridLayout->addLayout( verticalLayout, 0, 0, 1, 1 );
+
+//   // Infere plugin type
+//   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;
+
+//   QMetaObject::connectSlotsByName( this->m_ActiveParameters );
+//   this->m_ActiveParameters->show( );
+
+//   return( false );
+}
+
+// -------------------------------------------------------------------------
+void MainWnd::
+_ExecuteDoubleClickPlugin( const double* pnt )
+{
+//   if(
+//     this->m_InputImage == NULL ||
+//     this->m_SegmentedImage == NULL ||
+//     this->m_ActivePlugin == NULL ||
+//     this->m_ActiveParameters == NULL ||
+//     this->m_ActivePluginType != Self::DoubleClickPluginType
+//     )
+//     return;
+
+//   TParameters parameters = this->m_ActivePlugin->GetDefaultParameters( );
+
+//   // Variable parameters
+//   for(
+//     TParameters::iterator pIt = parameters.begin( );
+//     pIt != parameters.end( );
+//     ++pIt
+//     )
+//   {
+//     if( pIt->first != "Seed" )
+//     {
+//       if( pIt->second.first == "double" )
+//       {
+//         QDoubleSpinBox* v_double = this->m_ActiveParameters->
+//           findChild< QDoubleSpinBox* >( pIt->first.c_str( ) );
+//         if( v_double != NULL )
+//           parameters[ pIt->first ] =
+//             TParameter( "double", v_double->text( ).toStdString( ) );
+        
+//       } // fi
+
+//     } // fi
+
+//   } // rof
+
+//   // Seed
+//   std::stringstream seed_str;
+//   seed_str << pnt[ 0 ] << ":" << pnt[ 1 ] << ":" << pnt[ 2 ];
+//   parameters[ "Seed" ] = TParameter( "point", seed_str.str( ) );
+
+//   // Execute
+//   this->m_ActivePlugin->SetParameters( parameters );
+//   this->m_ActivePlugin->SetInput( 0, this->m_InputImage );
+//   this->m_ActivePlugin->SetInput( 1, this->m_SegmentedImage );
+//   std::string err = this->m_ActivePlugin->Update( );
+//   if( err != "" )
+//   {
+//     QMessageBox::critical( this, tr( "Error caugth!" ), tr( err.c_str( ) ) );
+//     return;
+
+//   } // fi
+
+//   // Join results
+//   itk::DataObject* s = this->m_SegmentedImage->GetDataObject( );
+//   if( dynamic_cast< itk::Image< char, 3 >* >( s ) != NULL )
+//     this->_JoinSegmentations< char >( );
+//   else if( dynamic_cast< itk::Image< short, 3 >* >( s ) != NULL )
+//     this->_JoinSegmentations< short >( );
+//   else if( dynamic_cast< itk::Image< int, 3 >* >( s ) != NULL )
+//     this->_JoinSegmentations< int >( );
+//   else if( dynamic_cast< itk::Image< long, 3 >* >( s ) != NULL )
+//     this->_JoinSegmentations< long >( );
+//   else if( dynamic_cast< itk::Image< unsigned char, 3 >* >( s ) != NULL )
+//     this->_JoinSegmentations< unsigned char >( );
+//   else if( dynamic_cast< itk::Image< unsigned short, 3 >* >( s ) != NULL )
+//     this->_JoinSegmentations< unsigned short >( );
+//   else if( dynamic_cast< itk::Image< unsigned int, 3 >* >( s ) != NULL )
+//     this->_JoinSegmentations< unsigned int >( );
+//   else if( dynamic_cast< itk::Image< unsigned long, 3 >* >( s ) != NULL )
+//     this->_JoinSegmentations< unsigned long >( );
+
+//   // Update visualization
+//   this->m_SegmentedImage->UpdateVTKImageData( );
+//   this->m_MPR->Render( 0 );
+//   this->m_MPR->Render( 1 );
+//   this->m_MPR->Render( 2 );
 }
 
 // -------------------------------------------------------------------------
@@ -158,25 +170,26 @@ _triggered_actionSegmentImage( )
 void MainWnd::
 _triggered_actionFilterSegmentation( )
 {
-  // Get filter name
-  if( this->m_SegmentedImage == NULL )
-    return;
-  QAction* action = dynamic_cast< QAction* >( this->sender( ) );
-  if( action == NULL )
-    return;
-  std::string filter_name = action->text( ).toStdString( );
-
-  // Create plugin
-  if( this->m_ActivePlugin != NULL ) delete this->m_ActivePlugin;
-  this->m_ActivePlugin =
-    dynamic_cast< TPlugin* >(
-      this->m_Plugins.CreateObject(
-        this->m_SegmentationFilterClasses[ filter_name ]
-        )
-      );
-
-  // Show parameters dialog
-  this->_ParametersDialog( this->m_ActivePlugin->GetDefaultParameters( ) );
+//   // Get filter name
+//   if( this->m_SegmentedImage == NULL )
+//     return;
+//   QAction* action = dynamic_cast< QAction* >( this->sender( ) );
+//   if( action == NULL )
+//     return;
+//   std::string filter_name = action->text( ).toStdString( );
+
+//   // Create plugin
+//   if( this->m_ActivePlugin != NULL ) delete this->m_ActivePlugin;
+//   this->m_ActivePlugin =
+//     dynamic_cast< TPlugin* >(
+//       this->m_Plugins.CreateObject(
+//         this->m_SegmentationFilterClasses[ filter_name ]
+//         )
+//       );
+//   this->m_ActivePluginCategory = Self::SegmentationFilteringPluginCategory;
+
+//   // Show parameters dialog
+//   this->_ParametersDialog( this->m_ActivePlugin->GetDefaultParameters( ) );
 }
 
 // -------------------------------------------------------------------------
@@ -185,4 +198,86 @@ _triggered_actionProcessMesh( )
 {
 }
 
+// -------------------------------------------------------------------------
+template< class P >
+void MainWnd::
+_JoinSegmentations( )
+{
+//   typedef itk::Image< P, 3 > _TImage;
+
+//   _TImage* old_segmentation =
+//     dynamic_cast< _TImage* >( this->m_SegmentedImage->GetDataObject( ) );
+//   _TImage* new_segmentation =
+//     dynamic_cast< _TImage* >(
+//       dynamic_cast< TPluginImage* >(
+//         this->m_ActivePlugin->GetOutput( 0 )
+//         )->GetDataObject( )
+//       );
+
+//   /* TODO: InPlaceOn does not execute correctly on input image
+//      typedef itk::AndImageFilter< _TImage, _TImage, _TImage > _TFilter;
+//      typename _TFilter::Pointer filter = _TFilter::New( );
+//      filter->InPlaceOn( );
+//      filter->SetInput( 0, old_segmentation );
+//      filter->SetInput( 1, new_segmentation );
+//      filter->Update( );
+//      //old_segmentation->DisconnectPipeline( );
+
+//      std::cout << old_segmentation->GetRequestedRegion( ) << std::endl;
+//      std::cout << new_segmentation->GetRequestedRegion( ) << std::endl;
+//      std::cout << old_segmentation->GetBufferedRegion( ) << std::endl;
+//      std::cout << new_segmentation->GetBufferedRegion( ) << std::endl;
+//   */
+//   typedef itk::ImageRegionConstIterator< _TImage > _TConstIt;
+//   typedef itk::ImageRegionIterator< _TImage > _TIt;
+//   _TConstIt nIt( new_segmentation, new_segmentation->GetRequestedRegion( ) );
+//   _TIt oIt( old_segmentation, old_segmentation->GetRequestedRegion( ) );
+//   nIt.GoToBegin( );
+//   oIt.GoToBegin( );
+//   for( ; !nIt.IsAtEnd( ); ++nIt, ++oIt )
+//     oIt.Set( nIt.Get( ) | oIt.Get( ) );
+}
+
+// -------------------------------------------------------------------------
+DoubleClickCommand* DoubleClickCommand::
+New( )
+{
+//  return( new DoubleClickCommand( ) );
+}
+
+// -------------------------------------------------------------------------
+void DoubleClickCommand::
+SetMainWnd( MainWnd* wnd )
+{
+//  this->m_MainWnd = wnd;
+}
+
+// -------------------------------------------------------------------------
+void DoubleClickCommand::
+Execute( vtkObject* caller, unsigned long eid, void* data )
+{
+//   If( This->M_Mainwnd != Null )
+//     This->M_Mainwnd->_Executedoubleclickplugin(
+//       Reinterpret_Cast< Const Double* >( Data )
+//       );
+}
+
+// -------------------------------------------------------------------------
+DoubleClickCommand::
+DoubleClickCommand( )
+{
+}
+/*
+  : Superclass( ),
+    m_MainWnd( NULL )
+{
+}
+*/
+
+// -------------------------------------------------------------------------
+DoubleClickCommand::
+~DoubleClickCommand( )
+{
+}
+
 // eof - $RCSfile$