def process_file(options, filename): print "Processing %s..." % (filename,) data = PixelData(io_data.read_pixels(filename, 'png')) base_filename = os.path.splitext(os.path.split(filename)[-1])[0] outdir = options.output_dir filetypes = [] if options.to_png: filetypes.append('PNG') if options.to_svg: filetypes.append('SVG') if options.write_pixels: for ft in filetypes: print " Writing pixels %s..." % (ft,) writer = io_data.get_writer(data, base_filename, ft.lower()) writer.export_pixels(outdir) data.depixel() if options.write_grid: for ft in filetypes: print " Writing grid %s..." % (ft,) writer = io_data.get_writer(data, base_filename, ft.lower()) writer.export_grid(outdir, options.draw_nodes) if options.write_shapes: for ft in filetypes: print " Writing shapes %s..." % (ft,) writer = io_data.get_writer(data, base_filename, ft.lower()) writer.export_shapes(outdir, options.draw_nodes)
def test_deform_grid(self): tg = nx.Graph() tg.add_nodes_from([ (0, 0), (0, 1), (0, 2), (0, 3), (1, 0), (1, 1), (1, 2), (1, 3), (1.25, 1.25), (1.25, 1.75), (1.75, 1.25), (1.75, 2.25), (2, 0), (2, 1), (2, 3), (2.25, 1.75), (3, 0), (3, 1), (3, 2), (3, 3), (4, 0), (4, 1), (4, 2), (4, 3), ]) tg.add_edges_from([ ((0, 0), (0, 1)), ((0, 1), (0, 2)), ((0, 3), (0, 2)), ((1, 0), (0, 0)), ((1, 0), (1, 1)), ((1, 0), (2, 0)), ((1, 1), (0, 1)), ((1, 2), (0, 2)), ((1, 3), (0, 3)), ((1, 3), (1, 2)), ((1, 3), (2, 3)), ((1.25, 1.25), (1, 1)), ((1.25, 1.25), (1.75, 1.25)), ((1.25, 1.75), (1, 2)), ((1.25, 1.75), (1.25, 1.25)), ((1.25, 1.75), (1.75, 2.25)), ((2, 1), (1.75, 1.25)), ((2, 1), (2, 0)), ((2, 1), (3, 1)), ((2, 3), (1.75, 2.25)), ((2.25, 1.75), (1.75, 1.25)), ((2.25, 1.75), (1.75, 2.25)), ((2.25, 1.75), (3, 2)), ((3, 0), (2, 0)), ((3, 0), (3, 1)), ((3, 0), (4, 0)), ((3, 2), (3, 1)), ((3, 2), (4, 2)), ((3, 3), (2, 3)), ((3, 3), (3, 2)), ((3, 3), (4, 3)), ((4, 0), (4, 1)), ((4, 1), (3, 1)), ((4, 1), (4, 2)), ((4, 2), (4, 3)), ]) pd = PixelData(mkpixels(ISLAND)) pd.depixel() self.assertEqual(sorted(tg.nodes()), sorted(pd.grid_graph.nodes())) self.assertEqual(sort_edges(tg.edges()), sort_edges(pd.grid_graph.edges()))
def process_file(options, filename): print "Processing %s..." % (filename, ) data = PixelData(io_data.read_pixels(filename, 'png')) base_filename = os.path.splitext(os.path.split(filename)[-1])[0] outdir = options.output_dir filetypes = [] if options.to_png: filetypes.append('PNG') if options.to_svg: filetypes.append('SVG') if options.write_pixels: for ft in filetypes: print " Writing pixels %s..." % (ft, ) writer = io_data.get_writer(data, base_filename, ft.lower()) writer.export_pixels(outdir) data.depixel() if options.write_grid: for ft in filetypes: print " Writing grid %s..." % (ft, ) writer = io_data.get_writer(data, base_filename, ft.lower()) writer.export_grid(outdir, options.draw_nodes) if options.write_shapes: for ft in filetypes: print " Writing shapes %s..." % (ft, ) writer = io_data.get_writer(data, base_filename, ft.lower()) writer.export_shapes(outdir, options.draw_nodes) if options.write_smooth: for ft in filetypes: print " Writing smooth shapes %s..." % (ft, ) writer = io_data.get_writer(data, base_filename, ft.lower()) writer.export_smooth(outdir, options.draw_nodes)