Commit 1f795e5e authored by Rick Gruber-Riemer's avatar Rick Gruber-Riemer

Moved calc_tile and vec2d to utils

parent d8a73657
......@@ -5,15 +5,15 @@ Created on 25.04.2014
"""
import argparse
import logging
import sys
import re
import os
import re
import stat
import sys
from _io import open
import calc_tile
import parameters
import utils.utilities as util
from utils import calc_tile
OSM_FILE_NAME = "data.osm"
......@@ -36,8 +36,8 @@ def _open_file(name, directory):
return open(directory + name, "w")
def _write_to_file(command, file_handle, python_exe, params_out):
file_handle.write(python_exe + ' ' + util.get_osm2city_directory() + os.sep + command)
def _write_to_file(the_command, file_handle, python_exec, params_out):
file_handle.write(python_exec + ' ' + util.get_osm2city_directory() + os.sep + the_command)
file_handle.write(' -f ' + params_out)
if BASH_PARALLEL_PROCESS:
file_handle.write(' &' + os.linesep + 'parallel_wait $max_parallel_process' + os.linesep)
......@@ -47,7 +47,8 @@ def _write_to_file(command, file_handle, python_exe, params_out):
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
parser = argparse.ArgumentParser(description="build-tiles generates a directory structure capable of generating a complete 1 degree lon/lat-areas of scenery")
parser = argparse.ArgumentParser(description="build-tiles generates a directory structure capable of \
generating a complete 1 degree lon/lat-areas of scenery")
parser.add_argument("-t", "--tile", dest="tile_name",
help="The name of the lon/lat-area (e.g. e009n47)", required=True)
parser.add_argument("-f", "--properties", dest="properties",
......@@ -76,7 +77,8 @@ if __name__ == '__main__':
help="Path to specific Python executable",
required=False)
parser.add_argument("-d", dest="osmosis_executable",
help="Use the OSM data as specified in params.ini and split it with Osmosis using the specified path to Osmosis",
help="Use the OSM data as specified in params.ini and split it with Osmosis \
using the specified path to Osmosis",
required=False)
args = parser.parse_args()
......@@ -188,8 +190,10 @@ done
replacement = '\\1 "' + replacement_path + '"'
for line in lines:
line = re.sub('^\s*(PREFIX\s*=)(.*)', replacement, line)
line = re.sub('^\s*(BOUNDARY_EAST\s*=)(.*)', '\\1 %f' % (calc_tile.get_east_lon(lon, lat, dx)), line)
line = re.sub('^\s*(BOUNDARY_WEST\s*=)(.*)', '\\1 %f' % (calc_tile.get_west_lon(lon, lat, dx)), line)
line = re.sub('^\s*(BOUNDARY_EAST\s*=)(.*)', '\\1 %f' % (calc_tile.get_east_lon(lon, lat, dx)),
line)
line = re.sub('^\s*(BOUNDARY_WEST\s*=)(.*)', '\\1 %f' % (calc_tile.get_west_lon(lon, lat, dx)),
line)
line = re.sub('^\s*(BOUNDARY_NORTH\s*=)(.*)', '\\1 %f' % (calc_tile.get_north_lat(lat, dy)), line)
line = re.sub('^\s*(BOUNDARY_SOUTH\s*=)(.*)', '\\1 %f' % (calc_tile.get_south_lat(lat, dy)), line)
line = re.sub('^\s*(OSM_FILE\s*=)(.*)', '\\1 "%s"' % OSM_FILE_NAME, line)
......
......@@ -8,25 +8,23 @@ Created on Thu Feb 28 23:18:08 2013
import copy
import logging
import math
from math import sin, cos, radians, tan, sqrt, pi
import os
import random
import re
import matplotlib.pyplot as plt
import numpy as np
import shapely.geometry as shg
from math import sin, cos, radians, tan, sqrt, pi
import ac3d
import ac3d_fast
import matplotlib.pyplot as plt
import myskeleton
import numpy as np
import parameters
import roofs
import shapely.geometry as shg
import textures.manager as tm
import tools
import utils.utilities as util
from vec2d import vec2d
from utils.vec2d import Vec2d
nb = 0
out = ""
......@@ -53,7 +51,7 @@ class Building(object):
self.longest_edge_len = 0.
self.levels = levels
self.first_node = 0 # index of first node in final OBJECT node list
self.anchor = vec2d(list(outer_ring.coords[0]))
self.anchor = Vec2d(list(outer_ring.coords[0]))
self.facade_texture = None
self.roof_texture = None
self.roof_complex = False
......@@ -89,9 +87,9 @@ class Building(object):
for inner in self.polygon.interiors:
min_r = 1e99
for i, node_i in enumerate(list(inner.coords)[:-1]):
node_i = vec2d(node_i)
node_i = Vec2d(node_i)
for o in outer_nodes_avail:
r = node_i.distance_to(vec2d(self.X_outer[o]))
r = node_i.distance_to(Vec2d(self.X_outer[o]))
if r <= min_r:
closest_i = node_i
min_r = r
......@@ -132,20 +130,20 @@ class Building(object):
# print "inner!", inner_rings
self.polygon = shg.Polygon(outer, inner)
def _set_X(self, the_offset: vec2d) -> None:
def _set_X(self, the_offset: Vec2d) -> None:
self.X = np.array(self.X_outer + self.X_inner)
for i in range(self._nnodes_ground):
self.X[i, 0] -= the_offset.x # -- cluster coordinates. NB: this changes building coordinates!
self.X[i, 1] -= the_offset.y
def set_ground_elev(self, elev, tile_elev, the_offset: vec2d) -> None:
def set_ground_elev(self, elev, tile_elev, the_offset: Vec2d) -> None:
def local_elev(p):
return elev(p + the_offset) - tile_elev
self._set_X(the_offset)
elevs = [local_elev(vec2d(self.X[i])) for i in range(self._nnodes_ground)]
elevs = [local_elev(Vec2d(self.X[i])) for i in range(self._nnodes_ground)]
self.ground_elev_min = min(elevs)
self.ground_elev_max = max(elevs)
......@@ -610,7 +608,7 @@ def analyse(buildings, static_objects, transform, elev, facades, roofs):
# Or is there a shapely equivalent?
# -- skip buildings outside elevation raster
if elev(vec2d(Xo[0])) == -9999:
if elev(Vec2d(Xo[0])) == -9999:
logging.debug("-9999")
tools.stats.skipped_no_elev += 1
continue
......@@ -1067,10 +1065,10 @@ def _write_ground(out, b, elev): # not used anywhere
# bla
offset_z = 0.05
z0 = elev(vec2d(x0, y0)) + offset_z
z1 = elev(vec2d(x1, y0)) + offset_z
z2 = elev(vec2d(x1, y1)) + offset_z
z3 = elev(vec2d(x0, y1)) + offset_z
z0 = elev(Vec2d(x0, y0)) + offset_z
z1 = elev(Vec2d(x1, y0)) + offset_z
z2 = elev(Vec2d(x1, y1)) + offset_z
z3 = elev(Vec2d(x0, y1)) + offset_z
o = out.next_node_index()
out.node(-y0, z0, -x0)
......
......@@ -64,7 +64,6 @@ import textwrap
from typing import List
import building_lib
import calc_tile
import cluster
import coordinates
import numpy as np
......@@ -75,9 +74,9 @@ import stg_io2
import textures.manager as tex_manager
import tools
import troubleshoot
from utils import osmparser
import utils.utilities as util
import vec2d as v
import utils.vec2d as v
from utils import osmparser, calc_tile
buildings = [] # -- master list, holds all buildings
OUR_MAGIC = "osm2city" # Used in e.g. stg files to mark edits by osm2city
......@@ -353,15 +352,15 @@ class Buildings(object):
if node.lat < self.minlat:
self.minlat = node.lat
# cmin = vec2d(self.minlon, self.minlat)
# cmax = vec2d(self.maxlon, self.maxlat)
# cmin = Vec2d(self.minlon, self.minlat)
# cmax = Vec2d(self.maxlon, self.maxlat)
# logging.info("min/max coord" + str(cmin) + " " + str(cmax))
# -----------------------------------------------------------------------------
# -- write xml
def write_xml(path: str, file_name: str, buildings: List[building_lib.Building], the_offset: v.vec2d) -> None:
def write_xml(path: str, file_name: str, buildings: List[building_lib.Building], the_offset: v.Vec2d) -> None:
# -- LOD animation
xml = open(path + file_name + ".xml", "w")
xml.write("""<?xml version="1.0"?>\n<PropertyList>\n""")
......@@ -504,7 +503,7 @@ if __name__ == "__main__":
logging.info("reading elevation data")
elev = tools.get_interpolator(fake=parameters.NO_ELEV)
logging.debug("height at origin" + str(elev(v.vec2d(0, 0))))
logging.debug("height at origin" + str(elev(v.Vec2d(0, 0))))
logging.debug("origin at " + str(tools.transform.toGlobal((0, 0))))
# -- now read OSM data. Either parse OSM xml, or read a previously cached .pkl file
......@@ -537,8 +536,8 @@ if __name__ == "__main__":
# tools.stats.print_summary()
buildings.make_way_buildings()
buildings._get_min_max_coords()
cmin = v.vec2d(buildings.minlon, buildings.minlat)
cmax = v.vec2d(buildings.maxlon, buildings.maxlat)
cmin = v.Vec2d(buildings.minlon, buildings.minlat)
cmax = v.Vec2d(buildings.maxlon, buildings.maxlat)
logging.info("min/max " + str(cmin) + " " + str(cmax))
# Search parents
......@@ -1011,8 +1010,8 @@ if __name__ == "__main__":
# buildings = new_buildings
# -- create (empty) clusters
lmin = v.vec2d(tools.transform.toLocal(cmin))
lmax = v.vec2d(tools.transform.toLocal(cmax))
lmin = v.Vec2d(tools.transform.toLocal(cmin))
lmax = v.Vec2d(tools.transform.toLocal(cmax))
clusters = cluster.Clusters(lmin, lmax, parameters.TILE_SIZE, parameters.PREFIX)
if parameters.OVERLAP_CHECK:
......@@ -1052,7 +1051,7 @@ if __name__ == "__main__":
# print node
# lon, lat = tools.transform.toGlobal(node)
# e = elev((lon,lat), is_global=True)
# stg_manager.add_object_shared("Models/Communications/cell-monopole1-75m.xml", vec2d(lon, lat), e, 0)
# stg_manager.add_object_shared("Models/Communications/cell-monopole1-75m.xml", Vec2d(lon, lat), e, 0)
#tools.write_gp(buildings)
......@@ -1082,7 +1081,7 @@ if __name__ == "__main__":
nroofs += 2 # we have 2 different LOD models for each roof
tile_elev = elev(cl.center)
center_global = v.vec2d(tools.transform.toGlobal(cl.center))
center_global = v.Vec2d(tools.transform.toGlobal(cl.center))
if tile_elev == -9999:
logging.warning("Skipping tile elev = -9999 at lat %.3f and lon %.3f", center_global.lat, center_global.lon)
continue # skip tile with improper elev
......
......@@ -17,9 +17,8 @@ import logging
import os
import numpy as np
import tools
from vec2d import vec2d
from utils.vec2d import Vec2d
class Cluster(object):
......@@ -50,7 +49,7 @@ class Clusters(object):
self.prefix = prefix
logging.info("Generating clusters %s %s", min, max)
self._clusters = [[self.init_cluster(vec2d(i, j))
self._clusters = [[self.init_cluster(Vec2d(i, j))
for j in range(self.n.y)] for i in range(self.n.x)]
# for i in range(self.nx * self.ny):
# self.list.append([])
......@@ -119,8 +118,8 @@ class Clusters(object):
for i in range(len(X.ravel())):
x = X.ravel()[i]
y = Y.ravel()[i]
p = vec2d(x,y)
r = vec2d(np.random.uniform(0,1,2))
p = Vec2d(x,y)
r = Vec2d(np.random.uniform(0,1,2))
out = p.sign() * (r < abs(p)).int()
f = out.x + out.y*3
x += out.x
......@@ -130,7 +129,7 @@ class Clusters(object):
self._clusters[I.x][I.y]
"""
print("clusters", self.n)
newclusters = [[self.init_cluster(vec2d(i, j)) for j in range(self.n.y)] for i in range(self.n.x)]
newclusters = [[self.init_cluster(Vec2d(i, j)) for j in range(self.n.y)] for i in range(self.n.x)]
f = open(self.prefix + os.sep + "reclustered.dat", "w")
for j in range(self.n.y):
......@@ -138,7 +137,7 @@ self._clusters[I.x][I.y]
cluster = self._clusters[i][j]
for b in cluster.objects:
norm_coord = (b.anchor - cluster.center) // self.size
rnd = vec2d(np.random.uniform(0, 1, 2))
rnd = Vec2d(np.random.uniform(0, 1, 2))
out = norm_coord.sign() * (rnd < abs(norm_coord)).int()
ni = int(i + out.x)
nj = int(j + out.y)
......@@ -192,8 +191,8 @@ if __name__ == "__main__":
for i in range(len(X.ravel())):
x = X.ravel()[i]
y = Y.ravel()[i]
p = vec2d(x, y)
r = vec2d(np.random.uniform(0, 1, 2))
p = Vec2d(x, y)
r = Vec2d(np.random.uniform(0, 1, 2))
out = p.sign() * (r < abs(p)).int()
f = out.x + out.y*3
x += out.x
......
......@@ -5,12 +5,10 @@ import math
import matplotlib.pyplot as plt
import numpy as np
import shapely.geometry as shg
import parameters
import shapely.geometry as shg
import textures.road
from vec2d import vec2d
from utils.vec2d import Vec2d
class LinearObject(object):
......@@ -196,7 +194,7 @@ class LinearObject(object):
Return nodes_list
"""
# if not offset:
# offset = vec2d(0,0)
# offset = Vec2d(0,0)
# if joint0 == 1D:
# if neighbour0.already_written:
# left_coords = left.coords[1:]
......@@ -548,7 +546,7 @@ class LinearObject(object):
# -- write OSM_ID label
if 0:
anchor = self.edge[0].coords[len_left/2]
e = elev(vec2d(anchor[0], anchor[1])) + self.AGL
e = elev(Vec2d(anchor[0], anchor[1])) + self.AGL
ac.add_label(' ' + str(self.osm_id), -anchor[1], e+4.8, -anchor[0], scale=2)
# -- write nodes
......@@ -556,14 +554,14 @@ class LinearObject(object):
ni = 0
ofs_l = obj.next_node_index()
for p in self.edge[0].coords:
e = elev(vec2d(p[0], p[1])) + self.AGL
e = elev(Vec2d(p[0], p[1])) + self.AGL
obj.node(-p[1], e, -p[0])
# ac.add_label('l'+str(ni), -p[1], e+5, -p[0], scale=5)
ni += 1
ofs_r = obj.next_node_index()
for p in self.edge[1].coords[::-1]:
e = elev(vec2d(p[0], p[1])) + self.AGL
e = elev(Vec2d(p[0], p[1])) + self.AGL
obj.node(-p[1], e, -p[0])
# ac.add_label('r'+str(ni), -p[1], e+5, -p[0], scale=5)
ni += 1
......
......@@ -5,19 +5,18 @@ Created on Fri Sep 6 19:37:03 2013
@author: tom
"""
import pySkeleton.polygon as polygon
from vec2d import vec2d
import logging
import os
import random
import textwrap
import numpy as np
import tools
import os
import logging
import parameters
import pySkeleton.polygon as polygon
import tools
from utils.vec2d import Vec2d
def myskel(out, b, name = "roof", offset_xy = vec2d(0, 0), offset_z = 0., header = False, max_height = 1e99):
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]
......
......@@ -5,10 +5,10 @@ Created on 15.06.2014
"""
import logging
import vec2d
from builtins import max
from utils import vec2d
class ObjectList(object):
'''
......@@ -40,8 +40,8 @@ class ObjectList(object):
self.minlat = min(self.minlat, node.lat)
self.min_max_scanned = True
cmin = vec2d.vec2d(self.minlon, self.minlat)
cmax = vec2d.vec2d(self.maxlon, self.maxlat)
cmin = vec2d.Vec2d(self.minlon, self.minlat)
cmax = vec2d.Vec2d(self.maxlon, self.maxlat)
logging.info("min/max " + str(cmin) + " " + str(cmax))
def __len__(self):
......
......@@ -17,8 +17,7 @@ import coordinates
import parameters
import stg_io2
import tools
from utils import osmparser
import vec2d
from utils import osmparser, vec2d
OUR_MAGIC = "osm2nature" # Used in e.g. stg files to mark edits by osm2nature.py
......@@ -37,14 +36,14 @@ class TreeNode(object):
def calc_global_coordinates(self, my_elev_interpolator, my_coord_transformator):
self.lon, self.lat = my_coord_transformator.toGlobal((self.x, self.y))
self.elevation = my_elev_interpolator(vec2d.vec2d(self.lon, self.lat), True)
self.elevation = my_elev_interpolator(vec2d.Vec2d(self.lon, self.lat), True)
def make_stg_entry(self, my_stg_mgr):
"""
Returns a stg entry for this tree.
E.g. OBJECT_SHARED Models/Airport/ils.xml 5.313108 45.364122 374.49 268.92
"""
my_stg_mgr.add_object_shared(self.tree_model, vec2d.vec2d(self.lon, self.lat)
my_stg_mgr.add_object_shared(self.tree_model, vec2d.Vec2d(self.lon, self.lat)
, self.elevation
, stg_angle(0)) # 90 less because arms are in x-direction in ac-file
......@@ -74,7 +73,7 @@ def process_osm_tree(nodes_dict, ways_dict, my_elev_interpolator, my_coord_trans
my_tree_node.tree_model = "Models/Trees/egkk_woods.xml"
my_tree_node.x, my_tree_node.y = my_coord_transformator.toLocal((my_tree_node.lon, my_tree_node.lat))
my_tree_node.elevation = my_elev_interpolator(vec2d.vec2d(my_tree_node.lon, my_tree_node.lat), True)
my_tree_node.elevation = my_elev_interpolator(vec2d.Vec2d(my_tree_node.lon, my_tree_node.lat), True)
print(("adding entry to trees", my_node.osm_id, " ", my_tree_node.x, " ", my_tree_node.y, " ", my_tree_node.elevation))
my_trees[my_tree_node.osm_id] = my_tree_node
......@@ -95,7 +94,7 @@ def process_osm_forest(nodes_dict, ways_dict, my_elev_interpolator, my_coord_tra
my_tree_node.lat = my_node.lat
my_tree_node.lon = my_node.lon
my_tree_node.x, my_tree_node.y = my_coord_transformator.toLocal((my_tree_node.lon, my_tree_node.lat))
my_tree_node.elevation = my_elev_interpolator(vec2d.vec2d(my_tree_node.lon, my_tree_node.lat), True)
my_tree_node.elevation = my_elev_interpolator(vec2d.Vec2d(my_tree_node.lon, my_tree_node.lat), True)
print(("adding entry to trees", my_tree_node.x, my_tree_node.y, my_tree_node.elevation))
my_trees[my_tree_node.osm_id] = my_tree_node
return my_trees
......
......@@ -17,12 +17,11 @@ import logging
import os
import re
import sys
import types
import traceback
import types
import textures.road
import vec2d as v
from utils import vec2d as v
# default_args_start # DO NOT MODIFY THIS LINE
# -*- coding: utf-8 -*-
......@@ -267,14 +266,14 @@ def get_repl_prefix():
def get_center_global():
cmin = v.vec2d(BOUNDARY_WEST, BOUNDARY_SOUTH)
cmax = v.vec2d(BOUNDARY_EAST, BOUNDARY_NORTH)
cmin = v.Vec2d(BOUNDARY_WEST, BOUNDARY_SOUTH)
cmax = v.Vec2d(BOUNDARY_EAST, BOUNDARY_NORTH)
return (cmin + cmax) * 0.5
def get_extent_global():
cmin = v.vec2d(BOUNDARY_WEST, BOUNDARY_SOUTH)
cmax = v.vec2d(BOUNDARY_EAST, BOUNDARY_NORTH)
cmin = v.Vec2d(BOUNDARY_WEST, BOUNDARY_SOUTH)
cmax = v.Vec2d(BOUNDARY_EAST, BOUNDARY_NORTH)
return cmin, cmax
......
......@@ -12,20 +12,19 @@ import math
import os
from random import randint
import shapely.geometry as shg
from shapely.geometry.base import CAP_STYLE, JOIN_STYLE
from shapely.geometry.linestring import LineString
import ac3d
import coordinates
import numpy as np
import parameters
import shapely.geometry as shg
import stg_io2
import tools
from cluster import Clusters
from objectlist import ObjectList
from shapely.geometry.base import CAP_STYLE, JOIN_STYLE
from shapely.geometry.linestring import LineString
from utils import osmparser
from vec2d import vec2d
from utils.vec2d import Vec2d
OUR_MAGIC = "osm2piers" # Used in e.g. stg files to mark edits by osm2Piers
......@@ -45,7 +44,7 @@ class Pier(object):
if r in nodes_dict:
self.osm_nodes.append(nodes_dict[r])
self.nodes = np.array([transform.toLocal((n.lon, n.lat)) for n in self.osm_nodes])
self.anchor = vec2d(self.nodes[0])
self.anchor = Vec2d(self.nodes[0])
def calc_elevation(self, elev_interpolator):
"""Calculates the elevation (level above sea) as a minimum of all nodes.
......@@ -91,7 +90,7 @@ class Piers(ObjectList):
def write_piers(self, stg_manager, replacement_prefix):
for cl in self.clusters:
if len(cl.objects) > 0:
center_tile = vec2d(tools.transform.toGlobal(cl.center))
center_tile = Vec2d(tools.transform.toGlobal(cl.center))
ac_fname = "%spiers%02i%02i.ac" % (replacement_prefix, cl.I.x, cl.I.y)
ac = ac3d.File(stats=tools.stats)
obj = ac.new_object('piers', "Textures/Terrain/asphalt.png")
......@@ -129,7 +128,7 @@ def _write_boat_area(pier, stg_manager):
# Simplyfy
ring = linear_ring.convex_hull.buffer(40, cap_style=CAP_STYLE.square, join_style=JOIN_STYLE.bevel).simplify(20)
for p in ring.exterior.coords:
coord = vec2d(p[0], p[1])
coord = Vec2d(p[0], p[1])
line_coords = [[centroid.x, centroid.y], p]
target_vector = shg.LineString(line_coords)
boat_position = linear_ring.intersection(target_vector)
......@@ -202,7 +201,7 @@ def _write_model(length, stg_manager, pos_global, direction, my_elev):
('Models/Maritime/Civilian/FerryBoat1.ac', 70)]
choice = randint(0, len(models) - 1)
model = models[choice]
stg_manager.add_object_shared(model[0], vec2d(pos_global), my_elev, direction + model[1])
stg_manager.add_object_shared(model[0], Vec2d(pos_global), my_elev, direction + model[1])
def _write_pier_area(pier, obj, offset):
......@@ -222,7 +221,7 @@ def _write_pier_area(pier, obj, offset):
for p in pier.nodes:
obj.node(-p[1] + offset.y, e, -p[0] + offset.x)
top_nodes = np.arange(len(pier.nodes))
pier.segment_len = np.array([0] + [vec2d(coord).distance_to(vec2d(linear_ring.coords[i])) for i, coord in enumerate(linear_ring.coords[1:])])
pier.segment_len = np.array([0] + [Vec2d(coord).distance_to(Vec2d(linear_ring.coords[i])) for i, coord in enumerate(linear_ring.coords[1:])])
rd_len = len(linear_ring.coords)
pier.dist = np.zeros((rd_len))
for i in range(1, rd_len):
......@@ -264,7 +263,7 @@ def _write_pier_line(pier, obj, offset):
obj.node(-p[1] + offset.y, e, -p[0] + offset.x)
nodes_l = np.arange(len(left.coords))
nodes_r = np.arange(len(right.coords))
pier.segment_len = np.array([0] + [vec2d(coord).distance_to(vec2d(line_string.coords[i])) for i, coord in enumerate(line_string.coords[1:])])
pier.segment_len = np.array([0] + [Vec2d(coord).distance_to(Vec2d(line_string.coords[i])) for i, coord in enumerate(line_string.coords[1:])])
rd_len = len(line_string.coords)
pier.dist = np.zeros((rd_len))
for i in range(1, rd_len):
......@@ -355,8 +354,8 @@ def main():
tools.init(transform)
# -- create (empty) clusters
lmin = vec2d(tools.transform.toLocal(cmin))
lmax = vec2d(tools.transform.toLocal(cmax))
lmin = Vec2d(tools.transform.toLocal(cmin))
lmax = Vec2d(tools.transform.toLocal(cmax))
clusters = Clusters(lmin, lmax, parameters.TILE_SIZE, parameters.PREFIX)
border = None
......
......@@ -21,7 +21,7 @@ import parameters
import stg_io2
import tools
from utils import osmparser
from vec2d import vec2d
from utils.vec2d import Vec2d
OUR_MAGIC = "osm2platforms" # Used in e.g. stg files to mark edits by osm2platforms
......@@ -48,7 +48,7 @@ class Platform(object):
self.nodes = np.array([transform.toLocal((n.lon, n.lat)) for n in self.osm_nodes])
# self.nodes = np.array([(n.lon, n.lat) for n in osm_nodes])
self.line_string = shg.LineString(self.nodes)
self.anchor = vec2d(self.nodes[0])
self.anchor = Vec2d(self.nodes[0])
class Platforms(ObjectList):
......@@ -86,7 +86,7 @@ class Platforms(ObjectList):
def write(self, elev, stg_manager, replacement_prefix):
for cl in self.clusters:
if len(cl.objects) > 0:
center_tile = vec2d(tools.transform.toGlobal(cl.center))
center_tile = Vec2d(tools.transform.toGlobal(cl.center))
ac_fname = "%splatforms%02i%02i.ac" % (replacement_prefix, cl.I.x, cl.I.y)
ac = ac3d.File(stats=tools.stats)
obj = ac.new_object('platforms', "Textures/Terrain/asphalt.png")
......@@ -114,10 +114,10 @@ class Platforms(ObjectList):
self.logger.info("Clockwise")
platform.nodes = platform.nodes[::-1]
for p in platform.nodes:
e = elev(vec2d(p[0], p[1])) + 1
e = elev(Vec2d(p[0], p[1])) + 1
obj.node(-p[1] + offset.y, e, -p[0] + offset.x)
top_nodes = np.arange(len(platform.nodes))
platform.segment_len = np.array([0] + [vec2d(coord).distance_to(vec2d(platform.line_string.coords[i])) for i, coord in enumerate(platform.line_string.coords[1:])])
platform.segment_len = np.array([0] + [Vec2d(coord).distance_to(Vec2d(platform.line_string.coords[i])) for i, coord in enumerate(platform.line_string.coords[1:])])
rd_len = len(platform.line_string.coords)
platform.dist = np.zeros((rd_len))
for i in range(1, rd_len):
......@@ -131,7 +131,7 @@ class Platforms(ObjectList):
obj.face(face, mat=0)
# Build bottom ring
for p in platform.nodes:
e = elev(vec2d(p[0], p[1])) - 1
e = elev(Vec2d(p[0], p[1])) - 1
obj.node(-p[1] + offset.y, e, -p[0] + offset.x)
# Build Sides
for i, n in enumerate(top_nodes[1:]):
......@@ -150,15 +150,15 @@ class Platforms(ObjectList):
e = 10000
idx_left = obj.next_node_index()
for p in left.coords:
e = elev(vec2d(p[0], p[1])) + 1
e = elev(Vec2d(p[0], p[1])) + 1
obj.node(-p[1] + offset.y, e, -p[0] + offset.x)
idx_right = obj.next_node_index()
for p in right.coords:
e = elev(vec2d(p[0], p[1])) + 1
e = elev(Vec2d(p[0], p[1])) + 1
obj.node(-p[1] + offset.y, e, -p[0] + offset.x)
nodes_l = np.arange(len(left.coords))
nodes_r = np.arange(len(right.coords))
platform.segment_len = np.array([0] + [vec2d(coord).distance_to(vec2d(platform.line_string.coords[i])) for i, coord in enumerate(platform.line_string.coords[1:])])
platform.segment_len = np.array([0] + [Vec2d(coord).distance_to(Vec2d(platform.line_string.coords[i])) for i, coord in enumerate(platform.line_string.coords[1:])])
rd_len = len(platform.line_string.coords)
platform.dist = np.zeros((rd_len))
for i in range(1, rd_len):
......@@ -175,12 +175,12 @@ class Platforms(ObjectList):
# Build bottom left line
idx_bottom_left = obj.next_node_index()
for p in left.coords:
e = elev(vec2d(p[0], p[1])) - 1
e = elev(Vec2d(p[0], p[1])) - 1
obj.node(-p[1]+ offset.y, e, -p[0]+ offset.x)
# Build bottom right line
idx_bottom_right = obj.next_node_index()
for p in right.coords:
e = elev(vec2d(p[0], p[1])) - 1
e = elev(Vec2d(p[0], p[1])) - 1
obj.node(-p[1]+ offset.y, e, -p[0]+ offset.x)
idx_end = obj.next_node_index() - 1
# Build Sides
......@@ -246,8 +246,8 @@ def main():
tools.init(transform)
# -- create (empty) clusters
lmin = vec2d(tools.transform.toLocal(cmin))
lmax = vec2d(tools.transform.toLocal(cmax))
lmin = Vec2d(tools.transform.toLocal(cmin))
lmax = Vec2d(tools.transform.toLocal(cmax))
clusters = Clusters(lmin, lmax, parameters.TILE_SIZE, parameters.PREFIX)
border = None
......
......@@ -5,11 +5,11 @@
# Class : Mesh
#===============================================================================
from . import point3D
#import rainbow
from vec2d import vec2d
import roofs
import numpy as np
import roofs
from utils.vec2d import Vec2d
class Mesh:
"""
A mesh is represented by an indexed face structure (IFS):
......@@ -99,7 +99,7 @@ class Mesh:
#
# f.close()
def ac3d_string(self, b, offset_xy = vec2d(0, 0), offset_z = 0., header = False):
def ac3d_string(self, b, offset_xy = Vec2d(0, 0), offset_z = 0., header = False):
"""return mesh as string in a AC3D format. You must append kids line."""
s = ""
if header:
......@@ -145,7 +145,7 @@ class Mesh:
return s
def to_out(self, out, b, offset_xy = vec2d(0, 0), offset_z = 0., header = False):
def to_out(self, out, b, offset_xy = Vec2d(0, 0), offset_z = 0., header = False):
"""create 3d object"""
if header:
out.new_object(b.roof_ac_name, b.roof_texture.filename + '.png')
......
......@@ -25,15 +25,13 @@ import sys
import unittest
import xml.sax
import shapely.geometry as shg
import coordinates
import parameters
import roads
import shapely.geometry as shg
import stg_io2
import tools
from utils import osmparser
import vec2d
from utils import osmparser, vec2d