47 #include <visp3/core/vpIoTools.h>
48 #include <visp3/core/vpRobust.h>
49 #include <visp3/io/vpParseArgv.h>
51 #define GETOPTARGS "cdho:"
53 void usage(
const char *name,
const char *badparam, std::string ofilename);
54 bool getOptions(
int argc,
const char **argv, std::string &ofilename);
64 void usage(
const char *name,
const char *badparam, std::string ofilename)
67 Test some vpMath functionalities. Compute weights and print\n\
68 them in an output file.\n\
70 Using gnuplot the content of the output file can be printed by:\n\
71 set style data line\n\
72 set ylabel \"weight\"\n\
74 set xlabel \"Normalized residuals\"\n\
75 plot '%s' title \"Tukey Estimator\" lw 2, 1 title \"Least-Squares\" lw 2\n\
79 %s [-o <output filename>] [-h]\n",
80 ofilename.c_str(), name);
84 -o <output filename> %s\n\
85 Name and path of the file containing computed \n\
93 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
105 bool getOptions(
int argc,
const char **argv, std::string &ofilename)
116 usage(argv[0],
nullptr, ofilename);
124 usage(argv[0], optarg_, ofilename);
130 if ((c == 1) || (c == -1)) {
132 usage(argv[0],
nullptr, ofilename);
133 std::cerr <<
"ERROR: " << std::endl;
134 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
141 int main(
int argc,
const char **argv)
144 std::string ofilename;
145 std::string username;
149 ofilename =
"C:/temp";
158 ofilename = ofilename +
"/" + username;
166 usage(argv[0],
nullptr, ofilename);
167 std::cerr << std::endl <<
"ERROR:" << std::endl;
168 std::cerr <<
" Cannot create " << ofilename << std::endl;
169 std::cerr <<
" Check your -o " << ofilename <<
" option " << std::endl;
175 ofilename = ofilename +
"/w.dat";
178 if (getOptions(argc, argv, ofilename) ==
false) {
186 std::cout <<
"Create file: " << ofilename << std::endl;
187 f.open(ofilename.c_str());
189 usage(argv[0],
nullptr, ofilename);
190 std::cerr << std::endl <<
"ERROR:" << std::endl;
191 std::cerr <<
" Cannot create the file: " << ofilename << std::endl;
192 std::cerr <<
" Check your -o " << ofilename <<
" option " << std::endl;
197 if (fabs(x / sig) <= (4.6851)) {
202 f << x <<
" " << w << std::endl;
207 std::cout <<
"Catch an exception: " << e << std::endl;
error that can be emitted by ViSP classes.
static double sqr(double x)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)