def drawFrame(N=2, nframe=1): myscreen = ovdvtk.VTKScreen(width=1920, height=1080) ovdvtk.drawOCLtext(myscreen) w2if = vtk.vtkWindowToImageFilter() w2if.SetInput(myscreen.renWin) lwr = vtk.vtkPNGWriter() lwr.SetInputConnection(w2if.GetOutputPort()) # lwr.SetFileName(filename) random.seed(42) scale = 1 far = 1 camPos = far zmult = 4 myscreen.camera.SetPosition(0, -camPos / float(1000), zmult * camPos) myscreen.camera.SetClippingRange(-(zmult + 1) * camPos, (zmult + 1) * camPos) myscreen.camera.SetFocalPoint(0.0, 0, 0) vd = ovd.VoronoiDiagram(far, 120) print ovd.version() # for vtk visualization vod = ovdvtk.VD(myscreen, vd, float(scale), textscale=0.01, vertexradius=0.003) vod.drawFarCircle() Nmax = N # random points plist = randomGenerators(far, Nmax) t_before = time.time() n = 0 id_list = [] for p in plist: print n, " adding ", p id_list.append(vd.addVertexSite(p)) n = n + 1 id1 = id_list[0] id2 = id_list[1] print "add segment ", id1, " to ", id2 vd.addLineSite(id1, id2) t_after = time.time() calctime = t_after - t_before print " VD done in ", calctime, " s, ", calctime / Nmax, " s per generator" vod.setAll() myscreen.render() # writeFrame( w2if, lwr, nframe ) # myscreen.iren.Start() print "PYTHON All DONE."
def draw_vd(vd, times): #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()) w2if = vtk.vtkWindowToImageFilter() w2if.SetInput(myscreen.renWin) lwr = vtk.vtkPNGWriter() lwr.SetInput(w2if.GetOutput()) #w2if.Modified() #lwr.SetFileName("tux1.png") scale = 1 myscreen.render() far = 1 camPos = far zmult = 3 # camPos/float(1000) myscreen.camera.SetPosition(0, -camPos / float(1000), zmult * camPos) myscreen.camera.SetClippingRange(-(zmult + 1) * camPos, (zmult + 1) * camPos) myscreen.camera.SetFocalPoint(0.0, 0, 0) # for vtk visualization vod = ovdvtk.VD(myscreen, vd, float(scale), textscale=0.01, vertexradius=0.003) vod.drawFarCircle() vod.textScale = 0.02 vod.vertexRadius = 0.0031 vod.drawVertices = 0 vod.drawVertexIndex = 0 vod.drawGenerators = 0 vod.offsetEdges = 0 vd.setEdgeOffset(0.05) #times=[] #times.append( 1 ) #times.append( 1 ) vod.setVDText2(times) vod.setAll() myscreen.render() #w2if.Modified() #lwr.SetFileName("{0}.png".format(Nmax)) #lwr.Write() myscreen.iren.Start()
def test(Nmax): vd = ovd.VoronoiDiagram(1,120) print "random_linesegments.py: ",Nmax," random segments." print "in directory: ", os.getcwd() sys.stdout.flush() f1 = "../../src/test/data/randomsegments_{0}.pickle.gz".format(Nmax) f2 = "../data/randomsegments_{0}.pickle.gz".format(Nmax) filename = "" if os.path.exists( f1 ): filename = f1 # "../src/test/data/randomsegments_{0}.pickle.gz".format(Nmax) # load pre-computed segments elif os.path.exists( f2 ): filename = f2 # (produced with lineseg_dataset_generator.py) print "trying to open data file ",filename f = gzip.open(filename, 'rb') pstring = f.read() segs = pickle.loads( pstring ) f.close() id_list = [] for seg in segs: seg_id=[] seg_id.append( vd.addVertexSite( seg[0] ) ) seg_id.append( vd.addVertexSite( seg[1] ) ) id_list.append( seg_id ) print "all point-sites inserted." assert( vd.check() ) nsegs = Nmax for s in id_list: vd.addLineSite(s[0],s[1]) print "all line-sites inserted." c = vd.check() print " VD check: ", c print sys.version print ovd.version() if c: print "Test passed." #exit(0) else: print "Test failed." #exit(-1) print "end of test()"
def test(Nmax): vd = ovd.VoronoiDiagram(1, 120) print "random_linesegments.py: ", Nmax, " random segments." print "in directory: ", os.getcwd() sys.stdout.flush() f1 = "../../src/test/data/randomsegments_{0}.pickle.gz".format(Nmax) f2 = "../data/randomsegments_{0}.pickle.gz".format(Nmax) filename = "" if os.path.exists(f1): filename = f1 # "../src/test/data/randomsegments_{0}.pickle.gz".format(Nmax) # load pre-computed segments elif os.path.exists(f2): filename = f2 # (produced with lineseg_dataset_generator.py) print "trying to open data file ", filename f = gzip.open(filename, 'rb') pstring = f.read() segs = pickle.loads(pstring) f.close() id_list = [] for seg in segs: seg_id = [] seg_id.append(vd.addVertexSite(seg[0])) seg_id.append(vd.addVertexSite(seg[1])) id_list.append(seg_id) print "all point-sites inserted." assert (vd.check()) nsegs = Nmax for s in id_list: vd.addLineSite(s[0], s[1]) print "all line-sites inserted." c = vd.check() print " VD check: ", c print sys.version print ovd.version() if c: print "Test passed." #exit(0) else: print "Test failed." #exit(-1) print "end of test()"
def draw_vd(vd, times): # 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()) w2if = vtk.vtkWindowToImageFilter() w2if.SetInput(myscreen.renWin) lwr = vtk.vtkPNGWriter() lwr.SetInput(w2if.GetOutput()) # w2if.Modified() # lwr.SetFileName("tux1.png") scale = 1 myscreen.render() far = 1 camPos = far zmult = 3 # camPos/float(1000) myscreen.camera.SetPosition(0, -camPos / float(1000), zmult * camPos) myscreen.camera.SetClippingRange(-(zmult + 1) * camPos, (zmult + 1) * camPos) myscreen.camera.SetFocalPoint(0.0, 0, 0) # for vtk visualization vod = ovdvtk.VD(myscreen, vd, float(scale), textscale=0.01, vertexradius=0.003) vod.drawFarCircle() vod.textScale = 0.02 vod.vertexRadius = 0.0031 vod.drawVertices = 0 vod.drawVertexIndex = 0 vod.drawGenerators = 0 vod.offsetEdges = 0 vd.setEdgeOffset(0.05) # times=[] # times.append( 1 ) # times.append( 1 ) vod.setVDText2(times) vod.setAll() myscreen.render() # w2if.Modified() # lwr.SetFileName("{0}.png".format(Nmax)) # lwr.Write() myscreen.iren.Start()
# 2012-07-25: this reportedly hangs. import openvoronoi points = ((-0.7000000000000002, -0.5249999999990376), (0.7, -0.5249999999990376), ) print "OpenVoronoi version: ", openvoronoi.version() dia = openvoronoi.VoronoiDiagram(0.972222, 2) for p in points: ovp = openvoronoi.Point(*p) print "Adding ", ovp dia.addVertexSite(ovp) print dia print "VD OK?: ", dia.check() # aewallin, I get: """ Adding (-0.7, -0.525) Adding (0.7, -0.525) VoronoiDiagram num_vertices = 18 num_edges = 31 num_point_sites = 2 num_line_sites = 0 num_split_vertices = 0 VD OK?: True
seg.reverse() # to get interior or exterior offsets segs_mod.append(seg) # drawSegment(myscreen, seg) return segs_mod if __name__ == "__main__": # w=2500 # screen resolution for big screens # h=1500 # w=1920 # h=1080 w = 1024 h = 1024 myscreen = ovdvtk.VTKScreen(width=w, height=h) # a VTK window for drawing ovdvtk.drawOCLtext(myscreen, rev_text=ovd.version()) # the OpenVoronoi text, revision, and date scale = 1 myscreen.render() far = 1 camPos = far zmult = 3 # camPos/float(1000) myscreen.camera.SetPosition(0, -camPos / float(1000), zmult * camPos) myscreen.camera.SetClippingRange(-(zmult + 1) * camPos, (zmult + 1) * camPos) myscreen.camera.SetFocalPoint(0.0, 0, 0) vd = ovd.VoronoiDiagram(far, 120) print(ovd.version())
#drawSegment(myscreen, seg) return segs_mod if __name__ == "__main__": #w=2500 # screen resolution for big screens #h=1500 #w=1920 #h=1080 w = 1024 h = 1024 myscreen = ovdvtk.VTKScreen(width=w, height=h) # a VTK window for drawing ovdvtk.drawOCLtext( myscreen, rev_text=ovd.version()) # the OpenVoronoi text, revision, and date scale = 1 myscreen.render() far = 1 camPos = far zmult = 3 # camPos/float(1000) myscreen.camera.SetPosition(0, -camPos / float(1000), zmult * camPos) myscreen.camera.SetClippingRange(-(zmult + 1) * camPos, (zmult + 1) * camPos) myscreen.camera.SetFocalPoint(0.0, 0, 0) vd = ovd.VoronoiDiagram(far, 120) print ovd.version()
import time import vtk import math import offset2vtk if __name__ == "__main__": #w=2500 # screen resolution for big screens #h=1500 #w=1920 #h=1080 w=1024 h=1024 myscreen = ovdvtk.VTKScreen(width=w, height=h) # a VTK window for drawing ovdvtk.drawOCLtext(myscreen, rev_text=ovd.version() ) # the OpenVoronoi text, revision, and date scale=1 myscreen.render() far = 1 camPos = far zmult = 3 # camPos/float(1000) myscreen.camera.SetPosition(0, -camPos/float(1000), zmult*camPos) myscreen.camera.SetClippingRange(-(zmult+1)*camPos,(zmult+1)*camPos) myscreen.camera.SetFocalPoint(0.0, 0, 0) vd = ovd.VoronoiDiagram(far,120) print ovd.version()
# 30 416 # 20 627 # wr.cubic_biarc_subdivision = 10 # no effect? # wr.cubic_line_subdivision = 10 # no effect? # wr.setFont(0) # wr.setFontbyPath("/usr/share/fonts/truetype/freefont/FreeSerif.ttf") s3 = ttt.ttt(text, wr) exts = wr.extents # print exts segs = wr.get_segments() return (segs, exts) if __name__ == "__main__": print ovd.version() + " " + ovd.build_type() # 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 zmult = 3
d = [] d.append(key) d.append(adict[key]) l.append(d) return l if __name__ == "__main__": scale = 1 random.seed(42) far = 1 zmult = 4 vd = ovd.VoronoiDiagram(far, 120) print ovd.version() Nmax = 40000 print "calculating VD for ", Nmax, " point-sites..." plist = randomGenerators(far, Nmax) t_before = time.time() n = 0 #id_list=[] for p in plist: #print n," adding ",p vd.addVertexSite(p) n = n + 1 t_after = time.time() calctime = t_after - t_before print " VD done in ", calctime, " s, ", 1e6 * calctime / ( Nmax * (math.log(Nmax) / math.log(2))), " us per n*log2(n())"
final_lead_out(myscreen, out_tangent, in_tangent, previous_center, previous_radius, cen2, r2, previous_out1, in1) nframe = nframe + 1 # myscreen.render() if __name__ == "__main__": # 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 myscreen.render() # random.seed(42) far = 1 camPos = far zmult = 1.8 # camPos/float(1000) myscreen.camera.SetPosition(0, -camPos / float(1000), zmult * camPos) myscreen.camera.SetClippingRange(-(zmult + 1) * camPos, (zmult + 1) * camPos) myscreen.camera.SetFocalPoint(0.0, 0.22, 0) # redirect stdout to file # example with redirection of sys.stdout
# 30 416 # 20 627 # wr.cubic_biarc_subdivision = 10 # no effect? # wr.cubic_line_subdivision = 10 # no effect? # wr.set_font(0) # wr.set_font_by_path("/usr/share/fonts/truetype/freefont/FreeSerif.ttf") s3 = ttt.ttt(text, wr) exts = wr.extents # print exts segs = wr.get_segments() return (segs, exts) if __name__ == "__main__": print("%s %s" % (ovd.version(), ovd.build_type())) # 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 zmult = 3
# lwr.Write() if __name__ == "__main__": # 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()) w2if = vtk.vtkWindowToImageFilter() w2if.SetInput(myscreen.renWin) lwr = vtk.vtkPNGWriter() lwr.SetInputConnection(w2if.GetOutputPort()) # w2if.Modified() # lwr.SetFileName("tux1.png") scale = 1 myscreen.render() random.seed(42) far = 1 camPos = far zmult = 3 # camPos/float(1000)
[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 ngc_writer.postamble()
import openvoronoi as ovd import time import math import sys import pickle import gzip import ovdgenerators as gens if __name__ == "__main__": print ovd.version() far = 1 Nmax = int(math.pow(2,10)) # number of line-segments to generate print "waiting for ",Nmax," segments..", sys.stdout.flush() t_before = time.time() segs = gens.randomSegments(far,Nmax) t_after = time.time() print ".done in {0:.3f} s.".format( t_after-t_before ) filename = "randomsegments_{0}.pickle.gz".format(Nmax) pstring = pickle.dumps( segs, 2 ) # 2 is binary format f = gzip.open(filename, 'wb') f.write(pstring) f.close() print "PYTHON All DONE."
import sys import pickle import gzip if __name__ == "__main__": # size of viewport in pixels # w=2500 # h=1500 # w=1920 # h=1080 w = 1024 h = 800 myscreen = ovdvtk.VTKScreen(width=w, height=h) ovdvtk.drawOCLtext(myscreen, rev_text=ovd.version()) w2if = vtk.vtkWindowToImageFilter() # for screenshots w2if.SetInput(myscreen.renWin) lwr = vtk.vtkPNGWriter() lwr.SetInputConnection(w2if.GetOutputPort()) # w2if.Modified() # lwr.SetFileName("tux1.png") scale = 1 myscreen.render() random.seed(42) far = 1 camPos = far zmult = 3 # camPos/float(1000)
while N_offsets > 0: current_loops = offset_dia.offset(current_offset) if len(current_loops) > 0: offset_loops.extend(current_loops) N_offsets = N_offsets - 1 current_offset = current_offset + second_offset _log.info("got %d loops from openvoronoi" % len(offset_loops)) return offset_loops if __name__ == "__main__": w = 1024 h = 1024 myscreen = ovdvtk.VTKScreen(width=w, height=h) # a VTK window for drawing ovdvtk.drawOCLtext(myscreen, rev_text=openvoronoi.version() ) # the OpenVoronoi text, revision, and date # rotate camera for 2D view far = 1 camPos = far zmult = 3 # camPos/float(1000) myscreen.camera.SetPosition(0, -camPos / float(1000), zmult * camPos) myscreen.camera.SetClippingRange(-(zmult + 1) * camPos, (zmult + 1) * camPos) myscreen.camera.SetFocalPoint(0.0, 0, 0) import sys filename = "star2_scaled.dxf" offset_distance = 0.1
t_after = time.time() seg_time = t_after - t_before return [pt_time, seg_time] if __name__ == "__main__": # 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 myscreen.render() # random.seed(42) far = 1 camPos = far zmult = 1.8 # camPos/float(1000) myscreen.camera.SetPosition(0, -camPos / float(1000), zmult * camPos) myscreen.camera.SetClippingRange(-(zmult + 1) * camPos, (zmult + 1) * camPos) myscreen.camera.SetFocalPoint(0.0, 0.22, 0) # redirect stdout to file # example with redirection of sys.stdout foo = WritableObject() # a writable object
while N_offsets > 0: current_loops = offset_dia.offset(current_offset) if len(current_loops) > 0: offset_loops.extend(current_loops) N_offsets = N_offsets - 1 current_offset = current_offset + second_offset _log.info("got %d loops from openvoronoi" % len(offset_loops)) return offset_loops if __name__ == "__main__": w = 1024 h = 1024 myscreen = ovdvtk.VTKScreen(width=w, height=h) # a VTK window for drawing ovdvtk.drawOCLtext(myscreen, rev_text=openvoronoi.version()) # the OpenVoronoi text, revision, and date # rotate camera for 2D view far = 1 camPos = far zmult = 3 # camPos/float(1000) myscreen.camera.SetPosition(0, -camPos / float(1000), zmult * camPos) myscreen.camera.SetClippingRange(-(zmult + 1) * camPos, (zmult + 1) * camPos) myscreen.camera.SetFocalPoint(0.0, 0, 0) import sys filename = "star2_scaled.dxf" offset_distance = 0.1 sys.argv = ["dummy", filename, offset_distance]
# 2012-07-25: this reportedly hangs. import openvoronoi points = ((-0.7000000000000002, -0.5249999999990376), (0.7, -0.5249999999990376), ) print("OpenVoronoi version: %s" % openvoronoi.version()) dia = openvoronoi.VoronoiDiagram(0.972222, 2) for p in points: ovp = openvoronoi.Point(*p) print("Adding %s" % ovp) dia.addVertexSite(ovp) print(dia) print("VD OK?: %s" % dia.check()) # aewallin, I get: """ Adding (-0.7, -0.525) Adding (0.7, -0.525) VoronoiDiagram num_vertices = 18 num_edges = 31 num_point_sites = 2 num_line_sites = 0 num_split_vertices = 0 VD OK?: True
import gzip def drawCircle(myscreen, c, r, circlecolor): ca = ovdvtk.Circle(center=(c.x,c.y,0) , radius=r, color=circlecolor, resolution=50 ) myscreen.addActor(ca) if __name__ == "__main__": #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() ) w2if = vtk.vtkWindowToImageFilter() w2if.SetInput(myscreen.renWin) lwr = vtk.vtkPNGWriter() lwr.SetInput( w2if.GetOutput() ) #w2if.Modified() #lwr.SetFileName("tux1.png") scale=1 myscreen.render() random.seed(42) far = 1 camPos = far zmult = 3 # camPos/float(1000)
[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)
# 10 err fonts.push_back( "/usr/share/fonts/truetype/freefont/FreeSansOblique.ttf" ); s3 = ttt.ttt(text, wr) segs = wr.get_segments() return segs if __name__ == "__main__": # w=2500 # h=1500 w = 1600 h = 1024 # w=1024 # h=1024 myscreen = ovdvtk.VTKScreen(width=w, height=h) ovdvtk.drawOCLtext(myscreen, rev_text=ovd.version()) w2if = vtk.vtkWindowToImageFilter() w2if.SetInput(myscreen.renWin) lwr = vtk.vtkPNGWriter() lwr.SetInputConnection(w2if.GetOutputPort()) # w2if.Modified() # lwr.SetFileName("tux1.png") scale = 1 far = 1 camPos = far zmult = 3 myscreen.camera.SetPosition(0, -camPos / float(1000), zmult * camPos) myscreen.camera.SetClippingRange(-(zmult + 1) * camPos, (zmult + 1) * camPos)
import openvoronoi as ovd import time import math import sys import pickle import gzip import ovdgenerators as gens if __name__ == "__main__": print(ovd.version()) far = 1 Nmax = int(math.pow(2, 10)) # number of line-segments to generate print("waiting for %s segments.." % Nmax) sys.stdout.flush() t_before = time.time() segs = gens.randomSegments(far, Nmax) t_after = time.time() print(".done in {0:.3f} s.".format(t_after - t_before)) filename = "randomsegments_{0}.pickle.gz".format(Nmax) pstring = pickle.dumps(segs, 2) # 2 is binary format f = gzip.open(filename, 'wb') f.write(pstring) f.close() print("PYTHON All DONE.")