45 #include <visp3/core/vpIoTools.h>
46 #include <visp3/core/vpRobust.h>
47 #include <visp3/io/vpParseArgv.h>
49 #define GETOPTARGS "cdho:"
51 #ifdef ENABLE_VISP_NAMESPACE
55 void usage(
const char *name,
const char *badparam, std::string ofilename);
56 bool getOptions(
int argc,
const char **argv, std::string &ofilename);
66 void usage(
const char *name,
const char *badparam, std::string ofilename)
69 Test some vpMath functionalities. Compute weights and print\n\
70 them in an output file.\n\
72 Using gnuplot the content of the output file can be printed by:\n\
73 set style data line\n\
74 set ylabel \"weight\"\n\
76 set xlabel \"Normalized residuals\"\n\
77 plot '%s' title \"Tukey Estimator\" lw 2, 1 title \"Least-Squares\" lw 2\n\
81 %s [-o <output filename>] [-h]\n",
82 ofilename.c_str(), name);
86 -o <output filename> %s\n\
87 Name and path of the file containing computed \n\
95 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
107 bool getOptions(
int argc,
const char **argv, std::string &ofilename)
118 usage(argv[0],
nullptr, ofilename);
126 usage(argv[0], optarg_, ofilename);
132 if ((c == 1) || (c == -1)) {
134 usage(argv[0],
nullptr, ofilename);
135 std::cerr <<
"ERROR: " << std::endl;
136 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
143 int main(
int argc,
const char **argv)
146 std::string ofilename;
147 std::string username;
151 ofilename =
"C:/temp";
160 ofilename = ofilename +
"/" + username;
169 usage(argv[0],
nullptr, ofilename);
170 std::cerr << std::endl <<
"ERROR:" << std::endl;
171 std::cerr <<
" Cannot create " << ofilename << std::endl;
172 std::cerr <<
" Check your -o " << ofilename <<
" option " << std::endl;
178 ofilename = ofilename +
"/w.dat";
181 if (getOptions(argc, argv, ofilename) ==
false) {
189 std::cout <<
"Create file: " << ofilename << std::endl;
190 f.open(ofilename.c_str());
192 usage(argv[0],
nullptr, ofilename);
193 std::cerr << std::endl <<
"ERROR:" << std::endl;
194 std::cerr <<
" Cannot create the file: " << ofilename << std::endl;
195 std::cerr <<
" Check your -o " << ofilename <<
" option " << std::endl;
200 if (fabs(x / sig) <= (4.6851)) {
206 f << x <<
" " << w << std::endl;
212 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)