Make a couple function calls a bit more "name space friendly".
Expose a polygon function that will split up long edge lines to keep the max edge distance below some threshold. This could be used for instance to reduce long lines in polygon area shapes so they can better follow the underlying terrain changes.
This commit is contained in:
parent
f6a4951f36
commit
65ea77978f
20 changed files with 179 additions and 173 deletions
|
@ -326,10 +326,10 @@ static void build_runway( const TGRunway& rwy_info,
|
|||
safe_base
|
||||
= gen_runway_area_w_extend( rwy_info, 0.0, 180.0, 0.0, 0.0, 50.0 );
|
||||
}
|
||||
*apt_clearing = polygon_union(safe_base, *apt_clearing);
|
||||
*apt_clearing = tgPolygonUnion(safe_base, *apt_clearing);
|
||||
|
||||
// add base to apt_base
|
||||
*apt_base = polygon_union( base, *apt_base );
|
||||
*apt_base = tgPolygonUnion( base, *apt_base );
|
||||
}
|
||||
|
||||
|
||||
|
@ -581,11 +581,11 @@ void build_airport( string airport_id, float alt_m,
|
|||
// generate convex hull (no longer)
|
||||
// TGPolygon hull = convex_hull(apt_pts);
|
||||
|
||||
TGPolygon filled_base = strip_out_holes( apt_base );
|
||||
TGPolygon filled_base = tgPolygonStripHoles( apt_base );
|
||||
// write_polygon( filled_base, "filled-base" );
|
||||
TGPolygon divided_base = split_long_edges( filled_base, 200.0 );
|
||||
TGPolygon divided_base = tgPolygonSplitLongEdges( filled_base, 200.0 );
|
||||
// write_polygon( divided_base, "divided-base" );
|
||||
TGPolygon base_poly = polygon_diff( divided_base, accum );
|
||||
TGPolygon base_poly = tgPolygonDiff( divided_base, accum );
|
||||
// write_polygon( base_poly, "base-raw" );
|
||||
|
||||
char buf[120]; // For debugging output
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
|
||||
#include <simgear/compiler.h>
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
#include <simgear/math/sg_geodesy.hxx>
|
||||
|
||||
#include <Geometry/poly_support.hxx>
|
||||
|
||||
|
@ -116,95 +115,3 @@ TGPolygon add_nodes_to_poly( const TGPolygon& poly,
|
|||
}
|
||||
|
||||
|
||||
// Traverse a polygon and split edges until they are less than max_len
|
||||
// (specified in meters)
|
||||
TGPolygon split_long_edges( const TGPolygon &poly, double max_len ) {
|
||||
TGPolygon result;
|
||||
Point3D p0, p1;
|
||||
int i, j, k;
|
||||
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, "split_long_edges()");
|
||||
|
||||
for ( i = 0; i < poly.contours(); ++i ) {
|
||||
// SG_LOG(SG_GENERAL, SG_DEBUG, "contour = " << i);
|
||||
for ( j = 0; j < poly.contour_size(i) - 1; ++j ) {
|
||||
p0 = poly.get_pt( i, j );
|
||||
p1 = poly.get_pt( i, j + 1 );
|
||||
|
||||
double az1, az2, s;
|
||||
geo_inverse_wgs_84( 0.0,
|
||||
p0.y(), p0.x(), p1.y(), p1.x(),
|
||||
&az1, &az2, &s );
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, "distance = " << s);
|
||||
|
||||
if ( s > max_len ) {
|
||||
int segments = (int)(s / max_len) + 1;
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, "segments = " << segments);
|
||||
|
||||
double dx = (p1.x() - p0.x()) / segments;
|
||||
double dy = (p1.y() - p0.y()) / segments;
|
||||
|
||||
for ( k = 0; k < segments; ++k ) {
|
||||
Point3D tmp( p0.x() + dx * k, p0.y() + dy * k, 0.0 );
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, tmp);
|
||||
result.add_node( i, tmp );
|
||||
}
|
||||
} else {
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, p0);
|
||||
result.add_node( i, p0 );
|
||||
}
|
||||
|
||||
// end of segment is beginning of next segment
|
||||
}
|
||||
p0 = poly.get_pt( i, poly.contour_size(i) - 1 );
|
||||
p1 = poly.get_pt( i, 0 );
|
||||
|
||||
double az1, az2, s;
|
||||
geo_inverse_wgs_84( 0.0,
|
||||
p0.y(), p0.x(), p1.y(), p1.x(),
|
||||
&az1, &az2, &s );
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, "distance = " << s);
|
||||
|
||||
if ( s > max_len ) {
|
||||
int segments = (int)(s / max_len) + 1;
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, "segments = " << segments);
|
||||
|
||||
double dx = (p1.x() - p0.x()) / segments;
|
||||
double dy = (p1.y() - p0.y()) / segments;
|
||||
|
||||
for ( k = 0; k < segments; ++k ) {
|
||||
Point3D tmp( p0.x() + dx * k, p0.y() + dy * k, 0.0 );
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, tmp);
|
||||
result.add_node( i, tmp );
|
||||
}
|
||||
} else {
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, p0);
|
||||
result.add_node( i, p0 );
|
||||
}
|
||||
|
||||
// maintain original hole flag setting
|
||||
result.set_hole_flag( i, poly.get_hole_flag( i ) );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// Traverse a polygon and toss all the internal holes
|
||||
TGPolygon strip_out_holes( const TGPolygon &poly ) {
|
||||
TGPolygon result; result.erase();
|
||||
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, "strip_out_holes()");
|
||||
|
||||
for ( int i = 0; i < poly.contours(); ++i ) {
|
||||
// SG_LOG(SG_GENERAL, SG_DEBUG, "contour = " << i);
|
||||
point_list contour = poly.get_contour( i );
|
||||
if ( ! poly.get_hole_flag(i) ) {
|
||||
result.add_contour( contour, poly.get_hole_flag(i) );
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -47,13 +47,4 @@ TGPolygon add_nodes_to_poly( const TGPolygon& poly,
|
|||
const TGTriNodes& tmp_nodes );
|
||||
|
||||
|
||||
// Traverse a polygon and split edges until they are less than max_len
|
||||
// (specified in meters)
|
||||
TGPolygon split_long_edges( const TGPolygon &poly, double max_len );
|
||||
|
||||
|
||||
// Traverse a polygon and toss all the internal holes
|
||||
TGPolygon strip_out_holes( const TGPolygon &poly );
|
||||
|
||||
|
||||
#endif // _POLY_EXTRA_HXX
|
||||
|
|
|
@ -203,11 +203,11 @@ void gen_runway_section( const TGRunway& rwy_info,
|
|||
}
|
||||
|
||||
// Clip the new polygon against what ever has already been created.
|
||||
TGPolygon clipped = polygon_diff( section, *accum );
|
||||
TGPolygon clipped = tgPolygonDiff( section, *accum );
|
||||
|
||||
// Split long edges to create an object that can better flow with
|
||||
// the surface terrain
|
||||
TGPolygon split = split_long_edges( clipped, 400.0 );
|
||||
TGPolygon split = tgPolygonSplitLongEdges( clipped, 400.0 );
|
||||
|
||||
// Create the final output and push on to the runway super_polygon
|
||||
// list
|
||||
|
@ -217,7 +217,7 @@ void gen_runway_section( const TGRunway& rwy_info,
|
|||
sp.set_material( prefix + material );
|
||||
rwy_polys->push_back( sp );
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, "section = " << clipped.contours());
|
||||
*accum = polygon_union( section, *accum );
|
||||
*accum = tgPolygonUnion( section, *accum );
|
||||
|
||||
// Store away what we need to know for texture coordinate
|
||||
// calculation. (CLO 10/20/02: why can't we calculate texture
|
||||
|
|
|
@ -76,28 +76,28 @@ void gen_simple_rwy( const TGRunway& rwy_info,
|
|||
TGSuperPoly sp;
|
||||
TGTexParams tp;
|
||||
|
||||
TGPolygon clipped_a = polygon_diff( runway_a, *accum );
|
||||
TGPolygon split_a = split_long_edges( clipped_a, 400.0 );
|
||||
TGPolygon clipped_a = tgPolygonDiff( runway_a, *accum );
|
||||
TGPolygon split_a = tgPolygonSplitLongEdges( clipped_a, 400.0 );
|
||||
sp.erase();
|
||||
sp.set_poly( split_a );
|
||||
sp.set_material( material );
|
||||
rwy_polys->push_back( sp );
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, "clipped_a = " << clipped_a.contours());
|
||||
*accum = polygon_union( runway_a, *accum );
|
||||
*accum = tgPolygonUnion( runway_a, *accum );
|
||||
tp = TGTexParams( runway_a.get_pt(0,0),
|
||||
rwy_info.width * SG_FEET_TO_METER,
|
||||
rwy_info.length * SG_FEET_TO_METER / 2.0,
|
||||
rwy_info.heading );
|
||||
texparams->push_back( tp );
|
||||
|
||||
TGPolygon clipped_b = polygon_diff( runway_b, *accum );
|
||||
TGPolygon split_b = split_long_edges( clipped_b, 400.0 );
|
||||
TGPolygon clipped_b = tgPolygonDiff( runway_b, *accum );
|
||||
TGPolygon split_b = tgPolygonSplitLongEdges( clipped_b, 400.0 );
|
||||
sp.erase();
|
||||
sp.set_poly( split_b );
|
||||
sp.set_material( material );
|
||||
rwy_polys->push_back( sp );
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, "clipped_b = " << clipped_b.contours());
|
||||
*accum = polygon_union( runway_b, *accum );
|
||||
*accum = tgPolygonUnion( runway_b, *accum );
|
||||
tp = TGTexParams( runway_b.get_pt(0,0),
|
||||
rwy_info.width * SG_FEET_TO_METER,
|
||||
rwy_info.length * SG_FEET_TO_METER / 2.0,
|
||||
|
|
|
@ -89,8 +89,8 @@ void gen_taxiway( const TGRunway& rwy_info,
|
|||
twid = 250.0;
|
||||
}
|
||||
|
||||
TGPolygon clipped_a = polygon_diff( runway_a, *accum );
|
||||
TGPolygon split_a = split_long_edges( clipped_a, 400.0 );
|
||||
TGPolygon clipped_a = tgPolygonDiff( runway_a, *accum );
|
||||
TGPolygon split_a = tgPolygonSplitLongEdges( clipped_a, 400.0 );
|
||||
sp.erase();
|
||||
|
||||
sp.set_poly( split_a );
|
||||
|
@ -98,21 +98,21 @@ void gen_taxiway( const TGRunway& rwy_info,
|
|||
sp.set_flag( "taxi" ); // mark as a taxiway
|
||||
rwy_polys->push_back( sp );
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, "clipped_a = " << clipped_a.contours());
|
||||
*accum = polygon_union( runway_a, *accum );
|
||||
*accum = tgPolygonUnion( runway_a, *accum );
|
||||
tp = TGTexParams( runway_a.get_pt(0,0),
|
||||
twid * SG_FEET_TO_METER,
|
||||
250 * SG_FEET_TO_METER,
|
||||
rwy_info.heading );
|
||||
texparams->push_back( tp );
|
||||
|
||||
TGPolygon clipped_b = polygon_diff( runway_b, *accum );
|
||||
TGPolygon split_b = split_long_edges( clipped_b, 400.0 );
|
||||
TGPolygon clipped_b = tgPolygonDiff( runway_b, *accum );
|
||||
TGPolygon split_b = tgPolygonSplitLongEdges( clipped_b, 400.0 );
|
||||
sp.erase();
|
||||
sp.set_poly( split_b );
|
||||
sp.set_material( material );
|
||||
rwy_polys->push_back( sp );
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, "clipped_b = " << clipped_b.contours());
|
||||
*accum = polygon_union( runway_b, *accum );
|
||||
*accum = tgPolygonUnion( runway_b, *accum );
|
||||
tp = TGTexParams( runway_b.get_pt(0,0),
|
||||
twid * SG_FEET_TO_METER,
|
||||
250 * SG_FEET_TO_METER,
|
||||
|
|
|
@ -15,7 +15,7 @@ testclipper_LDADD = \
|
|||
$(top_builddir)/src/Lib/landcover/liblandcover.a \
|
||||
$(top_builddir)/src/Lib/poly2tri/libpoly2tri.a \
|
||||
$(top_builddir)/src/Lib/TriangleJRS/libTriangleJRS.a \
|
||||
-lsgbucket -lsgdebug -lsgmisc -lsgstructure -lsgxml \
|
||||
-lsgbucket -lsgdebug -lsgmath -lsgmisc -lsgstructure -lsgxml \
|
||||
-lgenpolyclip -lz
|
||||
|
||||
INCLUDES = -I$(top_srcdir)/src/Lib -I$(top_srcdir)/src/BuildTiles
|
||||
|
|
|
@ -402,7 +402,7 @@ void TGClipper::merge_slivers( TGPolyList& clipped, TGPolygon& slivers ) {
|
|||
|
||||
poly = clipped.polys[area][j];
|
||||
original_contours = poly.contours();
|
||||
result = polygon_union( poly, sliver );
|
||||
result = tgPolygonUnion( poly, sliver );
|
||||
result_contours = result.contours();
|
||||
|
||||
if ( original_contours == result_contours ) {
|
||||
|
@ -489,7 +489,7 @@ bool TGClipper::clip_all(const point2d& min, const point2d& max) {
|
|||
land_mask.erase();
|
||||
for ( i = 0; i < (int)polys_in.polys[DefaultArea].size(); ++i ) {
|
||||
land_mask =
|
||||
polygon_union( land_mask, polys_in.polys[DefaultArea][i] );
|
||||
tgPolygonUnion( land_mask, polys_in.polys[DefaultArea][i] );
|
||||
}
|
||||
|
||||
// set up a mask for all water.
|
||||
|
@ -499,7 +499,7 @@ bool TGClipper::clip_all(const point2d& min, const point2d& max) {
|
|||
if (is_water_area(AreaType(i))) {
|
||||
for (unsigned int j = 0; j < polys_in.polys[i].size(); j++) {
|
||||
water_mask =
|
||||
polygon_union( water_mask, polys_in.polys[i][j] );
|
||||
tgPolygonUnion( water_mask, polys_in.polys[i][j] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -509,7 +509,7 @@ bool TGClipper::clip_all(const point2d& min, const point2d& max) {
|
|||
island_mask.erase();
|
||||
for ( i = 0; i < (int)polys_in.polys[IslandArea].size(); ++i ) {
|
||||
island_mask =
|
||||
polygon_union( island_mask, polys_in.polys[IslandArea][i] );
|
||||
tgPolygonUnion( island_mask, polys_in.polys[IslandArea][i] );
|
||||
}
|
||||
|
||||
// process polygons in priority order
|
||||
|
@ -528,20 +528,20 @@ bool TGClipper::clip_all(const point2d& min, const point2d& max) {
|
|||
|
||||
// if not a hole, clip the area to the land_mask
|
||||
if ( i != HoleArea ) {
|
||||
tmp = polygon_int( tmp, land_mask );
|
||||
tmp = tgPolygonInt( tmp, land_mask );
|
||||
}
|
||||
|
||||
// Airport areas are limited to existing land mass and
|
||||
// never override water.
|
||||
if ( i == AirportArea ) {
|
||||
tmp = polygon_int( tmp, land_mask );
|
||||
tmp = polygon_diff( tmp, water_mask );
|
||||
tmp = tgPolygonInt( tmp, land_mask );
|
||||
tmp = tgPolygonDiff( tmp, water_mask );
|
||||
}
|
||||
|
||||
// if a water area, cut out potential islands
|
||||
if ( is_water_area(AreaType(i)) ) {
|
||||
// clip against island mask
|
||||
tmp = polygon_diff( tmp, island_mask );
|
||||
tmp = tgPolygonDiff( tmp, island_mask );
|
||||
}
|
||||
|
||||
TGPolygon result_union, result_diff;
|
||||
|
@ -550,8 +550,8 @@ bool TGClipper::clip_all(const point2d& min, const point2d& max) {
|
|||
result_diff = tmp;
|
||||
result_union = tmp;
|
||||
} else {
|
||||
result_diff = polygon_diff( tmp, accum);
|
||||
result_union = polygon_union( tmp, accum);
|
||||
result_diff = tgPolygonDiff( tmp, accum);
|
||||
result_union = tgPolygonUnion( tmp, accum);
|
||||
}
|
||||
|
||||
// only add to output list if the clip left us with a polygon
|
||||
|
@ -587,7 +587,7 @@ bool TGClipper::clip_all(const point2d& min, const point2d& max) {
|
|||
// remains = new gpc_polygon;
|
||||
// remains->num_contours = 0;
|
||||
// remains->contour = NULL;
|
||||
remains = polygon_diff( polys_in.safety_base, accum );
|
||||
remains = tgPolygonDiff( polys_in.safety_base, accum );
|
||||
|
||||
if ( remains.contours() > 0 ) {
|
||||
// cout << "remains contours = " << remains.contours() << endl;
|
||||
|
|
|
@ -243,7 +243,7 @@ static int actual_load_polys( const string& dir,
|
|||
// to reduce the number of separate polygons.
|
||||
static void inline add_to_polys ( TGPolygon &accum, const TGPolygon &poly) {
|
||||
if ( accum.contours() > 0 ) {
|
||||
accum = polygon_union( accum, poly );
|
||||
accum = tgPolygonUnion( accum, poly );
|
||||
} else {
|
||||
accum = poly;
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ extern "C" {
|
|||
#include <simgear/constants.h>
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
#include <simgear/math/point3d.hxx>
|
||||
#include <simgear/math/sg_geodesy.hxx>
|
||||
#include <simgear/structure/exception.hxx>
|
||||
|
||||
SG_USING_STD(endl);
|
||||
|
@ -242,7 +243,7 @@ bool TGPolygon::is_inside( int a, int b ) const {
|
|||
// B.write( "B" );
|
||||
|
||||
// A is "inside" B if the polygon_diff( A, B ) is null.
|
||||
TGPolygon result = polygon_diff( A, B );
|
||||
TGPolygon result = tgPolygonDiff( A, B );
|
||||
// SG_LOG(SG_GENERAL, SG_DEBUG, "result size = " << result.total_size());
|
||||
|
||||
// char junk;
|
||||
|
@ -416,24 +417,24 @@ TGPolygon polygon_clip( clip_op poly_op, const TGPolygon& subject,
|
|||
|
||||
|
||||
// Difference
|
||||
TGPolygon polygon_diff( const TGPolygon& subject, const TGPolygon& clip ) {
|
||||
TGPolygon tgPolygonDiff( const TGPolygon& subject, const TGPolygon& clip ) {
|
||||
return polygon_clip( POLY_DIFF, subject, clip );
|
||||
}
|
||||
|
||||
// Intersection
|
||||
TGPolygon polygon_int( const TGPolygon& subject, const TGPolygon& clip ) {
|
||||
TGPolygon tgPolygonInt( const TGPolygon& subject, const TGPolygon& clip ) {
|
||||
return polygon_clip( POLY_INT, subject, clip );
|
||||
}
|
||||
|
||||
|
||||
// Exclusive or
|
||||
TGPolygon polygon_xor( const TGPolygon& subject, const TGPolygon& clip ) {
|
||||
TGPolygon tgPolygonXor( const TGPolygon& subject, const TGPolygon& clip ) {
|
||||
return polygon_clip( POLY_XOR, subject, clip );
|
||||
}
|
||||
|
||||
|
||||
// Union
|
||||
TGPolygon polygon_union( const TGPolygon& subject, const TGPolygon& clip ) {
|
||||
TGPolygon tgPolygonUnion( const TGPolygon& subject, const TGPolygon& clip ) {
|
||||
return polygon_clip( POLY_UNION, subject, clip );
|
||||
}
|
||||
|
||||
|
@ -483,6 +484,98 @@ TGPolygon polygon_canonify( const TGPolygon& in_poly ) {
|
|||
}
|
||||
|
||||
|
||||
// Traverse a polygon and split edges until they are less than max_len
|
||||
// (specified in meters)
|
||||
TGPolygon tgPolygonSplitLongEdges( const TGPolygon &poly, double max_len ) {
|
||||
TGPolygon result;
|
||||
Point3D p0, p1;
|
||||
int i, j, k;
|
||||
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, "split_long_edges()");
|
||||
|
||||
for ( i = 0; i < poly.contours(); ++i ) {
|
||||
// SG_LOG(SG_GENERAL, SG_DEBUG, "contour = " << i);
|
||||
for ( j = 0; j < poly.contour_size(i) - 1; ++j ) {
|
||||
p0 = poly.get_pt( i, j );
|
||||
p1 = poly.get_pt( i, j + 1 );
|
||||
|
||||
double az1, az2, s;
|
||||
geo_inverse_wgs_84( 0.0,
|
||||
p0.y(), p0.x(), p1.y(), p1.x(),
|
||||
&az1, &az2, &s );
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, "distance = " << s);
|
||||
|
||||
if ( s > max_len ) {
|
||||
int segments = (int)(s / max_len) + 1;
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, "segments = " << segments);
|
||||
|
||||
double dx = (p1.x() - p0.x()) / segments;
|
||||
double dy = (p1.y() - p0.y()) / segments;
|
||||
|
||||
for ( k = 0; k < segments; ++k ) {
|
||||
Point3D tmp( p0.x() + dx * k, p0.y() + dy * k, 0.0 );
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, tmp);
|
||||
result.add_node( i, tmp );
|
||||
}
|
||||
} else {
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, p0);
|
||||
result.add_node( i, p0 );
|
||||
}
|
||||
|
||||
// end of segment is beginning of next segment
|
||||
}
|
||||
p0 = poly.get_pt( i, poly.contour_size(i) - 1 );
|
||||
p1 = poly.get_pt( i, 0 );
|
||||
|
||||
double az1, az2, s;
|
||||
geo_inverse_wgs_84( 0.0,
|
||||
p0.y(), p0.x(), p1.y(), p1.x(),
|
||||
&az1, &az2, &s );
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, "distance = " << s);
|
||||
|
||||
if ( s > max_len ) {
|
||||
int segments = (int)(s / max_len) + 1;
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, "segments = " << segments);
|
||||
|
||||
double dx = (p1.x() - p0.x()) / segments;
|
||||
double dy = (p1.y() - p0.y()) / segments;
|
||||
|
||||
for ( k = 0; k < segments; ++k ) {
|
||||
Point3D tmp( p0.x() + dx * k, p0.y() + dy * k, 0.0 );
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, tmp);
|
||||
result.add_node( i, tmp );
|
||||
}
|
||||
} else {
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, p0);
|
||||
result.add_node( i, p0 );
|
||||
}
|
||||
|
||||
// maintain original hole flag setting
|
||||
result.set_hole_flag( i, poly.get_hole_flag( i ) );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// Traverse a polygon and toss all the internal holes
|
||||
TGPolygon tgPolygonStripHoles( const TGPolygon &poly ) {
|
||||
TGPolygon result; result.erase();
|
||||
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, "strip_out_holes()");
|
||||
|
||||
for ( int i = 0; i < poly.contours(); ++i ) {
|
||||
// SG_LOG(SG_GENERAL, SG_DEBUG, "contour = " << i);
|
||||
point_list contour = poly.get_contour( i );
|
||||
if ( ! poly.get_hole_flag(i) ) {
|
||||
result.add_contour( contour, poly.get_hole_flag(i) );
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
// Wrapper for the fast Polygon Triangulation based on Seidel's
|
||||
// Algorithm by Atul Narkhede and Dinesh Manocha
|
||||
|
|
|
@ -194,29 +194,38 @@ typedef poly_list::const_iterator const_poly_list_iterator;
|
|||
|
||||
// canonify the polygon winding, outer contour must be anti-clockwise,
|
||||
// all inner contours must be clockwise.
|
||||
TGPolygon polygon_canonify( const TGPolygon& in_poly );
|
||||
TGPolygon tgPolygonCanonify( const TGPolygon& in_poly );
|
||||
|
||||
|
||||
// Traverse a polygon and split edges until they are less than max_len
|
||||
// (specified in meters)
|
||||
TGPolygon tgPolygonSplitLongEdges( const TGPolygon &poly, double max_len );
|
||||
|
||||
|
||||
// Traverse a polygon and toss all the internal holes
|
||||
TGPolygon tgPolygonStripHoles( const TGPolygon &poly );
|
||||
|
||||
|
||||
// Wrapper for the fast Polygon Triangulation based on Seidel's
|
||||
// Algorithm by Atul Narkhede and Dinesh Manocha
|
||||
// http://www.cs.unc.edu/~dm/CODE/GEM/chapter.html
|
||||
|
||||
TGPolygon polygon_to_tristrip( const TGPolygon& poly );
|
||||
TGPolygon tgPolygon2tristrip( const TGPolygon& poly );
|
||||
|
||||
|
||||
// wrapper functions for gpc polygon clip routines
|
||||
|
||||
// Difference
|
||||
TGPolygon polygon_diff( const TGPolygon& subject, const TGPolygon& clip );
|
||||
TGPolygon tgPolygonDiff( const TGPolygon& subject, const TGPolygon& clip );
|
||||
|
||||
// Intersection
|
||||
TGPolygon polygon_int( const TGPolygon& subject, const TGPolygon& clip );
|
||||
TGPolygon tgPolygonInt( const TGPolygon& subject, const TGPolygon& clip );
|
||||
|
||||
// Exclusive or
|
||||
TGPolygon polygon_xor( const TGPolygon& subject, const TGPolygon& clip );
|
||||
TGPolygon tgPolygonXor( const TGPolygon& subject, const TGPolygon& clip );
|
||||
|
||||
// Union
|
||||
TGPolygon polygon_union( const TGPolygon& subject, const TGPolygon& clip );
|
||||
TGPolygon tgPolygonUnion( const TGPolygon& subject, const TGPolygon& clip );
|
||||
|
||||
// Output
|
||||
ostream &operator<< (ostream &output, const TGPolygon &poly);
|
||||
|
|
|
@ -91,7 +91,7 @@ static void clip_and_write_poly( string root, long int p_index, AreaType area,
|
|||
fclose(bfp);
|
||||
*/
|
||||
|
||||
result = polygon_int( base, shape );
|
||||
result = tgPolygonInt( base, shape );
|
||||
if ( preserve3d ) {
|
||||
result.inherit_elevations( shape );
|
||||
}
|
||||
|
@ -259,7 +259,7 @@ void tgSplitPolygon( const string& path, AreaType area,
|
|||
bottom.add_node( 0, Point3D(180.0, clip_line, 0) );
|
||||
bottom.add_node( 0, Point3D(-180.0, clip_line, 0) );
|
||||
|
||||
bottom_clip = polygon_int( bottom, shape );
|
||||
bottom_clip = tgPolygonInt( bottom, shape );
|
||||
} else {
|
||||
bottom_clip = horizontal_clip( shape, clip_line, Below );
|
||||
}
|
||||
|
@ -288,7 +288,7 @@ void tgSplitPolygon( const string& path, AreaType area,
|
|||
top.add_node( 0, Point3D(180.0, max.y(), 0) );
|
||||
top.add_node( 0, Point3D(-180.0, max.y(), 0) );
|
||||
|
||||
top_clip = polygon_int( top, shape );
|
||||
top_clip = tgPolygonInt( top, shape );
|
||||
} else {
|
||||
top_clip = horizontal_clip( shape, clip_line, Above );
|
||||
}
|
||||
|
|
|
@ -9,7 +9,8 @@ gshhs_LDADD = \
|
|||
$(top_builddir)/src/Lib/Polygon/libPolygon.a \
|
||||
$(top_builddir)/src/Lib/Geometry/libGeometry.a \
|
||||
$(top_builddir)/src/Lib/poly2tri/libpoly2tri.a \
|
||||
-lsgdebug -lsgbucket -lsgmisc -lsgstructure -lsgxml -lgenpolyclip -lz
|
||||
-lsgdebug -lsgbucket -lsgmath -lsgmisc -lsgstructure -lsgxml \
|
||||
-lgenpolyclip -lz
|
||||
|
||||
debug_SOURCES = \
|
||||
debug.cxx
|
||||
|
@ -18,6 +19,7 @@ debug_LDADD = \
|
|||
$(top_builddir)/src/Lib/Polygon/libPolygon.a \
|
||||
$(top_builddir)/src/Lib/Geometry/libGeometry.a \
|
||||
$(top_builddir)/src/Lib/poly2tri/libpoly2tri.a \
|
||||
-lsgdebug -lsgbucket -lsgmisc -lsgstructure -lsgxml -lgenpolyclip -lz
|
||||
-lsgdebug -lsgbucket -lsgmath -lsgmisc -lsgstructure -lsgxml \
|
||||
-lgenpolyclip -lz
|
||||
|
||||
INCLUDES = -I$(top_srcdir)/src -I$(top_srcdir)/src/Lib
|
||||
|
|
|
@ -122,20 +122,20 @@ void gen_clipped_polygon( const TGPolygon& shape, const TGPolygon& clip ) {
|
|||
upper_shape.erase();
|
||||
|
||||
SG_LOG ( SG_GENERAL, SG_INFO, "Clipping lower shape" );
|
||||
lower_shape = polygon_int( lower_mask, shape );
|
||||
lower_shape = tgPolygonInt( lower_mask, shape );
|
||||
lower_shape.shift( 360, 0 );
|
||||
result = polygon_int( lower_shape, clip );
|
||||
result = tgPolygonInt( lower_shape, clip );
|
||||
write_result( result );
|
||||
|
||||
SG_LOG ( SG_GENERAL, SG_INFO, "Clipping center shape" );
|
||||
center_shape = polygon_int( center_mask, shape );
|
||||
result = polygon_int( center_shape, clip );
|
||||
center_shape = tgPolygonInt( center_mask, shape );
|
||||
result = tgPolygonInt( center_shape, clip );
|
||||
write_result( result );
|
||||
|
||||
upper_shape = polygon_int( upper_mask, shape );
|
||||
upper_shape = tgPolygonInt( upper_mask, shape );
|
||||
SG_LOG ( SG_GENERAL, SG_INFO, "Clipping upper shape" );
|
||||
upper_shape.shift( -360, 0 );
|
||||
result = polygon_int( upper_shape, clip );
|
||||
result = tgPolygonInt( upper_shape, clip );
|
||||
write_result( result );
|
||||
}
|
||||
|
||||
|
|
|
@ -75,13 +75,13 @@ void split_and_shift_chunk( const string& path, AreaType area,
|
|||
upper_shape.erase();
|
||||
|
||||
SG_LOG ( SG_GENERAL, SG_INFO, "Clipping lower shape" );
|
||||
lower_shape = polygon_int( lower_mask, shape );
|
||||
lower_shape = tgPolygonInt( lower_mask, shape );
|
||||
lower_shape.shift( 360, 0 );
|
||||
|
||||
SG_LOG ( SG_GENERAL, SG_INFO, "Clipping center shape" );
|
||||
center_shape = polygon_int( center_mask, shape );
|
||||
center_shape = tgPolygonInt( center_mask, shape );
|
||||
|
||||
upper_shape = polygon_int( upper_mask, shape );
|
||||
upper_shape = tgPolygonInt( upper_mask, shape );
|
||||
SG_LOG ( SG_GENERAL, SG_INFO, "Clipping upper shape" );
|
||||
upper_shape.shift( -360, 0 );
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ testmerger_LDADD = \
|
|||
$(top_builddir)/src/Lib/Geometry/libGeometry.a \
|
||||
$(top_builddir)/src/Lib/poly2tri/libpoly2tri.a \
|
||||
$(top_builddir)/src/Lib/TriangleJRS/libTriangleJRS.a \
|
||||
-lsgdebug -lsgbucket -lsgmisc -lsgstructure -lsgxml -lgenpolyclip -lz
|
||||
-lsgdebug -lsgbucket -lsgmath -lsgmisc -lsgstructure -lsgxml \
|
||||
-lgenpolyclip -lz
|
||||
|
||||
INCLUDES = -I$(top_srcdir)/src/Lib
|
||||
|
|
|
@ -171,7 +171,7 @@ void FGMerger::merge( FGPolyList& clipped ) {
|
|||
cout << " polygon = " << j << endl;
|
||||
|
||||
poly = clipped.polys[area][j];
|
||||
result = polygon_union( poly, result );
|
||||
result = tgPolygonUnion( poly, result );
|
||||
done=true;
|
||||
}
|
||||
clipped.polys[area].clear();
|
||||
|
@ -200,8 +200,8 @@ void FGMerger::clip(FGPolyList& subject, FGPolyList& clip) {
|
|||
cout << " Clipping polygon with area = " << area << endl;
|
||||
poly=subject.polys[area][0];
|
||||
cliped=clip.polys[default_indx][0];
|
||||
result = polygon_int(poly, cliped);
|
||||
difference = polygon_diff(difference, result);
|
||||
result = tgPolygonInt(poly, cliped);
|
||||
difference = tgPolygonDiff(difference, result);
|
||||
subject.polys[area][0]=result;
|
||||
max_a[area] +=result.contour_size(0); // let's hope we have only 1 contour polygons (first approximation)
|
||||
}
|
||||
|
@ -216,7 +216,8 @@ void FGMerger::clip(FGPolyList& subject, FGPolyList& clip) {
|
|||
}
|
||||
|
||||
|
||||
subject.polys[max_area][0] = polygon_union(subject.polys[max_area][0], difference);
|
||||
subject.polys[max_area][0]
|
||||
= tgPolygonUnion(subject.polys[max_area][0], difference);
|
||||
}
|
||||
|
||||
void FGMerger::write(FGPolyList& subject, string& file) {
|
||||
|
|
|
@ -10,7 +10,8 @@ shape_decode_LDADD = \
|
|||
$(top_builddir)/src/Lib/poly2tri/libpoly2tri.a \
|
||||
$(top_builddir)/src/Lib/shapelib/libshape.a \
|
||||
$(top_builddir)/src/Lib/TriangleJRS/libTriangleJRS.a \
|
||||
-lsgdebug -lsgbucket -lsgmisc -lsgstructure -lsgxml -lgenpolyclip -lz
|
||||
-lsgdebug -lsgbucket -lsgmath -lsgmisc -lsgstructure -lsgxml \
|
||||
-lgenpolyclip -lz
|
||||
|
||||
noaa_decode_LDADD = \
|
||||
$(top_builddir)/src/Lib/Polygon/libPolygon.a \
|
||||
|
@ -18,6 +19,7 @@ noaa_decode_LDADD = \
|
|||
$(top_builddir)/src/Lib/poly2tri/libpoly2tri.a \
|
||||
$(top_builddir)/src/Lib/shapelib/libshape.a \
|
||||
$(top_builddir)/src/Lib/TriangleJRS/libTriangleJRS.a \
|
||||
-lsgdebug -lsgbucket -lsgmisc -lsgstructure -lsgxml -lgenpolyclip -lz
|
||||
-lsgdebug -lsgbucket -lsgmath -lsgmisc -lsgstructure -lsgxml \
|
||||
-lgenpolyclip -lz
|
||||
|
||||
INCLUDES = -I$(top_srcdir)/src/Lib
|
||||
|
|
|
@ -519,9 +519,9 @@ main (int argc, const char **argv)
|
|||
}
|
||||
|
||||
if (invert) {
|
||||
mask = polygon_union(mask, shape);
|
||||
mask = tgPolygonUnion(mask, shape);
|
||||
} else {
|
||||
shape = polygon_int(shape, bounds_poly);
|
||||
shape = tgPolygonInt(shape, bounds_poly);
|
||||
if (shape.total_size() >= 3) {
|
||||
cout << "Polygon with " << shape.total_size() << " points in "
|
||||
<< shape.contours() << " contour(s)" << endl;
|
||||
|
@ -534,7 +534,7 @@ main (int argc, const char **argv)
|
|||
// wait until the end (and hope for
|
||||
// not too large a polygon)
|
||||
if (invert) {
|
||||
mask = polygon_diff(bounds_poly, mask);
|
||||
mask = tgPolygonDiff(bounds_poly, mask);
|
||||
if (mask.total_size() >= 3) {
|
||||
cout << "Inverse polygon with " << mask.total_size() << " points in "
|
||||
<< mask.contours() << " contour(s)" << endl;
|
||||
|
|
|
@ -64,7 +64,7 @@ add_point (SGPropertyNode_ptr node)
|
|||
SG_LOG(SG_TERRAIN, SG_WARN, "More than one vertex supplied for point");
|
||||
TGPolygon poly;
|
||||
tg::makePolygon(p, node->getIntValue("width", 500), poly);
|
||||
poly = polygon_int(poly, bounds_poly);
|
||||
poly = tgPolygonInt(poly, bounds_poly);
|
||||
tgSplitPolygon(".", material, poly, false);
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,7 @@ add_line (SGPropertyNode_ptr node)
|
|||
|
||||
TGPolygon poly;
|
||||
tg::makePolygon(line, node->getIntValue("width", 10), poly);
|
||||
poly = polygon_int(poly, bounds_poly);
|
||||
poly = tgPolygonInt(poly, bounds_poly);
|
||||
tgSplitPolygon(".", material, poly, false);
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ add_polygon (SGPropertyNode_ptr node)
|
|||
}
|
||||
poly.set_hole_flag(i, contour_node->getBoolValue("hole", false));
|
||||
}
|
||||
poly = polygon_int(poly, bounds_poly);
|
||||
poly = tgPolygonInt(poly, bounds_poly);
|
||||
tgSplitPolygon(".", material, poly, false);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue