From ca98d2ef5db39b160887a172a84c5f0a30ba7271 Mon Sep 17 00:00:00 2001 From: Scott Giese Date: Tue, 29 Jan 2019 14:55:50 -0600 Subject: [PATCH] [tg-construct] Reduce technical debt --- src/BuildTiles/Main/cliptst.cxx | 22 +++++- src/BuildTiles/Main/priorities.hxx | 17 ++++- src/BuildTiles/Main/tgconstruct.cxx | 12 +-- src/BuildTiles/Main/tgconstruct.hxx | 4 +- src/BuildTiles/Main/tgconstruct_clip.cxx | 10 +-- src/BuildTiles/Main/tgconstruct_math.cxx | 5 +- src/BuildTiles/Main/tgconstruct_output.cxx | 6 +- src/BuildTiles/Main/tgconstruct_poly.cxx | 15 ++-- src/BuildTiles/Main/tgconstruct_tesselate.cxx | 2 +- src/BuildTiles/Main/tglandclass.cxx | 7 +- src/BuildTiles/Parallel/client.cxx | 25 +++---- src/BuildTiles/Parallel/server.cxx | 74 +++++++++---------- 12 files changed, 108 insertions(+), 91 deletions(-) diff --git a/src/BuildTiles/Main/cliptst.cxx b/src/BuildTiles/Main/cliptst.cxx index 6cbaf32f..91b9c6ea 100644 --- a/src/BuildTiles/Main/cliptst.cxx +++ b/src/BuildTiles/Main/cliptst.cxx @@ -35,9 +35,22 @@ int PrecisionFirstValue(const char * filename) char line[80]; FILE *f = fopen(filename, "r"); if (!f) return 0; - if (fgets(line, 80, f) == 0) return 0; //skip poly count - if (fgets(line, 80, f) == 0) return 0; //skip length first polygon - if (fgets(line, 80, f) == 0) return 0; //get coords first vertex + + if (fgets(line, 80, f) == 0) { + fclose(f); + return 0; //skip poly count + } + + if (fgets(line, 80, f) == 0) { + fclose(f); + return 0; //skip length first polygon + } + + if (fgets(line, 80, f) == 0) { + fclose(f); + return 0; //get coords first vertex + } + fclose(f); int i = 0; @@ -66,7 +79,6 @@ bool LoadFromFile(Polygons &ppg, char * filename, double scale) FILE *f = fopen(filename, "r"); if (!f) return false; int polyCnt, vertCnt; - char junk [80]; double X, Y; if (fscanf(f, "%d", &polyCnt) == 1 && polyCnt > 0) @@ -79,6 +91,8 @@ bool LoadFromFile(Polygons &ppg, char * filename, double scale) if (fscanf(f, "%lf%*[, ]%lf", &X, &Y) != 2) break; ppg[i][j].X = Round(X * scale); ppg[i][j].Y = Round(Y * scale); + + char junk [80]; fgets(junk, 80, f); } } diff --git a/src/BuildTiles/Main/priorities.hxx b/src/BuildTiles/Main/priorities.hxx index f1247efa..b955d39b 100644 --- a/src/BuildTiles/Main/priorities.hxx +++ b/src/BuildTiles/Main/priorities.hxx @@ -33,10 +33,14 @@ class TGAreaDefinition { public: - TGAreaDefinition( const std::string& n, const std::string& c, unsigned int p ) { - name = n; - category = c; + TGAreaDefinition( const std::string& n, const std::string& c, unsigned int p ) : + name(n), + category(c) + { priority = p; + smooth_method = 0; + layered = false; + default_layer = 0; }; std::string const& GetName() const { @@ -68,7 +72,12 @@ typedef area_definition_list::const_iterator area_definition_iterator; class TGAreaDefinitions { public: - TGAreaDefinitions() {}; + TGAreaDefinitions() : + sliver_area_name("") + { + sliver_area_priority = 0; + }; + int init( const std::string& filename ); unsigned int size() const { return area_defs.size(); diff --git a/src/BuildTiles/Main/tgconstruct.cxx b/src/BuildTiles/Main/tgconstruct.cxx index 1e0082f8..4d224e2e 100644 --- a/src/BuildTiles/Main/tgconstruct.cxx +++ b/src/BuildTiles/Main/tgconstruct.cxx @@ -40,11 +40,13 @@ TGConstruct::TGConstruct( const TGAreaDefinitions& areas, unsigned int s, SGLock ignoreLandmass(false), debug_all(false), ds_id((void*)-1), + l_id(nullptr), isOcean(false) { total_tiles = q.size(); num_areas = areas.size(); lock = l; + nudge = 0.0; } @@ -55,9 +57,9 @@ TGConstruct::~TGConstruct() { } // TGConstruct: Setup -void TGConstruct::set_paths( const std::string work, const std::string share, - const std::string match, const std::string output, - const std::vector load ) { +void TGConstruct::set_paths( const std::string& work, const std::string& share, + const std::string& match, const std::string& output, + const std::vector& load ) { work_base = work; share_base = share; match_base = match; @@ -72,12 +74,10 @@ void TGConstruct::set_options( bool ignore_lm, double n ) { void TGConstruct::run() { - unsigned int tiles_complete; - // as long as we have feometry to parse, do so while ( !workQueue.empty() ) { bucket = workQueue.pop(); - tiles_complete = total_tiles - workQueue.size(); + unsigned int tiles_complete = total_tiles - workQueue.size(); // assume non ocean tile until proven otherwise isOcean = false; diff --git a/src/BuildTiles/Main/tgconstruct.hxx b/src/BuildTiles/Main/tgconstruct.hxx index fdf6932b..295d0635 100644 --- a/src/BuildTiles/Main/tgconstruct.hxx +++ b/src/BuildTiles/Main/tgconstruct.hxx @@ -83,8 +83,8 @@ public: #endif // paths - void set_paths( const std::string work, const std::string share, const std::string match, - const std::string output, const std::vector load_dirs ); + void set_paths( const std::string& work, const std::string& share, const std::string& match, + const std::string& output, const std::vector& load_dirs ); void set_options( bool ignore_lm, double n ); // TODO : REMOVE diff --git a/src/BuildTiles/Main/tgconstruct_clip.cxx b/src/BuildTiles/Main/tgconstruct_clip.cxx index 1aa47327..858c4e79 100644 --- a/src/BuildTiles/Main/tgconstruct_clip.cxx +++ b/src/BuildTiles/Main/tgconstruct_clip.cxx @@ -40,7 +40,7 @@ bool TGConstruct::ClipLandclassPolys( void ) { tgPolygon safety_base; tgcontour_list slivers; SGGeod p; - bool debug_area, debug_shape; + bool debug_shape; tgAccumulator accum(bucket.gen_index_str()); unsigned int accum_idx = 0; @@ -102,7 +102,7 @@ bool TGConstruct::ClipLandclassPolys( void ) { // process polygons in priority order for ( unsigned int i = 0; i < area_defs.size(); i++ ) { - debug_area = IsDebugArea( i ); + bool debug_area = IsDebugArea( i ); for( unsigned int j = 0; j < polys_in.area_size(i); ++j ) { tgPolygon& current = polys_in.get_poly(i, j); debug_shape = IsDebugShape( polys_in.get_poly( i, j ).GetId() ); @@ -127,7 +127,7 @@ bool TGConstruct::ClipLandclassPolys( void ) { char name[32]; sprintf(layer, "pre_clip_%d", polys_in.get_poly( i, j ).GetId() ); - sprintf(name, "shape %d,%d", i,j); + sprintf(name, "shape %u,%u", i,j); tgShapefile::FromPolygon( tmp, ds_name, layer, name ); tgPolygon::ToClipperFile( tmp, ds_name, layer ); @@ -159,7 +159,7 @@ bool TGConstruct::ClipLandclassPolys( void ) { char name[32]; sprintf(layer, "post_clip_%d", polys_in.get_poly( i, j ).GetId() ); - sprintf(name, "shape %d,%d", i,j); + sprintf(name, "shape %u,%u", i,j); tgShapefile::FromPolygon( clipped, ds_name, layer, name ); } @@ -175,7 +175,7 @@ bool TGConstruct::ClipLandclassPolys( void ) { accum.Add( tmp ); if ( debug_area || debug_shape ) { char layer[32]; - sprintf(layer, "post_clip_accum_%d_%d", accum_idx++, polys_in.get_poly( i, j ).GetId() ); + sprintf(layer, "post_clip_accum_%u_%u", accum_idx++, polys_in.get_poly( i, j ).GetId() ); accum.ToShapefiles( ds_name, layer, false ); accum.ToClipperfiles( ds_name, layer, false ); diff --git a/src/BuildTiles/Main/tgconstruct_math.cxx b/src/BuildTiles/Main/tgconstruct_math.cxx index 333de7ac..5faf012f 100644 --- a/src/BuildTiles/Main/tgconstruct_math.cxx +++ b/src/BuildTiles/Main/tgconstruct_math.cxx @@ -68,8 +68,7 @@ SGVec3f TGConstruct::calc_normal( double area, const SGVec3d& p1, const SGVec3d& void TGConstruct::calc_normals( std::vector& geod_nodes, std::vector& wgs84_nodes, tgPolygon& poly ) { // for each face in the superpoly, calculate a face normal - SGVec3f normal; - double area; + SGVec3f normal; for (unsigned int tri = 0; tri < poly.Triangles(); tri++) { SGGeod g1 = geod_nodes[ poly.GetTriIdx( tri, 0 ) ]; @@ -80,7 +79,7 @@ void TGConstruct::calc_normals( std::vector& geod_nodes, std::vector 0 ) { @@ -133,10 +133,10 @@ void TGConstruct::WriteBtgFile( void ) nodes.get_wgs84_nodes( wgs84_nodes ); SGVec3d gbs_center = SGVec3d::fromGeod( bucket.get_center() ); - double dist_squared, radius_squared = 0; + double radius_squared = 0; for (int i = 0; i < (int)wgs84_nodes.size(); ++i) { - dist_squared = distSqr(gbs_center, wgs84_nodes[i]); + double dist_squared = distSqr(gbs_center, wgs84_nodes[i]); if ( dist_squared > radius_squared ) { radius_squared = dist_squared; } diff --git a/src/BuildTiles/Main/tgconstruct_poly.cxx b/src/BuildTiles/Main/tgconstruct_poly.cxx index 89f35f55..7352c9f4 100644 --- a/src/BuildTiles/Main/tgconstruct_poly.cxx +++ b/src/BuildTiles/Main/tgconstruct_poly.cxx @@ -72,7 +72,6 @@ int TGConstruct::LoadLandclassPolys( void ) { { // skipped! } else { - int area; std::string material; gzFile fp = gzopen( p.c_str(), "rb" ); unsigned int count; @@ -80,9 +79,9 @@ int TGConstruct::LoadLandclassPolys( void ) { sgReadUInt( fp, &count ); SG_LOG( SG_GENERAL, SG_DEBUG, " Load " << count << " polys from " << p.realpath() ); - for ( unsigned int i=0; i& selection ) { double min_dist = std::numeric_limits::infinity(); - double cur_dist; unsigned int min_idx = 0; - for ( unsigned int i=0; i& selection ) { double min_dist = std::numeric_limits::infinity(); - double cur_dist; unsigned int min_idx = 0; - for ( unsigned int i=0; i 0 ) { - message[len] = '\0'; - tile = atoi(message); - cout << " tile to construct = " << tile << endl; - close(sock); - return tile; - } else { - close(sock); - return -1; - } + /* input coming from socket */ + if ( (int len = read(sock, message, MAXBUF)) > 0 ) { + message[len] = '\0'; + long int tile = atoi(message); + cout << " tile to construct = " << tile << endl; + close(sock); + return tile; + } else { + close(sock); + return -1; + } } close(sock); diff --git a/src/BuildTiles/Parallel/server.cxx b/src/BuildTiles/Parallel/server.cxx index 042ebadc..e7d688c6 100644 --- a/src/BuildTiles/Parallel/server.cxx +++ b/src/BuildTiles/Parallel/server.cxx @@ -171,56 +171,56 @@ long int get_next_tile() { // first time this routine is called, init counters if ( first_time ) { - first_time = false; - start_seconds = seconds = time(NULL); - counter = global_counter = 0; + first_time = false; + start_seconds = seconds = time(NULL); + counter = global_counter = 0; } // cout << "lon = " << lon << " lat = " << lat << endl; // cout << "start_lat = " << start_lat << endl; if ( lon > start_lon + area_width ) { - // increment to next row - // skip every other row (to avoid two clients working on - // adjacent tiles) - lat += 2.0 * dy; + // increment to next row + // skip every other row (to avoid two clients working on + // adjacent tiles) + lat += 2.0 * dy; - SGBucket tmp( SGGeod::fromDeg(0.0, lat) ); - double dx = tmp.get_width(); - lon = start_lon + (shift_over*dx) + (dx*0.5); + SGBucket tmp( SGGeod::fromDeg(0.0, lat) ); + double dx = tmp.get_width(); + lon = start_lon + (shift_over*dx) + (dx*0.5); } if ( lat > start_lat + area_height ) { - ++pass; - if ( pass == 1 ) { - shift_over = 0.0; - shift_up = 0.0; - } else if ( pass == 2 ) { - shift_over = 1.0; - shift_up = 0.0; - } else if ( pass == 3 ) { - shift_over = 0.0; - shift_up = 1.0; - } else if ( pass == 4 ) { - shift_over = 1.0; - shift_up = 1.0; - } else { - return -1; - } + ++pass; + if ( pass == 1 ) { + shift_over = 0.0; + shift_up = 0.0; + } else if ( pass == 2 ) { + shift_over = 1.0; + shift_up = 0.0; + } else if ( pass == 3 ) { + shift_over = 0.0; + shift_up = 1.0; + } else if ( pass == 4 ) { + shift_over = 1.0; + shift_up = 1.0; + } else { + return -1; + } - // reset lat - // lat = -89.0 + (shift_up*dy) - (dy*0.5); - // lat = 27.0 + (0*dy) + (dy*0.5); - lat = start_lat + (shift_up*dy) + (dy*0.5); + // reset lat + // lat = -89.0 + (shift_up*dy) - (dy*0.5); + // lat = 27.0 + (0*dy) + (dy*0.5); + lat = start_lat + (shift_up*dy) + (dy*0.5); - // reset lon - SGBucket tmp( SGGeod::fromDeg(0.0, lat) ); - double dx = tmp.get_width(); - // lon = -82 + (shift_over*dx) + (dx*0.5); - lon = start_lon + (shift_over*dx) + (dx*0.5); + // reset lon + SGBucket tmp( SGGeod::fromDeg(0.0, lat) ); + double dx = tmp.get_width(); + // lon = -82 + (shift_over*dx) + (dx*0.5); + lon = start_lon + (shift_over*dx) + (dx*0.5); - cout << "starting pass = " << pass - << " with lat = " << lat << " lon = " << lon << endl; + cout << "starting pass = " << pass + << " with lat = " << lat << " lon = " << lon << endl; } // if ( ! start_lon ) {