Commit 3bab140b authored by Thomas Albrecht's avatar Thomas Albrecht

count textures used

parent 60077b9b
......@@ -597,18 +597,18 @@ if __name__ == "__main__":
parameters.show()
# -- initialize modules
tex.manager.init(create_atlas=args.do_textures or args.do_textures_only)
if args.do_textures_only:
sys.exit(0)
# -- prepare transformation to local coordinates
cmin, cmax = parameters.get_extent_global()
center = parameters.get_center_global()
#center = (11.38, 47.26)
tools.init(coordinates.Transformation(center, hdg = 0))
# print tools.transform.toGlobal(cmin), tools.transform.toGlobal(cmax)
tex.manager.init(create_atlas=args.do_textures or args.do_textures_only)
if args.do_textures_only:
sys.exit(0)
logging.info("reading elevation data")
elev = tools.get_interpolator(fake=parameters.NO_ELEV)
......
......@@ -18,6 +18,7 @@ import sys
import atlas
from texture import Texture
import catalog
import tools
#import textures_src
......@@ -188,6 +189,8 @@ class TextureManager(object):
new_provides.append(self.__cls + ':' + item)
#t.provides = [self.__cls + ':' + i for i in t.provides]
t.provides = new_provides
tools.stats.textures_total += 1
self.__l.append(t)
def keep_only(self, i):
......@@ -204,7 +207,9 @@ class TextureManager(object):
return None
#print "cands are\n", string.join([" " + str(c) for c in candidates], '\n')
#return candidates[3]
return candidates[random.randint(0, len(candidates)-1)]
the_texture = candidates[random.randint(0, len(candidates)-1)]
tools.stats.count_texture(the_texture)
return the_texture
def find_candidates(self, requires = []):
#return [self.__l[0]]
......@@ -212,6 +217,8 @@ class TextureManager(object):
for cand in self.__l:
if set(requires).issubset(cand.provides):
candidates.append(cand)
else:
logging.debug(" unmet requires %s" % str(cand))
return candidates
def __str__(self):
......@@ -231,7 +238,10 @@ class FacadeManager(TextureManager):
logging.warn("no matching texture for %1.f m x %1.1f m <%s>" % (height, width, str(requires)))
return None
ranked_list = self.rank_candidates(candidates, tags)
return ranked_list[random.randint(0, len(ranked_list) - 1)]
the_texture = ranked_list[random.randint(0, len(ranked_list) - 1)]
tools.stats.count_texture(the_texture)
return the_texture
def rank_candidates(self, candidates, tags):
ranked_list = []
......@@ -255,6 +265,7 @@ class FacadeManager(TextureManager):
# print "\ncands", [str(t.filename) for t in candidates]
# -- check height
# print " Candidates:"
#logging.info("Got %i cands" % len(candidates))
new_candidates = []
for t in candidates:
# print " <<<", t.filename
......@@ -269,6 +280,7 @@ class FacadeManager(TextureManager):
# candidates.remove(t)
# print "remaining cands", [str(t.filename) for t in new_candidates]
#logging.info("After width/height test %i remaining" % len(new_candidates))
return new_candidates
def find_matching_texture(cls, textures):
......@@ -285,52 +297,54 @@ def init(tex_prefix='', create_atlas=False):
print "textures: init"
global facades
global roofs
facades = FacadeManager('facade')
roofs = TextureManager('roof')
catalog.append_facades_de(tex_prefix, facades)
#append_facades_test()
catalog.append_roofs(tex_prefix, roofs)
catalog.append_facades_us(tex_prefix, facades)
#facades.keep_only(1)
if False:
print roofs[0].provides
print "black roofs: ", [str(i) for i in roofs.find_candidates(['roof:color:black'])]
print "red roofs: ", [str(i) for i in roofs.find_candidates(['roof:color:red'])]
print "old facades: "
for i in facades.find_candidates(['facade:shape:residential','age:old'], 10):
print i, i.v_cuts * i.v_size_meters
#print facades[0].provides
if False:
filename = tex_prefix + 'tex/atlas_facades'
pkl_fname = filename + '.pkl'
if create_atlas:
facades = FacadeManager('facade')
roofs = TextureManager('roof')
facades.append(Texture(tex_prefix + 'test.png',
10, [142,278,437,590,756,890,1024], True,
10, [130,216,297,387,512], True, True,
provides=['shape:urban','shape:residential','age:modern','age:old','compat:roof-flat','compat:roof-pitched']))
roofs.append(Texture(tex_prefix + 'test.png',
10., [], True, 10., [], True, provides=['color:black', 'color:red']))
# -- make texture atlas (or unpickle)
if create_atlas:
filename = tex_prefix + 'tex/atlas_facades'
pkl_fname = filename + '.pkl'
if 1:
# facades.make_texture_atlas(filename + '.png')
texture_list = facades.get_list() + roofs.get_list()
make_texture_atlas(texture_list, filename, '.png', lightmap=True)
logging.info("Saving %s", pkl_fname)
#fpickle = open(pkl_fname, 'wb')
#cPickle.dump(facades, fpickle, -1)
#fpickle.close()
else:
logging.info("Loading %s", pkl_fname)
fpickle = open(pkl_fname, 'rb')
facades = cPickle.load(fpickle)
fpickle.close()
catalog.append_facades_de(tex_prefix, facades)
#append_facades_test()
catalog.append_roofs(tex_prefix, roofs)
catalog.append_facades_us(tex_prefix, facades)
#facades.keep_only(1)
if False:
print roofs[0].provides
print "black roofs: ", [str(i) for i in roofs.find_candidates(['roof:color:black'])]
print "red roofs: ", [str(i) for i in roofs.find_candidates(['roof:color:red'])]
print "old facades: "
for i in facades.find_candidates(['facade:shape:residential','age:old'], 10):
print i, i.v_cuts * i.v_size_meters
#print facades[0].provides
if False:
facades = FacadeManager('facade')
roofs = TextureManager('roof')
facades.append(Texture(tex_prefix + 'test.png',
10, [142,278,437,590,756,890,1024], True,
10, [130,216,297,387,512], True, True,
provides=['shape:urban','shape:residential','age:modern','age:old','compat:roof-flat','compat:roof-pitched']))
roofs.append(Texture(tex_prefix + 'test.png',
10., [], True, 10., [], True, provides=['color:black', 'color:red']))
# -- make texture atlas
texture_list = facades.get_list() + roofs.get_list()
make_texture_atlas(texture_list, filename, '.png', lightmap=True)
logging.info("Saving %s", pkl_fname)
fpickle = open(pkl_fname, 'wb')
cPickle.dump(facades, fpickle, -1)
cPickle.dump(roofs, fpickle, -1)
fpickle.close()
else:
logging.info("Loading %s", pkl_fname)
fpickle = open(pkl_fname, 'rb')
facades = cPickle.load(fpickle)
roofs = cPickle.load(fpickle)
fpickle.close()
logging.info(facades)
......
......@@ -648,8 +648,8 @@ class Stats(object):
self.LOD = np.zeros(3)
self.nodes_ground = 0
self.nodes_simplified = 0
self.texture_x_repeated = 0
self.texture_x_simple = 0
self.textures_total = 0
self.textures_used = set()
def count(self, b):
"""update stats (vertices, surfaces, area) with given building's data
......@@ -669,6 +669,9 @@ class Stats(object):
def count_LOD(self, lod):
self.LOD[lod] += 1
def count_texture(self, texture):
self.textures_used.add(str(texture))
def print_summary(self):
out = sys.stdout
......@@ -697,9 +700,9 @@ class Stats(object):
out.write(textwrap.dedent(roof_line))
try:
texture_x_repeated_percent = (self.texture_x_repeated * 100. / (self.texture_x_repeated + self.texture_x_simple))
textures_used_percent = len(self.textures_used) * 100. / self.textures_total
except:
texture_x_repeated_percent = 0.
textures_used_percent = 99.9
out.write(textwrap.dedent("""
complex %i
......@@ -708,14 +711,14 @@ class Stats(object):
simplified %i
vertices %i
surfaces %i
repeated tex x %i out of %i (%2.0f %%)
used tex %i out of %i (%2.0f %%)
LOD bare %i (%2.0f %%)
LOD rough %i (%2.0f %%)
LOD detail %i (%2.0f %%)
""" % (self.have_complex_roof, self.roof_errors,
self.nodes_ground, self.nodes_simplified,
self.vertices, self.surfaces,
self.texture_x_repeated, (self.texture_x_repeated + self.texture_x_simple), texture_x_repeated_percent,
len(self.textures_used), self.textures_total, textures_used_percent,
self.LOD[0], lodzero,
self.LOD[1], lodone,
self.LOD[2], lodtwo)))
......
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