58 #include <visp3/core/vpImage.h>
59 #include <visp3/io/vpImageIo.h>
60 #include <visp3/io/vpParseArgv.h>
61 #include <visp3/core/vpIoTools.h>
62 #include <visp3/core/vpDebug.h>
66 #define GETOPTARGS "i:o:h"
68 void usage(
const char *name,
const char *badparam, std::string ipath, std::string opath, std::string user);
69 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath, std::string user);
82 void usage(
const char *name,
const char *badparam, std::string ipath, std::string opath, std::string user)
85 Read and write PGM images on the disk. Also test exceptions.\n\
88 %s [-i <input image path>] [-o <output image path>]\n\
94 -i <input image path> %s\n\
95 Set image input path.\n\
96 From this path read \"ViSP-images/Klimt/Klimt.pgm\"\n\
98 Setting the VISP_INPUT_IMAGE_PATH environment\n\
99 variable produces the same behaviour than using\n\
102 -o <output image path> %s\n\
103 Set image output path.\n\
104 From this directory, creates the \"%s\"\n\
105 subdirectory depending on the username, where \n\
106 Klimt_grey.pgm output image is written.\n\
109 Print the help.\n\n",
110 ipath.c_str(), opath.c_str(), user.c_str());
113 fprintf(stderr,
"ERROR: \n" );
114 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
129 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath, std::string user)
136 case 'i': ipath = optarg_;
break;
137 case 'o': opath = optarg_;
break;
138 case 'h': usage(argv[0], NULL, ipath, opath, user);
return false;
break;
141 usage(argv[0], optarg_, ipath, opath, user);
return false;
break;
145 if ((c == 1) || (c == -1)) {
147 usage(argv[0], NULL, ipath, opath, user);
148 std::cerr <<
"ERROR: " << std::endl;
149 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
159 main(
int argc,
const char ** argv)
162 std::string env_ipath;
163 std::string opt_ipath;
164 std::string opt_opath;
167 std::string filename;
168 std::string username;
170 std::cout <<
"-------------------------------------------------------" << std::endl ;
171 std::cout <<
" imageDiskRW.cpp" <<std::endl << std::endl ;
173 std::cout <<
" reading and writting of PPM image" << std::endl ;
174 std::cout <<
" read an image that does not exist" << std::endl ;
175 std::cout <<
" write in a directory that does no exist" << std::endl ;
176 std::cout <<
"-------------------------------------------------------" << std::endl ;
177 std::cout << std::endl ;
183 if (! env_ipath.empty())
187 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
189 #elif defined(_WIN32)
190 opt_opath =
"C:\\temp";
197 if (getOptions(argc, argv, opt_ipath, opt_opath, username) ==
false) {
202 if (!opt_ipath.empty())
204 if (!opt_opath.empty())
217 usage(argv[0], NULL, ipath, opath, username);
218 std::cerr << std::endl
219 <<
"ERROR:" << std::endl;
220 std::cerr <<
" Cannot create " << dirname << std::endl;
221 std::cerr <<
" Check your -o " << opath <<
" option " << std::endl;
228 if (!opt_ipath.empty() && !env_ipath.empty()) {
229 if (ipath != env_ipath) {
230 std::cout << std::endl
231 <<
"WARNING: " << std::endl;
232 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
233 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
234 <<
" we skip the environment variable." << std::endl;
239 if (opt_ipath.empty() && env_ipath.empty()){
240 usage(argv[0], NULL, ipath, opath, username);
241 std::cerr << std::endl
242 <<
"ERROR:" << std::endl;
243 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
245 <<
" environment variable to specify the location of the " << std::endl
246 <<
" image path where test images are located." << std::endl << std::endl;
274 std::cout <<
"Catch an exception: " << e << std::endl;
284 std::cout <<
"Catch an exception: " << e << std::endl;
288 std::cout <<
"----------------------------------------------------" << std::endl ;
309 std::cout <<
"Catch an exception: " << e << std::endl;
319 std::cout <<
"Catch an exception: " << e << std::endl;
324 std::cout <<
"Catch an exception: " << e << std::endl;
static void write(const vpImage< unsigned char > &I, const char *filename)
error that can be emited by ViSP classes.
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
static void read(vpImage< unsigned char > &I, const char *filename)