50 #include <itksys/RegularExpression.hxx>
60 m_Expression(
""), m_WatcherList(), m_ReportProgress(true), m_MaxKeySize(0)
96 std::cout<<exp<<std::endl;
105 std::cerr << std::endl;
108 itkExceptionMacro(
"No expression specified...");
113 std::cerr <<
"ERROR: Parameter keys have to set using \"-\", not \"--\"" << std::endl;
119 std::cerr <<
"ERROR: At least one key is not unique in the expression..." << std::endl;
127 std::cerr <<
"ERROR: At least one specified path within \"" <<
m_Parser->GetPathsAsString(
m_Expression)
128 <<
"\" is invalid or doesn't exist..." << std::endl;
170 catch(std::exception& err)
172 std::ostringstream message;
173 message <<
"The following error occurred during application execution : " << err.what() << std::endl;
190 std::cerr <<
"ERROR: No loaded application..." << std::endl;
196 const std::vector<std::string> appKeyList =
m_Application->GetParametersKeys(
true);
199 if( appKeyList.size()!=0 && keyList.size()==0 )
201 std::cerr <<
"ERROR: Waiting for at least one parameter..." << std::endl;
220 std::string unknownKey;
223 std::cerr <<
"ERROR: option -"<<unknownKey<<
" does not exist in the application." << std::endl;
231 std::cerr <<
"ERROR: Troubles loading parameter, please check your line argument..." << std::endl;
242 std::cerr <<
"ERROR: Troubles in parameter setting, please check your line argument..." << std::endl;
255 std::vector<std::string> val;
259 std::cerr <<
"ERROR: Invalid progress argument, must be unique value..." << std::endl;
262 if (val[0] ==
"1" || val[0] ==
"true")
267 if (val[0] ==
"0" || val[0] ==
"false")
273 std::cerr <<
"ERROR: Invalid progress argument, must be 0, 1, false or true..." << std::endl;
287 std::vector<std::string> pathList;
291 for (
unsigned i = 0; i < pathList.size(); i++)
307 std::string moduleName;
310 std::cerr <<
"ERROR: LoadApplication, no module found..." << std::endl;
319 std::cerr <<
"ERROR: Could not find application \"" << moduleName <<
"\"" << std::endl;
321 const char * ITK_AUTOLOAD_PATH = itksys::SystemTools::GetEnv(
"ITK_AUTOLOAD_PATH");
322 std::cerr <<
"ERROR: Module search path: " << (ITK_AUTOLOAD_PATH ? ITK_AUTOLOAD_PATH :
"none (check ITK_AUTOLOAD_PATH)") << std::endl;
325 if (list.size() == 0)
327 std::cerr <<
"ERROR: Available modules : none." << std::endl;
331 std::cerr <<
"ERROR: Available modules :" << std::endl;
332 for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it)
334 std::cerr <<
"\t" << *it << std::endl;
354 itkExceptionMacro(
"No application loaded");
357 const std::vector<std::string> appKeyList =
m_Application->GetParametersKeys(
true);
359 for (
unsigned int i = 0; i < appKeyList.size(); i++)
361 const std::string paramKey(appKeyList[i]);
362 std::vector<std::string> values;
366 const bool paramExists(
m_Parser->IsAttributExists(std::string(
"-").append(paramKey),
m_Expression));
379 if ( values.empty() )
381 std::cerr <<
"ERROR: No value associated to the parameter : \"" << paramKey <<
"\", invalid number of values " << values.size() << std::endl;
417 if (values.size() == 2)
420 if (values[1] ==
"uint8")
422 else if (values[1] ==
"int16")
424 else if (values[1] ==
"uint16")
426 else if (values[1] ==
"int32")
428 else if (values[1] ==
"uint32")
430 else if (values[1] ==
"float")
432 else if (values[1] ==
"double")
441 if (values.size() != 1 && values.size() != 2)
443 std::cerr <<
"ERROR: Invalid number of value for: \"" << paramKey <<
"\", invalid number of values " << values.size() << std::endl;
453 if(values.size() != 1)
460 for(
unsigned int i=1; i<values.size(); i++)
462 values[0].append(
" ");
463 values[0].append(values[i]);
466 else if (!param->GetAutomaticValue())
468 std::cerr <<
"ERROR: Invalid number of value for: \"" << paramKey <<
"\", must have 1 value, not "
469 << values.size() << std::endl;
487 if (values[0] ==
"1" || values[0] ==
"true")
492 if (values[0] ==
"0" || values[0] ==
"false")
498 std::cerr <<
"ERROR: Wrong parameter value: " << paramKey << std::endl;
503 param->SetUserValue(
true);
514 bool mustBeSet =
false;
520 if( param->IsRoot() || param->GetRoot()->IsRoot())
527 Parameter* currentParam = param->GetRoot();
528 while (!currentParam->
IsRoot())
535 currentParam = currentParam->
GetRoot();
537 if (currentParam->
IsRoot())
553 std::cerr <<
"ERROR: Missing mandatory parameter: " << paramKey <<
" " <<
m_Application->HasValue(paramKey)
561 if (values.size() == 0 && !
m_Application->HasValue(paramKey))
563 std::cerr <<
"ERROR: Missing mandatory parameter: " << paramKey << std::endl;
575 if (values.size() == 0)
577 std::cerr <<
"ERROR: Missing mandatory parameter: " << paramKey << std::endl;
606 std::cerr << std::endl;
608 std::cerr <<
"This is the "<<
m_Application->GetName() <<
" application."<<std::endl;
609 std::cerr<<std::endl;
611 std::cerr<<std::endl;
612 std::string link =
"http://www.orfeo-toolbox.org/Applications/";
614 link.append(
".html");
616 std::cerr <<
"Complete documentation: " << link << std::endl;
617 std::cerr<<std::endl;
618 std::cerr <<
"Parameters: " << std::endl;
620 const std::vector<std::string> appKeyList =
m_Application->GetParametersKeys(
true);
621 const unsigned int nbOfParam = appKeyList.size();
624 for (
unsigned int i = 0; i < nbOfParam; i++)
634 std::string bigKey =
"progress";
635 for(
unsigned int i=0; i<
m_MaxKeySize-std::string(
"progress").size(); i++)
638 std::cerr <<
" -"<<bigKey<<
" <boolean> Report progress " << std::endl;
640 for (
unsigned int i = 0; i < nbOfParam; i++)
649 std::cerr<<std::endl;
675 std::ostringstream oss;
682 bool isMissing =
false;
687 if( param->GetMandatory() && param->GetRole() !=
Role_Output )
689 if( param->IsRoot() || param->GetRoot()->IsRoot())
696 Parameter* currentParam = param->GetRoot();
697 while (!currentParam->
IsRoot())
704 currentParam = currentParam->
GetRoot();
706 if (currentParam->
IsRoot())
726 std::string bigKey = paramKey;
727 for(
unsigned int i=0; i<
m_MaxKeySize-paramKey.size(); i++)
730 oss<<
"-" << bigKey <<
" ";
753 oss <<
"<string> [pixel]";
759 oss <<
"<string list> ";
762 itkExceptionMacro(
"Not handled parameter type.");
765 oss<<
" " << param->GetName() <<
" ";
769 oss <<
" [pixel=uint8/uint16/int16/uint32/int32/float/double]";
770 oss <<
" (default value is float)";
780 for(
unsigned int i=0; i<keys.size(); i++)
783 if( i != keys.size()-1 )
800 oss<<
", on by default";
804 oss<<
", off by default";
810 oss<<
", default value is "<<
m_Application->GetParameterAsString(paramKey);
825 for (
unsigned int i = 0; i < keyList.size(); i++)
827 std::vector<std::string> listTmp = keyList;
828 const std::string keyRef = keyList[i];
829 listTmp.erase(listTmp.begin() + i);
830 for (
unsigned int j = 0; j < listTmp.size(); j++)
832 if (keyRef == listTmp[j])
864 std::vector<std::string> appKeyList =
m_Application->GetParametersKeys(
true);
865 appKeyList.push_back(
"help");
866 appKeyList.push_back(
"progress");
867 appKeyList.push_back(
"testenv");
870 for (
unsigned int i = 0; i < expKeyList.size(); i++)
872 refKey = expKeyList[i];
873 bool keyExist =
false;
874 for (
unsigned int j = 0; j < appKeyList.size(); j++)
876 if (refKey == appKeyList[j])
882 if (keyExist ==
false)
894 std::vector< std::pair<std::string, std::string> > paramList;
896 if( paramList.size() == 0 )
899 std::ostringstream oss;
900 for(
unsigned int i=0; i<paramList.size(); i++)
902 oss << paramList[i].first;
904 oss << paramList[i].second;
912 if( val.size() == 1 )
914 std::ofstream ofs(val[0].c_str());
917 fprintf(stderr,
"Error, can't open file");
918 itkExceptionMacro( <<
"Error, can't open file "<<val[0]<<
".");
925 std::cout <<
"Output parameters value:" << std::endl;
926 std::cout << oss.str() << std::endl;