49 #include <itksys/RegularExpression.hxx>
59 m_Expression(
""), m_WatcherList(), m_ReportProgress(true), m_MaxKeySize(0)
95 std::cout<<exp<<std::endl;
104 std::cerr << std::endl;
107 itkExceptionMacro(
"No expression specified...");
112 std::cerr <<
"ERROR: Parameter keys have to set using \"-\", not \"--\"" << std::endl;
118 std::cerr <<
"ERROR: At least one key is not unique in the expression..." << std::endl;
126 std::cerr <<
"ERROR: At least one specified path within \"" <<
m_Parser->GetPathsAsString(
m_Expression)
127 <<
"\" is invalid or doesn't exist..." << std::endl;
169 catch(std::exception& err)
171 std::ostringstream message;
172 message <<
"The following error occurred during application execution : " << err.what() << std::endl;
189 std::cerr <<
"ERROR: No loaded application..." << std::endl;
195 const std::vector<std::string> appKeyList =
m_Application->GetParametersKeys(
true);
198 if( appKeyList.size()!=0 && keyList.size()==0 )
200 std::cerr <<
"ERROR: Waiting for at least one parameter..." << std::endl;
219 std::string unknownKey;
222 std::cerr <<
"ERROR: option -"<<unknownKey<<
" does not exist in the application." << std::endl;
230 std::cerr <<
"ERROR: Troubles loading parameter, please check your line argument..." << std::endl;
241 std::cerr <<
"ERROR: Troubles in parameter setting, please check your line argument..." << std::endl;
254 std::vector<std::string> val;
258 std::cerr <<
"ERROR: Invalid progress argument, must be unique value..." << std::endl;
261 if (val[0] ==
"1" || val[0] ==
"true")
266 if (val[0] ==
"0" || val[0] ==
"false")
272 std::cerr <<
"ERROR: Invalid progress argument, must be 0, 1, false or true..." << std::endl;
286 std::vector<std::string> pathList;
290 for (
unsigned i = 0; i < pathList.size(); i++)
306 std::string moduleName;
309 std::cerr <<
"ERROR: LoadApplication, no module found..." << std::endl;
318 std::cerr <<
"ERROR: Could not find application \"" << moduleName <<
"\"" << std::endl;
320 const char * ITK_AUTOLOAD_PATH = itksys::SystemTools::GetEnv(
"ITK_AUTOLOAD_PATH");
321 std::cerr <<
"ERROR: Module search path: " << (ITK_AUTOLOAD_PATH ? ITK_AUTOLOAD_PATH :
"none (check ITK_AUTOLOAD_PATH)") << std::endl;
324 if (list.size() == 0)
326 std::cerr <<
"ERROR: Available modules : none." << std::endl;
330 std::cerr <<
"ERROR: Available modules :" << std::endl;
331 for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it)
333 std::cerr <<
"\t" << *it << std::endl;
353 itkExceptionMacro(
"No application loaded");
356 const std::vector<std::string> appKeyList =
m_Application->GetParametersKeys(
true);
358 for (
unsigned int i = 0; i < appKeyList.size(); i++)
360 const std::string paramKey(appKeyList[i]);
361 std::vector<std::string> values;
365 const bool paramExists(
m_Parser->IsAttributExists(std::string(
"-").append(paramKey),
m_Expression));
378 if ( values.empty() )
380 std::cerr <<
"ERROR: No value associated to the parameter : \"" << paramKey <<
"\", invalid number of values " << values.size() << std::endl;
411 if (values.size() == 2)
414 if (values[1] ==
"uint8")
416 else if (values[1] ==
"int16")
418 else if (values[1] ==
"uint16")
420 else if (values[1] ==
"int32")
422 else if (values[1] ==
"uint32")
424 else if (values[1] ==
"float")
426 else if (values[1] ==
"double")
435 if (values.size() != 1 && values.size() != 2)
437 std::cerr <<
"ERROR: Invalid number of value for: \"" << paramKey <<
"\", invalid number of values " << values.size() << std::endl;
447 if(values.size() != 1)
454 for(
unsigned int i=1; i<values.size(); i++)
456 values[0].append(
" ");
457 values[0].append(values[i]);
460 else if (!param->GetAutomaticValue())
462 std::cerr <<
"ERROR: Invalid number of value for: \"" << paramKey <<
"\", must have 1 value, not "
463 << values.size() << std::endl;
480 if (values[0] ==
"1" || values[0] ==
"true")
485 if (values[0] ==
"0" || values[0] ==
"false")
491 std::cerr <<
"ERROR: Wrong parameter value: " << paramKey << std::endl;
496 param->SetUserValue(
true);
507 bool mustBeSet =
false;
513 if( param->IsRoot() || param->GetRoot()->IsRoot())
520 Parameter* currentParam = param->GetRoot();
521 while (!currentParam->
IsRoot())
528 currentParam = currentParam->
GetRoot();
530 if (currentParam->
IsRoot())
546 std::cerr <<
"ERROR: Missing mandatory parameter: " << paramKey <<
" " <<
m_Application->HasValue(paramKey)
554 if (values.size() == 0 && !
m_Application->HasValue(paramKey))
556 std::cerr <<
"ERROR: Missing mandatory parameter: " << paramKey << std::endl;
568 if (values.size() == 0)
570 std::cerr <<
"ERROR: Missing mandatory parameter: " << paramKey << std::endl;
599 std::cerr << std::endl;
601 std::cerr <<
"This is the "<<
m_Application->GetName() <<
" application."<<std::endl;
602 std::cerr<<std::endl;
604 std::cerr<<std::endl;
605 std::string link =
"http://www.orfeo-toolbox.org/Applications/";
607 link.append(
".html");
609 std::cerr <<
"Complete documentation: " << link << std::endl;
610 std::cerr<<std::endl;
611 std::cerr <<
"Parameters: " << std::endl;
613 const std::vector<std::string> appKeyList =
m_Application->GetParametersKeys(
true);
614 const unsigned int nbOfParam = appKeyList.size();
617 for (
unsigned int i = 0; i < nbOfParam; i++)
627 std::string bigKey =
"progress";
628 for(
unsigned int i=0; i<
m_MaxKeySize-std::string(
"progress").size(); i++)
631 std::cerr <<
" -"<<bigKey<<
" <boolean> Report progress " << std::endl;
633 for (
unsigned int i = 0; i < nbOfParam; i++)
642 std::cerr<<std::endl;
668 std::ostringstream oss;
675 bool isMissing =
false;
680 if( param->GetMandatory() && param->GetRole() !=
Role_Output )
682 if( param->IsRoot() || param->GetRoot()->IsRoot())
689 Parameter* currentParam = param->GetRoot();
690 while (!currentParam->
IsRoot())
697 currentParam = currentParam->
GetRoot();
699 if (currentParam->
IsRoot())
719 std::string bigKey = paramKey;
720 for(
unsigned int i=0; i<
m_MaxKeySize-paramKey.size(); i++)
723 oss<<
"-" << bigKey <<
" ";
746 oss <<
"<string> [pixel]";
751 oss <<
"<string list> ";
754 itkExceptionMacro(
"Not handled parameter type.");
757 oss<<
" " << param->GetName() <<
" ";
761 oss <<
" [pixel=uint8/uint16/int16/uint32/int32/float/double]";
762 oss <<
" (default value is float)";
772 for(
unsigned int i=0; i<keys.size(); i++)
775 if( i != keys.size()-1 )
792 oss<<
", on by default";
796 oss<<
", off by default";
802 oss<<
", default value is "<<
m_Application->GetParameterAsString(paramKey);
817 for (
unsigned int i = 0; i < keyList.size(); i++)
819 std::vector<std::string> listTmp = keyList;
820 const std::string keyRef = keyList[i];
821 listTmp.erase(listTmp.begin() + i);
822 for (
unsigned int j = 0; j < listTmp.size(); j++)
824 if (keyRef == listTmp[j])
856 std::vector<std::string> appKeyList =
m_Application->GetParametersKeys(
true);
857 appKeyList.push_back(
"help");
858 appKeyList.push_back(
"progress");
859 appKeyList.push_back(
"testenv");
862 for (
unsigned int i = 0; i < expKeyList.size(); i++)
864 refKey = expKeyList[i];
865 bool keyExist =
false;
866 for (
unsigned int j = 0; j < appKeyList.size(); j++)
868 if (refKey == appKeyList[j])
874 if (keyExist ==
false)
886 std::vector< std::pair<std::string, std::string> > paramList;
888 if( paramList.size() == 0 )
891 std::ostringstream oss;
892 for(
unsigned int i=0; i<paramList.size(); i++)
894 oss << paramList[i].first;
896 oss << paramList[i].second;
904 if( val.size() == 1 )
906 std::ofstream ofs(val[0].c_str());
909 fprintf(stderr,
"Error, can't open file");
910 itkExceptionMacro( <<
"Error, can't open file "<<val[0]<<
".");
917 std::cout <<
"Output parameters value:" << std::endl;
918 std::cout << oss.str() << std::endl;