diff --git a/src/Airports/GenAirports850/main.cxx b/src/Airports/GenAirports850/main.cxx index 84d80f5b..ad9bc3b8 100644 --- a/src/Airports/GenAirports850/main.cxx +++ b/src/Airports/GenAirports850/main.cxx @@ -284,10 +284,6 @@ int main(int argc, char **argv) std::string lastaptfile = work_dir+"/last_apt"; - // initialize persistant polygon counter - std::string counter_file = airportareadir+"/poly_counter"; - tgPolygon::ChopIdxInit( counter_file ); - tg::Rectangle boundingBox(min, max); boundingBox.sanify(); diff --git a/src/BuildTiles/Main/tgconstruct.hxx b/src/BuildTiles/Main/tgconstruct.hxx index 5c9f830a..5384fddd 100644 --- a/src/BuildTiles/Main/tgconstruct.hxx +++ b/src/BuildTiles/Main/tgconstruct.hxx @@ -125,8 +125,9 @@ private: // Clip Data bool ClipLandclassPolys( void ); + // Clip Helpers - void move_slivers( TGPolygon& in, TGPolygon& out ); +// void move_slivers( TGPolygon& in, TGPolygon& out ); void merge_slivers( TGLandclass& clipped, tgcontour_list& sliver_list ); // Shared edge Matching @@ -192,11 +193,11 @@ public: void ConstructBucketStage3(); int load_landcover (); - double measure_roughness( TGPolygon &poly ); +// double measure_roughness( TGPolygon &poly ); AreaType get_landcover_type (const LandCover &cover, double xpos, double ypos, double dx, double dy); - void make_area( const LandCover &cover, TGPolygon *polys, - double x1, double y1, double x2, double y2, - double half_dx, double half_dy ); +// void make_area( const LandCover &cover, TGPolygon *polys, +// double x1, double y1, double x2, double y2, +// double half_dx, double half_dy ); // land cover file inline std::string get_cover () const { return cover; } diff --git a/src/BuildTiles/Main/tgconstruct_landclass.cxx b/src/BuildTiles/Main/tgconstruct_landclass.cxx index 76166f74..a99dc294 100644 --- a/src/BuildTiles/Main/tgconstruct_landclass.cxx +++ b/src/BuildTiles/Main/tgconstruct_landclass.cxx @@ -46,6 +46,7 @@ static const double quarter_cover_size = cover_size * 0.25; // make the area specified area, look up the land cover type, and add // it to polys +#if 0 void TGConstruct::make_area( const LandCover &cover, TGPolygon *polys, double x1, double y1, double x2, double y2, double half_dx, double half_dy ) @@ -75,9 +76,11 @@ void TGConstruct::make_area( const LandCover &cover, TGPolygon *polys, } } } +#endif // Come up with a "rough" metric for the roughness of the terrain // coverted by a polygon +#if 0 double TGConstruct::measure_roughness( TGPolygon &poly ) { int i; unsigned int j; @@ -116,6 +119,7 @@ double TGConstruct::measure_roughness( TGPolygon &poly ) { return diff / 50.0; } +#endif AreaType TGConstruct::get_landcover_type (const LandCover &cover, double xpos, double ypos, double dx, double dy) { diff --git a/src/Lib/Polygon/CMakeLists.txt b/src/Lib/Polygon/CMakeLists.txt index 5ce94618..7791b411 100644 --- a/src/Lib/Polygon/CMakeLists.txt +++ b/src/Lib/Polygon/CMakeLists.txt @@ -16,7 +16,5 @@ add_library(Polygon STATIC tg_unique_vec2f.hxx tg_unique_vec3d.hxx tg_unique_vec3f.hxx - trinodes.cxx - trinodes.hxx point3d.hxx -) +) \ No newline at end of file diff --git a/src/Lib/Polygon/polygon.cxx b/src/Lib/Polygon/polygon.cxx index 96e8ad68..fe20481b 100644 --- a/src/Lib/Polygon/polygon.cxx +++ b/src/Lib/Polygon/polygon.cxx @@ -23,6 +23,9 @@ #include #include +#include +#include + #include #include #include @@ -30,9 +33,10 @@ #include #include #include +#include +#include #include -#include #include "polygon.hxx" @@ -41,117 +45,24 @@ # define LONG_LONG_MIN LLONG_MIN #endif -using std::endl; -using std::cout; - -// Constructor -TGPolygon::TGPolygon( void ) -{ -} +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// NEW IMPLEMENTATIONS +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// Destructor -TGPolygon::~TGPolygon( void ) { -} +#include +#include -void TGPolygon::get_bounding_box( SGGeod& min, SGGeod& max ) const -{ - double minx = std::numeric_limits::infinity(); - double miny = std::numeric_limits::infinity(); - double maxx = -std::numeric_limits::infinity(); - double maxy = -std::numeric_limits::infinity(); +#include +#include +#include +#include +#include +#include - for ( int i = 0; i < contours(); i++ ) { - for (unsigned int j = 0; j < poly[i].size(); j++) { - SGGeod pt = poly[i][j].toSGGeod(); - if ( pt.getLongitudeDeg() < minx ) { minx = pt.getLongitudeDeg(); } - if ( pt.getLongitudeDeg() > maxx ) { maxx = pt.getLongitudeDeg(); } - if ( pt.getLatitudeDeg() < miny ) { miny = pt.getLatitudeDeg(); } - if ( pt.getLatitudeDeg() > maxy ) { maxy = pt.getLatitudeDeg(); } - } - } - min = SGGeod::fromDeg( minx, miny ); - max = SGGeod::fromDeg( maxx, maxy ); -} - -#if 0 -// 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 ) { - TGTriNodes nodes; - nodes.clear(); - - int i, j; - - // build a list of points from the source and dest polygons - - for ( i = 0; i < source.contours(); ++i ) { - for ( j = 0; j < source.contour_size(i); ++j ) { - Point3D p = source.get_pt( i, j ); - nodes.unique_add( p ); - } - } - - // traverse the dest polygon and build a mirror image but with - // elevations from the source polygon - - for ( i = 0; i < (int)poly.size(); ++i ) { - for ( j = 0; j < (int)poly[i].size(); ++j ) { - Point3D p = poly[i][j]; - int index = nodes.find( p ); - if ( index >= 0 ) { - Point3D ref = nodes.get_node( index ); - poly[i][j].setz( ref.z() ); - } - } - } - - // now post process result to catch any nodes that weren't updated - // (because the clipping process may have added points which - // weren't in the original.) - - double last = -9999.0; - for ( i = 0; i < (int)poly.size(); ++i ) { - // go front ways - last = -9999.0; - for ( j = 0; j < (int)poly[i].size(); ++j ) { - Point3D p = poly[i][j]; - if ( p.z() > -9000 ) { - last = p.z(); - } 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 ) { - last = p.z(); - } else { - if ( last > -9000 ) { - poly[i][j].setz( last ); - } - } - } - } -} -#endif - -// 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 ) { - poly[i][j].setz( elev ); - } - } -} +// TODO : Where does this belong // Calculate theta of angle (a, b, c) double tgPolygonCalcAngle(SGVec2d a, SGVec2d b, SGVec2d c) { SGVec2d u, v; @@ -170,900 +81,6 @@ double tgPolygonCalcAngle(SGVec2d a, SGVec2d b, SGVec2d c) { return acos(uv_dot / (udist * vdist)); } -// return the perimeter of a contour (assumes simple polygons, -// i.e. non-self intersecting.) -// -// negative areas indicate counter clockwise winding -// positive areas indicate clockwise winding. - -double TGPolygon::area_contour( const int contour ) const { - point_list c = poly[contour]; - double area = 0.0; - unsigned int i, j; - - if (c.size()) { - j = c.size() - 1; - for (i=0; i= size ) { - p3_index -= size; - } - - p1.x() = c[p1_index].x(); - p1.y() = c[p1_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(); - - angle = tgPolygonCalcAngle( p1, p2, p3 ); - - if ( angle < min_angle ) { - min_angle = angle; - } - } - - return min_angle; -} - -// return true if contour A is inside countour B -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(); - - pl = get_contour( a ); - A.add_contour( pl, 0 ); - - pl = get_contour( b ); - B.add_contour( pl, 0 ); - - // SG_LOG(SG_GENERAL, SG_DEBUG, "A size = " << A.total_size()); - // A.write( "A" ); - // SG_LOG(SG_GENERAL, SG_DEBUG, "B size = " << B.total_size()); - // B.write( "B" ); - - // A is "inside" B if the polygon_diff( A, B ) is null. - TGPolygon result = tgPolygonDiff( A, B ); - // SG_LOG(SG_GENERAL, SG_DEBUG, "result size = " << result.total_size()); - - // char junk; - // cin >> junk; - - 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; -} - - -// shift every point in the polygon by lon, 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 ); - } - } -} - - -// output -void TGPolygon::write( const std::string& file ) const { - FILE *fp = fopen( file.c_str(), "w" ); - - fprintf(fp, "%ld\n", poly.size()); - for ( int i = 0; i < (int)poly.size(); ++i ) { - fprintf(fp, "%ld\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()); - } - - fclose(fp); -} - - -// Move slivers from in polygon to out polygon. -void tgPolygonFindSlivers( TGPolygon& in, poly_list& slivers ) -{ - // traverse each contour of the polygon and attempt to identify - // likely slivers - - SG_LOG(SG_GENERAL, SG_DEBUG, "tgPolygonFindSlivers()"); - - TGPolygon out; - int i; - - out.erase(); - - double angle_cutoff = 10.0 * SGD_DEGREES_TO_RADIANS; - double area_cutoff = 0.000000001; - double min_angle; - double area; - - point_list contour; - int hole_flag; - - // process contours in reverse order so deleting a contour doesn't - // foul up our sequence - for ( i = in.contours() - 1; i >= 0; --i ) { - SG_LOG(SG_GENERAL, SG_DEBUG, "contour " << i ); - - min_angle = in.minangle_contour( i ); - area = in.area_contour( i ); - - SG_LOG(SG_GENERAL, SG_DEBUG, " min_angle (rad) = " << min_angle ); - SG_LOG(SG_GENERAL, SG_DEBUG, " min_angle (deg) = " << min_angle * 180.0 / SGD_PI ); - SG_LOG(SG_GENERAL, SG_DEBUG, " area = " << area ); - - if ( ((min_angle < angle_cutoff) && (area < area_cutoff)) || - ( area < area_cutoff / 10.0) ) - { - if ((min_angle < angle_cutoff) && (area < area_cutoff)) - { - SG_LOG(SG_GENERAL, SG_DEBUG, " WE THINK IT'S A SLIVER! - min angle < 10 deg, and area < 10 sq meters"); - } - else - { - SG_LOG(SG_GENERAL, SG_DEBUG, " WE THINK IT'S A SLIVER! - min angle > 10 deg, but area < 1 sq meters"); - } - - // check if this is a hole - hole_flag = in.get_hole_flag( i ); - - if ( hole_flag ) { - // just delete/eliminate/remove sliver holes - // cout << "just deleting a sliver hole" << endl; - in.delete_contour( i ); - } else { - // move sliver contour to out polygon - SG_LOG(SG_GENERAL, SG_INFO, " Found SLIVER!"); - - contour = in.get_contour( i ); - in.delete_contour( i ); - out.add_contour( contour, hole_flag ); - } - } - } - - if ( out.contours() ) - { - slivers.push_back( out ); - } -} - - - -// output -void TGPolygon::write_contour( const int contour, const std::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()); - } - - fclose(fp); -} - -// Set operation type -typedef enum { - POLY_DIFF, // Difference - POLY_INT, // Intersection - POLY_XOR, // Exclusive or - POLY_UNION // Union -} clip_op; - - -#define FIXEDPT (10000000000000000) -#define FIXED1M ( 90090) - - -static ClipperLib::IntPoint MakeClipperPoint( Point3D pt ) -{ - ClipperLib::long64 x, y; - - x = (ClipperLib::long64)( pt.x() * FIXEDPT ); - y = (ClipperLib::long64)( pt.y() * FIXEDPT ); - - return ClipperLib::IntPoint( x, y ); -} - -static Point3D MakeTGPoint( ClipperLib::IntPoint pt ) -{ - Point3D tg_pt; - double x, y; - - x = (double)( ((double)pt.X) / (double)FIXEDPT ); - y = (double)( ((double)pt.Y) / (double)FIXEDPT ); - - tg_pt = Point3D( x, y, -9999.0f); - - return tg_pt; -} - -static SGGeod MakeSGGeod( ClipperLib::IntPoint pt ) -{ - double x, y; - x = (double)( ((double)pt.X) / (double)FIXEDPT ); - y = (double)( ((double)pt.Y) / (double)FIXEDPT ); - - return SGGeod::fromDeg(x, y); -} - -double MakeClipperDelta( double mDelta ) -{ - double cDelta = mDelta * ( FIXEDPT / FIXED1M ); - - // SG_LOG(SG_GENERAL, SG_INFO, "mdelta:" << mDelta << " is " << cDelta ); - - return( cDelta ); -} - -static void make_clipper_poly( const TGPolygon& in, ClipperLib::Polygons *out ) -{ - ClipperLib::Polygon contour; - Point3D p; - int i, j; - - for (i=0; ipush_back(contour); - } -} - -void make_tg_poly_from_clipper( const ClipperLib::Polygons& in, TGPolygon *out ) -{ - out->erase(); - - // for each polygon, we need to check the orientation, to set the hole flag... - for (unsigned int i=0; iadd_node( i, MakeTGPoint(ip) ); - } - - if ( Orientation( in[i] ) ) { - //SG_LOG(SG_GENERAL, SG_INFO, "Building TG Poly : contour " << i << " is boundary " ); - out->set_hole_flag(i, 0); - } else { - //SG_LOG(SG_GENERAL, SG_INFO, "Building TG Poly : contour " << i << " is hole " ); - out->set_hole_flag(i, 1); - } - } -} - - -void get_Clipper_bounding_box( const ClipperLib::Polygons& in, SGGeod& min, SGGeod& max ) -{ - ClipperLib::IntPoint min_pt, max_pt; - - min_pt.X = min_pt.Y = LONG_LONG_MAX; - max_pt.X = max_pt.Y = LONG_LONG_MIN; - - // for each polygon, we need to check the orientation, to set the hole flag... - for (unsigned int i=0; i max_pt.X ) { - max_pt.X = in[i][j].X; - } - if ( in[i][j].Y > max_pt.Y ) { - max_pt.Y = in[i][j].Y; - } - } - } - - min = MakeSGGeod( min_pt ); - max = MakeSGGeod( max_pt ); -} - -void clipper_to_shapefile( ClipperLib::Polygons polys, char* ds ) -{ - ClipperLib::Polygons contour; - TGPolygon tgcontour; - char layer[32]; - - void* ds_id = tgShapefile::OpenDatasource( ds ); - - for (unsigned int i = 0; i < polys.size(); ++i) { - if ( Orientation( polys[i] ) ) { - sprintf( layer, "%04d_boundary", i ); - } else { - sprintf( layer, "%04d_hole", i ); - } - - void* l_id = tgShapefile::OpenLayer( ds_id, layer ); - contour.clear(); - contour.push_back( polys[i] ); - - tgcontour.erase(); - make_tg_poly_from_clipper( contour, &tgcontour ); - - tgShapefile::CreateFeature( ds_id, l_id, tgcontour, "contour" ); - } - - // close after each write - ds_id = tgShapefile::CloseDatasource( ds_id ); -} - -TGPolygon polygon_clip_clipper( clip_op poly_op, const TGPolygon& subject, const TGPolygon& clip ) -{ - TGPolygon result; - - ClipperLib::Polygons clipper_subject; - make_clipper_poly( subject, &clipper_subject ); - - ClipperLib::Polygons clipper_clip; - make_clipper_poly( clip, &clipper_clip ); - - ClipperLib::Polygons clipper_result; - - ClipperLib::ClipType op; - if ( poly_op == POLY_DIFF ) { - op = ClipperLib::ctDifference; - } else if ( poly_op == POLY_INT ) { - op = ClipperLib::ctIntersection; - } else if ( poly_op == POLY_XOR ) { - op = ClipperLib::ctXor; - } else if ( poly_op == POLY_UNION ) { - op = ClipperLib::ctUnion; - } else { - throw sg_exception("Unknown polygon op, exiting."); - } - - ClipperLib::Clipper c; - c.Clear(); - c.AddPolygons(clipper_subject, ClipperLib::ptSubject); - c.AddPolygons(clipper_clip, ClipperLib::ptClip); - - c.Execute(op, clipper_result, ClipperLib::pftEvenOdd, ClipperLib::pftEvenOdd); - - make_tg_poly_from_clipper( clipper_result, &result ); - - return result; -} - - -// Difference -TGPolygon tgPolygonDiff( const TGPolygon& subject, const TGPolygon& clip ) { - return polygon_clip_clipper( POLY_DIFF, subject, clip ); -} - -// Intersection -TGPolygon tgPolygonInt( const TGPolygon& subject, const TGPolygon& clip ) { - return polygon_clip_clipper( POLY_INT, subject, clip ); -} - -// Exclusive or -TGPolygon tgPolygonXor( const TGPolygon& subject, const TGPolygon& clip ) { - return polygon_clip_clipper( POLY_XOR, subject, clip ); -} - -// Union -TGPolygon tgPolygonUnion( const TGPolygon& subject, const TGPolygon& clip ) { - return polygon_clip_clipper( POLY_UNION, subject, clip ); -} - -TGPolygon tgPolygonUnion( const poly_list& clips ) -{ - ClipperLib::Polygons clipper_result; - ClipperLib::Clipper c; - TGPolygon result; - - c.Clear(); - for (unsigned int i=0; i ClipperPolysList; -ClipperPolysList clipper_accumulator; - -void tgPolygonInitClipperAccumulator( void ) -{ - clipper_accumulator.clear(); -} - -void tgPolygonFreeClipperAccumulator( void ) -{ - clipper_accumulator.clear(); -} - -void tgPolygonDumpAccumulator( char* ds, char* layer, char* name ) -{ - void* ds_id = tgShapefile::OpenDatasource( ds ); - void* l_id = tgShapefile::OpenLayer( ds_id, layer ); - TGPolygon accum; - - for (unsigned 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 ); - } - } - - return result; -} - - -// 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 ) { - 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 ( 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 ); - } - } 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 ) ); - } - - SG_LOG(SG_GENERAL, SG_DEBUG, "split_long_edges() complete"); - - return result; -} - - -// Traverse a polygon and return the union of all the non-hole contours -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) ) { - TGPolygon tmp; - tmp.add_contour( contour, poly.get_hole_flag(i) ); - result = tgPolygonUnion( tmp, result ); - } - } - - return result; -} - -void PrintClipperPoly( ClipperLib::Polygons polys ) -{ - int nContours = polys.size(); - - SG_LOG(SG_GENERAL, SG_INFO, "CLIPPER POLY : contours " << nContours ); - - for (int i = 0; i < nContours; i++) { - int nPoints = polys[i].size(); - SG_LOG(SG_GENERAL, SG_INFO, nPoints ); - - for (int j = 0; j < nPoints; j++) { - SG_LOG(SG_GENERAL, SG_INFO, "(" << polys[i][j].X << "," << polys[i][j].Y << ")" ); - } - } -} - -TGPolygon tgPolygonExpand(const TGPolygon &poly, double delta) -{ - TGPolygon result; - - ClipperLib::Polygons clipper_src, clipper_dst; - - make_clipper_poly( poly, &clipper_src ); - - //SG_LOG(SG_GENERAL, SG_INFO, "Clipper Source" ); - //PrintClipperPoly( clipper_src ); - - // convert delta from meters to clipper units - OffsetPolygons( clipper_src, clipper_dst, MakeClipperDelta(delta) ); - - //SG_LOG(SG_GENERAL, SG_INFO, "Clipper Dest" ); - //PrintClipperPoly( clipper_dst ); - - make_tg_poly_from_clipper( clipper_dst, &result ); - - return result; -} - -TGPolygon tgPolygonSimplify(const TGPolygon &poly) -{ - TGPolygon result; - ClipperLib::Polygons clipper_poly; - - make_clipper_poly( poly, &clipper_poly ); - - SimplifyPolygons(clipper_poly); - - make_tg_poly_from_clipper( clipper_poly, &result ); - - return result; -} - - -// Send a polygon to standard output. -std::ostream& operator << (std::ostream &output, const TGPolygon &poly) -{ - int nContours = poly.contours(); - - // Save the number of contours - output << nContours << "\n"; - for (int i = 0; i < nContours; i++) { - int nPoints = poly.contour_size(i); - - // Save number of points in the contour - output << nPoints << "\n"; - - // Then save the points - for ( int j = 0; j < nPoints; j++ ) { - output << poly.get_pt(i, j).x() << " "; - output << poly.get_pt(i, j).y() << " "; - output << poly.get_pt(i, j).z() << "\n"; - } - - // Then save contour hole flag - output << poly.get_hole_flag(i) << "\n"; - } - - return output; -} - -void TGPolygon::SaveToGzFile(gzFile& fp) const -{ - int nContours = poly.size(); - - // Save the number of contours - sgWriteInt( fp, nContours ); - for (int i = 0; i < nContours; i++) { - int nPoints = poly[i].size(); - - // Save number of points in the contour - sgWriteInt( fp, nPoints ); - - // Then save the points - for ( int j = 0; j < nPoints; j++ ) { - sgWritePoint3D( fp, poly[i][j] ); - } - - sgWriteInt( fp, hole_list[i] ); - } -} -// Read a polygon from input buffer. -std::istream& operator >> (std::istream &input, TGPolygon &poly) -{ - int nContours; - double x, y, z; - - // Read the number of contours - input >> nContours; - for (int i = 0; i < nContours; i++) { - int nPoints; - int hole; - - // Read number of points in the contour - input >> nPoints; - - // Then read the points - for ( int j = 0; j < nPoints; j++ ) { - input >> x; - input >> y; - input >> z; - - poly.add_node(i, Point3D(x,y,z)); - } - - // Then read contour hole flag - input >> hole; - poly.set_hole_flag(i, hole); - } - - return input; -} - -void TGPolygon::LoadFromGzFile(gzFile& fp) -{ - int nContours; - int nPoints; - int hole; - Point3D pt; - - // Save the number of contours - sgReadInt( fp, &nContours ); - for (int i = 0; i < nContours; i++) { - sgReadInt( fp, &nPoints ); - - // Then read the points - for ( int j = 0; j < nPoints; j++ ) { - sgReadPoint3D( fp, pt ); - add_node( i, pt ); - } - - sgReadInt( fp, &hole ); - set_hole_flag( i, hole ); - } -} - - - - - - - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// NEW IMPLEMENTATIONS -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - -#include -#include - -#include -#include -#include -#include -#include -#include @@ -1857,11 +874,11 @@ tg::Rectangle tgContour::GetBoundingBox( void ) const tgPolygon tgContour::Diff( const tgContour& subject, tgPolygon& clip ) { tgPolygon result; - TGTriNodes all_nodes; + UniqueSGGeodSet all_nodes; /* before diff - gather all nodes */ for ( unsigned int i = 0; i < subject.GetSize(); ++i ) { - all_nodes.unique_add( Point3D::fromSGGeod( subject.GetNode(i) ) ); + all_nodes.add( subject.GetNode(i) ); } ClipperLib::Polygon clipper_subject = tgContour::ToClipper( subject ); @@ -1883,11 +900,11 @@ tgPolygon tgContour::Diff( const tgContour& subject, tgPolygon& clip ) tgPolygon tgPolygon::Union( const tgContour& subject, tgPolygon& clip ) { tgPolygon result; - TGTriNodes all_nodes; + UniqueSGGeodSet all_nodes; /* before diff - gather all nodes */ for ( unsigned int i = 0; i < subject.GetSize(); ++i ) { - all_nodes.unique_add( Point3D::fromSGGeod( subject.GetNode(i) )); + all_nodes.add( subject.GetNode(i) ); } ClipperLib::Polygon clipper_subject = tgContour::ToClipper( subject ); @@ -1906,11 +923,11 @@ tgPolygon tgPolygon::Union( const tgContour& subject, tgPolygon& clip ) return result; } -tgContour tgContour::AddColinearNodes( const tgContour& subject, TGTriNodes nodes ) +tgContour tgContour::AddColinearNodes( const tgContour& subject, UniqueSGGeodSet& nodes ) { SGGeod p0, p1; tgContour result; - point_list tmp_nodes = nodes.get_node_list(); + std::vector& tmp_nodes = nodes.get_list(); for ( unsigned int n = 0; n < subject.GetSize()-1; n++ ) { p0 = subject.GetNode( n ); @@ -2143,12 +1160,12 @@ tgPolygon tgPolygon::SplitLongEdges( const tgPolygon& subject, double dist ) tgPolygon tgPolygon::StripHoles( const tgPolygon& subject ) { tgPolygon result; - TGTriNodes all_nodes; + UniqueSGGeodSet all_nodes; /* before diff - gather all nodes */ for ( unsigned int i = 0; i < subject.Contours(); ++i ) { for ( unsigned int j = 0; j < subject.ContourSize( i ); ++j ) { - all_nodes.unique_add( Point3D::fromSGGeod( subject.GetNode(i, j) ) ); + all_nodes.add( subject.GetNode(i, j) ); } } @@ -2176,12 +1193,12 @@ tgPolygon tgPolygon::StripHoles( const tgPolygon& subject ) tgPolygon tgPolygon::Simplify( const tgPolygon& subject ) { tgPolygon result; - TGTriNodes all_nodes; + UniqueSGGeodSet all_nodes; /* before diff - gather all nodes */ for ( unsigned int i = 0; i < subject.Contours(); ++i ) { for ( unsigned int j = 0; j < subject.ContourSize( i ); ++j ) { - all_nodes.unique_add( Point3D::fromSGGeod( subject.GetNode(i, j) ) ); + all_nodes.add( subject.GetNode(i, j) ); } } @@ -2213,7 +1230,7 @@ tgPolygon tgPolygon::RemoveTinyContours( const tgPolygon& subject ) SG_LOG(SG_GENERAL, SG_DEBUG, "remove_tiny_contours NO - " << c << " area is " << area << " requirement is " << min_area); result.AddContour( contour ); } else { - SG_LOG(SG_GENERAL, SG_INFO, "remove_tiny_contours " << c << " area is " << area << ": removing"); + SG_LOG(SG_GENERAL, SG_DEBUG, "remove_tiny_contours " << c << " area is " << area << ": removing"); } } @@ -2284,29 +1301,6 @@ tgPolygon tgPolygon::Expand( const tgPolygon& subject, double offset ) return result; } -#if 0 -inline double CalculateTheta( const SGGeod& p0, const SGGeod& p1, const SGGeod& p2 ) -{ - SGVec2d v0, v1, v2; - SGVec2d u, v; - double udist, vdist, uv_dot; - - v0 = SGVec2d( p0.getLongitudeDeg(), p0.getLatitudeDeg() ); - v1 = SGVec2d( p1.getLongitudeDeg(), p1.getLatitudeDeg() ); - v2 = SGVec2d( p2.getLongitudeDeg(), p2.getLatitudeDeg() ); - - u = v1 - v0; - udist = norm(u); - - v = v1 - v2; - vdist = norm(v); - - uv_dot = dot(u, v); - - return acos( uv_dot / (udist * vdist) ); -} -#endif - inline double CalculateTheta( const SGVec3d& dirCur, const SGVec3d& dirNext, const SGVec3d& cp ) { double dp = dot( dirCur, dirNext ); @@ -2445,8 +1439,6 @@ bool getIntersection_cgal(const SGGeod &p0, const SGGeod &p1, const SGGeod& p2, } } -#include - tgPolygon tgPolygon::Expand( const SGGeod& subject, double offset ) { tgPolygon result; @@ -2482,9 +1474,6 @@ tgpolygon_list tgContour::ExpandToPolygons( const tgContour& subject, double wid SGGeod calc_outer; double last_end_v = 0.0f; -// double heading = 0.0f; -// double az2 = 0.0f; -// double dist = 0.0f; tgContour expanded; tgPolygon segment; @@ -2594,14 +1583,14 @@ tgpolygon_list tgContour::ExpandToPolygons( const tgContour& subject, double wid tgPolygon tgPolygon::Union( const tgPolygon& subject, tgPolygon& clip ) { - tgPolygon result; - TGTriNodes all_nodes; - std::ofstream dmpfile; + tgPolygon result; + UniqueSGGeodSet all_nodes; + std::ofstream dmpfile; /* before union - gather all nodes */ for ( unsigned int i = 0; i < subject.Contours(); ++i ) { for ( unsigned int j = 0; j < subject.ContourSize( i ); ++j ) { - all_nodes.unique_add( Point3D::fromSGGeod( subject.GetNode(i, j) ) ); + all_nodes.add( subject.GetNode(i, j) ); } } @@ -2644,14 +1633,14 @@ tgPolygon tgPolygon::Union( const tgpolygon_list& polys ) { ClipperLib::Polygons clipper_result; ClipperLib::Clipper c; - TGTriNodes all_nodes; + UniqueSGGeodSet all_nodes; tgPolygon result; /* before union - gather all nodes */ for ( unsigned int i=0; i -#include // initialize the unique polygon index counter stored in path static long int poly_index = 0; @@ -3222,6 +2210,7 @@ bool tgPolygon::ChopIdxInit( const std::string& path ) return true; } +#endif /************************ TESSELATION ***********************************/ @@ -3463,11 +2452,11 @@ std::ostream& operator<< ( std::ostream& output, const tgTexParams& subject ) tgPolygon tgAccumulator::Diff( const tgContour& subject ) { tgPolygon result; - TGTriNodes all_nodes; + UniqueSGGeodSet all_nodes; /* before diff - gather all nodes */ for ( unsigned int i = 0; i < subject.GetSize(); ++i ) { - all_nodes.unique_add( Point3D::fromSGGeod( subject.GetNode(i) )); + all_nodes.add( subject.GetNode(i) ); } unsigned int num_hits = 0; @@ -3530,12 +2519,12 @@ void tgAccumulator::ToShapefiles( const std::string& path, const std::string& la tgPolygon tgAccumulator::Diff( const tgPolygon& subject ) { tgPolygon result; - TGTriNodes all_nodes; + UniqueSGGeodSet all_nodes; /* before diff - gather all nodes */ for ( unsigned int i = 0; i < subject.Contours(); ++i ) { for ( unsigned int j = 0; j < subject.ContourSize( i ); ++j ) { - all_nodes.unique_add( Point3D::fromSGGeod( subject.GetNode(i, j) ) ); + all_nodes.add( subject.GetNode(i, j) ); } } @@ -3892,9 +2881,6 @@ void tgChopper::Add( const tgPolygon& subject, const std::string& type ) } } -#include -#include - long int tgChopper::GenerateIndex( std::string path ) { std::string index_file = path + "/chop.idx"; @@ -4034,50 +3020,6 @@ void* tgShapefile::OpenLayer( void* ds_id, const char* layer_name ) { return (void*)layer; } -void tgShapefile::CreateFeature( void* ds_id, void* l_id, const TGPolygon &poly, const char* description ) -{ - OGRLayer* layer = (OGRLayer*)l_id; - OGRPolygon* polygon = new OGRPolygon(); - - for ( int i = 0; i < poly.contours(); i++ ) { - bool skip_ring=false; - point_list contour = poly.get_contour( i ); - - if (contour.size()<3) { - SG_LOG(SG_GENERAL, SG_DEBUG, "Polygon with less than 3 points"); - skip_ring=true; - } - - // FIXME: Current we ignore the hole-flag and instead assume - // that the first ring is not a hole and the rest - // are holes - OGRLinearRing *ring=new OGRLinearRing(); - for (unsigned int pt = 0; pt < contour.size(); pt++) { - OGRPoint *point=new OGRPoint(); - - point->setX( contour[pt].x() ); - point->setY( contour[pt].y() ); - point->setZ( 0.0 ); - ring->addPoint(point); - } - ring->closeRings(); - - if (!skip_ring) { - polygon->addRingDirectly(ring); - } - - OGRFeature* feature = NULL; - feature = new OGRFeature( layer->GetLayerDefn() ); - feature->SetField("ID", description); - feature->SetGeometry(polygon); - if( layer->CreateFeature( feature ) != OGRERR_NONE ) - { - SG_LOG(SG_GENERAL, SG_ALERT, "Failed to create feature in shapefile"); - } - OGRFeature::DestroyFeature(feature); - } -} - void tgShapefile::CloseLayer( void* l_id ) { //OGRLayer::DestroyLayer( layer ); @@ -4090,4 +3032,35 @@ void* tgShapefile::CloseDatasource( void* ds_id ) OGRDataSource::DestroyDataSource( datasource ); return (void *)-1; -} \ No newline at end of file +} + +void clipper_to_shapefile( ClipperLib::Polygons polys, char* ds ) +{ +#if 0 + ClipperLib::Polygons contour; + TGPolygon tgcontour; + char layer[32]; + + void* ds_id = tgShapefile::OpenDatasource( ds ); + + for (unsigned int i = 0; i < polys.size(); ++i) { + if ( Orientation( polys[i] ) ) { + sprintf( layer, "%04d_boundary", i ); + } else { + sprintf( layer, "%04d_hole", i ); + } + + void* l_id = tgShapefile::OpenLayer( ds_id, layer ); + contour.clear(); + contour.push_back( polys[i] ); + + tgcontour.erase(); + make_tg_poly_from_clipper( contour, &tgcontour ); + + tgShapefile::CreateFeature( ds_id, l_id, tgcontour, "contour" ); + } + + // close after each write + ds_id = tgShapefile::CloseDatasource( ds_id ); +#endif +} diff --git a/src/Lib/Polygon/polygon.hxx b/src/Lib/Polygon/polygon.hxx index 0517fc7d..a268e7a6 100644 --- a/src/Lib/Polygon/polygon.hxx +++ b/src/Lib/Polygon/polygon.hxx @@ -33,266 +33,12 @@ #include #include #include +#include #include #include -#include - -// forward declaration -class TGPolygon; - #include "clipper.hpp" -#define FG_MAX_VERTICES 1500000 - -typedef std::vector < point_list > polytype; -typedef polytype::iterator polytype_iterator; -typedef polytype::const_iterator const_polytype_iterator; - -class TGPolygon { - -private: - - 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 ); - - // 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 ); - } - - // 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; - } - - // return the ith point from the specified contour - inline Point3D get_pt( int contour, int i ) const - { - return poly[contour][i]; - } - - // update the value of a point - inline void set_pt( int contour, int i, const Point3D& p ) - { - poly[contour][i] = p; - } - - void get_bounding_box( SGGeod& min, SGGeod& max ) const; - - // 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; - } - - // 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; - } - - // 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 ); - - // Set the elevations of all points to the specified values - void set_elevations( double elev ); - - // shift every point in the polygon by lon, lat - void shift( double lon, double lat ); - - // erase - inline void erase() - { - poly.clear(); - } - - // informational - - // 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; - - void SaveToGzFile( gzFile& fp ) const; - void LoadFromGzFile( gzFile& fp ); - - // Friends for serialization - friend std::istream& operator>> ( std::istream&, TGPolygon& ); - friend std::ostream& operator<< ( std::ostream&, const TGPolygon& ); -}; - - -typedef std::vector < TGPolygon > poly_list; -typedef poly_list::iterator poly_list_iterator; -typedef poly_list::const_iterator const_poly_list_iterator; - - -// Calculate theta of angle (a, b, c) -double tgPolygonCalcAngle(SGVec2d a, SGVec2d b, SGVec2d c); - - -// canonify the polygon winding, outer contour must be anti-clockwise, -// all inner contours must be clockwise. -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 tgPolygon2tristrip( const TGPolygon& poly ); - -void tgPolygonFindSlivers( TGPolygon& in, poly_list& slivers ); - - -// Difference -TGPolygon tgPolygonDiff( const TGPolygon& subject, const TGPolygon& clip ); - -// Intersection -TGPolygon tgPolygonInt( const TGPolygon& subject, const TGPolygon& clip ); - -// Exclusive or -TGPolygon tgPolygonXor( const TGPolygon& subject, const TGPolygon& clip ); - -// Union -TGPolygon tgPolygonUnion( const TGPolygon& subject, const TGPolygon& clip ); -TGPolygon tgPolygonUnion( const poly_list& clips ); - -// wrapper for clipper clip routines - -void tgPolygonInitClipperAccumulator( void ); -void tgPolygonFreeClipperAccumulator( void ); -void tgPolygonDumpAccumulator( char* ds, char* layer, char*name ); -void tgPolygonAddToClipperAccumulator( const TGPolygon& subject, bool dump ); -TGPolygon tgPolygonDiffClipperWithAccumulator( const TGPolygon& subject ); - -// Save clipper to shapefile -void clipper_to_shapefile( ClipperLib::Polygons polys, char* datasource ); - -// Difference -TGPolygon tgPolygonDiffClipper( const TGPolygon& subject, const TGPolygon& clip ); - -// Intersection -TGPolygon tgPolygonIntClipper( const TGPolygon& subject, const TGPolygon& clip ); - -// Union -TGPolygon tgPolygonUnionClipper( const TGPolygon& subject, const TGPolygon& clip ); - -// Expand / Shrink -TGPolygon tgPolygonExpand(const TGPolygon &poly, double delta); - -// Simplify -TGPolygon tgPolygonSimplify(const TGPolygon &poly); - -void tgPolygonDumpClipper(const TGPolygon &poly); - -// Output -std::ostream &operator<<(std::ostream &output, const TGPolygon &poly); - - - - // WORK IN PROGRESS BEGIN ****************************************************** // Looking ato TGPolygon and TGSuperPoly, I think it would be best if we could @@ -316,7 +62,6 @@ std::ostream &operator<<(std::ostream &output, const TGPolygon &poly); #include #include -#include #include #include "tg_unique_geod.hxx" @@ -329,6 +74,12 @@ SGGeod OffsetPointMiddle( const SGGeod& gPrev, const SGGeod& gCur, const SGGeod& SGGeod OffsetPointFirst( const SGGeod& cur, const SGGeod& next, double offset_by ); SGGeod OffsetPointLast( const SGGeod& prev, const SGGeod& cur, double offset_by ); +// what abount this? + +// Save clipper to shapefile +void clipper_to_shapefile( ClipperLib::Polygons polys, char* datasource ); + + // forward declaration // Forward Declaration: class tgPolygon; @@ -401,7 +152,7 @@ public: static tgPolygon Diff( const tgContour& subject, tgPolygon& clip ); - static tgContour AddColinearNodes( const tgContour& subject, TGTriNodes nodes ); + static tgContour AddColinearNodes( const tgContour& subject, UniqueSGGeodSet& nodes ); static tgContour AddColinearNodes( const tgContour& subject, std::vector& nodes ); static bool FindColinearLine( const tgContour& subject, const SGGeod& node, SGGeod& start, SGGeod& end ); @@ -748,7 +499,7 @@ public: static void Tesselate( const tgPolygon& subject ); - static tgPolygon AddColinearNodes( const tgPolygon& subject, TGTriNodes& nodes ); + static tgPolygon AddColinearNodes( const tgPolygon& subject, UniqueSGGeodSet& nodes ); static tgPolygon AddColinearNodes( const tgPolygon& subject, std::vector& nodes ); static bool FindColinearLine( const tgPolygon& subject, SGGeod& node, SGGeod& start, SGGeod& end ); @@ -851,17 +602,6 @@ public: type = t; } - // TEMP TEMP TEMP : need to redo Airport.cxx methods - point_list TempGetPosListAsPoint3D( void ) { - point_list p3dlist; - - for (unsigned int i=0; i GetPositionList( void ) { std::vector positions; @@ -872,16 +612,6 @@ public: return positions; } - point_list TempGetNormalListAsPoint3D( void ) { - point_list p3dlist; - - for (unsigned int i=0; i GetNormalList( void ) { std::vector normals; @@ -892,8 +622,6 @@ public: return normals; } - // END TEMP TEMP TEMP - // Friend for output friend std::ostream& operator<< ( std::ostream&, const tgLightContour& ); @@ -929,12 +657,9 @@ public: static void Init( void ); static void* OpenDatasource( const char* datasource_name ); static void* OpenLayer( void* ds_id, const char* layer_name ); - static void CreateFeature( void* ds_id, void* l_id, const TGPolygon &poly, const char* description ); +// static void CreateFeature( void* ds_id, void* l_id, const TGPolygon &poly, const char* description ); static void CloseLayer( void* l_id ); static void* CloseDatasource( void* ds_id ); }; - #endif // _POLYGON_HXX - - diff --git a/src/Lib/Polygon/tg_nodes.hxx b/src/Lib/Polygon/tg_nodes.hxx index 39f9df3a..3578dce8 100644 --- a/src/Lib/Polygon/tg_nodes.hxx +++ b/src/Lib/Polygon/tg_nodes.hxx @@ -8,9 +8,6 @@ #include #include -//#include -//#include - #include #include #include @@ -144,6 +141,7 @@ private: Tree tg_kd_tree; bool kd_tree_valid; +#if 0 // return true of the two points are "close enough" as defined by // FG_PROXIMITY_EPSILON bool close_enough_2d( const SGGeod& p1, const SGGeod& p2 ) const; @@ -155,9 +153,10 @@ private: // return true of the two points are "close enough" as defined by // FG_COURSE_EPSILON bool course_close_enough( const SGGeod& p1, const SGGeod& p2 ); +#endif }; - +#if 0 // return true of the two points are "close enough" as defined by // FG_PROXIMITY_EPSILON checking just x and y dimensions inline bool TGNodes::close_enough_2d( const SGGeod& p1, const SGGeod& p2 ) @@ -196,5 +195,6 @@ inline bool TGNodes::course_close_enough( const SGGeod& p1, const SGGeod& p2 ) return false; } } +#endif #endif // _TG_NODES_HXX diff --git a/src/Lib/Polygon/trinodes.cxx b/src/Lib/Polygon/trinodes.cxx deleted file mode 100644 index 184f74e8..00000000 --- a/src/Lib/Polygon/trinodes.cxx +++ /dev/null @@ -1,163 +0,0 @@ -// trinodes.cxx -- "Triangle" nodes management class -// -// Written by Curtis Olson, started March 1999. -// -// Copyright (C) 1999 Curtis L. Olson - http://www.flightgear.org/~curt -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License as -// published by the Free Software Foundation; either version 2 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. -// -// $Id: trinodes.cxx,v 1.7 2004-11-19 22:25:50 curt Exp $ - - -#include "trinodes.hxx" - - -// Constructor -TGTriNodes::TGTriNodes( void ) { -} - - -// Destructor -TGTriNodes::~TGTriNodes( void ) { -} - - -// Add a point to the point list if it doesn't already exist. Returns -// the index (starting at zero) of the point in the list. -int TGTriNodes::unique_add( const Point3D& p ) { - point_list_iterator current, last; - int counter = 0; - - // cout << "unique add = " << p << endl; - - // see if point already exists - current = node_list.begin(); - last = node_list.end(); - for ( ; current != last; ++current ) { - if ( close_enough_2d(p, *current) ) { - // cout << "found an existing match!" << endl; - - // update elevation if new point has better info - if ( current->z() < -9000 ) { - current->setz( p.z() ); - } - - return counter; - } - - ++counter; - } - - // add to list - node_list.push_back( p ); - - return counter; -} - - -// Add a point to the point list if it doesn't already exist (checking -// all three dimensions.) Returns the index (starting at zero) of the -// point in the list. -int TGTriNodes::unique_add_3d( const Point3D& p ) { - point_list_iterator current, last; - int counter = 0; - - // cout << p.x() << "," << p.y() << endl; - - // see if point already exists - current = node_list.begin(); - last = node_list.end(); - for ( ; current != last; ++current ) { - if ( close_enough_3d(p, *current) ) { - // cout << "found an existing match!" << endl; - return counter; - } - - ++counter; - } - - // add to list - node_list.push_back( p ); - - return counter; -} - - -// Add the point with no uniqueness checking -int TGTriNodes::simple_add( const Point3D& p ) { - node_list.push_back( p ); - - return node_list.size() - 1; -} - - -// Add a point to the point list if it doesn't already exist. Returns -// the index (starting at zero) of the point in the list. Use a -// course proximity check -int TGTriNodes::course_add( const Point3D& p ) { - point_list_iterator current, last; - int counter = 0; - - // cout << p.x() << "," << p.y() << endl; - - // see if point already exists - current = node_list.begin(); - last = node_list.end(); - for ( ; current != last; ++current ) { - if ( course_close_enough(p, *current) ) { - // cout << "found an existing match!" << endl; - - // update elevation if new point has better info - if ( current->z() < -9000 ) { - current->setz( p.z() ); - } - - return counter; - } - - ++counter; - } - - // add to list - node_list.push_back( p ); - - return counter; -} - - -// Find the index of the specified point (compair to the same -// tolerance as unique_add(). Returns -1 if not found. -int TGTriNodes::find( const Point3D& p ) const { - const_point_list_iterator current, last; - int counter = 0; - - // cout << p.x() << "," << p.y() << endl; - - // see if point already exists - current = node_list.begin(); - last = node_list.end(); - for ( ; current != last; ++current ) { - if ( close_enough_2d(p, *current) ) { - // cout << "found an existing match!" << endl; - return counter; - } - - ++counter; - } - - return -1; -} - - diff --git a/src/Lib/Polygon/trinodes.hxx b/src/Lib/Polygon/trinodes.hxx deleted file mode 100644 index f58d9991..00000000 --- a/src/Lib/Polygon/trinodes.hxx +++ /dev/null @@ -1,148 +0,0 @@ -// trinodes.hxx -- "Triangle" nodes management class -// -// Written by Curtis Olson, started March 1999. -// -// Copyright (C) 1999 Curtis L. Olson - http://www.flightgear.org/~curt -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License as -// published by the Free Software Foundation; either version 2 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. -// -// $Id: trinodes.hxx,v 1.7 2004/11/19 22:25:50 curt Exp $ - - -#ifndef _TRINODES_HXX -#define _TRINODES_HXX - - -#ifndef __cplusplus -# error This library requires C++ -#endif - - -#include -#include - -#include - -#define FG_PROXIMITY_EPSILON 0.000001 -//#define FG_COURSE_EPSILON 0.0003 -#define FG_COURSE_EPSILON 0.0001 - -class TGTriNodes { - -private: - - point_list node_list; - - // return true of the two points are "close enough" as defined by - // FG_PROXIMITY_EPSILON - bool close_enough_2d( const Point3D& p1, const Point3D& p2 ) const; - - // return true of the two points are "close enough" as defined by - // FG_PROXIMITY_EPSILON - bool close_enough_3d( const Point3D& p1, const Point3D& p2 ) const; - - // return true of the two points are "close enough" as defined by - // FG_COURSE_EPSILON - bool course_close_enough( const Point3D& p1, const Point3D& p2 ); - -public: - - // Constructor and destructor - TGTriNodes( void ); - ~TGTriNodes( void ); - - // delete all the data out of node_list - inline void clear() { node_list.clear(); } - - // Add a point to the point list if it doesn't already exist. - // Returns the index (starting at zero) of the point in the list. - int unique_add( const Point3D& p ); - - // Add a point to the point list if it doesn't already exist - // (checking all three dimensions.) Returns the index (starting - // at zero) of the point in the list. - int unique_add_3d( const Point3D& p ); - - // Add the point with no uniqueness checking - int simple_add( const Point3D& p ); - - // Add a point to the point list if it doesn't already exist. - // Returns the index (starting at zero) of the point in the list. - // Use a course proximity check - int course_add( const Point3D& p ); - - // Find the index of the specified point (compair to the same - // tolerance as unique_add(). Returns -1 if not found. - int find( const Point3D& p ) const; - - // return the master node list - inline point_list& get_node_list() { return node_list; } - inline const point_list& get_node_list() const { return node_list; } - inline void set_node_list( point_list pl ) { node_list = pl; } - - // return the ith point - inline Point3D get_node( int i ) const { return node_list[i]; } - - // return the size of the node list - inline size_t size() const { return node_list.size(); } -}; - - -// return true of the two points are "close enough" as defined by -// FG_PROXIMITY_EPSILON checking just x and y dimensions -inline bool TGTriNodes::close_enough_2d( const Point3D& p1, const Point3D& p2 ) - const -{ - if ( ( fabs(p1.x() - p2.x()) < FG_PROXIMITY_EPSILON ) && - ( fabs(p1.y() - p2.y()) < FG_PROXIMITY_EPSILON ) ) { - return true; - } else { - return false; - } -} - - -// return true of the two points are "close enough" as defined by -// FG_PROXIMITY_EPSILON check all three dimensions -inline bool TGTriNodes::close_enough_3d( const Point3D& p1, const Point3D& p2 ) - const -{ - if ( ( fabs(p1.x() - p2.x()) < FG_PROXIMITY_EPSILON ) && - ( fabs(p1.y() - p2.y()) < FG_PROXIMITY_EPSILON ) && - ( fabs(p1.z() - p2.z()) < FG_PROXIMITY_EPSILON ) ) { - return true; - } else { - return false; - } -} - - -// return true of the two points are "close enough" as defined by -// FG_COURSE_EPSILON -inline bool TGTriNodes::course_close_enough( const Point3D& p1, - const Point3D& p2 ) -{ - if ( ( fabs(p1.x() - p2.x()) < FG_COURSE_EPSILON ) && - ( fabs(p1.y() - p2.y()) < FG_COURSE_EPSILON ) ) { - return true; - } else { - return false; - } -} - - -#endif // _TRINODES_HXX - - diff --git a/src/Utils/poly2ogr/poly2ogr.cxx b/src/Utils/poly2ogr/poly2ogr.cxx index ceeec1be..c8713fbb 100644 --- a/src/Utils/poly2ogr/poly2ogr.cxx +++ b/src/Utils/poly2ogr/poly2ogr.cxx @@ -45,6 +45,7 @@ #include #include +#include #include