1
0
Fork 0
terragear/src/Lib/e00/teste00.cxx

89 lines
2.4 KiB
C++
Raw Normal View History

// teste00.cxx - test the E00 parsing routines and dump some results.
2000-11-22 22:17:58 +00:00
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
2001-03-25 12:07:07 +00:00
#include <simgear/misc/sgstream.hxx>
2000-11-22 22:17:58 +00:00
#include "e00.hxx"
SG_USING_STD(cerr);
SG_USING_STD(cout);
SG_USING_STD(endl);
2000-11-22 22:17:58 +00:00
int main (int ac, const char ** av)
{
int i, j, k;
for (i = 1; i < ac; i++) {
2000-11-22 22:17:58 +00:00
cerr << "Reading " << av[i] << endl;
2001-03-25 12:07:07 +00:00
sg_gzifstream input(av[i]);
2000-11-22 22:17:58 +00:00
E00 data;
try {
data.readE00(input);
} catch (E00Exception &e) {
cerr << "Reading " << av[i] << " failed with exception "
<< e.getMessage() << endl;
2000-11-22 22:17:58 +00:00
exit(1);
}
cout << "Read " << av[i] << " successfully" << endl;
cout << "Read " << data.nPoints() << " point(s)" << endl;
cout << "Read " << data.nLines() << " line segment(s)" << endl;
cout << "Read " << data.nPolygons() << " polygon(s)" << endl;
cout << " (including enclosing polygon)" << endl;
// for (j = 1; j <= data.nInfoFiles(); j++) {
// const E00::IFO &ifo = data.getIFO(j);
// cout << "IFO file: " << ifo.fileName << endl;
// for (k = 0; k < ifo.numItems; k++) {
// cout << " " << ifo.defs[k].itemName << endl;
// }
// }
2000-11-22 22:17:58 +00:00
// Go over the polygons
cout << "Looking for largest polygon..." << endl;
int maxPolySize = 0;
for (j = 2; j <= data.nPolygons(); j++) {
int size = 0;
const E00::PAL &pal = data.getPAL(j);
for (k = 0; k < pal.numArcs; k++) {
int arcNum = pal.arcs[k].arcNum;
if (arcNum == 0) {
// contour boundary; do nothing
} else if (arcNum < 0) {
const E00::ARC &arc = data.getARC(0-arcNum);
size += arc.numberOfCoordinates;
} else {
const E00::ARC &arc = data.getARC(arcNum);
size += arc.numberOfCoordinates;
}
}
if (size > maxPolySize)
maxPolySize = size;
if (size > 1000) {
cout << "** Large polygon " << j << ": " << size << " points" << endl;
}
}
cout << "Largest polygon (excluding enclosing polygon) has "
<< maxPolySize << " points" << endl;
// Go over the line segments
cout << "Looking for longest line segment..." << endl;
int maxLineSize = 0;
for (j = 1; j <= data.nLines(); j++) {
const E00::ARC &arc = data.getARC(j);
if (arc.numberOfCoordinates > maxLineSize)
maxLineSize = arc.numberOfCoordinates;
}
cout << "Largest line segment (outside of polygon) has "
<< maxLineSize << " points" << endl;
2000-11-22 22:17:58 +00:00
}
return 0;
}
// end of teste00.cxx