1
0
Fork 0

Reduce debt. Eliminate shadow variables.

This commit is contained in:
Scott Giese 2019-01-30 20:14:29 -06:00
parent 488b69c63f
commit f88863e4c2
15 changed files with 118 additions and 90 deletions

View file

@ -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 )

View file

@ -51,7 +51,7 @@ static void usage( const string name ) {
SG_LOG(SG_GENERAL, SG_ALERT, " --work-dir=<directory>");
SG_LOG(SG_GENERAL, SG_ALERT, " --share-dir=<directory>");
SG_LOG(SG_GENERAL, SG_ALERT, " --match-dir=<directory>");
SG_LOG(SG_GENERAL, SG_ALERT, " --cover=<path to land-cover raster>");
// unused: SG_LOG(SG_GENERAL, SG_ALERT, " --cover=<path to land-cover raster>");
SG_LOG(SG_GENERAL, SG_ALERT, " --tile-id=<id>");
SG_LOG(SG_GENERAL, SG_ALERT, " --min-lon=<degrees>");
SG_LOG(SG_GENERAL, SG_ALERT, " --max-lon=<degrees>");
@ -59,7 +59,7 @@ static void usage( const string name ) {
SG_LOG(SG_GENERAL, SG_ALERT, " --max-lat=<degrees>");
SG_LOG(SG_GENERAL, SG_ALERT, " --nudge=<float>");
SG_LOG(SG_GENERAL, SG_ALERT, " --priorities=<filename>");
SG_LOG(SG_GENERAL, SG_ALERT, " --usgs-map=<filename>");
// unused: SG_LOG(SG_GENERAL, SG_ALERT, " --usgs-map=<filename>");
SG_LOG(SG_GENERAL, SG_ALERT, " --ignore-landmass");
SG_LOG(SG_GENERAL, SG_ALERT, " --threads");
SG_LOG(SG_GENERAL, SG_ALERT, " --threads=<numthreads>");
@ -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) {

View file

@ -36,17 +36,20 @@ const double TGConstruct::gSnap = 0.00000001; // approx 1 mm
TGConstruct::TGConstruct( const TGAreaDefinitions& areas, unsigned int s, SGLockedQueue<SGBucket>& 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();
}

View file

@ -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++) {

View file

@ -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();

View file

@ -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<SGGeod> const& corner_list = array.get_corner_list();
for (unsigned int i=0; i<corner_list.size(); i++) {
for (unsigned int i = 0; i < corner_list.size(); ++i) {
nodes.unique_add( corner_list[i] );
}
std::vector<SGGeod> const& fit_list = array.get_fitted_list();
for (unsigned int i=0; i<fit_list.size(); i++) {
for (unsigned int i = 0; i < fit_list.size(); ++i) {
SGGeod node = fit_list[i];
if ( CheckMatchingNode( node, false, false ) ) {
nodes.unique_add( node );

View file

@ -38,15 +38,13 @@ static unsigned int cur_poly_id = 0;
// load all 2d polygons from the specified load disk directories and
// clip against each other to resolve any overlaps
int TGConstruct::LoadLandclassPolys( void ) {
int i;
string base = bucket.gen_base_path();
string poly_path;
int total_polys_read = 0;
tgPolygon poly;
// load 2D polygons from all directories provided
for ( i = 0; i < (int)load_dirs.size(); ++i ) {
for ( int i = 0; i < (int)load_dirs.size(); ++i ) {
poly_path = work_base + "/" + load_dirs[i] + '/' + base;
string tile_str = bucket.gen_index_str();
@ -79,7 +77,7 @@ 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 < count; ++i ) {
for ( unsigned int idx = 0; idx < count; ++idx ) {
poly.LoadFromGzFile( fp );
int area = area_defs.get_area_priority( poly.GetFlag() );
material = area_defs.get_area_name( area );

View file

@ -38,7 +38,7 @@ using std::string;
void TGConstruct::CreateMatchedEdgeFiles( std::vector<SGBucket>& bucketList )
{
// todo - add to work queue
for ( unsigned int i=0; i<bucketList.size(); i++ ) {
for ( unsigned int i = 0; i < bucketList.size(); ++i ) {
SGBucket b = bucketList[i];
nodes.clear();
@ -54,7 +54,7 @@ void TGConstruct::CreateMatchedEdgeFiles( std::vector<SGBucket>& bucketList )
int nCount;
// read in all of the .btg nodes
for ( unsigned int j=0; j<wgs84_nodes.size(); j++ ) {
for ( unsigned int j = 0; j < wgs84_nodes.size(); ++j ) {
SGGeod pos = SGGeod::fromCart( wgs84_nodes[j] + obj.get_gbs_center() );
nodes.unique_add( pos );
}
@ -83,32 +83,32 @@ void TGConstruct::CreateMatchedEdgeFiles( std::vector<SGBucket>& 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<nCount; i++) {
sgWriteGeod( fp, north[i] );
for (int j = 0; j < nCount; ++j) {
sgWriteGeod( fp, north[j] );
}
// south
nCount = south.size();
SG_LOG( SG_GENERAL, SG_DEBUG, "write " << south.size() << " southern nodes to file " << filepath.c_str() );
sgWriteInt( fp, nCount );
for (int i=0; i<nCount; i++) {
sgWriteGeod( fp, south[i] );
for (int j = 0; j < nCount; ++j) {
sgWriteGeod( fp, south[j] );
}
// east
nCount = east.size();
SG_LOG( SG_GENERAL, SG_DEBUG, "write " << east.size() << " eastern nodes to file " << filepath.c_str() );
sgWriteInt( fp, nCount );
for (int i=0; i<nCount; i++) {
sgWriteGeod( fp, east[i] );
for (int j = 0; j < nCount; ++j) {
sgWriteGeod( fp, east[j] );
}
// west
nCount = west.size();
SG_LOG( SG_GENERAL, SG_DEBUG, "write " << west.size() << " western nodes to file " << filepath.c_str() );
sgWriteInt( fp, nCount );
for (int i=0; i<nCount; i++) {
sgWriteGeod( fp, west[i] );
for (int j = 0; j < nCount; ++j) {
sgWriteGeod( fp, west[j] );
}
gzclose(fp);

View file

@ -76,7 +76,6 @@ int make_socket (unsigned short int* port) {
// Give the socket a name.
name.sin_family = AF_INET;
name.sin_addr.s_addr = INADDR_ANY;
name.sin_port = 0 /* htons (port) */;
name.sin_addr.s_addr = htonl (INADDR_ANY);
if (bind (sock, (struct sockaddr *) &name, sizeof (name)) < 0) {

View file

@ -59,6 +59,13 @@ TGDem::TGDem() :
do_data = 0;
cur_col = cur_row = 0;
z_units = 2; // meters
for (int x = 0; x < DEM_SIZE_1; ++x) {
for (int y = 0; y < DEM_SIZE_1; ++y) {
dem_data[x][y] = 0.0;
output_data[x][y] = 0.0;
}
}
}
@ -69,6 +76,13 @@ TGDem::TGDem( const string &file ) :
}
TGDem::~TGDem() {
// printf("class TGDem DEstructor called.\n");
delete [] dem_data;
delete [] output_data;
}
// open a DEM file
bool
TGDem::open ( const string& file ) {
@ -472,12 +486,6 @@ TGDem::write_area( const string& root, SGBucket& b ) {
return true;
}
TGDem::~TGDem() {
// printf("class TGDem DEstructor called.\n");
delete [] dem_data;
delete [] output_data;
}
bool
TGDem::has_non_zero_elev (int start_x, int span_x,

View file

@ -60,6 +60,13 @@ TGDted::TGDted( int _res )
data = new short int[MAX_DTED_SIZE][MAX_DTED_SIZE];
output_data = new short int[MAX_DTED_SIZE][MAX_DTED_SIZE];
for (int x = 0; x < MAX_DTED_SIZE; ++x) {
for (int y = 0; y < MAX_DTED_SIZE; ++y) {
data[x][y] = 0;
output_data[x][y] = 0;
}
}
}
@ -70,6 +77,13 @@ TGDted::TGDted( int _res, const SGPath &file ) :
}
TGDted::~TGDted() {
// printf("class TGSrtmBase DEstructor called.\n");
delete [] data;
delete [] output_data;
}
// open an DTED file
bool
TGDted::open ( const SGPath &f ) {
@ -221,10 +235,3 @@ TGDted::load( ) {
return true;
}
TGDted::~TGDted() {
// printf("class TGSrtmBase DEstructor called.\n");
delete [] data;
delete [] output_data;
}

View file

@ -75,7 +75,7 @@ public:
// load an dted 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]; }
};

View file

@ -59,6 +59,14 @@ TGHgt::TGHgt( int _res )
data = new short int[MAX_HGT_SIZE][MAX_HGT_SIZE];
read_buffer = new short int[MAX_HGT_SIZE];
for (int x = 0; x < MAX_HGT_SIZE; ++x) {
for (int y = 0; y < MAX_HGT_SIZE; ++y) {
data[x][y] = 0;
}
read_buffer[x] = 0;
}
}
@ -69,6 +77,13 @@ TGHgt::TGHgt( int _res, const SGPath &file ) :
}
TGHgt::~TGHgt() {
// printf("class TGSrtmBase DEstructor called.\n");
delete [] data;
delete [] read_buffer;
}
// open an HGT file
bool
TGHgt::open ( const SGPath &f ) {
@ -161,7 +176,6 @@ TGHgt::load( ) {
return false;
}
for ( int row = size - 1; row >= 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;
}

View file

@ -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]; }
};

View file

@ -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);
}
}