From 5d45916b234da9039515b508ddee5ae01a4f6616 Mon Sep 17 00:00:00 2001 From: Peter Sadrozinski <peter@localhost.localdomain> Date: Tue, 31 Dec 2013 09:21:10 -0500 Subject: [PATCH] fix tile bounding box errors leading to z-fightine near tile borders - round to coorect snap point when converting double to clipper uint64 - add tgPolygon::ToClipperfile to aid debugging clipper related issues --- src/BuildTiles/Main/tgconstruct_clip.cxx | 12 ++++++++++++ src/Lib/terragear/tg_misc.cxx | 10 +++++----- src/Lib/terragear/tg_polygon.cxx | 15 +++++++++++++++ src/Lib/terragear/tg_polygon.hxx | 3 ++- 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/BuildTiles/Main/tgconstruct_clip.cxx b/src/BuildTiles/Main/tgconstruct_clip.cxx index ff2f5902..f2887167 100644 --- a/src/BuildTiles/Main/tgconstruct_clip.cxx +++ b/src/BuildTiles/Main/tgconstruct_clip.cxx @@ -200,6 +200,18 @@ bool TGConstruct::ClipLandclassPolys( void ) { slivers.clear(); + if ( debug_shapes.size() ) + { + char layer[32]; + char name[32]; + + sprintf(layer, "tile_rect" ); + sprintf(name, "shape"); + + tgShapefile::FromPolygon( safety_base, ds_name, layer, name ); + tgPolygon::ToClipperFile( safety_base, ds_name, layer ); + } + // finally, what ever is left over goes to ocean remains = accum.Diff( safety_base ); diff --git a/src/Lib/terragear/tg_misc.cxx b/src/Lib/terragear/tg_misc.cxx index 58ac8393..4f0dd510 100644 --- a/src/Lib/terragear/tg_misc.cxx +++ b/src/Lib/terragear/tg_misc.cxx @@ -10,8 +10,8 @@ const double isEqual2D_Epsilon = 0.000001; -#define CLIPPER_FIXEDPT (10000000000000000) -#define CLIPPER_FIXED1M ( 90090) +#define CLIPPER_FIXEDPT (1000000000000) +#define CLIPPER_METERS_PER_DEGREE (111000) SGGeod SGGeod_snap( const SGGeod& in, double grid ) { @@ -72,8 +72,8 @@ ClipperLib::IntPoint SGGeod_ToClipper( const SGGeod& p ) { ClipperLib::cUInt x, y; - x = (ClipperLib::cUInt)( p.getLongitudeDeg() * CLIPPER_FIXEDPT ); - y = (ClipperLib::cUInt)( p.getLatitudeDeg() * CLIPPER_FIXEDPT ); + x = (ClipperLib::cUInt)( (p.getLongitudeDeg() * CLIPPER_FIXEDPT) + 0.5); + y = (ClipperLib::cUInt)( (p.getLatitudeDeg() * CLIPPER_FIXEDPT) + 0.5); return ClipperLib::IntPoint( x, y ); } @@ -90,7 +90,7 @@ SGGeod SGGeod_FromClipper( const ClipperLib::IntPoint& p ) double Dist_ToClipper( double dist ) { - return ( dist * ( CLIPPER_FIXEDPT / CLIPPER_FIXED1M ) ); + return ( (dist / CLIPPER_METERS_PER_DEGREE) * CLIPPER_FIXEDPT ); } #ifdef _MSC_VER diff --git a/src/Lib/terragear/tg_polygon.cxx b/src/Lib/terragear/tg_polygon.cxx index 88bad7fe..f5c8fd27 100644 --- a/src/Lib/terragear/tg_polygon.cxx +++ b/src/Lib/terragear/tg_polygon.cxx @@ -19,6 +19,9 @@ // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. // +#include <iostream> +#include <fstream> + #include <simgear/constants.h> #include <simgear/threads/SGThread.hxx> #include <simgear/threads/SGGuard.hxx> @@ -358,6 +361,18 @@ void tgPolygon::LoadFromGzFile( gzFile& fp ) sgReadInt( fp, (int *)&preserve3d ); } +void tgPolygon::ToClipperFile( const tgPolygon& subject, const std::string& path, const std::string& filename ) +{ + ClipperLib::Paths clipper_subject = tgPolygon::ToClipper( subject ); + std::ofstream dmpfile; + char pathname[256]; + + sprintf( pathname, "%s/%s", path.c_str(), filename.c_str() ); + dmpfile.open (pathname); + dmpfile << clipper_subject; + dmpfile.close(); +} + // Friends for serialization std::ostream& operator<< ( std::ostream& output, const tgPolygon& subject ) { diff --git a/src/Lib/terragear/tg_polygon.hxx b/src/Lib/terragear/tg_polygon.hxx index bcf96d72..c31e9dfd 100644 --- a/src/Lib/terragear/tg_polygon.hxx +++ b/src/Lib/terragear/tg_polygon.hxx @@ -403,7 +403,8 @@ public: // Conversions static ClipperLib::Paths ToClipper( const tgPolygon& subject ); static tgPolygon FromClipper( const ClipperLib::Paths& subject ); - + static void ToClipperFile( const tgPolygon& subject, const std::string& path, const std::string& filename ); + static void ToShapefile( const tgPolygon& subject, const std::string& datasource, const std::string& layer, const std::string& feature ); // T-Junctions and segment search