diff --git a/topologytool.py b/topologytool.py index b801f45..3520f29 100644 --- a/topologytool.py +++ b/topologytool.py @@ -29,16 +29,22 @@ class Topology: linemap_roundcap=True, linemap_transparent=False, storage_directory=None, + linemap_background="Black", + linemap_foreground="White", + override_peak_multiplier=None ): self.country = country self.refetch_elevation_data = refetch_elevation_data self.iso_country = iso_country self.subregion = subregion + self.override_peak_multiplier = override_peak_multiplier self.linemap_size = linemap_size self.linemap_xscale = 1.0 * self.linemap_size[0] / linemap_cols self.linemap_yscale = 1.0 * self.linemap_size[1] / linemap_rows self.linemap_rows = linemap_rows self.linemap_cols = linemap_cols + self.linemap_background = linemap_background + self.linemap_foreground = linemap_foreground if linemap_width is None: self.linemap_width = linemap_size[1] / 400 else: @@ -226,7 +232,7 @@ class Topology: # get png data to cols x rows grid 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: rotation_string = f"{rotation:05.2f}" svg_filename = self.storage_directory + "/" + self.target_region_name + ".r" + rotation_string + ".svg" @@ -263,20 +269,25 @@ class Topology: max_val = values.max() # 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: + slant = 0 for r in range(rows): draw_list = [] + slant = slant + self.linemap_xscale / 15 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_cylinder_at_xy(cr,x,y,self.linemap_xscale,z,self.linemap_yscale/2) + if z != 0: + 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) - surface.write_to_png(svg_filename.replace(".svg", ".topo.png")) + surface.write_to_png(svg_filename.replace(".svg", ".cyl.png")) surface.finish() def create_svg_file(self, rotation=None, file_index=None): @@ -334,7 +345,10 @@ class Topology: # Background #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() # Simple Orthographic Projection Matrix (pseudo-3D) @@ -348,7 +362,10 @@ class Topology: max_val = values.max() # 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 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 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 c in range(cols): - 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() + if self.linemap_foreground == "White": + 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 self.linemap_foreground == "Black": + svg_draw_list(cr, draw_list, line_color="White", fill_shape=True) + svg_draw_list(cr, draw_list, line_color="Black", fill_shape=False) surface.write_to_png(svg_filename.replace(".svg", ".topo.png")) surface.finish() def main(): - topology = Topology(country="Switzerland", + topology = Topology(country="Italy", storage_directory="/Users/he/PycharmProjects/toposhirt/outputfiles", subregion_mode=False, - linemap_cols=50, - linemap_rows=50, + linemap_cols=200, + linemap_rows=200, 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() print(topology.get_boundingbox()) - #topology.create_svg_file() + topology.create_svg_file() topology.create_cylinder_svg_file() - for r in range(4*360): - print("Rotating by [{}] degrees".format(r/4.0)) - topology.create_cylinder_svg_file(rotation=(r / 4.0), file_index=r) + if False: + for r in range(4*360): + print("Rotating by [{}] degrees".format(r/4.0)) + topology.create_cylinder_svg_file(rotation=(r / 4.0), file_index=r) sys.exit(0)