Commit 8c60a7c4 authored by Rick Gruber-Riemer's avatar Rick Gruber-Riemer

Corrected xml files to only include LODs present in the corresponding ac files

parent e7f84e41
This diff is collapsed.
......@@ -14,19 +14,20 @@ Cluster borders overlap to make LOD less obvious.
@author: tom
"""
from vec2d import vec2d
import tools
import numpy as np
import logging
import os
import numpy as np
import tools
from vec2d import vec2d
class Cluster(object):
def __init__(self, I, center, size):
#self.out = open
self.objects = []
self.I = I
self.center = center # -- center in local coord
self.center = center # -- center in local coord
self.min = center - size/2.
self.max = center + size/2.
self.stats = tools.Stats()
......@@ -34,6 +35,7 @@ class Cluster(object):
def __str__(self):
print "cl", self.I
def clamp(i, vmin, vmax):
return max(vmin, min(i, vmax))
......@@ -48,20 +50,17 @@ class Clusters(object):
self.__len = self.n.x * self.n.y
self.prefix = prefix
#self.list = []
logging.info("Generating clusters %s %s"%(min,max))
self._clusters = [[self.init_cluster(vec2d(i,j))
for j in range(self.n.y)] for i in range(self.n.x)]
logging.info("Generating clusters %s %s", min, max)
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([])
print "cluster: ", self.n
print " delta: ", self.delta
print " min: ", self.min
print " max: ", self.max
#print self._clusters
def __len__(self):
return self.__len
......@@ -72,12 +71,14 @@ class Clusters(object):
def coords_to_index(self, X):
"""return cluster id for given point X"""
if X.x < self.min.x: X.x = self.min.x
if X.x > self.max.x: X.x = self.max.x
if X.y < self.min.y: X.y = self.min.y
if X.y > self.max.y: X.y = self.max.y
#print "min", self.min
#print "max", self.max
if X.x < self.min.x:
X.x = self.min.x
elif X.x > self.max.x:
X.x = self.max.x
if X.y < self.min.y:
X.y = self.min.y
elif X.y > self.max.y:
X.y = self.max.y
I = ((X - self.min) / self.size).int()
return I
......@@ -85,13 +86,10 @@ class Clusters(object):
def __call__(self, X):
"""return cluster instance for given point X"""
I = self.coords_to_index(X)
#print " I=(%s)" % I
return self._clusters[I.x][I.y]
#def __len__(self):
# return len(self._clusters)
def __iter__(self):
for each_list in self._clusters:
for item in each_list: yield item
......@@ -139,25 +137,20 @@ 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
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))
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" %
(b.anchor.x, b.anchor.y,
i, j, i + j * self.n.x,
ni, nj, ni + nj * self.n.x))
(b.anchor.x, b.anchor.y,
i, j, i + j * self.n.x,
ni, nj, ni + nj * self.n.x))
f.close()
self._clusters = newclusters
return
......@@ -185,9 +178,8 @@ self._clusters[I.x][I.y]
f = open(self.prefix + os.sep + "cluster_stats.dat", "w")
for j in range(self.n.y):
for i in range(self.n.x):
#id = j * self.n.x + i
cl = self._clusters[i][j]
f.write("%i %i %i\n" % (i,j,len(cl.objects)))
f.write("%i %i %i\n" % (i, j, len(cl.objects)))
f.write("\n")
f.close()
......@@ -195,29 +187,17 @@ self._clusters[I.x][I.y]
pass
#c = Clusters(0,5,2, 0,7,3)
#print c.cluster_id(-1111.999,3)
#def test(x,y):
# return [x, y]
#
#a = test(1,2)
#print a
if __name__ == "__main__":
import random
N = 20
X, Y = np.meshgrid(np.linspace(-1,1,N), np.linspace(-1,1,N))
X, Y = np.meshgrid(np.linspace(-1, 1, N), np.linspace(-1, 1, N))
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
y += out.y
print x, y, out.x, out.y, f
#int(f)
......@@ -90,6 +90,10 @@ class Building(object):
Holds all data relevant for a building. Coordinates, type, area, ...
Read-only access to node coordinates via self.X[node][0|1]
"""
LOD_BARE = 0
LOD_ROUGH = 1
LOD_DETAIL = 2
def __init__(self, osm_id, tags, outer_ring, name, height, levels,
stg_typ=None, stg_hdg=None, inner_rings_list=[], building_type='unknown', roof_type='flat', roof_height=0, refs=[]):
self.osm_id = osm_id
......@@ -114,7 +118,7 @@ class Building(object):
self.roof_separate_LOD = False # May or may not be faster
self.ac_name = None
self.ceiling = 0.
self.LOD = None
self.LOD = None # see Building.LOD_* for values
self.outer_nodes_closest = []
if len(outer_ring.coords) > 2:
self.set_polygon(outer_ring, self.inner_rings_list)
......@@ -531,8 +535,11 @@ def write_xml(path, fname, buildings):
xml.write("""<?xml version="1.0"?>\n<PropertyList>\n""")
xml.write("<path>%s.ac</path>" % fname)
# -- lightmap
has_lod_bare = False
has_lod_rough = False
has_lod_detail = False
# -- lightmap
# FIXME: use Effect/Building? What's the difference?
# <lightmap-factor type="float" n="0"><use>/scenery/LOWI/garage[0]/door[0]/position-norm</use></lightmap-factor>
if parameters.LIGHTMAP_ENABLE:
......@@ -565,51 +572,52 @@ def write_xml(path, fname, buildings):
</offsets>
</model>""" % (-yo, xo, zo) )) # -- I just don't get those coordinate systems.
if b.LOD is not None:
if b.LOD == Building.LOD_BARE:
has_lod_bare = True
elif b.LOD == Building.LOD_ROUGH:
has_lod_rough = True
elif b.LOD == Building.LOD_DETAIL:
has_lod_detail = True
else:
logging.warning("Building %s with unknown LOD level %i", b.osm_id, b.LOD)
# -- LOD animation
# no longer use bare (reserved for terrain)
# instead use rough, detail, roof
if has_lod_bare:
xml.write(textwrap.dedent("""
<animation>
<type>range</type>
<min-m>0</min-m>
<max-property>/sim/rendering/static-lod/bare</max-property>
<object-name>LOD_bare</object-name>
</animation>
"""))
if has_lod_rough:
xml.write(textwrap.dedent("""
<animation>
<type>range</type>
<min-m>0</min-m>
<max-property>/sim/rendering/static-lod/rough</max-property>
<object-name>LOD_rough</object-name>
</animation>
"""))
if has_lod_detail:
xml.write(textwrap.dedent("""
<animation>
<type>range</type>
<min-m>0</min-m>
<max-property>/sim/rendering/static-lod/detailed</max-property>
<object-name>LOD_detail</object-name>
</animation>
"""))
xml.write(textwrap.dedent("""
<animation>
<type>range</type>
<min-m>0</min-m>
<max-property>/sim/rendering/static-lod/bare</max-property>
<object-name>LOD_bare</object-name>
</animation>
<animation>
<type>range</type>
<min-m>0</min-m>
<max-property>/sim/rendering/static-lod/rough</max-property>
<object-name>LOD_rough</object-name>
</animation>
<animation>
<type>range</type>
<min-m>0</min-m>
<max-property>/sim/rendering/static-lod/detailed</max-property>
<object-name>LOD_detail</object-name>
</animation>
</PropertyList>
"""))
xml.close()
# <animation>
# <type>range</type>
# <min-m>0</min-m>
# <max-property>/sim/rendering/static-lod/roof</max-property>
# <object-name>LOD_roof</object-name>
# </animation>
# <animation>
# <type>range</type>
# <min-property>/sim/rendering/static-lod/roof</min-property>
# <max-property>/sim/rendering/static-lod/rough</max-property>
# <object-name>LOD_roof_flat</object-name>
# </animation>
# -----------------------------------------------------------------------------
# here we go!
......
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