Commit acbe3248 authored by Thomas Albrecht's avatar Thomas Albrecht

- re-enabled nearby checks

- fake reading .xml: replace .xml with .ac
- tranfer buildings between tiles: all LODs
- xml writer: formatting
- stg reader: ignore empty lines
parent db5de640
......@@ -50,8 +50,8 @@ class random_number(object):
def random_LOD():
r = random.uniform(0,1)
#if r < 0.7: return 2 # -- 60% detail
if r < 0.7: return 1 # 25% rough
return 0 # 15% bare
if r < 0.7: return 1 # 70% rough
return 0 # 30% bare
default_height=12.
random_level_height = random_number(float, 3.1, 3.6)
......@@ -93,18 +93,41 @@ def reset_nb():
nb = 0
def get_nodes_from_acs(objs, path_prefix):
"""load all .ac, extract nodes"""
"""load all .ac and .xml, extract nodes"""
# FIXME: use real ac3d reader: https://github.com/majic79/Blender-AC3D/blob/master/io_scene_ac3d/import_ac3d.py
# FIXME: don't skip .xml
# skip own .ac city-*.xml
all_nodes = np.array([[0,0]])
# for b in objs:
# if b.name.endswith(".xml") and b.stg_typ == "OBJECT_STATIC":
# print "READ xml", b.name
# try:
# xml = open(path_prefix + b.name, 'r')
# except:
# continue
# # first occurence of <path>name.ac</path>
#
# lines = ac.readlines()
# xml.close()
for b in objs:
if b.name.endswith(".ac") and b.stg_typ == "OBJECT_STATIC":
print "READ", b.name
fname = b.name
#print "in objs <%s>" % b.name
if fname.endswith(".xml"):
if fname.startswith("city-"): continue
fname = fname.replace(".xml", ".ac")
#print "now <%s> %s" % (fname, b.stg_typ)
if fname.endswith(".ac") and b.stg_typ == "OBJECT_STATIC":
print "READ_AC", b.name
try:
ac = open(path_prefix + b.name, 'r')
ac = open(path_prefix + fname, 'r')
except:
print "can't open", fname
continue
angle = radians(b.stg_hdg)
R = np.array([[cos(angle), -sin(angle)],
......@@ -158,14 +181,15 @@ def analyse(buildings, static_objects, transform, elev, facades, roofs):
- location clash with stg static models? drop building
- analyze surrounding: similar shaped buildings nearby? will get same texture
- set building type, roof type etc
- decide LOD
We're in global coordinates
"""
# -- build KDtree for static models
from scipy.spatial import KDTree
s = get_nodes_from_acs(static_objects.objs, "e013n51/")
#s = get_nodes_from_acs(static_objects.objs, "e013n51/")
s = get_nodes_from_acs(static_objects.objs, "e011n47/")
np.savetxt("nodes.dat", s)
# s = np.zeros((len(static_objects.objs), 2))
# i = 0
......@@ -304,7 +328,7 @@ def analyse(buildings, static_objects, transform, elev, facades, roofs):
# if b.name == "Semperoper":
# bla
if len(nearby) == -1:
if len(nearby):
for i in range(b.nnodes_ground):
tools.stats.debug2.write("%g %g\n" % (X[i,0], X[i,1]))
# print "nearby:", nearby
......@@ -332,7 +356,7 @@ def analyse(buildings, static_objects, transform, elev, facades, roofs):
#if ((X[i,0] - fk[0])**2 + (X[i,1] - fk[1])**2) > 1000000:
# continue
# -- skipping 30% of under 200 sqm buildings
# -- skipping 50% of under 200 sqm buildings
if b.area < 20. or (b.area < 200. and random.uniform(0,1) < 0.5):
#if b.area < 20. : # FIXME use limits.area_min:
print "Skipping small building (area)"
......@@ -376,7 +400,7 @@ def analyse(buildings, static_objects, transform, elev, facades, roofs):
def decide_LOD(buildings):
for b in buildings:
lod = random_LOD()
if b.area < 150: lod = 2
if b.area < 150: lod = 1
if b.area > 500: lod = 0
if b.levels > 5: lod = 0 # tall buildings always LOD bare
#if b.levels < 3: lod = 2 # small buildings always LOD detail
......
......@@ -102,19 +102,19 @@ self._clusters[I.x][I.y]
for j in range(self.n.y):
for i in range(self.n.x):
cluster = self._clusters[i][j]
print i, j, cluster.center
#print i, j, cluster.center
for b in cluster.objects:
if b.LOD == 1:
norm_coord = (b.anchor - cluster.center) / self.size
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)
ni = clamp(ni, 0, self.n.x-1)
nj = clamp(nj, 0, self.n.y-1)
else:
ni = i
nj = j
# if b.LOD == 1:
norm_coord = (b.anchor - cluster.center) / self.size
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)
ni = clamp(ni, 0, self.n.x-1)
nj = clamp(nj, 0, self.n.y-1)
# else:
# ni = i
# nj = j
newclusters[ni][nj].objects.append(b)
f.write("%4.0f %4.0f %i %i %i %i %i %i\n" %
......
......@@ -343,40 +343,42 @@ def write_ac_header(out, nb):
def write_xml(fname, LOD_lists):
# -- LOD animation
xml = open(fname + ".xml", "w")
xml.write("""<?xml version="1.0"?>
<PropertyList>
""")
xml.write("""<?xml version="1.0"?>\n<PropertyList>\n""")
xml.write("<path>%s.ac</path>" % fname)
xml.write("""
xml.write(textwrap.dedent("""
<animation>
<type>range</type>
""")
<type>range</type>
"""))
for name in LOD_lists[0]:
xml.write("<object-name>%s</object-name>\n" % name)
xml.write("""
xml.write(" <object-name>%s</object-name>\n" % name)
xml.write(textwrap.dedent("""
<min-m>0</min-m>
<max-property>/sim/rendering/static-lod/bare</max-property>
</animation>
<animation>
<type>range</type>
""")
</animation>
<animation>
<type>range</type>
"""))
for name in LOD_lists[1]:
xml.write("<object-name>%s</object-name>\n" % name)
xml.write("""
<min-m>0</min-m>
<max-property>/sim/rendering/static-lod/rough</max-property>
xml.write(" <object-name>%s</object-name>\n" % name)
xml.write(textwrap.dedent("""
<min-m>0</min-m>
<max-property>/sim/rendering/static-lod/rough</max-property>
</animation>
<animation>
<!--
<animation>
<type>range</type>
""")
"""))
for name in LOD_lists[2]:
xml.write("<object-name>%s</object-name>\n" % name)
xml.write("""
xml.write(" <object-name>%s</object-name>\n" % name)
xml.write(textwrap.dedent("""
<min-m>0</min-m>
<max-property>/sim/rendering/static-lod/detailed</max-property>
</animation>
-->
</PropertyList>
""")
"""))
xml.close()
......@@ -439,7 +441,8 @@ if __name__ == "__main__":
# - read relevant stgs
static_objects = stg_io.Stg(("e013n51/3171138.stg", "e013n51/3171139.stg"))
#static_objects = stg_io.Stg(["e013n51/3171138.stg", "e013n51/3171139.stg"])
static_objects = stg_io.Stg(["e011n47/3138129.stg"])
tools.stats.debug1 = open("debug1.dat", "w")
tools.stats.debug2 = open("debug2.dat", "w")
......@@ -466,6 +469,13 @@ if __name__ == "__main__":
clusters.write_stats()
# - write clusters
stg_fname = "city.stg"
stg = open(stg_fname, "w")
stg.write("# osm2city\n#\n")
stg.close()
for l in clusters._clusters: # FIXME: why 2 loops here??
for cl in l:
nb = len(cl.objects)
......@@ -504,7 +514,6 @@ if __name__ == "__main__":
# -- write stg
tile_index = calc_tile.tile_index(center_lon, center_lat)
#stg_fname = "%07i.stg" % tile_index
stg_fname = "city.stg"
stg = open(stg_fname, "a")
stg.write("OBJECT_STATIC %s %g %g %g %g\n" % (fname+".xml", center_lon, center_lat, tile_elev, 0))
stg.close()
......
......@@ -28,9 +28,10 @@ class Stg:
objs = []
f = open(filename)
for line in f.readlines():
if line.startswith('#'): continue
if line.startswith('#') or line.lstrip() == "": continue
splitted = line.split()
typ, path = splitted[0:2]
print "stg:", typ, path
lon = float(splitted[2])
lat = float(splitted[3])
alt = float(splitted[4])
......
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