incorporate cylinders with gradient into main class
This commit is contained in:
parent
dfe2d16d6c
commit
83d5128a0b
@ -29,16 +29,22 @@ class Topology:
|
|||||||
linemap_roundcap=True,
|
linemap_roundcap=True,
|
||||||
linemap_transparent=False,
|
linemap_transparent=False,
|
||||||
storage_directory=None,
|
storage_directory=None,
|
||||||
|
linemap_background="Black",
|
||||||
|
linemap_foreground="White",
|
||||||
|
override_peak_multiplier=None
|
||||||
):
|
):
|
||||||
self.country = country
|
self.country = country
|
||||||
self.refetch_elevation_data = refetch_elevation_data
|
self.refetch_elevation_data = refetch_elevation_data
|
||||||
self.iso_country = iso_country
|
self.iso_country = iso_country
|
||||||
self.subregion = subregion
|
self.subregion = subregion
|
||||||
|
self.override_peak_multiplier = override_peak_multiplier
|
||||||
self.linemap_size = linemap_size
|
self.linemap_size = linemap_size
|
||||||
self.linemap_xscale = 1.0 * self.linemap_size[0] / linemap_cols
|
self.linemap_xscale = 1.0 * self.linemap_size[0] / linemap_cols
|
||||||
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_background = linemap_background
|
||||||
|
self.linemap_foreground = linemap_foreground
|
||||||
if linemap_width is None:
|
if linemap_width is None:
|
||||||
self.linemap_width = linemap_size[1] / 400
|
self.linemap_width = linemap_size[1] / 400
|
||||||
else:
|
else:
|
||||||
@ -226,7 +232,7 @@ class Topology:
|
|||||||
# get png data to cols x rows grid
|
# get png data to cols x rows grid
|
||||||
values = self.convert_png_to_data(rotation)
|
values = self.convert_png_to_data(rotation)
|
||||||
|
|
||||||
svg_filename = self.storage_directory + "/" + self.target_region_name+".svg"
|
svg_filename = self.storage_directory + "/" + self.target_region_name+".cyl.svg"
|
||||||
if rotation is not None:
|
if rotation is not None:
|
||||||
rotation_string = f"{rotation:05.2f}"
|
rotation_string = f"{rotation:05.2f}"
|
||||||
svg_filename = self.storage_directory + "/" + self.target_region_name + ".r" + rotation_string + ".svg"
|
svg_filename = self.storage_directory + "/" + self.target_region_name + ".r" + rotation_string + ".svg"
|
||||||
@ -263,20 +269,25 @@ class Topology:
|
|||||||
max_val = values.max()
|
max_val = values.max()
|
||||||
|
|
||||||
# Normalize data for visualization height (0-100) -- max is no more than three row heights
|
# Normalize data for visualization height (0-100) -- max is no more than three row heights
|
||||||
norm_data = (values / max_val) * self.linemap_xscale * 3
|
if self.override_peak_multiplier is None:
|
||||||
|
norm_data = (values / max_val) * self.linemap_xscale * 3
|
||||||
|
else:
|
||||||
|
norm_data = (values / max_val) * self.linemap_xscale * self.override_peak_multiplier
|
||||||
|
|
||||||
if True:
|
if True:
|
||||||
|
slant = 0
|
||||||
for r in range(rows):
|
for r in range(rows):
|
||||||
draw_list = []
|
draw_list = []
|
||||||
|
slant = slant + self.linemap_xscale / 15
|
||||||
for c in range(cols):
|
for c in range(cols):
|
||||||
z = norm_data[r,c]
|
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
|
if z != 0:
|
||||||
draw_cylinder_at_xy(cr,x,y,self.linemap_xscale,z,self.linemap_yscale/2)
|
x,y = project(c, r, z) # now need to make array of x,y vals and pass to drawing func
|
||||||
|
draw_cylinder_at_xy(cr,x+slant,y,self.linemap_xscale,z,self.linemap_yscale/2)
|
||||||
#svg_draw_list(cr, draw_list, line_color="Black", fill_shape=True)
|
#svg_draw_list(cr, draw_list, line_color="Black", fill_shape=True)
|
||||||
|
|
||||||
|
|
||||||
surface.write_to_png(svg_filename.replace(".svg", ".topo.png"))
|
surface.write_to_png(svg_filename.replace(".svg", ".cyl.png"))
|
||||||
surface.finish()
|
surface.finish()
|
||||||
|
|
||||||
def create_svg_file(self, rotation=None, file_index=None):
|
def create_svg_file(self, rotation=None, file_index=None):
|
||||||
@ -334,7 +345,10 @@ class Topology:
|
|||||||
|
|
||||||
# Background
|
# Background
|
||||||
#cr.set_source_rgb(1, 1, 1)
|
#cr.set_source_rgb(1, 1, 1)
|
||||||
cr.set_source_rgb(0, 0, 0)
|
if self.linemap_background == "Black":
|
||||||
|
cr.set_source_rgb(0, 0, 0)
|
||||||
|
if self.linemap_background == "White":
|
||||||
|
cr.set_source_rgb(1, 1, 1)
|
||||||
cr.paint()
|
cr.paint()
|
||||||
|
|
||||||
# Simple Orthographic Projection Matrix (pseudo-3D)
|
# Simple Orthographic Projection Matrix (pseudo-3D)
|
||||||
@ -348,7 +362,10 @@ class Topology:
|
|||||||
max_val = values.max()
|
max_val = values.max()
|
||||||
|
|
||||||
# Normalize data for visualization height (0-100) -- max is no more than three row heights
|
# Normalize data for visualization height (0-100) -- max is no more than three row heights
|
||||||
norm_data = (values / max_val) * self.linemap_xscale * 3
|
if self.override_peak_multiplier is None:
|
||||||
|
norm_data = (values / max_val) * self.linemap_xscale * 3
|
||||||
|
else:
|
||||||
|
norm_data = (values / max_val) * self.linemap_xscale * self.override_peak_multiplier
|
||||||
|
|
||||||
# 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
|
||||||
@ -366,46 +383,37 @@ class Topology:
|
|||||||
x,y = project(c, r, z) # now need to make array of x,y vals and pass to drawing func
|
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))
|
draw_list.append((x,y))
|
||||||
print("***" + str(draw_list))
|
print("***" + str(draw_list))
|
||||||
svg_draw_list(cr, draw_list, line_color="Black", fill_shape=True)
|
if self.linemap_foreground == "White":
|
||||||
svg_draw_list(cr, draw_list, line_color="White", fill_shape=False)
|
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:
|
if self.linemap_foreground == "Black":
|
||||||
for r in range(rows):
|
svg_draw_list(cr, draw_list, line_color="White", fill_shape=True)
|
||||||
for c in range(cols):
|
svg_draw_list(cr, draw_list, line_color="Black", fill_shape=False)
|
||||||
z = norm_data[r, c]
|
|
||||||
x, y = project(c, r, z) # -z to make higher values go "up" in 2D
|
|
||||||
if c == 0:
|
|
||||||
cr.move_to(x, y + 50)
|
|
||||||
cr.line_to(x, y)
|
|
||||||
else:
|
|
||||||
cr.line_to(x, y)
|
|
||||||
cr.line_to(x, y + 50)
|
|
||||||
cr.close_path()
|
|
||||||
cr.set_source_rgb(0, 0, 0)
|
|
||||||
cr.fill_preserve()
|
|
||||||
cr.set_source_rgb(1, 1, 1)
|
|
||||||
cr.set_line_width(self.linemap_width)
|
|
||||||
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()
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
topology = Topology(country="Switzerland",
|
topology = Topology(country="Italy",
|
||||||
storage_directory="/Users/he/PycharmProjects/toposhirt/outputfiles",
|
storage_directory="/Users/he/PycharmProjects/toposhirt/outputfiles",
|
||||||
subregion_mode=False,
|
subregion_mode=False,
|
||||||
linemap_cols=50,
|
linemap_cols=200,
|
||||||
linemap_rows=50,
|
linemap_rows=200,
|
||||||
linemap_size=(1080,1080),
|
linemap_size=(1080,1080),
|
||||||
linemap_width=0.3)
|
linemap_width=1.0,
|
||||||
|
linemap_background="White",
|
||||||
|
linemap_foreground="Black",
|
||||||
|
override_peak_multiplier=6
|
||||||
|
)
|
||||||
topology.list_subunits()
|
topology.list_subunits()
|
||||||
print(topology.get_boundingbox())
|
print(topology.get_boundingbox())
|
||||||
#topology.create_svg_file()
|
topology.create_svg_file()
|
||||||
topology.create_cylinder_svg_file()
|
topology.create_cylinder_svg_file()
|
||||||
for r in range(4*360):
|
if False:
|
||||||
print("Rotating by [{}] degrees".format(r/4.0))
|
for r in range(4*360):
|
||||||
topology.create_cylinder_svg_file(rotation=(r / 4.0), file_index=r)
|
print("Rotating by [{}] degrees".format(r/4.0))
|
||||||
|
topology.create_cylinder_svg_file(rotation=(r / 4.0), file_index=r)
|
||||||
|
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user