Orfeo Toolbox  4.0
otbWrapperCommandLineLauncher.cxx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17  =========================================================================*/
19 
20 // Single value parameter
35 #include "otbWrapperRAMParameter.h"
38 
39 // List value parameter
44 
45 #include "otbImageFileWriter.h"
46 
47 
49 #include "otbWrapperApplication.h"
50 #include "otbWrapperTypes.h"
51 #include <itksys/RegularExpression.hxx>
52 #include <string>
53 #include <iostream>
54 
55 namespace otb
56 {
57 namespace Wrapper
58 {
59 
61  m_Expression(""), m_WatcherList(), m_ReportProgress(true), m_MaxKeySize(0)
62 {
66  m_LogOutput->SetStream(std::cout);
67 
68  // Add the callback to be added when a AddProcessToWatch event is invoked
70  m_AddProcessCommand->SetCallbackFunction(this, &CommandLineLauncher::LinkWatchers);
71 }
72 
74  m_Expression(exp)
75 {
78 }
79 
81 {
82  this->DeleteWatcherList();
83 }
84 
86 {
87  for (unsigned int i = 0; i < m_WatcherList.size(); i++)
88  {
89  delete m_WatcherList[i];
90  m_WatcherList[i] = NULL;
91  }
92  m_WatcherList.clear();
93 }
94 
95 bool CommandLineLauncher::Load(const std::string & exp)
96 {
97  m_Expression = exp;
98  return this->Load();
99 }
100 
102 {
103  // Add a space to clarify output logs
104  std::cerr << std::endl;
105  if (m_Expression == "")
106  {
107  itkExceptionMacro("No expression specified...");
108  }
109 
110  if (this->CheckParametersPrefix() == false)
111  {
112  std::cerr << "ERROR: Parameter keys have to set using \"-\", not \"--\"" << std::endl;
113  return false;
114  }
115 
116  if (this->CheckUnicity() == false)
117  {
118  std::cerr << "ERROR: At least one key is not unique in the expression..." << std::endl;
119  return false;
120  }
121 
122  if (this->LoadPath() == false)
123  {
124  if (m_Parser->GetPathsAsString(m_Expression).size() != 0)
125  {
126  std::cerr << "ERROR: At least one specified path within \"" << m_Parser->GetPathsAsString(m_Expression)
127  << "\" is invalid or doesn't exist..." << std::endl;
128  return false;
129  }
130  }
131 
132  this->LoadApplication();
133 
134  return true;
135 }
136 
138 {
139  if (this->BeforeExecute() == false)
140  {
141  return false;
142  }
143 
144  if( m_Application->Execute() == 0 )
145  {
146  this->DisplayOutputParameters();
147  return true;
148  }
149  else
150  return false;
151 }
152 
154 {
155  try
156  {
157  if (this->BeforeExecute() == false)
158  {
159  return false;
160  }
161 
162  if( m_Application->ExecuteAndWriteOutput() == 0 )
163  {
164  this->DisplayOutputParameters();
165  }
166  else
167  return false;
168  }
169  catch(std::exception& err)
170  {
171  std::ostringstream message;
172  message << "The following error occurred during application execution : " << err.what() << std::endl;
173  m_Application->GetLogger()->Write( itk::LoggerBase::FATAL, message.str() );
174  return false;
175  }
176  catch(...)
177  {
178  m_Application->GetLogger()->Write( itk::LoggerBase::FATAL, "An unknown exception has been raised during application execution" );
179  return false;
180  }
181 
182  return true;
183 }
184 
186 {
187  if (m_Application.IsNull())
188  {
189  std::cerr << "ERROR: No loaded application..." << std::endl;
190  return false;
191  }
192 
193  // Check if there's keys in the expression if the application takes
194  // at least 1 mandatory parameter
195  const std::vector<std::string> appKeyList = m_Application->GetParametersKeys(true);
196  std::vector<std::string> keyList = m_Parser->GetKeyList( m_Expression );
197 
198  if( appKeyList.size()!=0 && keyList.size()==0 )
199  {
200  std::cerr << "ERROR: Waiting for at least one parameter..." << std::endl;
201  this->DisplayHelp();
202  return false;
203  }
204 
205  // if help is asked...
206  if (m_Parser->IsAttributExists("-help", m_Expression) == true)
207  {
208  this->DisplayHelp();
209  return false;
210  }
211 
212  //display OTB version
213  if (m_Parser->IsAttributExists("-version", m_Expression) == true)
214  {
215  std::cerr << "This is the "<<m_Application->GetName() << " application, version " << OTB_VERSION_STRING <<std::endl;
216  return false;
217  }
218 
219  // if we want to load test environnement
220  if (m_Parser->IsAttributExists("-testenv", m_Expression) == true)
221  {
222  this->LoadTestEnv();
223  }
224 
225  // Check the key validity (ie. exist in the application parameters)
226  std::string unknownKey;
227  if (this->CheckKeyValidity(unknownKey) == false)
228  {
229  std::cerr << "ERROR: option -"<<unknownKey<<" does not exist in the application." << std::endl;
230  this->DisplayHelp();
231  return false;
232  }
233  try
234  {
235  if (this->LoadParameters() != OKPARAM)
236  {
237  std::cerr << "ERROR: Troubles loading parameter, please check your line argument..." << std::endl;
238  // Force to reload the application, the LoadParameters can change wrong values
239  this->LoadApplication();
240  m_Application->Init();
241  this->DisplayHelp();
242 
243  return false;
244  }
245  }
246  catch (itk::ExceptionObject& err)
247  {
248  std::cerr << "ERROR: Troubles in parameter setting, please check your line argument..." << std::endl;
249  std::cerr << err.GetDescription() << std::endl;
250  // Force to reload the application, the LoadParameters can change wrong values
251  this->LoadApplication();
252  m_Application->Init();
253  this->DisplayHelp();
254 
255  return false;
256  }
257 
258  // Check for the progress report
259  if (m_Parser->IsAttributExists("-progress", m_Expression) == true)
260  {
261  std::vector<std::string> val;
262  val = m_Parser->GetAttribut("-progress", m_Expression);
263  if (val.size() != 1)
264  {
265  std::cerr << "ERROR: Invalid progress argument, must be unique value..." << std::endl;
266  return false;
267  }
268  if (val[0] == "1" || val[0] == "true")
269  {
270  m_ReportProgress = true;
271  }
272  else
273  if (val[0] == "0" || val[0] == "false")
274  {
275  m_ReportProgress = false;
276  }
277  else
278  {
279  std::cerr << "ERROR: Invalid progress argument, must be 0, 1, false or true..." << std::endl;
280  // Force to reload the application, the LoadParameters can change wrong values
281  this->LoadApplication();
282  this->DisplayHelp();
283 
284  return false;
285  }
286  }
287 
288  return true;
289 }
290 
292 {
293  std::vector<std::string> pathList;
294  // If users has set path...
295  if (m_Parser->GetPaths(pathList, m_Expression) == CommandLineParser::OK)
296  {
297  for (unsigned i = 0; i < pathList.size(); i++)
298  {
300  }
301  }
302  else
303  {
304  return false;
305  }
306 
307  return true;
308 }
309 
311 {
312  // Look for the module name
313  std::string moduleName;
314  if (m_Parser->GetModuleName(moduleName, m_Expression) != CommandLineParser::OK)
315  {
316  std::cerr << "ERROR: LoadApplication, no module found..." << std::endl;
317  return;
318  }
319 
320  // Instantiate the application using the factory
322 
323  if (m_Application.IsNull())
324  {
325  std::cerr << "ERROR: Could not find application \"" << moduleName << "\"" << std::endl;
326 
327  const char * ITK_AUTOLOAD_PATH = itksys::SystemTools::GetEnv("ITK_AUTOLOAD_PATH");
328  std::cerr << "ERROR: Module search path: " << (ITK_AUTOLOAD_PATH ? ITK_AUTOLOAD_PATH : "none (check ITK_AUTOLOAD_PATH)") << std::endl;
329 
330  std::vector<std::string> list = ApplicationRegistry::GetAvailableApplications();
331  if (list.size() == 0)
332  {
333  std::cerr << "ERROR: Available modules : none." << std::endl;
334  }
335  else
336  {
337  std::cerr << "ERROR: Available modules :" << std::endl;
338  for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it)
339  {
340  std::cerr << "\t" << *it << std::endl;
341  }
342  }
343  }
344  else
345  {
346  // Attach log output to the Application logger
347  m_Application->GetLogger()->SetTimeStampFormat(itk::LoggerBase::HUMANREADABLE);
348  m_Application->GetLogger()->AddLogOutput(m_LogOutput);
349 
350  // Add an observer to the AddedProcess event
352 
353  }
354 }
355 
357 {
358  if (m_Application.IsNull())
359  {
360  itkExceptionMacro("No application loaded");
361  }
362 
363  /* Check for inxml parameter. If exists Update all Parameters from xml and
364  * check for user defined parameters for overriding those from XML
365  */
366  const char *inXMLKey = "inxml";
367  const char *attrib = "-inxml";
368  const bool paramInXMLExists(m_Parser->IsAttributExists(attrib, m_Expression));
369  if(paramInXMLExists)
370  {
371  std::vector<std::string> inXMLValues;
372  inXMLValues = m_Parser->GetAttribut(attrib, m_Expression);
373  m_Application->SetParameterString(inXMLKey, inXMLValues[0]);
374  m_Application->UpdateParameters();
375  }
376 
377  const std::vector<std::string> appKeyList = m_Application->GetParametersKeys(true);
378  // Loop over each parameter key declared in the application
379  for (unsigned int i = 0; i < appKeyList.size(); i++)
380  {
381  const std::string paramKey(appKeyList[i]);
382  std::vector<std::string> values;
383 
384  Parameter::Pointer param = m_Application->GetParameterByKey(paramKey);
385  ParameterType type = m_Application->GetParameterType(paramKey);
386 
387  const bool paramExists(m_Parser->IsAttributExists(std::string("-").append(paramKey), m_Expression));
388 
389  // if param is a Group, dont do anything, ParamGroup dont have values
390  if (type != ParameterType_Group)
391  {
392  // Get the attribute relative to this key as vector
393  values = m_Parser->GetAttribut(std::string("-").append(paramKey), m_Expression);
394 
395  // If the param does not exists in the cli, dont try to set a
396  // value on it, an exception will be thrown later in this function
397  if (paramExists)
398  {
399  // Check if there is a value associated to the attribute
400  if ( values.empty() )
401  {
402  std::cerr << "ERROR: No value associated to the parameter : \"" << paramKey
403  << "\", invalid number of values " << values.size() << std::endl;
404  return INVALIDNUMBEROFVALUE;
405  }
406 
407  // Ensure that the parameter is enabled
408  m_Application->EnableParameter(paramKey);
409 
411  {
412  dynamic_cast<InputVectorDataListParameter *> (param.GetPointer())->SetListFromFileName(values);
413  }
414  else
415  if (type == ParameterType_InputImageList)
416  {
417  dynamic_cast<InputImageListParameter *> (param.GetPointer())->SetListFromFileName(values);
418  }
419  else
421  {
422  dynamic_cast<InputFilenameListParameter *> (param.GetPointer())->SetListFromFileName(values);
423  }
424  else
425  if (type == ParameterType_StringList)
426  {
427  dynamic_cast<StringListParameter *> (param.GetPointer())->SetValue(values);
428  }
429  else
430  if (type == ParameterType_String)
431  {
432  dynamic_cast<StringParameter *> (param.GetPointer())->SetValue(
433  m_Parser->GetAttributAsString(std::string("-").append(paramKey), m_Expression) );
434  }
435  else
436  if (type == ParameterType_OutputImage)
437  {
438  m_Application->SetParameterString(paramKey, values[0]);
439  // Check if pixel type is given
440  if (values.size() == 2)
441  {
443  if (values[1] == "uint8")
444  outPixType = ImagePixelType_uint8;
445  else if (values[1] == "int16")
446  outPixType = ImagePixelType_int16;
447  else if (values[1] == "uint16")
448  outPixType = ImagePixelType_uint16;
449  else if (values[1] == "int32")
450  outPixType = ImagePixelType_int32;
451  else if (values[1] == "uint32")
452  outPixType = ImagePixelType_uint32;
453  else if (values[1] == "float")
454  outPixType = ImagePixelType_float;
455  else if (values[1] == "double")
456  outPixType = ImagePixelType_double;
457  else
458  {
459  return WRONGPARAMETERVALUE;
460  }
461  dynamic_cast<OutputImageParameter *> (param.GetPointer())->SetPixelType(outPixType);
462  }
463  else
464  if (values.size() != 1 && values.size() != 2)
465  {
466  std::cerr << "ERROR: Invalid number of value for: \"" << paramKey
467  << "\", invalid number of values " << values.size() << std::endl;
468  return INVALIDNUMBEROFVALUE;
469  }
470  }
471  else
472  if (type == ParameterType_ListView)
473  {
474  dynamic_cast<ListViewParameter *> (param.GetPointer())->SetSelectedNames(values);
475  }
476  else
477  if(values.size() != 1)
478  {
479  // Handle space in filename. Only for input
480  // files or directories
481  if (type == ParameterType_Directory || type == ParameterType_InputFilename ||
484  {
485  for(unsigned int i=1; i<values.size(); i++)
486  {
487  values[0].append(" ");
488  values[0].append(values[i]);
489  }
490  }
491  else if (!param->GetAutomaticValue())
492  {
493  std::cerr << "ERROR: Invalid number of value for: \"" << paramKey << "\", must have 1 value, not "
494  << values.size() << std::endl;
495  return INVALIDNUMBEROFVALUE;
496  }
497  }
498  // Single value parameter
499  if (type == ParameterType_Choice || type == ParameterType_Float || type == ParameterType_Int ||
505  type == ParameterType_OutputProcessXML) // || type == ParameterType_InputProcessXML)
506  {
507  m_Application->SetParameterString(paramKey, values[0]);
508  }
509  else
510  if (type == ParameterType_Empty)
511  {
512  if (values[0] == "1" || values[0] == "true")
513  {
514  dynamic_cast<EmptyParameter *> (param.GetPointer())->SetActive(true);
515  }
516  else
517  if (values[0] == "0" || values[0] == "false")
518  {
519  dynamic_cast<EmptyParameter *> (param.GetPointer())->SetActive(false);
520  }
521  else
522  {
523  std::cerr << "ERROR: Wrong parameter value: " << paramKey << std::endl;
524  return WRONGPARAMETERVALUE;
525  }
526  }
527  // Update the flag UserValue
528  param->SetUserValue(true);
529  // Call the DoUpdateParameter to update dependant params
530  m_Application->UpdateParameters();
531  }
532  }
533 
534  // When a parameter is mandatory :
535  // it must be set if :
536  // - The param is root
537  // - The param is not root and belonging to a Mandatory Group
538  // wich is activated
539  bool mustBeSet = false;
540  const bool hasValue = m_Application->HasValue(paramKey);
541 
542  //skip if mandatory parameters are missing because we have it already in XML
543  if(!paramInXMLExists)
544  {
545  if( param->GetMandatory() == true && param->GetRole() != Role_Output && type != ParameterType_Group)
546  {
547  // check if the parameter is linked to a root parameter with a chain of active parameters
548  if( param->IsRoot() || param->GetRoot()->IsRoot())
549  {
550  // the parameter is a root or inside a group at root level
551  mustBeSet = true;
552  }
553  else
554  {
555  Parameter* currentParam = param->GetRoot();
556  while (!currentParam->IsRoot())
557  {
558  if (!currentParam->GetActive())
559  {
560  // the missing parameter is not on an active branch : we can ignore it
561  break;
562  }
563  currentParam = currentParam->GetRoot();
564 
565  if (currentParam->IsRoot())
566  {
567  // the missing parameter is on an active branch : we need it
568  mustBeSet = true;
569  }
570  }
571  }
572  }
573  }
574 
575  if( mustBeSet )
576  {
577  if (!paramExists)
578  {
579  // If key doesn't exist and parameter hasn't default value set...
580  if (!hasValue)
581  {
582  std::cerr << "ERROR: Missing mandatory parameter: " << paramKey << " " << m_Application->HasValue(paramKey)
583  << std::endl;
585  }
586  }
587  else
588  {
589  values = m_Parser->GetAttribut(std::string("-").append(paramKey), m_Expression);
590  if (values.size() == 0 && !m_Application->HasValue(paramKey))
591  {
592  std::cerr << "ERROR: Missing mandatory parameter: " << paramKey << std::endl;
593  return MISSINGPARAMETERVALUE;
594  }
595  }
596  }
597  // Check if non mandatory parameter have values
598  else
599  {
600  if( paramExists )
601  {
602  values = m_Parser->GetAttribut(std::string("-").append(paramKey), m_Expression);
603  if (values.size() == 0)
604  {
605  std::cerr << "ERROR: Missing non-mandatory parameter: " << paramKey << std::endl;
606  return MISSINGPARAMETERVALUE;
607  }
608  }
609  }
610  }
611 
612  return OKPARAM;
613 }
614 
616 {
617  // Report the progress only if asked
618  if (m_ReportProgress)
619  {
620 
621  if (typeid(otb::Wrapper::AddProcessToWatchEvent) == typeid( event ))
622  {
623  const AddProcessToWatchEvent* eventToWatch = dynamic_cast<const AddProcessToWatchEvent*> (&event);
624 
626  eventToWatch->GetProcessDescription());
627  m_WatcherList.push_back(watch);
628  }
629  }
630 }
631 
633 {
634  std::cerr << "This is the "<<m_Application->GetName() << " application, version " << OTB_VERSION_STRING <<std::endl;
635 
636  std::cerr << m_Application->GetDescription() << std::endl;
637  std::cerr<<std::endl;
638  std::string link = "http://www.orfeo-toolbox.org/Applications/";
639  link.append(m_Application->GetName());
640  link.append(".html");
641 
642  std::cerr << "Complete documentation: " << link << std::endl;
643  std::cerr<<std::endl;
644  std::cerr << "Parameters: " << std::endl;
645 
646  const std::vector<std::string> appKeyList = m_Application->GetParametersKeys(true);
647  const unsigned int nbOfParam = appKeyList.size();
648 
649  m_MaxKeySize = std::string("progress").size();
650  for (unsigned int i = 0; i < nbOfParam; i++)
651  {
652  if (m_Application->GetParameterRole(appKeyList[i]) != Role_Output)
653  {
654  if( m_MaxKeySize < appKeyList[i].size() )
655  m_MaxKeySize = appKeyList[i].size();
656  }
657  }
658 
660  std::string bigKey = "progress";
661  for(unsigned int i=0; i<m_MaxKeySize-std::string("progress").size(); i++)
662  bigKey.append(" ");
663 
664  std::cerr << " -"<<bigKey<<" <boolean> Report progress " << std::endl;
665 
666  for (unsigned int i = 0; i < nbOfParam; i++)
667  {
668  Parameter::Pointer param = m_Application->GetParameterByKey(appKeyList[i]);
669  if (param->GetRole() != Role_Output)
670  {
671  std::cerr << this->DisplayParameterHelp(param, appKeyList[i]);
672  }
673  }
674 
675  std::cerr<<std::endl;
676  //std::string cl(m_Application->GetCLExample());
677 
678  std::cerr << "Examples: " << std::endl;
679  std::cerr << m_Application->GetCLExample() << std::endl;
680 
681 }
682 
683 
685 {
686  //Set seed for rand and itk mersenne twister
687  //srand(1);
688  // itk::Statistics::MersenneTwisterRandomVariateGenerator::GetInstance()->SetSeed(121212);
689 }
690 
691 
692 std::string CommandLineLauncher::DisplayParameterHelp(const Parameter::Pointer & param, const std::string paramKey)
693 {
694  // Display the type the type
695  ParameterType type = m_Application->GetParameterType(paramKey);
696 
697  // Discard Group parameters (they don't need a value)
698  if (type == ParameterType_Group)
699  {
700  return "";
701  }
702 
703  std::ostringstream oss;
704 
705  // When a parameter is mandatory :
706  // it must be set if :
707  // - The param is root
708  // - The param is not root and belonging to a Mandatory Group
709  // wich is activated
710  bool isMissing = false;
711  if (!m_Parser->IsAttributExists(std::string("-").append(paramKey), m_Expression))
712  {
713  if (!m_Application->HasValue(paramKey))
714  {
715  if( param->GetMandatory() && param->GetRole() != Role_Output )
716  {
717  if( param->IsRoot() || param->GetRoot()->IsRoot())
718  {
719  // the parameter is a root or inside a group at root level
720  isMissing = true;
721  }
722  else
723  {
724  Parameter* currentParam = param->GetRoot();
725  while (!currentParam->IsRoot())
726  {
727  if (!currentParam->GetActive())
728  {
729  // the missing parameter is not on an active branch : we can ignore it
730  break;
731  }
732  currentParam = currentParam->GetRoot();
733 
734  if (currentParam->IsRoot())
735  {
736  // the missing parameter is on an active branch : we need it
737  isMissing = true;
738  }
739  }
740  }
741  }
742  }
743  }
744 
745  if( isMissing )
746  {
747  oss << "MISSING ";
748  }
749  else
750  {
751  oss << " ";
752  }
753 
754  std::string bigKey = paramKey;
755  for(unsigned int i=0; i<m_MaxKeySize-paramKey.size(); i++)
756  bigKey.append(" ");
757 
758  oss<< "-" << bigKey << " ";
759 
760  // Display the type the parameter
761  if (type == ParameterType_Radius || type == ParameterType_Int || type == ParameterType_RAM)
762  {
763  oss << "<int32> ";
764  }
765  else if (type == ParameterType_Empty )
766  {
767  oss << "<boolean> ";
768  }
769  else if (type == ParameterType_Float)
770  {
771  oss << "<float> ";
772  }
775  type == ParameterType_String || type == ParameterType_Choice )
776  {
777  oss << "<string> ";
778  }
779  else if (type == ParameterType_OutputImage)
780  {
781  oss << "<string> [pixel]";
782  }
785  type == ParameterType_StringList )
786  {
787  oss << "<string list> ";
788  }
789  else
790  itkExceptionMacro("Not handled parameter type.");
791 
792 
793  oss<< " " << param->GetName() << " ";
794 
795  if (type == ParameterType_OutputImage)
796  {
797  oss << " [pixel=uint8/uint16/int16/uint32/int32/float/double]";
798  oss << " (default value is float)";
799  }
800 
801 
802  if (type == ParameterType_Choice)
803  {
804  std::vector<std::string> keys = dynamic_cast<ChoiceParameter*>(param.GetPointer())->GetChoiceKeys();
805  std::vector<std::string> names = dynamic_cast<ChoiceParameter*>(param.GetPointer())->GetChoiceNames();
806 
807  oss << "[";
808  for(unsigned int i=0; i<keys.size(); i++)
809  {
810  oss<<keys[i];
811  if( i != keys.size()-1 )
812  oss << "/";
813  }
814 
815  oss << "]";
816  }
817 
818  if(m_Application->IsMandatory(paramKey))
819  {
820  oss<<" (mandatory";
821  }
822  else
823  {
824  oss<<" (optional";
825 
826  if(m_Application->IsParameterEnabled(paramKey))
827  {
828  oss<<", on by default";
829  }
830  else
831  {
832  oss<<", off by default";
833  }
834  }
835 
836  if(m_Application->HasValue(paramKey))
837  {
838  oss<<", default value is "<<m_Application->GetParameterAsString(paramKey);
839  }
840  oss<<")";
841 
842  oss << std::endl;
843  return oss.str();
844 }
845 
847 {
848  bool res = true;
849  // Extract expression keys
850  std::vector<std::string> keyList = m_Parser->GetKeyList(m_Expression);
851 
852  // Check Unicity
853  for (unsigned int i = 0; i < keyList.size(); i++)
854  {
855  std::vector<std::string> listTmp = keyList;
856  const std::string keyRef = keyList[i];
857  listTmp.erase(listTmp.begin() + i);
858  for (unsigned int j = 0; j < listTmp.size(); j++)
859  {
860  if (keyRef == listTmp[j])
861  {
862  res = false;
863  break;
864  }
865  }
866  if (!res)
867  break;
868  }
869 
870  return res;
871 }
872 
874 {
875  bool res = true;
876  // Check if the chain " --" appears in the expression, could be a common mistake
877  if (m_Expression.find(" --") != std::string::npos )
878  {
879  res = false;
880  }
881 
882  return res;
883 }
884 
885 bool CommandLineLauncher::CheckKeyValidity(std::string& refKey)
886 {
887  bool res = true;
888  // Extract expression keys
889  std::vector<std::string> expKeyList = m_Parser->GetKeyList(m_Expression);
890 
891  // Extract application keys
892  std::vector<std::string> appKeyList = m_Application->GetParametersKeys(true);
893  appKeyList.push_back("help");
894  appKeyList.push_back("progress");
895  appKeyList.push_back("testenv");
896  appKeyList.push_back("version");
897 
898  // Check if each key in the expression exists in the application
899  for (unsigned int i = 0; i < expKeyList.size(); i++)
900  {
901  refKey = expKeyList[i];
902  bool keyExist = false;
903  for (unsigned int j = 0; j < appKeyList.size(); j++)
904  {
905  if (refKey == appKeyList[j])
906  {
907  keyExist = true;
908  break;
909  }
910  }
911  if (keyExist == false)
912  {
913  res = false;
914  break;
915  }
916  }
917 
918  return res;
919 }
920 
922 {
923  std::vector< std::pair<std::string, std::string> > paramList;
924  paramList = m_Application->GetOutputParametersSumUp();
925  if( paramList.size() == 0 )
926  return;
927 
928  std::ostringstream oss;
929  for( unsigned int i=0; i<paramList.size(); i++)
930  {
931  oss << paramList[i].first;
932  oss << ": ";
933  oss << paramList[i].second;
934  oss << std::endl;
935  }
936 
937 
938  if ( m_Parser->IsAttributExists("-testenv", m_Expression) )
939  {
940  std::vector<std::string> val = m_Parser->GetAttribut("-testenv", m_Expression);
941  if( val.size() == 1 )
942  {
943  std::ofstream ofs(val[0].c_str());
944  if (!ofs.is_open())
945  {
946  fprintf(stderr, "Error, can't open file");
947  itkExceptionMacro( << "Error, can't open file "<<val[0]<<".");
948  }
949  ofs << oss.str();
950  ofs.close();
951  }
952  }
953 
954  std::cout << "Output parameters value:" << std::endl;
955  std::cout << oss.str() << std::endl;
956 }
957 
958 }
959 }

Generated at Sat Mar 8 2014 16:28:48 for Orfeo Toolbox with doxygen 1.8.3.1