0

Merge remote branch 'munki/master'

This commit is contained in:
Andrew Brown
2010-09-07 21:19:08 -04:00
2 changed files with 29 additions and 19 deletions

13
gmap.py
View File

@@ -37,21 +37,20 @@ def main():
print "processing chunks in background"
results = world.render_chunks_async(chunks, False, options.procs)
print "Generating quad tree. This may take a while and has no progress bar right now, so sit tight."
print "Writing out html file"
if not os.path.exists(destdir):
os.mkdir(destdir)
zoom = world.get_quadtree_depth(mincol, maxcol, minrow, maxrow)
write_html(destdir, zoom+1)
print "Generating quad tree. This may take a while and has no progress bar right now, so sit tight."
tiledir = os.path.join(destdir, "tiles");
if not os.path.exists(tiledir):
os.mkdir(tiledir)
zoom = world.generate_quadtree(results, mincol, maxcol, minrow, maxrow, tiledir)
world.generate_quadtree(results, mincol, maxcol, minrow, maxrow, tiledir)
print "DONE"
print "Writing out html file"
write_html(destdir, zoom+1)
def write_html(path, zoomlevel):
templatepath = os.path.join(os.path.split(__file__)[0], "template.html")
html = open(templatepath, 'r').read()

View File

@@ -292,15 +292,13 @@ def render_worldtile(chunkmap, colstart, colend, rowstart, rowend, oldhash):
return tileimg, digest
def generate_quadtree(chunkmap, colstart, colend, rowstart, rowend, prefix):
"""Base call for quadtree_recurse. This sets up the recursion and generates
a quadtree given a chunkmap and the ranges.
This returns the power of 2 tiles wide and high the image is. This is one
less than the maximum zoom (level 0 is a single tile, level 1 is 2 tiles
wide by 2 tiles high, etc.)
def get_quadtree_depth(colstart, colend, rowstart, rowend):
"""Determines the zoom depth of a requested quadtree.
Return value is an integer >= 0. Higher integers mean higher resolution maps.
"""
# Pulled out of generate_quadtree. Original comment follows:
#
# This first call has a special job. No matter the input, we need to
# make sure that each recursive call splits both dimensions evenly
# into a power of 2 tiles wide and high.
@@ -320,6 +318,21 @@ def generate_quadtree(chunkmap, colstart, colend, rowstart, rowend, prefix):
else:
raise Exception("Your map is waaaay to big")
return p
def generate_quadtree(chunkmap, colstart, colend, rowstart, rowend, prefix):
"""Base call for quadtree_recurse. This sets up the recursion and generates
a quadtree given a chunkmap and the ranges.
This returns the power of 2 tiles wide and high the image is. This is one
less than the maximum zoom (level 0 is a single tile, level 1 is 2 tiles
wide by 2 tiles high, etc.)
"""
p = get_quadtree_depth(colstart, colend, rowstart, rowend);
colmid = (colstart + colend) // 2
rowmid = (rowstart + rowend) // 2
# Modify the lower and upper bounds to be sized correctly
colstart = colmid - 2*2**p
colend = colmid + 2*2**p
@@ -331,8 +344,6 @@ def generate_quadtree(chunkmap, colstart, colend, rowstart, rowend, prefix):
quadtree_recurse(chunkmap, colstart, colend, rowstart, rowend, prefix, "base")
return p
def quadtree_recurse(chunkmap, colstart, colend, rowstart, rowend, prefix, quadrant):
"""Recursive method that generates a quadtree.
A single call generates, saves, and returns an image with the range