From: <mk...@us...> - 2003-07-22 21:17:46
|
Update of /cvsroot/csp/APPLICATIONS/CSPSim/Tools/Terrain/tile In directory sc8-pr-cvs1:/tmp/cvs-serv13782 Modified Files: tile.cpp Log Message: Index: tile.cpp =================================================================== RCS file: /cvsroot/csp/APPLICATIONS/CSPSim/Tools/Terrain/tile/tile.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** tile.cpp 21 Jul 2003 08:04:57 -0000 1.1 --- tile.cpp 22 Jul 2003 21:17:41 -0000 1.2 *************** *** 29,32 **** --- 29,33 ---- #include <SimData/Random.h> #include <SimData/Math.h> + #include <SimData/FileUtility.h> #include <cstdio> #include <string> *************** *** 284,288 **** * @lo longitude contained in the quad (in degrees) */ ! DEM(double la, double lo): zero(true) { DEM_count++; //std::cout << DEM_count << "\n"; --- 285,289 ---- * @lo longitude contained in the quad (in degrees) */ ! DEM(double la, double lo, std::string const &datpath): zero(true) { DEM_count++; //std::cout << DEM_count << "\n"; *************** *** 297,304 **** bool show = false; //std::cout << fn << "\n"; ! filename = fn; ! gzFile fp = gzopen(fn, "rb"); if (fp==0) { ! fprintf(LOG, "missing quad %s (%f %f)\n", fn, la, lo); return; } --- 298,305 ---- bool show = false; //std::cout << fn << "\n"; ! filename = simdata::ospath::join(datpath, fn); ! gzFile fp = gzopen(filename.c_str(), "rb"); if (fp==0) { ! fprintf(LOG, "missing quad %s (%f %f)\n", filename.c_str(), la, lo); return; } *************** *** 349,356 **** READI(n); if (n > 10000) { ! std::cout << d.E << " " << d.N << " " << n << "\n"; ! std::cout << i << " of " << n_col << "\n"; ! std::cout << fn << "\n"; ! std::cout << res.x << " " << res.y << " " << res.z << "\n"; } if (n > 0) { --- 350,358 ---- READI(n); if (n > 10000) { ! std::cout << "Column count exceeds 10000\n"; ! std::cout << " > " << d.E << " " << d.N << " " << n << "\n"; ! std::cout << " > " << i << " of " << n_col << "\n"; ! std::cout << " > " << filename << "\n"; ! std::cout << " > " << res.x << " " << res.y << " " << res.z << "\n"; } if (n > 0) { *************** *** 376,380 **** gscale = 1.0; if (gnd_units == 1) gscale *= 12 * 0.0254; ! assert(fabs(cols.begin()->E - cor0.x) < 500.0); } ~DEM() { --- 378,388 ---- gscale = 1.0; if (gnd_units == 1) gscale *= 12 * 0.0254; ! if (fabs(cols.begin()->E - cor0.x) >= 500.0) { ! std::cout << "Problem with DAT input for quad " << filename << "\n"; ! std::cout << "Corner0.x = " << cor0.x << "\n"; ! std::cout << "Cols[0].E = " << cols.begin()->E << "\n"; ! std::cout << "Differ by more than 500 m, possible zone mismatch?\n"; ! ::exit(1); ! } } ~DEM() { *************** *** 675,679 **** if (fp) { fprintf(fp, "P6 %d %d %d\n", _num_rows, _num_cols, 255); ! fwrite(_image, _size, 3, fp); fclose(fp); } --- 683,705 ---- if (fp) { fprintf(fp, "P6 %d %d %d\n", _num_rows, _num_cols, 255); ! //fwrite(_image, _size, 3, fp); ! _idx = _image; ! unsigned char *buffer = new unsigned char[_size*3]; ! assert(buffer != 0); ! unsigned char *out = buffer; ! bool warned = false; ! for (int n = _size; --n >=0; ) { ! int v = *_idx++; ! if (v<0 && !warned) { ! std::cerr << "WARNING: negative elevations not supported by Demeter.\n"; ! warned = true; ! } ! if (v<0) v = 0; // XXX ! *out++ = (v>>16) & 0xff; ! *out++ = (v>>8) & 0xff; ! *out++ = v & 0xff; ! } ! fwrite(buffer, _size*3, 1, fp); ! delete[] buffer; fclose(fp); } *************** *** 726,731 **** --- 752,765 ---- OutputBT() { _size = 0; + _buffer_size = 32768; + _buffer = new short[_buffer_size]; + assert(_buffer); + _bindex = 0; } ~OutputBT() { + if (_buffer != 0) { + delete[] _buffer; + _buffer = 0; + } finish(); } *************** *** 760,763 **** --- 794,801 ---- void finish() { if (_fp == 0) return; + if (_bindex > 0) { + fwrite(_buffer, sizeof(short), _bindex, _fp); + _bindex = 0; + } fclose(_fp); _fp = 0; *************** *** 765,774 **** void setSample(double z) { assert(++_count <= _size); ! short v = static_cast<short>(z*_z_scale + _z_offset); ! fwrite(&v, sizeof(short), 1, _fp); } protected: int _size, _count; FILE *_fp; }; --- 803,819 ---- void setSample(double z) { assert(++_count <= _size); ! //short v = static_cast<short>(z*_z_scale + _z_offset); ! //fwrite(&v, sizeof(short), 1, _fp); ! _buffer[_bindex] = static_cast<short>(z*_z_scale + _z_offset); ! if (++_bindex >= _buffer_size) { ! fwrite(_buffer, sizeof(short), _bindex, _fp); ! _bindex = 0; ! } } protected: int _size, _count; FILE *_fp; + short *_buffer; + int _bindex, _buffer_size; }; *************** *** 811,815 **** * Read configuration setting from an ini file. */ ! bool initialize(char const *fn) { if (fn == 0) return false; FILE *f = (FILE*) fopen(fn, "rt"); --- 856,862 ---- * Read configuration setting from an ini file. */ ! bool initialize(char const *fn, char const *datpath, bool quiet=true) { ! _datpath = datpath; ! _quiet = quiet; if (fn == 0) return false; FILE *f = (FILE*) fopen(fn, "rt"); *************** *** 1002,1010 **** //output->setExtentDegrees(left, right, bottom, top); output->setExtentMeters(-width*0.5, +width*0.5, -height*0.5, height*0.5); for (i = 0; i < x_tiles; i++) { for (j = 0; j < y_tiles; j++) { output->start(prefix, i, j); //output->setExtent(); ! generateTile(i, j, output); output->finish(); /* --- 1049,1061 ---- //output->setExtentDegrees(left, right, bottom, top); output->setExtentMeters(-width*0.5, +width*0.5, -height*0.5, height*0.5); + bool verbose = (n < 9) && !_quiet; for (i = 0; i < x_tiles; i++) { for (j = 0; j < y_tiles; j++) { + if (!_quiet) { + std::cout << "generating tile " << (idx+1) << " of " << n << std::endl; + } output->start(prefix, i, j); //output->setExtent(); ! generateTile(i, j, output, verbose); output->finish(); /* *************** *** 1025,1029 **** */ idx++; - std::cout << "tile " << idx << " of " << n << std::endl; } } --- 1076,1079 ---- *************** *** 1083,1087 **** *out++ = v & 0xff; } ! fwrite(buffer, n, 3, fp); fclose(fp); delete[] buffer; --- 1133,1137 ---- *out++ = v & 0xff; } ! fwrite(buffer, n*3, 1, fp); fclose(fp); delete[] buffer; *************** *** 1147,1151 **** used.pop_back(); } ! DEM *d = new DEM(lat, lon); dem[index] = d; return d; --- 1197,1201 ---- used.pop_back(); } ! DEM *d = new DEM(lat, lon, _datpath); dem[index] = d; return d; *************** *** 1177,1180 **** --- 1227,1231 ---- } if (finder.getElevation() == 10000.0) { + std::cout << "Got elevation = 10000.0\n"; std::cout << quads << "\n"; std::cout << utm.asString() << "\n"; *************** *** 1188,1192 **** * Generate the projected elevation data for one tile. */ ! void generateTile(int tx, int ty, OutputHeightMap *output) { int i, j; double x, y, z; --- 1239,1243 ---- * Generate the projected elevation data for one tile. */ ! void generateTile(int tx, int ty, OutputHeightMap *output, bool verbose) { int i, j; double x, y, z; *************** *** 1199,1203 **** output->getLineStride(dx0, dy0); output->getCounts(lines, samples_per_line); ! while (--lines >= 0) { x = x0; y = y0; --- 1250,1254 ---- output->getLineStride(dx0, dy0); output->getCounts(lines, samples_per_line); ! for (int line=0; line < lines; line++) { x = x0; y = y0; *************** *** 1219,1222 **** --- 1270,1276 ---- x0 += dx0; y0 += dy0; + if (verbose && ((line+1) % 10 == 0)) { + std::cout << " line " << (line+1) << " of " << lines << std::endl; + } } } *************** *** 1265,1268 **** --- 1319,1324 ---- Matrix3 R_center; + std::string _datpath; + bool _quiet; short *tile; int x_tiles, y_tiles; *************** *** 1290,1293 **** --- 1346,1353 ---- }; + void usage() { + std::cerr << "Usage: tile [--help] [--datpath=path] [--quiet] [ini]\n"; + } + void help() { std::cerr << "\n"; *************** *** 1301,1304 **** --- 1361,1370 ---- std::cerr << "secant gnomonic projection.\n"; std::cerr << "\n"; + usage(); + std::cerr << "\n"; + std::cerr << "Options:\n"; + std::cerr << " --help Display this message\n"; + std::cerr << " --datpath=path Path to the input quads\n"; + std::cerr << "\n"; std::cerr << "The ini file contains lines of the form 'option = value'. Options include:\n"; std::cerr << " center_latitude (in degrees)\n"; *************** *** 1316,1319 **** --- 1382,1386 ---- std::cerr << " overlap (0 or 1)\n"; std::cerr << " subsamples (integer)\n"; + std::cerr << " dat_path (path to input dat files)\n"; std::cerr << " prefix (the base name for output files)\n"; std::cerr << " restrict (latitude and longitude restrictions, in degrees)\n"; *************** *** 1322,1331 **** } - void usage() { - std::cerr << "Usage: tile [--help] [ini]\n"; - ::exit(1); - } - int main(int argc, char **argv) { LOG = (FILE*) fopen("tile.log", "wt"); char *ini = 0; --- 1389,1395 ---- } int main(int argc, char **argv) { + const char *datpath = "."; + bool quiet = false; LOG = (FILE*) fopen("tile.log", "wt"); char *ini = 0; *************** *** 1336,1341 **** --- 1400,1414 ---- help(); ::exit(0); + } else + if (!strncmp(arg, "--datpath=", 10)) { + datpath = arg+10; + continue; + } else + if (!strcmp(arg, "--quiet")) { + quiet = true; + continue; } usage(); + ::exit(1); } else { ini = arg; *************** *** 1343,1351 **** } if (ini == 0) { ! help(); ::exit(0); } Tiler tiler; ! if (tiler.initialize(ini)) { tiler.run(); } --- 1416,1424 ---- } if (ini == 0) { ! usage(); ::exit(0); } Tiler tiler; ! if (tiler.initialize(ini, datpath, quiet)) { tiler.run(); } |