49 #include <visp/vpRobust.h>
52 #include <visp/vpIoTools.h>
53 #include <visp/vpParseArgv.h>
58 #define GETOPTARGS "ho:"
60 void usage(
const char *name,
const char *badparam, std::string ofilename);
61 bool getOptions(
int argc,
const char **argv, std::string &ofilename);
71 void usage(
const char *name,
const char *badparam, std::string ofilename)
74 Test some vpMath functionalities. Compute weights and print\n\
75 them in an output file.\n\
77 Using gnuplot the content of the output file can be printed by:\n\
78 set style data line\n\
79 set ylabel \"weight\"\n\
81 set xlabel \"Normalized residuals\"\n\
82 plot '%s' title \"Tukey Estimator\" lw 2, 1 title \"Least-Squares\" lw 2\n\
86 %s [-o <output filename>] [-h]\n", ofilename.c_str(), name);
90 -o <output filename> %s\n\
91 Name and path of the file containing computed \n\
99 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
111 bool getOptions(
int argc,
const char **argv, std::string &ofilename)
118 case 'o': ofilename = optarg_;
break;
119 case 'h': usage(argv[0], NULL, ofilename);
return false;
break;
122 usage(argv[0], optarg_, ofilename);
127 if ((c == 1) || (c == -1)) {
129 usage(argv[0], NULL, ofilename);
130 std::cerr <<
"ERROR: " << std::endl;
131 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
141 main(
int argc,
const char ** argv)
144 std::string ofilename;
145 std::string username;
149 ofilename =
"C:/temp";
158 ofilename = ofilename +
"/" + username;
167 usage(argv[0], NULL, ofilename);
168 std::cerr << std::endl
169 <<
"ERROR:" << std::endl;
170 std::cerr <<
" Cannot create " << ofilename << std::endl;
171 std::cerr <<
" Check your -o " << ofilename <<
" option " << std::endl;
177 ofilename = ofilename +
"/w.dat";
180 if (getOptions(argc, argv, ofilename) ==
false) {
188 std::cout <<
"Create file: " << ofilename << std::endl;
189 f.open(ofilename.c_str());
191 usage(argv[0], NULL, ofilename);
192 std::cerr << std::endl
193 <<
"ERROR:" << std::endl;
194 std::cerr <<
" Cannot create the file: " << ofilename << std::endl;
195 std::cerr <<
" Check your -o " << ofilename <<
" option " << std::endl;
202 if (fabs(x/sig)<=(4.6851))
210 f << x <<
" "<<w <<std::endl ;
216 std::cout <<
"Catch an exception: " << e << std::endl;
error that can be emited by ViSP classes.
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
static double sqr(double x)