Commit d11a086a authored by Rick Gruber-Riemer's avatar Rick Gruber-Riemer

Moving parameters to global variables on module level

parent 6d69a296
......@@ -23,6 +23,7 @@ import textwrap
import plot
from math import sin, cos, radians
import tools
import parameters
def write_and_count_numvert(out, building, numvert):
"""write numvert tag to .ac, update stats"""
......@@ -203,7 +204,7 @@ def simplify(X, threshold):
return X_simple, p_simple, nodes_lost
def analyse(buildings, static_objects, transform, elev, facades, roofs, params):
def analyse(buildings, static_objects, transform, elev, facades, roofs):
"""analyse all buildings
- calculate area
- location clash with stg static models? drop building
......@@ -217,7 +218,7 @@ def analyse(buildings, static_objects, transform, elev, facades, roofs, params):
#s = get_nodes_from_acs(static_objects.objs, "e013n51/")
if static_objects:
s = get_nodes_from_acs(static_objects, params.prefix+"city")
s = get_nodes_from_acs(static_objects, parameters.PREFIX + "city")
np.savetxt("nodes.dat", s)
# s = np.zeros((len(static_objects.objs), 2))
......@@ -270,7 +271,7 @@ def analyse(buildings, static_objects, transform, elev, facades, roofs, params):
# -- shapely: compute area
# r = LinearRing(list(X))
# p = Polygon(r)
X, p, nodes_simplified = simplify(X, params.building_simplify_tolerance)
X, p, nodes_simplified = simplify(X, parameters.BUILDING_SIMPLIFY_TOLERANCE)
b.area = p.area
b.nnodes_ground = X.shape[0] - 1
# if b.nnodes_ground < 3:
......@@ -334,13 +335,13 @@ def analyse(buildings, static_objects, transform, elev, facades, roofs, params):
b.height = float(b.levels) * level_height
#print "hei", b.height, b.levels
if b.height < params.building_min_height:
if b.height < parameters.BUILDING_MIN_HEIGHT:
print "Skipping small building with height < building_min_height parameter"
tools.stats.skipped_small += 1
continue
# -- skipping buildings smaller than min_area plus a percentage of buildings under a certain area
if b.area < params.building_min_area or (b.area < params.building_reduce_threshhold and random.uniform(0,1) < params.building_reduce_rate):
if b.area < parameters.BUILDING_MIN_AREA or (b.area < parameters.BUILDING_REDUCE_THRESHOLD and random.uniform(0,1) < parameters.BUILDING_REDUCE_RATE):
#if b.area < 20. : # FIXME use limits.area_min:
#print "Skipping small building (area)"
tools.stats.skipped_small += 1
......
......@@ -85,7 +85,6 @@ import tools
import calc_tile
import parameters
from parameters import Parameters
# -- defaults
no_elev = False # -- skip elevation interpolation; FIXME: remove from here and module -> Parameters
......@@ -161,14 +160,13 @@ class Coords(object):
self.lat = lat
class wayExtract(object):
def __init__(self, params):
def __init__(self):
self.buildings = []
self.coords_list = []
self.minlon = 181.
self.maxlon = -181.
self.minlat = 91.
self.maxlat = -91.
self.params = params #from parameters.py -> Parameters
def ways(self, ways):
"""callback method for ways"""
......@@ -182,7 +180,7 @@ class wayExtract(object):
_levels = 0
if 'name' in tags:
_name = tags['name']
if _name in self.params.skiplist:
if _name in parameters.SKIP_LIST:
print "SKIPPING", _name
return
if 'height' in tags:
......@@ -208,7 +206,7 @@ class wayExtract(object):
self.buildings.append(building)
# global stats
if tools.stats.objects == self.params.total_objects: raise ValueError
if tools.stats.objects == parameters.TOTAL_OBJECTS: raise ValueError
tools.stats.objects += 1
if tools.stats.objects % 70 == 0: print tools.stats.objects
......@@ -449,44 +447,42 @@ if __name__ == "__main__":
parser.add_argument("-c", dest="c", action="store_true", help="do not check for overlapping with static objects")
args = parser.parse_args()
if args.filename is None:
params = Parameters()
else:
params = parameters.readFromFile(args.filename)
if args.filename is not None:
parameters.readFromFile(args.filename)
if args.e:
params.no_elev = True
parameters.NO_ELEV = True
if args.c:
params.check_overlap = False
parameters.CHECK_OVERLAP = False
print params.printParams()
print parameters.printParams()
#initialize modules
tools.init()
tex.init()
# prepare translation to local coordinates
cmin = vec2d(params.boundary_west, params.boundary_south)
cmax = vec2d(params.boundary_east, params.boundary_north)
cmin = vec2d(parameters.BOUNDARY_WEST, parameters.BOUNDARY_SOUTH)
cmax = vec2d(parameters.BOUNDARY_EAST, parameters.BOUNDARY_NORTH)
center = (cmin + cmax)*0.5
transform = coordinates.Transformation(center, hdg = 0)
print transform.toGlobal(cmin), transform.toGlobal(cmax)
print "reading elevation data"
elev = tools.Interpolator(params.prefix + os.sep + "elev.xml", fake=params.no_elev) # -- fake skips actually reading the file, speeding up things
elev = tools.Interpolator(parameters.PREFIX + os.sep + "elev.xml", fake=parameters.NO_ELEV) # -- fake skips actually reading the file, speeding up things
print "height at origin", elev(vec2d(0,0))
print "origin at ", transform.toGlobal((0,0))
#tools.write_map('dresden.png', transform, elev, vec2d(minlon, minlat), vec2d(maxlon, maxlat))
if not params.use_pkl:
if not parameters.USE_PKL:
# - parse OSM -> return a list of building objects
way = wayExtract(params)
way = wayExtract()
#p = OSMParser(concurrency=4, ways_callback=way.ways, coords_callback=way.coords )
p = OSMParser(concurrency=1, coords_callback=way.coords)
print "start parsing coords"
p.parse(params.prefix + os.sep + params.osmfile)
p.parse(parameters.PREFIX + os.sep + parameters.OSM_FILE)
print "done parsing"
print "ncords:", len(way.coords_list)
print "bounds:", way.minlon, way.minlat, way.maxlon, way.maxlat
......@@ -494,7 +490,7 @@ if __name__ == "__main__":
p = OSMParser(concurrency=1, ways_callback=way.ways)
print "start parsing ways"
try:
p.parse(params.prefix + os.sep + params.osmfile)
p.parse(parameters.PREFIX + os.sep + parameters.OSM_FILE)
except ValueError:
pass
......@@ -510,8 +506,8 @@ if __name__ == "__main__":
cPickle.dump(buildings, fpickle, -1)
fpickle.close()
else:
fpickle = open(params.prefix + '/buildings.pkl', 'rb')
buildings = cPickle.load(fpickle)[:params.total_objects]
fpickle = open(parameters.PREFIX + '/buildings.pkl', 'rb')
buildings = cPickle.load(fpickle)[:parameters.TOTAL_OBJECTS]
fpickle.close()
print "unpickled %g buildings " % (len(buildings))
tools.stats.objects = len(buildings)
......@@ -520,9 +516,9 @@ if __name__ == "__main__":
# -- create clusters
lmin = vec2d(transform.toLocal(cmin))
lmax = vec2d(transform.toLocal(cmax))
clusters = Clusters(lmin, lmax, params.tile_size)
clusters = Clusters(lmin, lmax, parameters.TILE_SIZE)
if params.check_overlap:
if parameters.CHECK_OVERLAP:
# -- find relevant tiles by checking tile_index at center of each cluster.
# Then read objects from .stgs
stgs = []
......@@ -535,7 +531,7 @@ if __name__ == "__main__":
if stg not in stgs:
stgs.append(stg)
static_objects.extend(stg_io.read(path, stg, params.prefix, params.path_to_scenery))
static_objects.extend(stg_io.read(path, stg, parameters.PREFIX, parameters.PATH_TO_SCENERY))
print "read %i objects from %i tiles" % (len(static_objects), len(stgs)), stgs
else:
......@@ -550,7 +546,7 @@ if __name__ == "__main__":
# - analyze surrounding: similar shaped buildings nearby? will get same texture
# - set building type, roof type etc
# - decide LOD
buildings = building_lib.analyse(buildings, static_objects, transform, elev, tex.facades, tex.roofs, params)
buildings = building_lib.analyse(buildings, static_objects, transform, elev, tex.facades, tex.roofs)
#tools.write_gp(buildings)
......@@ -599,7 +595,7 @@ if __name__ == "__main__":
LOD_lists.append([])
# -- open ac and write header
fname = params.prefix+"city%02i%02i" % (cl.I.x, cl.I.y)
fname = parameters.PREFIX + "city%02i%02i" % (cl.I.x, cl.I.y)
out = open(fname+".ac", "w")
write_ac_header(out, nb + nroofs)
for b in cl.objects:
......
This diff is collapsed.
# List of parameters for osm2city
boundary_east = 9.58
boundary_north = 47.5
boundary_south = 47.48
boundary_west = 9.54
check_overlap = False
elev_raster_x = 10
elev_raster_y = 10
no_elev = False
osmfile = lszr.osm
path_to_scenery = /home/vanosten/bin/fgfs_scenery/customscenery/LSZR
prefix = LSZR
skiplist = Skip1, Skip2
tile_size = 1000
total_objects = 50000
use_pkl = False
building_min_area = 50.0
building_min_height = 3.0
building_reduce_rate = 0.5
building_reduce_threshhold = 200.0
building_simplify_tolerance = 1.0
BOUNDARY_EAST = 9.58
BOUNDARY_NORTH = 47.5
BOUNDARY_SOUTH = 47.48
BOUNDARY_WEST = 9.54
CHECK_OVERLAP = False
ELEV_RASTER_X = 10
ELEV_RASTER_Y = 10
NO_ELEV = False
OSM_FILE = lszr.osm
PATH_TO_SCENERY = /home/vanosten/bin/fgfs_scenery/customscenery/LSZR
PREFIX = LSZR
SKIP_LIST = Skip1, Skip2
TILE_SIZE = 1000
TOTAL_OBJECTS = 50000
USE_PKL = False
BUILDING_BUILDING_MIN_AREA = 50.0
BUILDING_MIN_HEIGHT = 3.0
BUILDING_REDUCE_RATE = 0.5
BUILDING_REDUCE_THRESHOLD = 200.0
BUILDING_SIMPLIFY_TOLERANCE = 1.0
......@@ -17,7 +17,6 @@ import vec2d
import coordinates
import parameters
from parameters import Parameters
class Interpolator(object):
"""load elevation data from file, interpolate"""
......@@ -74,16 +73,16 @@ class Interpolator(object):
self.h += h
def raster_glob(params):
cmin = vec2d.vec2d(params.boundary_west, params.boundary_south)
cmax = vec2d.vec2d(params.boundary_east, params.boundary_north)
def raster_glob():
cmin = vec2d.vec2d(parameters.BOUNDARY_WEST, parameters.BOUNDARY_SOUTH)
cmax = vec2d.vec2d(parameters.BOUNDARY_EAST, parameters.BOUNDARY_NORTH)
center = (cmin + cmax) * 0.5
transform = coordinates.Transformation((center.x, center.y), hdg = 0)
lmin = vec2d.vec2d(transform.toLocal(cmin.__iter__()))
lmax = vec2d.vec2d(transform.toLocal(cmax.__iter__()))
delta = (lmax - lmin)*0.5
print "Distance from middle to boundary in meters (x, y):", delta
raster(transform, "elev.in", -delta.x, -delta.y, 2*delta.x, 2*delta.y, params.elev_raster_x, params.elev_raster_y)
raster(transform, "elev.in", -delta.x, -delta.y, 2*delta.x, 2*delta.y, parameters.ELEV_RASTER_X, parameters.ELEV_RASTER_Y)
def raster(transform, fname, x0, y0, size_x=1000, size_y=1000, step_x=5, step_y=5):
# --- need $FGDATA/Nasal/elev.nas and elev.in
......@@ -242,10 +241,8 @@ if __name__ == "__main__":
help="read parameters from FILE (e.g. params.ini)", metavar="FILE")
args = parser.parse_args()
if args.filename is None:
params = Parameters()
else:
params = parameters.readFromFile(args.filename)
print params.printParams()
raster_glob(params)
if args.filename is not None:
parameters.readFromFile(args.filename)
print parameters.printParams()
raster_glob()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment