49 #include <visp/vpRobust.h>
52 #include <visp/vpIoTools.h>
53 #include <visp/vpParseArgv.h>
58 #define GETOPTARGS "ho:"
68 void usage(
const char *name,
const char *badparam, std::string ofilename)
71 Test some vpMath functionalities. Compute weights and print\n\
72 them in an output file.\n\
74 Using gnuplot the content of the output file can be printed by:\n\
75 set style data line\n\
76 set ylabel \"weight\"\n\
78 set xlabel \"Normalized residuals\"\n\
79 plot '%s' title \"Tukey Estimator\" lw 2, 1 title \"Least-Squares\" lw 2\n\
83 %s [-o <output filename>] [-h]\n", ofilename.c_str(), name);
87 -o <output filename> %s\n\
88 Name and path of the file containing computed \n\
96 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
108 bool getOptions(
int argc,
const char **argv, std::string &ofilename)
115 case 'o': ofilename = optarg;
break;
116 case 'h': usage(argv[0], NULL, ofilename);
return false;
break;
119 usage(argv[0], optarg, ofilename);
124 if ((c == 1) || (c == -1)) {
126 usage(argv[0], NULL, ofilename);
127 std::cerr <<
"ERROR: " << std::endl;
128 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
138 main(
int argc,
const char ** argv)
140 std::string ofilename;
141 std::string username;
145 ofilename =
"C:/temp";
154 ofilename = ofilename +
"/" + username;
163 usage(argv[0], NULL, ofilename);
164 std::cerr << std::endl
165 <<
"ERROR:" << std::endl;
166 std::cerr <<
" Cannot create " << ofilename << std::endl;
167 std::cerr <<
" Check your -o " << ofilename <<
" option " << std::endl;
173 ofilename = ofilename +
"/w.dat";
176 if (getOptions(argc, argv, ofilename) ==
false) {
184 std::cout <<
"Create file: " << ofilename << std::endl;
185 f.open(ofilename.c_str());
187 usage(argv[0], NULL, ofilename);
188 std::cerr << std::endl
189 <<
"ERROR:" << std::endl;
190 std::cerr <<
" Cannot create the file: " << ofilename << std::endl;
191 std::cerr <<
" Check your -o " << ofilename <<
" option " << std::endl;
198 if (fabs(x/sig)<=(4.6851))
206 f << x <<
" "<<w <<std::endl ;
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
static double sqr(double x)