19 using namespace navfn;
22 # include <netpbm/pgm.h>
39 gettimeofday(&t0,NULL);
40 double ret = t0.tv_sec * 1000.0;
41 ret += ((double)t0.tv_usec)*0.001;
56 COSTTYPE *
readPGM(
const char *fname,
int *width,
int *height,
bool raw =
false);
58 int main(
int argc,
char **argv)
65 bool got_start_goal =
false;
66 std::string pgm_file_name;
76 pgm_file_name = std::string( argv[ 1 ]) +
".pgm";
77 std::string txt_file_name = std::string( argv[ 1 ]) +
".txt";
79 std::ifstream txt_stream( txt_file_name.c_str() );
84 for(
int i = 0; i < 2; i++ )
86 txt_stream >> name >> x >> y;
87 if( txt_stream && name ==
"Goal:" )
92 else if( txt_stream && name ==
"Start:" )
98 got_start_goal =
true;
99 printf(
"start is %d, %d, goal is %d, %d.\n",
start[ 0 ],
start[ 1 ],
goal[ 0 ],
goal[ 1 ]);
103 printf(
"Failed to open file %s, assuming you didn't want to open a file.\n", txt_file_name.c_str() );
108 if( !got_start_goal )
114 size = atoi(argv[2]);
120 dispn = atoi(argv[4]);
127 cmap =
readPGM( pgm_file_name.c_str(),&sx,&sy,
true);
130 nav =
new NavFn(sx,sy);
136 sx = (int)((.001 + size) / (res*.001));
138 nav =
new NavFn(sx,sy);
163 printf(
"[NavTest] priority increment: %d\n", inc);
170 memcpy(nav->
costarr,cmap,sx*sy);
181 printf(
"Setup: %d ms Plan: %d ms Total: %d ms\n",
182 (
int)(t1-t0), (
int)(t2-t1), (
int)(t2-t0));
188 for (
int i=0; i<nav->
ny*nav->
nx; i++, pp++)
190 if (*pp < 10e7 && *pp > mmax)
195 printf(
"[NavFn] Cells not touched: %d/%d\n", ntot, nav->
nx*nav->
ny);
198 while (Fl::check()) {
199 if( Fl::event_key(
'q' ))
218 for (
int i=-
CS/2; i<
CS/2; i++)
221 for (
int j=-
CS/2; j<
CS/2; j++)
225 for (
int i=-
CS/2; i<
CS/2; i++)
228 for (
int j=-
CS/2; j<
CS/2; j++)
238 #define unknown_gray 0xCC // seems to be the value of "unknown" in maps
241 readPGM(
const char *fname,
int *width,
int *height,
bool raw)
243 pm_init(
"navtest",0);
246 pgmfile = fopen(fname,
"r");
249 printf(
"[NavTest] Can't find file %s\n", fname);
253 printf(
"[NavTest] Reading costmap file %s\n", fname);
257 pgm_readpgminit(pgmfile, &ncols, &nrows, &maxval, &format);
258 printf(
"[NavTest] Size: %d x %d\n", ncols, nrows);
263 for (
int i=0; i<ncols*nrows; i++)
266 gray * row(pgm_allocrow(ncols));
270 for (
int ii = 0; ii < nrows; ii++) {
271 pgm_readpgmrow(pgmfile, row, ncols, maxval, format);
274 for (
int jj(ncols - 1); jj >= 0; --jj)
277 cmap[ii*ncols+jj] = v;
287 for (
int jj(ncols - 1); jj >= 0; --jj)
304 printf(
"[NavTest] Found %d obstacle cells, %d free cells, %d unknown cells\n", otot, ftot, utot);