X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=appli%2FImageMPR%2FImageMPR.cxx;h=cc9a01569b7efcaa2d8d926401e628752d4d3314;hb=8e5fd31fd4d280781d8bc27a799361bf9c30b1d4;hp=47c3622e4e7430af2663940ea6a32de22d1e7de2;hpb=a02d2e4b730e0a8c7709856c9c47eb7ad19edda0;p=cpPlugins.git diff --git a/appli/ImageMPR/ImageMPR.cxx b/appli/ImageMPR/ImageMPR.cxx index 47c3622..cc9a015 100644 --- a/appli/ImageMPR/ImageMPR.cxx +++ b/appli/ImageMPR/ImageMPR.cxx @@ -33,8 +33,13 @@ ImageMPR( QWidget* parent ) ImageMPR_ConnectAction( LoadPlugins ); ImageMPR_ConnectAction( ShowPlugins ); - // Try to load default plugins - this->m_Plugins->LoadPluginsConfigurationFile( "Plugins.cfg" ); + // Try to load default plugins +#ifdef WIN32 + this->m_Plugins->LoadPlugins("cpPluginsIO.dll"); + this->m_Plugins->LoadPlugins("cpPluginsBasicFilters.dll"); +#else + this->m_Plugins->LoadPluginsConfigurationFile("Plugins.cfg"); +#endif this->m_Plugins->AssociatePluginsToMenu( this->m_UI->MenuFilters, this, SLOT( _execPlugin( ) ) ); @@ -138,10 +143,13 @@ _aOpenPolyData( ) void ImageMPR:: _aSaveImage( ) { - /* - if( this->m_MainImage.IsNotNull( ) ) - this->m_Plugins->WriteImage( this->m_MainImage, true ); - */ + std::string data_name = this->m_UI->MPR->GetSelectedData( ); + TPlugins::TImage* image = dynamic_cast< TPlugins::TImage* >( + this->m_Objects[ data_name ].second.GetPointer( ) + ); + if( image == NULL ) + return; + this->m_Plugins->WriteImage( image, true ); } // ------------------------------------------------------------------------- @@ -154,6 +162,13 @@ _aSaveSegmentation( ) void ImageMPR:: _aSavePolyData( ) { + std::string data_name = this->m_UI->MPR->GetSelectedData( ); + TPlugins::TMesh* mesh = dynamic_cast< TPlugins::TMesh* >( + this->m_Objects[ data_name ].second.GetPointer( ) + ); + if( mesh == NULL ) + return; + this->m_Plugins->WriteMesh( mesh, true ); } // ------------------------------------------------------------------------- @@ -188,13 +203,6 @@ _aShowPlugins( ) void ImageMPR:: _execPlugin( ) { - /* - typedef std::map< std::string, TPlugins::TImage::Pointer > _TImages; - typedef std::map< std::string, TPlugins::TMesh::Pointer > _TMeshes; - - // Get selected data - // std::string data_name = this->m_UI->MPR->GetSelectedData( ); - // Get filter name QAction* action = dynamic_cast< QAction* >( this->sender( ) ); if( action == NULL ) @@ -222,159 +230,104 @@ _execPlugin( ) } // fi + // Configure filter + if( !( filter->ExecConfigurationDialog( this ) ) ) + return; + // Assign inputs + std::string data_name = this->m_UI->MPR->GetSelectedData( ); std::vector< std::string > inputs_names = filter->GetInputsNames( ); if( inputs_names.size( ) == 1 ) { - std::string data_name = this->m_UI->MPR->GetSelectedData( ); - _TImages::iterator iIt = this->m_Images.find( data_name ); - _TImages::iterator mIt = this->m_Meshes.find( data_name ); - filter->SetInput( inputs_names[ 0 ]); - } - else if( inputs_names.size( ) > 1 ) - { - } // fi - - // Get outputs - std::vector< std::string > outputs_names = filter->GetOutputsNames( ); - */ - - /* - - // Choose inputs - if( filter_cate == "ImageToMeshFilter" ) - { - // Check inputs - _TImages::iterator iIt = this->m_Images.find( data_name ); - if( iIt == this->m_Images.end( ) ) + TTree::iterator iIt = this->m_Objects.find( data_name ); + if( iIt == this->m_Objects.end( ) ) { QMessageBox::critical( this, - tr( "Error creating filter" ), - tr( "No valid input selected." ) + tr( "Error configuring filter" ), + tr( "No valid input found. Please select a valid input." ) ); return; - } // fi - - // Execute configuration dialog - if( !( filter->ExecConfigurationDialog( this ) ) ) - return; - - // Execute filter - filter->SetInput( "Input", iIt->second ); - this->_Block( ); - std::string filter_err = filter->Update( ); - this->_Unblock( ); - if( filter_err != "" ) - { - QMessageBox::critical( - this, - tr( "Error executing" ), - tr( filter_err.c_str( ) ) - ); - return; + } //fi + filter->SetInput( inputs_names[ 0 ], iIt->second.second ); + } + else if( inputs_names.size( ) > 1 ) + { + QMessageBox::critical( + this, + tr( "Error executing" ), + tr( "Filter has multiple inputs: NOT YET IMPLEMENTED!!!" ) + ); + return; - } // fi + } // fi - // Keep and show results - TPlugins::TMesh::Pointer mesh = - filter->GetOutput< TPlugins::TMesh >( "Output" ); - this->m_Meshes[ filter_name ] = mesh; - this->_Block( ); - this->m_UI->MPR->ShowMesh( - mesh->GetVTK< vtkPolyData >( ), - filter_name, - data_name + // Execute filter + this->_Block( ); + std::string filter_err = filter->Update( ); + this->_Unblock( ); + if( filter_err != "" ) + { + QMessageBox::critical( + this, + tr( "Error executing" ), + tr( filter_err.c_str( ) ) ); - this->_Unblock( ); + return; } // fi - */ - /* - if( this->m_Plugins->CreateFilter( filter, name ) ) - { - if( filter->ExecConfigurationDialog( this ) ) + // Get outputs + std::vector< std::string > outputs_names = filter->GetOutputsNames( ); + for( + auto oIt = outputs_names.begin( ); + oIt != outputs_names.end( ); + ++oIt + ) + { + std::string out_name = filter_name + "_" + *oIt; + + TPlugins::TImage* image = filter->GetOutput< TPlugins::TImage >( *oIt ); + if( image != NULL ) { - filter->SetInput( "Input", this->m_MainImage ); - this->_Block( ); - err = filter->Update( ); - this->_Unblock( ); - TPlugins::TMesh::Pointer mesh = - filter->GetOutput< TPlugins::TMesh >( "Output" ); - this->m_Meshes.push_back( mesh ); - mesh->CreateVTKActor( ); - vtkActor* actor = mesh->GetVTKActor( ); - if( actor != NULL ) - this->m_UI->MPR->Add3DActor( actor ); + if( filter_cate == "ImageToBinaryImageFilter" ) + { + this->m_UI->MPR->ShowImage( + image->GetVTK< vtkImageData >( ), + out_name, + data_name, 1, 0, 0 + ); + } + else if( filter_cate == "ImageToImageFilter" ) + { + } // fi + + // Keep a track on a local data tree and go to next output + this->m_Objects[ out_name ] = TTreeNode( data_name, image ); + continue; } // fi - - } // fi - } - else - QMessageBox::critical( - this, - tr( "Error creating filter" ), - tr( "No valid filter defined." ) - ); - */ - /* - if( name == "cpPlugins::BasicFilters::FloodFillImageFilter" ) - { - this->m_Flooding = true; - } - else + + TPlugins::TMesh* mesh = filter->GetOutput< TPlugins::TMesh >( *oIt ); + if( mesh != NULL ) { - this->m_Flooding = false; - this->m_UI->MPR->ExecuteFilter( - name, this->m_ImageLoaded, "SegmentedImage" - ); - - } // fi - */ - - // Configure filter - /* - TPluginFilter::Pointer filter = - this->m_Plugins.CreateProcessObject( name ); - bool dlg_ok = filter->ExecConfigurationDialog( NULL ); - if( !dlg_ok ) - return; + // Show mesh + this->_Block( ); + this->m_UI->MPR->ShowMesh( + mesh->GetVTK< vtkPolyData >( ), + out_name, + data_name + ); + this->_Unblock( ); - // Execute filter - QApplication::setOverrideCursor( Qt::WaitCursor ); - this->setEnabled( false ); - filter->SetInput( 0, this->m_Image ); - std::string err = filter->Update( ); - QApplication::restoreOverrideCursor( ); - this->setEnabled( true ); + // Keep a track on a local data tree and go to next output + this->m_Objects[ out_name ] = TTreeNode( data_name, mesh ); + continue; - // Update image - if( err == "" ) - { - TPluginImage* result = filter->GetOutput< TPluginImage >( 0 ); - result->DisconnectPipeline( ); - this->m_Image = result; - if( this->m_Image.IsNotNull( ) ) - this->m_MPRObjects->SetImage( - this->m_Image->GetVTK< vtkImageData >( ) - ); - MementoState(this->m_state, this->m_Image); - this->m_state++; - if (this->m_state > this->m_max_state) - { - this->m_max_state = this->m_state; - } - } - else - QMessageBox::critical( - this, - tr( "Error executing filter" ), - tr( err.c_str( ) ) - ); - */ + } // fi + + } // rof } // -------------------------------------------------------------------------