X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=appli%2FInteractiveDeformableMeshSegmentation%2FMainWnd_ExecutePlugins.cxx;h=a22dd626232f627f6bf9c2a1015a4bb3e94f3185;hb=93fb9ff2b54c04231a22d71ff71cab186d411900;hp=cbbfac64d213a9884fbe31df39da5466529e14b0;hpb=6618a10363a5eb64022011925c86fa60a6c37e42;p=cpMesh.git diff --git a/appli/InteractiveDeformableMeshSegmentation/MainWnd_ExecutePlugins.cxx b/appli/InteractiveDeformableMeshSegmentation/MainWnd_ExecutePlugins.cxx index cbbfac6..a22dd62 100644 --- a/appli/InteractiveDeformableMeshSegmentation/MainWnd_ExecutePlugins.cxx +++ b/appli/InteractiveDeformableMeshSegmentation/MainWnd_ExecutePlugins.cxx @@ -17,147 +17,147 @@ 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 ); - - // 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 ); +// 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( ) ); +// 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 ); +// } // 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 ); } // ------------------------------------------------------------------------- @@ -170,26 +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 ] - ) - ); - this->m_ActivePluginCategory = Self::SegmentationFilteringPluginCategory; - - // 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( ) ); } // ------------------------------------------------------------------------- @@ -203,72 +203,76 @@ 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( ) ); +// 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( ) ); +// return( new DoubleClickCommand( ) ); } // ------------------------------------------------------------------------- void DoubleClickCommand:: SetMainWnd( MainWnd* wnd ) { - this->m_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 ) - ); +// If( This->M_Mainwnd != Null ) +// This->M_Mainwnd->_Executedoubleclickplugin( +// Reinterpret_Cast< Const Double* >( Data ) +// ); } // ------------------------------------------------------------------------- DoubleClickCommand:: DoubleClickCommand( ) +{ +} +/* : Superclass( ), m_MainWnd( NULL ) { } +*/ // ------------------------------------------------------------------------- DoubleClickCommand::