X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=appli%2Fplugins%2FcpPlugins_ExecuteWorkspace.cxx;fp=appli%2Fplugins%2FcpPlugins_ExecuteWorkspace.cxx;h=e5ee4cb07bb98c598ccf32388a2fd28309b3f5eb;hb=201c5026430f9bcc33f9db6a39f5d03db096c860;hp=0000000000000000000000000000000000000000;hpb=aa77db36cc1d87ba014c982a235239c3c87224f3;p=cpPlugins.git diff --git a/appli/plugins/cpPlugins_ExecuteWorkspace.cxx b/appli/plugins/cpPlugins_ExecuteWorkspace.cxx new file mode 100644 index 0000000..e5ee4cb --- /dev/null +++ b/appli/plugins/cpPlugins_ExecuteWorkspace.cxx @@ -0,0 +1,76 @@ +#include +#include +#include +#include +#include +#include + +int main( int argc, char* argv[] ) +{ + if( argc == 1 ) + { + std::cout << "Usage: " << argv[ 0 ] << " workspace args" << std::endl; + return( 1 ); + + } // fi + std::string ws_file = argv[ 1 ]; + + // Configure a plugin interface and load given workspace + cpPlugins::Interface interface; + cpPlugins::Workspace ws; + ws.SetInterface( &interface ); + std::string err = ws.LoadWorkspace( ws_file ); + if( err != "" ) + { + std::cerr + << "Error loading workspace \"" << ws_file << "\": " + << err << std::endl; + return( 1 ); + + } // fi + + // Read arguments + for( unsigned int i = 2; i < argc; i += 2 ) + { + std::vector< std::string > tokens; + cpPlugins::TokenizeString( tokens, argv[ i ], "@" ); + std::string filter_name = tokens[ 1 ]; + std::string param_name = tokens[ 0 ]; + std::string param_value = argv[ i + 1 ]; + + auto filter = ws.GetFilter( filter_name ); + if( filter != NULL ) + filter->GetParameters( )->SetString( param_name, param_value ); + else + std::cerr + << "Warning: filter \"" << filter_name + << "\" is not defined inside the loaded workspace." << std::endl; + + } // rof + + // Execute workspace + ws.PrintExecutionOn( ); + try + { + ws.Execute( ); + } + catch( itk::ExceptionObject& err1 ) + { + std::cerr << "Error caught: " << err1 << std::endl; + return( 1 ); + } + catch( std::exception& err2 ) + { + std::cerr << "Error caught: " << err2.what( ) << std::endl; + return( 1 ); + } + catch( ... ) + { + std::cerr << "Unknown error caught." << std::endl; + return( 1 ); + + } // yrt + return( 0 ); +} + +// eof - $RCSfile$