def config_writer(fname, text_string, num_loops, scale, subdiv, vertices, line_segments): config = configparser.ConfigParser() cfgfile = open(fname, 'w') #print "vertices" config.add_section('Info') config.set('Info', 'program', str('TrueTypeTracer')) config.set('Info', 'program_version', str(ttt.version())) config.set('Info', 'url', str('https://github.com/aewallin/truetype-tracer')) config.set('Info', 'Text', str(text_string)) config.set('Info', 'num_loops', str(num_loops)) config.set('Info', 'scale', str(scale)) config.set('Info', 'subdiv', str(subdiv)) config.set('Info', 'num_pointsites', str(len(vertices))) config.set('Info', 'num_linesites', str(len(line_segments))) config.add_section('PointSites') for p in vertices: print("%s %s" % (p, vertices[p])) config.set('PointSites', str(p), str((vertices[p][0], vertices[p][1]))) #print "line segments" config.add_section('LineSites') n_line = 0 for p in line_segments: config.set('LineSites', str(n_line), str((p[0], p[1]))) print("%s %s-%s" % (p, vertices[p[0]], vertices[p[1]])) n_line = n_line + 1 config.add_section('End') config.write(cfgfile) cfgfile.close()
def config_writer(fname, text_string, num_loops, scale, subdiv, vertices, line_segments): config = ConfigParser.ConfigParser() cfgfile = open(fname,'w') #print "vertices" config.add_section('Info') config.set('Info','program', str('TrueTypeTracer')) config.set('Info','program_version', str(ttt.version())) config.set('Info','url', str('https://github.com/aewallin/truetype-tracer')) config.set('Info','Text', str(text_string)) config.set('Info','num_loops', str(num_loops)) config.set('Info','scale', str(scale)) config.set('Info','subdiv', str(subdiv)) config.set('Info','num_pointsites', str(len(vertices))) config.set('Info','num_linesites', str(len(line_segments))) config.add_section('PointSites') for p in vertices: print p, vertices[p] config.set('PointSites',str(p), str( (vertices[p][0], vertices[p][1]) )) #print "line segments" config.add_section('LineSites') n_line=0 for p in line_segments: config.set('LineSites',str(n_line), str( (p[0], p[1]) )) print p, vertices[p[0]],"-",vertices[p[1]] n_line=n_line+1 config.add_section('End') config.write(cfgfile) cfgfile.close()
[segs, extents, scale] = get_scaled_segs( mytext ) print_scale= float(text_length)/float(0.6) times = insert_many_polygons(vd,segs) # insert segments into vd # count the number of segments num_segs = 0 for s in segs: num_segs = num_segs + len(s) text_length = (extents.maxx-extents.minx)*scale*print_scale text_height = (extents.maxy-extents.miny)*scale*print_scale # print comments to g-code file print "( ttt2medial.py - experimental v-carving script )" print "( TTT++",ttt.version()," )" print "( OpenVoronoi",ovd.version()," )" print "( number of polygons: ", len(segs)," )" print "( number of segments: ", num_segs ," )" print "( text length: ", text_length ," )" print "( text height: ",text_height," )" print "( VD built in %02.3f seconds = %02f us* n*log2{n} )" % ( sum(times), 1e6*float(sum(times))/(float(num_segs)*float(math.log10(num_segs)/math.log10(2))) ) print "( VD check: ", vd.check(), " )" pi = ovd.PolygonInterior( True ) # filter so that only polygon interior remains vd.filter_graph(pi) ma = ovd.MedialAxis() # filter so that only medial axis remains vd.filter_graph(ma) ngc_writer.preamble() printMedial( vd , print_scale) # the actual cutting g-code
np = 0 sum_pts = 0 segs = modify_segments(segs) for s in segs: sum_pts += len(s) print " polygon ", np, " has ", len(s), " points" np = np + 1 print "total points: ", sum_pts drawLoops(myscreen, segs, ovdvtk.yellow) # this script only draws geometry from ttt # no voronoi-diagram is created! if __name__ == "__main__": print "ttt version = ", ttt.version() # w=2500 # h=1500 # w=1920 # h=1080 # w=1024 # h=1024 w = 800 h = 600 myscreen = ovdvtk.VTKScreen(width=w, height=h) ovdvtk.drawOCLtext(myscreen, rev_text=ovd.version()) scale = 1 far = 1
[segs, extents, scale] = get_scaled_segs(mytext) print_scale = float(text_length) / float(0.6) times = insert_many_polygons(vd, segs) # insert segments into vd # count the number of segments num_segs = 0 for s in segs: num_segs = num_segs + len(s) text_length = (extents.maxx - extents.minx) * scale * print_scale text_height = (extents.maxy - extents.miny) * scale * print_scale # print comments to g-code file print "( ttt2medial.py - experimental v-carving script )" print "( TTT++", ttt.version(), " )" print "( OpenVoronoi", ovd.version(), " )" print "( number of polygons: ", len(segs), " )" print "( number of segments: ", num_segs, " )" print "( text length: ", text_length, " )" print "( text height: ", text_height, " )" print "( VD built in %02.3f seconds = %02f us* n*log2{n} )" % ( sum(times), 1e6 * float(sum(times)) / (float(num_segs) * float(math.log10(num_segs) / math.log10(2)))) print "( VD check: ", vd.check(), " )" pi = ovd.PolygonInterior( True) # filter so that only polygon interior remains vd.filter_graph(pi) ma = ovd.MedialAxis() # filter so that only medial axis remains vd.filter_graph(ma)
extents = ret[0] segs = ret[1] # translate so lower left corner is at (0,0) segs = translate(segs, -extents.minx, -extents.miny) # scale to desired length current_length = extents.maxx - extents.minx current_height = extents.maxy - extents.miny [segs, scale] = scale_segs(segs, current_length, length) # remove duplicate points segs = modify_segments(segs) return [segs, extents, scale] if __name__ == "__main__": print ttt.version() conic_subdiv = 200 seed = 42 if len(sys.argv) == 2: seed = int( sys.argv[1]) # if seed was specified on command-line, take it random.seed(seed) row_length = 15 n_rows = 10 length = 1 dx = -0.5 start_y = -0.5 current_y = start_y segs = []
def get_scaled_segs(chars, length): # generate segs with scale 1 [extents, segs] = ttt_segments(chars, 1) # translate so lower left corner is at (0,0) segs = translate(segs, -extents.minx, -extents.miny) # scale to desired length current_length = extents.maxx - extents.minx current_height = extents.maxy - extents.miny [segs, scale] = scale_segs(segs, current_length, length) # remove duplicate points segs = modify_segments(segs) return [segs, extents, scale] if __name__ == "__main__": print ttt.version() # exit() # w=2500 # h=1500 # w=1920 # h=1080 w = 1024 h = 1024 myscreen = ovdvtk.VTKScreen(width=w, height=h) ovdvtk.drawOCLtext(myscreen, rev_text=ovd.version()) scale = 1 far = 1 camPos = far
print "number of polygons: ", len(segs) np = 0 sum_pts=0 segs = modify_segments(segs) for s in segs: sum_pts+=len(s) print " polygon ",np," has ",len(s)," points" np=np+1 print "total points: ",sum_pts drawLoops(myscreen, segs, ovdvtk.yellow ) # this script only draws geometry from ttt # no voronoi-diagram is created! if __name__ == "__main__": print "ttt version = ",ttt.version() #w=2500 #h=1500 #w=1920 #h=1080 #w=1024 #h=1024 w=800 h=600 myscreen = ovdvtk.VTKScreen(width=w, height=h) ovdvtk.drawOCLtext(myscreen, rev_text=ovd.version() ) scale=1 far = 1
np = 0 sum_pts = 0 segs = modify_segments(segs) for s in segs: sum_pts += len(s) print(" polygon %s has %s points" % (np, len(s))) np = np + 1 print("total points: %s" % sum_pts) drawLoops(myscreen, segs, ovdvtk.yellow) # this script only draws geometry from ttt # no voronoi-diagram is created! if __name__ == "__main__": print("ttt version = %s" % ttt.version()) # w=2500 # h=1500 # w=1920 # h=1080 # w=1024 # h=1024 w = 800 h = 600 myscreen = ovdvtk.VTKScreen(width=w, height=h) ovdvtk.drawOCLtext(myscreen, rev_text=ovd.version()) scale = 1 far = 1
extents = ret[0] segs = ret[1] # translate so lower left corner is at (0,0) segs = translate(segs, -extents.minx, -extents.miny) # scale to desired length current_length = extents.maxx - extents.minx current_height = extents.maxy - extents.miny [segs, scale] = scale_segs(segs, current_length, length) # remove duplicate points segs = modify_segments(segs) return [segs, extents, scale] if __name__ == "__main__": print(ttt.version()) conic_subdiv = 200 seed = 42 if len(sys.argv) == 2: seed = int( sys.argv[1]) # if seed was specified on command-line, take it random.seed(seed) row_length = 15 n_rows = 10 length = 1 dx = -0.5 start_y = -0.5 current_y = start_y segs = []