now does better obscuring of mountains in the back

This commit is contained in:
admin 2026-02-03 16:18:18 -08:00
parent 8904c7d966
commit 859303c94b

View File

@ -21,7 +21,7 @@ class Topology:
linemap_size=(800,800), linemap_size=(800,800),
linemap_rows=30, linemap_rows=30,
linemap_cols=30, linemap_cols=30,
linemap_width=1.0, linemap_width=None,
linemap_roundcap=True, linemap_roundcap=True,
linemap_transparent=False, linemap_transparent=False,
storage_directory=None, storage_directory=None,
@ -35,7 +35,8 @@ class Topology:
self.linemap_yscale = 1.0 * self.linemap_size[1] / linemap_rows self.linemap_yscale = 1.0 * self.linemap_size[1] / linemap_rows
self.linemap_rows = linemap_rows self.linemap_rows = linemap_rows
self.linemap_cols = linemap_cols self.linemap_cols = linemap_cols
self.linemap_width = linemap_width if linemap_width is None:
self.linemap_width = linemap_size[1] / 400
self.linemap_roundcap = linemap_roundcap self.linemap_roundcap = linemap_roundcap
self.linemap_transparent = linemap_transparent self.linemap_transparent = linemap_transparent
self.subregion_mode = subregion_mode self.subregion_mode = subregion_mode
@ -159,6 +160,24 @@ class Topology:
return values return values
def create_svg_file(self, rotation=None,file_index=None): def create_svg_file(self, rotation=None,file_index=None):
# subfunction to draw an array, options are line y/n, fill y/n, line and fill color
def svg_draw_list(svg_context, draw_list, line_color="White",fill_shape=False):
if line_color == "White":
svg_context.set_source_rgb(1, 1, 1)
if line_color == "Black":
svg_context.set_source_rgb(0, 0, 0)
for item in range(len(draw_list)):
if item == 0:
svg_context.move_to(draw_list[item][0],draw_list[item][1])
else:
svg_context.line_to(draw_list[item][0],draw_list[item][1])
if fill_shape:
svg_context.close_path()
svg_context.fill_preserve()
svg_context.stroke()
# if no refetch, check if file exists # if no refetch, check if file exists
if os.path.exists(self.elevation_filename): if os.path.exists(self.elevation_filename):
print("Elevation file exists") print("Elevation file exists")
@ -201,7 +220,7 @@ class Topology:
# Projects (x,y,z) -> (x+z/2, y+z/2) # Projects (x,y,z) -> (x+z/2, y+z/2)
# max height should be no more than 3 times the distance between rows, this could be a setting # max height should be no more than 3 times the distance between rows, this could be a setting
def project(x, y, z): def project(x, y, z):
return (x * self.linemap_xscale, y * self.linemap_yscale - z) return (x * self.linemap_xscale, y * self.linemap_yscale - (z if z > 0 else (-1.5 * self.linemap_yscale)))
# return (offset[0] + x * scale + z * 2, offset[1] + y * scale + z * 2) # return (offset[0] + x * scale + z * 2, offset[1] + y * scale + z * 2)
rows, cols = values.shape rows, cols = values.shape
@ -212,11 +231,24 @@ class Topology:
# Draw Lines along rows # Draw Lines along rows
cr.set_source_rgb(0, 0, 0) # Black lines cr.set_source_rgb(0, 0, 0) # Black lines
cr.set_line_width(2.0) cr.set_line_width(self.linemap_width)
cr.set_line_cap(cairo.LINE_CAP_ROUND) cr.set_line_cap(cairo.LINE_CAP_ROUND)
cr.set_line_join(cairo.LINE_JOIN_ROUND) cr.set_line_join(cairo.LINE_JOIN_ROUND)
x = 0 x = 0
y = 0 y = 0
if True:
for r in range(rows):
draw_list = []
for c in range(cols):
z = norm_data[r,c]
x,y = project(c, r, z) # now need to make array of x,y vals and pass to drawing func
draw_list.append((x,y))
print("***" + str(draw_list))
svg_draw_list(cr, draw_list, line_color="Black", fill_shape=True)
svg_draw_list(cr, draw_list, line_color="White", fill_shape=False)
if False:
for r in range(rows): for r in range(rows):
for c in range(cols): for c in range(cols):
z = norm_data[r, c] z = norm_data[r, c]
@ -231,8 +263,10 @@ class Topology:
cr.set_source_rgb(0, 0, 0) cr.set_source_rgb(0, 0, 0)
cr.fill_preserve() cr.fill_preserve()
cr.set_source_rgb(1, 1, 1) cr.set_source_rgb(1, 1, 1)
cr.set_line_width(2.0) cr.set_line_width(self.linemap_width)
cr.stroke() cr.stroke()
surface.write_to_png(svg_filename.replace(".svg", ".topo.png")) surface.write_to_png(svg_filename.replace(".svg", ".topo.png"))
surface.finish() surface.finish()
@ -240,17 +274,17 @@ def main():
topology = Topology(country="Switzerland", topology = Topology(country="Switzerland",
storage_directory="/Users/he/PycharmProjects/toposhirt/outputfiles", storage_directory="/Users/he/PycharmProjects/toposhirt/outputfiles",
subregion_mode=False, subregion_mode=False,
linemap_cols=150, linemap_cols=80,
linemap_rows=150, linemap_rows=80,
linemap_size=(1224,1224)) linemap_size=(1080,1080))
topology.list_subunits() topology.list_subunits()
print(topology.get_boundingbox()) print(topology.get_boundingbox())
topology.create_svg_file() topology.create_svg_file()
sys.exit(0)
for r in range(4*360): for r in range(4*360):
print("Rotating by [{}] degrees".format(r/4.0)) print("Rotating by [{}] degrees".format(r/4.0))
topology.create_svg_file(rotation=(r / 4.0), file_index=r) topology.create_svg_file(rotation=(r / 4.0), file_index=r)
sys.exit(0)
t2=Topology(country="United Kingdom", t2=Topology(country="United Kingdom",
subregion_mode=True, subregion_mode=True,