Added support for loading 3d polygons.
This commit is contained in:
parent
727e512fad
commit
ccde971251
1 changed files with 39 additions and 21 deletions
|
@ -71,7 +71,7 @@ bool FGClipper::load_polys(const string& path) {
|
||||||
AreaType poly_type = DefaultArea;
|
AreaType poly_type = DefaultArea;
|
||||||
int contours, count, i, j;
|
int contours, count, i, j;
|
||||||
int hole_flag;
|
int hole_flag;
|
||||||
double startx, starty, x, y, lastx, lasty;
|
double startx, starty, startz, x, y, z, lastx, lasty, lastz;
|
||||||
|
|
||||||
SG_LOG( SG_CLIPPER, SG_INFO, "Loading " << path << " ..." );
|
SG_LOG( SG_CLIPPER, SG_INFO, "Loading " << path << " ..." );
|
||||||
|
|
||||||
|
@ -109,6 +109,7 @@ bool FGClipper::load_polys(const string& path) {
|
||||||
|
|
||||||
for ( i = 0; i < contours; ++i ) {
|
for ( i = 0; i < contours; ++i ) {
|
||||||
in >> count;
|
in >> count;
|
||||||
|
// cout << "Contour = " << i << " size = " << count << endl;
|
||||||
|
|
||||||
if ( count < 3 ) {
|
if ( count < 3 ) {
|
||||||
SG_LOG( SG_CLIPPER, SG_ALERT,
|
SG_LOG( SG_CLIPPER, SG_ALERT,
|
||||||
|
@ -120,29 +121,44 @@ bool FGClipper::load_polys(const string& path) {
|
||||||
|
|
||||||
in >> startx;
|
in >> startx;
|
||||||
in >> starty;
|
in >> starty;
|
||||||
p = Point3D(startx, starty, 0.0);
|
if ( poly3d ) {
|
||||||
// cout << "poly pt = " << p << endl;
|
in >> startz;
|
||||||
|
} else {
|
||||||
|
startz = -9999.0;
|
||||||
|
}
|
||||||
|
p = Point3D(startx, starty, startz);
|
||||||
|
// cout << "load poly's: poly pt = " << p << endl;
|
||||||
poly.add_node( i, p );
|
poly.add_node( i, p );
|
||||||
SG_LOG( SG_CLIPPER, SG_BULK, "0 = "
|
SG_LOG( SG_CLIPPER, SG_BULK, "0 = " << p );
|
||||||
<< startx << ", " << starty );
|
|
||||||
|
|
||||||
for ( j = 1; j < count - 1; ++j ) {
|
for ( j = 1; j < count - 1; ++j ) {
|
||||||
in >> x;
|
in >> x;
|
||||||
in >> y;
|
in >> y;
|
||||||
p = Point3D( x, y, 0.0 );
|
if ( poly3d ) {
|
||||||
// cout << "poly pt = " << p << endl;
|
in >> z;
|
||||||
|
} else {
|
||||||
|
z = -9999.0;
|
||||||
|
}
|
||||||
|
p = Point3D( x, y, z );
|
||||||
|
// cout << "load poly's: poly pt = " << p << endl;
|
||||||
poly.add_node( i, p );
|
poly.add_node( i, p );
|
||||||
}
|
}
|
||||||
|
|
||||||
in >> lastx;
|
in >> lastx;
|
||||||
in >> lasty;
|
in >> lasty;
|
||||||
|
if ( poly3d ) {
|
||||||
|
in >> lastz;
|
||||||
|
} else {
|
||||||
|
lastz = -9999.0;
|
||||||
|
}
|
||||||
|
|
||||||
if ( (fabs(startx - lastx) < SG_EPSILON)
|
if ( (fabs(startx - lastx) < SG_EPSILON)
|
||||||
&& (fabs(starty - lasty) < SG_EPSILON) ) {
|
&& (fabs(starty - lasty) < SG_EPSILON)
|
||||||
|
&& (fabs(startz - lastz) < SG_EPSILON) ) {
|
||||||
// last point same as first, discard
|
// last point same as first, discard
|
||||||
} else {
|
} else {
|
||||||
p = Point3D( lastx, lasty, 0.0 );
|
p = Point3D( lastx, lasty, lastz );
|
||||||
// cout << "poly pt = " << p << endl;
|
// cout << "load poly's: poly pt = " << p << endl;
|
||||||
poly.add_node( i, p );
|
poly.add_node( i, p );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -214,7 +230,7 @@ bool FGClipper::load_osgb36_polys(const string& path) {
|
||||||
|
|
||||||
in >> startx;
|
in >> startx;
|
||||||
in >> starty;
|
in >> starty;
|
||||||
OSRef = Point3D(startx, starty, 0.0);
|
OSRef = Point3D(startx, starty, -9999.0);
|
||||||
|
|
||||||
//Convert from OSGB36 Eastings/Northings to WGS84 Lat/Lon
|
//Convert from OSGB36 Eastings/Northings to WGS84 Lat/Lon
|
||||||
//Note that startx and starty themselves must not be altered since we compare them with unaltered lastx and lasty later
|
//Note that startx and starty themselves must not be altered since we compare them with unaltered lastx and lasty later
|
||||||
|
@ -230,7 +246,7 @@ bool FGClipper::load_osgb36_polys(const string& path) {
|
||||||
for ( j = 1; j < count - 1; ++j ) {
|
for ( j = 1; j < count - 1; ++j ) {
|
||||||
in >> x;
|
in >> x;
|
||||||
in >> y;
|
in >> y;
|
||||||
OSRef = Point3D( x, y, 0.0 );
|
OSRef = Point3D( x, y, -9999.0 );
|
||||||
|
|
||||||
OSLatLon = ConvertEastingsNorthingsToLatLon(OSRef);
|
OSLatLon = ConvertEastingsNorthingsToLatLon(OSRef);
|
||||||
OSCartesian = ConvertAiry1830PolarToCartesian(OSLatLon);
|
OSCartesian = ConvertAiry1830PolarToCartesian(OSLatLon);
|
||||||
|
@ -248,7 +264,7 @@ bool FGClipper::load_osgb36_polys(const string& path) {
|
||||||
&& (fabs(starty - lasty) < SG_EPSILON) ) {
|
&& (fabs(starty - lasty) < SG_EPSILON) ) {
|
||||||
// last point same as first, discard
|
// last point same as first, discard
|
||||||
} else {
|
} else {
|
||||||
OSRef = Point3D( lastx, lasty, 0.0 );
|
OSRef = Point3D( lastx, lasty, -9999.0 );
|
||||||
|
|
||||||
OSLatLon = ConvertEastingsNorthingsToLatLon(OSRef);
|
OSLatLon = ConvertEastingsNorthingsToLatLon(OSRef);
|
||||||
OSCartesian = ConvertAiry1830PolarToCartesian(OSLatLon);
|
OSCartesian = ConvertAiry1830PolarToCartesian(OSLatLon);
|
||||||
|
@ -468,10 +484,10 @@ bool FGClipper::clip_all(const point2d& min, const point2d& max) {
|
||||||
|
|
||||||
// set up clipping tile
|
// set up clipping tile
|
||||||
polys_in.safety_base.erase();
|
polys_in.safety_base.erase();
|
||||||
polys_in.safety_base.add_node( 0, Point3D(min.x, min.y, 0.0) );
|
polys_in.safety_base.add_node( 0, Point3D(min.x, min.y, -9999.0) );
|
||||||
polys_in.safety_base.add_node( 0, Point3D(max.x, min.y, 0.0) );
|
polys_in.safety_base.add_node( 0, Point3D(max.x, min.y, -9999.0) );
|
||||||
polys_in.safety_base.add_node( 0, Point3D(max.x, max.y, 0.0) );
|
polys_in.safety_base.add_node( 0, Point3D(max.x, max.y, -9999.0) );
|
||||||
polys_in.safety_base.add_node( 0, Point3D(min.x, max.y, 0.0) );
|
polys_in.safety_base.add_node( 0, Point3D(min.x, max.y, -9999.0) );
|
||||||
|
|
||||||
// set up land mask, we clip most things to this since it is our
|
// set up land mask, we clip most things to this since it is our
|
||||||
// best representation of land vs. ocean. If we have other less
|
// best representation of land vs. ocean. If we have other less
|
||||||
|
@ -513,7 +529,7 @@ bool FGClipper::clip_all(const point2d& min, const point2d& max) {
|
||||||
// for ( ; current != last; ++current ) {
|
// for ( ; current != last; ++current ) {
|
||||||
for( j = 0; j < (int)polys_in.polys[i].size(); ++j ) {
|
for( j = 0; j < (int)polys_in.polys[i].size(); ++j ) {
|
||||||
TGPolygon current = polys_in.polys[i][j];
|
TGPolygon current = polys_in.polys[i][j];
|
||||||
SG_LOG( SG_CLIPPER, SG_DEBUG, get_area_name( (AreaType)i )
|
SG_LOG( SG_CLIPPER, SG_INFO, get_area_name( (AreaType)i )
|
||||||
<< " = " << current.contours() );
|
<< " = " << current.contours() );
|
||||||
|
|
||||||
tmp = current;
|
tmp = current;
|
||||||
|
@ -618,6 +634,8 @@ bool FGClipper::clip_all(const point2d& min, const point2d& max) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
SG_LOG( SG_CLIPPER, SG_INFO, " master clipper finished." );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue