Dear All,<br><br>I am trying to read command-line argument using ITK's <metaCommand.h>.<br>I have problems in setting default values for a LIST. <br>Even though I am setting default values using AddOptionField(), it's not taking those values.<br>
<br>Here is the code for a toy-example that reproduces my problem:<br><br>When the command-line input to the following program is:<br>example.exe -l 3 10 20 30<br>I got the output as expected, and is:<br>Input Image Name:input.mhd<br>
Number of labels: 3<br>Label Value: 10<br>Label Value: 20<br>Label Value: 30<br><br><br>When I call the same executable with no arguments, the output is:<br>Input Image Name:input.mhd<br>Number of labels: 0<br><br>However, the output that I was expecting is:<br>
Input Image Name:input.mhd<br>
Number of labels: 4<br>
Label Value: 10<br>
Label Value: 20<br>
Label Value: 30<br>
Label Value: 40<br>
<br>Is this a bug? or, am I doing some mistake here in setting default values for a list?<br><br>Thank you in advance for your help.<br><br>Warm Regards,<br>Subrahmanyam Gorthi.<br><br><br>//----------------------------------------------------------------------------- <br>
#include<iostream><br>#include<string><br>#include<list><br>#include "metaCommand.h"<br><br>int main( int argc, char* argv[] )<br>{<br> MetaCommand command;<br><br> // Input file name...<br>
// By default, set input file name to: input.mhd<br>
command.SetOption("inputFile", "i", false, "Input file");<br> command.AddOptionField("inputFile", "fileName1",<br> MetaCommand::STRING, true, "input.mhd");<br>
<br> // Label Values...<br> // By default, take 4 labels, and set their values to: 10, 20, 30, 40<br> command.SetOption("labelValues", "l", false, "List of label values");<br> command.AddOptionField("labelValues", "labelList1",<br>
MetaCommand::LIST, true, "4 10 20 30 40");<br><br> // Now, Parse the command line<br> if (!command.Parse(argc,argv))<br> {<br> std::cerr << "Error in parsing the input arguments!" << std::endl; <br>
exit( EXIT_FAILURE );<br> }<br><br> // Printing the argument values...<br> std::string inputImageFile=command.GetValueAsString("inputFile", "fileName1");<br> std::cout << "Input Image Name:" << inputImageFile << std::endl;<br>
<br> std::list<std::string> listOfLables;<br> listOfLables.clear();<br><br> listOfLables = command.GetValueAsList("labelValues");<br> int numLabels = listOfLables.size();<br><br> std::cout << "Number of labels: " << numLabels << std::endl;<br>
<br> typedef std::list<std::string>::const_iterator LabelValuesIterator;<br> LabelValuesIterator labelValuesItr;<br><br> for(labelValuesItr = listOfLables.begin();<br> labelValuesItr != listOfLables.end(); ++labelValuesItr)<br>
{<br> std::cout << "Label Value: " << *labelValuesItr << std::endl; <br> }<br><br> return EXIT_SUCCESS;<br>}<br>//----------------------------------------------------------------------------- <br>