From 79ea7c6819dc5b5cb3fe7174ba7c6a8d5e1b8832 Mon Sep 17 00:00:00 2001 From: Torsten Dreyer Date: Wed, 9 Jan 2019 09:27:13 +0100 Subject: [PATCH 01/25] Fix probably typo, don't cast col/row_step to int --- src/Lib/DEM/dem.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Lib/DEM/dem.cxx b/src/Lib/DEM/dem.cxx index ab372df7..42f7589b 100644 --- a/src/Lib/DEM/dem.cxx +++ b/src/Lib/DEM/dem.cxx @@ -446,8 +446,8 @@ TGDem::write_area( const string& root, SGBucket& b ) { } gzprintf( fp, "%d %d\n", (int)min_x, (int)min_y ); - gzprintf( fp, "%d %f %d %f\n", span_x + 1, (int)col_step, - span_y + 1, (int)row_step ); + gzprintf( fp, "%d %f %d %f\n", span_x + 1, col_step, + span_y + 1, row_step ); for ( int i = start_x; i <= start_x + span_x; ++i ) { for ( int j = start_y; j <= start_y + span_y; ++j ) { gzprintf( fp, "%d ", (int)dem_data[i][j] ); From 661f840843bec936fd9115b8533513305f77ece7 Mon Sep 17 00:00:00 2001 From: Torsten Dreyer Date: Wed, 9 Jan 2019 14:23:26 +0100 Subject: [PATCH 02/25] Fix some memory leaks detangle some /interesting/ use of pointer/reference usage --- src/Prep/Terra/Quadedge.cc | 1 + src/Prep/Terra/Quadedge.h | 14 +++++++------- src/Prep/Terra/Subdivision.cc | 19 +++++++------------ src/Prep/Terra/Subdivision.h | 2 +- src/Prep/Terra/Vec2.h | 1 - 5 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/Prep/Terra/Quadedge.cc b/src/Prep/Terra/Quadedge.cc index 91520269..478b2691 100644 --- a/src/Prep/Terra/Quadedge.cc +++ b/src/Prep/Terra/Quadedge.cc @@ -63,6 +63,7 @@ Edge::~Edge() e2->qnext = NULL; e3->qnext = NULL; +//FIXME: who deletes the edges allocated in ctor? (Torsten Dreyer 01/2019) //delete e1; //delete e2; //delete e3; diff --git a/src/Prep/Terra/Quadedge.h b/src/Prep/Terra/Quadedge.h index 6ac8f3f6..5df29e35 100644 --- a/src/Prep/Terra/Quadedge.h +++ b/src/Prep/Terra/Quadedge.h @@ -15,8 +15,8 @@ private: Edge(Edge *prev); -protected: - Vec2 *data; +//protected: + Vec2 data; Edge *next; Triangle *lface; @@ -47,16 +47,16 @@ public: Edge *Rprev() const { return Sym()->Onext(); } - Vec2& Org() const { return *data; } - Vec2& Dest() const { return *Sym()->data; } + const Vec2& Org() const { return data; } + const Vec2& Dest() const { return Sym()->data; } Triangle *Lface() const { return lface; } void set_Lface(Triangle *t) { lface = t; } - void EndPoints(Vec2& org, Vec2& dest) + void EndPoints(const Vec2& org, const Vec2& dest) { - data = &org; - Sym()->data = &dest; + data = org; + Sym()->data = dest; } // diff --git a/src/Prep/Terra/Subdivision.cc b/src/Prep/Terra/Subdivision.cc index b34fc358..e21c9ff1 100644 --- a/src/Prep/Terra/Subdivision.cc +++ b/src/Prep/Terra/Subdivision.cc @@ -28,7 +28,7 @@ Subdivision::~Subdivision() } } -Edge *Subdivision::makeEdge(Vec2& org, Vec2& dest) +Edge *Subdivision::makeEdge(const Vec2& org, const Vec2& dest) { Edge *e = new Edge(); edges.push_back(e); @@ -54,31 +54,26 @@ Edge *Subdivision::makeEdge() void Subdivision::initMesh(const Vec2& A,const Vec2& B, const Vec2& C,const Vec2& D) { - Vec2& a = A.clone(); - Vec2& b = B.clone(); - Vec2& c = C.clone(); - Vec2& d = D.clone(); - Edge *ea = makeEdge(); - ea->EndPoints(a, b); + ea->EndPoints(A, B); Edge *eb = makeEdge(); splice(ea->Sym(), eb); - eb->EndPoints(b, c); + eb->EndPoints(B, C); Edge *ec = makeEdge(); splice(eb->Sym(), ec); - ec->EndPoints(c, d); + ec->EndPoints(C, D); Edge *ed = makeEdge(); splice(ec->Sym(), ed); - ed->EndPoints(d, a); + ed->EndPoints(D, A); splice(ed->Sym(), ea); Edge *diag = makeEdge(); splice(ed->Sym(),diag); splice(eb->Sym(),diag->Sym()); - diag->EndPoints(a,c); + diag->EndPoints(A,C); startingEdge = ea; @@ -334,7 +329,7 @@ Edge *Subdivision::spoke(Vec2& x, Edge *e) // x lies within the Lface of e } - Edge *base = makeEdge(e->Org(), x.clone()); + Edge *base = makeEdge(e->Org(), x ); splice(base, e); diff --git a/src/Prep/Terra/Subdivision.h b/src/Prep/Terra/Subdivision.h index 1e65860a..c9022a35 100644 --- a/src/Prep/Terra/Subdivision.h +++ b/src/Prep/Terra/Subdivision.h @@ -66,7 +66,7 @@ protected: ~Subdivision(); Edge *makeEdge(); - Edge *makeEdge(Vec2& org, Vec2& dest); + Edge *makeEdge(const Vec2& org, const Vec2& dest); virtual Triangle *allocFace(Edge *e); Triangle& makeFace(Edge *e); diff --git a/src/Prep/Terra/Vec2.h b/src/Prep/Terra/Vec2.h index d57dbdb9..5c708a28 100644 --- a/src/Prep/Terra/Vec2.h +++ b/src/Prep/Terra/Vec2.h @@ -16,7 +16,6 @@ public: Vec2(real x=0, real y=0) { elt[0]=x; elt[1]=y; } Vec2(const Vec2& v) { copy(v); } Vec2(const real *v) { elt[0]=v[0]; elt[1]=v[1]; } - Vec2& clone() const { return *(new Vec2(elt[0], elt[1])); } // Access methods real& operator()(int i) { return elt[i]; } From 1a3d4e386ebb394ec749ddd7ec702283fdb29ac5 Mon Sep 17 00:00:00 2001 From: Scott Giese Date: Sun, 13 Jan 2019 01:30:40 -0600 Subject: [PATCH 03/25] hgt: runtime optimization --- src/Lib/HGT/hgt.cxx | 34 +++++++++++++++++----------------- src/Lib/HGT/hgt.hxx | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Lib/HGT/hgt.cxx b/src/Lib/HGT/hgt.cxx index 76f77c66..f768b031 100644 --- a/src/Lib/HGT/hgt.cxx +++ b/src/Lib/HGT/hgt.cxx @@ -58,16 +58,12 @@ TGHgt::TGHgt( int _res ) hgt_resolution = _res; data = new short int[MAX_HGT_SIZE][MAX_HGT_SIZE]; - output_data = new short int[MAX_HGT_SIZE][MAX_HGT_SIZE]; + read_buffer = new short int[MAX_HGT_SIZE]; } -TGHgt::TGHgt( int _res, const SGPath &file ) +TGHgt::TGHgt( int _res, const SGPath &file ) : TGHgt( _res ) { - hgt_resolution = _res; - data = new short int[MAX_HGT_SIZE][MAX_HGT_SIZE]; - output_data = new short int[MAX_HGT_SIZE][MAX_HGT_SIZE]; - TGHgt::open( file ); } @@ -164,16 +160,21 @@ TGHgt::load( ) { return false; } - short int *var; + for ( int row = size - 1; row >= 0; --row ) { - for ( int col = 0; col < size; ++col ) { - var = &data[col][row]; - if ( gzread ( fd, var, sizeof(short) ) != sizeof(short) ) { - return false; - } - if ( sgIsLittleEndian() ) { - sgEndianSwap( (unsigned short int*)var); - } + if ( gzfread( (voidp)read_buffer, 2, size, fd ) != (unsigned)size ) { + return false; + } + + // convert to column-major + for ( int col = 0; col < size; ++col ) + data[col][row] = *(read_buffer + col); + } + + if (sgIsLittleEndian()) { + auto pData = (unsigned short *)data; + for (int i = 0; i < rows * cols; ++i) { + sgEndianSwap(pData++); } } @@ -181,9 +182,8 @@ TGHgt::load( ) { } - TGHgt::~TGHgt() { // printf("class TGSrtmBase DEstructor called.\n"); delete [] data; - delete [] output_data; + delete [] read_buffer; } diff --git a/src/Lib/HGT/hgt.hxx b/src/Lib/HGT/hgt.hxx index faa9f49c..afd7026f 100644 --- a/src/Lib/HGT/hgt.hxx +++ b/src/Lib/HGT/hgt.hxx @@ -53,7 +53,7 @@ private: // pointers to the actual grid data allocated here short int (*data)[MAX_HGT_SIZE]; - short int (*output_data)[MAX_HGT_SIZE]; + short int *read_buffer; public: From e84b69efaeed99c3bda1e05843a7f7e0ad124091 Mon Sep 17 00:00:00 2001 From: Scott Giese Date: Wed, 16 Jan 2019 19:27:58 -0600 Subject: [PATCH 04/25] Clean up some compile warnings --- src/Lib/Array/array.cxx | 12 +++++------- src/Lib/terragear/tg_contour.cxx | 3 +-- src/Prep/Cliff/cliff-decode.cxx | 6 ++---- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/Lib/Array/array.cxx b/src/Lib/Array/array.cxx index 340eb275..9da18a56 100644 --- a/src/Lib/Array/array.cxx +++ b/src/Lib/Array/array.cxx @@ -123,7 +123,6 @@ void TGArray::load_cliffs(const string & height_base) { //Get the directory so we can list the children tgPolygon poly; //actually a contour but whatever... - int total_contours_read = 0; SGPath b(height_base); simgear::Dir d(b.dir()); simgear::PathList files = d.children(simgear::Dir::TYPE_FILE); @@ -509,10 +508,8 @@ double TGArray::rectify_point(const int xgrid, const int ygrid, const std::vecto //ygrid: grid units vertically //Loop over corner points, if no points available, give up int corners[4][2]; //possible corners - int final_pts[3][2]; // rectangle corners int pt_cnt = 0; double centre_long, centre_lat; - double cliff_error = col_step; //Assume row step, col step the same int original_height = get_array_elev(xgrid,ygrid); centre_long = (originx + col_step*xgrid)/3600; centre_lat = (originy + row_step*ygrid)/3600; @@ -587,7 +584,8 @@ double TGArray::altitude_from_grid( double lon, double lat ) const { // we expect incoming (lon,lat) to be in arcsec for now double xlocal, ylocal, dx, dy, zA, zB, elev; - int x1, x2, x3, y1, y2, y3; + int x1 = 0, x2 = 0, x3 = 0; + int y1 = 0, y2 = 0, y3 = 0; float z1, z2, z3; int xindex, yindex; @@ -858,10 +856,10 @@ bool TGArray::check_points( const double lon1, const double lat1, const double l SGGeod pt2 = SGGeod::fromDeg( lon2,lat2 ); bool same_side = true; - for ( int i=0;i(cliffs_list.size()); ++i ) { bool check_result = cliffs_list[i].AreSameSide( pt1,pt2 ); - if(!check_result) { + if (!check_result) { SG_LOG(SG_GENERAL, SG_DEBUG, "Cliff " << i <<":" <(cliffs_list.size()); ++i ) { double dist = cliffs_list[i].MinDist(pt1); if (dist < bad_zone) return true; } diff --git a/src/Lib/terragear/tg_contour.cxx b/src/Lib/terragear/tg_contour.cxx index b8497b4c..0ef581d7 100644 --- a/src/Lib/terragear/tg_contour.cxx +++ b/src/Lib/terragear/tg_contour.cxx @@ -111,8 +111,7 @@ bool tgContour::AreSameSide( const SGGeod& firstpt, const SGGeod& secondpt) cons //Now cycle over all nodes and count how many times we intersect int intersect_ct = 0; if (node_list.size()) { - int j = node_list.size() - 1; - for (int i=0;i(node_list.size()) - 1; ++i) { double nx1 = node_list[i].getLatitudeDeg(); double ny1 = node_list[i].getLongitudeDeg(); double nx2 = node_list[i+1].getLatitudeDeg(); diff --git a/src/Prep/Cliff/cliff-decode.cxx b/src/Prep/Cliff/cliff-decode.cxx index 5d398263..397b6c8b 100644 --- a/src/Prep/Cliff/cliff-decode.cxx +++ b/src/Prep/Cliff/cliff-decode.cxx @@ -80,9 +80,7 @@ void Decoder::processLineString(OGRLineString* poGeometry) tgContour line; SGGeod p0, p1; - double heading, dist, az2; - int i, j, numPoints, numSegs; - double max_dist; + int i, numPoints; numPoints = poGeometry->getNumPoints(); if (numPoints < 2) { @@ -90,7 +88,7 @@ void Decoder::processLineString(OGRLineString* poGeometry) return; } - heading = SGGeodesy::courseDeg( p1, p0 ); + SGGeodesy::courseDeg( p1, p0 ); // now add the middle points : if they are too far apart, add intermediate nodes for ( i=0;i Date: Sun, 20 Jan 2019 17:52:56 -0600 Subject: [PATCH 05/25] Minor clean up --- src/Lib/Array/array.cxx | 93 ++++++++++++++++---------------- src/Lib/Array/array.hxx | 36 +++++++------ src/Lib/terragear/tg_contour.cxx | 2 +- 3 files changed, 67 insertions(+), 64 deletions(-) diff --git a/src/Lib/Array/array.cxx b/src/Lib/Array/array.cxx index 9da18a56..4eee6a13 100644 --- a/src/Lib/Array/array.cxx +++ b/src/Lib/Array/array.cxx @@ -39,18 +39,18 @@ using std::string; TGArray::TGArray( void ): - array_in(NULL), - fitted_in(NULL), - in_data(NULL) + array_in(NULL), + fitted_in(NULL), + in_data(NULL) { } TGArray::TGArray( const string &file ): - array_in(NULL), - fitted_in(NULL), - in_data(NULL) + array_in(NULL), + fitted_in(NULL), + in_data(NULL) { TGArray::open(file); } @@ -198,7 +198,6 @@ TGArray::parse( SGBucket& b ) { SG_LOG(SG_GENERAL, SG_DEBUG, " cols = " << cols << " rows = " << rows ); SG_LOG(SG_GENERAL, SG_DEBUG, " col_step = " << col_step << " row_step = " << row_step ); - in_data = new short[cols * rows]; memset(in_data, 0, sizeof(short) * cols * rows); SG_LOG(SG_GENERAL, SG_DEBUG, " File not open, so using zero'd data" ); @@ -250,35 +249,36 @@ void TGArray::parse_bin() // Write out an array. If rectified is true, the heights have been adjusted // for discontinuities. void TGArray::write_bin(const string root_dir, bool rectified, SGBucket& b) { - // generate output file name - string base = b.gen_base_path(); - string path = root_dir + "/" + base; - string extension = ".arr.new.gz"; - if (rectified) extension = ".arr.rectified.gz"; - SGPath sgp( path ); - sgp.append( "dummy" ); - sgp.create_dir( 0755 ); - - string array_file = path + "/" + b.gen_index_str() + extension; - SG_LOG(SG_GENERAL, SG_DEBUG, "array_file = " << array_file ); - - // write the file - gzFile fp; - if ( (fp = gzopen( array_file.c_str(), "wb9" )) == NULL ) { - SG_LOG(SG_GENERAL, SG_ALERT, "ERROR: cannot open " << array_file << " for writing!" ); - return; - } + // generate output file name + string base = b.gen_base_path(); + string path = root_dir + "/" + base; + string extension = ".arr.new.gz"; + if (rectified) + extension = ".arr.rectified.gz"; + SGPath sgp( path ); + sgp.append( "dummy" ); + sgp.create_dir( 0755 ); - int32_t header = 0x54474152; //'TGAR' - sgWriteLong(fp,header); - sgWriteInt(fp,originx); - sgWriteInt(fp,originy); - sgWriteInt(fp,cols); - sgWriteInt(fp,col_step); - sgWriteInt(fp,rows); - sgWriteInt(fp,row_step); - sgWriteShort(fp, rows*cols, in_data); - gzclose(fp); + string array_file = path + "/" + b.gen_index_str() + extension; + SG_LOG(SG_GENERAL, SG_DEBUG, "array_file = " << array_file ); + + // write the file + gzFile fp; + if ( (fp = gzopen( array_file.c_str(), "wb9" )) == NULL ) { + SG_LOG(SG_GENERAL, SG_ALERT, "ERROR: cannot open " << array_file << " for writing!" ); + return; + } + + int32_t header = 0x54474152; //'TGAR' + sgWriteLong(fp,header); + sgWriteInt(fp,originx); + sgWriteInt(fp,originy); + sgWriteInt(fp,cols); + sgWriteInt(fp,col_step); + sgWriteInt(fp,rows); + sgWriteInt(fp,row_step); + sgWriteShort(fp, rows*cols, in_data); + gzclose(fp); } // write an Array file @@ -296,18 +296,18 @@ bool TGArray::write( const string root_dir, SGBucket& b ) { // write the file gzFile fp; if ( (fp = gzopen( array_file.c_str(), "wb9" )) == NULL ) { - SG_LOG(SG_GENERAL, SG_ALERT, "ERROR: cannot open " << array_file << " for writing!" ); - return false; + SG_LOG(SG_GENERAL, SG_ALERT, "ERROR: cannot open " << array_file << " for writing!" ); + return false; } SG_LOG(SG_GENERAL, SG_DEBUG, "origin = " << originx << ", " << originy ); gzprintf( fp, "%d %d\n", (int)originx, (int)originy ); gzprintf( fp, "%d %d %d %d\n", cols, (int)col_step, rows, (int)row_step ); for ( int i = 0; i < cols; ++i ) { - for ( int j = 0; j < rows; ++j ) { - gzprintf( fp, "%d ", get_array_elev(i, j) ); - } - gzprintf( fp, "\n" ); + for ( int j = 0; j < rows; ++j ) { + gzprintf( fp, "%d ", get_array_elev(i, j) ); + } + gzprintf( fp, "\n" ); } gzclose(fp); @@ -610,19 +610,19 @@ double TGArray::altitude_from_grid( double lon, double lat ) const { yindex = (int)(ylocal); if ( xindex + 1 == cols ) { - xindex--; + xindex--; } if ( yindex + 1 == rows ) { - yindex--; + yindex--; } if ( (xindex < 0) || (xindex + 1 >= cols) || (yindex < 0) || (yindex + 1 >= rows) ) { - SG_LOG(SG_GENERAL, SG_DEBUG, "WARNING: Attempt to interpolate value outside of array!!!" ); - - return -9999; + SG_LOG(SG_GENERAL, SG_DEBUG, "WARNING: Attempt to interpolate value outside of array!!!" ); + + return -9999; } // Now check if we are on the same side of any cliffs @@ -924,4 +924,3 @@ bool TGArray::is_open() const return false; } } - diff --git a/src/Lib/Array/array.hxx b/src/Lib/Array/array.hxx index 46fe8854..e1e1b7e4 100644 --- a/src/Lib/Array/array.hxx +++ b/src/Lib/Array/array.hxx @@ -47,8 +47,9 @@ private: // number of columns and rows int cols, rows; - // Whether or not the input data have been rectified - bool rectified; + // Whether or not the input data have been rectified + bool rectified; + // Distance between column and row data points (in arc seconds) double col_step, row_step; @@ -59,15 +60,17 @@ private: std::vector corner_list; std::vector fitted_list; - // list of cliff contours - tgcontour_list cliffs_list; + // list of cliff contours + tgcontour_list cliffs_list; + void parse_bin(); - // Routines for height rectification - std::vector collect_bad_points(const double bad_zone); - bool is_bad_point(const int xgrid, const int ygrid, const std::vector bad_points) const; - double rectify_point(const int xgrid, const int ygrid, const std::vector bad_points) const; - bool is_near_cliff(const double lon1,const double lon2, const double bad_zone) const; + // Routines for height rectification + std::vector collect_bad_points(const double bad_zone); + bool is_bad_point(const int xgrid, const int ygrid, const std::vector bad_points) const; + double rectify_point(const int xgrid, const int ygrid, const std::vector bad_points) const; + bool is_near_cliff(const double lon1,const double lon2, const double bad_zone) const; + public: // Constructor @@ -80,8 +83,8 @@ public: // open an Array file (use "-" if input is coming from stdin) bool open ( const std::string& file_base ); - // Load contours from polygon files delineating height discontinuities - void load_cliffs(const std::string & height_base); + // Load contours from polygon files delineating height discontinuities + void load_cliffs(const std::string & height_base); // return if array was successfully opened or not bool is_open() const; @@ -95,9 +98,9 @@ public: // write an Array file bool write( const std::string root_dir, SGBucket& b ); - // write an Array file in binary format. If ht_rect is true, - // the file will have extension 'arr.rectified.gz' - void write_bin(const std::string root_dir, bool ht_rect, SGBucket& b); + // write an Array file in binary format. If ht_rect is true, + // the file will have extension 'arr.rectified.gz' + void write_bin(const std::string root_dir, bool ht_rect, SGBucket& b); // do our best to remove voids by picking data from the nearest // neighbor. @@ -127,8 +130,9 @@ public: int get_array_elev( int col, int row ) const; void set_array_elev( int col, int row, int val ); - // Check whether or not two points are on the same side of contour - bool check_points (const double a,const double b, const double c, const double d) const; + // Check whether or not two points are on the same side of contour + bool check_points (const double a,const double b, const double c, const double d) const; + // reset Array to initial state - ready to load another elevation file void unload( void ); }; diff --git a/src/Lib/terragear/tg_contour.cxx b/src/Lib/terragear/tg_contour.cxx index 0ef581d7..63b700a4 100644 --- a/src/Lib/terragear/tg_contour.cxx +++ b/src/Lib/terragear/tg_contour.cxx @@ -812,7 +812,7 @@ extern SGGeod InterpolateElevation( const SGGeod& dst_node, const SGGeod& start, static void AddIntermediateNodes( const SGGeod& p0, const SGGeod& p1, bool preserve3d, std::vector& nodes, tgContour& result, double bbEpsilon, double errEpsilon ) { - TGNode* new_pt; + TGNode* new_pt = nullptr; SGGeod new_geode; SG_LOG(SG_GENERAL, SG_BULK, " " << p0 << " <==> " << p1 ); From 40e554e1cff4b387569fe659e05c440e54d7326d Mon Sep 17 00:00:00 2001 From: Scott Giese Date: Sun, 20 Jan 2019 17:55:08 -0600 Subject: [PATCH 06/25] TerraGear now requires the C++14 Standard --- CMakeLists.txt | 10 ++++++---- CMakeModules/FindSimGear.cmake | 13 ++++++++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ba5cda9d..fe3e59f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,9 +18,9 @@ include (CheckCXXSourceCompiles) include (CheckIncludeFile) include (CPack) -# let's use & require C++11 - note these are only functional with CMake 3.1 +# let's use & require C++14 - note these are only functional with CMake 3.1 # we do manual fallbacks for CMake 3.0 in the compilers section -set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED YES) project(TerraGear) @@ -153,9 +153,11 @@ if(CMAKE_COMPILER_IS_GNUCXX) set(WARNING_FLAGS -Wall) if (CMAKE_VERSION VERSION_LESS 3.1) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") endif() -endif(CMAKE_COMPILER_IS_GNUCXX) +elseif (MSVC AND CMAKE_VERSION VERSION_LESS 3.1) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std=c++14") +endif() if (WIN32) if (MSVC) diff --git a/CMakeModules/FindSimGear.cmake b/CMakeModules/FindSimGear.cmake index 906026b9..7d696dc0 100644 --- a/CMakeModules/FindSimGear.cmake +++ b/CMakeModules/FindSimGear.cmake @@ -188,9 +188,16 @@ unset(SIMGEAR_COMPILE_TEST CACHE) # disable OSG dependencies for test-compiling set(CMAKE_REQUIRED_DEFINITIONS "-DNO_OPENSCENEGRAPH_INTERFACE") -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED YES) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") +if ((NOT CMAKE_CXX_STANDARD) OR (${CMAKE_CXX_STANDARD} LESS 11)) + set(CMAKE_CXX_STANDARD 11) + set(CMAKE_CXX_STANDARD_REQUIRED YES) + + if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_VERSION VERSION_LESS 3.1) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + elseif (MSVC AND CMAKE_VERSION VERSION_LESS 3.1) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std=c++11") + endif() +endif() check_cxx_source_runs( "#include From 3ec0a1eabba004ae1d9f694f81a5d713bb89ad56 Mon Sep 17 00:00:00 2001 From: Scott Giese Date: Sun, 20 Jan 2019 17:57:31 -0600 Subject: [PATCH 07/25] Expand initial Heap size to 16K to reduce occurrences of resizing --- src/Prep/Terra/GreedyInsert.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Prep/Terra/GreedyInsert.cc b/src/Prep/Terra/GreedyInsert.cc index 22be0b6f..b60d14cc 100644 --- a/src/Prep/Terra/GreedyInsert.cc +++ b/src/Prep/Terra/GreedyInsert.cc @@ -24,7 +24,7 @@ void TrackedTriangle::update(Subdivision& s) GreedySubdivision::GreedySubdivision(Map *map) { H = map; - heap = new Heap(128); + heap = new Heap(16384); int w = H->width; int h = H->height; From 1716820c16f7639c56698206087627cba555c4aa Mon Sep 17 00:00:00 2001 From: Scott Giese Date: Sun, 20 Jan 2019 18:02:41 -0600 Subject: [PATCH 08/25] genapt: Resolve memory leaks. Reclaimed 1,419,778 bytes in 6,419 blocks. genapt memory stability : Good. --- src/Airports/GenAirports850/airport.cxx | 44 +++++----- src/Airports/GenAirports850/airport.hxx | 32 +++---- src/Airports/GenAirports850/beznode.hxx | 5 +- src/Airports/GenAirports850/closedpoly.cxx | 66 +++++--------- src/Airports/GenAirports850/closedpoly.hxx | 18 ++-- src/Airports/GenAirports850/elevations.cxx | 2 +- src/Airports/GenAirports850/helipad.hxx | 4 +- src/Airports/GenAirports850/linearfeature.cxx | 20 ++--- src/Airports/GenAirports850/linearfeature.hxx | 12 +-- .../GenAirports850/linked_objects.hxx | 8 +- src/Airports/GenAirports850/main.cxx | 4 +- src/Airports/GenAirports850/object.hxx | 4 +- src/Airports/GenAirports850/parser.cxx | 87 +++++++++---------- src/Airports/GenAirports850/parser.hxx | 61 ++++++------- src/Airports/GenAirports850/runway.hxx | 6 +- src/Airports/GenAirports850/scheduler.cxx | 19 ++-- src/Airports/GenAirports850/taxiway.hxx | 4 +- src/Lib/terragear/tg_surface.cxx | 2 +- 18 files changed, 196 insertions(+), 202 deletions(-) diff --git a/src/Airports/GenAirports850/airport.cxx b/src/Airports/GenAirports850/airport.cxx index 1ac75a08..6b87c6f4 100644 --- a/src/Airports/GenAirports850/airport.cxx +++ b/src/Airports/GenAirports850/airport.cxx @@ -93,59 +93,59 @@ Airport::Airport( int c, char* def) Airport::~Airport() { - for (unsigned int i=0; i + #include #include #include @@ -20,46 +22,46 @@ public: Airport( int c, char* def); ~Airport(); - void AddRunway( Runway* runway ) + void AddRunway( std::shared_ptr runway ) { runways.push_back( runway ); } - void AddWaterRunway( WaterRunway* waterrunway ) + void AddWaterRunway( std::shared_ptr waterrunway ) { waterrunways.push_back( waterrunway ); } - void AddObj( LightingObj* lightobj ) + void AddObj( std::shared_ptr lightobj ) { lightobjects.push_back( lightobj ); } - void AddHelipad( Helipad* helipad ) + void AddHelipad( std::shared_ptr helipad ) { helipads.push_back( helipad ); } - void AddTaxiway( Taxiway* taxiway ) + void AddTaxiway( std::shared_ptr taxiway ) { taxiways.push_back( taxiway ); } - void AddPavement( ClosedPoly* pavement ) + void AddPavement( std::shared_ptr pavement ) { pavements.push_back( pavement ); } - void AddFeature( LinearFeature* feature ) + void AddFeature( std::shared_ptr feature ) { features.push_back( feature ); } - void AddFeatures( FeatureList* feature_list ) + void AddFeatures( FeatureList feature_list ) { - for (unsigned int i=0; isize(); i++) + for (auto feature : feature_list) { - features.push_back( feature_list->at(i) ); + features.push_back( feature ); } } @@ -68,22 +70,22 @@ public: return features.size(); } - void AddBoundary( ClosedPoly* bndry ) + void AddBoundary( std::shared_ptr bndry ) { boundary.push_back( bndry ); } - void AddWindsock( Windsock* windsock ) + void AddWindsock( std::shared_ptr windsock ) { windsocks.push_back( windsock ); } - void AddBeacon( Beacon* beacon ) + void AddBeacon( std::shared_ptr beacon ) { beacons.push_back( beacon ); } - void AddSign( Sign* sign ) + void AddSign( std::shared_ptr sign ) { signs.push_back( sign ); } @@ -163,6 +165,6 @@ private: debug_map debug_features; }; -typedef std::vector AirportList; +typedef std::vector> AirportList; #endif diff --git a/src/Airports/GenAirports850/beznode.hxx b/src/Airports/GenAirports850/beznode.hxx index 3fcac81f..7fc5524b 100644 --- a/src/Airports/GenAirports850/beznode.hxx +++ b/src/Airports/GenAirports850/beznode.hxx @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -282,8 +283,8 @@ private: // array of BezNodes make a contour -typedef std::vector BezContour; -typedef std::vector BezContourArray; +typedef std::vector> BezContour; +typedef std::vector BezContourArray; #endif diff --git a/src/Airports/GenAirports850/closedpoly.cxx b/src/Airports/GenAirports850/closedpoly.cxx index 3efb82c4..a0313f02 100644 --- a/src/Airports/GenAirports850/closedpoly.cxx +++ b/src/Airports/GenAirports850/closedpoly.cxx @@ -37,9 +37,8 @@ ClosedPoly::ClosedPoly( char* desc ) description = "none"; } - boundary = NULL; - cur_contour = NULL; - cur_feature = NULL; + boundary.clear(); + cur_contour.clear(); } ClosedPoly::ClosedPoly( int st, float s, float th, char* desc ) @@ -62,9 +61,8 @@ ClosedPoly::ClosedPoly( int st, float s, float th, char* desc ) description = "none"; } - boundary = NULL; - cur_contour = NULL; - cur_feature = NULL; + boundary.clear(); + cur_contour.clear(); } ClosedPoly::~ClosedPoly() @@ -72,14 +70,9 @@ ClosedPoly::~ClosedPoly() TG_LOG( SG_GENERAL, SG_DEBUG, "Deleting ClosedPoly " << description ); } -void ClosedPoly::AddNode( BezNode* node ) +void ClosedPoly::AddNode( std::shared_ptr node ) { - // if this is the first node of the contour - create a new contour - if (!cur_contour) - { - cur_contour = new BezContour; - } - cur_contour->push_back( node ); + cur_contour.push_back( node ); TG_LOG(SG_GENERAL, SG_DEBUG, "CLOSEDPOLY::ADDNODE : " << node->GetLoc() ); @@ -89,7 +82,7 @@ void ClosedPoly::AddNode( BezNode* node ) if (!cur_feature) { std::string feature_desc = description + " - "; - if (boundary) + if (boundary.size() == 0) { feature_desc += "hole"; } @@ -99,7 +92,7 @@ void ClosedPoly::AddNode( BezNode* node ) } TG_LOG(SG_GENERAL, SG_DEBUG, " Adding node " << node->GetLoc() << " to current linear feature " << cur_feature); - cur_feature = new LinearFeature(feature_desc, 1.0f ); + cur_feature = std::make_shared(feature_desc, 1.0f); } cur_feature->AddNode( node ); } @@ -122,26 +115,26 @@ void ClosedPoly::CloseCurContour() // add the contour to the poly - first one is the outer boundary // subsequent contours are holes - if ( boundary == NULL ) + if ( boundary.size() == 0 ) { boundary = cur_contour; // generate the convex hull from the bezcontour node locations // CreateConvexHull(); - cur_contour = NULL; + cur_contour.clear(); } else { holes.push_back( cur_contour ); - cur_contour = NULL; + cur_contour.clear(); } } -void ClosedPoly::ConvertContour( BezContour* src, tgContour& dst ) +void ClosedPoly::ConvertContour( const BezContour& src, tgContour& dst ) { - BezNode* curNode; - BezNode* nextNode; + std::shared_ptr curNode; + std::shared_ptr nextNode; SGGeod curLoc; SGGeod nextLoc; @@ -152,25 +145,25 @@ void ClosedPoly::ConvertContour( BezContour* src, tgContour& dst ) double total_dist; int num_segs = BEZIER_DETAIL; - TG_LOG(SG_GENERAL, SG_DEBUG, "Creating a contour with " << src->size() << " nodes"); + TG_LOG(SG_GENERAL, SG_DEBUG, "Creating a contour with " << src.size() << " nodes"); // clear anything in this point list dst.Erase(); // iterate through each bezier node in the contour - for (unsigned int i = 0; i <= src->size()-1; i++) + for (unsigned int i = 0; i <= src.size()-1; i++) { TG_LOG(SG_GENERAL, SG_DEBUG, "\nHandling Node " << i << "\n\n"); - curNode = src->at(i); - if (i < src->size() - 1) + curNode = src.at(i); + if (i < src.size() - 1) { - nextNode = src->at(i+1); + nextNode = src.at(i + 1); } else { // for the last node, next is the first. as all contours are closed - nextNode = src->at(0); + nextNode = src.at(0); } // now determine how we will iterate from current node to next node @@ -337,14 +330,14 @@ void ClosedPoly::Finish() tgContour dst_contour; // error handling - if (boundary == NULL) + if (boundary.size() == 0) { TG_LOG(SG_GENERAL, SG_ALERT, "no boundary"); } TG_LOG(SG_GENERAL, SG_DEBUG, "Converting a poly with " << holes.size() << " holes"); - if (boundary != NULL) + if (boundary.size() != 0) { // create the boundary ConvertContour( boundary, dst_contour ); @@ -367,22 +360,9 @@ void ClosedPoly::Finish() } // save memory by deleting unneeded resources - for (unsigned int i=0; isize(); i++) - { - delete boundary->at(i); - } - delete boundary; - boundary = NULL; + boundary.clear(); // and the hole contours - for (unsigned int i=0; isize(); j++) - { - delete holes[i]->at(j); - } - } - holes.clear(); } diff --git a/src/Airports/GenAirports850/closedpoly.hxx b/src/Airports/GenAirports850/closedpoly.hxx index 623add8b..a400d57c 100644 --- a/src/Airports/GenAirports850/closedpoly.hxx +++ b/src/Airports/GenAirports850/closedpoly.hxx @@ -1,6 +1,8 @@ #ifndef _BEZPOLY_H_ #define _BEZPOLY_H_ +#include + #include #include "beznode.hxx" @@ -14,7 +16,7 @@ public: ~ClosedPoly(); inline std::string GetDescription() { return description; } - void AddNode( BezNode* node ); + void AddNode( std::shared_ptr node ); void CloseCurContour(); void Finish(); @@ -36,15 +38,15 @@ public: tgAccumulator& accum, std::string& shapefile_name ); - FeatureList* GetFeatures() + FeatureList& GetFeatures() { - return &features; + return features; } private: // convert the BezierPoly to a normal Poly (adding nodes for the curves) void CreateConvexHull( void ); - void ConvertContour( BezContour* src, tgContour& dst ); + void ConvertContour( const BezContour& src, tgContour& dst ); std::string GetMaterial( int surface ); @@ -58,13 +60,13 @@ private: std::string description; // outer boundary definition as bezier nodes - BezContour* boundary; + BezContour boundary; // holes BezContourArray holes; // contour that nodes will be added until done - BezContour* cur_contour; + BezContour cur_contour; // Converted polygon after parsing complete tgPolygon pre_tess; @@ -73,10 +75,10 @@ private: tgpolygon_list shoulder_polys; // pavement definitions have multiple linear features (markings and lights for each contour) - LinearFeature* cur_feature; + std::shared_ptr cur_feature; FeatureList features; }; -typedef std::vector PavementList; +typedef std::vector> PavementList; #endif diff --git a/src/Airports/GenAirports850/elevations.cxx b/src/Airports/GenAirports850/elevations.cxx index 5607c290..3e017beb 100644 --- a/src/Airports/GenAirports850/elevations.cxx +++ b/src/Airports/GenAirports850/elevations.cxx @@ -109,7 +109,7 @@ double tgAverageElevation( const std::string &root, const string_list elev_src, } } - array.close(); + array.unload(); } else { done = true; } diff --git a/src/Airports/GenAirports850/helipad.hxx b/src/Airports/GenAirports850/helipad.hxx index 654734d4..5127f24e 100644 --- a/src/Airports/GenAirports850/helipad.hxx +++ b/src/Airports/GenAirports850/helipad.hxx @@ -16,6 +16,8 @@ #ifndef _HELIPAD_HXX #define _HELIPAD_HXX +#include + #include #include #include @@ -91,6 +93,6 @@ private: }; -typedef std::vector HelipadList; +typedef std::vector> HelipadList; #endif diff --git a/src/Airports/GenAirports850/linearfeature.cxx b/src/Airports/GenAirports850/linearfeature.cxx index fe5bdcf7..b8a0ed67 100644 --- a/src/Airports/GenAirports850/linearfeature.cxx +++ b/src/Airports/GenAirports850/linearfeature.cxx @@ -4,10 +4,10 @@ #include "beznode.hxx" #include "linearfeature.hxx" -void LinearFeature::ConvertContour( BezContour* src, bool closed ) +void LinearFeature::ConvertContour( const BezContour& src, bool closed ) { - BezNode* curNode; - BezNode* nextNode; + std::shared_ptr curNode; + std::shared_ptr nextNode; SGGeod curLoc; SGGeod nextLoc; @@ -22,24 +22,24 @@ void LinearFeature::ConvertContour( BezContour* src, bool closed ) Marking* cur_mark = NULL; Lighting* cur_light = NULL; - TG_LOG(SG_GENERAL, SG_DEBUG, " LinearFeature::ConvertContour - Creating a contour with " << src->size() << " nodes"); + TG_LOG(SG_GENERAL, SG_DEBUG, " LinearFeature::ConvertContour - Creating a contour with " << src.size() << " nodes"); // clear anything in the point list points.Erase(); // iterate through each bezier node in the contour - for (unsigned int i=0; i <= src->size()-1; i++) + for (unsigned int i = 0; i <= src.size() - 1; ++i) { - curNode = src->at(i); + curNode = src.at(i); - if (i < src->size() - 1) + if (i < src.size() - 1) { - nextNode = src->at(i+1); + nextNode = src.at(i+1); } else { // for the last node, next is the first. as all contours are closed - nextNode = src->at(0); + nextNode = src.at(0); } //////////////////////////////////////////////////////////////////////////////////// @@ -380,7 +380,7 @@ int LinearFeature::Finish( bool closed, unsigned int idx ) // create the inner and outer boundaries to generate polys // this generates 2 point lists for the contours, and remembers // the start stop points for markings and lights - ConvertContour( &contour, closed ); + ConvertContour( contour, closed ); // now generate the supoerpoly and texparams lists for markings for (unsigned int i=0; i + #include #include #include @@ -46,7 +48,7 @@ public: unsigned int start_idx; unsigned int end_idx; }; -typedef std::vector MarkingList; +typedef std::vector MarkingList; struct Lighting { @@ -65,7 +67,7 @@ public: return 0; } }; -typedef std::vector LightingList; +typedef std::vector LightingList; class LinearFeature { @@ -93,7 +95,7 @@ public: inline std::string GetDescription() { return description; } - void AddNode( BezNode* b ) + void AddNode( std::shared_ptr b ) { contour.push_back( b ); } @@ -111,7 +113,7 @@ private: LightingList lights; Lighting* cur_light; - void ConvertContour( BezContour* src, bool closed ); + void ConvertContour( const BezContour& src, bool closed ); // text description std::string description; @@ -126,6 +128,6 @@ private: tglightcontour_list lighting_polys; }; -typedef std::vector FeatureList; +typedef std::vector> FeatureList; #endif diff --git a/src/Airports/GenAirports850/linked_objects.hxx b/src/Airports/GenAirports850/linked_objects.hxx index c7ddf071..b50f4205 100644 --- a/src/Airports/GenAirports850/linked_objects.hxx +++ b/src/Airports/GenAirports850/linked_objects.hxx @@ -1,6 +1,8 @@ #ifndef _LINKED_OBJECTS_H_ #define _LINKED_OBJECTS_H_ +#include + #include class Windsock @@ -23,7 +25,7 @@ public: } }; -typedef std::vector WindsockList; +typedef std::vector> WindsockList; class Beacon @@ -46,7 +48,7 @@ public: } }; -typedef std::vector BeaconList; +typedef std::vector> BeaconList; class Sign { @@ -81,6 +83,6 @@ public: } }; -typedef std::vector SignList; +typedef std::vector> SignList; #endif diff --git a/src/Airports/GenAirports850/main.cxx b/src/Airports/GenAirports850/main.cxx index b6abdb88..f64705e4 100644 --- a/src/Airports/GenAirports850/main.cxx +++ b/src/Airports/GenAirports850/main.cxx @@ -57,6 +57,8 @@ void setup_default_elevation_sources(string_list& elev_src) { elev_src.push_back( "SRTM-1" ); elev_src.push_back( "SRTM-3" ); elev_src.push_back( "SRTM-30" ); + elev_src.push_back( "SRTMGL1" ); + elev_src.push_back( "SRTMGL3" ); } // Display help and usage @@ -349,7 +351,7 @@ int main(int argc, char **argv) } // Create the scheduler - Scheduler* scheduler = new Scheduler(input_file, work_dir, elev_src); + auto scheduler = std::make_unique(input_file, work_dir, elev_src); // auto scheduler = std::unique_ptr(new Scheduler(input_file, work_dir, elev_src)); // Add any debug diff --git a/src/Airports/GenAirports850/object.hxx b/src/Airports/GenAirports850/object.hxx index 361bd1b9..d819a574 100644 --- a/src/Airports/GenAirports850/object.hxx +++ b/src/Airports/GenAirports850/object.hxx @@ -1,6 +1,8 @@ #ifndef _OBJECT_H_ #define _OBJECT_H_ +#include + #include #include @@ -20,6 +22,6 @@ public: void BuildBtg( tglightcontour_list& lights ); }; -typedef std::vector LightingObjList; +typedef std::vector> LightingObjList; #endif diff --git a/src/Airports/GenAirports850/parser.cxx b/src/Airports/GenAirports850/parser.cxx index 92269fb2..9585774a 100644 --- a/src/Airports/GenAirports850/parser.cxx +++ b/src/Airports/GenAirports850/parser.cxx @@ -236,8 +236,7 @@ void Parser::run() cur_airport->GetCleanupTime( clean_time ); cur_airport->GetTriangulationTime( triangulation_time ); - delete cur_airport; - cur_airport = NULL; + cur_airport = nullptr; } log_time = time(0); @@ -250,12 +249,12 @@ void Parser::run() } } -BezNode* Parser::ParseNode( int type, char* line, BezNode* prevNode ) +std::shared_ptr Parser::ParseNode( int type, char* line, std::shared_ptr prevNode ) { double lat, lon; double ctrl_lat, ctrl_lon; int feat_type1, feat_type2; - BezNode *curNode = NULL; + std::shared_ptr curNode = nullptr; bool hasCtrl = false; bool close = false; @@ -347,15 +346,15 @@ BezNode* Parser::ParseNode( int type, char* line, BezNode* prevNode ) } // if this is a new node, add it - as first part never has prev cp - if (curNode == NULL) + if (curNode == nullptr) { if (hasCtrl) { - curNode = new BezNode(lat, lon, ctrl_lat, ctrl_lon); + curNode = std::make_shared(lat, lon, ctrl_lat, ctrl_lon); } else { - curNode = new BezNode(lat, lon); + curNode = std::make_shared(lat, lon); } } @@ -386,35 +385,35 @@ BezNode* Parser::ParseNode( int type, char* line, BezNode* prevNode ) curNode->SetTerm( term ); curNode->SetClose( close ); - return curNode; + return std::move(curNode); } -LinearFeature* Parser::ParseFeature( char* line ) +std::shared_ptr Parser::ParseFeature( char* line ) { - LinearFeature* feature; + std::shared_ptr feature; if (strlen( line )) { - feature = new LinearFeature(line, 0.0f); + feature = std::make_shared(line, 0.0f); } else { - feature = new LinearFeature(NULL, 0.0f); + feature = std::make_shared(nullptr, 0.0f); } TG_LOG(SG_GENERAL, SG_DEBUG, "Creating Linear Feature with description \"" << line << "\""); - return feature; + return std::move(feature); } -ClosedPoly* Parser::ParsePavement( char* line ) +std::shared_ptr Parser::ParsePavement( char* line ) { - ClosedPoly* poly; + std::shared_ptr poly; int st = 0; // surface type float s = 0.0f; // smoothness float th = 0.0f; // texture heading char desc[256]; // description - char *d = NULL; + char *d = nullptr; int numParams; numParams = sscanf(line, "%d %f %f %s", &st, &s, &th, desc); @@ -429,16 +428,16 @@ ClosedPoly* Parser::ParsePavement( char* line ) TG_LOG(SG_GENERAL, SG_DEBUG, "Creating Closed Poly with st " << st << " smoothness " << s << " texture heading " << th); } - poly = new ClosedPoly(st, s, th, d); + poly = std::make_shared(st, s, th, d); - return poly; + return std::move(poly); } -ClosedPoly* Parser::ParseBoundary( char* line ) +std::shared_ptr Parser::ParseBoundary( char* line ) { - ClosedPoly* poly; + std::shared_ptr poly; char desc[256]; - char *d = NULL; + char *d = nullptr; int numParams; numParams = sscanf(line, "%s", desc); @@ -453,9 +452,9 @@ ClosedPoly* Parser::ParseBoundary( char* line ) } TG_LOG(SG_GENERAL, SG_DEBUG, "Creating Closed Poly for airport boundary : " << d); - poly = new ClosedPoly(d); + poly = std::make_shared(d); - return poly; + return std::move(poly); } int Parser::SetState( int state ) @@ -467,7 +466,7 @@ int Parser::SetState( int state ) TG_LOG(SG_GENERAL, SG_DEBUG, "Closing and Adding pavement"); cur_pavement->Finish(); cur_airport->AddPavement( cur_pavement ); - cur_pavement = NULL; + cur_pavement = nullptr; } if ( cur_airport && cur_state == STATE_PARSE_BOUNDARY ) @@ -475,7 +474,7 @@ int Parser::SetState( int state ) TG_LOG(SG_GENERAL, SG_DEBUG, "Closing and Adding boundary"); cur_boundary->Finish(); cur_airport->AddBoundary( cur_boundary ); - cur_boundary = NULL; + cur_boundary = nullptr; } cur_state = state; @@ -489,7 +488,7 @@ int Parser::ParseLine(char* line) char* tok; int code; - BezNode* cur_node = NULL; + std::shared_ptr cur_node = nullptr; if (*line != '#') { @@ -509,7 +508,7 @@ int Parser::ParseLine(char* line) { SetState( STATE_PARSE_SIMPLE ); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing land airport: " << line); - cur_airport = new Airport( code, line ); + cur_airport = std::make_shared( code, line ); } else { @@ -521,7 +520,7 @@ int Parser::ParseLine(char* line) { SetState( STATE_PARSE_SIMPLE ); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing heliport: " << line); - cur_airport = new Airport( code, line ); + cur_airport = std::make_shared( code, line ); } else { @@ -532,7 +531,7 @@ int Parser::ParseLine(char* line) case LAND_RUNWAY_CODE: SetState( STATE_PARSE_SIMPLE ); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing runway: " << line); - cur_runway = new Runway(line); + cur_runway = std::make_shared(line); if (cur_airport) { cur_airport->AddRunway( cur_runway ); @@ -542,7 +541,7 @@ int Parser::ParseLine(char* line) case WATER_RUNWAY_CODE: SetState( STATE_PARSE_SIMPLE ); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing water runway: " << line); - cur_waterrunway = new WaterRunway(line); + cur_waterrunway = std::make_shared(line); if (cur_airport) { cur_airport->AddWaterRunway( cur_waterrunway ); @@ -551,7 +550,7 @@ int Parser::ParseLine(char* line) case HELIPAD_CODE: SetState( STATE_PARSE_SIMPLE ); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing helipad: " << line); - cur_helipad = new Helipad(line); + cur_helipad = std::make_shared(line); if (cur_airport) { cur_airport->AddHelipad( cur_helipad ); @@ -561,7 +560,7 @@ int Parser::ParseLine(char* line) case TAXIWAY_CODE: SetState( STATE_PARSE_SIMPLE ); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing taxiway: " << line); - cur_taxiway = new Taxiway(line); + cur_taxiway = std::make_shared(line); if (cur_airport) { cur_airport->AddTaxiway( cur_taxiway ); @@ -658,11 +657,11 @@ int Parser::ParseLine(char* line) cur_feat->Finish( true, cur_airport->NumFeatures() ); cur_airport->AddFeature( cur_feat ); } - cur_feat = NULL; + cur_feat = nullptr; SetState( STATE_PARSE_SIMPLE ); } - prev_node = NULL; - cur_node = NULL; + prev_node = nullptr; + cur_node = nullptr; break; case TERM_NODE_CODE: @@ -696,15 +695,13 @@ int Parser::ParseLine(char* line) else { TG_LOG(SG_GENERAL, SG_ALERT, "Parsing termination node with no previous nodes!!!" ); - - // this feature is bogus... - delete cur_feat; } - cur_feat = NULL; + + cur_feat = nullptr; SetState( STATE_PARSE_SIMPLE ); } - prev_node = NULL; - cur_node = NULL; + prev_node = nullptr; + cur_node = nullptr; break; case AIRPORT_VIEWPOINT_CODE: @@ -718,25 +715,25 @@ int Parser::ParseLine(char* line) case LIGHT_BEACON_CODE: SetState( STATE_PARSE_SIMPLE ); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing light beacon: " << line); - cur_beacon = new Beacon(line); + cur_beacon = std::make_shared(line); cur_airport->AddBeacon( cur_beacon ); break; case WINDSOCK_CODE: SetState( STATE_PARSE_SIMPLE ); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing windsock: " << line); - cur_windsock = new Windsock(line); + cur_windsock = std::make_shared(line); cur_airport->AddWindsock( cur_windsock ); break; case TAXIWAY_SIGN: SetState( STATE_PARSE_SIMPLE ); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing taxiway sign: " << line); - cur_sign = new Sign(line); + cur_sign = std::make_shared(line); cur_airport->AddSign( cur_sign ); break; case LIGHTING_OBJECT: SetState( STATE_PARSE_SIMPLE ); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing lighting object: " << line); - cur_object = new LightingObj(line); + cur_object = std::make_shared(line); cur_airport->AddObj( cur_object ); break; case COMM_FREQ1_CODE: diff --git a/src/Airports/GenAirports850/parser.hxx b/src/Airports/GenAirports850/parser.hxx index ba6a2561..565a7eb2 100644 --- a/src/Airports/GenAirports850/parser.hxx +++ b/src/Airports/GenAirports850/parser.hxx @@ -3,6 +3,7 @@ #include #include +#include #include @@ -94,19 +95,19 @@ public: work_dir = root; elevation = elev_src; - cur_airport = NULL; - cur_runway = NULL; - cur_waterrunway = NULL; - cur_helipad = NULL; - cur_taxiway = NULL; - cur_pavement = NULL; - cur_boundary = NULL; - cur_feat = NULL; - cur_object = NULL; - cur_windsock = NULL; - cur_beacon = NULL; - cur_sign = NULL; - prev_node = NULL; + cur_airport = nullptr; + cur_runway = nullptr; + cur_waterrunway = nullptr; + cur_helipad = nullptr; + cur_taxiway = nullptr; + cur_pavement = nullptr; + cur_boundary = nullptr; + cur_feat = nullptr; + cur_object = nullptr; + cur_windsock = nullptr; + cur_beacon = nullptr; + cur_sign = nullptr; + prev_node = nullptr; cur_state = STATE_NONE; } @@ -124,14 +125,14 @@ private: int SetState( int state ); - BezNode* ParseNode( int type, char* line, BezNode* prevNode ); - LinearFeature* ParseFeature( char* line ); - ClosedPoly* ParsePavement( char* line ); - ClosedPoly* ParseBoundary( char* line ); + std::shared_ptr ParseNode( int type, char* line, std::shared_ptr prevNode ); + std::shared_ptr ParseFeature( char* line ); + std::shared_ptr ParsePavement( char* line ); + std::shared_ptr ParseBoundary( char* line ); int ParseLine( char* line ); - BezNode* prev_node; + std::shared_ptr prev_node; int cur_state; std::string filename; string_list elevation; @@ -139,18 +140,18 @@ private: // a polygon conists of an array of contours // (first is outside boundry, remaining are holes) - Airport* cur_airport; - Taxiway* cur_taxiway; - Runway* cur_runway; - WaterRunway* cur_waterrunway; - Helipad* cur_helipad; - ClosedPoly* cur_pavement; - ClosedPoly* cur_boundary; - LinearFeature* cur_feat; - LightingObj* cur_object; - Windsock* cur_windsock; - Beacon* cur_beacon; - Sign* cur_sign; + std::shared_ptr cur_airport; + std::shared_ptr cur_taxiway; + std::shared_ptr cur_runway; + std::shared_ptr cur_waterrunway; + std::shared_ptr cur_helipad; + std::shared_ptr cur_pavement; + std::shared_ptr cur_boundary; + std::shared_ptr cur_feat; + std::shared_ptr cur_object; + std::shared_ptr cur_windsock; + std::shared_ptr cur_beacon; + std::shared_ptr cur_sign; // debug std::string debug_path; diff --git a/src/Airports/GenAirports850/runway.hxx b/src/Airports/GenAirports850/runway.hxx index 05424505..b36a7e64 100644 --- a/src/Airports/GenAirports850/runway.hxx +++ b/src/Airports/GenAirports850/runway.hxx @@ -1,6 +1,8 @@ #ifndef _RUNWAY_H_ #define _RUNWAY_H_ +#include + #include #include #include @@ -176,7 +178,7 @@ private: tglightcontour_list gen_malsx( const std::string& kind, bool recip ); }; -typedef std::vector RunwayList; +typedef std::vector > RunwayList; class WaterRunway @@ -203,6 +205,6 @@ private: double lat[2]; double lon[2]; }; -typedef std::vector WaterRunwayList; +typedef std::vector > WaterRunwayList; #endif diff --git a/src/Airports/GenAirports850/scheduler.cxx b/src/Airports/GenAirports850/scheduler.cxx index 25a6a894..039341b1 100644 --- a/src/Airports/GenAirports850/scheduler.cxx +++ b/src/Airports/GenAirports850/scheduler.cxx @@ -4,6 +4,7 @@ #endif #include +#include #include #include @@ -370,7 +371,7 @@ bool Scheduler::AddAirports( long start_pos, tgRectangle* boundingBox ) case SEA_AIRPORT_CODE: case HELIPORT_CODE: { - Airport* airport = new Airport( code, def ); + auto airport = std::make_unique( code, def ); if (match) { // Start off with given snap value @@ -380,7 +381,6 @@ bool Scheduler::AddAirports( long start_pos, tgRectangle* boundingBox ) // remember this new apt pos and name, and clear match cur_apt_pos = cur_pos; cur_apt_name = airport->GetIcao(); - delete airport; match = false; } @@ -400,14 +400,13 @@ bool Scheduler::AddAirports( long start_pos, tgRectangle* boundingBox ) // if the the runway start / end coords are within the rect, // we have a winner { - Runway* runway = new Runway(def); + auto runway = std::make_unique(def); if ( boundingBox->isInside(runway->GetStart()) ) { match = true; } else if ( boundingBox->isInside(runway->GetEnd()) ) { match = true; } - delete runway; } break; @@ -415,14 +414,13 @@ bool Scheduler::AddAirports( long start_pos, tgRectangle* boundingBox ) // if the the runway start / end coords are within the rect, // we have a winner { - WaterRunway* runway = new WaterRunway(def); + auto runway = std::make_unique(def); if ( boundingBox->isInside(runway->GetStart()) ) { match = true; } else if ( boundingBox->isInside(runway->GetEnd()) ) { match = true; } - delete runway; } break; @@ -430,11 +428,10 @@ bool Scheduler::AddAirports( long start_pos, tgRectangle* boundingBox ) // if the heliport coords are within the rect, we have // a winner { - Helipad* helipad = new Helipad(def); + auto helipad = std::make_unique(def); if ( boundingBox->isInside(helipad->GetLoc()) ) { match = true; } - delete helipad; } break; @@ -496,9 +493,9 @@ void Scheduler::Schedule( int num_threads, std::string& summaryfile ) // csvfile.open( summaryfile.c_str(), std::ios_base::out | std::ios_base::trunc ); // csvfile.close(); - std::vector parsers; + std::vector> parsers; for (int i=0; i( filename, work_dir, elevation ); // parser->set_debug(); parser->start(); parsers.push_back( parser ); @@ -511,6 +508,6 @@ void Scheduler::Schedule( int num_threads, std::string& summaryfile ) // Then wait until they are finished for (unsigned int i=0; ijoin(); - delete parsers[i]; + parsers[i] = nullptr; } } diff --git a/src/Airports/GenAirports850/taxiway.hxx b/src/Airports/GenAirports850/taxiway.hxx index 7da527a6..3ec00aef 100644 --- a/src/Airports/GenAirports850/taxiway.hxx +++ b/src/Airports/GenAirports850/taxiway.hxx @@ -1,6 +1,8 @@ #ifndef _TAXIWAY_H_ #define _TAXIWAY_H_ +#include + #include #include #include @@ -39,6 +41,6 @@ private: void GenLights(tglightcontour_list& rwy_lights); }; -typedef std::vector TaxiwayList; +typedef std::vector> TaxiwayList; #endif diff --git a/src/Lib/terragear/tg_surface.cxx b/src/Lib/terragear/tg_surface.cxx index df8d4652..7a59077d 100644 --- a/src/Lib/terragear/tg_surface.cxx +++ b/src/Lib/terragear/tg_surface.cxx @@ -168,7 +168,7 @@ static void tgCalcElevations( const std::string &root, const string_list elev_sr } } - array.close(); + array.unload(); } else { done = true; From c9d2959f3aca8b6c1ebeb68da03d06b5b0fb1df2 Mon Sep 17 00:00:00 2001 From: Scott Giese Date: Sun, 20 Jan 2019 22:34:57 -0600 Subject: [PATCH 09/25] CMake: Fix build on Windows --- CMakeLists.txt | 2 -- CMakeModules/FindSimGear.cmake | 2 +- src/Airports/GenAirports850/CMakeLists.txt | 3 +-- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fe3e59f1..3dece2a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,8 +58,6 @@ if (MSVC) else (EXISTS ${TEST_3RDPARTY_DIR}) set(MSVC_3RDPARTY_ROOT NOT_FOUND CACHE PATH "Location where the third-party dependencies are extracted") endif (EXISTS ${TEST_3RDPARTY_DIR}) - - set( RT_LIBRARY "winmm.lib" ) else (MSVC) set(MSVC_3RDPARTY_ROOT) endif (MSVC) diff --git a/CMakeModules/FindSimGear.cmake b/CMakeModules/FindSimGear.cmake index 7d696dc0..2720c20b 100644 --- a/CMakeModules/FindSimGear.cmake +++ b/CMakeModules/FindSimGear.cmake @@ -157,7 +157,7 @@ else(SIMGEAR_SHARED) ${ZLIB_LIBRARY}) if(WIN32) - list(APPEND SIMGEAR_CORE_LIBRARY_DEPENDENCIES ws2_32.lib Shlwapi.lib ) + list(APPEND SIMGEAR_CORE_LIBRARY_DEPENDENCIES ws2_32.lib Shlwapi.lib Winmm.lib) endif(WIN32) if(NOT MSVC) diff --git a/src/Airports/GenAirports850/CMakeLists.txt b/src/Airports/GenAirports850/CMakeLists.txt index a699042d..00d280fe 100644 --- a/src/Airports/GenAirports850/CMakeLists.txt +++ b/src/Airports/GenAirports850/CMakeLists.txt @@ -33,7 +33,6 @@ target_link_libraries(genapts850 ${CMAKE_THREAD_LIBS_INIT} ${SIMGEAR_CORE_LIBRARIES} ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES} - ${Boost_LIBRARIES} - ${RT_LIBRARY}) + ${Boost_LIBRARIES}) install(TARGETS genapts850 RUNTIME DESTINATION bin) From ba4d58675a121eb268f47434d935c47518a9467a Mon Sep 17 00:00:00 2001 From: Scott Giese Date: Sat, 26 Jan 2019 23:59:54 -0600 Subject: [PATCH 10/25] ogr-decode: Resolve memory leaks. Reclaimed 529,410 bytes in 5,750 blocks. ogr-decode memory stability : Good. Remaining Leaks: 32 bytes in 1 block. --- src/Lib/terragear/tg_shapefile.cxx | 4 ++ src/Prep/OGRDecode/ogr-decode.cxx | 101 +++++++++++++++++++---------- 2 files changed, 70 insertions(+), 35 deletions(-) diff --git a/src/Lib/terragear/tg_shapefile.cxx b/src/Lib/terragear/tg_shapefile.cxx index 72968b90..932a3cf4 100644 --- a/src/Lib/terragear/tg_shapefile.cxx +++ b/src/Lib/terragear/tg_shapefile.cxx @@ -98,6 +98,10 @@ void* tgShapefile::CloseDatasource( void* ds_id ) { GDALDataset* datasource = ( GDALDataset * )ds_id; GDALClose((GDALDatasetH) datasource ); + + GDALDestroyDriverManager(); + tgShapefile::initialized = false; + return (void *)-1; } diff --git a/src/Prep/OGRDecode/ogr-decode.cxx b/src/Prep/OGRDecode/ogr-decode.cxx index ced8f8de..bff89797 100644 --- a/src/Prep/OGRDecode/ogr-decode.cxx +++ b/src/Prep/OGRDecode/ogr-decode.cxx @@ -356,11 +356,16 @@ void Decoder::run() // Main Thread void processLayer(OGRLayer* poLayer, tgChopper& results ) { - int feature_count=poLayer->GetFeatureCount(); + int feature_count = poLayer->GetFeatureCount(); - if (feature_count!=-1 && start_record>0 && start_record>=feature_count) { + if (feature_count != -1 && start_record > 0 && start_record >= feature_count) { SG_LOG( SG_GENERAL, SG_ALERT, "Layer has only " << feature_count << " records, but start record is set to " << start_record ); - exit( 1 ); + if (!continue_on_errors) { + SG_LOG( SG_GENERAL, SG_ALERT, "Aborting!" ); + exit( 1 ); + } + else + return; } /* determine the indices of the required columns */ @@ -372,8 +377,12 @@ void processLayer(OGRLayer* poLayer, tgChopper& results ) point_width_field=poFDefn->GetFieldIndex(point_width_col.c_str()); if (point_width_field==-1) { SG_LOG( SG_GENERAL, SG_ALERT, "Field " << point_width_col << " for point-width not found in layer" ); - if (!continue_on_errors) - exit( 1 ); + if (!continue_on_errors) { + SG_LOG( SG_GENERAL, SG_ALERT, "Aborting!" ); + exit( 1 ); + } + else + return; } } @@ -381,8 +390,12 @@ void processLayer(OGRLayer* poLayer, tgChopper& results ) line_width_field=poFDefn->GetFieldIndex(line_width_col.c_str()); if (line_width_field==-1) { SG_LOG( SG_GENERAL, SG_ALERT, "Field " << line_width_col << " for line-width not found in layer" ); - if (!continue_on_errors) - exit( 1 ); + if (!continue_on_errors) { + SG_LOG( SG_GENERAL, SG_ALERT, "Aborting!" ); + exit( 1 ); + } + else + return; } } @@ -390,8 +403,12 @@ void processLayer(OGRLayer* poLayer, tgChopper& results ) area_type_field=poFDefn->GetFieldIndex(area_type_col.c_str()); if (area_type_field==-1) { SG_LOG( SG_GENERAL, SG_ALERT, "Field " << area_type_col << " for area type not found in layer" ); - if (!continue_on_errors) - exit( 1 ); + if (!continue_on_errors) { + SG_LOG( SG_GENERAL, SG_ALERT, "Aborting!" ); + exit( 1 ); + } + else + return; } } @@ -400,42 +417,52 @@ void processLayer(OGRLayer* poLayer, tgChopper& results ) oSourceSRS=poLayer->GetSpatialRef(); if (oSourceSRS == NULL) { SG_LOG( SG_GENERAL, SG_ALERT, "Layer " << layername << " has no defined spatial reference system" ); - exit( 1 ); + if (!continue_on_errors) { + SG_LOG( SG_GENERAL, SG_ALERT, "Aborting!" ); + exit( 1 ); + } + else + return; } char* srsWkt; oSourceSRS->exportToWkt(&srsWkt); SG_LOG( SG_GENERAL, SG_DEBUG, "Source spatial reference system: " << srsWkt ); - OGRFree(srsWkt); + CPLFree(srsWkt); oTargetSRS.SetWellKnownGeogCS( "WGS84" ); - OGRCoordinateTransformation *poCT = OGRCreateCoordinateTransformation(oSourceSRS, &oTargetSRS); + auto poCT = OGRCreateCoordinateTransformation(oSourceSRS, &oTargetSRS); /* setup attribute and spatial queries */ if (use_spatial_query) { - double trans_min_x,trans_min_y,trans_max_x,trans_max_y; + double trans_min_x, trans_min_y, trans_max_x, trans_max_y; /* do a simple reprojection of the source SRS */ - OGRCoordinateTransformation *poCTinverse; + auto poCTinverse = OGRCreateCoordinateTransformation(&oTargetSRS, oSourceSRS); - poCTinverse = OGRCreateCoordinateTransformation(&oTargetSRS, oSourceSRS); + trans_min_x = spat_min_x; + trans_min_y = spat_min_y; + trans_max_x = spat_max_x; + trans_max_y = spat_max_y; - trans_min_x=spat_min_x; - trans_min_y=spat_min_y; - trans_max_x=spat_max_x; - trans_max_y=spat_max_y; - - poCTinverse->Transform(1,&trans_min_x,&trans_min_y); - poCTinverse->Transform(1,&trans_max_x,&trans_max_y); + poCTinverse->Transform(1, &trans_min_x, &trans_min_y); + poCTinverse->Transform(1, &trans_max_x, &trans_max_y); poLayer->SetSpatialFilterRect(trans_min_x, trans_min_y, trans_max_x, trans_max_y); + + OCTDestroyCoordinateTransformation ( poCTinverse ); } if (use_attribute_query) { if (poLayer->SetAttributeFilter(attribute_query.c_str()) != OGRERR_NONE) { SG_LOG( SG_GENERAL, SG_ALERT, "Error in query expression '" << attribute_query << "'" ); - exit( 1 ); + if (!continue_on_errors) { + SG_LOG( SG_GENERAL, SG_ALERT, "Aborting!" ); + exit( 1 ); + } + else + return; } } @@ -449,16 +476,16 @@ void processLayer(OGRLayer* poLayer, tgChopper& results ) // Now process the workqueue with threads // this just generates all the tgPolygons - std::vector decoders; + std::vector> decoders; for (int i=0; i( poCT, area_type_field, point_width_field, line_width_field, results ); decoder->start(); decoders.push_back( decoder ); } // Then wait until they are finished - for (unsigned int i=0; ijoin(); + for (auto decoder : decoders) { + decoder->join(); } OCTDestroyCoordinateTransformation ( poCT ); @@ -683,27 +710,30 @@ int main( int argc, char **argv ) { SG_LOG( SG_GENERAL, SG_DEBUG, "Opening datasource " << datasource << " for reading." ); GDALAllRegister(); - GDALDataset *poDS; + GDALDataset *poDS; poDS = (GDALDataset*) GDALOpenEx( datasource.c_str(), GDAL_OF_VECTOR, NULL, NULL, NULL ); - if( poDS == NULL ) + if ( poDS == NULL ) { SG_LOG( SG_GENERAL, SG_ALERT, "Failed opening datasource " << datasource ); - exit( 1 ); + + GDALDestroyDriverManager(); + + return EXIT_FAILURE; } SG_LOG( SG_GENERAL, SG_ALERT, "Processing datasource " << datasource ); - OGRLayer *poLayer; - if (argc>3) { - for (int i=3;i 3) { + for (int i = 3; i < argc; ++i) { poLayer = poDS->GetLayerByName( argv[i] ); - if (poLayer == NULL ) { SG_LOG( SG_GENERAL, SG_ALERT, "Failed opening layer " << argv[i] << " from datasource " << datasource ); - exit( 1 ); + return EXIT_FAILURE; } + processLayer(poLayer, results ); } } else { @@ -717,6 +747,7 @@ int main( int argc, char **argv ) { } GDALClose(poDS); + GDALDestroyDriverManager(); SG_LOG(SG_GENERAL, SG_ALERT, "Saving to buckets"); results.Save( save_shapefiles ); From 0739823db6a79eac9b8357be0e61fe96d2c98f1b Mon Sep 17 00:00:00 2001 From: Scott Giese Date: Sun, 27 Jan 2019 12:25:12 -0600 Subject: [PATCH 11/25] raw2ascii, demchop, and SRTM-30 are obsolete. --- README | 48 +++---------- README.cygwin | 5 +- README.howto | 14 ++-- src/Prep/DemChop/CMakeLists.txt | 10 --- src/Prep/DemChop/demchop.cxx | 104 ----------------------------- src/Prep/DemChop/process-DEM-30.sh | 7 -- src/Prep/TerraFit/terrafit.cc | 2 +- src/Prep/TerraFit/terrafit.py.in | 2 +- 8 files changed, 17 insertions(+), 175 deletions(-) delete mode 100644 src/Prep/DemChop/demchop.cxx delete mode 100755 src/Prep/DemChop/process-DEM-30.sh diff --git a/README b/README index f560615a..796adcd2 100644 --- a/README +++ b/README @@ -46,56 +46,26 @@ Preprocessing Terrain TerraGear supports several terrain data sources: -1. 30-arcsec SRTM based terrain data covering the world (recommended - over other 30-arcsec data sources): +1. [Preferred] SRTM (version 3): + Void filled, 1-arc-sec and 3-arc-sec, near worldwide coverage. - ftp://edcsgs9.cr.usgs.gov/pub/data/srtm/SRTM30/ + https://e4ftl01.cr.usgs.gov/MEASURES/SRTMGL1.003/ - I don't recall the details at the moment for processing this data. - Probably similar to the processing of the GLOBE data. - -2. 30-arcsec world wide data: GLOBE project: - - http://www.ngdc.noaa.gov/seg/topo/globe.shtml - - a) First convert the "bin" DEM format to "ascii" DEM format using - "Prep/DemRaw2ascii/raw2ascii" - - b) Then process the resulting files with "Prep/DemChop/demchop" + a) Chop up each .zip files using "Prep/DemChop/hgtchop" -3. 30-arcsec world wide data: GTOPO30 data: - - http://edcwww.cr.usgs.gov/landdaac/gtopo30/gtopo30.html - - a) First convert the "bin" DEM format to "ascii" DEM format using - "Prep/DemRaw2ascii/raw2ascii" - - b) Then process the resulting files with "Prep/DemChop/demchop" - - -4. SRTM (version 1 & 2) (1 and 3-arcsec nearly world wide coverage): +2. SRTM (version 1 & 2): + May contain voids, 1-arc-sec and 3-arc-sec, near worldwide coverage. ftp://edcsgs9.cr.usgs.gov/pub/data/srtm/ a) Chop up each .zip files using "Prep/DemChop/hgtchop" -5. 3-arcsec ASCII DEM files: - - Generally, I recommend using the SRTM data over this older data - set, however in places like Alaska, there is no SRTM coverage so - this data is better than the 30 arcsec data. - - http://edcwww.cr.usgs.gov/doc/edchome/ndcdb/ndcdb.html - - a) Create the .arr.gz files using the "Prep/DemChop/demchop" utility. - - The result for any of these terrain sources should be a "work" tree with a .arr.gz file for each FG tile. -6. SRTM data comes with 'voids'. These are areas where their +3. SRTM versions 1 & 2 come with 'voids'. These are areas where their automated data processing system could not reliably determine the elevation. Often this happens over water, or over mountain peaks. There is a big chunk of the Grand Canyon missing, a big chunk of @@ -106,13 +76,13 @@ with a .arr.gz file for each FG tile. I half trust is the USGS 3 arcsec DEM data for the USA. So we can't fix voids outside the USA right now. - In the same directory as DemChop and HgtChop there is a "fillvoids" + In the same directory as HgtChop there is a "fillvoids" program. You might wish to run it with something like the following command line: find /export/fgfs05/curt/Work/SRTM2-North_America3 -name '*.arr.gz' -exec ./fillvoids {} /stage/fgfs05/curt/Work/USGS-DEM-USA-3 \; -7. After you create the .arr.gz files you have to create a +4. After you create the .arr.gz files you have to create a corresponding .fit.gz file for each of these. This is a data reduction step which fits a set of polygons to the raw terrain with a set of constraints on the maximum error allowed relative to the diff --git a/README.cygwin b/README.cygwin index d0436ec0..c1479a44 100644 --- a/README.cygwin +++ b/README.cygwin @@ -23,7 +23,6 @@ under Windows. If running the tools from the standard Win32 command prompt a lot of the tools have problems with directory creation - with the tools that try to create many subdirectories this can be a major problem. It is much better to run the tools from a Cygwin bash shell -- in this case only raw2ascii has a directory creation problem - the -output directory specified on the command line needs to be manually -created. +- the output directory specified on the command line needs to be +manually created. diff --git a/README.howto b/README.howto index de0f8e16..0eb189a3 100644 --- a/README.howto +++ b/README.howto @@ -21,24 +21,18 @@ Preparation and Preprocessing 1) DEM data. As the first step you have to download DEM for the area you need. (You -can get them from USGS site). If this is a 30 arc sec DEM (which is most -probable) you need to transfer this file into ASCII format using -raw2ascii +can get them from USGS site). -Usage: ./raw2ascii - -Here output dir is quite arbitrary as we will remove all the files from -it later. Then you have to chop files that we got into the tiles used for the -scenery generation. You should use demchop for this. As we already have +scenery generation. You should use hgtchop for this. As we already have a number of files I'm using the following Perl script #-------------------------------------------------------------------------- #!/usr/bin/perl -my @files=glob("./*.dem"); +my @files=glob("./*.hgt"); my $size=@files; for (my $i=0;$i<$size;$i++) { - system("demchop $files[$i] /home/anovikov/w020n90/Work/DEM-30"); + system("hgtchop $files[$i] /home/anovikov/w020n90/Work/SRTM-3"); } #-------------------------------------------------------------------------- diff --git a/src/Prep/DemChop/CMakeLists.txt b/src/Prep/DemChop/CMakeLists.txt index 1d29e622..889410e1 100644 --- a/src/Prep/DemChop/CMakeLists.txt +++ b/src/Prep/DemChop/CMakeLists.txt @@ -1,15 +1,5 @@ include_directories(${PROJECT_SOURCE_DIR}/src/Lib/terragear) -add_executable(demchop demchop.cxx) - -target_link_libraries(demchop - DEM - ${ZLIB_LIBRARY} - ${SIMGEAR_CORE_LIBRARIES} - ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES}) - -install(TARGETS demchop RUNTIME DESTINATION bin) - add_executable(hgtchop hgtchop.cxx) target_link_libraries(hgtchop diff --git a/src/Prep/DemChop/demchop.cxx b/src/Prep/DemChop/demchop.cxx deleted file mode 100644 index 753fc0c0..00000000 --- a/src/Prep/DemChop/demchop.cxx +++ /dev/null @@ -1,104 +0,0 @@ -// demchop.cxx -- chop up a dem file into it's corresponding pieces and stuff -// them into the workspace directory -// -// Written by Curtis Olson, started March 1999. -// -// Copyright (C) 1997 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: demchop.cxx,v 1.13 2004-11-19 22:25:51 curt Exp $ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -#include -#include -#include - -#include - -#include -#include -#include - -#include - -using std::endl; -using std::cout; -using std::string; - - -int main(int argc, char **argv) { - sglog().setLogLevels( SG_ALL, SG_WARN ); - - if ( argc != 3 ) { - SG_LOG( SG_GENERAL, SG_ALERT, "Usage " << argv[0] << " " ); - return EXIT_FAILURE; - } - - auto start_time = std::chrono::high_resolution_clock::now(); - - string dem_name = argv[1]; - string work_dir = argv[2]; - - SGPath sgp( work_dir ); - sgp.append( "dummy" ); - sgp.create_dir( 0755 ); - - TGDem dem(dem_name); - dem.parse(); - dem.close(); - - SGGeod min = SGGeod::fromDeg(dem.get_originx() / 3600.0 + SG_HALF_BUCKET_SPAN, - dem.get_originy() / 3600.0 + SG_HALF_BUCKET_SPAN); - - SGGeod max = SGGeod::fromDeg( (dem.get_originx() + dem.get_cols() * dem.get_col_step()) / 3600.0 - SG_HALF_BUCKET_SPAN, - (dem.get_originy() + dem.get_rows() * dem.get_row_step()) / 3600.0 - SG_HALF_BUCKET_SPAN ); - SGBucket b_min( min ); - SGBucket b_max( max ); - - if ( b_min == b_max ) { - dem.write_area( work_dir, b_min ); - } else { - SGBucket b_cur; - int dx, dy, i, j; - - sgBucketDiff(b_min, b_max, &dx, &dy); - cout << "DEM file spans tile boundaries" << endl; - cout << " dx = " << dx << " dy = " << dy << endl; - - if ( (dx > 20) || (dy > 20) ) { - cout << "somethings really wrong!!!!" << endl; - return EXIT_FAILURE; - } - - for ( j = 0; j <= dy; j++ ) { - for ( i = 0; i <= dx; i++ ) { - b_cur = b_min.sibling(i, j); - dem.write_area( work_dir, b_cur ); - } - } - } - - auto finish_time = std::chrono::high_resolution_clock::now(); - std::chrono::duration elapsed = finish_time - start_time; - std::cout << std::endl << "Elapsed time: " << elapsed.count() << " seconds" << std::endl << std::endl; - - return EXIT_SUCCESS; -} diff --git a/src/Prep/DemChop/process-DEM-30.sh b/src/Prep/DemChop/process-DEM-30.sh deleted file mode 100755 index 2bbdf828..00000000 --- a/src/Prep/DemChop/process-DEM-30.sh +++ /dev/null @@ -1,7 +0,0 @@ -#! /bin/bash - -WORKDIR=$HOME/workdirs/world_scenery - -for f in $WORKDIR/SRTM-30-ASCII/*/*.dem; do - demchop $f $WORKDIR/SRTM-30 -done \ No newline at end of file diff --git a/src/Prep/TerraFit/terrafit.cc b/src/Prep/TerraFit/terrafit.cc index 43f5cdf2..7704632c 100644 --- a/src/Prep/TerraFit/terrafit.cc +++ b/src/Prep/TerraFit/terrafit.cc @@ -275,7 +275,7 @@ void usage(char* progname, const std::string& msg) { SG_LOG(SG_GENERAL,SG_INFO, "will produce a better surface approximation."); SG_LOG(SG_GENERAL,SG_INFO, ""); SG_LOG(SG_GENERAL,SG_INFO, "The input file must be a .arr.gz file such as that produced"); - SG_LOG(SG_GENERAL,SG_INFO, "by demchop or hgtchop utils."); + SG_LOG(SG_GENERAL,SG_INFO, "by the hgtchop utility."); SG_LOG(SG_GENERAL,SG_INFO, ""); SG_LOG(SG_GENERAL,SG_INFO, "Force will overwrite existing .arr.gz files, even if the input is older"); SG_LOG(SG_GENERAL,SG_INFO, ""); diff --git a/src/Prep/TerraFit/terrafit.py.in b/src/Prep/TerraFit/terrafit.py.in index af9714fc..0b22bf4b 100644 --- a/src/Prep/TerraFit/terrafit.py.in +++ b/src/Prep/TerraFit/terrafit.py.in @@ -184,7 +184,7 @@ def usage(msg=''): sys.stderr.write("will produce a better surface approximation.\n") sys.stderr.write("\n") sys.stderr.write("The input file must be a .arr.gz file such as that produced\n") - sys.stderr.write("by demchop or hgtchop utils.\n") + sys.stderr.write("by the hgtchop utility.\n") sys.stderr.write("\n") sys.stderr.write("**** NOTE ****:\n") sys.stderr.write("If a directory is input all .arr files in directory will be\n") From 4d0a32044d971818b32089130bb280f5cd31d0c3 Mon Sep 17 00:00:00 2001 From: Scott Giese Date: Sun, 27 Jan 2019 13:18:39 -0600 Subject: [PATCH 12/25] Remove features that were never implemented. --- src/Airports/GenAirports850/main.cxx | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/src/Airports/GenAirports850/main.cxx b/src/Airports/GenAirports850/main.cxx index f64705e4..d826971a 100644 --- a/src/Airports/GenAirports850/main.cxx +++ b/src/Airports/GenAirports850/main.cxx @@ -39,7 +39,7 @@ using namespace std; // Display usage static void usage( int argc, char **argv ) { TG_LOG(SG_GENERAL, SG_ALERT, "Usage: " << argv[0] << "\n--input=" - << "\n--work=\n[ --start-id=abcd ] [ --restart-id=abcd ] [ --nudge=n ] " + << "\n--work=\n[ --start-id=abcd ] [ --nudge=n ] " << "[--min-lon=] [--max-lon=] [--min-lat=] [--max-lat=] " << "[ --airport=abcd ] [--max-slope=] [--tile=] [--threads] [--threads=x]" << "[--chunk=] [--clear-dem-path] [--dem-path=] [--verbose] [--help] [--log-level=bulk|info|debug|warn|alert]"); @@ -81,8 +81,6 @@ static void help( int argc, char **argv, const string_list& elev_src ) { cout << "a valid airport code eg. --airport-id=KORD, or a starting airport can be specified using --start-id=abcd \n"; cout << "where once again abcd is a valid airport code. In this case, all airports in the file subsequent to the \n"; cout << "start-id are done. This is convenient when re-starting after a previous error. \n"; - cout << "If you want to restart with the airport after a problem icao, use --restart-id=abcd, as this works the same as\n"; - cout << " with the exception that the airport abcd is skipped \n"; cout << "\nAn input area may be specified by lat and lon extent using min and max lat and lon. \n"; //cout << "Alternatively, you may specify a chunk (10 x 10 degrees) or tile (1 x 1 degree) using a string \n"; //cout << "such as eg. w080n40, e000s27. \n"; @@ -154,9 +152,7 @@ int main(int argc, char **argv) std::string input_file = ""; std::string summary_file = "./genapt850.csv"; std::string start_id = ""; - std::string restart_id = ""; std::string airport_id = ""; - std::string last_apt_file = "./last_apt.txt"; int num_threads = 1; int arg_pos; @@ -179,10 +175,6 @@ int main(int argc, char **argv) { start_id = arg.substr(11); } - else if ( arg.find("--restart-id=") == 0 ) - { - restart_id = arg.substr(13); - } else if ( arg.find("--nudge=") == 0 ) { nudge = atoi( arg.substr(8).c_str() ); @@ -191,10 +183,6 @@ int main(int argc, char **argv) { gSnap = atof( arg.substr(7).c_str() ); } - else if ( arg.find("--last_apt_file=") == 0 ) - { - last_apt_file = arg.substr(16); - } else if ( arg.find("--min-lon=") == 0 ) { min.setLongitudeDeg(atof( arg.substr(10).c_str() )); @@ -314,8 +302,6 @@ int main(int argc, char **argv) sgp.append( "dummy" ); sgp.create_dir( 0755 ); - std::string lastaptfile = work_dir+"/last_apt"; - tgRectangle boundingBox(min, max); boundingBox.sanify(); From a8677d4f166cd6e8bfe9a3ad610937834c341944 Mon Sep 17 00:00:00 2001 From: Scott Giese Date: Sun, 27 Jan 2019 13:21:08 -0600 Subject: [PATCH 13/25] Minor improvements for resource management --- src/Lib/terragear/tg_chopper.cxx | 6 ++++-- src/Prep/Cliff/cliff-decode.cxx | 3 ++- src/Prep/GDALChop/gdalchop.cxx | 2 ++ src/Prep/OGRDecode/ogr-decode.cxx | 1 + 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Lib/terragear/tg_chopper.cxx b/src/Lib/terragear/tg_chopper.cxx index 0206373b..7606d7a9 100644 --- a/src/Lib/terragear/tg_chopper.cxx +++ b/src/Lib/terragear/tg_chopper.cxx @@ -165,15 +165,17 @@ long int tgChopper::GenerateIndex( std::string path ) if ( fread( (void*)&index, sizeof(long int), 1, fp ) != 1 ) { SG_LOG(SG_GENERAL, SG_ALERT, "Error reading Index file " << index_file << " abort"); + fclose( fp ); boost::interprocess::named_mutex::remove("tgChopper_index2"); exit(0); } + + rewind( fp ); } index++; - - rewind( fp ); fwrite( (void*)&index, sizeof(long int), 1, fp ); + fclose( fp ); } diff --git a/src/Prep/Cliff/cliff-decode.cxx b/src/Prep/Cliff/cliff-decode.cxx index 397b6c8b..3c2a0198 100644 --- a/src/Prep/Cliff/cliff-decode.cxx +++ b/src/Prep/Cliff/cliff-decode.cxx @@ -185,7 +185,7 @@ void processLayer(OGRLayer* poLayer, tgChopper& results ) char* srsWkt; oSourceSRS->exportToWkt(&srsWkt); SG_LOG( SG_GENERAL, SG_DEBUG, "Source spatial reference system: " << srsWkt ); - OGRFree(srsWkt); + CPLFree(srsWkt); oTargetSRS.SetWellKnownGeogCS( "WGS84" ); @@ -417,6 +417,7 @@ int main( int argc, char **argv ) { } GDALClose(poDS); + GDALDestroyDriverManager(); SG_LOG(SG_GENERAL, SG_ALERT, "Saving to buckets"); results.Add_Extension("cliffs"); diff --git a/src/Prep/GDALChop/gdalchop.cxx b/src/Prep/GDALChop/gdalchop.cxx index a89f7bee..7bdc26ae 100644 --- a/src/Prep/GDALChop/gdalchop.cxx +++ b/src/Prep/GDALChop/gdalchop.cxx @@ -532,6 +532,8 @@ int main(int argc, const char **argv) } } + GDALDestroyDriverManager(); + auto finish_time = std::chrono::high_resolution_clock::now(); std::chrono::duration elapsed = finish_time - start_time; std::cout << std::endl << "Elapsed time: " << elapsed.count() << " seconds" << std::endl << std::endl; diff --git a/src/Prep/OGRDecode/ogr-decode.cxx b/src/Prep/OGRDecode/ogr-decode.cxx index bff89797..6d61e158 100644 --- a/src/Prep/OGRDecode/ogr-decode.cxx +++ b/src/Prep/OGRDecode/ogr-decode.cxx @@ -459,6 +459,7 @@ void processLayer(OGRLayer* poLayer, tgChopper& results ) SG_LOG( SG_GENERAL, SG_ALERT, "Error in query expression '" << attribute_query << "'" ); if (!continue_on_errors) { SG_LOG( SG_GENERAL, SG_ALERT, "Aborting!" ); + OCTDestroyCoordinateTransformation ( poCT ); exit( 1 ); } else From fb50bb46814f011597af36e1d1d9f48c7cc25056 Mon Sep 17 00:00:00 2001 From: Scott Giese Date: Sun, 27 Jan 2019 18:59:01 -0600 Subject: [PATCH 14/25] [Genapts] Reduce technical debt. Migrate away from usage of . --- src/Airports/GenAirports850/airport.cxx | 20 ++--- src/Airports/GenAirports850/beznode.hxx | 2 +- src/Airports/GenAirports850/closedpoly.cxx | 47 ++++-------- src/Airports/GenAirports850/closedpoly.hxx | 2 +- src/Airports/GenAirports850/elevations.cxx | 2 +- src/Airports/GenAirports850/elevations.hxx | 2 +- src/Airports/GenAirports850/helipad.cxx | 25 +++--- src/Airports/GenAirports850/helipad.hxx | 2 +- src/Airports/GenAirports850/linearfeature.hxx | 21 ++--- .../GenAirports850/linked_objects.cxx | 33 +++++--- .../GenAirports850/linked_objects.hxx | 6 +- src/Airports/GenAirports850/object.cxx | 10 ++- src/Airports/GenAirports850/object.hxx | 2 +- src/Airports/GenAirports850/output.cxx | 1 - src/Airports/GenAirports850/runway.cxx | 76 +++++++++++++------ src/Airports/GenAirports850/runway.hxx | 4 +- src/Airports/GenAirports850/taxiway.cxx | 33 +++++--- src/Airports/GenAirports850/taxiway.hxx | 2 +- 18 files changed, 168 insertions(+), 122 deletions(-) diff --git a/src/Airports/GenAirports850/airport.cxx b/src/Airports/GenAirports850/airport.cxx index 6b87c6f4..6582a7d7 100644 --- a/src/Airports/GenAirports850/airport.cxx +++ b/src/Airports/GenAirports850/airport.cxx @@ -243,7 +243,6 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src ) // runway lights tglightcontour_list rwy_lights; - bool make_shapefiles = false; char debug_root[32]; sprintf(debug_root, "./airport_dbg/%s/", icao.c_str() ); @@ -305,6 +304,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src ) { TG_LOG(SG_GENERAL, SG_DEBUG, "Build Feature Poly " << i + 1 << " of " << features.size() << " : " << features[i]->GetDescription() ); + bool make_shapefiles = false; features[i]->BuildBtg( line_polys, rwy_lights, lf_accum, make_shapefiles ); } @@ -327,7 +327,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src ) //slivers.clear(); if ( isDebugRunway(i) ) { - sprintf( shapefile_name, "runway_%d", i ); + sprintf( shapefile_name, "runway_%u", i ); } else { strcpy( shapefile_name, "" ); } @@ -393,7 +393,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src ) //slivers.clear(); if ( isDebugPavement(i) ) { - sprintf( shapefile_name, "pvmnt_%d", i ); + sprintf( shapefile_name, "pvmnt_%u", i ); } else { strcpy( shapefile_name, "" ); } @@ -427,7 +427,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src ) //slivers.clear(); if ( isDebugTaxiway(i) ) { - sprintf( shapefile_name, "taxiway_%d", i ); + sprintf( shapefile_name, "taxiway_%u", i ); } else { strcpy( shapefile_name, "" ); } @@ -1106,10 +1106,10 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src ) } SGVec3d gbs_center = SGVec3d::fromGeod( b.get_center() ); - double dist_squared, radius_squared = 0; + double radius_squared = 0; for ( unsigned int i = 0; i < 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; } @@ -1258,7 +1258,7 @@ bool Airport::CheckZFightingTriangles( const char* prefix, const char* debug_roo tgContour intContour = intersection.GetContour( m ); if ( (intContour.GetSize() > 2) && (intContour.GetArea() > min_area_thresh) ) { TG_LOG( SG_GENERAL, SG_ALERT, prefix << "Z-FIGHTING between runway poly " << i << " and pavement poly " << k << " contour has " << intContour.GetSize() << " nodes " << " area is " << intContour.GetArea() ); - sprintf( desc, "rwy_%06d_pvmt_%06d", i, j ); + sprintf( desc, "rwy_%06u_pvmt_%06u", i, j ); tgShapefile::FromContour( intContour, debug_root, layer, desc ); zfighting = true; } @@ -1292,7 +1292,7 @@ bool Airport::CheckZFightingTriangles( const char* prefix, const char* debug_roo tgContour intContour = intersection.GetContour( m ); if ( (intContour.GetSize() > 2) && (intContour.GetArea() > min_area_thresh) ) { TG_LOG( SG_GENERAL, SG_ALERT, prefix << "Z-FIGHTING between pavement poly " << i << " and runway poly " << k << " contour has " << intContour.GetSize() << " nodes " << " area is " << intContour.GetArea() ); - sprintf( desc, "pvmt_%06d_rwy_%06d", i, j ); + sprintf( desc, "pvmt_%06u_rwy_%06u", i, j ); tgShapefile::FromContour( intContour, debug_root, layer, desc ); zfighting = true; } @@ -1325,7 +1325,7 @@ bool Airport::CheckZFightingTriangles( const char* prefix, const char* debug_roo tgContour intContour = intersection.GetContour( m ); if ( (intContour.GetSize() > 2) && (intContour.GetArea() > min_area_thresh) ) { TG_LOG( SG_GENERAL, SG_ALERT, prefix << "Z-FIGHTING between base poly and runway poly " << j << " contour has " << intContour.GetSize() << " nodes " << " area is " << intContour.GetArea() ); - sprintf( desc, "base_rwy_%06d", j ); + sprintf( desc, "base_rwy_%06u", j ); tgShapefile::FromContour( intContour, debug_root, layer, desc ); zfighting = true; } @@ -1353,7 +1353,7 @@ bool Airport::CheckZFightingTriangles( const char* prefix, const char* debug_roo tgContour intContour = intersection.GetContour( m ); if ( (intContour.GetSize() > 2) && (intContour.GetArea() > min_area_thresh) ) { TG_LOG( SG_GENERAL, SG_ALERT, prefix << "Z-FIGHTING between base poly and pavement poly " << j << " contour has " << intContour.GetSize() << " nodes " << " area is " << intContour.GetArea() ); - sprintf( desc, "base_pvmt_%06d", j ); + sprintf( desc, "base_pvmt_%06u", j ); tgShapefile::FromContour( intContour, debug_root, layer, desc ); zfighting = true; } diff --git a/src/Airports/GenAirports850/beznode.hxx b/src/Airports/GenAirports850/beznode.hxx index 7fc5524b..26f6d2e7 100644 --- a/src/Airports/GenAirports850/beznode.hxx +++ b/src/Airports/GenAirports850/beznode.hxx @@ -120,7 +120,7 @@ inline double CalculateTheta( const SGVec3d& dirCur, const SGVec3d& dirNext, con class BezNode { public: - BezNode( SGGeod l ) + explicit BezNode( SGGeod l ) { loc = l; diff --git a/src/Airports/GenAirports850/closedpoly.cxx b/src/Airports/GenAirports850/closedpoly.cxx index a0313f02..c3df2504 100644 --- a/src/Airports/GenAirports850/closedpoly.cxx +++ b/src/Airports/GenAirports850/closedpoly.cxx @@ -21,48 +21,33 @@ static void stringPurifier( std::string& s ) } } -ClosedPoly::ClosedPoly( char* desc ) +ClosedPoly::ClosedPoly( char* desc ) : + is_pavement(false), + is_border(false), + has_feature(false), + surface_type(0), + smoothness(0.0), + texture_heading(0.0), + description(std::string(desc ? desc : "none")) { - is_pavement = false; - is_border = true; - has_feature = false; - - if ( desc ) - { - description = desc; - stringPurifier(description); - } - else - { - description = "none"; - } + is_border = true; + + stringPurifier(description); boundary.clear(); cur_contour.clear(); } -ClosedPoly::ClosedPoly( int st, float s, float th, char* desc ) +ClosedPoly::ClosedPoly( int st, float s, float th, char* desc ) : + ClosedPoly( desc ) { surface_type = st; smoothness = s; texture_heading = th; is_pavement = (surface_type != 15) ? true : false; // wrong?? - is_border = false; + is_border = false; has_feature = true; - - if ( desc ) - { - description = desc; - stringPurifier(description); - } - else - { - description = "none"; - } - - boundary.clear(); - cur_contour.clear(); } ClosedPoly::~ClosedPoly() @@ -438,10 +423,10 @@ int ClosedPoly::BuildBtg( tgpolygon_list& rwy_polys, tgcontour_list& slivers, tg int ClosedPoly::BuildBtg( tgpolygon_list& rwy_polys, tgcontour_list& slivers, tgAccumulator& accum, std::string& shapefile_name ) { - char layer[128]; - if ( is_pavement && pre_tess.Contours() ) { + char layer[128]; + if( shapefile_name.size() ) { sprintf( layer, "%s_preclip", shapefile_name.c_str() ); tgShapefile::FromPolygon( pre_tess, "./airport_dbg", layer, std::string("preclip") ); diff --git a/src/Airports/GenAirports850/closedpoly.hxx b/src/Airports/GenAirports850/closedpoly.hxx index a400d57c..f75783bf 100644 --- a/src/Airports/GenAirports850/closedpoly.hxx +++ b/src/Airports/GenAirports850/closedpoly.hxx @@ -11,7 +11,7 @@ class ClosedPoly { public: - ClosedPoly( char* desc ); + explicit ClosedPoly( char* desc ); ClosedPoly( int st, float s, float th, char* desc ); ~ClosedPoly(); diff --git a/src/Airports/GenAirports850/elevations.cxx b/src/Airports/GenAirports850/elevations.cxx index 3e017beb..05a0a9b8 100644 --- a/src/Airports/GenAirports850/elevations.cxx +++ b/src/Airports/GenAirports850/elevations.cxx @@ -37,7 +37,7 @@ // lookup node elevations for each point in the SGGeod list. Returns // average of all points. Doesn't modify the original list. double tgAverageElevation( const std::string &root, const string_list elev_src, - const std::vector points_source ) + const std::vector& points_source ) { bool done = false; unsigned int i; diff --git a/src/Airports/GenAirports850/elevations.hxx b/src/Airports/GenAirports850/elevations.hxx index 1da27119..9851298a 100644 --- a/src/Airports/GenAirports850/elevations.hxx +++ b/src/Airports/GenAirports850/elevations.hxx @@ -25,7 +25,7 @@ // lookup node elevations for each point in the SGGeod list. Returns // average of all points. Doesn't modify the original list. double tgAverageElevation( const std::string &root, const string_list elev_src, - const std::vector points_source ); + const std::vector& points_source ); // lookup node elevations for each point in the specified nurbs++ // matrix. diff --git a/src/Airports/GenAirports850/helipad.cxx b/src/Airports/GenAirports850/helipad.cxx index 6c26c925..dd27495e 100644 --- a/src/Airports/GenAirports850/helipad.cxx +++ b/src/Airports/GenAirports850/helipad.cxx @@ -23,19 +23,26 @@ #include "runway.hxx" #include "debug.hxx" -#include -#include Helipad::Helipad(char* definition) { + // helipad format: + // designator lat lon heading length width surface markings shoulder smoothness edge-lighting + // example: + // "H1 21.30433555 -157.85586778 0.00 10.70 10.70 2 0 0 0.25 0\r" - // format: - // helipad designator lat lon heading length width surface markings shoulder smoothness edge lighting - - // int fscanf(FILE *stream, const char *format, ...); - sscanf(definition, "%s %lf %lf %lf %lf %lf %d %d %d %lf %d", - heli.designator, &heli.lat, &heli.lon, &heli.heading, &heli.length, &heli.width, &heli.surface, - &heli.marking, &heli.shoulder, &heli.smoothness, &heli.edge_lights); + std::istringstream ss(definition); + ss >> heli.designator + >> heli.lat + >> heli.lon + >> heli.heading + >> heli.length + >> heli.width + >> heli.surface + >> heli.marking + >> heli.shoulder + >> heli.smoothness + >> heli.edge_lights; TG_LOG(SG_GENERAL, SG_DEBUG, "Read helipad: (" << heli.lon << "," << heli.lat << ") heading: " << heli.heading << " length: " << heli.length << " width: " << heli.width ); } diff --git a/src/Airports/GenAirports850/helipad.hxx b/src/Airports/GenAirports850/helipad.hxx index 5127f24e..0dc3cc1a 100644 --- a/src/Airports/GenAirports850/helipad.hxx +++ b/src/Airports/GenAirports850/helipad.hxx @@ -25,7 +25,7 @@ class Helipad { public: - Helipad(char* def); + explicit Helipad(char* def); void BuildBtg( tgpolygon_list& heli_polys, tglightcontour_list& heli_lights, diff --git a/src/Airports/GenAirports850/linearfeature.hxx b/src/Airports/GenAirports850/linearfeature.hxx index 1d417ac3..74054be8 100644 --- a/src/Airports/GenAirports850/linearfeature.hxx +++ b/src/Airports/GenAirports850/linearfeature.hxx @@ -72,23 +72,18 @@ typedef std::vector LightingList; class LinearFeature { public: - LinearFeature( char* desc, double o ) + LinearFeature( char* desc, double o ) : + LinearFeature(std::string(desc ? desc : "none"), o) { - if ( desc ) - { - description = desc; - } - else - { - description = "none"; - } - offset = o; } - LinearFeature( std::string desc, double o ) + LinearFeature( const std::string& desc, double o ) : + offset(o), + width(0), + cur_mark(nullptr), + cur_light(nullptr), + description(desc) { - description = desc; - offset = o; } ~LinearFeature(); diff --git a/src/Airports/GenAirports850/linked_objects.cxx b/src/Airports/GenAirports850/linked_objects.cxx index 3eb82729..52c809e6 100644 --- a/src/Airports/GenAirports850/linked_objects.cxx +++ b/src/Airports/GenAirports850/linked_objects.cxx @@ -1,35 +1,50 @@ #include + #include "linked_objects.hxx" #include "debug.hxx" -#include -Windsock::Windsock( char* definition ) +Windsock::Windsock(char* definition) { - sscanf(definition, "%lf %lf %d", &lat, &lon, &lit); + std::istringstream ss(definition); + ss >> lat + >> lon + >> lit; TG_LOG(SG_GENERAL, SG_DEBUG, "Read Windsock: (" << lon << "," << lat << ") lit: " << lit ); } -Beacon::Beacon( char* definition ) +Beacon::Beacon(char* definition) { - sscanf(definition, "%lf %lf %d", &lat, &lon, &code); + std::istringstream ss(definition); + ss >> lat + >> lon + >> code; TG_LOG(SG_GENERAL, SG_DEBUG, "Read Beacon: (" << lon << "," << lat << ") code: " << code ); } -Sign::Sign( char* definition ) +Sign::Sign(char* definition) { char sgdef[256]; double def_heading; - sscanf(definition, "%lf %lf %lf %d %d %s", &lat, &lon, &def_heading, &reserved, &size, sgdef ); + std::istringstream ss(definition); + ss >> lat + >> lon + >> def_heading + >> reserved + >> size + >> sgdef; // 850 format sign heading is the heading which points away from the visible numbers // Flightgear wants the heading to be the heading in which the sign is read heading = -def_heading + 360.0; - TG_LOG(SG_GENERAL, SG_DEBUG, "Read Sign: (" << lon << "," << lat << ") heading " << def_heading << " size " << size << " definition: " << sgdef << " calc view heading: " << heading ); + TG_LOG(SG_GENERAL, SG_DEBUG, "Read Sign: (" << lon << "," << lat << + ") heading " << def_heading << + " size " << size << + " definition: " << sgdef << + " calc view heading: " << heading ); sgn_def = sgdef; } - diff --git a/src/Airports/GenAirports850/linked_objects.hxx b/src/Airports/GenAirports850/linked_objects.hxx index b50f4205..da4b2cf5 100644 --- a/src/Airports/GenAirports850/linked_objects.hxx +++ b/src/Airports/GenAirports850/linked_objects.hxx @@ -8,7 +8,7 @@ class Windsock { public: - Windsock(char* def); + explicit Windsock(char* def); double lat; double lon; @@ -31,7 +31,7 @@ typedef std::vector> WindsockList; class Beacon { public: - Beacon(char* def); + explicit Beacon(char* def); double lat; double lon; @@ -53,7 +53,7 @@ typedef std::vector> BeaconList; class Sign { public: - Sign(char* def); + explicit Sign(char* def); double lat; double lon; diff --git a/src/Airports/GenAirports850/object.cxx b/src/Airports/GenAirports850/object.cxx index 5565a9ee..e830504f 100644 --- a/src/Airports/GenAirports850/object.cxx +++ b/src/Airports/GenAirports850/object.cxx @@ -1,12 +1,18 @@ #include #include + #include "object.hxx" #include "debug.hxx" -#include LightingObj::LightingObj( char* definition ) { - sscanf(definition, "%lf %lf %d %lf %lf %s", &lat, &lon, &type, &heading, &glideslope, &assoc_rw); + std::istringstream ss(definition); + ss >> lat + >> lon + >> type + >> heading + >> glideslope + >> assoc_rw; TG_LOG(SG_GENERAL, SG_DEBUG, "Read lighting object: (" << lon << "," << lat << ") heading: " << heading << " type: " << type ); } diff --git a/src/Airports/GenAirports850/object.hxx b/src/Airports/GenAirports850/object.hxx index d819a574..f97aa530 100644 --- a/src/Airports/GenAirports850/object.hxx +++ b/src/Airports/GenAirports850/object.hxx @@ -9,7 +9,7 @@ class LightingObj { public: - LightingObj(char* def); + explicit LightingObj(char* def); double lat; double lon; diff --git a/src/Airports/GenAirports850/output.cxx b/src/Airports/GenAirports850/output.cxx index f7581e1c..898d1682 100644 --- a/src/Airports/GenAirports850/output.cxx +++ b/src/Airports/GenAirports850/output.cxx @@ -24,7 +24,6 @@ #include #endif -#include #include #include #include diff --git a/src/Airports/GenAirports850/runway.cxx b/src/Airports/GenAirports850/runway.cxx index 55873737..99556f2f 100644 --- a/src/Airports/GenAirports850/runway.cxx +++ b/src/Airports/GenAirports850/runway.cxx @@ -7,8 +7,6 @@ #include -#include - #include "global.hxx" #include "apt_math.hxx" #include "beznode.hxx" @@ -20,43 +18,74 @@ Runway::Runway(char* definition) { double az2; - // format: - // runway width surface shoulder smoothness centerline lights edge lighting distance remaining signs - // 100 46.02 2 1 0.00 1 2 1 + // runway format: + // width surface shoulder smoothness centerline lights edge lighting distance remaining signs + // 46.02 2 1 0.00 1 2 1 // - // runway number runway end lat runway end long threshold overrun markings approach lighting - // 09L 33.63470475 -084.44798671 0.00 120.09 3 7 + // runway number runway end lat runway end long threshold overrun markings approach lighting + // 09L 33.63470475 -084.44798671 0.00 120.09 3 7 // - // touchdown zone lighting runway end identifier lights - // 0 1 + // touchdown zone lighting runway end identifier lights + // 0 1 // - // runway number runway end lat runway end long threshold overrun markings approach lighting - // 27R 33.63469907 -084.40893004 0.00 120.09 3 6 + // runway number runway end lat runway end long threshold overrun markings approach lighting + // 27R 33.63469907 -084.40893004 0.00 120.09 3 6 // - // touchdown zone lighting runway end identifier lights - // 0 1 + // touchdown zone lighting runway end identifier lights + // 0 1 // Parse the line - // 46.02 2 1 0.00 1 2 1 09L 33.63470475 -084.44798671 0.00 120.09 3 7 0 1 27R 33.63469907 -084.40893004 0.00 120.09 3 6 0 1 + // 46.02 2 1 0.00 1 2 1 09L 33.63470475 -084.44798671 0.00 120.09 3 7 0 1 27R 33.63469907 -084.40893004 0.00 120.09 3 6 0 1 - // int fscanf(FILE *stream, const char *format, ...); - sscanf(definition, "%lf %d %d %lf %d %d %d %s %lf %lf %lf %lf %d %d %d %d %s %lf %lf %lf %lf %d %d %d %d", - &rwy.width, &rwy.surface, &rwy.shoulder, &rwy.smoothness, &rwy.centerline_lights, &rwy.edge_lights, &rwy.dist_remain_signs, - rwy.rwnum[0], &rwy.lat[0], &rwy.lon[0], &rwy.threshold[0], &rwy.overrun[0], &rwy.marking[0], &rwy.approach_lights[0], &rwy.tz_lights[0], &rwy.reil[0], - rwy.rwnum[1], &rwy.lat[1], &rwy.lon[1], &rwy.threshold[1], &rwy.overrun[1], &rwy.marking[1], &rwy.approach_lights[1], &rwy.tz_lights[1], &rwy.reil[1] - ); + std::istringstream ss(definition); + ss >> rwy.width + >> rwy.surface + >> rwy.shoulder + >> rwy.smoothness + >> rwy.centerline_lights + >> rwy.edge_lights + >> rwy.dist_remain_signs + >> rwy.rwnum[0] + >> rwy.lat[0] + >> rwy.lon[0] + >> rwy.threshold[0] + >> rwy.overrun[0] + >> rwy.marking[0] + >> rwy.approach_lights[0] + >> rwy.tz_lights[0] + >> rwy.reil[0] + >> rwy.rwnum[1] + >> rwy.lat[1] + >> rwy.lon[1] + >> rwy.threshold[1] + >> rwy.overrun[1] + >> rwy.marking[1] + >> rwy.approach_lights[1] + >> rwy.tz_lights[1] + >> rwy.reil[1]; // calculate runway heading and length (used a lot) SGGeodesy::inverse( GetStart(), GetEnd(), rwy.heading, az2, rwy.length ); - TG_LOG(SG_GENERAL, SG_DEBUG, "Read runway: (" << rwy.lon[0] << "," << rwy.lat[0] << ") to (" << rwy.lon[1] << "," << rwy.lat[1] << ") heading: " << rwy.heading << " length: " << rwy.length << " width: " << rwy.width ); - + TG_LOG(SG_GENERAL, SG_DEBUG, "Read runway: (" << rwy.lon[0] << "," << rwy.lat[0] << + ") to (" << rwy.lon[1] << "," << rwy.lat[1] << + ") heading: " << rwy.heading << + " length: " << rwy.length << + " width: " << rwy.width ); } WaterRunway::WaterRunway(char* definition) { - sscanf(definition, "%lf %d %s %lf %lf %s %lf %lf", &width, &buoys, rwnum[0], &lat[0], &lon[0], rwnum[1], &lat[1], &lon[1]); + std::istringstream ss(definition); + ss >> width + >> buoys + >> rwnum[0] + >> lat[0] + >> lon[0] + >> rwnum[1] + >> lat[1] + >> lon[1]; TG_LOG(SG_GENERAL, SG_DEBUG, "Read water runway: (" << lon[0] << "," << lat[0] << ") to (" << lon[1] << "," << lat[1] << ") width: " << width << " buoys = " << buoys ); } @@ -85,6 +114,7 @@ tgContour WaterRunway::GetBuoys() } } } + return buoys_nodes; } diff --git a/src/Airports/GenAirports850/runway.hxx b/src/Airports/GenAirports850/runway.hxx index b36a7e64..51ebece8 100644 --- a/src/Airports/GenAirports850/runway.hxx +++ b/src/Airports/GenAirports850/runway.hxx @@ -13,7 +13,7 @@ class Runway { public: - Runway(char* def); + explicit Runway(char* def); SGGeod GetStart() { @@ -184,7 +184,7 @@ typedef std::vector > RunwayList; class WaterRunway { public: - WaterRunway(char* def); + explicit WaterRunway(char* def); tgContour GetBuoys(); diff --git a/src/Airports/GenAirports850/taxiway.cxx b/src/Airports/GenAirports850/taxiway.cxx index 10be3956..ec397338 100644 --- a/src/Airports/GenAirports850/taxiway.cxx +++ b/src/Airports/GenAirports850/taxiway.cxx @@ -6,8 +6,6 @@ #include -#include - #include "global.hxx" #include "apt_math.hxx" #include "beznode.hxx" @@ -29,20 +27,31 @@ Taxiway::Taxiway(char* definition) double smoothness; int signs; - // format: - // taxiway lat lon designation heading length threshold overrun - // 10 44.38085600 -074.20606200 xxx 79.29 3384 0.0 0.0 + // taxiway format: + // lat lon designation heading length threshold overrun + // 44.38085600 -074.20606200 xxx 79.29 3384 0.0 0.0 // - // width lighting surface shoulder markings smoothness dist remain - // 60 161161 1 0 0 0.35 0 + // width lighting surface shoulder markings smoothness dist remain + // 60 161161 1 0 0 0.35 0 // Parse the line - // 44.38085600 -074.20606200 xxx 79.29 3384 0.0 0.0 60 161161 1 0 0 0.35 0 + // 44.38085600 -074.20606200 xxx 79.29 3384 0.0 0.0 60 161161 1 0 0 0.35 0 - // int fscanf(FILE *stream, const char *format, ...); - sscanf(definition, "%lf %lf %s %lf %lf %lf %lf %lf %s %d %d %d %lf %d", - &lat, &lon, designation, &heading, &length, &threshold, &overrun, - &width, lighting, &surface, &shoulder, &markings, &smoothness, &signs); + std::istringstream ss(definition); + ss >> lat + >> lon + >> designation + >> heading + >> length + >> threshold + >> overrun + >> width + >> lighting + >> surface + >> shoulder + >> markings + >> smoothness + >> signs; TG_LOG(SG_GENERAL, SG_DEBUG, "Read taxiway: (" << lon << "," << lat << ") heading: " << heading << " length: " << length << " width: " << width ); diff --git a/src/Airports/GenAirports850/taxiway.hxx b/src/Airports/GenAirports850/taxiway.hxx index 3ec00aef..bb439dda 100644 --- a/src/Airports/GenAirports850/taxiway.hxx +++ b/src/Airports/GenAirports850/taxiway.hxx @@ -13,7 +13,7 @@ class Taxiway { public: - Taxiway(char* def); + explicit Taxiway(char* def); int BuildBtg( tgpolygon_list& taxi_polys, tglightcontour_list& taxi_lights, From 4fa060649891644f452bd63fa59f2f45d7460ad5 Mon Sep 17 00:00:00 2001 From: Scott Giese Date: Mon, 28 Jan 2019 00:11:44 -0600 Subject: [PATCH 15/25] [Lib, Prep, Utils] Reduce technical debt. --- src/Lib/Array/array.cxx | 21 +++++++++++---------- src/Lib/Array/array.hxx | 10 +++++----- src/Lib/Array/rectify_height.cxx | 28 ++++++++++++++-------------- src/Prep/DemChop/srtmchop.cxx | 5 ++--- src/Prep/GDALChop/gdalchop.cxx | 4 ++-- src/Prep/TerraFit/terrafit.cc | 2 +- src/Utils/poly2ogr/poly2ogr.cxx | 9 ++++++--- 7 files changed, 41 insertions(+), 38 deletions(-) diff --git a/src/Lib/Array/array.cxx b/src/Lib/Array/array.cxx index 4eee6a13..0dc3cc9d 100644 --- a/src/Lib/Array/array.cxx +++ b/src/Lib/Array/array.cxx @@ -38,19 +38,20 @@ using std::string; -TGArray::TGArray( void ): +TGArray::TGArray() : array_in(NULL), fitted_in(NULL), + originx(0.0), originy(0.0), + cols(0), rows(0), + rectified(false), + col_step(0.0), row_step(0.0), in_data(NULL) { - } -TGArray::TGArray( const string &file ): - array_in(NULL), - fitted_in(NULL), - in_data(NULL) +TGArray::TGArray( const string &file ) : + TGArray() { TGArray::open(file); } @@ -248,7 +249,7 @@ void TGArray::parse_bin() // Write out an array. If rectified is true, the heights have been adjusted // for discontinuities. -void TGArray::write_bin(const string root_dir, bool rectified, SGBucket& b) { +void TGArray::write_bin(const string& root_dir, bool rectified, SGBucket& b) { // generate output file name string base = b.gen_base_path(); string path = root_dir + "/" + base; @@ -282,7 +283,7 @@ void TGArray::write_bin(const string root_dir, bool rectified, SGBucket& b) { } // write an Array file -bool TGArray::write( const string root_dir, SGBucket& b ) { +bool TGArray::write( const string& root_dir, SGBucket& b ) { // generate output file name string base = b.gen_base_path(); string path = root_dir + "/" + base; @@ -444,7 +445,7 @@ std::vector TGArray::collect_bad_points(const double bad_zone) { } // Check to see if the specified grid point is bad -bool TGArray::is_bad_point(const int xgrid, const int ygrid, const std::vector bad_points) const { +bool TGArray::is_bad_point(const int xgrid, const int ygrid, const std::vector& bad_points) const { int grididx; grididx = xgrid+ygrid*cols; auto result = std::find( std::begin(bad_points),std::end(bad_points),grididx ); @@ -503,7 +504,7 @@ through the three known points. TODO: Handle points on the boundaries. */ -double TGArray::rectify_point(const int xgrid, const int ygrid, const std::vector bad_points) const { +double TGArray::rectify_point(const int xgrid, const int ygrid, const std::vector& bad_points) const { //xgrid: grid units horizontally //ygrid: grid units vertically //Loop over corner points, if no points available, give up diff --git a/src/Lib/Array/array.hxx b/src/Lib/Array/array.hxx index e1e1b7e4..c737b75a 100644 --- a/src/Lib/Array/array.hxx +++ b/src/Lib/Array/array.hxx @@ -67,15 +67,15 @@ private: // Routines for height rectification std::vector collect_bad_points(const double bad_zone); - bool is_bad_point(const int xgrid, const int ygrid, const std::vector bad_points) const; - double rectify_point(const int xgrid, const int ygrid, const std::vector bad_points) const; + bool is_bad_point(const int xgrid, const int ygrid, const std::vector& bad_points) const; + double rectify_point(const int xgrid, const int ygrid, const std::vector& bad_points) const; bool is_near_cliff(const double lon1,const double lon2, const double bad_zone) const; public: // Constructor TGArray( void ); - TGArray( const std::string& file ); + explicit TGArray( const std::string& file ); // Destructor ~TGArray( void ); @@ -96,11 +96,11 @@ public: bool parse( SGBucket& b ); // write an Array file - bool write( const std::string root_dir, SGBucket& b ); + bool write( const std::string& root_dir, SGBucket& b ); // write an Array file in binary format. If ht_rect is true, // the file will have extension 'arr.rectified.gz' - void write_bin(const std::string root_dir, bool ht_rect, SGBucket& b); + void write_bin(const std::string& root_dir, bool ht_rect, SGBucket& b); // do our best to remove voids by picking data from the nearest // neighbor. diff --git a/src/Lib/Array/rectify_height.cxx b/src/Lib/Array/rectify_height.cxx index b6bf7709..6c26220c 100644 --- a/src/Lib/Array/rectify_height.cxx +++ b/src/Lib/Array/rectify_height.cxx @@ -40,7 +40,7 @@ and if they have an associated cliff file, will adjust and then output the heights. */ // display usage and exit -static void usage( const std::string name ) { +static void usage( const std::string& name ) { SG_LOG(SG_GENERAL, SG_ALERT, "Usage: " << name); SG_LOG(SG_GENERAL, SG_ALERT, " --work-dir="); SG_LOG(SG_GENERAL, SG_ALERT, " --height-dir="); @@ -69,26 +69,26 @@ int main( int argc, char **argv) { // int arg_pos; for (arg_pos = 1; arg_pos < argc; arg_pos++) { - std::string arg = argv[arg_pos]; + std::string arg = argv[arg_pos]; - if (arg.find("--work-dir=") == 0) { + if (arg.compare(0, 11, "--work-dir=") == 0) { work_dir = arg.substr(11); - } else if (arg.find("--height-dir=") == 0) { - height_dir = arg.substr(13); - } else if (arg.find("--tile-id=") == 0) { + } else if (arg.compare(0, 13, "--height-dir=") == 0) { + height_dir = arg.substr(13); + } else if (arg.compare(0, 10, "--tile-id=") == 0) { tile_id = atol(arg.substr(10).c_str()); - } else if ( arg.find("--min-lon=") == 0 ) { + } else if ( arg.compare(0, 10, "--min-lon=") == 0 ) { min.setLongitudeDeg(atof( arg.substr(10).c_str() )); - } else if ( arg.find("--max-lon=") == 0 ) { + } else if ( arg.compare(0, 10, "--max-lon=") == 0 ) { max.setLongitudeDeg(atof( arg.substr(10).c_str() )); - } else if ( arg.find("--min-lat=") == 0 ) { + } else if ( arg.compare(0, 10, "--min-lat=") == 0 ) { min.setLatitudeDeg(atof( arg.substr(10).c_str() )); - } else if ( arg.find("--max-lat=") == 0 ) { + } else if ( arg.compare(0, 10, "--max-lat=") == 0 ) { max.setLatitudeDeg(atof( arg.substr(10).c_str() )); - } else if ( arg.find("--min-dist=") == 0) { - bad_zone = atof(arg.substr(11).c_str()); - } else if (arg.find("--") == 0) { - usage(argv[0]); + } else if ( arg.compare(0, 11, "--min-dist=") == 0) { + bad_zone = atof(arg.substr(11).c_str()); + } else if (arg.compare(0, 2, "--") == 0) { + usage(argv[0]); } else { break; } diff --git a/src/Prep/DemChop/srtmchop.cxx b/src/Prep/DemChop/srtmchop.cxx index 5866951a..7fe50dad 100644 --- a/src/Prep/DemChop/srtmchop.cxx +++ b/src/Prep/DemChop/srtmchop.cxx @@ -59,7 +59,7 @@ using std::ios; #define MAX_HGT_SIZE 6001 class TGSrtmTiff : public TGSrtmBase { public: - TGSrtmTiff( const SGPath &file ); + explicit TGSrtmTiff( const SGPath &file ); ~TGSrtmTiff(); bool open( const SGPath &f ); bool close(); @@ -181,8 +181,7 @@ bool TGSrtmTiff::open( const SGPath &f ) { } bool TGSrtmTiff::load() { - int size; - cols = rows = size = 6000; + cols = rows = 6000; col_step = row_step = 3; uint32 w, h, d; diff --git a/src/Prep/GDALChop/gdalchop.cxx b/src/Prep/GDALChop/gdalchop.cxx index 7bdc26ae..daffa97e 100644 --- a/src/Prep/GDALChop/gdalchop.cxx +++ b/src/Prep/GDALChop/gdalchop.cxx @@ -76,7 +76,7 @@ int SimpleRasterTransformer(void *pTransformerArg, int bDstToSrc, int nPointCount, double *x, double *y, double *z, int *panSuccess ) { - SimpleRasterTransformerInfo* info = (SimpleRasterTransformerInfo*)pTransformerArg; + SimpleRasterTransformerInfo* info = static_cast(pTransformerArg); int success; if (bDstToSrc) { @@ -105,7 +105,7 @@ int SimpleRasterTransformer(void *pTransformerArg, class ImageInfo { public: - ImageInfo(GDALDataset *dataset); + explicit ImageInfo(GDALDataset *dataset); void GetBounds(double &n, double &s, double &e, double &w) const { n = north; diff --git a/src/Prep/TerraFit/terrafit.cc b/src/Prep/TerraFit/terrafit.cc index 7704632c..59bf89bf 100644 --- a/src/Prep/TerraFit/terrafit.cc +++ b/src/Prep/TerraFit/terrafit.cc @@ -75,7 +75,7 @@ SGLockedQueue global_workQueue; */ class ArrayMap: public Terra::Map { public: - ArrayMap(TGArray& array): array(array) { + explicit ArrayMap(TGArray& array): array(array) { width=array.get_cols(); height=array.get_rows(); min=30000; diff --git a/src/Utils/poly2ogr/poly2ogr.cxx b/src/Utils/poly2ogr/poly2ogr.cxx index 00c834ef..33c7445f 100644 --- a/src/Utils/poly2ogr/poly2ogr.cxx +++ b/src/Utils/poly2ogr/poly2ogr.cxx @@ -147,10 +147,12 @@ OGRLayer* get_layer_for_material(const std::string& material) { OGRLinearRing* make_ring_from_fan(const int_list& fan, const std::vector& nodes) { OGRLinearRing* ring = new OGRLinearRing(); int_list::const_iterator vertex = fan.begin(); + if (fan[1]==fan[fan.size()-1]) { /* The fan is closed, so the first vertex is in the interior */ - vertex++; + ++vertex; } + for (;vertex!=fan.end();++vertex) { OGRPoint *point=new OGRPoint(); const SGGeod& node = nodes[*vertex]; @@ -347,12 +349,13 @@ void process_polygon_file(const std::string& path) { for (int pt=0;pt> x >> y; point->setX(x); point->setY(y); + if (poly3d) { + double z; in >> z; point->setZ(z); } else { From 279868b7829ad787c2e10df045b2e9296cdcd3d0 Mon Sep 17 00:00:00 2001 From: Scott Giese Date: Mon, 28 Jan 2019 01:10:53 -0600 Subject: [PATCH 16/25] [Utils] Discontinue usage of deprecated GDAL methods. --- src/Utils/poly2ogr/poly2ogr.cxx | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/Utils/poly2ogr/poly2ogr.cxx b/src/Utils/poly2ogr/poly2ogr.cxx index 33c7445f..febfb3e2 100644 --- a/src/Utils/poly2ogr/poly2ogr.cxx +++ b/src/Utils/poly2ogr/poly2ogr.cxx @@ -459,10 +459,13 @@ void usage(const char* progname, const std::string& msg) { SG_LOG(SG_GENERAL, SG_INFO, "\t--format format"); SG_LOG(SG_GENERAL, SG_INFO, "\t\tSpecify the output format"); SG_LOG(SG_GENERAL, SG_INFO, "\t\tAvailable formats:"); - OGRSFDriverRegistrar* registrar=OGRSFDriverRegistrar::GetRegistrar(); - for (int i=0;iGetDriverCount();i++) { - SG_LOG(SG_GENERAL, SG_INFO, "\t\t\t-f \"" << registrar->GetDriver(i)->GetDescription() << "\""); + + auto driverManager = GetGDALDriverManager(); + for (int i = 0; i < driverManager->GetDriverCount(); ++i) { + auto ogrDriver = driverManager->GetDriver(i); + SG_LOG(SG_GENERAL, SG_INFO, "\t\t\t-f \"" << ogrDriver->GetDescription() << "\""); } + SG_LOG(SG_GENERAL, SG_INFO, "\t\tDefault: ESRI Shapefile"); SG_LOG(SG_GENERAL, SG_INFO, ""); SG_LOG(SG_GENERAL, SG_INFO, "The polygons from the given paths are read and transferred"); @@ -483,7 +486,7 @@ struct option options[]={ int main(int argc, char** argv) { sglog().setLogLevels( SG_ALL, SG_DEBUG ); - OGRRegisterAll(); + GDALAllRegister(); int option; @@ -518,18 +521,18 @@ int main(int argc, char** argv) { exit(1); } - const char* dst_datasource=argv[optind++]; - OGRSFDriver *ogrdriver; + auto driverManager = GetGDALDriverManager(); - ogrdriver = (OGRSFDriver*) OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(format_name); - if (!ogrdriver) { - usage(argv[0],std::string("Unknown datasource format driver:")+format_name); + auto gdalDriver = driverManager->GetDriverByName(format_name); + if (!gdalDriver) { + usage(argv[0], std::string("Unknown datasource format driver:") + format_name); exit(1); } - datasource = ogrdriver->CreateDataSource(dst_datasource,NULL); + const char* dst_datasource = argv[optind++]; + auto datasource = gdalDriver->Create(dst_datasource, 0, 0, 0, GDALDataType::GDT_Unknown, NULL); if (!datasource) { - usage(argv[0],std::string("Unable to create datasource:")+dst_datasource); + usage(argv[0],std::string("Unable to create datasource:") + dst_datasource); exit(1); } @@ -537,7 +540,8 @@ int main(int argc, char** argv) { process_file(SGPath(argv[i])); } - OGRDataSource::DestroyDataSource( datasource ); + GDALClose((GDALDatasetH) datasource ); + GDALDestroyDriverManager(); return 0; } From 911f7f9d27769fd09093e44af5de0c87d08d9935 Mon Sep 17 00:00:00 2001 From: Scott Giese Date: Tue, 29 Jan 2019 14:02:18 -0600 Subject: [PATCH 17/25] [Genapts] Reduce technical debt. --- src/Airports/GenAirports850/helipad.hxx | 24 +- src/Airports/GenAirports850/linearfeature.cxx | 8 +- src/Airports/GenAirports850/main.cxx | 68 +-- src/Airports/GenAirports850/output.cxx | 2 +- src/Airports/GenAirports850/parser.cxx | 521 +++++++++--------- src/Airports/GenAirports850/parser.hxx | 39 +- src/Airports/GenAirports850/runway.hxx | 2 +- src/Airports/GenAirports850/rwy_gen.cxx | 13 +- src/Airports/GenAirports850/rwy_simple.cxx | 6 +- src/Airports/GenAirports850/scheduler.cxx | 53 +- src/Airports/GenAirports850/scheduler.hxx | 10 +- 11 files changed, 352 insertions(+), 394 deletions(-) diff --git a/src/Airports/GenAirports850/helipad.hxx b/src/Airports/GenAirports850/helipad.hxx index 0dc3cc1a..2965dc99 100644 --- a/src/Airports/GenAirports850/helipad.hxx +++ b/src/Airports/GenAirports850/helipad.hxx @@ -56,18 +56,18 @@ public: private: struct TGRunway { - // data for helipad - char designator[16]; - double lat; - double lon; - double heading; - double length; - double width; - int surface; - int marking; - int shoulder; - double smoothness; - int edge_lights; + // data for helipad + char designator[16]; + double lat; + double lon; + double heading; + double length; + double width; + int surface; + int marking; + int shoulder; + double smoothness; + int edge_lights; }; TGRunway heli; diff --git a/src/Airports/GenAirports850/linearfeature.cxx b/src/Airports/GenAirports850/linearfeature.cxx index b8a0ed67..72232d55 100644 --- a/src/Airports/GenAirports850/linearfeature.cxx +++ b/src/Airports/GenAirports850/linearfeature.cxx @@ -370,10 +370,8 @@ int LinearFeature::Finish( bool closed, unsigned int idx ) double heading; double dist; double az2; - double last_end_v; double width = 0; std::string material; - double cur_light_dist = 0.0f; double light_delta = 0; bool markStarted; @@ -386,7 +384,7 @@ int LinearFeature::Finish( bool closed, unsigned int idx ) for (unsigned int i=0; itype ) @@ -568,7 +566,7 @@ int LinearFeature::Finish( bool closed, unsigned int idx ) for (unsigned int i=0; iLightDirection(); bool alternate = false; @@ -637,7 +635,7 @@ int LinearFeature::Finish( bool closed, unsigned int idx ) while (cur_light_dist < dist) { - if (cur_light_dist == 0.0f) + if (cur_light_dist == 0.0) { tmp = prev_outer; } diff --git a/src/Airports/GenAirports850/main.cxx b/src/Airports/GenAirports850/main.cxx index d826971a..62b0ca39 100644 --- a/src/Airports/GenAirports850/main.cxx +++ b/src/Airports/GenAirports850/main.cxx @@ -41,8 +41,8 @@ static void usage( int argc, char **argv ) { TG_LOG(SG_GENERAL, SG_ALERT, "Usage: " << argv[0] << "\n--input=" << "\n--work=\n[ --start-id=abcd ] [ --nudge=n ] " << "[--min-lon=] [--max-lon=] [--min-lat=] [--max-lat=] " - << "[ --airport=abcd ] [--max-slope=] [--tile=] [--threads] [--threads=x]" - << "[--chunk=] [--clear-dem-path] [--dem-path=] [--verbose] [--help] [--log-level=bulk|info|debug|warn|alert]"); + << "[ --airport=abcd ] [--max-slope=] [--threads] [--threads=x]" + << "[--clear-dem-path] [--dem-path=] [--verbose] [--help] [--log-level=bulk|info|debug|warn|alert]"); } @@ -82,8 +82,6 @@ static void help( int argc, char **argv, const string_list& elev_src ) { cout << "where once again abcd is a valid airport code. In this case, all airports in the file subsequent to the \n"; cout << "start-id are done. This is convenient when re-starting after a previous error. \n"; cout << "\nAn input area may be specified by lat and lon extent using min and max lat and lon. \n"; - //cout << "Alternatively, you may specify a chunk (10 x 10 degrees) or tile (1 x 1 degree) using a string \n"; - //cout << "such as eg. w080n40, e000s27. \n"; cout << "\nAn input file containing only a subset of the world's \n"; cout << "airports may of course be used.\n"; cout << "\n\n"; @@ -92,7 +90,7 @@ static void help( int argc, char **argv, const string_list& elev_src ) { cout << "The following subdirectories of the work-dir will be searched for elevation files:\n\n"; string_list::const_iterator elev_src_it; - for (elev_src_it = elev_src.begin(); elev_src_it != elev_src.end(); elev_src_it++) { + for (elev_src_it = elev_src.begin(); elev_src_it != elev_src.end(); ++elev_src_it) { cout << *elev_src_it << "\n"; } cout << "\n"; @@ -159,110 +157,96 @@ int main(int argc, char **argv) for (arg_pos = 1; arg_pos < argc; arg_pos++) { string arg = argv[arg_pos]; - if ( arg.find("--log-level=") == 0 ) + if (arg.compare(0, 12, "--log-level=") == 0) { setLoggingPriority(arg.substr(12)); } - else if ( arg.find("--work=") == 0 ) + else if (arg.compare(0, 7, "--work=") == 0) { work_dir = arg.substr(7); } - else if ( arg.find("--input=") == 0 ) + else if (arg.compare(0, 8, "--input=") == 0) { input_file = arg.substr(8); } - else if ( arg.find("--start-id=") == 0 ) + else if (arg.compare(0, 11, "--start-id=") == 0) { start_id = arg.substr(11); } - else if ( arg.find("--nudge=") == 0 ) + else if (arg.compare(0, 8, "--nudge=") == 0) { nudge = atoi( arg.substr(8).c_str() ); } - else if ( arg.find("--snap=") == 0 ) + else if (arg.compare(0, 7, "--snap=") == 0) { gSnap = atof( arg.substr(7).c_str() ); } - else if ( arg.find("--min-lon=") == 0 ) + else if (arg.compare(0, 10, "--min-lon=") == 0) { min.setLongitudeDeg(atof( arg.substr(10).c_str() )); } - else if ( arg.find("--max-lon=") == 0 ) + else if (arg.compare(0, 10, "--max-lon=") == 0) { max.setLongitudeDeg(atof( arg.substr(10).c_str() )); } - else if ( arg.find("--min-lat=") == 0 ) + else if (arg.compare(0, 10, "--min-lat=") == 0) { min.setLatitudeDeg(atof( arg.substr(10).c_str() )); } - else if ( arg.find("--max-lat=") == 0 ) + else if (arg.compare(0, 10, "--max-lat=") == 0) { max.setLatitudeDeg(atof( arg.substr(10).c_str() )); } -#if 0 // relly? - do we need this? - else if ( arg.find("--chunk=") == 0 ) - { - tg::Rectangle rectangle = tg::parseChunk(arg.substr(8).c_str(), 10.0); - min = rectangle.getMin(); - max = rectangle.getMax(); - } - else if ( arg.find("--tile=") == 0 ) - { - tg::Rectangle rectangle = tg::parseTile(arg.substr(7).c_str()); - min = rectangle.getMin(); - max = rectangle.getMax(); - } -#endif - else if ( arg.find("--airport=") == 0 ) + else if (arg.compare(0, 10, "--airport=") == 0) { airport_id = simgear::strutils::uppercase( arg.substr(10).c_str() ); } - else if ( arg == "--clear-dem-path" ) + else if (arg.compare(0, 16, "--clear-dem-path") == 0) { elev_src.clear(); } - else if ( arg.find("--dem-path=") == 0 ) + else if (arg.compare(0, 11, "--dem-path=") == 0) { elev_src.push_back( arg.substr(11) ); } - else if ( (arg.find("--verbose") == 0) || (arg.find("-v") == 0) ) + else if (arg.compare(0, 9, "--verbose") == 0 || arg.compare(0, 2, "-v") == 0) { sglog().setLogLevels( SG_GENERAL, SG_BULK ); } - else if ( (arg.find("--max-slope=") == 0) ) + else if (arg.compare(0, 12, "--max-slope=") == 0) { slope_max = atof( arg.substr(12).c_str() ); } - else if ( (arg.find("--threads=") == 0) ) + else if (arg.compare(0, 10, "--threads=") == 0) { num_threads = atoi( arg.substr(10).c_str() ); } - else if ( (arg.find("--threads") == 0) ) + else if (arg.compare(0, 9, "--threads") == 0) { num_threads = boost::thread::hardware_concurrency(); } - else if (arg.find("--debug-dir=") == 0) + else if (arg.compare(0, 12, "--debug-dir=") == 0) { debug_dir = arg.substr(12); } - else if (arg.find("--debug-runways=") == 0) + else if (arg.compare(0, 16, "--debug-runways=") == 0) { debug_runway_defs.push_back( arg.substr(16) ); } - else if (arg.find("--debug-pavements=") == 0) + else if (arg.compare(0, 18, "--debug-pavements=") == 0) { debug_pavement_defs.push_back( arg.substr(18) ); } - else if (arg.find("--debug-taxiways=") == 0) + else if (arg.compare(0, 17, "--debug-taxiways=") == 0) { TG_LOG(SG_GENERAL, SG_INFO, "add debug taxiway " << arg.substr(17) ); debug_taxiway_defs.push_back( arg.substr(17) ); } - else if (arg.find("--debug-features=") == 0) + else if (arg.compare(0, 17, "--debug-features=") == 0) { debug_feature_defs.push_back( arg.substr(17) ); } - else if ( (arg.find("--help") == 0) || (arg.find("-h") == 0) ) + else if (arg.compare(0, 6, "--help") == 0 || arg.compare(0, 2, "-h") == 0) { help( argc, argv, elev_src ); exit(-1); diff --git a/src/Airports/GenAirports850/output.cxx b/src/Airports/GenAirports850/output.cxx index 898d1682..040e6dbf 100644 --- a/src/Airports/GenAirports850/output.cxx +++ b/src/Airports/GenAirports850/output.cxx @@ -101,7 +101,7 @@ void write_index_object_sign( const string &base, const SGBucket &b, exit(-1); } - fprintf( fp, "OBJECT_SIGN %s %.6f %.6f %.1f %.2f %u\n", sign.c_str(), + fprintf( fp, "OBJECT_SIGN %s %.6f %.6f %.1f %.2f %d\n", sign.c_str(), p.getLongitudeDeg(), p.getLatitudeDeg(), p.getElevationM(), heading, size ); fclose( fp ); } diff --git a/src/Airports/GenAirports850/parser.cxx b/src/Airports/GenAirports850/parser.cxx index 9585774a..8a9a4de5 100644 --- a/src/Airports/GenAirports850/parser.cxx +++ b/src/Airports/GenAirports850/parser.cxx @@ -8,17 +8,15 @@ bool Parser::GetAirportDefinition( char* line, std::string& icao ) { - char* tok; - int code; - bool match = false; + bool match = false; // Get the number code - tok = strtok(line, " \t\r\n"); + char* tok = strtok(line, " \t\r\n"); if (tok) { line += strlen(tok)+1; - code = atoi(tok); + int code = atoi(tok); switch(code) { @@ -40,7 +38,7 @@ bool Parser::GetAirportDefinition( char* line, std::string& icao ) return match; } -void Parser::set_debug( std::string path, std::vector runway_defs, +void Parser::set_debug( const std::string& path, std::vector runway_defs, std::vector pavement_defs, std::vector taxiway_defs, std::vector feature_defs ) @@ -416,7 +414,7 @@ std::shared_ptr Parser::ParsePavement( char* line ) char *d = nullptr; int numParams; - numParams = sscanf(line, "%d %f %f %s", &st, &s, &th, desc); + numParams = sscanf(line, "%d %f %f %255s", &st, &s, &th, desc); if (numParams == 4) { @@ -440,7 +438,7 @@ std::shared_ptr Parser::ParseBoundary( char* line ) char *d = nullptr; int numParams; - numParams = sscanf(line, "%s", desc); + numParams = sscanf(line, "%255s", desc); if (numParams == 1) { @@ -485,164 +483,196 @@ int Parser::SetState( int state ) // TODO: This should be a loop here, and main should just pass the file name and airport code... int Parser::ParseLine(char* line) { - char* tok; - int code; - std::shared_ptr cur_node = nullptr; - if (*line != '#') + if (*line == '#') + return cur_state; + + // Get the number code + char* tok = strtok(line, " \t\r\n"); + + if (tok) { - // Get the number code - tok = strtok(line, " \t\r\n"); + line += strlen(tok)+1; + int code = atoi(tok); - if (tok) + switch(code) { - line += strlen(tok)+1; - code = atoi(tok); + case LAND_AIRPORT_CODE: + case SEA_AIRPORT_CODE: + if (cur_state == STATE_NONE) + { + SetState( STATE_PARSE_SIMPLE ); + TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing land airport: " << line); + cur_airport = std::make_shared( code, line ); + } + else + { + SetState( STATE_DONE ); + } + break; + case HELIPORT_CODE: + if (cur_state == STATE_NONE) + { + SetState( STATE_PARSE_SIMPLE ); + TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing heliport: " << line); + cur_airport = std::make_shared( code, line ); + } + else + { + SetState( STATE_DONE ); + } + break; - switch(code) - { - case LAND_AIRPORT_CODE: - case SEA_AIRPORT_CODE: - if (cur_state == STATE_NONE) - { - SetState( STATE_PARSE_SIMPLE ); - TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing land airport: " << line); - cur_airport = std::make_shared( code, line ); - } - else - { - SetState( STATE_DONE ); - } - break; - case HELIPORT_CODE: - if (cur_state == STATE_NONE) - { - SetState( STATE_PARSE_SIMPLE ); - TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing heliport: " << line); - cur_airport = std::make_shared( code, line ); - } - else - { - SetState( STATE_DONE ); - } - break; - - case LAND_RUNWAY_CODE: - SetState( STATE_PARSE_SIMPLE ); - TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing runway: " << line); - cur_runway = std::make_shared(line); - if (cur_airport) - { - cur_airport->AddRunway( cur_runway ); - } - break; - - case WATER_RUNWAY_CODE: - SetState( STATE_PARSE_SIMPLE ); - TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing water runway: " << line); - cur_waterrunway = std::make_shared(line); - if (cur_airport) - { - cur_airport->AddWaterRunway( cur_waterrunway ); - } - break; - case HELIPAD_CODE: - SetState( STATE_PARSE_SIMPLE ); - TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing helipad: " << line); - cur_helipad = std::make_shared(line); - if (cur_airport) - { - cur_airport->AddHelipad( cur_helipad ); - } - break; - - case TAXIWAY_CODE: - SetState( STATE_PARSE_SIMPLE ); - TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing taxiway: " << line); - cur_taxiway = std::make_shared(line); - if (cur_airport) - { - cur_airport->AddTaxiway( cur_taxiway ); - } - break; - - case PAVEMENT_CODE: - SetState( STATE_PARSE_PAVEMENT ); - TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing pavement: " << line); - cur_pavement = ParsePavement( line ); - break; - - case LINEAR_FEATURE_CODE: - SetState( STATE_PARSE_FEATURE ); - TG_LOG(SG_GENERAL, SG_DEBUG, "Linear Feature: " << line); - cur_feat = ParseFeature( line ); - break; - - case BOUNDARY_CODE: - SetState( STATE_PARSE_BOUNDARY ); - TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing Boundary: " << line); - cur_boundary = ParseBoundary( line ); - break; - - case NODE_CODE: - case BEZIER_NODE_CODE: - TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing node: " << line); - cur_node = ParseNode( code, line, prev_node ); - - if ( prev_node && (cur_node != prev_node) ) - { - // prev node is done - process it - if ( cur_state == STATE_PARSE_PAVEMENT ) - { - cur_pavement->AddNode( prev_node ); - } - else if ( cur_state == STATE_PARSE_FEATURE ) - { - cur_feat->AddNode( prev_node ); - } - else if ( cur_state == STATE_PARSE_BOUNDARY ) - { - cur_boundary->AddNode( prev_node ); - } - } + case LAND_RUNWAY_CODE: + SetState( STATE_PARSE_SIMPLE ); + TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing runway: " << line); + cur_runway = std::make_shared(line); + if (cur_airport) + { + cur_airport->AddRunway( cur_runway ); + } + break; - prev_node = cur_node; - break; - - case CLOSE_NODE_CODE: - case CLOSE_BEZIER_NODE_CODE: - TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing close loop node: " << line); - cur_node = ParseNode( code, line, prev_node ); + case WATER_RUNWAY_CODE: + SetState( STATE_PARSE_SIMPLE ); + TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing water runway: " << line); + cur_waterrunway = std::make_shared(line); + if (cur_airport) + { + cur_airport->AddWaterRunway( cur_waterrunway ); + } + break; + case HELIPAD_CODE: + SetState( STATE_PARSE_SIMPLE ); + TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing helipad: " << line); + cur_helipad = std::make_shared(line); + if (cur_airport) + { + cur_airport->AddHelipad( cur_helipad ); + } + break; - if ( cur_state == STATE_PARSE_PAVEMENT && prev_node ) + case TAXIWAY_CODE: + SetState( STATE_PARSE_SIMPLE ); + TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing taxiway: " << line); + cur_taxiway = std::make_shared(line); + if (cur_airport) + { + cur_airport->AddTaxiway( cur_taxiway ); + } + break; + + case PAVEMENT_CODE: + SetState( STATE_PARSE_PAVEMENT ); + TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing pavement: " << line); + cur_pavement = ParsePavement( line ); + break; + + case LINEAR_FEATURE_CODE: + SetState( STATE_PARSE_FEATURE ); + TG_LOG(SG_GENERAL, SG_DEBUG, "Linear Feature: " << line); + cur_feat = ParseFeature( line ); + break; + + case BOUNDARY_CODE: + SetState( STATE_PARSE_BOUNDARY ); + TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing Boundary: " << line); + cur_boundary = ParseBoundary( line ); + break; + + case NODE_CODE: + case BEZIER_NODE_CODE: + TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing node: " << line); + cur_node = ParseNode( code, line, prev_node ); + + if ( prev_node && (cur_node != prev_node) ) + { + // prev node is done - process it + if ( cur_state == STATE_PARSE_PAVEMENT ) { - if (cur_node != prev_node) - { - cur_pavement->AddNode( prev_node ); - cur_pavement->AddNode( cur_node ); - } - else - { - cur_pavement->AddNode( cur_node ); - } - cur_pavement->CloseCurContour(); - } - else if ( cur_state == STATE_PARSE_BOUNDARY ) - { - if (cur_node != prev_node) - { - cur_boundary->AddNode( prev_node ); - cur_boundary->AddNode( cur_node ); - } - else - { - cur_boundary->AddNode( cur_node ); - } - cur_boundary->CloseCurContour(); + cur_pavement->AddNode( prev_node ); } else if ( cur_state == STATE_PARSE_FEATURE ) { + cur_feat->AddNode( prev_node ); + } + else if ( cur_state == STATE_PARSE_BOUNDARY ) + { + cur_boundary->AddNode( prev_node ); + } + } + + prev_node = cur_node; + break; + + case CLOSE_NODE_CODE: + case CLOSE_BEZIER_NODE_CODE: + TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing close loop node: " << line); + cur_node = ParseNode( code, line, prev_node ); + + if ( cur_state == STATE_PARSE_PAVEMENT && prev_node ) + { + if (cur_node != prev_node) + { + cur_pavement->AddNode( prev_node ); + cur_pavement->AddNode( cur_node ); + } + else + { + cur_pavement->AddNode( cur_node ); + } + cur_pavement->CloseCurContour(); + } + else if ( cur_state == STATE_PARSE_BOUNDARY ) + { + if (cur_node != prev_node) + { + cur_boundary->AddNode( prev_node ); + cur_boundary->AddNode( cur_node ); + } + else + { + cur_boundary->AddNode( cur_node ); + } + cur_boundary->CloseCurContour(); + } + else if ( cur_state == STATE_PARSE_FEATURE ) + { + if (cur_node != prev_node) + { + cur_feat->AddNode( prev_node ); + cur_feat->AddNode( cur_node ); + } + else + { + cur_feat->AddNode( cur_node ); + } + if (cur_airport) + { + cur_feat->Finish( true, cur_airport->NumFeatures() ); + cur_airport->AddFeature( cur_feat ); + } + cur_feat = nullptr; + SetState( STATE_PARSE_SIMPLE ); + } + prev_node = nullptr; + cur_node = nullptr; + break; + + case TERM_NODE_CODE: + case TERM_BEZIER_NODE_CODE: + TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing termination node: " << line); + + if ( cur_state == STATE_PARSE_FEATURE ) + { + // we have some bad data - termination nodes right after the + // linear feature declaration - can't do anything with a + // single point - detect and delete. + if ( prev_node ) + { + cur_node = ParseNode( code, line, prev_node ); + if (cur_node != prev_node) { cur_feat->AddNode( prev_node ); @@ -654,121 +684,86 @@ int Parser::ParseLine(char* line) } if (cur_airport) { - cur_feat->Finish( true, cur_airport->NumFeatures() ); + cur_feat->Finish( false, cur_airport->NumFeatures() ); cur_airport->AddFeature( cur_feat ); } - cur_feat = nullptr; - SetState( STATE_PARSE_SIMPLE ); } - prev_node = nullptr; - cur_node = nullptr; - break; - - case TERM_NODE_CODE: - case TERM_BEZIER_NODE_CODE: - TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing termination node: " << line); - - if ( cur_state == STATE_PARSE_FEATURE ) + else { - // we have some bad data - termination nodes right after the - // linear feature declaration - can't do anything with a - // single point - detect and delete. - if ( prev_node ) - { - cur_node = ParseNode( code, line, prev_node ); - - if (cur_node != prev_node) - { - cur_feat->AddNode( prev_node ); - cur_feat->AddNode( cur_node ); - } - else - { - cur_feat->AddNode( cur_node ); - } - if (cur_airport) - { - cur_feat->Finish( false, cur_airport->NumFeatures() ); - cur_airport->AddFeature( cur_feat ); - } - } - else - { - TG_LOG(SG_GENERAL, SG_ALERT, "Parsing termination node with no previous nodes!!!" ); - } - - cur_feat = nullptr; - SetState( STATE_PARSE_SIMPLE ); + TG_LOG(SG_GENERAL, SG_ALERT, "Parsing termination node with no previous nodes!!!" ); } - prev_node = nullptr; - cur_node = nullptr; - break; - - case AIRPORT_VIEWPOINT_CODE: + + cur_feat = nullptr; SetState( STATE_PARSE_SIMPLE ); - TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing viewpoint: " << line); - break; - case AIRPLANE_STARTUP_LOCATION_CODE: - SetState( STATE_PARSE_SIMPLE ); - TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing airplane startup location: " << line); - break; - case LIGHT_BEACON_CODE: - SetState( STATE_PARSE_SIMPLE ); - TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing light beacon: " << line); - cur_beacon = std::make_shared(line); - cur_airport->AddBeacon( cur_beacon ); - break; - case WINDSOCK_CODE: - SetState( STATE_PARSE_SIMPLE ); - TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing windsock: " << line); - cur_windsock = std::make_shared(line); - cur_airport->AddWindsock( cur_windsock ); - break; - case TAXIWAY_SIGN: - SetState( STATE_PARSE_SIMPLE ); - TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing taxiway sign: " << line); - cur_sign = std::make_shared(line); - cur_airport->AddSign( cur_sign ); - break; - case LIGHTING_OBJECT: - SetState( STATE_PARSE_SIMPLE ); - TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing lighting object: " << line); - cur_object = std::make_shared(line); - cur_airport->AddObj( cur_object ); - break; - case COMM_FREQ1_CODE: - SetState( STATE_PARSE_SIMPLE ); - TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing commfreq 1: " << line); - break; - case COMM_FREQ2_CODE: - SetState( STATE_PARSE_SIMPLE ); - TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing commfreq 2: " << line); - break; - case COMM_FREQ3_CODE: - SetState( STATE_PARSE_SIMPLE ); - TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing commfreq 3: " << line); - break; - case COMM_FREQ4_CODE: - SetState( STATE_PARSE_SIMPLE ); - TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing commfreq 4: " << line); - break; - case COMM_FREQ5_CODE: - SetState( STATE_PARSE_SIMPLE ); - TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing commfreq 5: " << line); - break; - case COMM_FREQ6_CODE: - SetState( STATE_PARSE_SIMPLE ); - TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing commfreq 6: " << line); - break; - case COMM_FREQ7_CODE: - SetState( STATE_PARSE_SIMPLE ); - TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing commfreq 7: " << line); - break; - case END_OF_FILE : - TG_LOG(SG_GENERAL, SG_DEBUG, "Reached end of file"); - SetState( STATE_DONE ); - break; - } + } + prev_node = nullptr; + cur_node = nullptr; + break; + + case AIRPORT_VIEWPOINT_CODE: + SetState( STATE_PARSE_SIMPLE ); + TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing viewpoint: " << line); + break; + case AIRPLANE_STARTUP_LOCATION_CODE: + SetState( STATE_PARSE_SIMPLE ); + TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing airplane startup location: " << line); + break; + case LIGHT_BEACON_CODE: + SetState( STATE_PARSE_SIMPLE ); + TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing light beacon: " << line); + cur_beacon = std::make_shared(line); + cur_airport->AddBeacon( cur_beacon ); + break; + case WINDSOCK_CODE: + SetState( STATE_PARSE_SIMPLE ); + TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing windsock: " << line); + cur_windsock = std::make_shared(line); + cur_airport->AddWindsock( cur_windsock ); + break; + case TAXIWAY_SIGN: + SetState( STATE_PARSE_SIMPLE ); + TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing taxiway sign: " << line); + cur_sign = std::make_shared(line); + cur_airport->AddSign( cur_sign ); + break; + case LIGHTING_OBJECT: + SetState( STATE_PARSE_SIMPLE ); + TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing lighting object: " << line); + cur_object = std::make_shared(line); + cur_airport->AddObj( cur_object ); + break; + case COMM_FREQ1_CODE: + SetState( STATE_PARSE_SIMPLE ); + TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing commfreq 1: " << line); + break; + case COMM_FREQ2_CODE: + SetState( STATE_PARSE_SIMPLE ); + TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing commfreq 2: " << line); + break; + case COMM_FREQ3_CODE: + SetState( STATE_PARSE_SIMPLE ); + TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing commfreq 3: " << line); + break; + case COMM_FREQ4_CODE: + SetState( STATE_PARSE_SIMPLE ); + TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing commfreq 4: " << line); + break; + case COMM_FREQ5_CODE: + SetState( STATE_PARSE_SIMPLE ); + TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing commfreq 5: " << line); + break; + case COMM_FREQ6_CODE: + SetState( STATE_PARSE_SIMPLE ); + TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing commfreq 6: " << line); + break; + case COMM_FREQ7_CODE: + SetState( STATE_PARSE_SIMPLE ); + TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing commfreq 7: " << line); + break; + case END_OF_FILE : + TG_LOG(SG_GENERAL, SG_DEBUG, "Reached end of file"); + SetState( STATE_DONE ); + break; } } diff --git a/src/Airports/GenAirports850/parser.hxx b/src/Airports/GenAirports850/parser.hxx index 565a7eb2..5f4a00ea 100644 --- a/src/Airports/GenAirports850/parser.hxx +++ b/src/Airports/GenAirports850/parser.hxx @@ -89,30 +89,29 @@ class Parser : public SGThread { public: - Parser(const std::string& datafile, const std::string& root, const string_list& elev_src ) + Parser(const std::string& datafile, const std::string& root, const string_list& elev_src ) : + prev_node(nullptr), + filename(datafile), + elevation(elev_src), + work_dir(root), + cur_airport(nullptr), + cur_taxiway(nullptr), + cur_runway(nullptr), + cur_waterrunway(nullptr), + cur_helipad(nullptr), + cur_pavement(nullptr), + cur_boundary(nullptr), + cur_feat(nullptr), + cur_object(nullptr), + cur_windsock(nullptr), + cur_beacon(nullptr), + cur_sign(nullptr) { - filename = datafile; - work_dir = root; - elevation = elev_src; - - cur_airport = nullptr; - cur_runway = nullptr; - cur_waterrunway = nullptr; - cur_helipad = nullptr; - cur_taxiway = nullptr; - cur_pavement = nullptr; - cur_boundary = nullptr; - cur_feat = nullptr; - cur_object = nullptr; - cur_windsock = nullptr; - cur_beacon = nullptr; - cur_sign = nullptr; - prev_node = nullptr; - cur_state = STATE_NONE; + cur_state = STATE_NONE; } // Debug - void set_debug( std::string path, std::vector runway_defs, + void set_debug( const std::string& path, std::vector runway_defs, std::vector pavement_defs, std::vector taxiway_defs, std::vector feature_defs ); diff --git a/src/Airports/GenAirports850/runway.hxx b/src/Airports/GenAirports850/runway.hxx index 51ebece8..7a894958 100644 --- a/src/Airports/GenAirports850/runway.hxx +++ b/src/Airports/GenAirports850/runway.hxx @@ -55,7 +55,7 @@ public: private: struct TGRunway { - // data for whole runway + // data for whole runway int surface; int shoulder; int centerline_lights; diff --git a/src/Airports/GenAirports850/rwy_gen.cxx b/src/Airports/GenAirports850/rwy_gen.cxx index 8f728849..34d04b92 100644 --- a/src/Airports/GenAirports850/rwy_gen.cxx +++ b/src/Airports/GenAirports850/rwy_gen.cxx @@ -832,19 +832,16 @@ void Runway::gen_rwy( tgpolygon_list& rwy_polys, start1_pct = 0.0; end1_pct = 0.0; - double part_len = 0.0; - int count=0; - if (rwy.overrun[rwhalf] > 0.0) { /* Generate approach end overrun */ - count = (int) (rwy.overrun[rwhalf] * 2.0/ rwy.width); - if(count < 1) { + int count = (int) (rwy.overrun[rwhalf] * 2.0/ rwy.width); + if (count < 1) { count = 1; } - part_len = rwy.overrun[rwhalf] / (double)count; - for(int i=0; i #include + #include "runway.hxx" #include "debug.hxx" @@ -37,9 +38,7 @@ void Runway::gen_simple_rwy( tgpolygon_list& rwy_polys, std::string empty = ""; for ( int rwhalf=0; rwhalf<2; ++rwhalf ) { - double length = rwy.length / 2.0; - double start_pct = 0.0; double end_pct = 0.0; double heading = 0.0; @@ -53,7 +52,6 @@ void Runway::gen_simple_rwy( tgpolygon_list& rwy_polys, runway_half.AddNode( 0, runway.GetNode(5) ); runway_half.AddNode( 0, runway.GetNode(2) ); } - else { heading = rwy.heading; @@ -71,7 +69,7 @@ void Runway::gen_simple_rwy( tgpolygon_list& rwy_polys, if ( rwy.threshold[rwhalf] > 0.0 ) { TG_LOG( SG_GENERAL, SG_DEBUG, "Displaced threshold for RW side " << rwhalf << " is " << rwy.threshold[rwhalf] ); - start_pct = end_pct; + double start_pct = end_pct; end_pct = start_pct + ( rwy.threshold[rwhalf] / length ); Runway::gen_runway_section( runway_half, start_pct, end_pct, diff --git a/src/Airports/GenAirports850/scheduler.cxx b/src/Airports/GenAirports850/scheduler.cxx index 039341b1..8e54b520 100644 --- a/src/Airports/GenAirports850/scheduler.cxx +++ b/src/Airports/GenAirports850/scheduler.cxx @@ -49,7 +49,7 @@ std::ostream& operator<< (std::ostream &out, const AirportInfo &ai) return out; // MSVC } -void Scheduler::set_debug( std::string path, std::vector runway_defs, +void Scheduler::set_debug( const std::string& path, std::vector runway_defs, std::vector pavement_defs, std::vector taxiway_defs, std::vector feature_defs ) @@ -176,32 +176,31 @@ void Scheduler::set_debug( std::string path, std::vector runway_def } } -bool Scheduler::IsAirportDefinition( char* line, std::string icao ) +bool Scheduler::IsAirportDefinition( char* line, const std::string& icao ) { - char* tok; - int code; - bool match = false; + bool match = false; // Get the number code - tok = strtok(line, " \t\r\n"); + char* tok = strtok(line, " \t\r\n"); if (tok) { line += strlen(tok)+1; - code = atoi(tok); + int code = atoi(tok); switch(code) { case LAND_AIRPORT_CODE: case SEA_AIRPORT_CODE: case HELIPORT_CODE: - { - Airport ap( code, line ); - if ( ap.GetIcao() == icao ) { - match = true; + Airport ap( code, line ); + + if ( ap.GetIcao() == icao ) + { + match = true; + } } - } break; case LAND_RUNWAY_CODE: @@ -240,7 +239,6 @@ bool Scheduler::IsAirportDefinition( char* line, std::string icao ) void Scheduler::AddAirport( std::string icao ) { char line[2048]; - long cur_pos; bool found = false; AirportInfo ai; @@ -255,7 +253,7 @@ void Scheduler::AddAirport( std::string icao ) while ( !in.eof() && !found ) { // remember the position of this line - cur_pos = in.tellg(); + long cur_pos = in.tellg(); // get a line in.getline(line, 2048); @@ -273,7 +271,7 @@ void Scheduler::AddAirport( std::string icao ) } } -long Scheduler::FindAirport( std::string icao ) +long Scheduler::FindAirport( const std::string& icao ) { char line[2048]; long cur_pos = 0; @@ -321,11 +319,8 @@ void Scheduler::RetryAirport( AirportInfo* pai ) bool Scheduler::AddAirports( long start_pos, tgRectangle* boundingBox ) { char line[2048]; - char* def; - long cur_pos; long cur_apt_pos = 0; std::string cur_apt_name; - char* tok; int code; bool match; bool done; @@ -351,14 +346,14 @@ bool Scheduler::AddAirports( long start_pos, tgRectangle* boundingBox ) while (!done) { // remember the position of this line - cur_pos = in.tellg(); + long cur_pos = in.tellg(); // get a line in.getline(line, 2048); - def = &line[0]; + char* def = &line[0]; // Get the number code - tok = strtok(def, " \t\r\n"); + char* tok = strtok(def, " \t\r\n"); if (tok) { @@ -471,12 +466,11 @@ bool Scheduler::AddAirports( long start_pos, tgRectangle* boundingBox ) } } -Scheduler::Scheduler(std::string& datafile, const std::string& root, const string_list& elev_src) +Scheduler::Scheduler(std::string& datafile, const std::string& root, const string_list& elev_src) : + filename(datafile), + elevation(elev_src), + work_dir(root) { - filename = datafile; - work_dir = root; - elevation = elev_src; - std::ifstream in( filename.c_str() ); if ( !in.is_open() ) { @@ -487,16 +481,9 @@ Scheduler::Scheduler(std::string& datafile, const std::string& root, const strin void Scheduler::Schedule( int num_threads, std::string& summaryfile ) { -// std::ofstream csvfile; - - // open and truncate the summary file : monitor only appends -// csvfile.open( summaryfile.c_str(), std::ios_base::out | std::ios_base::trunc ); -// csvfile.close(); - std::vector> parsers; for (int i=0; i( filename, work_dir, elevation ); - // parser->set_debug(); parser->start(); parsers.push_back( parser ); } diff --git a/src/Airports/GenAirports850/scheduler.hxx b/src/Airports/GenAirports850/scheduler.hxx index ad979648..6f308a4e 100644 --- a/src/Airports/GenAirports850/scheduler.hxx +++ b/src/Airports/GenAirports850/scheduler.hxx @@ -44,9 +44,9 @@ public: { } - AirportInfo( std::string id, long p, double s ) + AirportInfo( const std::string& id, long p, double s ) : + icao(id) { - icao = id; pos = p; snap = s; @@ -99,7 +99,7 @@ class Scheduler public: Scheduler(std::string& datafile, const std::string& root, const string_list& elev_src); - long FindAirport( std::string icao ); + long FindAirport( const std::string& icao ); void AddAirport( std::string icao ); bool AddAirports( long start_pos, tgRectangle* boundingBox ); void RetryAirport( AirportInfo* pInfo ); @@ -107,13 +107,13 @@ public: void Schedule( int num_threads, std::string& summaryfile ); // Debug - void set_debug( std::string path, std::vector runway_defs, + void set_debug( const std::string& path, std::vector runway_defs, std::vector pavement_defs, std::vector taxiway_defs, std::vector feature_defs ); private: - bool IsAirportDefinition( char* line, std::string icao ); + bool IsAirportDefinition( char* line, const std::string& icao ); std::string filename; string_list elevation; From ca98d2ef5db39b160887a172a84c5f0a30ba7271 Mon Sep 17 00:00:00 2001 From: Scott Giese Date: Tue, 29 Jan 2019 14:55:50 -0600 Subject: [PATCH 18/25] [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 ) { From 9a5eac3c5935954c9b8d6a8fbe6f1172a3c2d482 Mon Sep 17 00:00:00 2001 From: Scott Giese Date: Tue, 29 Jan 2019 23:07:35 -0600 Subject: [PATCH 19/25] Reduce technical debt --- src/Airports/GenAirports850/airport.cxx | 95 ++++--------------- src/Airports/GenAirports850/airport.hxx | 5 +- src/Airports/GenAirports850/beznode.hxx | 44 +++------ src/Airports/GenAirports850/closedpoly.cxx | 4 +- src/Airports/GenAirports850/lights.cxx | 11 +-- src/Airports/GenAirports850/linearfeature.cxx | 6 +- src/Airports/GenAirports850/linearfeature.hxx | 4 +- src/Lib/DEM/dem.cxx | 35 ++++--- src/Lib/DEM/dem.hxx | 2 +- src/Lib/HGT/dted.cxx | 6 +- src/Lib/HGT/dted.hxx | 2 +- src/Lib/HGT/hgt.cxx | 3 +- src/Lib/HGT/hgt.hxx | 2 +- src/Lib/HGT/srtmbase.cxx | 4 - src/Lib/HGT/srtmbase.hxx | 15 ++- src/Lib/landcover/landcover.hxx | 2 +- src/Lib/landcover/test-landcover.cxx | 2 +- src/Lib/terragear/clipper.cpp | 14 ++- src/Lib/terragear/clipper.hpp | 6 +- src/Lib/terragear/tg_surface.hxx | 14 +-- src/Lib/terragear/tg_unique_geod.hxx | 2 +- src/Prep/Terra/Vec2.h | 2 +- src/Prep/Terra/Vec3.h | 2 +- src/Prep/Terra/xterra.cc | 7 +- 24 files changed, 111 insertions(+), 178 deletions(-) diff --git a/src/Airports/GenAirports850/airport.cxx b/src/Airports/GenAirports850/airport.cxx index 6582a7d7..c809f085 100644 --- a/src/Airports/GenAirports850/airport.cxx +++ b/src/Airports/GenAirports850/airport.cxx @@ -93,60 +93,17 @@ Airport::Airport( int c, char* def) Airport::~Airport() { - for (auto feature : features) - { - feature = nullptr; - } - - for (auto helipad : helipads) - { - helipad = nullptr; - } - - for (auto runway : runways) - { - runway = nullptr; - } - - for (auto waterrunway : waterrunways) - { - waterrunway = nullptr; - } - - for (auto pavement : pavements) - { - pavement = nullptr; - } - - for (auto taxiway : taxiways) - { - taxiway = nullptr; - } - - for (auto lightobject : lightobjects) - { - lightobject = nullptr; - } - - for (auto windsock : windsocks) - { - windsock = nullptr; - } - - for (auto beacon : beacons) - { - beacon = nullptr; - } - - for (auto sign : signs) - { - sign = nullptr; - } - - for (auto boundaryItem : boundary) - { - boundaryItem = nullptr; - } + std::fill(features.begin(), features.end(), nullptr); + std::fill(helipads.begin(), helipads.end(), nullptr); + std::fill(runways.begin(), runways.end(), nullptr); + std::fill(waterrunways.begin(), waterrunways.end(), nullptr); + std::fill(pavements.begin(), pavements.end(), nullptr); + std::fill(taxiways.begin(), taxiways.end(), nullptr); + std::fill(lightobjects.begin(), lightobjects.end(), nullptr); + std::fill(windsocks.begin(), windsocks.end(), nullptr); + std::fill(beacons.begin(), beacons.end(), nullptr); + std::fill(signs.begin(), signs.end(), nullptr); + std::fill(boundary.begin(), boundary.end(), nullptr); } bool Airport::isDebugRunway( int rwy ) @@ -813,7 +770,6 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src ) group_list strips_tc; strips_tc.clear(); string_list strip_materials; strip_materials.clear(); - int index; int_list pt_v, tri_v, strip_v; int_list pt_n, tri_n, strip_n; int_list tri_tc, strip_tc; @@ -837,9 +793,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src ) sgboTri.material = material; for (int l = 0; l < 3; ++l) { - int index; - - index = nodes.add( poly.GetTriNode( i, l ) ); + int index = nodes.add( poly.GetTriNode( i, l ) ); sgboTri.v_list.push_back( index ); // use 'the' normal @@ -868,9 +822,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src ) sgboTri.material = material; for (int l = 0; l < 3; ++l) { - int index; - - index = nodes.add( poly.GetTriNode( i, l ) ); + int index = nodes.add( poly.GetTriNode( i, l ) ); sgboTri.v_list.push_back( index ); // use 'the' normal @@ -899,9 +851,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src ) sgboTri.material = material; for (int l = 0; l < 3; ++l) { - int index; - - index = nodes.add( poly.GetTriNode( i, l ) ); + int index = nodes.add( poly.GetTriNode( i, l ) ); sgboTri.v_list.push_back( index ); // use 'the' normal @@ -924,9 +874,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src ) sgboTri.material = material; for (int l = 0; l < 3; ++l) { - int index; - - index = nodes.add( base_poly.GetTriNode( k, l ) ); + int index = nodes.add( base_poly.GetTriNode( k, l ) ); sgboTri.v_list.push_back( index ); // use 'the' normal @@ -947,7 +895,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src ) { for ( unsigned int j = 0; j < divided_base.ContourSize( i ); ++j ) { - index = nodes.add( divided_base.GetNode(i, j) ); + int index = nodes.add( divided_base.GetNode(i, j) ); TG_LOG(SG_GENERAL, SG_DEBUG, "added base point " << divided_base.GetNode(i, j) << " at " << index ); } } @@ -1080,9 +1028,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src ) for ( unsigned int j = 0; j < rwy_lights[i].ContourSize(); ++j ) { - int index; - - index = nodes.add( rwy_lights[i].GetPosition(j) ); + int index = nodes.add( rwy_lights[i].GetPosition(j) ); sgboPt.v_list.push_back( index ); index = normals.add( rwy_lights[i].GetNormal(j) ); @@ -1157,7 +1103,6 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src ) } #endif - SGGeod ref_geod; // calc elevations and write out windsock references TG_LOG(SG_GENERAL, SG_DEBUG, "Computing windsock node elevations"); @@ -1181,7 +1126,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src ) // write out beacon references for ( unsigned int i = 0; i < beacons.size(); ++i ) { - ref_geod = beacons[i]->GetLoc(); + SGGeod ref_geod = beacons[i]->GetLoc(); ref_geod.setElevationM( apt_surf.calc_elevation( ref_geod, 0.0 ) ); write_index_object_shared( objpath, b, ref_geod, @@ -1192,7 +1137,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src ) // write out taxiway signs references for ( unsigned int i = 0; i < signs.size(); ++i ) { - ref_geod = signs[i]->GetLoc(); + SGGeod ref_geod = signs[i]->GetLoc(); ref_geod.setElevationM( apt_surf.calc_elevation( ref_geod, 0.0 ) ); write_index_object_sign( objpath, b, ref_geod, signs[i]->GetDefinition(), @@ -1207,7 +1152,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src ) for ( unsigned int j = 0; j < buoys.GetSize(); ++j ) { - ref_geod = buoys.GetNode(j); + SGGeod ref_geod = buoys.GetNode(j); ref_geod.setElevationM( apt_surf.calc_elevation( ref_geod, 0.0 ) ); write_index_object_shared( objpath, b, ref_geod, "Models/Airport/water_rw_buoy.xml", diff --git a/src/Airports/GenAirports850/airport.hxx b/src/Airports/GenAirports850/airport.hxx index 11064043..da40b561 100644 --- a/src/Airports/GenAirports850/airport.hxx +++ b/src/Airports/GenAirports850/airport.hxx @@ -59,10 +59,7 @@ public: void AddFeatures( FeatureList feature_list ) { - for (auto feature : feature_list) - { - features.push_back( feature ); - } + std::copy( feature_list.begin(), feature_list.end(), features.begin() ); } int NumFeatures( void ) diff --git a/src/Airports/GenAirports850/beznode.hxx b/src/Airports/GenAirports850/beznode.hxx index 26f6d2e7..92d08608 100644 --- a/src/Airports/GenAirports850/beznode.hxx +++ b/src/Airports/GenAirports850/beznode.hxx @@ -120,10 +120,9 @@ inline double CalculateTheta( const SGVec3d& dirCur, const SGVec3d& dirNext, con class BezNode { public: - explicit BezNode( SGGeod l ) + explicit BezNode( SGGeod l ) : + loc(l) { - loc = l; - has_prev_cp = false; has_next_cp = false; @@ -133,28 +132,18 @@ public: close = false; } - BezNode( double lat, double lon ) + BezNode( double lat, double lon ) : + BezNode(SGGeod::fromDeg(lon, lat)) { - loc = SGGeod::fromDeg( lon, lat ); - - has_prev_cp = false; - has_next_cp = false; - - mark = 0; - light = 0; - term = false; - close = false; } - BezNode( SGGeod l, SGGeod cp ) + BezNode( SGGeod l, SGGeod cp ) : + loc(l), + prev_cp(Mirror(cp)), + next_cp(cp) { - loc = l; - - next_cp = cp; - has_next_cp = true; - - prev_cp = Mirror(cp); has_prev_cp = true; + has_next_cp = true; mark = 0; light = 0; @@ -162,20 +151,9 @@ public: close = false; } - BezNode( double lat, double lon, double cp_lat, double cp_lon ) + BezNode( double lat, double lon, double cp_lat, double cp_lon ) : + BezNode(SGGeod::fromDeg(lon, lat), SGGeod::fromDeg(cp_lon, cp_lat)) { - loc = SGGeod::fromDeg( lon, lat ); - - next_cp = SGGeod::fromDeg( cp_lon, cp_lat ); - has_next_cp = true; - - prev_cp = Mirror( next_cp ); - has_prev_cp = true; - - mark = 0; - light = 0; - term = false; - close = false; } SGGeod Mirror( const SGGeod& pt ) diff --git a/src/Airports/GenAirports850/closedpoly.cxx b/src/Airports/GenAirports850/closedpoly.cxx index c3df2504..bb538ff6 100644 --- a/src/Airports/GenAirports850/closedpoly.cxx +++ b/src/Airports/GenAirports850/closedpoly.cxx @@ -136,7 +136,7 @@ void ClosedPoly::ConvertContour( const BezContour& src, tgContour& dst ) dst.Erase(); // iterate through each bezier node in the contour - for (unsigned int i = 0; i <= src.size()-1; i++) + for (unsigned int i = 0; i < src.size(); ++i) { TG_LOG(SG_GENERAL, SG_DEBUG, "\nHandling Node " << i << "\n\n"); @@ -147,7 +147,7 @@ void ClosedPoly::ConvertContour( const BezContour& src, tgContour& dst ) } else { - // for the last node, next is the first. as all contours are closed + // for the last node, next is the first node, as all contours are closed nextNode = src.at(0); } diff --git a/src/Airports/GenAirports850/lights.cxx b/src/Airports/GenAirports850/lights.cxx index fc9edbf2..d08b9951 100644 --- a/src/Airports/GenAirports850/lights.cxx +++ b/src/Airports/GenAirports850/lights.cxx @@ -402,7 +402,6 @@ tglightcontour_list Runway::gen_calvert( const string &kind, bool recip ) { tgLightContour w_lights; tgLightContour r_lights; - int i, j; string flag; SGVec3f normal = gen_runway_light_vector( 3.0, recip ); @@ -438,9 +437,7 @@ tglightcontour_list Runway::gen_calvert( const string &kind, bool recip ) // first set of single lights pt = ref; - for ( i = 0; i < count; ++i ) { - - + for ( int i = 0; i < count; ++i ) { // centre lights pt = SGGeodesy::direct(pt, length_hdg, -vert_space); @@ -529,7 +526,7 @@ tglightcontour_list Runway::gen_calvert( const string &kind, bool recip ) int num_lights = 0; // draw nice crossbars - for ( i = 0; i < 5; i++ ) { + for ( int i = 0; i < 5; ++i ) { switch ( i ) { case 0: num_lights = 4; @@ -549,14 +546,14 @@ tglightcontour_list Runway::gen_calvert( const string &kind, bool recip ) } pt = crossbar[i]; - for ( j = 0 ; j < num_lights; j++ ) { + for ( int j = 0 ; j < num_lights; ++j ) { // left side lights pt = SGGeodesy::direct(pt, left_hdg, horiz_space); w_lights.AddLight(pt, normal); } pt = crossbar[i]; - for ( j = 0; j < num_lights; j++ ) { + for ( int j = 0; j < num_lights; ++j ) { // right side lights pt = SGGeodesy::direct(pt, left_hdg, -horiz_space); w_lights.AddLight(pt, normal); diff --git a/src/Airports/GenAirports850/linearfeature.cxx b/src/Airports/GenAirports850/linearfeature.cxx index 72232d55..622eec97 100644 --- a/src/Airports/GenAirports850/linearfeature.cxx +++ b/src/Airports/GenAirports850/linearfeature.cxx @@ -28,17 +28,17 @@ void LinearFeature::ConvertContour( const BezContour& src, bool closed ) points.Erase(); // iterate through each bezier node in the contour - for (unsigned int i = 0; i <= src.size() - 1; ++i) + for (unsigned int i = 0; i < src.size(); ++i) { curNode = src.at(i); if (i < src.size() - 1) { - nextNode = src.at(i+1); + nextNode = src.at(i + 1); } else { - // for the last node, next is the first. as all contours are closed + // for the last node, next is the first node, as all contours are closed nextNode = src.at(0); } diff --git a/src/Airports/GenAirports850/linearfeature.hxx b/src/Airports/GenAirports850/linearfeature.hxx index 74054be8..4ccc34a0 100644 --- a/src/Airports/GenAirports850/linearfeature.hxx +++ b/src/Airports/GenAirports850/linearfeature.hxx @@ -78,12 +78,12 @@ public: } LinearFeature( const std::string& desc, double o ) : - offset(o), - width(0), cur_mark(nullptr), cur_light(nullptr), description(desc) { + offset = o; + width = 0; } ~LinearFeature(); diff --git a/src/Lib/DEM/dem.cxx b/src/Lib/DEM/dem.cxx index 42f7589b..b55ffa23 100644 --- a/src/Lib/DEM/dem.cxx +++ b/src/Lib/DEM/dem.cxx @@ -38,19 +38,33 @@ using std::string; TGDem::TGDem() : - z_units(2) // meters + in(nullptr), + dem_data(new float[DEM_SIZE_1][DEM_SIZE_1]), + output_data(new float[DEM_SIZE_1][DEM_SIZE_1]), + dem_description(""), + dem_quadrangle(""), + option_name("") { - // cout << "class TGDem CONstructor called." << endl; - dem_data = new float[DEM_SIZE_1][DEM_SIZE_1]; - output_data = new float[DEM_SIZE_1][DEM_SIZE_1]; + originx = originy = 0.0; + cols =rows = 0; + col_step = row_step = 0.0; + dem_x1 = dem_x2 = dem_x3 = dem_x4 = 0.0; + dem_y1 = dem_y2 = dem_y3 = dem_y4 = 0.0; + dem_z1 = dem_z2 = 0.0; + dem_resolution = dem_num_profiles = 0; + prof_col = prof_row = 0; + prof_num_cols = prof_num_rows = 0; + prof_x1 = prof_y1 = 0.0; + prof_data = 0.0; + do_data = 0; + cur_col = cur_row = 0; + z_units = 2; // meters } -TGDem::TGDem( const string &file ) { - // cout << "class TGDem CONstructor called." << endl; - dem_data = new float[DEM_SIZE_1][DEM_SIZE_1]; - output_data = new float[DEM_SIZE_1][DEM_SIZE_1]; - +TGDem::TGDem( const string &file ) : + TGDem::TGDem() +{ TGDem::open(file); } @@ -150,7 +164,6 @@ TGDem::next_exp() { bool TGDem::read_a_record() { int i, inum; - double dnum; string name, token, buf; char c; @@ -187,7 +200,7 @@ TGDem::read_a_record() { // Map projection parameters (ignored) for ( i = 0; i < 15; i++ ) { - dnum = next_exp(); + double dnum = next_exp(); SG_LOG(SG_GENERAL, SG_DEBUG, i << ": " << dnum); } diff --git a/src/Lib/DEM/dem.hxx b/src/Lib/DEM/dem.hxx index c0ee2578..ff02b3bc 100644 --- a/src/Lib/DEM/dem.hxx +++ b/src/Lib/DEM/dem.hxx @@ -95,7 +95,7 @@ public: // Constructor TGDem(); - TGDem( const std::string& file ); + explicit TGDem( const std::string& file ); // Destructor ~TGDem(); diff --git a/src/Lib/HGT/dted.cxx b/src/Lib/HGT/dted.cxx index 56700c08..5f71887f 100644 --- a/src/Lib/HGT/dted.cxx +++ b/src/Lib/HGT/dted.cxx @@ -47,7 +47,6 @@ #include #include - #include "dted.hxx" using std::cout; @@ -64,9 +63,9 @@ TGDted::TGDted( int _res ) } -TGDted::TGDted( int _res, const SGPath &file ):TGDted(_res) +TGDted::TGDted( int _res, const SGPath &file ) : + TGDted(_res) { - TGDted::open( file ); } @@ -224,7 +223,6 @@ TGDted::load( ) { } - TGDted::~TGDted() { // printf("class TGSrtmBase DEstructor called.\n"); delete [] data; diff --git a/src/Lib/HGT/dted.hxx b/src/Lib/HGT/dted.hxx index fbd2d426..582f46ba 100644 --- a/src/Lib/HGT/dted.hxx +++ b/src/Lib/HGT/dted.hxx @@ -60,7 +60,7 @@ public: // Constructor, _res must be either "1" for the 1arcsec data or // "3" for the 3arcsec data. - TGDted( int _res ); + explicit TGDted( int _res ); TGDted( int _res, const SGPath &file ); // Destructor diff --git a/src/Lib/HGT/hgt.cxx b/src/Lib/HGT/hgt.cxx index f768b031..d45615e0 100644 --- a/src/Lib/HGT/hgt.cxx +++ b/src/Lib/HGT/hgt.cxx @@ -62,7 +62,8 @@ TGHgt::TGHgt( int _res ) } -TGHgt::TGHgt( int _res, const SGPath &file ) : TGHgt( _res ) +TGHgt::TGHgt( int _res, const SGPath &file ) : + TGHgt( _res ) { TGHgt::open( file ); } diff --git a/src/Lib/HGT/hgt.hxx b/src/Lib/HGT/hgt.hxx index afd7026f..4784820a 100644 --- a/src/Lib/HGT/hgt.hxx +++ b/src/Lib/HGT/hgt.hxx @@ -59,7 +59,7 @@ public: // Constructor, _res must be either "1" for the 1arcsec data or // "3" for the 3arcsec data. - TGHgt( int _res ); + explicit TGHgt( int _res ); TGHgt( int _res, const SGPath &file ); // Destructor diff --git a/src/Lib/HGT/srtmbase.cxx b/src/Lib/HGT/srtmbase.cxx index 947a5a45..e2b76eb4 100644 --- a/src/Lib/HGT/srtmbase.cxx +++ b/src/Lib/HGT/srtmbase.cxx @@ -21,10 +21,6 @@ // $Id: hgt.cxx,v 1.7 2005-12-19 16:06:45 curt Exp $ -#ifdef HAVE_CONFIG_H -# include -#endif - #include #include #include diff --git a/src/Lib/HGT/srtmbase.hxx b/src/Lib/HGT/srtmbase.hxx index 88849a8f..3f895675 100644 --- a/src/Lib/HGT/srtmbase.hxx +++ b/src/Lib/HGT/srtmbase.hxx @@ -24,10 +24,6 @@ #ifndef _SRTMBASE_HXX #define _SRTMBASE_HXX -#ifdef HAVE_CONFIG_H -# include -#endif - #include #include @@ -36,8 +32,13 @@ class TGSrtmBase { protected: - TGSrtmBase() : remove_tmp_file(false) - {} + TGSrtmBase() : + remove_tmp_file(false) + { + originx = originy = 0.0; + cols = rows = 0; + col_step = row_step = 0.0; + } ~TGSrtmBase(); @@ -83,5 +84,3 @@ public: #endif // _SRTMBASE_HXX - - diff --git a/src/Lib/landcover/landcover.hxx b/src/Lib/landcover/landcover.hxx index a6f72fcc..e32acf39 100644 --- a/src/Lib/landcover/landcover.hxx +++ b/src/Lib/landcover/landcover.hxx @@ -61,7 +61,7 @@ class LandCover { public: - LandCover( const std::string &filename ); + explicit LandCover( const std::string &filename ); virtual ~LandCover (); virtual int getValue (long x, long y) const; diff --git a/src/Lib/landcover/test-landcover.cxx b/src/Lib/landcover/test-landcover.cxx index ae54f3c1..19424312 100644 --- a/src/Lib/landcover/test-landcover.cxx +++ b/src/Lib/landcover/test-landcover.cxx @@ -40,7 +40,7 @@ main (int ac, const char * av[]) int value = lu.getValue(lon, lat); cout << "Value is " << value << " \"" << lu.getDescUSGS(value) << '"' << endl; - } catch (string e) { + } catch (const string& e) { cerr << "Died with exception: " << e << endl; return 1; } diff --git a/src/Lib/terragear/clipper.cpp b/src/Lib/terragear/clipper.cpp index ab91cc67..a6b8cf03 100644 --- a/src/Lib/terragear/clipper.cpp +++ b/src/Lib/terragear/clipper.cpp @@ -181,6 +181,8 @@ int PolyTree::Total() const PolyNode::PolyNode(): Parent(0), Index(0), m_IsOpen(false) { + m_jointype = JoinType::Square; + m_endtype = EndType::ClosedPolygon; } //------------------------------------------------------------------------------ @@ -718,7 +720,10 @@ void DisposeOutPts(OutPt*& pp) inline void InitEdge(TEdge* e, TEdge* eNext, TEdge* ePrev, const IntPoint& Pt) { + // Dx is explicitly being set due to memset not being portable for floating-point values std::memset(e, 0, sizeof(TEdge)); + e->Dx = 0.0; + e->Next = eNext; e->Prev = ePrev; e->Curr = Pt; @@ -880,10 +885,13 @@ bool HorzSegmentsOverlap(cInt seg1a, cInt seg1b, cInt seg2a, cInt seg2b) // ClipperBase class methods ... //------------------------------------------------------------------------------ -ClipperBase::ClipperBase() //constructor +ClipperBase::ClipperBase() : + m_ActiveEdges(nullptr) { m_CurrentLM = m_MinimaList.begin(); //begin() == end() here m_UseFullRange = false; + m_PreserveCollinear = false; + m_HasOpenPaths = false; } //------------------------------------------------------------------------------ @@ -4199,13 +4207,13 @@ void ClipperOffset::DoRound(int j, int k) m_normals[k].X * m_normals[j].X + m_normals[k].Y * m_normals[j].Y); int steps = std::max((int)Round(m_StepsPerRad * std::fabs(a)), 1); - double X = m_normals[k].X, Y = m_normals[k].Y, X2; + double X = m_normals[k].X, Y = m_normals[k].Y; for (int i = 0; i < steps; ++i) { m_destPoly.push_back(IntPoint( Round(m_srcPoly[j].X + X * m_delta), Round(m_srcPoly[j].Y + Y * m_delta))); - X2 = X; + double X2 = X; X = X * m_cos - m_sin * Y; Y = X2 * m_sin + Y * m_cos; } diff --git a/src/Lib/terragear/clipper.hpp b/src/Lib/terragear/clipper.hpp index e0253e0d..ff34c225 100644 --- a/src/Lib/terragear/clipper.hpp +++ b/src/Lib/terragear/clipper.hpp @@ -118,7 +118,7 @@ struct DoublePoint double X; double Y; DoublePoint(double x = 0, double y = 0) : X(x), Y(y) {} - DoublePoint(IntPoint ip) : X((double)ip.X), Y((double)ip.Y) {} + explicit DoublePoint(const IntPoint& ip) : X(ip.X), Y(ip.Y) {} }; //------------------------------------------------------------------------------ @@ -263,7 +263,7 @@ protected: class Clipper : public virtual ClipperBase { public: - Clipper(int initOptions = 0); + explicit Clipper(int initOptions = 0); bool Execute(ClipType clipType, Paths &solution, PolyFillType fillType = PolyFillType::EvenOdd); @@ -391,7 +391,7 @@ private: class clipperException : public std::exception { public: - clipperException(const char* description): m_descr(description) {} + explicit clipperException(const char* description): m_descr(description) {} virtual ~clipperException() throw() {} virtual const char* what() const throw() {return m_descr.c_str();} private: diff --git a/src/Lib/terragear/tg_surface.hxx b/src/Lib/terragear/tg_surface.hxx index 9e12a70e..608dfb66 100644 --- a/src/Lib/terragear/tg_surface.hxx +++ b/src/Lib/terragear/tg_surface.hxx @@ -53,10 +53,11 @@ public: //int index = ( row * _cols ) + col; if ( col < 0 || col >= _cols ) { SG_LOG(SG_GENERAL, SG_WARN, "column out of bounds on read (" << col << " >= " << _cols << ")"); - int *p = 0; *p = 1; // force crash - } else if ( row < 0 || row >= _rows ) { + col = col < 0 ? 0 : _cols - 1; + } + else if ( row < 0 || row >= _rows ) { SG_LOG(SG_GENERAL, SG_WARN, "row out of bounds on read (" << row << " >= " << _rows << ")"); - int *p = 0; *p = 1; // force crash + row = row < 0 ? 0 : _rows - 1; } return m[row][col]; @@ -66,10 +67,11 @@ public: //int index = ( row * _cols ) + col; if ( col < 0 || col >= _cols ) { SG_LOG(SG_GENERAL, SG_WARN,"column out of bounds on set (" << col << " >= " << _cols << ")"); - int *p = 0; *p = 1; // force crash - } else if ( row < 0 || row >= _rows ) { + col = col < 0 ? 0 : _cols - 1; + } + else if ( row < 0 || row >= _rows ) { SG_LOG(SG_GENERAL, SG_WARN,"row out of bounds on set (" << row << " >= " << _rows << ")"); - int *p = 0; *p = 1; // force crash + row = row < 0 ? 0 : _rows - 1; } m[row][col] = p; } diff --git a/src/Lib/terragear/tg_unique_geod.hxx b/src/Lib/terragear/tg_unique_geod.hxx index 323d872f..97bc9db4 100644 --- a/src/Lib/terragear/tg_unique_geod.hxx +++ b/src/Lib/terragear/tg_unique_geod.hxx @@ -27,7 +27,7 @@ class SGGeodIndex { public: - SGGeodIndex( SGGeod g ) { + explicit SGGeodIndex( SGGeod g ) { geod = g; std::size_t FNV_prime; diff --git a/src/Prep/Terra/Vec2.h b/src/Prep/Terra/Vec2.h index 5c708a28..67fe9dc9 100644 --- a/src/Prep/Terra/Vec2.h +++ b/src/Prep/Terra/Vec2.h @@ -163,7 +163,7 @@ inline std::ostream& operator<<(std::ostream& out, const Vec2& v) inline std::istream& operator>>(std::istream& in, Vec2& v) { - char c; + char c = '\0'; return in >> c >> v[0] >> v[1] >> c; } diff --git a/src/Prep/Terra/Vec3.h b/src/Prep/Terra/Vec3.h index 31b6741e..763c7040 100644 --- a/src/Prep/Terra/Vec3.h +++ b/src/Prep/Terra/Vec3.h @@ -174,7 +174,7 @@ inline std::ostream& operator<<(std::ostream& out, const Vec3& v) inline std::istream& operator>>(std::istream& in, Vec3& v) { - char c; + char c = '\0'; return in >> c >> v[0] >> v[1] >> v[2] >> c; } diff --git a/src/Prep/Terra/xterra.cc b/src/Prep/Terra/xterra.cc index f0471012..470fa18e 100644 --- a/src/Prep/Terra/xterra.cc +++ b/src/Prep/Terra/xterra.cc @@ -4,15 +4,14 @@ #include "gui.h" - -main(int argc, char **argv) +int main(int argc, char **argv) { glutInit(&argc, argv); Terra::process_cmdline(argc, argv); - Terra::gui_init(); - Terra::gui_interact(); + + return 0; } From 488b69c63fe2380c51315bc46b9bb3c856bd170d Mon Sep 17 00:00:00 2001 From: Scott Giese Date: Wed, 30 Jan 2019 01:51:48 -0600 Subject: [PATCH 20/25] [genapts] Eliminate variable shadowing. Default initialization overrides. --- src/Airports/GenAirports850/closedpoly.cxx | 4 +-- src/Airports/GenAirports850/linearfeature.cxx | 6 ++-- src/Airports/GenAirports850/main.cxx | 3 +- src/Airports/GenAirports850/parser.cxx | 36 +++++++++---------- src/Airports/GenAirports850/scheduler.cxx | 36 +++++++++---------- 5 files changed, 38 insertions(+), 47 deletions(-) diff --git a/src/Airports/GenAirports850/closedpoly.cxx b/src/Airports/GenAirports850/closedpoly.cxx index bb538ff6..bc129fd0 100644 --- a/src/Airports/GenAirports850/closedpoly.cxx +++ b/src/Airports/GenAirports850/closedpoly.cxx @@ -126,9 +126,9 @@ void ClosedPoly::ConvertContour( const BezContour& src, tgContour& dst ) SGGeod cp1; SGGeod cp2; - int curve_type = CURVE_LINEAR; + int curve_type; double total_dist; - int num_segs = BEZIER_DETAIL; + int num_segs; TG_LOG(SG_GENERAL, SG_DEBUG, "Creating a contour with " << src.size() << " nodes"); diff --git a/src/Airports/GenAirports850/linearfeature.cxx b/src/Airports/GenAirports850/linearfeature.cxx index 622eec97..63b734af 100644 --- a/src/Airports/GenAirports850/linearfeature.cxx +++ b/src/Airports/GenAirports850/linearfeature.cxx @@ -14,10 +14,10 @@ void LinearFeature::ConvertContour( const BezContour& src, bool closed ) SGGeod cp1; SGGeod cp2; - int curve_type = CURVE_LINEAR; + int curve_type; double total_dist; double theta1, theta2; - int num_segs = BEZIER_DETAIL; + int num_segs; Marking* cur_mark = NULL; Lighting* cur_light = NULL; @@ -161,7 +161,7 @@ void LinearFeature::ConvertContour( const BezContour& src, bool closed ) // Sometimes, the control point lies just beyond the final point. We try to make a 'hook' at the end, which makes some really bad polys // Just convert the entire segment to linear // this can be detected in quadratic curves (current issue in LFKJ) when the contol point lies within the line generated from point 1 to point 2 - // theat close to 180 at the control point to the cur node and next node + // at close to 180 at the control point to the cur node and next node if ( curve_type == CURVE_QUADRATIC ) { if ( (std::abs(theta1 - 180.0) < 5.0 ) || (std::abs(theta1) < 5.0 ) || (std::isnan(theta1)) ) diff --git a/src/Airports/GenAirports850/main.cxx b/src/Airports/GenAirports850/main.cxx index 62b0ca39..a3c69295 100644 --- a/src/Airports/GenAirports850/main.cxx +++ b/src/Airports/GenAirports850/main.cxx @@ -129,7 +129,6 @@ int main(int argc, char **argv) SGGeod min = SGGeod::fromDeg( -180, -90 ); SGGeod max = SGGeod::fromDeg( 180, 90 ); - long position = 0; // Setup elevation directories string_list elev_src; @@ -344,7 +343,7 @@ int main(int argc, char **argv) TG_LOG(SG_GENERAL, SG_INFO, "move forward to " << start_id ); // scroll forward in datafile - position = scheduler->FindAirport( start_id ); + long position = scheduler->FindAirport( start_id ); // add remaining airports within boundary if ( scheduler->AddAirports( position, &boundingBox ) ) diff --git a/src/Airports/GenAirports850/parser.cxx b/src/Airports/GenAirports850/parser.cxx index 8a9a4de5..841d7706 100644 --- a/src/Airports/GenAirports850/parser.cxx +++ b/src/Airports/GenAirports850/parser.cxx @@ -62,13 +62,12 @@ void Parser::set_debug( const std::string& path, std::vector runway shapes.push_back( std::numeric_limits::max() ); } else { std::stringstream ss(dsd); - int i; - - while (ss >> i) + int idx; + while (ss >> idx) { - TG_LOG(SG_GENERAL, SG_ALERT, "Adding debug runway " << i); + TG_LOG(SG_GENERAL, SG_ALERT, "Adding debug runway " << idx); - shapes.push_back(i); + shapes.push_back(idx); if (ss.peek() == ',') ss.ignore(); @@ -91,13 +90,12 @@ void Parser::set_debug( const std::string& path, std::vector runway shapes.push_back( std::numeric_limits::max() ); } else { std::stringstream ss(dsd); - int i; - - while (ss >> i) + int idx; + while (ss >> idx) { - TG_LOG(SG_GENERAL, SG_ALERT, "Adding debug pavement " << i); + TG_LOG(SG_GENERAL, SG_ALERT, "Adding debug pavement " << idx); - shapes.push_back(i); + shapes.push_back(idx); if (ss.peek() == ',') ss.ignore(); @@ -120,13 +118,12 @@ void Parser::set_debug( const std::string& path, std::vector runway shapes.push_back( std::numeric_limits::max() ); } else { std::stringstream ss(dsd); - int i; - - while (ss >> i) + int idx; + while (ss >> idx) { - TG_LOG(SG_GENERAL, SG_ALERT, "Adding debug taxiway " << i); + TG_LOG(SG_GENERAL, SG_ALERT, "Adding debug taxiway " << idx); - shapes.push_back(i); + shapes.push_back(idx); if (ss.peek() == ',') ss.ignore(); @@ -149,13 +146,12 @@ void Parser::set_debug( const std::string& path, std::vector runway shapes.push_back( std::numeric_limits::max() ); } else { std::stringstream ss(dsd); - int i; - - while (ss >> i) + int idx; + while (ss >> idx) { - TG_LOG(SG_GENERAL, SG_ALERT, "Adding debug feature " << i); + TG_LOG(SG_GENERAL, SG_ALERT, "Adding debug feature " << idx); - shapes.push_back(i); + shapes.push_back(idx); if (ss.peek() == ',') ss.ignore(); diff --git a/src/Airports/GenAirports850/scheduler.cxx b/src/Airports/GenAirports850/scheduler.cxx index 8e54b520..a844151e 100644 --- a/src/Airports/GenAirports850/scheduler.cxx +++ b/src/Airports/GenAirports850/scheduler.cxx @@ -73,13 +73,12 @@ void Scheduler::set_debug( const std::string& path, std::vector run shapes.push_back( std::numeric_limits::max() ); } else { std::stringstream ss(dsd); - int i; - - while (ss >> i) + int idx; + while (ss >> idx) { - TG_LOG(SG_GENERAL, SG_ALERT, "Adding debug runway " << i << " for " << icao ); + TG_LOG(SG_GENERAL, SG_ALERT, "Adding debug runway " << idx << " for " << icao ); - shapes.push_back(i); + shapes.push_back(idx); if (ss.peek() == ',') ss.ignore(); @@ -102,13 +101,12 @@ void Scheduler::set_debug( const std::string& path, std::vector run shapes.push_back( std::numeric_limits::max() ); } else { std::stringstream ss(dsd); - int i; - - while (ss >> i) + int idx; + while (ss >> idx) { - TG_LOG(SG_GENERAL, SG_ALERT, "Adding debug pavement " << i << " for " << icao ); + TG_LOG(SG_GENERAL, SG_ALERT, "Adding debug pavement " << idx << " for " << icao ); - shapes.push_back(i); + shapes.push_back(idx); if (ss.peek() == ',') ss.ignore(); @@ -131,13 +129,12 @@ void Scheduler::set_debug( const std::string& path, std::vector run shapes.push_back( std::numeric_limits::max() ); } else { std::stringstream ss(dsd); - int i; - - while (ss >> i) + int idx; + while (ss >> idx) { - TG_LOG(SG_GENERAL, SG_ALERT, "Adding debug taxiway " << i << " for " << icao ); + TG_LOG(SG_GENERAL, SG_ALERT, "Adding debug taxiway " << idx << " for " << icao ); - shapes.push_back(i); + shapes.push_back(idx); if (ss.peek() == ',') ss.ignore(); @@ -160,13 +157,12 @@ void Scheduler::set_debug( const std::string& path, std::vector run shapes.push_back( std::numeric_limits::max() ); } else { std::stringstream ss(dsd); - int i; - - while (ss >> i) + int idx; + while (ss >> idx) { - TG_LOG(SG_GENERAL, SG_ALERT, "Adding debug feature " << i << " for " << icao ); + TG_LOG(SG_GENERAL, SG_ALERT, "Adding debug feature " << idx << " for " << icao ); - shapes.push_back(i); + shapes.push_back(idx); if (ss.peek() == ',') ss.ignore(); From f88863e4c2315d2566f1534d6a01bb0d9fd9bf0a Mon Sep 17 00:00:00 2001 From: Scott Giese Date: Wed, 30 Jan 2019 20:14:29 -0600 Subject: [PATCH 21/25] Reduce debt. Eliminate shadow variables. --- src/Airports/GenAirports850/airport.hxx | 5 +++- src/BuildTiles/Main/main.cxx | 16 +++++----- src/BuildTiles/Main/tgconstruct.cxx | 15 ++++++---- src/BuildTiles/Main/tgconstruct_clip.cxx | 9 +++--- src/BuildTiles/Main/tgconstruct_debug.cxx | 30 +++++++++---------- src/BuildTiles/Main/tgconstruct_elevation.cxx | 8 ++--- src/BuildTiles/Main/tgconstruct_poly.cxx | 6 ++-- src/BuildTiles/Main/tgconstruct_shared.cxx | 20 ++++++------- src/BuildTiles/Parallel/server.cxx | 1 - src/Lib/DEM/dem.cxx | 20 +++++++++---- src/Lib/HGT/dted.cxx | 21 ++++++++----- src/Lib/HGT/dted.hxx | 2 +- src/Lib/HGT/hgt.cxx | 23 +++++++++----- src/Lib/HGT/hgt.hxx | 2 +- src/Lib/terragear/clipper.cpp | 30 +++++++++++-------- 15 files changed, 118 insertions(+), 90 deletions(-) diff --git a/src/Airports/GenAirports850/airport.hxx b/src/Airports/GenAirports850/airport.hxx index da40b561..11064043 100644 --- a/src/Airports/GenAirports850/airport.hxx +++ b/src/Airports/GenAirports850/airport.hxx @@ -59,7 +59,10 @@ public: void AddFeatures( FeatureList feature_list ) { - std::copy( feature_list.begin(), feature_list.end(), features.begin() ); + for (auto feature : feature_list) + { + features.push_back( feature ); + } } int NumFeatures( void ) diff --git a/src/BuildTiles/Main/main.cxx b/src/BuildTiles/Main/main.cxx index 5e58c3f8..53a4ddf5 100644 --- a/src/BuildTiles/Main/main.cxx +++ b/src/BuildTiles/Main/main.cxx @@ -51,7 +51,7 @@ static void usage( const string name ) { SG_LOG(SG_GENERAL, SG_ALERT, " --work-dir="); SG_LOG(SG_GENERAL, SG_ALERT, " --share-dir="); SG_LOG(SG_GENERAL, SG_ALERT, " --match-dir="); - SG_LOG(SG_GENERAL, SG_ALERT, " --cover="); + // unused: SG_LOG(SG_GENERAL, SG_ALERT, " --cover="); SG_LOG(SG_GENERAL, SG_ALERT, " --tile-id="); SG_LOG(SG_GENERAL, SG_ALERT, " --min-lon="); SG_LOG(SG_GENERAL, SG_ALERT, " --max-lon="); @@ -59,7 +59,7 @@ static void usage( const string name ) { SG_LOG(SG_GENERAL, SG_ALERT, " --max-lat="); SG_LOG(SG_GENERAL, SG_ALERT, " --nudge="); SG_LOG(SG_GENERAL, SG_ALERT, " --priorities="); - SG_LOG(SG_GENERAL, SG_ALERT, " --usgs-map="); + // unused: SG_LOG(SG_GENERAL, SG_ALERT, " --usgs-map="); SG_LOG(SG_GENERAL, SG_ALERT, " --ignore-landmass"); SG_LOG(SG_GENERAL, SG_ALERT, " --threads"); SG_LOG(SG_GENERAL, SG_ALERT, " --threads="); @@ -84,9 +84,9 @@ int main(int argc, char **argv) { string work_dir = "."; string share_dir = ""; string match_dir = ""; - string cover = ""; + // unused: string cover = ""; string priorities_file = DEFAULT_PRIORITIES_FILE; - string usgs_map_file = DEFAULT_USGS_MAPFILE; + // unused: string usgs_map_file = DEFAULT_USGS_MAPFILE; SGGeod min, max; long tile_id = -1; int num_threads = 1; @@ -130,12 +130,12 @@ int main(int argc, char **argv) { max.setLatitudeDeg(atof( arg.substr(10).c_str() )); } else if (arg.find("--nudge=") == 0) { nudge = atof(arg.substr(8).c_str())*SG_EPSILON; - } else if (arg.find("--cover=") == 0) { - cover = arg.substr(8); + // } else if (arg.find("--cover=") == 0) { + // unused: cover = arg.substr(8); } else if (arg.find("--priorities=") == 0) { priorities_file = arg.substr(13); - } else if (arg.find("--usgs-map=") == 0) { - usgs_map_file = arg.substr(11); + // } else if (arg.find("--usgs-map=") == 0) { + // unused: usgs_map_file = arg.substr(11); } else if (arg.find("--ignore-landmass") == 0) { ignoreLandmass = true; } else if (arg.find("--threads=") == 0) { diff --git a/src/BuildTiles/Main/tgconstruct.cxx b/src/BuildTiles/Main/tgconstruct.cxx index 4d224e2e..ed79ed71 100644 --- a/src/BuildTiles/Main/tgconstruct.cxx +++ b/src/BuildTiles/Main/tgconstruct.cxx @@ -36,17 +36,20 @@ const double TGConstruct::gSnap = 0.00000001; // approx 1 mm TGConstruct::TGConstruct( const TGAreaDefinitions& areas, unsigned int s, SGLockedQueue& q, SGMutex* l) : area_defs(areas), workQueue(q), - stage(s), - ignoreLandmass(false), - debug_all(false), ds_id((void*)-1), l_id(nullptr), - isOcean(false) + ds_name(""), + layer_name(""), + feature_name(""), + lock(l) { total_tiles = q.size(); - num_areas = areas.size(); - lock = l; + stage = s; + ignoreLandmass = false; nudge = 0.0; + debug_all = false; + isOcean = false; + num_areas = areas.size(); } diff --git a/src/BuildTiles/Main/tgconstruct_clip.cxx b/src/BuildTiles/Main/tgconstruct_clip.cxx index 858c4e79..dff1dcf0 100644 --- a/src/BuildTiles/Main/tgconstruct_clip.cxx +++ b/src/BuildTiles/Main/tgconstruct_clip.cxx @@ -39,13 +39,12 @@ bool TGConstruct::ClipLandclassPolys( void ) { tgPolygon remains; tgPolygon safety_base; tgcontour_list slivers; - SGGeod p; bool debug_shape; tgAccumulator accum(bucket.gen_index_str()); unsigned int accum_idx = 0; // set up clipping tile : and remember to add the nodes! - p = bucket.get_corner( SG_BUCKET_SW ); + SGGeod p = bucket.get_corner( SG_BUCKET_SW ); p.setElevationM( -9999.0 ); safety_base.AddNode( 0, p ); nodes.unique_add( p ); @@ -281,10 +280,10 @@ bool TGConstruct::ClipLandclassPolys( void ) { // Now make sure any newly added intersection nodes are added to the tgnodes for (unsigned int area = 0; area < area_defs.size(); area++) { bool isRoad = area_defs.is_road_area( area ); - for (unsigned int p = 0; p < polys_clipped.area_size(area); p++ ) { - tgPolygon& poly = polys_clipped.get_poly( area, p ); + for (unsigned int idxPoly = 0; idxPoly < polys_clipped.area_size(area); ++idxPoly ) { + tgPolygon& poly = polys_clipped.get_poly( area, idxPoly ); - SG_LOG( SG_CLIPPER, SG_DEBUG, "Collecting nodes for " << area_defs.get_area_name(area) << ":" << p+1 << " of " << polys_clipped.area_size(area) ); + SG_LOG( SG_CLIPPER, SG_DEBUG, "Collecting nodes for " << area_defs.get_area_name(area) << ":" << idxPoly + 1 << " of " << polys_clipped.area_size(area) ); for (unsigned int con=0; con < poly.Contours(); con++) { for (unsigned int n = 0; n < poly.ContourSize( con ); n++) { diff --git a/src/BuildTiles/Main/tgconstruct_debug.cxx b/src/BuildTiles/Main/tgconstruct_debug.cxx index 68a464a6..50697ddd 100644 --- a/src/BuildTiles/Main/tgconstruct_debug.cxx +++ b/src/BuildTiles/Main/tgconstruct_debug.cxx @@ -47,25 +47,24 @@ void TGConstruct::get_debug( void ) debug_shapes.clear(); /* Find any ids for our tile */ - for (unsigned int i=0; i< debug_area_defs.size(); i++) { + for (unsigned int i = 0; i < debug_area_defs.size(); ++i) { string dsd = debug_area_defs[i]; size_t d_pos = dsd.find(":"); string tile = dsd.substr(0, d_pos); - if( tile == bucket.gen_index_str() ) { - dsd.erase(0, d_pos+1); + if ( tile == bucket.gen_index_str() ) { + dsd.erase(0, d_pos + 1); if ( dsd == "all" ) { debug_all = true; } else { std::stringstream ss(dsd); - int i; - - while (ss >> i) + int idx; + while (ss >> idx) { - SG_LOG(SG_GENERAL, SG_ALERT, "Adding debug area " << i); + SG_LOG(SG_GENERAL, SG_ALERT, "Adding debug area " << idx); - debug_areas.push_back(i); + debug_areas.push_back(idx); if (ss.peek() == ',') ss.ignore(); @@ -74,25 +73,24 @@ void TGConstruct::get_debug( void ) } } - for (unsigned int i=0; i< debug_shape_defs.size(); i++) { + for (unsigned int i = 0; i < debug_shape_defs.size(); ++i) { string dsd = debug_shape_defs[i]; size_t d_pos = dsd.find(":"); string tile = dsd.substr(0, d_pos); - if( tile == bucket.gen_index_str() ) { - dsd.erase(0, d_pos+1); + if ( tile == bucket.gen_index_str() ) { + dsd.erase(0, d_pos + 1); if ( dsd == "all" ) { debug_all = true; } else { std::stringstream ss(dsd); - int i; - - while (ss >> i) + int idx; + while (ss >> idx) { - SG_LOG(SG_GENERAL, SG_ALERT, "Adding debug shape " << i); + SG_LOG(SG_GENERAL, SG_ALERT, "Adding debug shape " << idx); - debug_shapes.push_back(i); + debug_shapes.push_back(idx); if (ss.peek() == ',') ss.ignore(); diff --git a/src/BuildTiles/Main/tgconstruct_elevation.cxx b/src/BuildTiles/Main/tgconstruct_elevation.cxx index 1c1c2773..15c7c1a0 100644 --- a/src/BuildTiles/Main/tgconstruct_elevation.cxx +++ b/src/BuildTiles/Main/tgconstruct_elevation.cxx @@ -34,9 +34,8 @@ using std::string; // and return list of fitted nodes. void TGConstruct::LoadElevationArray( bool add_nodes ) { string base = bucket.gen_base_path(); - int i; - for ( i = 0; i < (int)load_dirs.size(); ++i ) { + for ( int i = 0; i < (int)load_dirs.size(); ++i ) { string array_path = work_base + "/" + load_dirs[i] + "/" + base + "/" + bucket.gen_index_str(); if ( array.open(array_path) ) { @@ -48,14 +47,15 @@ void TGConstruct::LoadElevationArray( bool add_nodes ) { array.parse( bucket ); array.remove_voids( ); + if ( add_nodes ) { std::vector const& corner_list = array.get_corner_list(); - for (unsigned int i=0; i const& fit_list = array.get_fitted_list(); - for (unsigned int i=0; i& bucketList ) { // todo - add to work queue - for ( unsigned int i=0; i& bucketList ) int nCount; // read in all of the .btg nodes - for ( unsigned int j=0; j& bucketList ) nCount = north.size(); SG_LOG( SG_GENERAL, SG_DEBUG, "write " << north.size() << " northern nodes to file " << filepath.c_str() ); sgWriteInt( fp, nCount ); - for (int i=0; i= 0; --row ) { if ( gzfread( (voidp)read_buffer, 2, size, fd ) != (unsigned)size ) { return false; @@ -181,10 +195,3 @@ TGHgt::load( ) { return true; } - - -TGHgt::~TGHgt() { - // printf("class TGSrtmBase DEstructor called.\n"); - delete [] data; - delete [] read_buffer; -} diff --git a/src/Lib/HGT/hgt.hxx b/src/Lib/HGT/hgt.hxx index 4784820a..6ed2e53d 100644 --- a/src/Lib/HGT/hgt.hxx +++ b/src/Lib/HGT/hgt.hxx @@ -74,7 +74,7 @@ public: // load an hgt file bool load(); - virtual short height( int x, int y ) const { return data[x][y]; } + virtual short height( int x, int y ) const override { return data[x][y]; } }; diff --git a/src/Lib/terragear/clipper.cpp b/src/Lib/terragear/clipper.cpp index a6b8cf03..a8606c83 100644 --- a/src/Lib/terragear/clipper.cpp +++ b/src/Lib/terragear/clipper.cpp @@ -936,7 +936,6 @@ TEdge* FindNextLocMin(TEdge* E) TEdge* ClipperBase::ProcessBound(TEdge* E, bool NextIsForward) { TEdge *Result = E; - TEdge *Horz = 0; if (E->OutIdx == Skip) { @@ -1008,7 +1007,7 @@ TEdge* ClipperBase::ProcessBound(TEdge* E, bool NextIsForward) //nb: at the top of a bound, horizontals are added to the bound //only when the preceding edge attaches to the horizontal's left vertex //unless a Skip edge is encountered when that becomes the top divide - Horz = Result; + TEdge *Horz = Result; while (IsHorizontal(*Horz->Prev)) Horz = Horz->Prev; if (Horz->Prev->Top.X > Result->Next->Top.X) Result = Horz->Prev; } @@ -1028,7 +1027,7 @@ TEdge* ClipperBase::ProcessBound(TEdge* E, bool NextIsForward) Result = Result->Prev; if (IsHorizontal(*Result) && Result->Prev->OutIdx != Skip) { - Horz = Result; + TEdge *Horz = Result; while (IsHorizontal(*Horz->Next)) Horz = Horz->Next; if (Horz->Next->Top.X == Result->Prev->Top.X || Horz->Next->Top.X > Result->Prev->Top.X) Result = Horz->Next; @@ -2663,14 +2662,14 @@ void Clipper::ProcessHorizontal(TEdge *horzEdge) if (dir == Direction::LeftToRight) { maxIt = m_Maxima.begin(); - while (maxIt != m_Maxima.end() && *maxIt <= horzEdge->Bot.X) maxIt++; + while (maxIt != m_Maxima.end() && *maxIt <= horzEdge->Bot.X) ++maxIt; if (maxIt != m_Maxima.end() && *maxIt >= eLastHorz->Top.X) maxIt = m_Maxima.end(); } else { maxRit = m_Maxima.rbegin(); - while (maxRit != m_Maxima.rend() && *maxRit > horzEdge->Bot.X) maxRit++; + while (maxRit != m_Maxima.rend() && *maxRit > horzEdge->Bot.X) ++maxRit; if (maxRit != m_Maxima.rend() && *maxRit <= eLastHorz->Top.X) maxRit = m_Maxima.rend(); } @@ -2697,7 +2696,7 @@ void Clipper::ProcessHorizontal(TEdge *horzEdge) { if (horzEdge->OutIdx >= 0 && !IsOpen) AddOutPt(horzEdge, IntPoint(*maxIt, horzEdge->Bot.Y)); - maxIt++; + ++maxIt; } } else @@ -2706,7 +2705,7 @@ void Clipper::ProcessHorizontal(TEdge *horzEdge) { if (horzEdge->OutIdx >= 0 && !IsOpen) AddOutPt(horzEdge, IntPoint(*maxRit, horzEdge->Bot.Y)); - maxRit++; + ++maxRit; } } }; @@ -2988,7 +2987,7 @@ void Clipper::DoMaxima(TEdge *e) } else if( e->OutIdx >= 0 && eMaxPair->OutIdx >= 0 ) { - if (e->OutIdx >= 0) AddLocalMaxPoly(e, eMaxPair, e->Top); + AddLocalMaxPoly(e, eMaxPair, e->Top); DeleteFromAEL(e); DeleteFromAEL(eMaxPair); } @@ -3207,19 +3206,26 @@ int PointCount(OutPt *Pts) void Clipper::BuildResult(Paths &polys) { polys.reserve(m_PolyOuts.size()); + for (PolyOutList::size_type i = 0; i < m_PolyOuts.size(); ++i) { - if (!m_PolyOuts[i]->Pts) continue; - Path pg; + if (!m_PolyOuts[i]->Pts) + continue; + OutPt* p = m_PolyOuts[i]->Pts->Prev; + int cnt = PointCount(p); - if (cnt < 2) continue; + if (cnt < 2) + continue; + + Path pg; pg.reserve(cnt); - for (int i = 0; i < cnt; ++i) + for (int j = 0; j < cnt; ++j) { pg.push_back(p->Pt); p = p->Prev; } + polys.push_back(pg); } } From 640c91b3690b8dceac1cefe1915f4060532563ec Mon Sep 17 00:00:00 2001 From: Scott Giese Date: Thu, 31 Jan 2019 16:54:37 -0600 Subject: [PATCH 22/25] [grass scripts] minor clean up --- gismodules/v.contri/main.c | 1 + gismodules/v.flatten/main.c | 78 ++++++++++++++++----------------- gismodules/v.out.btg/main.c | 5 ++- gisscripts/IntersectsRemoval.sh | 7 --- gisscripts/grassVMap.sh | 21 ++------- gisscripts/grassVMap0convert.sh | 3 -- 6 files changed, 46 insertions(+), 69 deletions(-) diff --git a/gismodules/v.contri/main.c b/gismodules/v.contri/main.c index 0e0f5330..ed02edd9 100644 --- a/gismodules/v.contri/main.c +++ b/gismodules/v.contri/main.c @@ -33,6 +33,7 @@ #include "triangle.h" + void build_segments(struct triangulateio* tri, struct Map_info* map) { plus_t node_idx, line_idx; diff --git a/gismodules/v.flatten/main.c b/gismodules/v.flatten/main.c index 954d08d6..9effcb5d 100644 --- a/gismodules/v.flatten/main.c +++ b/gismodules/v.flatten/main.c @@ -24,7 +24,8 @@ #include #include -void apply_setz_operator( struct Map_info* map, double z, int* cats, int ncats, int layer) + +void apply_setz_operator(struct Map_info* map, double z, int* cats, int ncats, int layer) { const plus_t area_count = Vect_get_num_areas( map ); plus_t area_idx; @@ -42,7 +43,7 @@ void apply_setz_operator( struct Map_info* map, double z, int* cats, int ncats, } } -void apply_mean_operator( struct Map_info* map, int* cats, int ncats, int layer ) +void apply_mean_operator(struct Map_info* map, int* cats, int ncats, int layer) { if (ncats > 0) { /* We have to greedily collect adjacent selected areas */ @@ -53,7 +54,7 @@ void apply_mean_operator( struct Map_info* map, int* cats, int ncats, int layer } } -void apply_slope_operator( struct Map_info* map, double slope, int* cats, int ncats, int layer) +void apply_slope_operator(struct Map_info* map, double slope, int* cats, int ncats, int layer) { if (ncats > 0) { /* We apply slope to individual areas */ @@ -73,9 +74,7 @@ int main(int argc, char *argv[]) struct Option *fieldopt; int field; struct Map_info oldmap, newmap; - struct field_info* fieldinfo; - dbDriver* driver; - int i, ncats, *cats; + int ncats, *cats; G_gisinit(argv[0]); @@ -131,36 +130,36 @@ int main(int argc, char *argv[]) Vect_close(&oldmap); if (whereopt->answer!=NULL) { - field = Vect_get_field_number( &newmap, fieldopt->answer ); - fieldinfo = Vect_get_field( &newmap, field ); - if (!fieldinfo) { - G_fatal_error(_("Database connection not defined for layer <%s>"), - fieldopt->answer); - } - - G_debug(1, "Loading categories from table <%s>", fieldinfo->table); - - driver = db_start_driver_open_database(fieldinfo->driver, fieldinfo->database); - if (driver == NULL) { - G_fatal_error(_("Unable to open database <%s> by driver <%s>"), - fieldinfo->database, fieldinfo->driver); - } - - ncats = db_select_int(driver, fieldinfo->table, fieldinfo->key, whereopt->answer, - &cats); - if (ncats == -1) { - G_fatal_error(_("Unable select records from table <%s>"), fieldinfo->table); - } - G_message(_("%d categories loaded from table <%s>"), ncats, - fieldinfo->table); - - db_close_database(driver); - db_shutdown_driver(driver); - } else { - field = -1; - cats = NULL; - ncats = -1; - } + field = Vect_get_field_number( &newmap, fieldopt->answer ); + struct field_info* fieldinfo = Vect_get_field( &newmap, field ); + if (!fieldinfo) { + G_fatal_error(_("Database connection not defined for layer <%s>"), + fieldopt->answer); + } + + G_debug(1, "Loading categories from table <%s>", fieldinfo->table); + + dbDriver* driver = db_start_driver_open_database(fieldinfo->driver, fieldinfo->database); + if (driver == NULL) { + G_fatal_error(_("Unable to open database <%s> by driver <%s>"), + fieldinfo->database, fieldinfo->driver); + } + + ncats = db_select_int(driver, fieldinfo->table, fieldinfo->key, whereopt->answer, + &cats); + if (ncats == -1) { + G_fatal_error(_("Unable select records from table <%s>"), fieldinfo->table); + } + G_message(_("%d categories loaded from table <%s>"), ncats, + fieldinfo->table); + + db_close_database(driver); + db_shutdown_driver(driver); + } else { + field = -1; + cats = NULL; + ncats = -1; + } if (!strcmp(operator->answer, "setz")) { apply_setz_operator( &newmap, atof(value->answer), cats, ncats, field ); @@ -172,9 +171,10 @@ int main(int argc, char *argv[]) Vect_build(&newmap); - if (cats != NULL) { - G_free(cats); - } + if (cats != NULL) { + G_free(cats); + } + Vect_close(&newmap); /* Don't forget to report to caller sucessful end of data processing :) */ diff --git a/gismodules/v.out.btg/main.c b/gismodules/v.out.btg/main.c index 54e24b4b..923ed106 100644 --- a/gismodules/v.out.btg/main.c +++ b/gismodules/v.out.btg/main.c @@ -21,10 +21,11 @@ #include #include + int main(int argc, char *argv[]) { struct GModule *module; /* GRASS module for parsing arguments */ - struct Option *old, *new; + struct Option *old; struct Map_info oldmap; G_gisinit(argv[0]); @@ -36,7 +37,7 @@ int main(int argc, char *argv[]) /* Define the different options as defined in gis.h */ old = G_define_standard_option(G_OPT_V_INPUT); - new = G_define_standard_option(G_OPT_F_OUTPUT); + G_define_standard_option(G_OPT_F_OUTPUT); /* options and flags parser */ if (G_parser(argc, argv)) diff --git a/gisscripts/IntersectsRemoval.sh b/gisscripts/IntersectsRemoval.sh index d5ef5f8d..f24e2f81 100755 --- a/gisscripts/IntersectsRemoval.sh +++ b/gisscripts/IntersectsRemoval.sh @@ -39,13 +39,6 @@ MODE="testing" # production, testing InitCutoutTable () { ${PSQL} "DROP TABLE ${CUTLAYER}" -# ${PSQL} "CREATE TABLE ${CUTLAYER} (ogc_fid serial NOT NULL, \ -# wkb_geometry geometry, \ -# CONSTRAINT enforce_dims_wkb_geometry CHECK (ST_NDims(wkb_geometry) = 2), \ -# CONSTRAINT enforce_geotype_wkb_geometry CHECK ((ST_GeometryType(wkb_geometry) = 'ST_Polygon'::text) \ -# OR (ST_GeometryType(wkb_geometry) = 'ST_MultiPolygon'::text)), \ -# CONSTRAINT enforce_srid_wkb_geometry CHECK (ST_SRID(wkb_geometry) = 4326) \ -# )" ${PSQL} "CREATE TABLE ${CUTLAYER} (ogc_fid serial NOT NULL, \ wkb_geometry geometry, \ CONSTRAINT enforce_dims_wkb_geometry CHECK (ST_NDims(wkb_geometry) = 2), \ diff --git a/gisscripts/grassVMap.sh b/gisscripts/grassVMap.sh index 89333a3b..9e7d42a5 100755 --- a/gisscripts/grassVMap.sh +++ b/gisscripts/grassVMap.sh @@ -25,10 +25,11 @@ date DUMPDIR=${HOME}/shp mkdir -p ${DUMPDIR} RUNDIR=`pwd` + cd `dirname ${0}` && export BASEDIR=`pwd` + cd ${RUNDIR} CALLNAME=`basename ${0}` -# MAPPINGFILE=${BASEDIR}/CORINEtoCS.txt if [ ${CALLNAME} = "grassVMap.sh" ]; then @@ -50,33 +51,24 @@ elif [ ${CALLNAME} = "grassCLC06.sh" ]; then else SRCID=0 fi + PREFIX=${TYPE}${YEAR} -#PREFIX=nl -#PREFIX=clc${YEAR}_nl CLEANMAP=cleanmap if [ ${TYPE} = "v0" ]; then SRCKBS=nad83 - #SNAP=0.00001 SNAP=0.000001 - #MIN_AREA1=1 MIN_AREA1=0.0000001 MIN_AREA=100 - #MIN_AREA=0.000000001 elif [ ${TYPE} = "cs" ]; then SRCKBS=wgs84 SNAP=0.000001 - #MIN_AREA1=1 MIN_AREA1=0.0000001 MIN_AREA=1 elif [ ${TYPE} = "clc" ]; then SRCKBS=laea SNAP=0.01 - #SNAP=0.001 - #SNAP=0.0001 - #SNAP=0.000001 MIN_AREA=1 - #MIN_AREA=0.000000001 fi ######################################################################## @@ -148,7 +140,6 @@ fn_importVMap() { LAYER=`basename ${SHAPEFILE} | cut -f 1 -d \.` MAP=`echo ${LAYER} | sed -e 's/-/_/g'` g.remove vect=${MAP} -# v.in.ogr dsn="${LOADDIR}" layer=${LAYER} output=${MAP} snap=${SNAP} --verbose v.in.ogr dsn="${LOADDIR}" layer=${LAYER} output=${MAP} --verbose done } @@ -238,11 +229,9 @@ fn_split() { v.extract -t input=${LAYER} type=area output=${PREFIX}_mixedcrop_${ZONE} where="f_code NOT LIKE 'BH135' and veg = 0" v.extract -t input=${LAYER} type=area output=${PREFIX}_drycrop_${ZONE} where="f_code NOT LIKE 'BH135' and veg = 1" v.extract -t input=${LAYER} type=area output=${PREFIX}_irrcrop_${ZONE} where="f_code NOT LIKE 'BH135' and veg > 1" -# v.extract -t input=${LAYER} type=area output=${PREFIX}_rice_${ZONE} where="f_code LIKE 'BH135'" ;; "grassa@veg(*)_area") v.extract -t input=${LAYER} type=area output=${PREFIX}_grassland_${ZONE} where="f_code LIKE 'EB010'" -# v.extract -t input=${LAYER} type=area output=${PREFIX}_bamboo_${ZONE} where="f_code LIKE 'EC010'" v.extract -t input=${LAYER} type=area output=${PREFIX}_scrub_${ZONE} where="f_code NOT LIKE 'EB010' AND f_code NOT LIKE 'EC010'" ;; "oasisa@veg(*)_area") @@ -257,7 +246,6 @@ fn_split() { v.extract -t input=${LAYER} type=area output=${PREFIX}_marsh_${ZONE} where="f_code NOT LIKE 'BH015'" ;; "treesa@veg(*)_area") -# v.extract -t input=${LAYER} type=area output=${PREFIX}_mangrove_${ZONE} where="veg = 19" v.extract -t input=${LAYER} type=area output=${PREFIX}_deciduousforest_${ZONE} where="veg = 24" v.extract -t input=${LAYER} type=area output=${PREFIX}_evergreenforest_${ZONE} where="veg = 25" v.extract -t input=${LAYER} type=area output=${PREFIX}_mixedforest_${ZONE} where="veg != 19 AND veg != 24 AND veg != 25" @@ -292,7 +280,6 @@ fn_reclass() { done g.remove vect=${OUTPUT}_patched v.patch input=`g.mlist type=vect pattern="${OUTPUT}_[a-z][a-z][a-z]_lcclass" separator=,` output=${OUTPUT}_patched -# v.patch input=`g.mlist type=vect pattern="${OUTPUT}_[a-z][a-z][a-z]_lcclass" separator=,` output=${INTMAP} g.remove vect=${OUTPUT}_bpol,${OUTPUT}_snap,${OUTPUT}_split,${OUTPUT}_rmsa,${OUTPUT}_rmdangle,${OUTPUT}_rmarea,${OUTPUT}_prune v.clean input=${OUTPUT}_patched output=${OUTPUT}_bpol -c tool=bpol type=boundary --verbose @@ -451,7 +438,6 @@ fn_export() { # SELECTION=`v.category input=${CLEANMAP} type=centroid option=print | sort -n | uniq` for CATEGORY in ${SELECTION}; do -# LAYER=${PREFIX}_${CATEGORY} LAYER=`grep \^${CATEGORY} ${MAPPINGFILE} | awk '{print $2}' | sed -e "s/^cs_/${PREFIX}_/g"` g.remove vect=${LAYER} v.extract cats=${CATEGORY} input=${CLEANMAP} output=${LAYER} type=area @@ -461,7 +447,6 @@ fn_export() { g.rename vect=${LAYER},${NEWLAYER} LAYER=${NEWLAYER} fi -# v.out.ogr input=${LAYER} type=area dsn=${DUMPDIR}/${PREFIX}_c${CATEGORY}.shp # For CLC v.out.ogr input=${LAYER} type=area dsn=${DUMPDIR}/${LAYER}.shp # For VMap0/CS fn_topostgis ${LAYER} done diff --git a/gisscripts/grassVMap0convert.sh b/gisscripts/grassVMap0convert.sh index 3cf336cf..7d4b8660 100755 --- a/gisscripts/grassVMap0convert.sh +++ b/gisscripts/grassVMap0convert.sh @@ -28,8 +28,6 @@ mkdir -p ${DUMPDIR} export LD_LIBRARY_PATH=/opt/GRASS.32/lib OGR2OGR=/opt/GRASS.32/bin/ogr2ogr OGRINFO=/opt/GRASS.32/bin/ogrinfo -#OGR2OGR=/usr/local/bin/ogr2ogr -#OGRINFO=/usr/local/bin/ogrinfo AREAS="v0eur_5/vmaplv0/eurnasia v0noa_5/vmaplv0/noamer v0sas_5/vmaplv0/sasaus v0soa_5/vmaplv0/soamafr" @@ -46,7 +44,6 @@ GetFeatureNames () { ConvertToSHapefiles () { for VMAP_URL in ${AREAS}; do ZONE=`echo ${VMAP_URL} | cut -f 1 -d \/ | sed -e 's/^v0//g' -e 's/_5\$//g'` -# for FEATURE in `GetFeatureNames`; do for FEATURE in `${OGRINFO} gltp:/vrf/home/martin/live/vmap0/${VMAP_URL} 2>&1 | egrep \^"[0-9].*@" | awk '{print $2}' | sort | uniq`; do CATEGORY=`echo ${FEATURE} | cut -f 1 -d \@` DIR=`echo ${FEATURE} | cut -f 1 -d \( | cut -f 2 -d \@` From 791314a909fd2ccba36dde11a6f7366e9c696840 Mon Sep 17 00:00:00 2001 From: Scott Giese Date: Thu, 31 Jan 2019 17:49:43 -0600 Subject: [PATCH 23/25] Last set of technical debt items --- src/Lib/terragear/TNT/jama_qr.h | 12 ++-- src/Lib/terragear/clipper.cpp | 31 +++++---- src/Lib/terragear/clipper.hpp | 4 +- src/Lib/terragear/tg_accumulator.cxx | 21 +++--- src/Lib/terragear/tg_accumulator.hxx | 2 +- src/Lib/terragear/tg_chopper.cxx | 6 +- src/Lib/terragear/tg_chopper.hxx | 9 +-- src/Lib/terragear/tg_contour.cxx | 76 ++++++++++------------ src/Lib/terragear/tg_nodes.cxx | 12 ++-- src/Lib/terragear/tg_polygon.cxx | 10 ++- src/Lib/terragear/tg_polygon.hxx | 2 + src/Lib/terragear/tg_polygon_clean.cxx | 11 ++-- src/Lib/terragear/tg_polygon_tesselate.cxx | 15 +++-- src/Lib/terragear/tg_shapefile.cxx | 15 ++--- src/Lib/terragear/tg_surface.cxx | 4 +- src/Lib/terragear/tg_unique_geod.hxx | 6 +- src/Lib/terragear/tg_unique_tgnode.hxx | 11 ++-- src/Prep/OGRDecode/ogr-decode.cxx | 16 ++--- src/Prep/TerraFit/terrafit.cc | 3 +- src/Utils/poly2ogr/poly2ogr.cxx | 4 +- 20 files changed, 136 insertions(+), 134 deletions(-) diff --git a/src/Lib/terragear/TNT/jama_qr.h b/src/Lib/terragear/TNT/jama_qr.h index 98d37f53..216f2278 100644 --- a/src/Lib/terragear/TNT/jama_qr.h +++ b/src/Lib/terragear/TNT/jama_qr.h @@ -60,13 +60,13 @@ public: @param A rectangular (m>=n) matrix. */ - QR(const TNT::Array2D &A) /* constructor */ - { - QR_ = A.copy(); + explicit QR(const TNT::Array2D &A) : /* constructor */ + QR_(A.copy()) + { m = A.dim1(); n = A.dim2(); Rdiag = TNT::Array1D(n); - int i=0, j=0, k=0; + int i, j, k; // Main loop. for (k = 0; k < n; k++) { @@ -182,7 +182,7 @@ public: TNT::Array2D getQ() const { - int i=0, j=0, k=0; + int i, j, k; TNT::Array2D Q(m,n); for (k = n-1; k >= 0; k--) { @@ -277,7 +277,7 @@ public: int nx = B.dim2(); TNT::Array2D X = B.copy(); - int i=0, j=0, k=0; + int i, j, k; // Compute Y = transpose(Q)*B for (k = 0; k < n; k++) { diff --git a/src/Lib/terragear/clipper.cpp b/src/Lib/terragear/clipper.cpp index a8606c83..fa8cad96 100644 --- a/src/Lib/terragear/clipper.cpp +++ b/src/Lib/terragear/clipper.cpp @@ -258,7 +258,7 @@ class Int128 Int128(long64 _lo = 0) { - lo = (ulong64)_lo; + lo = (ulong64)_lo; if (_lo < 0) hi = -1; else hi = 0; } @@ -553,8 +553,8 @@ bool SlopesEqual(const TEdge &e1, const TEdge &e2, bool UseFullInt64Range) } //------------------------------------------------------------------------------ -bool SlopesEqual(const IntPoint pt1, const IntPoint pt2, - const IntPoint pt3, bool UseFullInt64Range) +bool SlopesEqual(const IntPoint& pt1, const IntPoint& pt2, + const IntPoint& pt3, bool UseFullInt64Range) { #ifndef use_int32 if (UseFullInt64Range) @@ -565,8 +565,8 @@ bool SlopesEqual(const IntPoint pt1, const IntPoint pt2, } //------------------------------------------------------------------------------ -bool SlopesEqual(const IntPoint pt1, const IntPoint pt2, - const IntPoint pt3, const IntPoint pt4, bool UseFullInt64Range) +bool SlopesEqual(const IntPoint& pt1, const IntPoint& pt2, + const IntPoint& pt3, const IntPoint& pt4, bool UseFullInt64Range) { #ifndef use_int32 if (UseFullInt64Range) @@ -583,7 +583,7 @@ inline bool IsHorizontal(TEdge &e) } //------------------------------------------------------------------------------ -inline double GetDx(const IntPoint pt1, const IntPoint pt2) +inline double GetDx(const IntPoint& pt1, const IntPoint& pt2) { return (pt1.Y == pt2.Y) ? HORIZONTAL : (double)(pt2.X - pt1.X) / (pt2.Y - pt1.Y); @@ -862,8 +862,8 @@ OutPt* GetBottomPt(OutPt *pp) } //------------------------------------------------------------------------------ -bool Pt2IsBetweenPt1AndPt3(const IntPoint pt1, - const IntPoint pt2, const IntPoint pt3) +bool Pt2IsBetweenPt1AndPt3(const IntPoint& pt1, + const IntPoint& pt2, const IntPoint& pt3) { if ((pt1 == pt3) || (pt1 == pt2) || (pt3 == pt2)) return false; @@ -1480,6 +1480,11 @@ bool ClipperBase::LocalMinimaPending() Clipper::Clipper(int initOptions) : ClipperBase() //constructor { + m_ClipType = ClipType::Intersection; + m_SortedEdges = 0; + m_ClipFillType = PolyFillType::EvenOdd; + m_SubjFillType = PolyFillType::EvenOdd; + m_UsingPolyTree = false; m_ExecuteLocked = false; m_UseFullRange = false; m_ReverseOutput = ((initOptions & static_cast(InitOptions::ReverseSolution)) != 0); @@ -1946,7 +1951,7 @@ void Clipper::CopyAELToSEL() } //------------------------------------------------------------------------------ -void Clipper::AddJoin(OutPt *op1, OutPt *op2, const IntPoint OffPt) +void Clipper::AddJoin(OutPt *op1, OutPt *op2, const IntPoint& OffPt) { Join* j = new Join; j->OutPt1 = op1; @@ -1972,7 +1977,7 @@ void Clipper::ClearGhostJoins() } //------------------------------------------------------------------------------ -void Clipper::AddGhostJoin(OutPt *op, const IntPoint OffPt) +void Clipper::AddGhostJoin(OutPt *op, const IntPoint& OffPt) { Join* j = new Join; j->OutPt1 = op; @@ -3383,7 +3388,7 @@ OutPt* DupOutPt(OutPt* outPt, bool InsertAfter) //------------------------------------------------------------------------------ bool JoinHorz(OutPt* op1, OutPt* op1b, OutPt* op2, OutPt* op2b, - const IntPoint Pt, bool DiscardLeft) + const IntPoint& Pt, bool DiscardLeft) { Direction Dir1 = (op1->Pt.X > op1b->Pt.X ? Direction::RightToLeft : Direction::LeftToRight); Direction Dir2 = (op2->Pt.X > op2b->Pt.X ? Direction::RightToLeft : Direction::LeftToRight); @@ -3802,6 +3807,8 @@ ClipperOffset::ClipperOffset(double miterLimit, double arcTolerance) this->MiterLimit = miterLimit; this->ArcTolerance = arcTolerance; m_lowest.X = -1; + m_delta = m_sinA = m_sin = m_cos = 0.0; + m_miterLim = m_StepsPerRad = 0.0; } //------------------------------------------------------------------------------ @@ -4534,7 +4541,7 @@ void MinkowskiSum(const Path& pattern, const Path& path, Paths& solution, bool p } //------------------------------------------------------------------------------ -void TranslatePath(const Path& input, Path& output, const IntPoint delta) +void TranslatePath(const Path& input, Path& output, const IntPoint& delta) { //precondition: input != output output.resize(input.size()); diff --git a/src/Lib/terragear/clipper.hpp b/src/Lib/terragear/clipper.hpp index ff34c225..16f1e9b7 100644 --- a/src/Lib/terragear/clipper.hpp +++ b/src/Lib/terragear/clipper.hpp @@ -341,10 +341,10 @@ private: bool IsHole(TEdge *e); bool FindOwnerFromSplitRecs(OutRec &outRec, OutRec *&currOrfl); void FixHoleLinkage(OutRec &outrec); - void AddJoin(OutPt *op1, OutPt *op2, const IntPoint offPt); + void AddJoin(OutPt *op1, OutPt *op2, const IntPoint& offPt); void ClearJoins(); void ClearGhostJoins(); - void AddGhostJoin(OutPt *op, const IntPoint offPt); + void AddGhostJoin(OutPt *op, const IntPoint& offPt); bool JoinPoints(Join *j, OutRec* outRec1, OutRec* outRec2); void JoinCommonEdges(); void DoSimplePolygons(); diff --git a/src/Lib/terragear/tg_accumulator.cxx b/src/Lib/terragear/tg_accumulator.cxx index 85962ba8..1c95f494 100644 --- a/src/Lib/terragear/tg_accumulator.cxx +++ b/src/Lib/terragear/tg_accumulator.cxx @@ -56,7 +56,7 @@ tgPolygon tgAccumulator::Diff( const tgContour& subject ) max_hits = num_hits-1; FILE* fp = fopen( "./accumulator_fail.log", "a" ); - fprintf( fp, "%s : reduce from %d to %d\n", debugstr.c_str(), num_hits, max_hits ); + fprintf( fp, "%s : reduce from %u to %u\n", debugstr.c_str(), num_hits, max_hits ); fclose(fp); } else { result = tgPolygon::FromClipper( clipper_result ); @@ -119,7 +119,7 @@ tgPolygon tgAccumulator::Diff( const tgPolygon& subject ) max_hits = num_hits-1; FILE* fp = fopen( "./accumulator_fail.log", "a" ); - fprintf( fp, "%s : reduce from %d to %d\n", debugstr.c_str(), num_hits, max_hits ); + fprintf( fp, "%s : reduce from %u to %u\n", debugstr.c_str(), num_hits, max_hits ); fclose(fp); } else { result = tgPolygon::FromClipper( clipper_result ); @@ -173,14 +173,14 @@ void tgAccumulator::Add( const tgPolygon& subject ) void tgAccumulator::ToShapefiles( const std::string& path, const std::string& layer_prefix, bool individual ) { - char shapefile[32]; - char layer[32]; - if ( accum.size() ) { if ( individual ) { for (unsigned int i=0; i < accum.size(); i++) { - sprintf( layer, "%s_%d", layer_prefix.c_str(), i ); - sprintf( shapefile, "accum_%d", i ); + char layer[32]; + sprintf( layer, "%s_%u", layer_prefix.c_str(), i ); + + char shapefile[32]; + sprintf( shapefile, "accum_%u", i ); tgShapefile::FromClipper( accum[i], path, layer, std::string(shapefile) ); } } else { @@ -204,13 +204,13 @@ void tgAccumulator::ToShapefiles( const std::string& path, const std::string& la void tgAccumulator::ToClipperfiles( const std::string& path, const std::string& layer_prefix, bool individual ) { std::ofstream file; - char filename[256]; if ( accum.size() ) { if ( individual ) { + char filename[256]; for (unsigned int i=0; i < accum.size(); i++) { - sprintf( filename, "%s/%s_%d", path.c_str(), layer_prefix.c_str(), i ); - + sprintf( filename, "%s/%s_%u", path.c_str(), layer_prefix.c_str(), i ); + file.open (filename); file << accum[i]; file.close(); @@ -225,6 +225,7 @@ void tgAccumulator::ToClipperfiles( const std::string& path, const std::string& } if ( c.Execute( ClipperLib::ClipType::Union, clipper_result, ClipperLib::PolyFillType::NonZero, ClipperLib::PolyFillType::NonZero) ) { + char filename[256]; sprintf( filename, "%s/%s", path.c_str(), layer_prefix.c_str() ); file.open (filename); diff --git a/src/Lib/terragear/tg_accumulator.hxx b/src/Lib/terragear/tg_accumulator.hxx index fa38b75e..a03fd55c 100644 --- a/src/Lib/terragear/tg_accumulator.hxx +++ b/src/Lib/terragear/tg_accumulator.hxx @@ -8,7 +8,7 @@ class tgAccumulator { public: - tgAccumulator( const std::string& d ) : debugstr(d) {} + explicit tgAccumulator( const std::string& d ) : debugstr(d) {} tgPolygon Diff( const tgContour& subject ); tgPolygon Diff( const tgPolygon& subject ); diff --git a/src/Lib/terragear/tg_chopper.cxx b/src/Lib/terragear/tg_chopper.cxx index 7606d7a9..e2d42351 100644 --- a/src/Lib/terragear/tg_chopper.cxx +++ b/src/Lib/terragear/tg_chopper.cxx @@ -141,7 +141,7 @@ void tgChopper::Add( const tgPolygon& subject, const std::string& type ) } } -long int tgChopper::GenerateIndex( std::string path ) +long int tgChopper::GenerateIndex( const std::string& path ) { std::string index_file = path + "/chop.idx"; long int index = 0; @@ -194,7 +194,7 @@ void tgChopper::Save( bool DebugShapefiles ) char layer[32]; char ds_name[64]; - for (it=bp_map.begin(); it != bp_map.end(); it++) { + for (it=bp_map.begin(); it != bp_map.end(); ++it) { SGBucket b( (*it).first ); tgpolygon_list const& polys = (*it).second; @@ -226,7 +226,7 @@ void tgChopper::Save( bool DebugShapefiles ) if ( DebugShapefiles ) { - sprintf(layer, "poly_%s-%d", b.gen_index_str().c_str(), i ); + sprintf(layer, "poly_%s-%u", b.gen_index_str().c_str(), i ); tgShapefile::FromPolygon( polys[i], ds_name, layer, "poly" ); } } diff --git a/src/Lib/terragear/tg_chopper.hxx b/src/Lib/terragear/tg_chopper.hxx index e01f0215..60cfb0c4 100644 --- a/src/Lib/terragear/tg_chopper.hxx +++ b/src/Lib/terragear/tg_chopper.hxx @@ -9,9 +9,10 @@ typedef bucket_polys_map::iterator bucket_polys_map_interator; class tgChopper { public: - tgChopper( const std::string& path ) { - root_path = path; - extra_extension = ""; + explicit tgChopper( const std::string& path ) : + root_path(path), + extra_extension("") + { } void Add( const tgPolygon& poly, const std::string& type ); @@ -21,7 +22,7 @@ public: } private: - long int GenerateIndex( std::string path ); + long int GenerateIndex( const std::string& path ); void ClipRow( const tgPolygon& subject, const double& center_lat, const std::string& type ); tgPolygon Clip( const tgPolygon& subject, const std::string& type, SGBucket& b ); void Chop( const tgPolygon& subject, const std::string& type ); diff --git a/src/Lib/terragear/tg_contour.cxx b/src/Lib/terragear/tg_contour.cxx index 63b700a4..7a67961c 100644 --- a/src/Lib/terragear/tg_contour.cxx +++ b/src/Lib/terragear/tg_contour.cxx @@ -25,8 +25,8 @@ tgContour tgContour::Snap( const tgContour& subject, double snap ) double tgContour::GetMinimumAngle( void ) const { - unsigned int p1_index, p2_index, p3_index; - double angle, min_angle = 2.0 * SGD_PI; + unsigned int p1_index, p3_index; + double min_angle = 2.0 * SGD_PI; unsigned int size = node_list.size(); SG_LOG(SG_GENERAL, SG_DEBUG, " tgContour::GetMinimumAngle() : contour size is " << size ); @@ -38,7 +38,7 @@ double tgContour::GetMinimumAngle( void ) const p1_index = i - 1; } - p2_index = i; + unsigned p2_index = i; if ( i == size - 1 ) { p3_index = 0; @@ -46,7 +46,7 @@ double tgContour::GetMinimumAngle( void ) const p3_index = i + 1; } - angle = SGGeod_CalculateTheta( node_list[p1_index], node_list[p2_index], node_list[p3_index] ); + double angle = SGGeod_CalculateTheta( node_list[p1_index], node_list[p2_index], node_list[p3_index] ); if ( angle < min_angle ) { min_angle = angle; } @@ -58,16 +58,14 @@ double tgContour::GetMinimumAngle( void ) const double tgContour::GetArea( void ) const { double area = 0.0; - SGVec2d a, b; - unsigned int i, j; if ( node_list.size() ) { - j = node_list.size() - 1; - for (i=0; i piece = SGLineSegment(start,end); - dist = distSqr( piece,probexyz ); + double dist = distSqr( piece,probexyz ); if (dist < mindist) mindist = dist; } } @@ -633,7 +629,6 @@ static bool FindIntermediateNode( const SGGeod& start, const SGGeod& end, double bbEpsilon, double errEpsilon ) { bool found_node = false; - double m, m1, b, b1, y_err, x_err, y_err_min, x_err_min; SGGeod p0 = start; SGGeod p1 = end; @@ -641,8 +636,8 @@ static bool FindIntermediateNode( const SGGeod& start, const SGGeod& end, double xdist = fabs(p0.getLongitudeDeg() - p1.getLongitudeDeg()); double ydist = fabs(p0.getLatitudeDeg() - p1.getLatitudeDeg()); - x_err_min = xdist + 1.0; - y_err_min = ydist + 1.0; + double x_err_min = xdist + 1.0; + double y_err_min = ydist + 1.0; if ( xdist > ydist ) { // sort these in a sensible order @@ -655,15 +650,15 @@ static bool FindIntermediateNode( const SGGeod& start, const SGGeod& end, p_max = p0; } - m = (p_min.getLatitudeDeg() - p_max.getLatitudeDeg()) / (p_min.getLongitudeDeg() - p_max.getLongitudeDeg()); - b = p_max.getLatitudeDeg() - m * p_max.getLongitudeDeg(); + double m = (p_min.getLatitudeDeg() - p_max.getLatitudeDeg()) / (p_min.getLongitudeDeg() - p_max.getLongitudeDeg()); + double b = p_max.getLatitudeDeg() - m * p_max.getLongitudeDeg(); for ( int i = 0; i < (int)nodes.size(); ++i ) { // cout << i << endl; SGGeod current = nodes[i]; if ( (current.getLongitudeDeg() > (p_min.getLongitudeDeg() + (bbEpsilon))) && (current.getLongitudeDeg() < (p_max.getLongitudeDeg() - (bbEpsilon))) ) { - y_err = fabs(current.getLatitudeDeg() - (m * current.getLongitudeDeg() + b)); + double y_err = fabs(current.getLatitudeDeg() - (m * current.getLongitudeDeg() + b)); if ( y_err < errEpsilon ) { found_node = true; @@ -685,15 +680,15 @@ static bool FindIntermediateNode( const SGGeod& start, const SGGeod& end, p_max = p0; } - m1 = (p_min.getLongitudeDeg() - p_max.getLongitudeDeg()) / (p_min.getLatitudeDeg() - p_max.getLatitudeDeg()); - b1 = p_max.getLongitudeDeg() - m1 * p_max.getLatitudeDeg(); + double m1 = (p_min.getLongitudeDeg() - p_max.getLongitudeDeg()) / (p_min.getLatitudeDeg() - p_max.getLatitudeDeg()); + double b1 = p_max.getLongitudeDeg() - m1 * p_max.getLatitudeDeg(); for ( int i = 0; i < (int)nodes.size(); ++i ) { SGGeod current = nodes[i]; if ( (current.getLatitudeDeg() > (p_min.getLatitudeDeg() + (bbEpsilon))) && (current.getLatitudeDeg() < (p_max.getLatitudeDeg() - (bbEpsilon))) ) { - x_err = fabs(current.getLongitudeDeg() - (m1 * current.getLatitudeDeg() + b1)); + double x_err = fabs(current.getLongitudeDeg() - (m1 * current.getLatitudeDeg() + b1)); if ( x_err < errEpsilon ) { found_node = true; @@ -714,7 +709,6 @@ static bool FindIntermediateNode( const SGGeod& start, const SGGeod& end, double bbEpsilon, double errEpsilon ) { bool found_node = false; - double m, m1, b, b1, y_err, x_err, y_err_min, x_err_min; SGGeod p0 = start; SGGeod p1 = end; @@ -722,8 +716,8 @@ static bool FindIntermediateNode( const SGGeod& start, const SGGeod& end, double xdist = fabs(p0.getLongitudeDeg() - p1.getLongitudeDeg()); double ydist = fabs(p0.getLatitudeDeg() - p1.getLatitudeDeg()); - x_err_min = xdist + 1.0; - y_err_min = ydist + 1.0; + double x_err_min = xdist + 1.0; + double y_err_min = ydist + 1.0; if ( xdist > ydist ) { // sort these in a sensible order @@ -736,15 +730,15 @@ static bool FindIntermediateNode( const SGGeod& start, const SGGeod& end, p_max = p0; } - m = (p_min.getLatitudeDeg() - p_max.getLatitudeDeg()) / (p_min.getLongitudeDeg() - p_max.getLongitudeDeg()); - b = p_max.getLatitudeDeg() - m * p_max.getLongitudeDeg(); + double m = (p_min.getLatitudeDeg() - p_max.getLatitudeDeg()) / (p_min.getLongitudeDeg() - p_max.getLongitudeDeg()); + double b = p_max.getLatitudeDeg() - m * p_max.getLongitudeDeg(); for ( int i = 0; i < (int)nodes.size(); ++i ) { // cout << i << endl; SGGeod current = nodes[i]->GetPosition(); if ( (current.getLongitudeDeg() > (p_min.getLongitudeDeg() + (bbEpsilon))) && (current.getLongitudeDeg() < (p_max.getLongitudeDeg() - (bbEpsilon))) ) { - y_err = fabs(current.getLatitudeDeg() - (m * current.getLongitudeDeg() + b)); + double y_err = fabs(current.getLatitudeDeg() - (m * current.getLongitudeDeg() + b)); if ( y_err < errEpsilon ) { found_node = true; @@ -766,15 +760,15 @@ static bool FindIntermediateNode( const SGGeod& start, const SGGeod& end, p_max = p0; } - m1 = (p_min.getLongitudeDeg() - p_max.getLongitudeDeg()) / (p_min.getLatitudeDeg() - p_max.getLatitudeDeg()); - b1 = p_max.getLongitudeDeg() - m1 * p_max.getLatitudeDeg(); + double m1 = (p_min.getLongitudeDeg() - p_max.getLongitudeDeg()) / (p_min.getLatitudeDeg() - p_max.getLatitudeDeg()); + double b1 = p_max.getLongitudeDeg() - m1 * p_max.getLatitudeDeg(); for ( int i = 0; i < (int)nodes.size(); ++i ) { SGGeod current = nodes[i]->GetPosition(); if ( (current.getLatitudeDeg() > (p_min.getLatitudeDeg() + (bbEpsilon))) && (current.getLatitudeDeg() < (p_max.getLatitudeDeg() - (bbEpsilon))) ) { - x_err = fabs(current.getLongitudeDeg() - (m1 * current.getLatitudeDeg() + b1)); + double x_err = fabs(current.getLongitudeDeg() - (m1 * current.getLatitudeDeg() + b1)); if ( x_err < errEpsilon ) { found_node = true; @@ -1002,8 +996,6 @@ tgContour tgContour::Expand( const tgContour& subject, double offset ) tgpolygon_list tgContour::ExpandToPolygons( const tgContour& subject, double width ) { - int turn_dir; - SGGeod cur_inner; SGGeod cur_outer; SGGeod prev_inner; @@ -1011,8 +1003,6 @@ tgpolygon_list tgContour::ExpandToPolygons( const tgContour& subject, double wid SGGeod calc_inner; SGGeod calc_outer; - double last_end_v = 0.0f; - tgContour expanded; tgPolygon segment; tgAccumulator accum("ExpandToPolygons"); @@ -1021,8 +1011,7 @@ tgpolygon_list tgContour::ExpandToPolygons( const tgContour& subject, double wid // generate poly and texparam lists for each line segment for (unsigned int i = 0; i < subject.GetSize(); i++) { - last_end_v = 0.0f; - turn_dir = 0; + int turn_dir = 0; sglog().setLogLevels( SG_ALL, SG_INFO ); @@ -1033,8 +1022,8 @@ tgpolygon_list tgContour::ExpandToPolygons( const tgContour& subject, double wid if (i == 0) { // first point on the list - offset heading is 90deg - cur_outer = OffsetPointFirst( subject.GetNode(i), subject.GetNode(i+1), -width/2.0f ); - cur_inner = OffsetPointFirst( subject.GetNode(i), subject.GetNode(i+1), width/2.0f ); + cur_outer = OffsetPointFirst( subject.GetNode(i), subject.GetNode(1), -width/2.0f ); + cur_inner = OffsetPointFirst( subject.GetNode(i), subject.GetNode(1), width/2.0f ); } else if (i == subject.GetSize()-1) { @@ -1098,6 +1087,8 @@ tgpolygon_list tgContour::ExpandToPolygons( const tgContour& subject, double wid } } + double last_end_v = 0.0; + expanded.SetHole(false); segment.AddContour(expanded); segment.SetTexParams( prev_inner, width, 20.0f, heading ); @@ -1105,6 +1096,7 @@ tgpolygon_list tgContour::ExpandToPolygons( const tgContour& subject, double wid segment.SetTexMethod( TG_TEX_BY_TPS_CLIPU, -1.0, 0.0, 1.0, 0.0 ); result.push_back( segment ); + // BUG??: value will never be utilized last_end_v = 1.0f - (fmod( (double)(dist - last_end_v), (double)1.0f )); } diff --git a/src/Lib/terragear/tg_nodes.cxx b/src/Lib/terragear/tg_nodes.cxx index ab66041e..b855599f 100644 --- a/src/Lib/terragear/tg_nodes.cxx +++ b/src/Lib/terragear/tg_nodes.cxx @@ -148,7 +148,7 @@ bool TGNodes::get_geod_inside( const SGGeod& min, const SGGeod& max, std::vector tg_kd_tree.search(std::back_inserter( result ), exact_bb); // and convert the tuples back into SGGeod - for ( it = result.begin(); it != result.end(); it++ ) { + for ( it = result.begin(); it != result.end(); ++it ) { points.push_back( SGGeod::fromDegM( boost::get<0>(*it).x(), boost::get<0>(*it).y(), boost::get<1>(*it) ) ); } @@ -178,7 +178,7 @@ bool TGNodes::get_nodes_inside( const SGGeod& min, const SGGeod& max, std::vecto tg_kd_tree.search(std::back_inserter( result ), exact_bb); // and convert the tuples back into SGGeod - for ( it = result.begin(); it != result.end(); it++ ) { + for ( it = result.begin(); it != result.end(); ++it ) { points.push_back( boost::get<2>(*it) ); } @@ -217,7 +217,7 @@ bool TGNodes::get_geod_edge( const SGBucket& b, std::vector& north, std: exact_bb = Fuzzy_bb(ll, ur); result.clear(); tg_kd_tree.search(std::back_inserter( result ), exact_bb); - for ( it = result.begin(); it != result.end(); it++ ) { + for ( it = result.begin(); it != result.end(); ++it ) { north.push_back( SGGeod::fromDegM( boost::get<0>(*it).x(), boost::get<0>(*it).y(), boost::get<1>(*it) ) ); } @@ -228,7 +228,7 @@ bool TGNodes::get_geod_edge( const SGBucket& b, std::vector& north, std: result.clear(); tg_kd_tree.search(std::back_inserter( result ), exact_bb); - for ( it = result.begin(); it != result.end(); it++ ) { + for ( it = result.begin(); it != result.end(); ++it ) { south.push_back( SGGeod::fromDegM( boost::get<0>(*it).x(), boost::get<0>(*it).y(), boost::get<1>(*it) ) ); } @@ -239,7 +239,7 @@ bool TGNodes::get_geod_edge( const SGBucket& b, std::vector& north, std: result.clear(); tg_kd_tree.search(std::back_inserter( result ), exact_bb); - for ( it = result.begin(); it != result.end(); it++ ) { + for ( it = result.begin(); it != result.end(); ++it ) { east.push_back( SGGeod::fromDegM( boost::get<0>(*it).x(), boost::get<0>(*it).y(), boost::get<1>(*it) ) ); } @@ -250,7 +250,7 @@ bool TGNodes::get_geod_edge( const SGBucket& b, std::vector& north, std: result.clear(); tg_kd_tree.search(std::back_inserter( result ), exact_bb); - for ( it = result.begin(); it != result.end(); it++ ) { + for ( it = result.begin(); it != result.end(); ++it ) { west.push_back( SGGeod::fromDegM( boost::get<0>(*it).x(), boost::get<0>(*it).y(), boost::get<1>(*it) ) ); } diff --git a/src/Lib/terragear/tg_polygon.cxx b/src/Lib/terragear/tg_polygon.cxx index 555bbaec..f0dcb874 100644 --- a/src/Lib/terragear/tg_polygon.cxx +++ b/src/Lib/terragear/tg_polygon.cxx @@ -211,8 +211,6 @@ void tgPolygon::Texture( void ) { SGGeod p; SGVec2f t; - double x, y; - float tx, ty; SG_LOG(SG_GENERAL, SG_DEBUG, "Texture Poly with material " << material << " method " << tp.method << " tpref " << tp.ref << " heading " << tp.heading ); @@ -272,8 +270,8 @@ void tgPolygon::Texture( void ) // 3. Convert from polar to cartesian coordinates // - x = sin( course * SGD_DEGREES_TO_RADIANS ) * dist; - y = cos( course * SGD_DEGREES_TO_RADIANS ) * dist; + double x = sin( course * SGD_DEGREES_TO_RADIANS ) * dist; + double y = cos( course * SGD_DEGREES_TO_RADIANS ) * dist; SG_LOG(SG_GENERAL, SG_DEBUG, " x = " << x << " y = " << y); // @@ -282,7 +280,7 @@ void tgPolygon::Texture( void ) float tmp; tmp = (float)x / (float)tp.width; - tx = tmp * (float)(tp.maxu - tp.minu) + (float)tp.minu; + float tx = tmp * (float)(tp.maxu - tp.minu) + (float)tp.minu; SG_LOG(SG_GENERAL, SG_DEBUG, " (" << tx << ")"); // clip u? @@ -292,7 +290,7 @@ void tgPolygon::Texture( void ) } tmp = (float)y / (float)tp.length; - ty = tmp * (float)(tp.maxv - tp.minv) + (float)tp.minv; + float ty = tmp * (float)(tp.maxv - tp.minv) + (float)tp.minv; SG_LOG(SG_GENERAL, SG_DEBUG, " (" << ty << ")"); // clip v? diff --git a/src/Lib/terragear/tg_polygon.hxx b/src/Lib/terragear/tg_polygon.hxx index 1cf7cef7..8c3a11a8 100644 --- a/src/Lib/terragear/tg_polygon.hxx +++ b/src/Lib/terragear/tg_polygon.hxx @@ -244,7 +244,9 @@ public: tgPolygon() { preserve3d = false; closed = true; + id = 0; } + ~tgPolygon() { contours.clear(); triangles.clear(); diff --git a/src/Lib/terragear/tg_polygon_clean.cxx b/src/Lib/terragear/tg_polygon_clean.cxx index 68509f74..146029b2 100644 --- a/src/Lib/terragear/tg_polygon_clean.cxx +++ b/src/Lib/terragear/tg_polygon_clean.cxx @@ -213,21 +213,19 @@ void tgPolygon::RemoveSlivers( tgPolygon& subject, tgcontour_list& slivers ) double angle_cutoff = 10.0 * SGD_DEGREES_TO_RADIANS; double area_cutoff = 0.000000001; - double min_angle; - double area; // process contours in reverse order so deleting a contour doesn't // foul up our sequence for ( i = subject.Contours() - 1; i >= 0; --i ) { SG_LOG(SG_GENERAL, SG_DEBUG, "contour " << i ); - contour = subject.GetContour(i); + contour = subject.GetContour(i); SG_LOG(SG_GENERAL, SG_DEBUG, " calc min angle for contour " << i); - min_angle = contour.GetMinimumAngle(); + double min_angle = contour.GetMinimumAngle(); SG_LOG(SG_GENERAL, SG_DEBUG, " min_angle (rad) = " << min_angle ); - area = contour.GetArea(); + double area = contour.GetArea(); SG_LOG(SG_GENERAL, SG_DEBUG, " area = " << area ); if ( ((min_angle < angle_cutoff) && (area < area_cutoff)) || @@ -262,7 +260,6 @@ tgcontour_list tgPolygon::MergeSlivers( tgpolygon_list& polys, tgcontour_list& s tgContour contour; tgcontour_list unmerged; unsigned int original_contours, result_contours; - bool done; for ( unsigned int i = 0; i < sliver_list.size(); i++ ) { sliver = sliver_list[i]; @@ -270,7 +267,7 @@ tgcontour_list tgPolygon::MergeSlivers( tgpolygon_list& polys, tgcontour_list& s sliver.SetHole( false ); - done = false; + bool done = false; // try to merge the slivers with the list of clipped polys for ( unsigned int j = 0; j < polys.size() && !done; j++ ) { diff --git a/src/Lib/terragear/tg_polygon_tesselate.cxx b/src/Lib/terragear/tg_polygon_tesselate.cxx index 9cc29021..2295fd46 100644 --- a/src/Lib/terragear/tg_polygon_tesselate.cxx +++ b/src/Lib/terragear/tg_polygon_tesselate.cxx @@ -13,15 +13,18 @@ #include "tg_polygon.hxx" #include "tg_misc.hxx" -/* determining if a face is within the reulting poly */ +/* determining if a face is within the resulting poly */ struct FaceInfo2 { - FaceInfo2() {} - int nesting_level; + FaceInfo2() { + nesting_level = 0; + } - bool in_domain(){ - return nesting_level%2 == 1; - } + int nesting_level; + + bool in_domain() { + return nesting_level % 2 == 1; + } }; typedef CGAL::Exact_predicates_exact_constructions_kernel K; diff --git a/src/Lib/terragear/tg_shapefile.cxx b/src/Lib/terragear/tg_shapefile.cxx index 932a3cf4..b8356e03 100644 --- a/src/Lib/terragear/tg_shapefile.cxx +++ b/src/Lib/terragear/tg_shapefile.cxx @@ -116,7 +116,7 @@ void tgShapefile::FromClipper( const ClipperLib::Paths& subject, const std::stri OGRPolygon* polygon = new OGRPolygon(); SG_LOG(SG_GENERAL, SG_DEBUG, "subject has " << subject.size() << " contours "); - for ( unsigned int i = 0; i < subject.size(); i++ ) { + for ( unsigned int i = 0; i < subject.size(); ++i ) { ClipperLib::Path const& contour = subject[i]; if (contour.size() < 3) { @@ -146,7 +146,8 @@ void tgShapefile::FromClipper( const ClipperLib::Paths& subject, const std::stri feature->SetField("ID", description.c_str()); feature->SetGeometry(polygon); - if( l_id->CreateFeature( feature ) != OGRERR_NONE ) + + if ( l_id->CreateFeature( feature ) != OGRERR_NONE ) { SG_LOG(SG_GENERAL, SG_ALERT, "Failed to create feature in shapefile"); } @@ -155,9 +156,7 @@ void tgShapefile::FromClipper( const ClipperLib::Paths& subject, const std::stri } // close after each write - if ( ds_id >= 0 ) { - ds_id = tgShapefile::CloseDatasource( ds_id ); - } + tgShapefile::CloseDatasource( ds_id ); } void tgShapefile::FromContour( const tgContour& subject, const std::string& datasource, const std::string& layer, const std::string& description ) @@ -201,7 +200,7 @@ void tgShapefile::FromContour( const tgContour& subject, const std::string& data } // close after each write - ds_id = tgShapefile::CloseDatasource( ds_id ); + tgShapefile::CloseDatasource( ds_id ); } void tgShapefile::FromTriangles( const tgPolygon& subject, const std::string& datasource, const std::string& layer, const std::string& description ) @@ -241,7 +240,7 @@ void tgShapefile::FromTriangles( const tgPolygon& subject, const std::string& da } // close after each write - ds_id = tgShapefile::CloseDatasource( ds_id ); + tgShapefile::CloseDatasource( ds_id ); } void tgShapefile::FromPolygon( const tgPolygon& subject, const std::string& datasource, const std::string& layer, const std::string& description ) @@ -295,7 +294,7 @@ void tgShapefile::FromPolygon( const tgPolygon& subject, const std::string& data } // close after each write - ds_id = tgShapefile::CloseDatasource( ds_id ); + tgShapefile::CloseDatasource( ds_id ); } tgPolygon tgShapefile::ToPolygon( const void* subject ) diff --git a/src/Lib/terragear/tg_surface.cxx b/src/Lib/terragear/tg_surface.cxx index 7a59077d..125f393b 100644 --- a/src/Lib/terragear/tg_surface.cxx +++ b/src/Lib/terragear/tg_surface.cxx @@ -226,10 +226,10 @@ tgSurface::tgSurface( const std::string& path, double average_elev_m, double slope_max, double slope_eps - ) + ) : + _aptBounds(aptBounds) { // Calculate desired size of grid - _aptBounds = aptBounds; _min_deg = _aptBounds.getMin(); _max_deg = _aptBounds.getMax(); _average_elev_m = average_elev_m; diff --git a/src/Lib/terragear/tg_unique_geod.hxx b/src/Lib/terragear/tg_unique_geod.hxx index 97bc9db4..3f14a0a5 100644 --- a/src/Lib/terragear/tg_unique_geod.hxx +++ b/src/Lib/terragear/tg_unique_geod.hxx @@ -27,9 +27,9 @@ class SGGeodIndex { public: - explicit SGGeodIndex( SGGeod g ) { - geod = g; - + explicit SGGeodIndex( SGGeod g ) : + geod(g) + { std::size_t FNV_prime; std::size_t offset_basis; diff --git a/src/Lib/terragear/tg_unique_tgnode.hxx b/src/Lib/terragear/tg_unique_tgnode.hxx index 9255da2d..92268948 100644 --- a/src/Lib/terragear/tg_unique_tgnode.hxx +++ b/src/Lib/terragear/tg_unique_tgnode.hxx @@ -39,8 +39,9 @@ public: // constructor for serialization only } - TGNode( SGGeod p ) { - position = p; + explicit TGNode( SGGeod p ) : + position(p) + { CalcWgs84(); fixed_position = false; // no matter what - don't move x, y, or z (likely a hole around an airport generated ny genapts) @@ -131,9 +132,9 @@ private: class TGNodeIndex { public: - TGNodeIndex( SGGeod g ) { - geod = g; - + explicit TGNodeIndex( SGGeod g ) : + geod(g) + { std::size_t FNV_prime; std::size_t offset_basis; diff --git a/src/Prep/OGRDecode/ogr-decode.cxx b/src/Prep/OGRDecode/ogr-decode.cxx index 6d61e158..3002ad3b 100644 --- a/src/Prep/OGRDecode/ogr-decode.cxx +++ b/src/Prep/OGRDecode/ogr-decode.cxx @@ -135,7 +135,7 @@ void Decoder::processLineString(OGRLineString* poGeometry, const string& area_ty SGGeod p0, p1; double heading, dist, az2; - int i, j, numPoints, numSegs; + int j, numPoints, numSegs; double max_dist; numPoints = poGeometry->getNumPoints(); @@ -154,7 +154,7 @@ void Decoder::processLineString(OGRLineString* poGeometry, const string& area_ty line.AddNode( SGGeodesy::direct( p0, heading, EP_STRETCH ) ); // now add the middle points : if they are too far apart, add intermediate nodes - for ( i=1;igetX(i-1), poGeometry->getY(i-1) ); p1 = SGGeod::fromDeg( poGeometry->getX(i ), poGeometry->getY(i ) ); SGGeodesy::inverse( p0, p1, heading, az2, dist ); @@ -185,7 +185,7 @@ void Decoder::processLineString(OGRLineString* poGeometry, const string& area_ty // make a plygons from the line segments segments = tgContour::ExpandToPolygons( line, width ); - for ( unsigned int i=0; igetNumGeometries();i++) { + for (int i = 0; i < multipt->getNumGeometries(); ++i) { processPoint((OGRPoint*)(multipt->getGeometryRef(i)), area_type_name, width); } break; @@ -325,7 +325,7 @@ void Decoder::run() } OGRMultiLineString* multilines=(OGRMultiLineString*)poGeometry; - for (int i=0;igetNumGeometries();i++) { + for (int i = 0; i < multilines->getNumGeometries(); ++i) { processLineString((OGRLineString*)(multilines->getGeometryRef(i)), area_type_name, width, texture_lines); } break; @@ -338,7 +338,7 @@ void Decoder::run() case wkbMultiPolygon: { SG_LOG( SG_GENERAL, SG_DEBUG, "MultiPolygon feature" ); OGRMultiPolygon* multipoly=(OGRMultiPolygon*)poGeometry; - for (int i=0;igetNumGeometries();i++) { + for (int i = 0; i < multipoly->getNumGeometries(); ++i) { processPolygon((OGRPolygon*)(multipoly->getGeometryRef(i)), area_type_name); } break; @@ -478,7 +478,7 @@ void processLayer(OGRLayer* poLayer, tgChopper& results ) // Now process the workqueue with threads // this just generates all the tgPolygons std::vector> decoders; - for (int i=0; i( poCT, area_type_field, point_width_field, line_width_field, results ); decoder->start(); decoders.push_back( decoder ); @@ -738,7 +738,7 @@ int main( int argc, char **argv ) { processLayer(poLayer, results ); } } else { - for (int i=0;iGetLayerCount();i++) { + for (int i = 0; i < poDS->GetLayerCount(); ++i) { poLayer = poDS->GetLayer(i); assert(poLayer != NULL); diff --git a/src/Prep/TerraFit/terrafit.cc b/src/Prep/TerraFit/terrafit.cc index 59bf89bf..bfd62368 100644 --- a/src/Prep/TerraFit/terrafit.cc +++ b/src/Prep/TerraFit/terrafit.cc @@ -91,9 +91,10 @@ public: } depth=32; } + virtual ~ArrayMap() {} - virtual Terra::real eval(int i, int j) { + virtual Terra::real eval(int i, int j) override { return (Terra::real)array.get_array_elev(i,j); } diff --git a/src/Utils/poly2ogr/poly2ogr.cxx b/src/Utils/poly2ogr/poly2ogr.cxx index febfb3e2..154f14fb 100644 --- a/src/Utils/poly2ogr/poly2ogr.cxx +++ b/src/Utils/poly2ogr/poly2ogr.cxx @@ -53,7 +53,7 @@ typedef std::map LayerMap; const char* format_name="ESRI Shapefile"; bool do_split=false; -OGRDataSource *datasource; +GDALDataset *datasource; OGRLayer *defaultLayer; OGRLayer *pointsLayer=NULL; LayerMap layerMap; @@ -530,7 +530,7 @@ int main(int argc, char** argv) { } const char* dst_datasource = argv[optind++]; - auto datasource = gdalDriver->Create(dst_datasource, 0, 0, 0, GDALDataType::GDT_Unknown, NULL); + datasource = gdalDriver->Create(dst_datasource, 0, 0, 0, GDALDataType::GDT_Unknown, NULL); if (!datasource) { usage(argv[0],std::string("Unable to create datasource:") + dst_datasource); exit(1); From 8fe4a00eea9461f71393eca08b2412357eb2079d Mon Sep 17 00:00:00 2001 From: Scott Giese Date: Fri, 1 Feb 2019 12:54:43 -0600 Subject: [PATCH 24/25] [chop.idx] Make maintenance of the index cross-platform and reliable. --- src/Lib/terragear/tg_chopper.cxx | 83 ++++++++++++++++---------------- src/Lib/terragear/tg_chopper.hxx | 2 +- src/Prep/Cliff/cliff-decode.cxx | 2 +- 3 files changed, 43 insertions(+), 44 deletions(-) diff --git a/src/Lib/terragear/tg_chopper.cxx b/src/Lib/terragear/tg_chopper.cxx index e2d42351..46f436a1 100644 --- a/src/Lib/terragear/tg_chopper.cxx +++ b/src/Lib/terragear/tg_chopper.cxx @@ -141,42 +141,43 @@ void tgChopper::Add( const tgPolygon& subject, const std::string& type ) } } -long int tgChopper::GenerateIndex( const std::string& path ) +uint32_t tgChopper::GenerateIndex(const std::string& path) { std::string index_file = path + "/chop.idx"; - long int index = 0; + uint32_t index = 0; //Open or create the named mutex boost::interprocess::named_mutex mutex(boost::interprocess::open_or_create, "tgChopper_index2"); { boost::interprocess::scoped_lock lock(mutex); - /* first try to read the file */ - FILE *fp = fopen( index_file.c_str(), "r+" ); - if ( fp == NULL ) { - /* doesn't exist - create it */ - fp = fopen( index_file.c_str(), "w" ); - if ( fp == NULL ) { - SG_LOG(SG_GENERAL, SG_ALERT, "Error cannot open Index file " << index_file << " for writing"); - boost::interprocess::named_mutex::remove("tgChopper_index2"); - exit( 0 ); - } - } else { - if ( fread( (void*)&index, sizeof(long int), 1, fp ) != 1 ) - { + // first, read the current index + FILE* fp = fopen(index_file.c_str(), "r"); + if (fp != NULL) { + if (fread((void*)&index, sizeof(uint32_t), 1, fp) != 1) { SG_LOG(SG_GENERAL, SG_ALERT, "Error reading Index file " << index_file << " abort"); - fclose( fp ); + fclose(fp); + boost::interprocess::named_mutex::remove("tgChopper_index2"); exit(0); } - rewind( fp ); + fclose(fp); } - index++; - fwrite( (void*)&index, sizeof(long int), 1, fp ); + // overwrite the existing file - or create if it doesn't already exist + fp = fopen(index_file.c_str(), "w"); + if (fp == NULL) { + SG_LOG(SG_GENERAL, SG_ALERT, "Error cannot open Index file " << index_file << " for writing"); - fclose( fp ); + boost::interprocess::named_mutex::remove("tgChopper_index2"); + exit(0); + } + + ++index; + fwrite((void*)&index, sizeof(uint32_t), 1, fp); + + fclose(fp); } boost::interprocess::named_mutex::remove("tgChopper_index2"); @@ -184,53 +185,51 @@ long int tgChopper::GenerateIndex( const std::string& path ) return index; } -void tgChopper::Save( bool DebugShapefiles ) +void tgChopper::Save(bool DebugShapefiles) { // traverse the bucket list bucket_polys_map_interator it; char tile_name[16]; - char poly_ext[16]; char layer[32]; char ds_name[64]; - for (it=bp_map.begin(); it != bp_map.end(); ++it) { - SGBucket b( (*it).first ); + for (it = bp_map.begin(); it != bp_map.end(); ++it) { + SGBucket b((*it).first); tgpolygon_list const& polys = (*it).second; - sprintf(ds_name, "./bucket_%s", b.gen_index_str().c_str() ); + sprintf(ds_name, "./bucket_%s", b.gen_index_str().c_str()); std::string path = root_path + "/" + b.gen_base_path(); - sprintf( tile_name, "%ld", b.gen_index() ); + sprintf(tile_name, "%ld", b.gen_index()); std::string polyfile = path + "/" + tile_name; - SGPath sgp( polyfile ); - sgp.create_dir( 0755 ); + SGPath sgp(polyfile); + sgp.create_dir(0755); - long int poly_index = GenerateIndex( path ); - - sprintf( poly_ext, "%ld", poly_index ); - polyfile = polyfile + "." + poly_ext + "." + extra_extension; + uint32_t poly_index = GenerateIndex(path); + char poly_ext[32]; + sprintf(poly_ext, "%u%.25s", poly_index, extra_extension.c_str()); + polyfile = polyfile + "." + poly_ext; gzFile fp; - if ( (fp = gzopen( polyfile.c_str(), "wb9" )) == NULL ) { - SG_LOG( SG_GENERAL, SG_INFO, "ERROR: opening " << polyfile.c_str() << " for writing!" ); + if ((fp = gzopen(polyfile.c_str(), "wb9")) == NULL) { + SG_LOG(SG_GENERAL, SG_INFO, "ERROR: opening " << polyfile.c_str() << " for writing!"); return; } /* Write polys to the file */ - sgWriteUInt( fp, polys.size() ); - for ( unsigned int i=0; i Date: Fri, 1 Feb 2019 14:53:24 -0600 Subject: [PATCH 25/25] [chop.idx] Ensure binary r/w. --- src/Lib/terragear/tg_chopper.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Lib/terragear/tg_chopper.cxx b/src/Lib/terragear/tg_chopper.cxx index 46f436a1..d1758e80 100644 --- a/src/Lib/terragear/tg_chopper.cxx +++ b/src/Lib/terragear/tg_chopper.cxx @@ -152,7 +152,7 @@ uint32_t tgChopper::GenerateIndex(const std::string& path) boost::interprocess::scoped_lock lock(mutex); // first, read the current index - FILE* fp = fopen(index_file.c_str(), "r"); + FILE* fp = fopen(index_file.c_str(), "rb"); if (fp != NULL) { if (fread((void*)&index, sizeof(uint32_t), 1, fp) != 1) { SG_LOG(SG_GENERAL, SG_ALERT, "Error reading Index file " << index_file << " abort"); @@ -166,7 +166,7 @@ uint32_t tgChopper::GenerateIndex(const std::string& path) } // overwrite the existing file - or create if it doesn't already exist - fp = fopen(index_file.c_str(), "w"); + fp = fopen(index_file.c_str(), "wb"); if (fp == NULL) { SG_LOG(SG_GENERAL, SG_ALERT, "Error cannot open Index file " << index_file << " for writing");