62 #include <visp/vpImage.h>
63 #include <visp/vpImageIo.h>
64 #include <visp/vpParseArgv.h>
65 #include <visp/vpIoTools.h>
66 #include <visp/vpDebug.h>
70 #define GETOPTARGS "i:o:h"
83 void usage(
const char *name,
const char *badparam, std::string ipath, std::string opath, std::string user)
86 Read and write PGM images on the disk. Also test exceptions.\n\
89 %s [-i <input image path>] [-o <output image path>]\n\
95 -i <input image path> %s\n\
96 Set image input path.\n\
97 From this path read \"ViSP-images/Klimt/Klimt.pgm\"\n\
99 Setting the VISP_INPUT_IMAGE_PATH environment\n\
100 variable produces the same behaviour than using\n\
103 -o <output image path> %s\n\
104 Set image output path.\n\
105 From this directory, creates the \"%s\"\n\
106 subdirectory depending on the username, where \n\
107 Klimt_grey.pgm output image is written.\n\
110 Print the help.\n\n",
111 ipath.c_str(), opath.c_str(), user.c_str());
114 fprintf(stderr,
"ERROR: \n" );
115 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
130 bool getOptions(
int argc,
const char **argv,
131 std::string &ipath, std::string &opath, std::string user)
138 case 'i': ipath = optarg;
break;
139 case 'o': opath = optarg;
break;
140 case 'h': usage(argv[0], NULL, ipath, opath, user);
return false;
break;
143 usage(argv[0], optarg, ipath, opath, user);
return false;
break;
147 if ((c == 1) || (c == -1)) {
149 usage(argv[0], NULL, ipath, opath, user);
150 std::cerr <<
"ERROR: " << std::endl;
151 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
161 main(
int argc,
const char ** argv)
164 std::string env_ipath;
165 std::string opt_ipath;
166 std::string opt_opath;
169 std::string filename;
170 std::string username;
172 std::cout <<
"-------------------------------------------------------" << std::endl ;
173 std::cout <<
" imageDiskRW.cpp" <<std::endl << std::endl ;
175 std::cout <<
" reading and writting of PPM image" << std::endl ;
176 std::cout <<
" read an image that does not exist" << std::endl ;
177 std::cout <<
" write in a directory that does no exist" << std::endl ;
178 std::cout <<
"-------------------------------------------------------" << std::endl ;
179 std::cout << std::endl ;
183 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
188 if (! env_ipath.empty())
192 #if defined(UNIX) && !defined(WIN32)
195 opt_opath =
"C:\\temp";
202 if (getOptions(argc, argv, opt_ipath, opt_opath, username) ==
false) {
207 if (!opt_ipath.empty())
209 if (!opt_opath.empty())
222 usage(argv[0], NULL, ipath, opath, username);
223 std::cerr << std::endl
224 <<
"ERROR:" << std::endl;
225 std::cerr <<
" Cannot create " << dirname << std::endl;
226 std::cerr <<
" Check your -o " << opath <<
" option " << std::endl;
233 if (!opt_ipath.empty() && !env_ipath.empty()) {
234 if (ipath != env_ipath) {
235 std::cout << std::endl
236 <<
"WARNING: " << std::endl;
237 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
238 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
239 <<
" we skip the environment variable." << std::endl;
244 if (opt_ipath.empty() && env_ipath.empty()){
245 usage(argv[0], NULL, ipath, opath, username);
246 std::cerr << std::endl
247 <<
"ERROR:" << std::endl;
248 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
250 <<
" environment variable to specify the location of the " << std::endl
251 <<
" image path where test images are located." << std::endl << std::endl;
280 filename = ipath +
vpIoTools::path(
"/ViSP-images/image-that-does-not-exist.ppm");
287 std::cout << e << std::endl ;
294 filename = dirname +
vpIoTools::path(
"/directory-that-does-not-exist/Klimt.ppm");
300 std::cout << e << std::endl ;
303 std::cout <<
"----------------------------------------------------" << std::endl ;
321 filename = ipath +
vpIoTools::path(
"/ViSP-images/image-that-does-not-exist.ppm");
327 std::cout << e << std::endl ;
333 filename = dirname +
vpIoTools::path(
"/directory-that-does-not-exist/Klimt.ppm");
339 std::cout << e << std::endl ;
static void write(const vpImage< unsigned char > &I, const char *filename)
Error that can be emited by the vpImage class and its derivates.
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
static void read(vpImage< unsigned char > &I, const char *filename)