]> Creatis software - cpPlugins.git/blob - appli/bash/cpPlugins_ExecuteWorkspace.cxx
...
[cpPlugins.git] / appli / bash / cpPlugins_ExecuteWorkspace.cxx
1 #include <iostream>
2 #include <set>
3 #include <string>
4 #include <vector>
5 #include <cpPlugins/Interface.h>
6 #include <cpPlugins/Workspace.h>
7
8 int main( int argc, char* argv[] )
9 {
10   if( argc == 1 )
11   {
12     std::cout << "Usage: " << argv[ 0 ] << " workspace args" << std::endl;
13     return( 1 );
14
15   } // fi
16   std::string ws_file = argv[ 1 ];
17
18   // Configure a plugin interface and load given workspace
19   cpPlugins::Interface interface;
20   cpPlugins::Workspace ws;
21   ws.SetInterface( &interface );
22   std::string err = ws.LoadWorkspace( ws_file );
23   if( err != "" )
24   {
25     std::cerr
26       << "Error loading workspace \"" << ws_file << "\": "
27       << err << std::endl;
28     return( 1 );
29
30   } // fi
31
32   // Read arguments
33   for( unsigned int i = 2; i < argc; i += 2 )
34   {
35     std::vector< std::string > tokens;
36     cpPlugins::TokenizeString( tokens, argv[ i ], "@" );
37     std::string filter_name = tokens[ 1 ];
38     std::string param_name  = tokens[ 0 ];
39     std::string param_value = argv[ i + 1 ];
40
41     auto filter = ws.GetFilter( filter_name );
42     if( filter != NULL )
43       filter->GetParameters( )->SetString( param_name, param_value );
44     else
45       std::cerr
46         << "Warning: filter \"" << filter_name
47         << "\" is not defined inside the loaded workspace." << std::endl;
48
49   } // rof
50
51   // Execute workspace
52   ws.PrintExecutionOn( );
53   try
54   {
55     ws.Execute( );
56   }
57   catch( itk::ExceptionObject& err1 )
58   {
59     std::cerr << "Error caught: " << err1 << std::endl;
60     return( 1 );
61   }
62   catch( std::exception& err2 )
63   {
64     std::cerr << "Error caught: " << err2.what( ) << std::endl;
65     return( 1 );
66   }
67   catch( ... )
68   {
69     std::cerr << "Unknown error caught." << std::endl;
70     return( 1 );
71
72   } // yrt
73   return( 0 );
74 }
75
76 // eof - $RCSfile$