diff --git a/src/Lib/Polygon/chop-bin.cxx b/src/Lib/Polygon/chop-bin.cxx index 8d08e445..e0a90361 100644 --- a/src/Lib/Polygon/chop-bin.cxx +++ b/src/Lib/Polygon/chop-bin.cxx @@ -47,10 +47,12 @@ using std::cout; using std::endl; static void clip_and_write_poly( string root, long int p_index, - const string &poly_type, - SGBucket b, const TGPolygon& shape, - bool preserve3d ) { + const string &poly_type, + SGBucket b, const TGPolygon& shape, + bool preserve3d ) +{ Point3D c, min, max, p; + c = Point3D( b.get_center_lon(), b.get_center_lat(), 0 ); double span = b.get_width(); TGPolygon base, result; @@ -58,24 +60,23 @@ static void clip_and_write_poly( string root, long int p_index, // calculate bucket dimensions if ( (c.y() >= -89.0) && (c.y() < 89.0) ) { - min.setx( c.x() - span / 2.0 ); - max.setx( c.x() + span / 2.0 ); - min.sety( c.y() - SG_HALF_BUCKET_SPAN ); - max.sety( c.y() + SG_HALF_BUCKET_SPAN ); + min.setx( c.x() - span / 2.0 ); + max.setx( c.x() + span / 2.0 ); + min.sety( c.y() - SG_HALF_BUCKET_SPAN ); + max.sety( c.y() + SG_HALF_BUCKET_SPAN ); } else if ( c.y() < -89.0) { - min.setx( -90.0 ); - max.setx( -89.0 ); - min.sety( -180.0 ); - max.sety( 180.0 ); + min.setx( -90.0 ); + max.setx( -89.0 ); + min.sety( -180.0 ); + max.sety( 180.0 ); } else if ( c.y() >= 89.0) { - min.setx( 89.0 ); - max.setx( 90.0 ); - min.sety( -180.0 ); - max.sety( 180.0 ); - } else { - SG_LOG ( SG_GENERAL, SG_ALERT, - "Out of range latitude in clip_and_write_poly() = " << c.y() ); - } + min.setx( 89.0 ); + max.setx( 90.0 ); + min.sety( -180.0 ); + max.sety( 180.0 ); + } else + SG_LOG( SG_GENERAL, SG_ALERT, + "Out of range latitude in clip_and_write_poly() = " << c.y() ); min.setz( 0.0 ); max.setz( 0.0 ); @@ -91,70 +92,68 @@ static void clip_and_write_poly( string root, long int p_index, // SG_LOG( SG_GENERAL, SG_DEBUG, "base = 4 vertices" ); /* - FILE *bfp= fopen("base", "w"); - gpc_write_polygon(bfp, &base); - fclose(bfp); - */ + FILE *bfp= fopen("base", "w"); + gpc_write_polygon(bfp, &base); + fclose(bfp); + */ - SG_LOG(SG_GENERAL, SG_DEBUG, "shape contours = " << shape.contours() ); - for ( int ii = 0; ii < shape.contours(); ii++ ) { - SG_LOG(SG_GENERAL, SG_DEBUG, " hole = " << shape.get_hole_flag(ii) ); - } + cout << "shape contours = " << shape.contours() << " "; + for ( int ii = 0; ii < shape.contours(); ii++ ) + cout << "hole = " << shape.get_hole_flag(ii) << " "; + cout << endl; result = tgPolygonInt( base, shape ); // write_polygon(shape, "shape"); // write_polygon(result, "result"); - SG_LOG(SG_GENERAL, SG_DEBUG, "result contours = " << result.contours() ); + cout << "result contours = " << result.contours() << " "; for ( int ii = 0; ii < result.contours(); ii++ ) { - SG_LOG(SG_GENERAL, SG_DEBUG, " hole = " << result.get_hole_flag(ii) ); + cout << "hole = " << result.get_hole_flag(ii) << " "; //if ( result.get_hole_flag(ii) ) { // exit(0); //} } - if ( preserve3d ) { + cout << endl; + if ( preserve3d ) result.inherit_elevations( shape ); - } if ( result.contours() > 0 ) { - long int t_index = b.gen_index(); - string path = root + "/" + b.gen_base_path(); + long int t_index = b.gen_index(); + string path = root + "/" + b.gen_base_path(); SGPath sgp( path ); sgp.append( "dummy" ); sgp.create_dir( 0755 ); - sprintf( tile_name, "%ld", t_index ); - string polyfile = path + "/" + tile_name; + sprintf( tile_name, "%ld", t_index ); + string polyfile = path + "/" + tile_name; - sprintf( poly_index, "%ld", p_index ); - polyfile += "."; - polyfile += poly_index; + sprintf( poly_index, "%ld", p_index ); + polyfile += "."; + polyfile += poly_index; - - FILE *rfp= fopen( polyfile.c_str(), "w" ); - if ( preserve3d ) { + + FILE *rfp = fopen( polyfile.c_str(), "w" ); + if ( preserve3d ) fprintf( rfp, "#3D\n" ); - } else { + else fprintf( rfp, "#2D\n" ); - } - fprintf( rfp, "%s\n", poly_type.c_str() ); + fprintf( rfp, "%s\n", poly_type.c_str() ); - fprintf( rfp, "%d\n", result.contours() ); - for ( int i = 0; i < result.contours(); ++i ) { - fprintf( rfp, "%d\n", result.contour_size(i) ); - fprintf( rfp, "%d\n", result.get_hole_flag(i) ); - for ( int j = 0; j < result.contour_size(i); ++j ) { - p = result.get_pt( i, j ); - if ( preserve3d ) { + fprintf( rfp, "%d\n", result.contours() ); + for ( int i = 0; i < result.contours(); ++i ) { + fprintf( rfp, "%d\n", result.contour_size(i) ); + fprintf( rfp, "%d\n", result.get_hole_flag(i) ); + for ( int j = 0; j < result.contour_size(i); ++j ) { + p = result.get_pt( i, j ); + if ( preserve3d ) fprintf( rfp, "%.15f %.15f %.15f\n", p.x(), p.y(), p.z() ); - } else { + else fprintf( rfp, "%.15f %.15f\n", p.x(), p.y() ); - } - } - } - fclose( rfp ); + } + } + fclose( rfp ); } } @@ -169,23 +168,19 @@ void tgChopNormalPolygon( const string& path, const string& poly_type, int i, j; // bail out immediately if polygon is empty - if ( shape.contours() == 0 ) { - return; - } + if ( shape.contours() == 0 ) + return; min = Point3D( 200.0 ); max = Point3D( -200.0 ); // find min/max of polygon for ( i = 0; i < shape.contours(); i++ ) { - for ( j = 0; j < shape.contour_size(i); j++ ) { - p = shape.get_pt( i, j ); + for ( j = 0; j < shape.contour_size(i); j++ ) { + p = shape.get_pt( i, j ); - if ( p.x() < min.x() ) { min.setx( p.x() ); } - if ( p.y() < min.y() ) { min.sety( p.y() ); } - if ( p.x() > max.x() ) { max.setx( p.x() ); } - if ( p.y() > max.y() ) { max.sety( p.y() ); } - } + if ( p.x() < min.x() ) min.setx( p.x() ); if ( p.y() < min.y() ) min.sety( p.y() ); if ( p.x() > max.x() ) max.setx( p.x() ); if ( p.y() > max.y() ) max.sety( p.y() ); + } } // get next polygon index @@ -202,27 +197,27 @@ void tgChopNormalPolygon( const string& path, const string& poly_type, SG_LOG( SG_GENERAL, SG_DEBUG, " Bucket max = " << b_max ); if ( b_min == b_max ) { - // shape entirely contained in a single bucket, write and bail - clip_and_write_poly( path, index, poly_type, b_min, shape, preserve3d ); - return; + // shape entirely contained in a single bucket, write and bail + clip_and_write_poly( path, index, poly_type, b_min, shape, preserve3d ); + return; } SGBucket b_cur; int dx, dy; - + sgBucketDiff(b_min, b_max, &dx, &dy); - SG_LOG( SG_GENERAL, SG_INFO, - " polygon spans tile boundaries" ); - SG_LOG( SG_GENERAL, SG_DEBUG, " dx = " << dx - << " dy = " << dy ); + SG_LOG( SG_GENERAL, SG_INFO, + " polygon spans tile boundaries" ); + SG_LOG( SG_GENERAL, SG_DEBUG, " dx = " << dx + << " dy = " << dy ); if ( (dx > 2880) || (dy > 1440) ) throw sg_exception("something is really wrong in split_polygon()!!!!"); if ( dy <= 1 ) { - // we are down to at most two rows, write each column and then bail - double min_center_lat=b_min.get_center_lat(); - double min_center_lon=b_min.get_center_lon(); + // we are down to at most two rows, write each column and then bail + double min_center_lat = b_min.get_center_lat(); + double min_center_lon = b_min.get_center_lon(); for ( j = 0; j <= dy; ++j ) { for ( i = 0; i <= dx; ++i ) { b_cur = sgBucketOffset(min_center_lon, min_center_lat, i, j); @@ -230,7 +225,7 @@ void tgChopNormalPolygon( const string& path, const string& poly_type, preserve3d ); } } - return; + return; } // we have two or more rows left, split in half (along a @@ -243,31 +238,30 @@ void tgChopNormalPolygon( const string& path, const string& poly_type, SGBucket b_clip = sgBucketOffset(min.x(), min.y(), 0, mid); double clip_line = b_clip.get_center_lat(); if ( (clip_line >= -90.0 + SG_HALF_BUCKET_SPAN) - && (clip_line < 90.0 - SG_HALF_BUCKET_SPAN) ) - { - clip_line += SG_HALF_BUCKET_SPAN; - } else if ( clip_line < -89.0 ) { - clip_line = -89.0; - } else if ( clip_line >= 89.0 ) { - clip_line = 90.0; - } else { - SG_LOG ( SG_GENERAL, SG_ALERT, - "Out of range latitude in clip_and_write_poly() = " - << clip_line ); + && (clip_line < 90.0 - SG_HALF_BUCKET_SPAN) ) + clip_line += SG_HALF_BUCKET_SPAN; + else if ( clip_line < -89.0 ) + clip_line = -89.0; + else if ( clip_line >= 89.0 ) + clip_line = 90.0; + else { + SG_LOG( SG_GENERAL, SG_ALERT, + "Out of range latitude in clip_and_write_poly() = " + << clip_line ); } { - // - // Crop bottom area (hopefully by putting this in it's own - // scope we can shorten the life of some really large data - // structures to reduce memory use) - // + // + // Crop bottom area (hopefully by putting this in it's own + // scope we can shorten the life of some really large data + // structures to reduce memory use) + // - SG_LOG ( SG_GENERAL, SG_DEBUG, - "Generating bottom half (" << min.y() << "-" << - clip_line << ")" ); + SG_LOG( SG_GENERAL, SG_DEBUG, + "Generating bottom half (" << min.y() << "-" << + clip_line << ")" ); - TGPolygon bottom, bottom_clip; + TGPolygon bottom, bottom_clip; bottom.erase(); bottom_clip.erase(); @@ -279,21 +273,21 @@ void tgChopNormalPolygon( const string& path, const string& poly_type, bottom_clip = tgPolygonInt( bottom, shape ); - tgChopNormalPolygon( path, poly_type, bottom_clip, preserve3d ); + tgChopNormalPolygon( path, poly_type, bottom_clip, preserve3d ); } { - // - // Crop top area (hopefully by putting this in it's own scope - // we can shorten the life of some really large data - // structures to reduce memory use) - // + // + // Crop top area (hopefully by putting this in it's own scope + // we can shorten the life of some really large data + // structures to reduce memory use) + // - SG_LOG ( SG_GENERAL, SG_DEBUG, - "Generating top half (" << clip_line << "-" << - max.y() << ")" ); + SG_LOG( SG_GENERAL, SG_DEBUG, + "Generating top half (" << clip_line << "-" << + max.y() << ")" ); - TGPolygon top, top_clip; + TGPolygon top, top_clip; top.erase(); top_clip.erase(); @@ -305,7 +299,7 @@ void tgChopNormalPolygon( const string& path, const string& poly_type, top_clip = tgPolygonInt( top, shape ); - tgChopNormalPolygon( path, poly_type, top_clip, preserve3d ); + tgChopNormalPolygon( path, poly_type, top_clip, preserve3d ); } } @@ -322,23 +316,19 @@ void tgChopBigSimplePolygon( const string& path, const string& poly_type, int i, j; // bail out immediately if polygon is empty - if ( shape.contours() == 0 ) { - return; - } + if ( shape.contours() == 0 ) + return; min = Point3D( 200.0 ); max = Point3D( -200.0 ); // find min/max of polygon for ( i = 0; i < shape.contours(); i++ ) { - for ( j = 0; j < shape.contour_size(i); j++ ) { - p = shape.get_pt( i, j ); + for ( j = 0; j < shape.contour_size(i); j++ ) { + p = shape.get_pt( i, j ); - if ( p.x() < min.x() ) { min.setx( p.x() ); } - if ( p.y() < min.y() ) { min.sety( p.y() ); } - if ( p.x() > max.x() ) { max.setx( p.x() ); } - if ( p.y() > max.y() ) { max.sety( p.y() ); } - } + if ( p.x() < min.x() ) min.setx( p.x() ); if ( p.y() < min.y() ) min.sety( p.y() ); if ( p.x() > max.x() ) max.setx( p.x() ); if ( p.y() > max.y() ) max.sety( p.y() ); + } } // get next polygon index @@ -355,36 +345,36 @@ void tgChopBigSimplePolygon( const string& path, const string& poly_type, SG_LOG( SG_GENERAL, SG_DEBUG, " Bucket max = " << b_max ); if ( b_min == b_max ) { - // shape entirely contained in a single bucket, write and bail - clip_and_write_poly( path, index, poly_type, b_min, shape, preserve3d ); - return; + // shape entirely contained in a single bucket, write and bail + clip_and_write_poly( path, index, poly_type, b_min, shape, preserve3d ); + return; } SGBucket b_cur; int dx, dy; - + sgBucketDiff(b_min, b_max, &dx, &dy); - SG_LOG( SG_GENERAL, SG_INFO, - " polygon spans tile boundaries" ); - SG_LOG( SG_GENERAL, SG_DEBUG, " dx = " << dx - << " dy = " << dy ); + SG_LOG( SG_GENERAL, SG_INFO, + " polygon spans tile boundaries" ); + SG_LOG( SG_GENERAL, SG_DEBUG, " dx = " << dx + << " dy = " << dy ); if ( (dx > 2880) || (dy > 1440) ) throw sg_exception("something is really wrong in split_polygon()!!!!"); if ( dy <= 1 ) { - // we are down to at most two rows, write each column and then - // bail + // we are down to at most two rows, write each column and then + // bail double min_center_lat = b_min.get_center_lat(); double min_center_lon = b_min.get_center_lon(); - for ( j = 0; j <= 1; ++j ) { - for ( i = 0; i <= dx; ++i ) { - b_cur = sgBucketOffset(min_center_lon, min_center_lat, i, j); - clip_and_write_poly( path, index, poly_type, b_cur, shape, + for ( j = 0; j <= 1; ++j ) { + for ( i = 0; i <= dx; ++i ) { + b_cur = sgBucketOffset(min_center_lon, min_center_lat, i, j); + clip_and_write_poly( path, index, poly_type, b_cur, shape, preserve3d ); - } - } - return; + } + } + return; } // we have more than one row left, split in half and recurse with @@ -396,73 +386,71 @@ void tgChopBigSimplePolygon( const string& path, const string& poly_type, // determine horizontal clip line SGBucket b_clip = sgBucketOffset(min.x(), min.y(), 0, mid); double clip_line = b_clip.get_center_lat(); - if ( (clip_line >= -89.0) && (clip_line < 89.0) ) { - clip_line += SG_HALF_BUCKET_SPAN; - } else if ( clip_line < -89.0 ) { - clip_line = -89.0; - } else if ( clip_line >= 89.0 ) { - clip_line = 90.0; - } else { - SG_LOG ( SG_GENERAL, SG_ALERT, - "Out of range latitude in clip_and_write_poly() = " - << clip_line ); + if ( (clip_line >= -89.0) && (clip_line < 89.0) ) + clip_line += SG_HALF_BUCKET_SPAN; + else if ( clip_line < -89.0 ) + clip_line = -89.0; + else if ( clip_line >= 89.0 ) + clip_line = 90.0; + else { + SG_LOG( SG_GENERAL, SG_ALERT, + "Out of range latitude in clip_and_write_poly() = " + << clip_line ); } { - // - // Crop bottom area (hopefully by putting this in it's own - // scope we can shorten the life of some really large data - // structures to reduce memory use) - // + // + // Crop bottom area (hopefully by putting this in it's own + // scope we can shorten the life of some really large data + // structures to reduce memory use) + // - SG_LOG ( SG_GENERAL, SG_DEBUG, - "Generating bottom half (" << min.y() << "-" << - clip_line << ")" ); + SG_LOG( SG_GENERAL, SG_DEBUG, + "Generating bottom half (" << min.y() << "-" << + clip_line << ")" ); - TGPolygon bottom, bottom_clip; - if ( shape.total_size() < 50000 ) { - bottom.erase(); - bottom_clip.erase(); + TGPolygon bottom, bottom_clip; + if ( shape.total_size() < 50000 ) { + bottom.erase(); + bottom_clip.erase(); - bottom.add_node( 0, Point3D(-180.0, min.y(), 0) ); - bottom.add_node( 0, Point3D(180.0, min.y(), 0) ); - bottom.add_node( 0, Point3D(180.0, clip_line, 0) ); - bottom.add_node( 0, Point3D(-180.0, clip_line, 0) ); + bottom.add_node( 0, Point3D(-180.0, min.y(), 0) ); + bottom.add_node( 0, Point3D(180.0, min.y(), 0) ); + bottom.add_node( 0, Point3D(180.0, clip_line, 0) ); + bottom.add_node( 0, Point3D(-180.0, clip_line, 0) ); - bottom_clip = tgPolygonInt( bottom, shape ); - } else { - bottom_clip = horizontal_clip( shape, clip_line, Below ); - } + bottom_clip = tgPolygonInt( bottom, shape ); + } else + bottom_clip = horizontal_clip( shape, clip_line, Below ); - tgChopBigSimplePolygon( path, poly_type, bottom_clip, preserve3d ); + tgChopBigSimplePolygon( path, poly_type, bottom_clip, preserve3d ); } { - // - // Crop top area (hopefully by putting this in it's own scope - // we can shorten the life of some really large data - // structures to reduce memory use) - // + // + // Crop top area (hopefully by putting this in it's own scope + // we can shorten the life of some really large data + // structures to reduce memory use) + // - SG_LOG ( SG_GENERAL, SG_DEBUG, - "Generating top half (" << clip_line << "-" << - max.y() << ")" ); + SG_LOG( SG_GENERAL, SG_DEBUG, + "Generating top half (" << clip_line << "-" << + max.y() << ")" ); - TGPolygon top, top_clip; - if ( shape.total_size() < 50000 ) { - top.erase(); - top_clip.erase(); + TGPolygon top, top_clip; + if ( shape.total_size() < 50000 ) { + top.erase(); + top_clip.erase(); - top.add_node( 0, Point3D(-180.0, clip_line, 0) ); - top.add_node( 0, Point3D(180.0, clip_line, 0) ); - top.add_node( 0, Point3D(180.0, max.y(), 0) ); - top.add_node( 0, Point3D(-180.0, max.y(), 0) ); + top.add_node( 0, Point3D(-180.0, clip_line, 0) ); + top.add_node( 0, Point3D(180.0, clip_line, 0) ); + top.add_node( 0, Point3D(180.0, max.y(), 0) ); + top.add_node( 0, Point3D(-180.0, max.y(), 0) ); - top_clip = tgPolygonInt( top, shape ); - } else { - top_clip = horizontal_clip( shape, clip_line, Above ); - } + top_clip = tgPolygonInt( top, shape ); + } else + top_clip = horizontal_clip( shape, clip_line, Above ); - tgChopBigSimplePolygon( path, poly_type, top_clip, preserve3d ); + tgChopBigSimplePolygon( path, poly_type, top_clip, preserve3d ); } } diff --git a/src/Lib/Polygon/index.cxx b/src/Lib/Polygon/index.cxx index f1848a77..cd337c29 100644 --- a/src/Lib/Polygon/index.cxx +++ b/src/Lib/Polygon/index.cxx @@ -19,7 +19,7 @@ // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // // $Id: index.cxx,v 1.7 2004-11-19 22:25:50 curt Exp $ - + #include #include @@ -35,15 +35,16 @@ static long int poly_index; static string poly_path; // initialize the unique polygon index counter stored in path -bool poly_index_init( string path ) { +bool poly_index_init( string path ) +{ poly_path = path; FILE *fp = fopen( poly_path.c_str(), "r" ); if ( fp == NULL ) { - SG_LOG(SG_GENERAL, SG_WARN, "Warning: cannot open " << poly_path); - poly_index = 0; - return false; + SG_LOG(SG_GENERAL, SG_WARN, "Warning: cannot open " << poly_path); + poly_index = 0; + return false; } fscanf( fp, "%ld", &poly_index ); @@ -55,15 +56,15 @@ bool poly_index_init( string path ) { // increment the persistant counter and return the next poly_index -long int poly_index_next() { +long int poly_index_next() +{ ++poly_index; FILE *fp = fopen( poly_path.c_str(), "w" ); - if ( fp == NULL ) { - SG_LOG(SG_GENERAL, SG_ALERT, - "Error cannot open " << poly_path << " for writing"); - } + if ( fp == NULL ) + SG_LOG(SG_GENERAL, SG_ALERT, + "Error cannot open " << poly_path << " for writing"); fprintf( fp, "%ld\n", poly_index ); diff --git a/src/Lib/Polygon/names.hxx b/src/Lib/Polygon/names.hxx index 20bc3245..4b7880f8 100644 --- a/src/Lib/Polygon/names.hxx +++ b/src/Lib/Polygon/names.hxx @@ -19,7 +19,7 @@ // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // // $Id: names.hxx,v 1.16 2007-10-31 15:05:13 curt Exp $ - + #ifndef _NAMES_HXX #define _NAMES_HXX @@ -31,17 +31,17 @@ inline static bool is_ocean_area( const std::string &area ) { - return area=="Ocean" || area=="Bay Estuary or Ocean"; + return area == "Ocean" || area == "Bay Estuary or Ocean"; } inline static bool is_void_area( const std::string &area ) { - return area=="Void Area"; + return area == "Void Area"; } inline static bool is_null_area( const std::string& area ) { - return area=="Null"; + return area == "Null"; } #endif // _NAMES_HXX diff --git a/src/Lib/Polygon/point2d.hxx b/src/Lib/Polygon/point2d.hxx index f702e211..63f5078b 100644 --- a/src/Lib/Polygon/point2d.hxx +++ b/src/Lib/Polygon/point2d.hxx @@ -8,16 +8,16 @@ class point2d { public: - union { - double x; - double dist; - double lon; - }; - union { - double y; - double theta; - double lat; - }; +union { + double x; + double dist; + double lon; +}; +union { + double y; + double theta; + double lat; +}; }; #endif // TG_POINT2D_HXX diff --git a/src/Lib/Polygon/polygon.cxx b/src/Lib/Polygon/polygon.cxx index 7d517b14..192bfd2a 100644 --- a/src/Lib/Polygon/polygon.cxx +++ b/src/Lib/Polygon/polygon.cxx @@ -25,7 +25,9 @@ // // http://www.cs.man.ac.uk/aig/staff/alan/software/ // - +extern "C" { +#include +} #include #include @@ -41,22 +43,25 @@ using std::endl; -// Constructor +// Constructor TGPolygon::TGPolygon( void ) { } // Destructor -TGPolygon::~TGPolygon( void ) { +TGPolygon::~TGPolygon( void ) +{ } // Set the elevations of points in the current polgyon based on the // elevations of points in source. For points that are not found in // source, propogate the value from the nearest matching point. -void TGPolygon::inherit_elevations( const TGPolygon &source ) { +void TGPolygon::inherit_elevations( const TGPolygon &source ) +{ TGTriNodes nodes; + nodes.clear(); int i, j; @@ -94,43 +99,39 @@ void TGPolygon::inherit_elevations( const TGPolygon &source ) { last = -9999.0; for ( j = 0; j < (int)poly[i].size(); ++j ) { Point3D p = poly[i][j]; - if ( p.z() > -9000 ) { + if ( p.z() > -9000 ) last = p.z(); - } else { - if ( last > -9000 ) { - poly[i][j].setz( last ); - } - } + else if ( last > -9000 ) + poly[i][j].setz( last ); + } // go back ways last = -9999.0; for ( j = poly[i].size() - 1; j >= 0; --j ) { Point3D p = poly[i][j]; - if ( p.z() > -9000 ) { + if ( p.z() > -9000 ) last = p.z(); - } else { - if ( last > -9000 ) { - poly[i][j].setz( last ); - } - } + else if ( last > -9000 ) + poly[i][j].setz( last ); + } } } // Set the elevations of all points to the specified values -void TGPolygon::set_elevations( double elev ) { - for ( unsigned i = 0; i < poly.size(); ++i ) { - for ( unsigned int j = 0; j < poly[i].size(); ++j ) { +void TGPolygon::set_elevations( double elev ) +{ + for ( unsigned i = 0; i < poly.size(); ++i ) + for ( unsigned int j = 0; j < poly[i].size(); ++j ) poly[i][j].setz( elev ); - } - } } // Calculate theta of angle (a, b, c) -double tgPolygonCalcAngle(point2d a, point2d b, point2d c) { +double tgPolygonCalcAngle(point2d a, point2d b, point2d c) +{ point2d u, v; double udist, vdist, uv_dot, tmp; @@ -162,7 +163,8 @@ double tgPolygonCalcAngle(point2d a, point2d b, point2d c) { // negative areas indicate counter clockwise winding // positive areas indicate clockwise winding. -double TGPolygon::area_contour( const int contour ) const { +double TGPolygon::area_contour( const int contour ) const +{ // area = 1/2 * sum[i = 0 to k-1][x(i)*y(i+1) - x(i+1)*y(i)] // where i=k is defined as i=0 @@ -170,9 +172,8 @@ double TGPolygon::area_contour( const int contour ) const { int size = c.size(); double sum = 0.0; - for ( int i = 0; i < size; ++i ) { - sum += c[(i+1)%size].x() * c[i].y() - c[i].x() * c[(i+1)%size].y(); - } + for ( int i = 0; i < size; ++i ) + sum += c[(i + 1) % size].x() * c[i].y() - c[i].x() * c[(i + 1) % size].y(); // area can be negative or positive depending on the polygon // winding order @@ -181,7 +182,8 @@ double TGPolygon::area_contour( const int contour ) const { // return the smallest interior angle of the contour -double TGPolygon::minangle_contour( const int contour ) { +double TGPolygon::minangle_contour( const int contour ) +{ point_list c = poly[contour]; int size = c.size(); int p1_index, p2_index, p3_index; @@ -190,32 +192,29 @@ double TGPolygon::minangle_contour( const int contour ) { double min_angle = 2.0 * SGD_PI; for ( int i = 0; i < size; ++i ) { - p1_index = i - 1; - if ( p1_index < 0 ) { - p1_index += size; - } + p1_index = i - 1; + if ( p1_index < 0 ) + p1_index += size; - p2_index = i; + p2_index = i; - p3_index = i + 1; - if ( p3_index >= size ) { - p3_index -= size; - } + p3_index = i + 1; + if ( p3_index >= size ) + p3_index -= size; - p1.x = c[p1_index].x(); - p1.y = c[p1_index].y(); + p1.x = c[p1_index].x(); + p1.y = c[p1_index].y(); - p2.x = c[p2_index].x(); - p2.y = c[p2_index].y(); + p2.x = c[p2_index].x(); + p2.y = c[p2_index].y(); - p3.x = c[p3_index].x(); - p3.y = c[p3_index].y(); + p3.x = c[p3_index].x(); + p3.y = c[p3_index].y(); - angle = tgPolygonCalcAngle( p1, p2, p3 ); + angle = tgPolygonCalcAngle( p1, p2, p3 ); - if ( angle < min_angle ) { - min_angle = angle; - } + if ( angle < min_angle ) + min_angle = angle; } return min_angle; @@ -223,10 +222,12 @@ double TGPolygon::minangle_contour( const int contour ) { // return true if contour A is inside countour B -bool TGPolygon::is_inside( int a, int b ) const { +bool TGPolygon::is_inside( int a, int b ) const +{ // make polygons from each specified contour TGPolygon A, B; point_list pl; + A.erase(); B.erase(); @@ -248,10 +249,9 @@ bool TGPolygon::is_inside( int a, int b ) const { // char junk; // cin >> junk; - if ( result.contours() == 0 ) { - // SG_LOG(SG_GENERAL, SG_DEBUG, " " << a << " is_inside() " << b); - return true; - } + if ( result.contours() == 0 ) + // SG_LOG(SG_GENERAL, SG_DEBUG, " " << a << " is_inside() " << b); + return true; // SG_LOG(SG_GENERAL, SG_DEBUG, " " << a << " not is_inside() " << b); return false; @@ -259,27 +259,28 @@ bool TGPolygon::is_inside( int a, int b ) const { // shift every point in the polygon by lon, lat -void TGPolygon::shift( double lon, double lat ) { +void TGPolygon::shift( double lon, double lat ) +{ for ( int i = 0; i < (int)poly.size(); ++i ) { - for ( int j = 0; j < (int)poly[i].size(); ++j ) { - poly[i][j].setx( poly[i][j].x() + lon ); - poly[i][j].sety( poly[i][j].y() + lat ); - } + for ( int j = 0; j < (int)poly[i].size(); ++j ) { + poly[i][j].setx( poly[i][j].x() + lon ); + poly[i][j].sety( poly[i][j].y() + lat ); + } } } // output -void TGPolygon::write( const string& file ) const { +void TGPolygon::write( const string& file ) const +{ FILE *fp = fopen( file.c_str(), "w" ); fprintf(fp, "%d\n", poly.size()); for ( int i = 0; i < (int)poly.size(); ++i ) { fprintf(fp, "%d\n", poly[i].size()); - for ( int j = 0; j < (int)poly[i].size(); ++j ) { - fprintf(fp, "%.6f %.6f\n", poly[i][j].x(), poly[i][j].y()); - } - fprintf(fp, "%.6f %.6f\n", poly[i][0].x(), poly[i][0].y()); + for ( int j = 0; j < (int)poly[i].size(); ++j ) + fprintf(fp, "%.6f %.6f\n", poly[i][j].x(), poly[i][j].y()); + fprintf(fp, "%.6f %.6f\n", poly[i][0].x(), poly[i][0].y()); } fclose(fp); @@ -287,85 +288,73 @@ void TGPolygon::write( const string& file ) const { // output -void TGPolygon::write_contour( const int contour, const string& file ) const { +void TGPolygon::write_contour( const int contour, const string& file ) const +{ FILE *fp = fopen( file.c_str(), "w" ); - - for ( int j = 0; j < (int)poly[contour].size(); ++j ) { - fprintf(fp, "%.6f %.6f\n", poly[contour][j].x(), poly[contour][j].y()); - } + + for ( int j = 0; j < (int)poly[contour].size(); ++j ) + fprintf(fp, "%.6f %.6f\n", poly[contour][j].x(), poly[contour][j].y()); fclose(fp); } -// Set operation type -typedef enum { - POLY_DIFF, // Difference - POLY_INT, // Intersection - POLY_XOR, // Exclusive or - POLY_UNION // Union -} clip_op; -#ifdef CLIP_GPC // // wrapper functions for gpc polygon clip routines // // Make a gpc_poly from an TGPolygon -void make_gpc_poly( const TGPolygon& in, gpc_polygon *out ) { +void make_gpc_poly( const TGPolygon& in, gpc_polygon *out ) +{ gpc_vertex_list v_list; + v_list.num_vertices = 0; v_list.vertex = new gpc_vertex[FG_MAX_VERTICES]; + // SG_LOG(SG_GENERAL, SG_DEBUG, "making a gpc_poly"); + // SG_LOG(SG_GENERAL, SG_DEBUG, " input contours = " << in.contours()); + Point3D p; // build the gpc_polygon structures for ( int i = 0; i < in.contours(); ++i ) { - // SG_LOG(SG_GENERAL, SG_DEBUG, " contour " << i << " = " << in.contour_size( i )); - if ( in.contour_size( i ) > FG_MAX_VERTICES ) { - char message[128]; - sprintf(message, "Polygon too large, need to increase FG_MAX_VERTICES to a least %d", in.contour_size(i)); - throw sg_exception(message);; - } + // SG_LOG(SG_GENERAL, SG_DEBUG, " contour " << i << " = " << in.contour_size( i )); + if ( in.contour_size( i ) > FG_MAX_VERTICES ) { + char message[128]; + sprintf(message, "Polygon too large, need to increase FG_MAX_VERTICES to a least %d", in.contour_size(i)); + throw sg_exception(message);; + } -#if 0 - SG_LOG(SG_GENERAL, SG_ALERT, - " make_clipper_poly : processing contour " << i << ", nodes = " - << in.contour_size(i) << ", hole = " - << in.get_hole_flag(i) - ); -#endif - - for ( int j = 0; j < in.contour_size( i ); ++j ) { - p = in.get_pt( i, j ); - v_list.vertex[j].x = p.x(); - v_list.vertex[j].y = p.y(); - } - v_list.num_vertices = in.contour_size( i ); - gpc_add_contour( out, &v_list, in.get_hole_flag( i ) ); + for ( int j = 0; j < in.contour_size( i ); ++j ) { + p = in.get_pt( i, j ); + v_list.vertex[j].x = p.x(); + v_list.vertex[j].y = p.y(); + } + v_list.num_vertices = in.contour_size( i ); + gpc_add_contour( out, &v_list, in.get_hole_flag( i ) ); } // free alocated memory delete [] v_list.vertex; } -void make_tg_poly( const gpc_polygon* in, TGPolygon *out ) -{ - for ( int i = 0; i < in->num_contours; ++i ) { - for ( int j = 0; j < in->contour[i].num_vertices; j++ ) { - Point3D p( in->contour[i].vertex[j].x, in->contour[i].vertex[j].y, -9999.0 ); - out->add_node(i, p); - } - out->set_hole_flag( i, in->hole[i] ); - } -} +// Set operation type +typedef enum { + POLY_DIFF, // Difference + POLY_INT, // Intersection + POLY_XOR, // Exclusive or + POLY_UNION // Union +} clip_op; + // Generic clipping routine -TGPolygon polygon_clip( clip_op poly_op, const TGPolygon& subject, - const TGPolygon& clip ) +TGPolygon polygon_clip( clip_op poly_op, const TGPolygon& subject, + const TGPolygon& clip ) { TGPolygon result; gpc_polygon *gpc_subject = new gpc_polygon; + gpc_subject->num_contours = 0; gpc_subject->contour = NULL; gpc_subject->hole = NULL; @@ -383,21 +372,44 @@ TGPolygon polygon_clip( clip_op poly_op, const TGPolygon& subject, gpc_result->hole = NULL; gpc_op op; - if ( poly_op == POLY_DIFF ) { - op = GPC_DIFF; - } else if ( poly_op == POLY_INT ) { - op = GPC_INT; - } else if ( poly_op == POLY_XOR ) { - op = GPC_XOR; - } else if ( poly_op == POLY_UNION ) { - op = GPC_UNION; - } else { + if ( poly_op == POLY_DIFF ) + op = GPC_DIFF; + else if ( poly_op == POLY_INT ) + op = GPC_INT; + else if ( poly_op == POLY_XOR ) + op = GPC_XOR; + else if ( poly_op == POLY_UNION ) + op = GPC_UNION; + else throw sg_exception("Unknown polygon op, exiting."); - } gpc_polygon_clip( op, gpc_subject, gpc_clip, gpc_result ); - make_tg_poly( gpc_result, &result ); + for ( int i = 0; i < gpc_result->num_contours; ++i ) { + // SG_LOG(SG_GENERAL, SG_DEBUG, + // " processing contour = " << i << ", nodes = " + // << gpc_result->contour[i].num_vertices << ", hole = " + // << gpc_result->hole[i]); + + // sprintf(junkn, "g.%d", junkc++); + // junkfp = fopen(junkn, "w"); + + for ( int j = 0; j < gpc_result->contour[i].num_vertices; j++ ) { + Point3D p( gpc_result->contour[i].vertex[j].x, + gpc_result->contour[i].vertex[j].y, + -9999.0 ); + // junkp = in_nodes.get_node( index ); + // fprintf(junkfp, "%.4f %.4f\n", junkp.x(), junkp.y()); + result.add_node(i, p); + // SG_LOG(SG_GENERAL, SG_DEBUG, " - " << index); + } + // fprintf(junkfp, "%.4f %.4f\n", + // gpc_result->contour[i].vertex[0].x, + // gpc_result->contour[i].vertex[0].y); + // fclose(junkfp); + + result.set_hole_flag( i, gpc_result->hole[i] ); + } // free allocated memory gpc_free_polygon( gpc_subject ); @@ -407,322 +419,40 @@ TGPolygon polygon_clip( clip_op poly_op, const TGPolygon& subject, return result; } -// Generic clipping routine -TGPolygon polygon_clip( clip_op poly_op, const TGPolygon& subject, const gpc_polygon& clip ) -{ - TGPolygon result; - - gpc_polygon *gpc_subject = new gpc_polygon; - gpc_subject->num_contours = 0; - gpc_subject->contour = NULL; - gpc_subject->hole = NULL; - make_gpc_poly( subject, gpc_subject ); - - gpc_polygon *gpc_clip = (gpc_polygon*)&clip; - - gpc_polygon *gpc_result = new gpc_polygon; - gpc_result->num_contours = 0; - gpc_result->contour = NULL; - gpc_result->hole = NULL; - - gpc_op op; - if ( poly_op == POLY_DIFF ) { - op = GPC_DIFF; - } else if ( poly_op == POLY_INT ) { - op = GPC_INT; - } else if ( poly_op == POLY_XOR ) { - op = GPC_XOR; - } else if ( poly_op == POLY_UNION ) { - op = GPC_UNION; - } else { - throw sg_exception("Unknown polygon op, exiting."); - } - - gpc_polygon_clip( op, gpc_subject, gpc_clip, gpc_result ); - - make_tg_poly( gpc_result, &result ); - - // free allocated memory - gpc_free_polygon( gpc_subject ); - gpc_free_polygon( gpc_result ); - - return result; -} - -gpc_polygon polygon_clip_keep_native_fmt( clip_op poly_op, const TGPolygon& subject, const gpc_polygon& clip ) -{ - gpc_polygon *gpc_subject = new gpc_polygon; - gpc_subject->num_contours = 0; - gpc_subject->contour = NULL; - gpc_subject->hole = NULL; - make_gpc_poly( subject, gpc_subject ); - - gpc_polygon *gpc_clip = (gpc_polygon*)&clip; - - gpc_polygon result; - result.num_contours = 0; - result.contour = NULL; - result.hole = NULL; - - gpc_op op; - if ( poly_op == POLY_DIFF ) { - op = GPC_DIFF; - } else if ( poly_op == POLY_INT ) { - op = GPC_INT; - } else if ( poly_op == POLY_XOR ) { - op = GPC_XOR; - } else if ( poly_op == POLY_UNION ) { - op = GPC_UNION; - } else { - throw sg_exception("Unknown polygon op, exiting."); - } - - gpc_polygon_clip( op, gpc_subject, gpc_clip, &result ); - - // free allocated memory - gpc_free_polygon( gpc_subject ); - - return result; -} -#endif - -#ifdef CLIP_CLIPPER - -#define FIXEDPT (10000000000000) - -IntPoint MakeClipperPoint( Point3D pt ) -{ - long64 x, y; - - x = (long64)( pt.x() * FIXEDPT ); - y = (long64)( pt.y() * FIXEDPT ); - - return IntPoint( x, y ); -} - -Point3D MakeTGPoint( IntPoint pt ) -{ - double x, y; - - x = (double)( ((double)pt.X) / (double)FIXEDPT ); - y = (double)( ((double)pt.Y) / (double)FIXEDPT ); - - return Point3D( x, y, -9999.0f); -} - -void make_clipper_poly( const TGPolygon& in, Polygons *out ) -{ - Polygon contour; - Point3D p; - int i, j; - - if (in.contours()) - { - // assume contour 0 is boundary, 1..x are holes - // create the boundary - for (j=0; jpush_back(contour); - - // create the holes - for (i=1; ipush_back(contour); - } - } -} - -void make_tg_poly( const ExPolygons& in, TGPolygon *out ) -{ - int res_contour = 0; - out->erase(); - - for (int i=0; iouter.size(); j++) - { - ip = IntPoint( pg->outer[j].X, pg->outer[j].Y ); - out->add_node(res_contour, MakeTGPoint(ip)); - } - out->set_hole_flag(res_contour, 0); - res_contour++; - - // then the holes - for (int j = 0; j < pg->holes.size(); j++) - { - for (int k = 0; k < pg->holes[j].size(); k++) - { - ip = IntPoint( pg->holes[j].at(k).X, pg->holes[j].at(k).Y ); - out->add_node(res_contour, MakeTGPoint(ip)); - } - out->set_hole_flag(res_contour, 1); - res_contour++; - } - } -} - -TGPolygon polygon_clip( clip_op poly_op, const TGPolygon& subject, const TGPolygon& clip ) -{ - TGPolygon result; - - Polygons clipper_subject; - make_clipper_poly( subject, &clipper_subject ); - - Polygons clipper_clip; - make_clipper_poly( clip, &clipper_clip ); - - ExPolygons clipper_result; - - ClipType op; - if ( poly_op == POLY_DIFF ) { - op = ctDifference; - } else if ( poly_op == POLY_INT ) { - op = ctIntersection; - } else if ( poly_op == POLY_XOR ) { - op = ctXor; - } else if ( poly_op == POLY_UNION ) { - op = ctUnion; - } else { - throw sg_exception("Unknown polygon op, exiting."); - } - - Clipper c; - c.Clear(); - c.AddPolygons(clipper_subject, ptSubject); - c.AddPolygons(clipper_clip, ptClip); - - c.Execute(op, clipper_result, pftEvenOdd, pftEvenOdd); - make_tg_poly( clipper_result, &result ); - - return result; -} - -TGPolygon polygon_clip( clip_op poly_op, const TGPolygon& subject, const Polygons& clipper_clip ) -{ - TGPolygon result; - - Polygons clipper_subject; - make_clipper_poly( subject, &clipper_subject ); - - ExPolygons clipper_result; - - ClipType op; - if ( poly_op == POLY_DIFF ) { - op = ctDifference; - } else if ( poly_op == POLY_INT ) { - op = ctIntersection; - } else if ( poly_op == POLY_XOR ) { - op = ctXor; - } else if ( poly_op == POLY_UNION ) { - op = ctUnion; - } else { - throw sg_exception("Unknown polygon op, exiting."); - } - - Clipper c; - c.Clear(); - c.AddPolygons(clipper_subject, ptSubject); - c.AddPolygons(clipper_clip, ptClip); - - c.Execute(op, clipper_result, pftEvenOdd, pftEvenOdd); - make_tg_poly( clipper_result, &result ); - - return result; -} - -Polygons polygon_clip_keep_native_fmt( clip_op poly_op, const TGPolygon& subject, const Polygons& clipper_clip ) -{ - Polygons clipper_subject; - make_clipper_poly( subject, &clipper_subject ); - - ExPolygons clipper_result; - Polygons result; - - ClipType op; - if ( poly_op == POLY_DIFF ) { - op = ctDifference; - } else if ( poly_op == POLY_INT ) { - op = ctIntersection; - } else if ( poly_op == POLY_XOR ) { - op = ctXor; - } else if ( poly_op == POLY_UNION ) { - op = ctUnion; - } else { - throw sg_exception("Unknown polygon op, exiting."); - } - - Clipper c; - c.Clear(); - c.AddPolygons(clipper_subject, ptSubject); - c.AddPolygons(clipper_clip, ptClip); - - c.Execute(op, clipper_result, pftEvenOdd, pftEvenOdd); - - // copy contours to polygons structure - for (int i=0; i 1 ) - throw sg_exception("ERROR: polygon with more than one enclosing contour"); - } - double area = in_poly.area_contour( i ); - if ( hole_flag && (area < 0) ) { - // reverse contour - point_list rcontour; - rcontour.clear(); - for ( int j = (int)contour.size() - 1; j >= 0; --j ) { - rcontour.push_back( contour[j] ); - } - result.add_contour( rcontour, hole_flag ); - } else if ( !hole_flag && (area > 0) ) { - // reverse contour - point_list rcontour; - rcontour.clear(); - for ( int j = (int)contour.size() - 1; j >= 0; --j ) { - rcontour.push_back( contour[j] ); - } - result.add_contour( rcontour, hole_flag ); - } else { - result.add_contour( contour, hole_flag ); - } + point_list contour = in_poly.get_contour( i ); + int hole_flag = in_poly.get_hole_flag( i ); + if ( !hole_flag ) { + non_hole_count++; + if ( non_hole_count > 1 ) + throw sg_exception("ERROR: polygon with more than one enclosing contour"); + } + double area = in_poly.area_contour( i ); + if ( hole_flag && (area < 0) ) { + // reverse contour + point_list rcontour; + rcontour.clear(); + for ( int j = (int)contour.size() - 1; j >= 0; --j ) + rcontour.push_back( contour[j] ); + result.add_contour( rcontour, hole_flag ); + } else if ( !hole_flag && (area > 0) ) { + // reverse contour + point_list rcontour; + rcontour.clear(); + for ( int j = (int)contour.size() - 1; j >= 0; --j ) + rcontour.push_back( contour[j] ); + result.add_contour( rcontour, hole_flag ); + } else + result.add_contour( contour, hole_flag ); } return result; @@ -766,7 +493,8 @@ 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 tgPolygonSplitLongEdges( const TGPolygon &poly, double max_len ) +{ TGPolygon result; Point3D p0, p1; int i, j, k; @@ -774,73 +502,72 @@ TGPolygon tgPolygonSplitLongEdges( const TGPolygon &poly, double max_len ) { 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 ) { - SG_LOG(SG_GENERAL, SG_DEBUG, "point = " << j); - p0 = poly.get_pt( i, j ); - p1 = poly.get_pt( i, j + 1 ); - SG_LOG(SG_GENERAL, SG_DEBUG, " " << p0 << " - " << p1); + SG_LOG(SG_GENERAL, SG_DEBUG, "contour = " << i); + for ( j = 0; j < poly.contour_size(i) - 1; ++j ) { + SG_LOG(SG_GENERAL, SG_DEBUG, "point = " << j); + p0 = poly.get_pt( i, j ); + p1 = poly.get_pt( i, j + 1 ); + SG_LOG(SG_GENERAL, SG_DEBUG, " " << p0 << " - " << p1); - if ( fabs(p0.y()) < (90.0 - SG_EPSILON) - || fabs(p1.y()) < (90.0 - SG_EPSILON) ) - { - 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 ( fabs(p0.y()) < (90.0 - SG_EPSILON) + || fabs(p1.y()) < (90.0 - SG_EPSILON) ) { + 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); + 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; + 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 ); - } - } 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 ); + 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 ); + } + } else { + SG_LOG(SG_GENERAL, SG_DEBUG, p0); + result.add_node( i, p0 ); + } - 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); + // end of segment is beginning of next segment + } + p0 = poly.get_pt( i, poly.contour_size(i) - 1 ); + p1 = poly.get_pt( i, 0 ); - 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; + 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); - 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 ); - } + if ( s > max_len ) { + int segments = (int)(s / max_len) + 1; + SG_LOG(SG_GENERAL, SG_DEBUG, "segments = " << segments); - // maintain original hole flag setting - result.set_hole_flag( i, poly.get_hole_flag( i ) ); + 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 ) ); } SG_LOG(SG_GENERAL, SG_DEBUG, "split_long_edges() complete"); @@ -850,15 +577,16 @@ TGPolygon tgPolygonSplitLongEdges( const TGPolygon &poly, double max_len ) { // Traverse a polygon and return the union of all the non-hole contours -TGPolygon tgPolygonStripHoles( const TGPolygon &poly ) { +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); + // SG_LOG(SG_GENERAL, SG_DEBUG, "contour = " << i); point_list contour = poly.get_contour( i ); - if ( ! poly.get_hole_flag(i) ) { + if ( !poly.get_hole_flag(i) ) { TGPolygon tmp; tmp.add_contour( contour, poly.get_hole_flag(i) ); result = tgPolygonUnion( tmp, result ); @@ -868,162 +596,19 @@ TGPolygon tgPolygonStripHoles( const TGPolygon &poly ) { return result; } - -#if 0 -// 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 - -// I make this oversize because given an n sided concave polygon with -// m, n, o, ... sided holes, I have no idea how many triangles would -// result and I don't have time right now to see if an upper bound can -// be determined easily. -#define FG_MAX_TRIANGLES 100000 - -TGPolygon polygon_to_tristrip( const TGPolygon& in_poly ) { - int i, j; - - // canonify the polygon winding, outer contour must be - // anti-clockwise, all inner contours must be clockwise. - TGPolygon canon_poly = polygon_canonify( in_poly ); - - // create and fill in the required structures - int ncontours = canon_poly.contours(); - int cntr[ncontours]; - int vsize = 1; - for ( i = 0; i < canon_poly.contours(); ++i ) { - cntr[i] = canon_poly.contour_size( i ); - vsize += cntr[i]; - } - double vertices[vsize][2]; - int counter = 1; - Point3D p; - for ( i = 0; i < canon_poly.contours(); ++i ) { - for ( j = 0; j < canon_poly.contour_size( i ); ++j ) { - p = canon_poly.get_pt( i, j ); - vertices[counter][0] = p.x(); - vertices[counter][1] = p.y(); - counter++; - } - } - int triangles[FG_MAX_TRIANGLES][3]; - - // do the triangulation - int ntriangles = triangulate_polygon(ncontours, cntr, vertices, triangles); - - /* - gpc_polygon *tmp_poly = new gpc_polygon; - tmp_poly->num_contours = 0; - tmp_poly->contour = NULL; - tmp_poly->hole = NULL; - make_gpc_poly( in_poly, tmp_poly ); - - gpc_tristrip *tmp_tristrip = new gpc_tristrip; - tmp_tristrip->num_strips = 0; - tmp_tristrip->strip = NULL; - - gpc_polygon_to_tristrip( tmp_poly, tmp_tristrip ); - - TGPolygon result; - - for ( int i = 0; i < tmp_tristrip->num_strips; ++i ) { - SG_LOG(SG_GENERAL, SG_DEBUG, " processing strip = " - << i << ", nodes = " - << tmp_tristrip->strip[i].num_vertices); - - // sprintf(junkn, "g.%d", junkc++); - // junkfp = fopen(junkn, "w"); - - for ( int j = 0; j < tmp_tristrip->strip[i].num_vertices; j++ ) { - Point3D p( tmp_tristrip->strip[i].vertex[j].x, - tmp_tristrip->strip[i].vertex[j].y, - 0 ); - // junkp = in_nodes.get_node( index ); - // fprintf(junkfp, "%.4f %.4f\n", junkp.x(), junkp.y()); - result.add_node(i, p); - // SG_LOG(SG_GENERAL, SG_DEBUG, " - " << index); - } - // fprintf(junkfp, "%.4f %.4f\n", - // gpc_result->contour[i].vertex[0].x, - // gpc_result->contour[i].vertex[0].y); - // fclose(junkfp); - } - - // free allocated memory - gpc_free_polygon( tmp_poly ); - gpc_free_tristrip( tmp_tristrip ); - */ - - // return result; -} -#endif - - -#if 0 -// -// wrapper functions for gpc polygon to tristrip routine -// - -TGPolygon polygon_to_tristrip_old( const TGPolygon& in_poly ) { - gpc_polygon *tmp_poly = new gpc_polygon; - tmp_poly->num_contours = 0; - tmp_poly->contour = NULL; - tmp_poly->hole = NULL; - make_gpc_poly( in_poly, tmp_poly ); - - gpc_tristrip *tmp_tristrip = new gpc_tristrip; - tmp_tristrip->num_strips = 0; - tmp_tristrip->strip = NULL; - - gpc_polygon_to_tristrip( tmp_poly, tmp_tristrip ); - - TGPolygon result; - - for ( int i = 0; i < tmp_tristrip->num_strips; ++i ) { - SG_LOG(SG_GENERAL, SG_DEBUG, " processing strip = " - << i << ", nodes = " - << tmp_tristrip->strip[i].num_vertices); - - // sprintf(junkn, "g.%d", junkc++); - // junkfp = fopen(junkn, "w"); - - for ( int j = 0; j < tmp_tristrip->strip[i].num_vertices; j++ ) { - Point3D p( tmp_tristrip->strip[i].vertex[j].x, - tmp_tristrip->strip[i].vertex[j].y, - 0 ); - // junkp = in_nodes.get_node( index ); - // fprintf(junkfp, "%.4f %.4f\n", junkp.x(), junkp.y()); - result.add_node(i, p); - // SG_LOG(SG_GENERAL, SG_DEBUG, " - " << index); - } - // fprintf(junkfp, "%.4f %.4f\n", - // gpc_result->contour[i].vertex[0].x, - // gpc_result->contour[i].vertex[0].y); - // fclose(junkfp); - } - - // free allocated memory - gpc_free_polygon( tmp_poly ); - gpc_free_tristrip( tmp_tristrip ); - - return result; -} -#endif - - // Send a polygon to standard output. ostream & -operator<< (ostream &output, const TGPolygon &poly) +operator<<(ostream &output, const TGPolygon &poly) { int nContours = poly.contours(); + output << nContours << endl; for (int i = 0; i < nContours; i++) { - int nPoints = poly.contour_size(i); - output << nPoints << endl; - output << poly.get_hole_flag(i) << endl; - for (int j = 0; j < nPoints; j++) { - output << poly.get_pt(i, j) << endl; - } + int nPoints = poly.contour_size(i); + output << nPoints << endl; + output << poly.get_hole_flag(i) << endl; + for (int j = 0; j < nPoints; j++) + output << poly.get_pt(i, j) << endl; } return output; // MSVC diff --git a/src/Lib/Polygon/polygon.hxx b/src/Lib/Polygon/polygon.hxx index 26319977..384ee365 100644 --- a/src/Lib/Polygon/polygon.hxx +++ b/src/Lib/Polygon/polygon.hxx @@ -25,9 +25,9 @@ #define _POLYGON_HXX -#ifndef __cplusplus +#ifndef __cplusplus # error This library requires C++ -#endif +#endif /* which clipping lib to use? Looks like we should go with clipper * It appears to be both faster and generates better accuracy @@ -86,136 +86,155 @@ class TGPolygon { private: - polytype poly; // polygons - point_list inside_list; // point inside list - int_list hole_list; // hole flag list - +polytype poly; // polygons +point_list inside_list; // point inside list +int_list hole_list; // hole flag list + public: - // Constructor and destructor - TGPolygon( void ); - ~TGPolygon( void ); +// Constructor and destructor +TGPolygon( void ); +~TGPolygon( void ); - // Add a contour - inline void add_contour( const point_list contour, const int hole_flag ) { - poly.push_back( contour ); - inside_list.push_back( Point3D( 0.0 ) ); - hole_list.push_back( hole_flag ); +// Add a contour +inline void add_contour( const point_list contour, const int hole_flag ) +{ + poly.push_back( contour ); + inside_list.push_back( Point3D( 0.0 ) ); + hole_list.push_back( hole_flag ); +} + +// Get a contour +inline point_list get_contour( const int i ) const +{ + return poly[i]; +} + +// Delete a contour +inline void delete_contour( const int i ) +{ + polytype_iterator start_poly = poly.begin(); + + poly.erase( start_poly + i ); + + point_list_iterator start_inside = inside_list.begin(); + inside_list.erase( start_inside + i ); + + int_list_iterator start_hole = hole_list.begin(); + hole_list.erase( start_hole + i ); +} + +// Add the specified node (index) to the polygon +inline void add_node( int contour, Point3D p ) +{ + if ( contour >= (int)poly.size() ) { + // extend polygon + point_list empty_contour; + empty_contour.clear(); + for ( int i = 0; i < contour - (int)poly.size() + 1; ++i ) { + poly.push_back( empty_contour ); + inside_list.push_back( Point3D(0.0) ); + hole_list.push_back( 0 ); + } } + poly[contour].push_back( p ); +} - // Get a contour - inline point_list get_contour( const int i ) const { - return poly[i]; - } +// return size +inline int contours() const +{ + return poly.size(); +} +inline int contour_size( int contour ) const +{ + return poly[contour].size(); +} +inline int total_size() const +{ + int size = 0; - // Delete a contour - inline void delete_contour( const int i ) { - polytype_iterator start_poly = poly.begin(); - poly.erase( start_poly + i ); + for ( int i = 0; i < contours(); ++i ) + size += poly[i].size(); + return size; +} - point_list_iterator start_inside = inside_list.begin(); - inside_list.erase( start_inside + i ); +// return the ith point from the specified contour +inline Point3D get_pt( int contour, int i ) const +{ + return poly[contour][i]; +} - int_list_iterator start_hole = hole_list.begin(); - hole_list.erase( start_hole + i ); - } +// update the value of a point +inline void set_pt( int contour, int i, const Point3D& p ) +{ + poly[contour][i] = p; +} - // Add the specified node (index) to the polygon - inline void add_node( int contour, Point3D p ) { - if ( contour >= (int)poly.size() ) { - // extend polygon - point_list empty_contour; - empty_contour.clear(); - for ( int i = 0; i < contour - (int)poly.size() + 1; ++i ) { - poly.push_back( empty_contour ); - inside_list.push_back( Point3D(0.0) ); - hole_list.push_back( 0 ); - } - } - poly[contour].push_back( p ); - } +// get and set an arbitrary point inside the specified polygon contour +inline Point3D get_point_inside( const int contour ) const +{ + return inside_list[contour]; +} +inline void set_point_inside( int contour, const Point3D& p ) +{ + inside_list[contour] = p; +} - // return size - inline int contours() const { return poly.size(); } - inline int contour_size( int contour ) const { - return poly[contour].size(); - } - inline int total_size() const { - int size = 0; - for ( int i = 0; i < contours(); ++i ) { - size += poly[i].size(); - } - return size; - } +// get and set hole flag +inline int get_hole_flag( const int contour ) const +{ + return hole_list[contour]; +} +inline void set_hole_flag( const int contour, const int flag ) +{ + hole_list[contour] = flag; +} +inline bool has_holes() const +{ + for (int i = 0; i < contours(); i++) + if (get_hole_flag(i)) + return true; + return false; +} - // return the ith point from the specified contour - inline Point3D get_pt( int contour, int i ) const { - return poly[contour][i]; - } +// Set the elevations of points in the current polgyon based on +// the elevations of points in source. For points that are not +// found in source, propogate the value from the nearest matching +// point. +void inherit_elevations( const TGPolygon &source ); - // update the value of a point - inline void set_pt( int contour, int i, const Point3D& p ) { - poly[contour][i] = p; - } +// Set the elevations of all points to the specified values +void set_elevations( double elev ); - // get and set an arbitrary point inside the specified polygon contour - inline Point3D get_point_inside( const int contour ) const { - return inside_list[contour]; - } - inline void set_point_inside( int contour, const Point3D& p ) { - inside_list[contour] = p; - } +// shift every point in the polygon by lon, lat +void shift( double lon, double lat ); - // get and set hole flag - inline int get_hole_flag( const int contour ) const { - return hole_list[contour]; - } - inline void set_hole_flag( const int contour, const int flag ) { - hole_list[contour] = flag; - } - inline bool has_holes () const { - for (int i = 0; i < contours(); i++) { - if (get_hole_flag(i)) - return true; - } - return false; - } +// erase +inline void erase() +{ + poly.clear(); +} - // Set the elevations of points in the current polgyon based on - // the elevations of points in source. For points that are not - // found in source, propogate the value from the nearest matching - // point. - void inherit_elevations( const TGPolygon &source ); +// informational - // Set the elevations of all points to the specified values - void set_elevations( double elev ); +// return the area of a contour (assumes simple polygons, +// i.e. non-self intersecting.) +// +// negative areas indicate counter clockwise winding +// positive areas indicate clockwise winding. +double area_contour( const int contour ) const; - // shift every point in the polygon by lon, lat - void shift( double lon, double lat ); +// return the smallest interior angle of the contour +double minangle_contour( const int contour ); - // erase - inline void erase() { poly.clear(); } +// return true if contour B is inside countour A +bool is_inside( int a, int b ) const; - // informational +// output +void write( const std::string& file ) const; - // return the area of a contour (assumes simple polygons, - // i.e. non-self intersecting.) - // - // negative areas indicate counter clockwise winding - // positive areas indicate clockwise winding. - double area_contour( const int contour ) const; - - // return the smallest interior angle of the contour - double minangle_contour( const int contour ); - - // return true if contour B is inside countour A - bool is_inside( int a, int b ) const; - - // output - void write( const std::string& file ) const; - - // output - void write_contour( const int contour, const std::string& file ) const; +// output +void write_contour( const int contour, const std::string& file ) const; }; @@ -276,7 +295,7 @@ ClipPolyType tgPolygonUnion( const TGPolygon& subject, const ClipPolyType& clip #endif // Output -std::ostream &operator<< (std::ostream &output, const TGPolygon &poly); +std::ostream &operator<<(std::ostream &output, const TGPolygon &poly); #endif // _POLYGON_HXX diff --git a/src/Lib/Polygon/simple_clip.cxx b/src/Lib/Polygon/simple_clip.cxx index d7cbcfa4..6ceaeab3 100644 --- a/src/Lib/Polygon/simple_clip.cxx +++ b/src/Lib/Polygon/simple_clip.cxx @@ -37,43 +37,39 @@ // the x value of a point on the line that intersects with the // horizontal line through y. Return true if an intersection is found, // false otherwise. -static bool intersects_y( Point3D p0, Point3D p1, double y, Point3D *result ) { +static bool intersects_y( Point3D p0, Point3D p1, double y, Point3D *result ) +{ // sort the end points if ( p0.y() > p1.y() ) { - Point3D tmp = p0; - p0 = p1; - p1 = tmp; - } - - if ( (y < p0.y()) || (y > p1.y()) ) { - // out of range of line segment, bail right away - return false; + Point3D tmp = p0; + p0 = p1; + p1 = tmp; } + if ( (y < p0.y()) || (y > p1.y()) ) + // out of range of line segment, bail right away + return false; + // equation of a line through (x0,y0) and (x1,y1): - // + // // y = y1 + (x - x1) * (y0 - y1) / (x0 - x1) // x = x1 + (y - y1) * (x0 - x1) / (y0 - y1) double x; - if ( fabs(p0.y() - p1.y()) > CLIP_EPSILON ) { - x = p1.x() + (y - p1.y()) * (p0.x() - p1.x()) / (p0.y() - p1.y()); - } else { - return false; - } + if ( fabs(p0.y() - p1.y()) > CLIP_EPSILON ) + x = p1.x() + (y - p1.y()) * (p0.x() - p1.x()) / (p0.y() - p1.y()); + else + return false; result->setx(x); result->sety(y); if ( p0.x() <= p1.x() ) { - if ( (p0.x() <= x) && (x <= p1.x()) ) { - return true; - } - } else { - if ( (p0.x() >= x) && (x >= p1.x()) ) { - return true; - } - } + if ( (p0.x() <= x) && (x <= p1.x()) ) + return true; + } else if ( (p0.x() >= x) && (x >= p1.x()) ) + return true; + return false; } @@ -81,24 +77,25 @@ static bool intersects_y( Point3D p0, Point3D p1, double y, Point3D *result ) { // find the smallest point in contour 0 of poly such that x > min_x // and y = y. Returns index of the found point, -1 if no match found. -static int find_point( const TGPolygon& poly, double min_x, double y ) { +static int find_point( const TGPolygon& poly, double min_x, double y ) +{ Point3D p, save; int index = -1; save.setx( 361.0 ); for ( int i = 0; i < poly.contour_size( 0 ); ++i ) { - p = poly.get_pt( 0, i ); - if ( p.y() == y ) { - // printf("(%d) p.y() = %.12f y = %.12f\n", i, p.y(), y); - // SG_LOG(SG_GENERAL, SG_DEBUG, " " << p); - if ( p.x() > min_x ) { - if ( p.x() < save.x() ) { - save = p; - index = i; - } - } - } + p = poly.get_pt( 0, i ); + if ( p.y() == y ) { + // printf("(%d) p.y() = %.12f y = %.12f\n", i, p.y(), y); + // SG_LOG(SG_GENERAL, SG_DEBUG, " " << p); + if ( p.x() > min_x ) { + if ( p.x() < save.x() ) { + save = p; + index = i; + } + } + } } return index; @@ -108,31 +105,27 @@ static int find_point( const TGPolygon& poly, double min_x, double y ) { // return if interesection is valid (not in the ignore list) static bool valid_intersection( int intersection, const int_list& ignore_ints ) { - for ( int i = 0; i < (int)ignore_ints.size(); ++i ) { - if ( intersection == ignore_ints[i] ) { - return false; - } - } + for ( int i = 0; i < (int)ignore_ints.size(); ++i ) + if ( intersection == ignore_ints[i] ) + return false; return true; } // return index of next valid intersection -static int next_intersection( const int_list& keep_ints, - const int_list& ignore_ints, - const int beginning_at ) +static int next_intersection( const int_list& keep_ints, + const int_list& ignore_ints, + const int beginning_at ) { // SG_LOG(SG_GENERAL, SG_DEBUG, "[ni] start_int = " << beginning_at); int i = beginning_at; - if ( i < 0 ) { i = 0; } - while ( i < (int)keep_ints.size() ) { - // SG_LOG(SG_GENERAL, SG_DEBUG, " i = " << i); - if ( keep_ints[i] != -1 ) { - if ( valid_intersection(keep_ints[i], ignore_ints) ) { - return i; - } - } - ++i; + + if ( i < 0 ) i = 0; while ( i < (int)keep_ints.size() ) { + // SG_LOG(SG_GENERAL, SG_DEBUG, " i = " << i); + if ( keep_ints[i] != -1 ) + if ( valid_intersection(keep_ints[i], ignore_ints) ) + return i; + ++i; } return -1; @@ -140,32 +133,28 @@ static int next_intersection( const int_list& keep_ints, // return true if point.y() touches or is inside of line, else return false -inline bool is_on_or_inside( double line, Point3D p, fgSideType side ) { +inline bool is_on_or_inside( double line, Point3D p, fgSideType side ) +{ if ( side == Above ) { - if ( p.y() >= line ) { - return true; - } - } else if ( side == Below ) { - if ( p.y() <= line ) { - return true; - } - } + if ( p.y() >= line ) + return true; + } else if ( side == Below ) + if ( p.y() <= line ) + return true; return false; } // return true if point.y() is inside of line, else return false -inline bool is_inside( double line, Point3D p, fgSideType side ) { +inline bool is_inside( double line, Point3D p, fgSideType side ) +{ if ( side == Above ) { - if ( p.y() > line ) { - return true; - } - } else if ( side == Below ) { - if ( p.y() < line ) { - return true; - } - } + if ( p.y() > line ) + return true; + } else if ( side == Below ) + if ( p.y() < line ) + return true; return false; } @@ -174,8 +163,8 @@ inline bool is_inside( double line, Point3D p, fgSideType side ) { // Walk through the input polygon and split it into the // portion that is inside the clip region static bool simple_clip( const TGPolygon& in, const double y, - const fgSideType side, - TGPolygon& result ) + const fgSideType side, + TGPolygon& result ) { Point3D p, p_last, p_int; int i; @@ -184,68 +173,65 @@ static bool simple_clip( const TGPolygon& in, const double y, SG_LOG(SG_GENERAL, SG_DEBUG, "input poly size = " << in.total_size()); - p_last = in.get_pt( 0, in.contour_size(0)-1 ); + p_last = in.get_pt( 0, in.contour_size(0) - 1 ); for ( i = 0; i < (int)in.contour_size(0); ++i ) { - p = in.get_pt( 0, i ); + p = in.get_pt( 0, i ); - if ( (fabs(p.x() - p_last.x()) < CLIP_EPSILON) && - (fabs(p.y() - p_last.y()) < CLIP_EPSILON) && - (i > 0) ) { - // SG_LOG(SG_GENERAL, SG_WARN, - // "WARNING: p and p_last are identical at index = " << i); - } + if ( (fabs(p.x() - p_last.x()) < CLIP_EPSILON) && + (fabs(p.y() - p_last.y()) < CLIP_EPSILON) && + (i > 0) ) { + // SG_LOG(SG_GENERAL, SG_WARN, + // "WARNING: p and p_last are identical at index = " << i); + } - if ( is_on_or_inside(y, p, side) ) { - if ( is_on_or_inside(y, p_last, side) ) { - // SG_LOG(SG_GENERAL, SG_DEBUG, "inside & inside " << i << " " << p); - result.add_node( 0, p ); - } else { - if ( !intersects_y(p, p_last, y, &p_int) ) { - SG_LOG(SG_GENERAL, SG_DEBUG, "Huh, this should have intersected!"); - return false; - } else { - // SG_LOG(SG_GENERAL, SG_DEBUG, - // "intersection outside to inside " << i << " " - // << p_int " i - 1 = " << in.get_pt( 0, i-1 )); - // SG_LOG(SG_GENERAL, SG_DEBUG, " i = " << in.get_pt( 0, i )); - // SG_LOG(SG_GENERAL, SG_DEBUG, " i + 1 = " << in.get_pt( 0, i+1 )); - result.add_node( 0, p_int ); - if ( (fabs(p.x() - p_int.x()) < CLIP_EPSILON) && - (fabs(p.y() - p_int.y()) < CLIP_EPSILON) ) - { - // SG_LOG(SG_GENERAL, SG_DEBUG, - // "WARNING: p and p_int are identical, " - // << "omitting p"); - } else { - SG_LOG(SG_GENERAL, SG_DEBUG, "adding intersection" << i << " " << p); - result.add_node( 0, p ); - } - } + if ( is_on_or_inside(y, p, side) ) { + if ( is_on_or_inside(y, p_last, side) ) + // SG_LOG(SG_GENERAL, SG_DEBUG, "inside & inside " << i << " " << p); + result.add_node( 0, p ); + else { + if ( !intersects_y(p, p_last, y, &p_int) ) { + SG_LOG(SG_GENERAL, SG_DEBUG, "Huh, this should have intersected!"); + return false; + } else { + // SG_LOG(SG_GENERAL, SG_DEBUG, + // "intersection outside to inside " << i << " " + // << p_int " i - 1 = " << in.get_pt( 0, i-1 )); + // SG_LOG(SG_GENERAL, SG_DEBUG, " i = " << in.get_pt( 0, i )); + // SG_LOG(SG_GENERAL, SG_DEBUG, " i + 1 = " << in.get_pt( 0, i+1 )); + result.add_node( 0, p_int ); + if ( (fabs(p.x() - p_int.x()) < CLIP_EPSILON) && + (fabs(p.y() - p_int.y()) < CLIP_EPSILON) ) { + // SG_LOG(SG_GENERAL, SG_DEBUG, + // "WARNING: p and p_int are identical, " + // << "omitting p"); + } else { + SG_LOG(SG_GENERAL, SG_DEBUG, "adding intersection" << i << " " << p); + result.add_node( 0, p ); + } + } } - } else { - if ( is_inside(y, p_last, side) ) { - if ( !intersects_y(p, p_last, y, &p_int) ) { - SG_LOG(SG_GENERAL, SG_DEBUG, "Huh, this should have intersected!"); - return false; - } else { - // SG_LOG(SG_GENERAL, SG_DEBUG, - // "intersection inside to outside " << i << " " - // << p_int); - if ( (fabs(p.x() - p_int.x()) < CLIP_EPSILON) && - (fabs(p.y() - p_int.y()) < CLIP_EPSILON) ) - { - SG_LOG(SG_GENERAL, SG_DEBUG, - "WARNING: p and p_int are identical, " - << "omitting p"); - } else { - result.add_node( 0, p_int ); - } - } - } - } + } else { + if ( is_inside(y, p_last, side) ) { + if ( !intersects_y(p, p_last, y, &p_int) ) { + SG_LOG(SG_GENERAL, SG_DEBUG, "Huh, this should have intersected!"); + return false; + } else { + // SG_LOG(SG_GENERAL, SG_DEBUG, + // "intersection inside to outside " << i << " " + // << p_int); + if ( (fabs(p.x() - p_int.x()) < CLIP_EPSILON) && + (fabs(p.y() - p_int.y()) < CLIP_EPSILON) ) { + SG_LOG(SG_GENERAL, SG_DEBUG, + "WARNING: p and p_int are identical, " + << "omitting p"); + } else + result.add_node( 0, p_int ); + } + } + } - p_last = p; + p_last = p; } return true; @@ -253,10 +239,10 @@ static bool simple_clip( const TGPolygon& in, const double y, // build the list of intersections -static bool build_intersections( const TGPolygon& arcs, double line, - fgSideType side, - int_list& keep_ints, - int_list& ignore_ints ) +static bool build_intersections( const TGPolygon& arcs, double line, + fgSideType side, + int_list& keep_ints, + int_list& ignore_ints ) { keep_ints.clear(); ignore_ints.clear(); @@ -265,63 +251,58 @@ static bool build_intersections( const TGPolygon& arcs, double line, double current_x = -181.0; while ( index >= 0 ) { - index = find_point( arcs, current_x, line ); - if ( index >= 0 ) { - SG_LOG(SG_GENERAL, SG_DEBUG, "intersection at " << index << " = " - << arcs.get_pt( 0, index )); - keep_ints.push_back( index ); - current_x = arcs.get_pt( 0, index ).x(); + index = find_point( arcs, current_x, line ); + if ( index >= 0 ) { + SG_LOG(SG_GENERAL, SG_DEBUG, "intersection at " << index << " = " + << arcs.get_pt( 0, index )); + keep_ints.push_back( index ); + current_x = arcs.get_pt( 0, index ).x(); - int before = index - 1; - if ( before < 0 ) { before += arcs.contour_size(0); } - int after = (index + 1) % arcs.contour_size(0); - SG_LOG(SG_GENERAL, SG_DEBUG, " before = " - << arcs.get_pt(0, before)); - SG_LOG(SG_GENERAL, SG_DEBUG, " int = " - << arcs.get_pt(0, index)); - SG_LOG(SG_GENERAL, SG_DEBUG, " after = " - << arcs.get_pt(0, after)); - if ( side == Above ) { - if ( (arcs.get_pt(0, before).y() > line) && - (arcs.get_pt(0, after).y() > line) ) - { - SG_LOG(SG_GENERAL, SG_DEBUG, "side = above"); - SG_LOG(SG_GENERAL, SG_DEBUG, - "V intersection with clip line from above"); - SG_LOG(SG_GENERAL, SG_DEBUG, - "Adding intersection to ignore_ints"); - ignore_ints.push_back( index ); - } - if ( (arcs.get_pt(0, before).y() <= line) && - (arcs.get_pt(0, after).y() <= line) ) - { - SG_LOG(SG_GENERAL, SG_DEBUG, "side = above"); - SG_LOG(SG_GENERAL, SG_DEBUG, - "V intersection with clip line from BELOW\n" - << "or an extra in-clip-line intersection.\n" - << "Adding intersection to ignore_ints"); - ignore_ints.push_back( index ); - } - } else if ( side == Below ) { - if ( (arcs.get_pt(0, before).y() >= line) && - (arcs.get_pt(0, after).y() >= line) ) - { - SG_LOG(SG_GENERAL, SG_DEBUG, "side = below"); - SG_LOG(SG_GENERAL, SG_DEBUG, "V intersection with clip line from above"); - SG_LOG(SG_GENERAL, SG_DEBUG, "Adding intersection to ignore_ints"); - ignore_ints.push_back( index ); - } - if ( (arcs.get_pt(0, before).y() < line) && - (arcs.get_pt(0, after).y() < line) ) - { - SG_LOG(SG_GENERAL, SG_DEBUG, "side = below"); - SG_LOG(SG_GENERAL, SG_DEBUG, "V intersection with clip line from BELOW"); - SG_LOG(SG_GENERAL, SG_DEBUG, "or an extra in-clip-line intersection."); - SG_LOG(SG_GENERAL, SG_DEBUG, "Adding intersection to ignore_ints"); - ignore_ints.push_back( index ); - } - } - } + int before = index - 1; + if ( before < 0 ) before += arcs.contour_size(0); int after = (index + 1) % arcs.contour_size(0); + SG_LOG(SG_GENERAL, SG_DEBUG, " before = " + << arcs.get_pt(0, before)); + SG_LOG(SG_GENERAL, SG_DEBUG, " int = " + << arcs.get_pt(0, index)); + SG_LOG(SG_GENERAL, SG_DEBUG, " after = " + << arcs.get_pt(0, after)); + if ( side == Above ) { + if ( (arcs.get_pt(0, before).y() > line) && + (arcs.get_pt(0, after).y() > line) ) { + SG_LOG(SG_GENERAL, SG_DEBUG, "side = above"); + SG_LOG(SG_GENERAL, SG_DEBUG, + "V intersection with clip line from above"); + SG_LOG(SG_GENERAL, SG_DEBUG, + "Adding intersection to ignore_ints"); + ignore_ints.push_back( index ); + } + if ( (arcs.get_pt(0, before).y() <= line) && + (arcs.get_pt(0, after).y() <= line) ) { + SG_LOG(SG_GENERAL, SG_DEBUG, "side = above"); + SG_LOG(SG_GENERAL, SG_DEBUG, + "V intersection with clip line from BELOW\n" + << "or an extra in-clip-line intersection.\n" + << "Adding intersection to ignore_ints"); + ignore_ints.push_back( index ); + } + } else if ( side == Below ) { + if ( (arcs.get_pt(0, before).y() >= line) && + (arcs.get_pt(0, after).y() >= line) ) { + SG_LOG(SG_GENERAL, SG_DEBUG, "side = below"); + SG_LOG(SG_GENERAL, SG_DEBUG, "V intersection with clip line from above"); + SG_LOG(SG_GENERAL, SG_DEBUG, "Adding intersection to ignore_ints"); + ignore_ints.push_back( index ); + } + if ( (arcs.get_pt(0, before).y() < line) && + (arcs.get_pt(0, after).y() < line) ) { + SG_LOG(SG_GENERAL, SG_DEBUG, "side = below"); + SG_LOG(SG_GENERAL, SG_DEBUG, "V intersection with clip line from BELOW"); + SG_LOG(SG_GENERAL, SG_DEBUG, "or an extra in-clip-line intersection."); + SG_LOG(SG_GENERAL, SG_DEBUG, "Adding intersection to ignore_ints"); + ignore_ints.push_back( index ); + } + } + } } return true; @@ -329,7 +310,8 @@ static bool build_intersections( const TGPolygon& arcs, double line, // test for duplicate nodes -TGPolygon fix_dups( TGPolygon& in ) { +TGPolygon fix_dups( TGPolygon& in ) +{ TGPolygon result; double x_last = -20000.0; @@ -337,15 +319,14 @@ TGPolygon fix_dups( TGPolygon& in ) { double x, y; for ( int i = 0; i < (int)in.contour_size(0); ++i ) { - x = in.get_pt(0, i).x(); - y = in.get_pt(0, i).y(); - if ( (x == x_last) && (y == y_last) ) { - // ignore - } else { - result.add_node(0, in.get_pt(0, i)); - } - x_last = x; - y_last = y; + x = in.get_pt(0, i).x(); + y = in.get_pt(0, i).y(); + if ( (x == x_last) && (y == y_last) ) { + // ignore + } else + result.add_node(0, in.get_pt(0, i)); + x_last = x; + y_last = y; } return result; @@ -357,9 +338,9 @@ TGPolygon fix_dups( TGPolygon& in ) { // with single contour polygons (no holes.) Returns true if routine // thinks it was successful. -static bool clip_contour( const TGPolygon& in, const double y, - const fgSideType side, - TGPolygon& result ) +static bool clip_contour( const TGPolygon& in, const double y, + const fgSideType side, + TGPolygon& result ) { TGPolygon result_arcs, arcs; int i, i1, i2, index; @@ -367,13 +348,13 @@ static bool clip_contour( const TGPolygon& in, const double y, // Step 1: sanity checks if ( (int)in.contours() != 1 ) { - SG_LOG(SG_GENERAL, SG_DEBUG, "we only handle single contour polygons"); - return false; + SG_LOG(SG_GENERAL, SG_DEBUG, "we only handle single contour polygons"); + return false; } if ( (int)in.contour_size( 0 ) < 3 ) { - SG_LOG(SG_GENERAL, SG_DEBUG, "we must have at least three vertices to work"); - return false; + SG_LOG(SG_GENERAL, SG_DEBUG, "we must have at least three vertices to work"); + return false; } @@ -381,15 +362,13 @@ static bool clip_contour( const TGPolygon& in, const double y, // portion that is on or inside the clip line if ( simple_clip( in, y, side, result_arcs ) ) { - if ( result_arcs.contours() > 0 ) { - SG_LOG(SG_GENERAL, SG_DEBUG, "result_arcs size = " - << result_arcs.total_size()); - } else { - SG_LOG(SG_GENERAL, SG_DEBUG, "empty result"); - } - } else { + if ( result_arcs.contours() > 0 ) + SG_LOG(SG_GENERAL, SG_DEBUG, "result_arcs size = " + << result_arcs.total_size()); + else + SG_LOG(SG_GENERAL, SG_DEBUG, "empty result"); + } else throw sg_exception("simple_clip_above() failed!"); - } // Step 3: check for trivial cases @@ -398,25 +377,25 @@ static bool clip_contour( const TGPolygon& in, const double y, // trivial -- nothing inside of clip line if ( result_arcs.contours() == 0 ) { - SG_LOG(SG_GENERAL, SG_DEBUG, "trivially empty"); - return true; + SG_LOG(SG_GENERAL, SG_DEBUG, "trivially empty"); + return true; } // trivial -- everything inside of clip line i1 = find_point( result_arcs, -181.0, y ); if ( i1 < 0 ) { - SG_LOG(SG_GENERAL, SG_DEBUG, "trivially full"); - result = result_arcs; - return true; + SG_LOG(SG_GENERAL, SG_DEBUG, "trivially full"); + result = result_arcs; + return true; } // trivial -- single clip line intersection (polygon just nicks // it) -- everything inside - i2 = find_point( result_arcs, result_arcs.get_pt(0,i1).x(), y ); + i2 = find_point( result_arcs, result_arcs.get_pt(0, i1).x(), y ); if ( i2 < 0 ) { - SG_LOG(SG_GENERAL, SG_DEBUG, "trivially full (clip line nicks edge)"); - result = result_arcs; - return true; + SG_LOG(SG_GENERAL, SG_DEBUG, "trivially full (clip line nicks edge)"); + result = result_arcs; + return true; } @@ -427,13 +406,12 @@ static bool clip_contour( const TGPolygon& in, const double y, tmp.erase(); if ( side == Below ) { - for ( i = result_arcs.contour_size(0) - 1; i >= 0; --i ) { - Point3D p = result_arcs.get_pt( 0, i ); - tmp.add_node( 0, p ); - } - } else { - tmp = result_arcs; - } + for ( i = result_arcs.contour_size(0) - 1; i >= 0; --i ) { + Point3D p = result_arcs.get_pt( 0, i ); + tmp.add_node( 0, p ); + } + } else + tmp = result_arcs; arcs = fix_dups( tmp ); @@ -449,7 +427,7 @@ static bool clip_contour( const TGPolygon& in, const double y, // individual contours.) int start_int = next_intersection( keep_ints, ignore_ints, 0 ); - int next_int = next_intersection( keep_ints, ignore_ints, start_int+1 ); + int next_int = next_intersection( keep_ints, ignore_ints, start_int + 1 ); SG_LOG(SG_GENERAL, SG_DEBUG, "start_int = " << start_int); SG_LOG(SG_GENERAL, SG_DEBUG, "next_int = " << next_int); @@ -457,72 +435,70 @@ static bool clip_contour( const TGPolygon& in, const double y, // while we have keep_ints left to process while ( start_int >= 0 ) { - point_list contour; - contour.clear(); + point_list contour; + contour.clear(); - index = keep_ints[next_int]; - keep_ints[next_int] = -1; - SG_LOG(SG_GENERAL, SG_DEBUG, "\nstarting at point = " - << arcs.get_pt(0,index)); + index = keep_ints[next_int]; + keep_ints[next_int] = -1; + SG_LOG(SG_GENERAL, SG_DEBUG, "\nstarting at point = " + << arcs.get_pt(0, index)); - while ( index != keep_ints[start_int] ) { - SG_LOG(SG_GENERAL, SG_DEBUG, "index = " << index - << " start_int = " << start_int - << " keep_ints[start_int] = " << keep_ints[start_int]); + while ( index != keep_ints[start_int] ) { + SG_LOG(SG_GENERAL, SG_DEBUG, "index = " << index + << " start_int = " << start_int + << " keep_ints[start_int] = " << keep_ints[start_int]); - // start with the 2nd item in the intersection list and - // traverse until we find another intersection - contour.push_back( arcs.get_pt(0,index) ); - index = (index + 1) % arcs.contour_size(0); - - while ( (arcs.get_pt(0,index).y() != y) || - ! valid_intersection(index, ignore_ints) ) - { - contour.push_back( arcs.get_pt(0,index) ); - index = (index + 1) % arcs.contour_size(0); - } - contour.push_back( arcs.get_pt(0,index) ); - SG_LOG(SG_GENERAL, SG_WARN, "exited at poly index = " - << index << " " << arcs.get_pt(0,index)); + // start with the 2nd item in the intersection list and + // traverse until we find another intersection + contour.push_back( arcs.get_pt(0, index) ); + index = (index + 1) % arcs.contour_size(0); - // find which intersection we came out on in our list - SG_LOG(SG_GENERAL, SG_DEBUG, "finding exit intersection for " << index); - i = 0; - while ( i < (int)keep_ints.size() ) { - // SG_LOG(SG_GENERAL, SG_DEBUG, " keep_int[" << i << "] = " << keep_ints[i]); - if ( index == keep_ints[i] ) { - SG_LOG(SG_GENERAL, SG_DEBUG, " intersection index = " << i); - if ( index != keep_ints[start_int] ) { - SG_LOG(SG_GENERAL, SG_DEBUG, " not start index so keep going"); - keep_ints[i] = -1; - next_int = next_intersection( keep_ints, ignore_ints, - i+1 ); - index = keep_ints[next_int]; - keep_ints[next_int] = -1; - SG_LOG(SG_GENERAL, SG_DEBUG, - " next_int = " << next_int << " index = " - << index); - } - break; - } - ++i; - } - if ( i == (int)keep_ints.size() ) { - throw sg_exception("oops, didn't find that intersection, you are screwed"); - } - } - keep_ints[start_int] = -1; - result.add_contour( contour, count ); - count++; + while ( (arcs.get_pt(0, index).y() != y) || + !valid_intersection(index, ignore_ints) ) { + contour.push_back( arcs.get_pt(0, index) ); + index = (index + 1) % arcs.contour_size(0); + } + contour.push_back( arcs.get_pt(0, index) ); + SG_LOG(SG_GENERAL, SG_WARN, "exited at poly index = " + << index << " " << arcs.get_pt(0, index)); - // find next keep_ints - start_int = next_intersection( keep_ints, ignore_ints, -1 ); - next_int = next_intersection( keep_ints, ignore_ints, start_int+1 ); - - SG_LOG(SG_GENERAL, SG_DEBUG, "start_int = " << start_int); - SG_LOG(SG_GENERAL, SG_DEBUG, "next_int = " << next_int); + // find which intersection we came out on in our list + SG_LOG(SG_GENERAL, SG_DEBUG, "finding exit intersection for " << index); + i = 0; + while ( i < (int)keep_ints.size() ) { + // SG_LOG(SG_GENERAL, SG_DEBUG, " keep_int[" << i << "] = " << keep_ints[i]); + if ( index == keep_ints[i] ) { + SG_LOG(SG_GENERAL, SG_DEBUG, " intersection index = " << i); + if ( index != keep_ints[start_int] ) { + SG_LOG(SG_GENERAL, SG_DEBUG, " not start index so keep going"); + keep_ints[i] = -1; + next_int = next_intersection( keep_ints, ignore_ints, + i + 1 ); + index = keep_ints[next_int]; + keep_ints[next_int] = -1; + SG_LOG(SG_GENERAL, SG_DEBUG, + " next_int = " << next_int << " index = " + << index); + } + break; + } + ++i; + } + if ( i == (int)keep_ints.size() ) + throw sg_exception("oops, didn't find that intersection, you are screwed"); + } + keep_ints[start_int] = -1; + result.add_contour( contour, count ); + count++; + + // find next keep_ints + start_int = next_intersection( keep_ints, ignore_ints, -1 ); + next_int = next_intersection( keep_ints, ignore_ints, start_int + 1 ); + + SG_LOG(SG_GENERAL, SG_DEBUG, "start_int = " << start_int); + SG_LOG(SG_GENERAL, SG_DEBUG, "next_int = " << next_int); } - + return true; } @@ -533,16 +509,17 @@ static bool clip_contour( const TGPolygon& in, const double y, // results. Doesn't work with holes. Returns true if routine thinks // it was successful. -TGPolygon horizontal_clip( const TGPolygon& in, const double y, - const fgSideType side ) +TGPolygon horizontal_clip( const TGPolygon& in, const double y, + const fgSideType side ) { TGPolygon result; + result.erase(); // Step 1: sanity checks if ( (int)in.contours() == 0 ) { - SG_LOG(SG_GENERAL, SG_DEBUG, "Error: 0 contour polygon"); - return result; + SG_LOG(SG_GENERAL, SG_DEBUG, "Error: 0 contour polygon"); + return result; } // clip each contour individually @@ -550,23 +527,23 @@ TGPolygon horizontal_clip( const TGPolygon& in, const double y, point_list contour; for ( int i = 0; i < in.contours(); ++i ) { - if ( (int)in.contour_size( i ) < 3 ) { - SG_LOG(SG_GENERAL, SG_DEBUG, "we must have at least three vertices to work"); - return result; - } + if ( (int)in.contour_size( i ) < 3 ) { + SG_LOG(SG_GENERAL, SG_DEBUG, "we must have at least three vertices to work"); + return result; + } - tmp_poly.erase(); + tmp_poly.erase(); - contour = in.get_contour( i ); - tmp_poly.add_contour( contour, 0 ); + contour = in.get_contour( i ); + tmp_poly.add_contour( contour, 0 ); - clip_contour( tmp_poly, y, side, clip_poly ); + clip_contour( tmp_poly, y, side, clip_poly ); - // add each clip_poly contour to the result poly - for ( int j = 0; j < clip_poly.contours(); ++j ) { - contour = clip_poly.get_contour( j ); - result.add_contour( contour, 0 ); - } + // add each clip_poly contour to the result poly + for ( int j = 0; j < clip_poly.contours(); ++j ) { + contour = clip_poly.get_contour( j ); + result.add_contour( contour, 0 ); + } } return result; diff --git a/src/Lib/Polygon/simple_clip.hxx b/src/Lib/Polygon/simple_clip.hxx index 816edb54..19b91e01 100644 --- a/src/Lib/Polygon/simple_clip.hxx +++ b/src/Lib/Polygon/simple_clip.hxx @@ -44,7 +44,7 @@ enum fgSideType { // results. Doesn't work with holes. Returns true if routine thinks // it was successful. -TGPolygon horizontal_clip( const TGPolygon& in, const double y, +TGPolygon horizontal_clip( const TGPolygon& in, const double y, const fgSideType side ); diff --git a/src/Lib/Polygon/superpoly.cxx b/src/Lib/Polygon/superpoly.cxx index 65b5d6e7..7ba7a3dc 100644 --- a/src/Lib/Polygon/superpoly.cxx +++ b/src/Lib/Polygon/superpoly.cxx @@ -26,18 +26,20 @@ // Constructor TGSuperPoly::TGSuperPoly() : -flag( "" ) + flag( "" ) { } // Destructor -TGSuperPoly::~TGSuperPoly() { +TGSuperPoly::~TGSuperPoly() +{ } // erase the "super" polygon -void TGSuperPoly::erase() { +void TGSuperPoly::erase() +{ material = ""; poly.erase(); normals.erase(); diff --git a/src/Lib/Polygon/superpoly.hxx b/src/Lib/Polygon/superpoly.hxx index 1f54de92..a062fb08 100644 --- a/src/Lib/Polygon/superpoly.hxx +++ b/src/Lib/Polygon/superpoly.hxx @@ -25,9 +25,9 @@ #define _SUPERPOLY_HXX -#ifndef __cplusplus +#ifndef __cplusplus # error This library requires C++ -#endif +#endif #include @@ -42,39 +42,75 @@ class TGSuperPoly { private: - std::string material; // material/texture name - TGPolygon poly; // master polygon - TGPolygon normals; // corresponding normals - TGPolygon texcoords; // corresponding texture coordinates - TGPolygon tris; // triangulation - std::string flag; // For various potential record keeping needs +std::string material; // material/texture name +TGPolygon poly; // master polygon +TGPolygon normals; // corresponding normals +TGPolygon texcoords; // corresponding texture coordinates +TGPolygon tris; // triangulation +std::string flag; // For various potential record keeping needs public: - // Constructor and destructor - TGSuperPoly( void ); - ~TGSuperPoly( void ); +// Constructor and destructor +TGSuperPoly( void ); +~TGSuperPoly( void ); - inline std::string get_material() const { return material; } - inline void set_material( const std::string &m ) { material = m; } +inline std::string get_material() const +{ + return material; +} +inline void set_material( const std::string &m ) +{ + material = m; +} - inline TGPolygon get_poly() const { return poly; } - inline void set_poly( const TGPolygon &p ) { poly = p; } +inline TGPolygon get_poly() const +{ + return poly; +} +inline void set_poly( const TGPolygon &p ) +{ + poly = p; +} - inline TGPolygon get_normals() const { return normals; } - inline void set_normals( const TGPolygon &p ) { normals = p; } +inline TGPolygon get_normals() const +{ + return normals; +} +inline void set_normals( const TGPolygon &p ) +{ + normals = p; +} - inline TGPolygon get_texcoords() const { return texcoords; } - inline void set_texcoords( const TGPolygon &p ) { texcoords = p; } +inline TGPolygon get_texcoords() const +{ + return texcoords; +} +inline void set_texcoords( const TGPolygon &p ) +{ + texcoords = p; +} - inline TGPolygon get_tris() const { return tris; } - inline void set_tris( const TGPolygon &p ) { tris = p; } +inline TGPolygon get_tris() const +{ + return tris; +} +inline void set_tris( const TGPolygon &p ) +{ + tris = p; +} - inline std::string get_flag() const { return flag; } - inline void set_flag( const std::string f ) { flag = f; } +inline std::string get_flag() const +{ + return flag; +} +inline void set_flag( const std::string f ) +{ + flag = f; +} - // erase the polygon - void erase(); +// erase the polygon +void erase(); }; diff --git a/src/Lib/Polygon/texparams.hxx b/src/Lib/Polygon/texparams.hxx index dec7dadc..80487a7b 100644 --- a/src/Lib/Polygon/texparams.hxx +++ b/src/Lib/Polygon/texparams.hxx @@ -26,9 +26,9 @@ #define _TEXPARAMS_HXX -#ifndef __cplusplus +#ifndef __cplusplus # error This library requires C++ -#endif +#endif #include @@ -40,55 +40,108 @@ class TGTexParams { private: - Point3D ref; - double width; - double length; - double heading; +Point3D ref; +double width; +double length; +double heading; - double minu; - double maxu; - double minv; - double maxv; +double minu; +double maxu; +double minv; +double maxv; public: - // Constructor and destructor - inline TGTexParams( void ) { } - inline TGTexParams( const Point3D &r, const double w, const double l, - const double h ) { - ref = r; - width = w; - length = l; - heading = h; +// Constructor and destructor +inline TGTexParams( void ) +{ +} +inline TGTexParams( const Point3D &r, const double w, const double l, + const double h ) +{ + ref = r; + width = w; + length = l; + heading = h; - minu = minv = 0.0; - maxu = maxv = 1.0; - } - inline ~TGTexParams( void ) { } + minu = minv = 0.0; + maxu = maxv = 1.0; +} +inline ~TGTexParams( void ) +{ +} - inline Point3D get_ref() const { return ref; } - inline void set_ref( const Point3D &r ) { ref = r; } +inline Point3D get_ref() const +{ + return ref; +} +inline void set_ref( const Point3D &r ) +{ + ref = r; +} - inline double get_width() const { return width; } - inline void set_width( const double w ) { width = w; } +inline double get_width() const +{ + return width; +} +inline void set_width( const double w ) +{ + width = w; +} - inline double get_length() const { return length; } - inline void set_length( const double l ) { length = l; } +inline double get_length() const +{ + return length; +} +inline void set_length( const double l ) +{ + length = l; +} - inline double get_heading() const { return heading; } - inline void set_heading( const double h ) { heading = h; } +inline double get_heading() const +{ + return heading; +} +inline void set_heading( const double h ) +{ + heading = h; +} - inline double get_minu() const { return minu; } - inline void set_minu( const double x ) { minu = x; } +inline double get_minu() const +{ + return minu; +} +inline void set_minu( const double x ) +{ + minu = x; +} - inline double get_maxu() const { return maxu; } - inline void set_maxu( const double x ) { maxu = x; } +inline double get_maxu() const +{ + return maxu; +} +inline void set_maxu( const double x ) +{ + maxu = x; +} - inline double get_minv() const { return minv; } - inline void set_minv( const double x ) { minv = x; } +inline double get_minv() const +{ + return minv; +} +inline void set_minv( const double x ) +{ + minv = x; +} - inline double get_maxv() const { return maxv; } - inline void set_maxv( const double x ) { maxv = x; } +inline double get_maxv() const +{ + return maxv; +} +inline void set_maxv( const double x ) +{ + maxv = x; +} };