59 #include <visp3/core/vpDebug.h>
60 #include <visp3/core/vpImage.h>
61 #include <visp3/core/vpIoTools.h>
62 #include <visp3/io/vpImageIo.h>
63 #include <visp3/io/vpParseArgv.h>
65 #define GETOPTARGS "i:o:h"
78 void usage(
const char *name,
const char *badparam, std::string ipath, std::string opath, std::string user)
81 Read and write PGM images on the disk. Also test exceptions.\n\
84 %s [-i <input image path>] [-o <output image path>]\n\
90 -i <input image path> %s\n\
91 Set image input path.\n\
92 From this path read \"Klimt/Klimt.pgm\"\n\
94 Setting the VISP_INPUT_IMAGE_PATH environment\n\
95 variable produces the same behaviour than using\n\
98 -o <output image path> %s\n\
99 Set image output path.\n\
100 From this directory, creates the \"%s\"\n\
101 subdirectory depending on the username, where \n\
102 Klimt_grey.pgm output image is written.\n\
105 Print the help.\n\n", ipath.c_str(), opath.c_str(), user.c_str());
108 fprintf(stderr,
"ERROR: \n");
109 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
124 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath,
const std::string &user)
138 usage(argv[0], NULL, ipath, opath, user);
143 usage(argv[0], optarg_, ipath, opath, user);
149 if ((c == 1) || (c == -1)) {
151 usage(argv[0], NULL, ipath, opath, user);
152 std::cerr <<
"ERROR: " << std::endl;
153 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
160 int main(
int argc,
const char **argv)
163 std::string env_ipath;
164 std::string opt_ipath;
165 std::string opt_opath;
168 std::string filename;
169 std::string username;
171 std::cout <<
"-------------------------------------------------------" << std::endl;
172 std::cout <<
" imageDiskRW.cpp" << std::endl << std::endl;
174 std::cout <<
" reading and writting of PPM image" << std::endl;
175 std::cout <<
" read an image that does not exist" << std::endl;
176 std::cout <<
" write in a directory that does no exist" << std::endl;
177 std::cout <<
"-------------------------------------------------------" << std::endl;
178 std::cout << std::endl;
185 if (!env_ipath.empty())
189 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
191 #elif defined(_WIN32)
192 opt_opath =
"C:\\temp";
199 if (getOptions(argc, argv, opt_ipath, opt_opath, username) ==
false) {
204 if (!opt_ipath.empty())
206 if (!opt_opath.empty())
218 usage(argv[0], NULL, ipath, opath, username);
219 std::cerr << std::endl <<
"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 <<
"WARNING: " << std::endl;
231 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
232 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
233 <<
" we skip the environment variable." << std::endl;
238 if (opt_ipath.empty() && env_ipath.empty()) {
239 usage(argv[0], NULL, ipath, opath, username);
240 std::cerr << std::endl <<
"ERROR:" << std::endl;
241 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
242 <<
" environment variable to specify the location of the " << std::endl
243 <<
" image path where test images are located." << std::endl
272 std::cout <<
"Catch an expected exception: " << e << std::endl;
281 std::cout <<
"Catch an expected exception: " << e << std::endl;
284 std::cout <<
"----------------------------------------------------" << std::endl;
304 std::cout <<
"Catch an expected exception: " << e << std::endl;
313 std::cout <<
"Catch an expected exception: " << e << std::endl;
317 std::cout <<
"Catch an unexpected exception: " << e << std::endl;