Commit 9a657324 authored by Rick Gruber-Riemer's avatar Rick Gruber-Riemer

Dismissing tools.py and making DB batching possibly.

parent faba5ab8
import argparse
import logging
import os
import parameters
import sys
import buildings
import copy_data_stuff
import platforms
import pylons
import roads
import utils.aptdat_io as aptdat_io
import utils.calc_tile as calc_tile
from utils.utilities import BoundaryError, parse_boundary
import utils.coordinates as coordinates
from utils.utilities import BoundaryError, FGElev, parse_boundary
if __name__ == '__main__':
......@@ -60,9 +64,9 @@ if __name__ == '__main__':
tile_boundary_east = full_lon + (lon_index + 1) / num_lon_parts
tile_boundary_south = full_lat + lat_index / num_lat_parts
tile_boundary_north = full_lat + (lat_index + 1) / num_lat_parts
if tile_boundary_east <= boundary_west or tile_boundary_west > boundary_east:
if tile_boundary_east <= boundary_west or tile_boundary_west >= boundary_east:
continue
if tile_boundary_north <= boundary_south or tile_boundary_south > boundary_north:
if tile_boundary_north <= boundary_south or tile_boundary_south >= boundary_north:
continue
if boundary_west > tile_boundary_west:
tile_boundary_west = boundary_west
......@@ -73,9 +77,11 @@ if __name__ == '__main__':
if tile_boundary_north > boundary_north:
tile_boundary_north = boundary_north
tile_index = calc_tile.tile_index((tile_boundary_west,tile_boundary_south))
tile_index = calc_tile.tile_index((tile_boundary_west, tile_boundary_south))
tile_prefix = ("%s%s%s" % (calc_tile.directory_name((full_lon, full_lat)), os.sep, tile_index))
scenery_tiles_list.append([tile_boundary_west, tile_boundary_south,
tile_boundary_east, tile_boundary_north])
tile_boundary_east, tile_boundary_north,
tile_prefix])
logging.info("Added scenery tile {} with boundary {}, {}, {}, {}".format(tile_index,
tile_boundary_west,
tile_boundary_south,
......@@ -88,8 +94,29 @@ if __name__ == '__main__':
parameters.BOUNDARY_SOUTH = scenery_tile[1]
parameters.BOUNDARY_EAST = scenery_tile[2]
parameters.BOUNDARY_NORTH = scenery_tile[3]
parameters.PREFIX = scenery_tile[4]
# prepare shared resources
my_coords_transform = coordinates.Transformation(parameters.get_center_global())
my_fg_elev = FGElev(my_coords_transform)
my_blocked_areas = aptdat_io.get_apt_dat_blocked_areas(my_coords_transform,
parameters.BOUNDARY_WEST, parameters.BOUNDARY_SOUTH,
parameters.BOUNDARY_EAST, parameters.BOUNDARY_NORTH)
# run programs
buildings.process()
roads.process()
pylons.process()
platforms.process()
buildings.process(my_coords_transform, my_fg_elev, my_blocked_areas)
roads.process(my_coords_transform, my_fg_elev, my_blocked_areas)
pylons.process(my_coords_transform, my_fg_elev)
platforms.process(my_coords_transform, my_fg_elev)
# clean-up
my_fg_elev.close()
logging.info("******* Finished one tile *******")
if parameters.USE_NEW_STG_VERBS:
copy_data_stuff.process(False, "Buildings")
copy_data_stuff.process(False, "Roads")
copy_data_stuff.process(False, "Pylons")
else:
copy_data_stuff.process(False, "Objects")
This diff is collapsed.
This diff is collapsed.
......@@ -15,7 +15,6 @@ import logging
import os
import parameters
import tools
import utils.utilities
from utils.vec2d import Vec2d
from utils.stg_io2 import STGVerbType
......@@ -57,7 +56,6 @@ class ClusterContainer(object):
max_grid_y = int(delta.y // self.size + 1)
self.max_grid = GridIndex(max_grid_x, max_grid_y)
self.__len = self.max_grid.ix * self.max_grid.iy
self.prefix = parameters.PREFIX
self.stg_verb_type = stg_verb_type
logging.info("Generating clusters %s %s", min_point, max_point)
......@@ -103,7 +101,7 @@ class ClusterContainer(object):
for item in each_list:
yield item
def append(self, anchor: Vec2d, obj) -> Cluster:
def append(self, anchor: Vec2d, obj, stats: utils.utilities.Stats) -> Cluster:
"""Finds the cluster within the cluster grid where a given object's anchor point is situated and then
adds the object to that cluster."""
the_cluster = self(anchor)
......@@ -112,13 +110,13 @@ class ClusterContainer(object):
# Local stats
self(anchor).stats.count(obj)
# Global stats
tools.stats.count(obj)
stats.count(obj)
except AttributeError:
pass
return the_cluster
def write_statistics(self, clusters_name: str) -> None:
my_file = open(self.prefix + os.sep + clusters_name + ".dat", "w")
my_file = open(parameters.PREFIX + os.sep + clusters_name + ".dat", "w")
for j in range(self.max_grid.iy):
for i in range(self.max_grid.ix):
cl = self._clusters[i][j]
......
......@@ -13,7 +13,7 @@ import parameters
import utils.utilities as util
def main(copy_fg_data: bool, scenery_type: str) -> None:
def process(copy_fg_data: bool, scenery_type: str) -> None:
scenery_path = parameters.get_output_path()
scenery_path += os.sep + scenery_type
......@@ -75,7 +75,7 @@ if __name__ == "__main__":
parser.add_argument("-f", "--file", dest="filename",
help="Mandatory: read parameters from FILE (e.g. params.ini)", metavar="FILE", required=True)
parser.add_argument("-t", "--type", dest="scenery_type",
help="Mandatory: Scenery type - typically 'Objects', 'Buildings', 'Roads', 'Pylons' ",
help="Mandatory: Scenery type - typically 'Objects', 'Buildings', 'Roads', 'Pylons'",
metavar="STRING", required=False)
parser.add_argument("-a", action="store_true",
help="also copy effects etc. in fgdata to $FG_ROOT", required=False)
......@@ -83,8 +83,8 @@ if __name__ == "__main__":
parameters.read_from_file(args.filename)
if args.scenery_type:
scenery_type = args.scenery_type
my_scenery_type = args.scenery_type
else:
scenery_type = "Objects"
my_scenery_type = "Objects"
main(args.a, scenery_type)
process(args.a, my_scenery_type)
......@@ -36,7 +36,6 @@ In most situations it is enough to call the following command once and then only
/usr/bin/python3 /home/pingu/develop_vcs/osm2city/prepare_textures.py -f LSZS/params.ini
Alternatively `buildings.py` can be called with the ``-a`` option.
Chapter :ref:`Textures <chapter-parameters-textures>` has an overview of how roof and facade textures can be filtered to suit a given scenery's needs by means of parameters.
......
......@@ -12,30 +12,20 @@ import random
import numpy as np
import parameters
import pySkeleton.polygon as polygon
import tools
from utils import utilities
from utils.vec2d import Vec2d
def myskel(out, b, name = "roof", offset_xy = Vec2d(0, 0), offset_z = 0., header = False, max_height = 1e99):
#vertices = [(202.0, 52.0), (400.0, 52.0), (400.0, 153.0), (202.0, 152.0)]
#edges = [(0, 1), (1, 2), (2, 3), (3, 0)]
#speeds = [1.0, 1.0, 1.0, 1.0]
# vertices = [(550.0, 102.0), (550.0, 301.0), (200.0, 303.0), (201.0, 102.0), (501.0, 154.0), (351.0, 152.0), (350.0, 251.0), (498.0, 249.0)]
# edges = [(0, 1), (1, 2), (2, 3), (3, 0), (4, 5), (5, 6), (6, 7), (7, 4)]
# speeds = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
def myskel(out, b, stats: utilities.Stats, offset_xy=Vec2d(0, 0), offset_z=0., header=False, max_height=1e99):
vertices = b.X_outer
no = len(b.X_outer)
edges = [(i, i+1) for i in range(no-1)]
edges.append((no-1, 0))
speeds = [1.] * no
#print "OSMID", b.osm_id
if False and b.osm_id == 34112567:
if False:
vertices = np.array(vertices)
# print "vertices = ", vertices
minx = min(vertices[:, 0])
maxx = max(vertices[:, 0])
......@@ -48,13 +38,8 @@ def myskel(out, b, name = "roof", offset_xy = Vec2d(0, 0), offset_z = 0., header
vertices[:, 0] -= (minx)
vertices[:, 1] -= (miny)
#sc = dx/600.
#vertices /= sc
vertices += 10.
# print "vertices = ", vertices
# print "edges = ", edges
# print "speeds = ", speeds
f = open("a.fp", "w")
f.write("%i\n" % len(vertices))
for v in vertices:
......@@ -65,21 +50,16 @@ def myskel(out, b, name = "roof", offset_xy = Vec2d(0, 0), offset_z = 0., header
f.close()
gp = "try"
tools.write_one_gp(b, gp)
utilities.write_one_gp(b, gp)
os.system("gnuplot %s.gp" % gp)
tools.write_one_gp(b, gp)
utilities.write_one_gp(b, gp)
poly = polygon.Polygon(vertices, edges, speeds)
angle = random.uniform(parameters.BUILDING_SKEL_ROOFS_MIN_ANGLE, parameters.BUILDING_SKEL_ROOFS_MAX_ANGLE)
# print angle
#skeleton = poly.straight_skeleton()
# print "skel", skeleton
roof_mesh = poly.roof_3D(angle * 3.1415 / 180.)
s = roof_mesh.ac3d_string(b, offset_xy, offset_z, header)
# -- for some reason, roof_3d fails at times.
try:
# if True:
poly = polygon.Polygon(vertices, edges, speeds)
if 'roof:angle' in b.tags:
angle = float(b.tags['roof:angle'])
......@@ -87,24 +67,22 @@ def myskel(out, b, name = "roof", offset_xy = Vec2d(0, 0), offset_z = 0., header
angle = random.uniform(parameters.BUILDING_SKEL_ROOFS_MIN_ANGLE, parameters.BUILDING_SKEL_ROOFS_MAX_ANGLE)
while angle > 0:
roof_mesh = poly.roof_3D(angle * 3.1415 / 180.)
#roof.mesh.vertices
# roof.mesh.vertices
roof_height = max([p[2] for p in roof_mesh.vertices])
if roof_height < max_height:
break
#We'll just flatten the roof then instead of loosing it
angle = angle - 5
# We'll just flatten the roof then instead of loosing it
angle -= 5
if roof_height > max_height:
logging.warning("roof too high %g > %g" % (roof_height, max_height))
return False
result = roof_mesh.to_out(out, b, offset_xy, offset_z, header)
except Exception as reason:
# if False:
logging.error("Error while creating 3d roof (OSM_ID %s, %s)" % (b.osm_id, reason))
tools.stats.roof_errors += 1
gp = parameters.PREFIX + os.sep + 'roof-error-%04i' % tools.stats.roof_errors
tools.write_one_gp(b, gp)
#os.system("gnuplot %s.gp" % gp)
stats.roof_errors += 1
gp = parameters.PREFIX + os.sep + 'roof-error-%04i' % stats.roof_errors
utilities.write_one_gp(b, gp)
return False
if False and header:
......@@ -113,7 +91,3 @@ def myskel(out, b, name = "roof", offset_xy = Vec2d(0, 0), offset_z = 0., header
f.close()
return result
if __name__ == "__main__":
myskel(header = True)
......@@ -9,12 +9,9 @@ Script part of osm2city which takes OpenStreetMap data as input and generates da
import argparse
import logging
import math
import os
import sys
import xml.sax
import parameters
import tools
from utils import osmparser, vec2d, coordinates, stg_io2
from utils.utilities import FGElev
......@@ -129,7 +126,6 @@ def main():
parser.add_argument("-f", "--file", dest="filename",
help="read parameters from FILE (e.g. params.ini)", metavar="FILE")
parser.add_argument("-e", dest="e", action="store_true", help="skip elevation interpolation")
parser.add_argument("-u", dest="uninstall", action="store_true", help="uninstall ours from .stg")
parser.add_argument("-l", "--loglevel", help="set loglevel. Valid levels are VERBOSE, DEBUG, INFO, WARNING, ERROR, CRITICAL")
args = parser.parse_args()
if args.filename is not None:
......@@ -137,21 +133,15 @@ def main():
parameters.set_loglevel(args.loglevel) # -- must go after reading params file
if args.e:
parameters.NO_ELEV = True
files_to_remove = None
if args.uninstall:
logging.info("Uninstalling.")
files_to_remove = []
parameters.NO_ELEV = True
# Initializing tools for global/local coordinate transformations
center_global = parameters.get_center_global()
osm_fname = parameters.get_OSM_file_name()
coords_transform = coordinates.Transformation(center_global, hdg=0)
tools.init(coords_transform)
# Reading elevation data
logging.info("Reading ground elevation data might take some time ...")
fg_elev = FGElev(coords_transform, fake=parameters.NO_ELEV)
fg_elev = FGElev(coords_transform)
# Transform to real objects
logging.info("Transforming OSM data to Line and Pylon objects")
......@@ -188,18 +178,6 @@ def main():
print((forest_tree.elevation))
forest_tree.make_stg_entry(stg_manager)
# -- initialize STGManager
if args.uninstall:
for f in files_to_remove:
try:
os.remove(f)
except IOError:
pass
stg_manager.drop_ours()
stg_manager.write()
logging.info("uninstall done.")
sys.exit(0)
stg_manager.write()
fg_elev.close()
......
......@@ -77,6 +77,7 @@ DB_USER_PASSWORD = "n/a" # The password for the DB_USER.
NO_ELEV = False # -- skip elevation probing
FG_ELEV = '"D:/Program Files/FlightGear/bin/Win64/fgelev.exe"'
FG_ELEV_CACHE = True # saves the elevation probing results to a file, so next rerun is faster (but uses disk space!)
PROBE_FOR_WATER = False # only possible with FGElev version after 9th of November 2016 / FG 2016.4.1
USE_NEW_STG_VERBS = False
......@@ -167,9 +168,9 @@ CLUSTER_MIN_OBJECTS = 5 # -- discard cluster if too little objects
# =============================================================================
C2P_PROCESS_POWERLINES = True
C2P_PROCESS_AERIALWAYS = True
C2P_PROCESS_AERIALWAYS = False
C2P_PROCESS_OVERHEAD_LINES = True
C2P_PROCESS_STREETLAMPS = True
C2P_PROCESS_STREETLAMPS = False
# Each powerline and aerialway has segments delimited by pylons. The longer the value the better clustering and
# the better the performance. However due to rounding errors the longer the length per cluster the larger the
......@@ -280,7 +281,7 @@ def get_OSM_file_name():
def get_repl_prefix():
"""FIXME: what does the REGEXP actually mean?"""
"""If the PREFIX contains '/' or '\' characters due to batch processing, then they get replaced with underscore."""
return re.sub('[\/]', '_', PREFIX)
......
......@@ -17,12 +17,10 @@ from typing import List
import numpy as np
import parameters
import shapely.geometry as shg
import tools
from cluster import ClusterContainer
from shapely.geometry.base import CAP_STYLE, JOIN_STYLE
from shapely.geometry.linestring import LineString
from utils import osmparser, coordinates, ac3d, stg_io2
from utils.utilities import FGElev
from utils import osmparser, coordinates, ac3d, stg_io2, utilities
from utils.vec2d import Vec2d
OUR_MAGIC = "osm2piers" # Used in e.g. stg files to mark edits by osm2Piers
......@@ -46,7 +44,7 @@ class Pier(object):
self.nodes = np.array([transform.toLocal((n.lon, n.lat)) for n in self.osm_nodes])
self.anchor = Vec2d(self.nodes[0])
def calc_elevation(self, fg_elev: FGElev) -> None:
def calc_elevation(self, fg_elev: utilities.FGElev) -> None:
"""Calculates the elevation (level above sea) as a minimum of all nodes.
Minimum is taken because there could be residuals from shore in FlightGear scenery.
......@@ -77,12 +75,13 @@ def _process_osm_piers(nodes_dict, ways_dict, my_coord_transformator, clipping_b
return my_piers
def _write_piers(stg_manager, replacement_prefix, clusters):
def _write_piers(stg_manager, replacement_prefix, clusters, coords_transform: coordinates.Transformation,
stats: utilities.Stats):
for cl in clusters:
if len(cl.objects) > 0:
center_tile = Vec2d(tools.transform.toGlobal(cl.center))
center_tile = Vec2d(coords_transform.toGlobal(cl.center))
ac_file_name = "%spiers%02i%02i.ac" % (replacement_prefix, cl.grid_index.ix, cl.grid_index.iy)
ac = ac3d.File(stats=tools.stats)
ac = ac3d.File(stats=stats)
obj = ac.new_object('piers', "Textures/Terrain/asphalt.png")
for pier in cl.objects[:]:
length = len(pier.nodes)
......@@ -99,18 +98,18 @@ def _write_piers(stg_manager, replacement_prefix, clusters):
f.close()
def _write_boats(stg_manager, piers: List[Pier]):
def _write_boats(stg_manager, piers: List[Pier], coords_transform: coordinates.Transformation):
for pier in piers:
length = len(pier.nodes)
if length > 3 \
and pier.nodes[0][0] == pier.nodes[(length - 1)][0] \
and pier.nodes[0][1] == pier.nodes[(length - 1)][1]:
_write_boat_area(pier, stg_manager)
_write_boat_area(pier, stg_manager, coords_transform)
else:
_write_boat_line(pier, stg_manager)
_write_boat_line(pier, stg_manager, coords_transform)
def _write_boat_area(pier, stg_manager):
def _write_boat_area(pier, stg_manager, coords_transform: coordinates.Transformation):
if len(pier.nodes) < 3:
return
# Guess a possible position for realistic boat placement
......@@ -130,13 +129,13 @@ def _write_boat_area(pier, stg_manager):
parallel = segment.parallel_offset(10, 'right')
boat_position = parallel.interpolate(segment.length / 2)
try:
pos_global = tools.transform.toGlobal((boat_position.x, boat_position.y))
pos_global = coords_transform.toGlobal((boat_position.x, boat_position.y))
_write_model(segment.length, stg_manager, pos_global, direction, pier.elevation)
except AttributeError as reason:
logging.error(reason)
def _write_boat_line(pier, stg_manager):
def _write_boat_line(pier, stg_manager, coords_transform: coordinates.Transformation):
line_string = LineString(pier.nodes)
right_line = line_string.parallel_offset(4, 'left', resolution=8, join_style=1, mitre_limit=10.0)
coords = right_line.coords
......@@ -144,7 +143,7 @@ def _write_boat_line(pier, stg_manager):
segment = LineString(coords[i:i + 2])
boat_position = segment.interpolate(segment.length / 2)
try:
pos_global = tools.transform.toGlobal((boat_position.x, boat_position.y))
pos_global = coords_transform.toGlobal((boat_position.x, boat_position.y))
direction = math.degrees(math.atan2(segment.coords[0][0] - segment.coords[1][0],
segment.coords[0][1] - segment.coords[1][1]))
if segment.length > 5:
......@@ -307,16 +306,14 @@ def _write_pier_line(pier, obj, offset):
obj.face(sideface, mat=0)
def process() -> None:
def process(coords_transform: coordinates.Transformation, fg_elev: utilities.FGElev) -> None:
stats = utilities.Stats()
# -- prepare transformation to local coordinates
cmin, cmax = parameters.get_extent_global()
center_global = parameters.get_center_global()
coords_transform = coordinates.Transformation(center_global, hdg=0)
tools.init(coords_transform)
# -- create (empty) clusters
lmin = Vec2d(tools.transform.toLocal(cmin))
lmax = Vec2d(tools.transform.toLocal(cmax))
lmin = Vec2d(coords_transform.toLocal(cmin))
lmax = Vec2d(coords_transform.toLocal(cmax))
clusters = ClusterContainer(lmin, lmax)
if not parameters.USE_DATABASE:
......@@ -337,9 +334,8 @@ def process() -> None:
return
for pier in piers:
clusters.append(pier.anchor, pier)
clusters.append(pier.anchor, pier, stats)
fg_elev = FGElev(coords_transform)
for pier in piers:
pier.calc_elevation(fg_elev)
......@@ -348,14 +344,11 @@ def process() -> None:
replacement_prefix = parameters.get_repl_prefix()
stg_manager = stg_io2.STGManager(path_to_output, SCENERY_TYPE, OUR_MAGIC, replacement_prefix, overwrite=True)
_write_piers(stg_manager, replacement_prefix, clusters)
_write_boats(stg_manager, piers)
_write_piers(stg_manager, replacement_prefix, clusters, coords_transform, stats)
_write_boats(stg_manager, piers, coords_transform)
# -- write stg
stg_manager.write()
fg_elev.close()
logging.info("******* Finished *******")
if __name__ == "__main__":
......@@ -370,4 +363,11 @@ if __name__ == "__main__":
parameters.set_loglevel(args.loglevel) # -- must go after reading params file
parameters.show()
process()
my_coords_transform = coordinates.Transformation(parameters.get_center_global())
my_fg_elev = utilities.FGElev(my_coords_transform)
process(my_coords_transform, my_fg_elev)
my_fg_elev.close()
logging.info("******* Finished *******")
......@@ -16,9 +16,7 @@ import shapely.geometry as shg
from cluster import ClusterContainer
import parameters
import tools
from utils import osmparser, coordinates, ac3d, stg_io2
from utils.utilities import FGElev
from utils import osmparser, coordinates, ac3d, stg_io2, utilities
from utils.vec2d import Vec2d
......@@ -67,12 +65,13 @@ def _process_osm_platform(nodes_dict, ways_dict, my_coord_transformator,
return my_platforms
def _write(fg_elev: FGElev, stg_manager, replacement_prefix, clusters):
def _write(fg_elev: utilities.FGElev, stg_manager, replacement_prefix, clusters,
coords_transform: coordinates.Transformation, stats: utilities.Stats):
for cl in clusters:
if len(cl.objects) > 0:
center_tile = Vec2d(tools.transform.toGlobal(cl.center))
center_tile = Vec2d(coords_transform.toGlobal(cl.center))
ac_file_name = "%splatforms%02i%02i.ac" % (replacement_prefix, cl.grid_index.ix, cl.grid_index.iy)
ac = ac3d.File(stats=tools.stats)
ac = ac3d.File(stats=stats)
obj = ac.new_object('platforms', "Textures/Terrain/asphalt.png")
for platform in cl.objects[:]:
if platform.is_area:
......@@ -88,7 +87,7 @@ def _write(fg_elev: FGElev, stg_manager, replacement_prefix, clusters):
f.close()
def _write_area(platform, fg_elev: FGElev, obj, offset):
def _write_area(platform, fg_elev: utilities.FGElev, obj, offset):
"""Writes a platform mapped as an area"""
linear_ring = shg.LinearRing(platform.nodes)
......@@ -127,7 +126,7 @@ def _write_area(platform, fg_elev: FGElev, obj, offset):
obj.face(sideface, mat=0)
def _write_line(platform, fg_elev: FGElev, obj, offset):
def _write_line(platform, fg_elev: utilities.FGElev, obj, offset):
"""Writes a platform as a area which only is mapped as a line"""
o = obj.next_node_index()
left = platform.line_string.parallel_offset(2, 'left', resolution=8, join_style=1, mitre_limit=10.0)
......@@ -199,16 +198,14 @@ def _write_line(platform, fg_elev: FGElev, obj, offset):
obj.face(sideface, mat=0)
def process() -> None:
def process(coords_transform: coordinates.Transformation, fg_elev: utilities.FGElev) -> None:
stats = utilities.Stats()
# -- prepare transformation to local coordinates
cmin, cmax = parameters.get_extent_global()
center_global = parameters.get_center_global()
coords_transform = coordinates.Transformation(center_global, hdg=0)
tools.init(coords_transform)
# -- create (empty) clusters
lmin = Vec2d(tools.transform.toLocal(cmin))
lmax = Vec2d(tools.transform.toLocal(cmax))
lmin = Vec2d(coords_transform.toLocal(cmin))
lmax = Vec2d(coords_transform.toLocal(cmax))
clusters = ClusterContainer(lmin, lmax)
if not parameters.USE_DATABASE:
......@@ -229,9 +226,7 @@ def process() -> None:
return
for platform in platforms:
clusters.append(platform.anchor, platform)
fg_elev = FGElev(coords_transform, fake=parameters.NO_ELEV)
clusters.append(platform.anchor, platform, stats)
# -- initialize STGManager
path_to_output = parameters.get_output_path()
......@@ -239,13 +234,10 @@ def process() -> None:
stg_manager = stg_io2.STGManager(path_to_output, SCENERY_TYPE, OUR_MAGIC, replacement_prefix,
overwrite=True)
_write(fg_elev, stg_manager, replacement_prefix, clusters)
_write(fg_elev, stg_manager, replacement_prefix, clusters, coords_transform, stats)
# -- write stg
stg_manager.write()
fg_elev.close()
logging.info("******* Finished *******")
if __name__ == "__main__":
......@@ -260,4 +252,11 @@ if __name__ == "__main__":
parameters.set_loglevel(args.loglevel) # -- must go after reading params file
parameters.show()
process()
my_coords_transform = coordinates.Transformation(parameters.get_center_global())
my_fg_elev = utilities.FGElev(my_coords_transform)
process(my_coords_transform, my_fg_elev)
my_fg_elev.close()
logging.info("******* Finished *******")
......@@ -27,7 +27,6 @@ from typing import List
import img2np
import numpy as np
import parameters
import tools
import utils.utilities as util
from PIL import Image
from textures import atlas
......@@ -238,15 +237,12 @@ def _dump_all_provides_across_textures(texture_list: List[Texture]) -> None:
logging.debug("4th level provides: %s", provided_features_level_four)
def init(create_atlas: bool=True) -> None:
def init(stats: util.Stats, create_atlas: bool=True) -> None:
logging.debug("textures: init")
global facades
global roofs
global atlas_file_name
if tools.stats is None: # if e.g. manager.init is called from osm2city, then tools.init does not need to be called
tools.init(None)
my_tex_prefix = util.assert_trailing_slash(parameters.PATH_TO_OSM2CITY_DATA)
atlas_file_name = "tex" + os.sep + "atlas_facades"
my_tex_prefix_src = my_tex_prefix + 'tex.src'
......@@ -255,8 +251,8 @@ def init(create_atlas: bool=True) -> None:
pkl_file_name = my_tex_prefix + "tex" + os.sep + "atlas_facades.pkl"
if create_atlas:
facades = FacadeManager('facade')
roofs = RoofManager('roof')
facades = FacadeManager('facade', stats)
roofs = RoofManager('roof', stats)
# read registrations
_append_roofs(roofs, my_tex_prefix_src)
......@@ -295,8 +291,8 @@ def init(create_atlas: bool=True) -> None:
pickle_file.close()
logging.debug(facades)
tools.stats.textures_total = dict((filename, 0) for filename in map((lambda x: x.filename), facades.get_list()))
tools.stats.textures_total.update(dict((filename, 0) for filename in map((lambda x: x.filename), roofs.get_list())))
stats.textures_total = dict((filename, 0) for filename in map((lambda x: x.filename), facades.get_list()))
stats.textures_total.update(dict((filename, 0) for filename in map((lambda x: x.filename), roofs.get_list())))
if __name__ == "__main__":
......@@ -312,4 +308,5 @@ if __name__ == "__main__":
parameters.read_from_file(args.filename)
parameters.set_loglevel(args.loglevel) # -- must go after reading params file
init()
my_stats = util.Stats()
init(my_stats)
......@@ -20,8 +20,6 @@ TODO:
import argparse
import logging
import math
import os
import sys
import time
from typing import Dict, Tuple
import unittest
......@@ -30,9 +28,7 @@ import xml.sax
import parameters
import roads
import shapely.geometry as shg
import tools
from utils import osmparser, vec2d, coordinates, stg_io2
from utils.utilities import FGElev
from utils import osmparser, vec2d, coordinates, stg_io2, utilities
OUR_MAGIC = "osm2pylon" # Used in e.g. stg files to mark edits by osm2pylon
SCENERY_TYPE = "Pylons"
......@@ -286,7 +282,7 @@ class SharedPylon(object):
self.needs_stg_entry = True
self.direction_type = SharedPylon.DIRECTION_TYPE_NORMAL # correction for which direction mast looks at
def calc_global_coordinates(self, fg_elev: FGElev, my_coord_transformator) -> None:
def calc_global_coordinates(self, fg_elev: utilities.FGElev, my_coord_transformator) -> None:
self.lon, self.lat = my_coord_transformator.toGlobal((self.x, self.y))
self.elevation = fg_elev.probe_elev(vec2d.Vec2d(self.lon, self.lat), True)
......@@ -378,7 +374,7 @@ class StreetlampWay(LineWithoutCables):
return False
return True
def calc_and_map(self, fg_elev: FGElev, my_coord_transformator):
def calc_and_map(self, fg_elev: utilities.FGElev, my_coord_transformator):
if self.highway.is_roundabout:
shared_pylon = SharedPylon()
shared_pylon.pylon_model = "Models/StreetFurniture/Streetlamp3.xml"
......@@ -472,15 +468,13 @@ class Line(LineWithoutCables):
catenary_a, segment.length)
segment.cables.append(cable)
def make_cables_ac_xml_stg_entries(self, my_stg_mgr, line_index, wayname, cluster_max_length, my_files_to_remove):
def make_cables_ac_xml_stg_entries(self, my_stg_mgr, line_index, wayname, cluster_max_length):
"""
Writes the stg entries for the cables of this WayLine in a string separated by linebreaks
E.g. OBJECT_STATIC LSZSpylons1901.xml 9.75516 46.4135 2000.48 0
After this it creates the xml-file and ac-file containing the cables.
Each WaySegment is represented as an object group in ac with each cable of the WaySegment as a child
files_to_remove is used if the whole operation is only to uninstall
In order to reduce rounding errors clusters of WaySegments are used instead of a whole WayLine per file.
"""
cluster_segments = list()
......@@ -507,9 +501,6 @@ class Line(LineWithoutCables):
vec2d.Vec2d(start_pylon.lon, start_pylon.lat),
start_pylon.elevation, 90 + angle_difference)
my_files_to_remove.append(path_to_stg + cluster_filename + ".ac")
my_files_to_remove.append(path_to_stg + cluster_filename + ".xml")
ac_file_lines = list()
ac_file_lines.append("AC3Db")
ac_file_lines.append('MATERIAL "cable" rgb 0.3 0.3 0.3 amb 0.3 0.3 0.3 emis 0.0 0.0 0.0 spec 0.3 0.3 0.3 shi 1 trans 0')
......@@ -715,7 +706,7 @@ class RailLine(Line):
self.nodes = [] # RailNodes
self.linear = None # The LineaString of the line