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