[tg-construct] Reduce technical debt
This commit is contained in:
parent
911f7f9d27
commit
ca98d2ef5d
12 changed files with 108 additions and 91 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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("<unnamed>")
|
||||
{
|
||||
sliver_area_priority = 0;
|
||||
};
|
||||
|
||||
int init( const std::string& filename );
|
||||
unsigned int size() const {
|
||||
return area_defs.size();
|
||||
|
|
|
@ -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<std::string> load ) {
|
||||
void TGConstruct::set_paths( const std::string& work, const std::string& share,
|
||||
const std::string& match, const std::string& output,
|
||||
const std::vector<std::string>& 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;
|
||||
|
|
|
@ -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<std::string> load_dirs );
|
||||
void set_paths( const std::string& work, const std::string& share, const std::string& match,
|
||||
const std::string& output, const std::vector<std::string>& load_dirs );
|
||||
void set_options( bool ignore_lm, double n );
|
||||
|
||||
// TODO : REMOVE
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -68,8 +68,7 @@ SGVec3f TGConstruct::calc_normal( double area, const SGVec3d& p1, const SGVec3d&
|
|||
|
||||
void TGConstruct::calc_normals( std::vector<SGGeod>& geod_nodes, std::vector<SGVec3d>& 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<SGGeod>& geod_nodes, std::vector<SGV
|
|||
SGVec3d v2 = wgs84_nodes[ poly.GetTriIdx( tri, 1 ) ];
|
||||
SGVec3d v3 = wgs84_nodes[ poly.GetTriIdx( tri, 2 ) ];
|
||||
|
||||
area = tgTriangle::area( g1, g2, g3 );
|
||||
double area = tgTriangle::area( g1, g2, g3 );
|
||||
normal = calc_normal( area, v1, v2, v3 );
|
||||
|
||||
poly.SetTriFaceArea( tri, area );
|
||||
|
|
|
@ -87,7 +87,7 @@ void TGConstruct::AddCustomObjects( void ) {
|
|||
in.getline(line, 2048);
|
||||
SG_LOG( SG_GENERAL, SG_DEBUG, "line = " << line );
|
||||
|
||||
int result = sscanf( line, "%s %s", token, name );
|
||||
int result = sscanf( line, "%255s %255s", token, name );
|
||||
SG_LOG( SG_GENERAL, SG_DEBUG, "scanf scanned " << result << " tokens" );
|
||||
|
||||
if ( result > 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;
|
||||
}
|
||||
|
|
|
@ -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<count; i++ ) {
|
||||
for ( unsigned int i = 0; i < count; ++i ) {
|
||||
poly.LoadFromGzFile( fp );
|
||||
area = area_defs.get_area_priority( poly.GetFlag() );
|
||||
int area = area_defs.get_area_priority( poly.GetFlag() );
|
||||
material = area_defs.get_area_name( area );
|
||||
bool isRoad = area_defs.is_road_area( area );
|
||||
|
||||
|
@ -212,11 +211,10 @@ bool TGConstruct::CheckMatchingNode( SGGeod& node, bool road, bool fixed )
|
|||
SGGeod TGConstruct::GetNearestNodeLongitude( const SGGeod& node, const std::vector<SGGeod>& selection )
|
||||
{
|
||||
double min_dist = std::numeric_limits<double>::infinity();
|
||||
double cur_dist;
|
||||
unsigned int min_idx = 0;
|
||||
|
||||
for ( unsigned int i=0; i<selection.size(); i++ ) {
|
||||
cur_dist = fabs( node.getLongitudeDeg() - selection[i].getLongitudeDeg() );
|
||||
for ( unsigned int i = 0; i < selection.size(); ++i ) {
|
||||
double cur_dist = fabs( node.getLongitudeDeg() - selection[i].getLongitudeDeg() );
|
||||
if ( cur_dist < min_dist ) {
|
||||
min_dist = cur_dist;
|
||||
min_idx = i;
|
||||
|
@ -229,11 +227,10 @@ SGGeod TGConstruct::GetNearestNodeLongitude( const SGGeod& node, const std::vect
|
|||
SGGeod TGConstruct::GetNearestNodeLatitude( const SGGeod& node, const std::vector<SGGeod>& selection )
|
||||
{
|
||||
double min_dist = std::numeric_limits<double>::infinity();
|
||||
double cur_dist;
|
||||
unsigned int min_idx = 0;
|
||||
|
||||
for ( unsigned int i=0; i<selection.size(); i++ ) {
|
||||
cur_dist = fabs( node.getLatitudeDeg() - selection[i].getLatitudeDeg() );
|
||||
for ( unsigned int i = 0; i < selection.size(); ++i ) {
|
||||
double cur_dist = fabs( node.getLatitudeDeg() - selection[i].getLatitudeDeg() );
|
||||
if ( cur_dist < min_dist ) {
|
||||
min_dist = cur_dist;
|
||||
min_idx = i;
|
||||
|
|
|
@ -43,7 +43,7 @@ void TGConstruct::TesselatePolys( void )
|
|||
|
||||
if ( IsDebugShape( poly.GetId() ) ) {
|
||||
char layer[32];
|
||||
sprintf(layer, "pretess_%d_%d", area, p );
|
||||
sprintf(layer, "pretess_%u_%u", area, p );
|
||||
tgShapefile::FromPolygon( poly, ds_name, layer, "poly" );
|
||||
}
|
||||
|
||||
|
|
|
@ -66,12 +66,11 @@ void TGLandclass::LoadFromGzFile(gzFile& fp)
|
|||
|
||||
std::ostream& operator<< ( std::ostream& out, const TGLandclass& lc )
|
||||
{
|
||||
unsigned int count;
|
||||
tgPolygon poly;
|
||||
|
||||
// Save all landclass shapes
|
||||
for (unsigned int i=0; i<lc.polys.size(); i++) {
|
||||
count = lc.polys[i].size();
|
||||
unsigned int count = lc.polys[i].size();
|
||||
out << count << "\n";
|
||||
for (unsigned int j=0; j<count; j++) {
|
||||
out << lc.polys[i][j] << " ";
|
||||
|
@ -84,14 +83,14 @@ std::ostream& operator<< ( std::ostream& out, const TGLandclass& lc )
|
|||
|
||||
void TGLandclass::SaveToGzFile(gzFile& fp)
|
||||
{
|
||||
int i, j, num_layers, num_polys;
|
||||
int i, j, num_layers;
|
||||
tgPolygon shape;
|
||||
|
||||
// Save all landclass shapes
|
||||
num_layers = polys.size();
|
||||
sgWriteInt( fp, num_layers );
|
||||
for (i=0; i<num_layers; i++) {
|
||||
num_polys = polys[i].size();
|
||||
int num_polys = polys[i].size();
|
||||
sgWriteInt( fp, num_polys );
|
||||
|
||||
for (j=0; j<num_polys; j++) {
|
||||
|
|
|
@ -140,8 +140,7 @@ int make_socket (char *host, unsigned short int port) {
|
|||
|
||||
// connect to the server and get the next task
|
||||
long int get_next_task( const string& host, int port, long int last_tile ) {
|
||||
long int tile;
|
||||
int sock, len;
|
||||
int sock;
|
||||
fd_set ready;
|
||||
char message[MAXBUF];
|
||||
|
||||
|
@ -172,17 +171,17 @@ long int get_next_task( const string& host, int port, long int last_tile ) {
|
|||
cout << " received reply" << endl;
|
||||
|
||||
if ( FD_ISSET(sock, &ready) ) {
|
||||
/* input coming from socket */
|
||||
if ( (len = read(sock, message, MAXBUF)) > 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);
|
||||
|
|
|
@ -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 ) {
|
||||
|
|
Loading…
Add table
Reference in a new issue