X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=appli%2Fbash%2FExecutePipeline.cxx;fp=appli%2Fbash%2FExecutePipeline.cxx;h=a293c3a50742142ce0f69494cad953cbc617d2c9;hb=2e142df11d6f312a2a2b5097b8da73571ed523e8;hp=0000000000000000000000000000000000000000;hpb=61b3659afe961ed248f30e26f9ca8f28fcfafddc;p=cpPlugins.git diff --git a/appli/bash/ExecutePipeline.cxx b/appli/bash/ExecutePipeline.cxx new file mode 100644 index 0000000..a293c3a --- /dev/null +++ b/appli/bash/ExecutePipeline.cxx @@ -0,0 +1,143 @@ +// ========================================================================= +// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co) +// ========================================================================= + +#include +#include +#include +#include +#include + +int main( int argc, char* argv[] ) +{ + typedef cpPlugins::Pipeline TPipeline; + namespace bpo = boost::program_options; + + // Declare the supported options. + bpo::options_description d( "Allowed options" ); + d.add_options( ) + ( "help,h", "produce help message" ) + ( "interactive,i", bpo::bool_switch( )->default_value( false ), "Run an interactive menu to configure pipeline" ) + ( "overwrite,o", bpo::bool_switch( )->default_value( false ), "Overwrite XML file" ) + ( "contents,c", bpo::bool_switch( )->default_value( false ), "Print pipeline contents" ) + ( "value,v", bpo::value< std::vector< std::string > >( ), "Parameter values" ) + ( "pipeline,p", bpo::value< std::string >( )->required( ), "Pipeline file" ) + ; + bpo::positional_options_description p; + p.add( "pipeline", -1 ); + + // Parse input arguments + bpo::variables_map v; + try + { + bpo::store( + bpo:: + command_line_parser( argc, argv ).options( d ).positional( p ).run( ), + v + ); + bpo::notify( v ); + if( v.count( "help" ) > 0 ) + { + std::cerr << d << std::endl; + return( 0 ); + + } // fi + } + catch( std::exception& err ) + { + std::cerr << "Error caught: " << err.what( ) << std::endl; + std::cerr << d << std::endl; + return( 1 ); + + } // yrt + + try + { + // Load pipeline + TPipeline::SharedPtr pipeline = TPipeline::New( ); + pipeline->ExecutionDebugOn( ); + pipeline->LoadXML( v[ "pipeline" ].as< std::string >( ) ); + + // Configure pipeline + if( v.count( "value" ) > 0 ) + { + for( + const std::string& pv: + v[ "value" ].as< std::vector< std::string > >( ) + ) + { + std::size_t b = pv.find_first_of( "=" ); + pipeline->SetInValue( pv.substr( 0, b ), pv.substr( b + 1 ) ); + + } // rof + + } // fi + + // Just print pipeline contents + if( v[ "contents" ].as< bool >( ) ) + { + /* TODO + TPipeline::TParametersMap pmap = pipeline->GetParametersMap( ); + TPipeline::TParametersMap::const_iterator pIt; + for( pIt = pmap.begin( ); pIt != pmap.end( ); ++pIt ) + { + std::cout + << pIt->first << " (" + << pIt->second.first << "=" + << pIt->second.second << ")" + << std::endl; + + } // rof + */ + return( 0 ); + + } // fi + + // Interactively configure pipeline + if( v[ "interactive" ].as< bool >( ) ) + { + std::cout << "** Interactively configuring pipeline **" << std::endl; + /* TODO + TPipeline::TParametersMap pmap = pipeline->GetParametersMap( ); + TPipeline::TParametersMap::const_iterator pIt; + for( pIt = pmap.begin( ); pIt != pmap.end( ); ++pIt ) + { + std::cout + << pIt->first << " (" + << pIt->second.first << "=" + << pIt->second.second << "): " + << std::ends; + std::string line; + std::getline( std::cin, line ); + if( line != "" ) + { + std::size_t p = pIt->first.find( "@" ); + pipeline->SetParameter( + pIt->first.substr( p + 1 ), + pIt->first.substr( 0, p ), + line + ); + + } // fi + + } // rof + */ + } // fi + + // Execute pipeline + pipeline->Update( ); + + // Save pipeline + if( v[ "overwrite" ].as< bool >( ) ) + pipeline->SaveXML( v[ "pipeline" ].as< std::string >( ) ); + } + catch( std::exception& err ) + { + std::cerr << "ERROR CAUGHT: " << err.what( ) << std::endl; + return( 1 ); + + } // yrt + return( 0 ); +} + +// eof - $RCSfile$