def main(filename="frame/f.png", yc=6, n=0): f = ocl.Ocode() f.set_depth(10) myscreen = camvtk.VTKScreen() myscreen.camera.SetPosition(50, 22, 40) myscreen.camera.SetFocalPoint(0, 0, 0) myscreen.camera.Azimuth(n * 0.5) # box around octree oct_cube = camvtk.Cube(center=(0, 0, 0), length=40, color=camvtk.white) oct_cube.SetWireframe() myscreen.addActor(oct_cube) # screenshot writer w2if = vtk.vtkWindowToImageFilter() w2if.SetInput(myscreen.renWin) lwr = vtk.vtkPNGWriter() lwr.SetInput(w2if.GetOutput()) arrowcenter = (1, 2, 0) xar = camvtk.Arrow(color=camvtk.red, center=arrowcenter, rotXYZ=(0, 0, 0)) myscreen.addActor(xar) yar = camvtk.Arrow(color=camvtk.green, center=arrowcenter, rotXYZ=(0, 0, 90)) myscreen.addActor(yar) zar = camvtk.Arrow(color=camvtk.blue, center=arrowcenter, rotXYZ=(0, -90, 0)) myscreen.addActor(zar) t = ocl.LinOCT() #t2 = ocl.LinOCT() t.init(3) #t2.init(3) print " after init() t :", t.str() #print " after init() t2 :", t2.str() # sphere svol = ocl.SphereOCTVolume() svol.radius = 3.2 svol.center = ocl.Point(1, 0, 3) # cube cube1 = ocl.CubeOCTVolume() cube1.side = 69 cube1.center = ocl.Point(0, 0, 0) #cylinder cylvol = ocl.CylinderOCTVolume() cylvol.p2 = ocl.Point(0, 0, 4) cylvol.radius = 4 c = ocl.CylCutter(1) c.length = 3 print "cutter length=", c.length p1 = ocl.Point(0, 0, 0) p2 = ocl.Point(1, 1.4, 0) g1vol = ocl.CylMoveOCTVolume(c, p1, p2) cyl1 = camvtk.Cylinder(center=(p1.x, p1.y, p1.z), radius=c.radius, height=c.length, rotXYZ=(90, 0, 0), color=camvtk.grey) cyl1.SetWireframe() myscreen.addActor(cyl1) cyl2 = camvtk.Cylinder(center=(p2.x, p2.y, p2.z), radius=c.radius, height=c.length, rotXYZ=(90, 0, 0), color=camvtk.grey) cyl2.SetWireframe() myscreen.addActor(cyl2) startp = camvtk.Sphere(center=(p1.x, p1.y, p1.z), radius=0.1, color=camvtk.green) myscreen.addActor(startp) endp = camvtk.Sphere(center=(p2.x, p2.y, p2.z), radius=0.1, color=camvtk.red) myscreen.addActor(endp) t.build(g1vol) #print "t2 build()" #t2.build(cube1) #print " t2 after build() ", t2.size() #t2.condense() #print " t2 after condense() ", t2.size() # original trees drawTree(myscreen, t, opacity=1, color=camvtk.green) #drawTree(myscreen,t2,opacity=1, color=camvtk.red) #print " diff12()...", #t3 = t2.operation(1,t) #print "done." #print " diff21()...", #t4 = t2.operation(2,t) #print "done." #print " intersection()...", #t5 = t2.operation(3,t) #print "done." #print " sum()...", #t6 = t2.operation(4,t) #print "done." #print " difference 1-2 t3 (blue) =", t3.size() #print " difference 2-1 t4 (yellow)=", t4.size() #print " intersection t5 (pink) =", t5.size() #print " union t6 (grey) =", t6.size() #drawTree(myscreen,t3,opacity=1, color=camvtk.blue, offset=(0,15,0)) #drawTree(myscreen,t4,opacity=1, color=camvtk.yellow,offset=(0,-15,0)) #drawTree(myscreen,t5,opacity=1, color=camvtk.pink,offset=(-15,0,0)) #drawTree(myscreen,t6,opacity=1, color=camvtk.grey,offset=(-15,-15,0)) title = camvtk.Text() title.SetPos((myscreen.width - 350, myscreen.height - 30)) title.SetText("OpenCAMLib " + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")) myscreen.addActor(title) #st2 = camvtk.Text() #ytext = "Linear OCTree set operations: difference, intersection, union" #st2.SetText(ytext) #st2.SetPos( (50, myscreen.height-30) ) #myscreen.addActor( st2) #st3 = camvtk.Text() #text = "Original OCTrees\n Ball:%d nodes\n Cube: %d nodes" % ( t.size(), t2.size() ) #st3.SetText(text) #st3.SetPos( (50, 200) ) #myscreen.addActor( st3) #st4 = camvtk.Text() #un = " Union (grey): %d nodes\n" % (t6.size()) #int = " Intersection (pink): %d nodes\n" % (t5.size()) #diff1 = " difference Cube-Ball (blue): %d nodes\n" % (t3.size()) #diff2 = " difference Ball-Cube (yellow): %d nodes\n" % (t4.size()) #text= un+int+diff1+diff2 #st4.SetText(text) #st4.SetPos( (50, 100) ) #myscreen.addActor( st4) myscreen.render() lwr.SetFileName(filename) time.sleep(0.2) #lwr.Write() myscreen.iren.Start()
def main(filename="frame/f.png"): print(ocl.revision()) myscreen = camvtk.VTKScreen() myscreen.camera.SetPosition(20, 12, 20) myscreen.camera.SetFocalPoint(0, 0, 0) # axis arrows camvtk.drawArrows(myscreen, center=(2, 2, 2)) # screenshot writer w2if = vtk.vtkWindowToImageFilter() w2if.SetInput(myscreen.renWin) lwr = vtk.vtkPNGWriter() lwr.SetInput(w2if.GetOutput()) c = ocl.CylCutter(1) # cutter c.length = 3 print("cutter length=", c.length) p1 = ocl.CLPoint(-0.2, -0.2, 0.2) # start of move p2 = ocl.CLPoint(-0.2, 0.2, 0.0) # end of move p3 = ocl.CLPoint(0.5, 0.0, -0.5) clpoints = [] clpoints.append(p1) clpoints.append(p2) clpoints.append(p3) f = ocl.Ocode() f.set_depth(6) # depth and scale set here. f.set_scale(1) # cube cube1 = ocl.CubeOCTVolume() cube1.side = 2.123 cube1.center = ocl.Point(0, 0, 0) cube1.calcBB() stock = ocl.LinOCT() stock.init(3) stock.build(cube1) # draw initial octree tlist = pyocl.octree2trilist(stock) surf = camvtk.STLSurf(triangleList=tlist) myscreen.addActor(surf) Nmoves = len(clpoints) print(Nmoves, "CL-points to process") for n in range(0, Nmoves - 1): #if n<Nmoves-1: print(n, " to ", n + 1) startp = clpoints[n] endp = clpoints[n + 1] sweep = ocl.LinOCT() sweep.init(3) g1vol = ocl.CylMoveOCTVolume(c, ocl.Point(startp.x, startp.y, startp.z), ocl.Point(endp.x, endp.y, endp.z)) camvtk.drawCylCutter(myscreen, c, startp) camvtk.drawCylCutter(myscreen, c, endp) myscreen.addActor( camvtk.Line(p1=(startp.x, startp.y, startp.z), p2=(endp.x, endp.y, endp.z), color=camvtk.red)) sweep.build(g1vol) stock.diff(sweep) myscreen.removeActor(surf) tlist = pyocl.octree2trilist(stock) surf = camvtk.STLSurf(triangleList=tlist) surf.SetColor(camvtk.cyan) surf.SetOpacity(1.0) myscreen.addActor(surf) myscreen.render() time.sleep(0.2) #exit() # draw trees #print "drawing trees" #camvtk.drawTree2(myscreen, stock, opacity=1, color=camvtk.cyan) # box around octree oct_cube = camvtk.Cube(center=(0, 0, 0), length=4 * f.get_scale(), color=camvtk.white) oct_cube.SetWireframe() myscreen.addActor(oct_cube) # OCL text title = camvtk.Text() title.SetPos((myscreen.width - 350, myscreen.height - 30)) title.SetText("OpenCAMLib " + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")) myscreen.addActor(title) print(" render()...", ) myscreen.render() print("done.") lwr.SetFileName(filename) time.sleep(0.2) #lwr.Write() myscreen.iren.Start()
def main(filename="frame/f.png",yc=6, n=0): print(ocl.revision()) f=ocl.Ocode() f.set_depth(7) # depth and scale set here. f.set_scale(1) myscreen = camvtk.VTKScreen() myscreen.camera.SetPosition(50, 22, 40) myscreen.camera.SetFocalPoint(0,0, 0) myscreen.camera.Azimuth( n*0.5 ) # box around octree oct_cube = camvtk.Cube(center=(0,0,0), length=4*f.get_scale(), color=camvtk.white) oct_cube.SetWireframe() myscreen.addActor(oct_cube) # screenshot writer w2if = vtk.vtkWindowToImageFilter() w2if.SetInput(myscreen.renWin) lwr = vtk.vtkPNGWriter() lwr.SetInput( w2if.GetOutput() ) # X Y Z arrows arrowcenter=(1,2,0) xar = camvtk.Arrow(color=camvtk.red, center=arrowcenter, rotXYZ=(0,0,0)) myscreen.addActor(xar) yar = camvtk.Arrow(color=camvtk.green, center=arrowcenter, rotXYZ=(0,0,90)) myscreen.addActor(yar) zar = camvtk.Arrow(color=camvtk.blue, center=arrowcenter, rotXYZ=(0,-90,0)) myscreen.addActor(zar) t = ocl.LinOCT() t2 = ocl.LinOCT() t.init(5) t2.init(4) print(" after init() t :", t.str()) print(" after init() t2 :", t2.str()) c = ocl.CylCutter(1) # cutter c.length = 3 print("cutter length=", c.length) p1 = ocl.Point(-0.2,-0.2,0.2) # start of move p2 = ocl.Point(1.5,1.5,-1) # end of move # volume of g1 move g1vol = ocl.CylMoveOCTVolume(c, p1, p2) # sphere svol = ocl.SphereOCTVolume() svol.radius=1 svol.center = ocl.Point(0,0,1) svol.calcBB() # cube cube1 = ocl.CubeOCTVolume() cube1.side=2.123 cube1.center = ocl.Point(0,0,0) cube1.calcBB() #cylinder volume at start of move cylvol = ocl.CylinderOCTVolume() cylvol.p1 = ocl.Point(p1) cylvol.p2 = ocl.Point(p1)+ocl.Point(0,0,c.length) cylvol.radius= c.radius cylvol.calcBB() # draw exact cylinder cp = 0.5*(cylvol.p1 + cylvol.p2) height = (cylvol.p2-cylvol.p1).norm() cylvolactor = camvtk.Cylinder(center=(cp.x, cp.y, cp.z-float(height)/2), radius = cylvol.radius, height=height, rotXYZ=(90,0,0)) cylvolactor.SetWireframe() myscreen.addActor(cylvolactor) # cylinder at start of move #drawCylCutter(myscreen, c, p1) # cylinder at end of move drawCylCutter(myscreen, c, p2) # green ball at start of move startp = camvtk.Sphere(center=(p1.x,p1.y,p1.z), radius=0.1, color=camvtk.green) myscreen.addActor(startp) # red ball at end of move endp = camvtk.Sphere(center=(p2.x,p2.y,p2.z), radius=0.1, color=camvtk.red) myscreen.addActor(endp) # build g1 tree t_before = time.time() t.build( g1vol ) t_after = time.time() print("g1 build took ", t_after-t_before," s") # build cube t_before = time.time() t2.build( cube1 ) t_after = time.time() print("cube build took ", t_after-t_before," s") #t.sort() #t2.sort() print("calling diff()...",) t_before = time.time() #dt = t2.operation(1,t) t2.diff(t) t_after = time.time() print("done.") print("diff took ", t_after-t_before," s") print("diff has ", t2.size()," nodes") # original trees print("drawing trees") drawTree2(myscreen,t,opacity=1, color=camvtk.green) drawTree2(myscreen,t2,opacity=0.2, color=camvtk.cyan) drawTree2(myscreen,t2,opacity=1, color=camvtk.cyan, offset=(5,0,0)) # elliptical tube pmax = p1 + 1.5* (p2-p1) pmin = p1 - 0.5* (p2-p1) myscreen.addActor( camvtk.Sphere(center=(pmax.x,pmax.y,pmax.z), radius=0.1, color=camvtk.lgreen) ) myscreen.addActor( camvtk.Sphere(center=(pmin.x,pmin.y,pmin.z), radius=0.1, color=camvtk.pink) ) aaxis = pmin + ocl.Point(-0.353553, 0.353553, 0) baxis = pmin + ocl.Point(0.0243494, 0.0243494, 0.126617) myscreen.addActor( camvtk.Sphere(center=(aaxis.x,aaxis.y,aaxis.z), radius=0.1, color=camvtk.orange) ) myscreen.addActor( camvtk.Sphere(center=(baxis.x,baxis.y,baxis.z), radius=0.1, color=camvtk.yellow) ) title = camvtk.Text() title.SetPos( (myscreen.width-350, myscreen.height-30) ) title.SetText("OpenCAMLib " + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")) myscreen.addActor(title) print(" render()...",) myscreen.render() print("done.") lwr.SetFileName(filename) time.sleep(0.2) #lwr.Write() myscreen.iren.Start()
def main(filename="frame/f.png",yc=6, n=0): f=ocl.Ocode() f.set_depth(9) f.set_scale(5) myscreen = camvtk.VTKScreen() myscreen.camera.SetPosition(50, 22, 40) myscreen.camera.SetFocalPoint(0,0, 0) myscreen.camera.Azimuth( n*0.5 ) # box around octree oct_cube = camvtk.Cube(center=(0,0,0), length=4*f.get_scale(), color=camvtk.white) oct_cube.SetWireframe() myscreen.addActor(oct_cube) # screenshot writer w2if = vtk.vtkWindowToImageFilter() w2if.SetInput(myscreen.renWin) lwr = vtk.vtkPNGWriter() lwr.SetInput( w2if.GetOutput() ) arrowcenter=(1,2,0) xar = camvtk.Arrow(color=camvtk.red, center=arrowcenter, rotXYZ=(0,0,0)) myscreen.addActor(xar) yar = camvtk.Arrow(color=camvtk.green, center=arrowcenter, rotXYZ=(0,0,90)) myscreen.addActor(yar) zar = camvtk.Arrow(color=camvtk.blue, center=arrowcenter, rotXYZ=(0,-90,0)) myscreen.addActor(zar) """ dl = myscreen.GetLights() print("original default light:") print(dl) print("nextitem()") l1 = dl.GetNextItem() print(" light:") print(l1) #print myscreen.GetLights() lights = vtk.vtkLightCollection() l = myscreen.MakeLight() l2 = myscreen.MakeLight() #myscreen.RemoveAllLights() l.SetAmbientColor(0.5, 0.5, 0.5) l.SetPosition(0,0,20) l.SetConeAngle(360) l2.SetPosition(0,0,-20) l2.SetConeAngle(360) l2.SetIntensity(0.5) myscreen.AddLight(l) myscreen.AddLight(l2) #myscreen.SetLightCollection(lights) llist = myscreen.GetLights() li = llist.GetNextItem() print(" new list of lights:") print(li) #for li in llist: # print(li) print(" newly created light:") print(l) dl = myscreen.GetLights() print("NEW light:") print(dl) """ t = ocl.LinOCT() t2 = ocl.LinOCT() t.init(0) t2.init(1) #drawTree2(myscreen, t, opacity=0.2) #myscreen.render() #myscreen.iren.Start() #exit() print(" after init() t :", t.str()) print(" after init() t2 :", t2.str()) # sphere svol = ocl.SphereOCTVolume() svol.radius=3.2 svol.center = ocl.Point(1,0,3) svol.calcBB() # cube cube1 = ocl.CubeOCTVolume() cube1.side=2.123 cube1.center = ocl.Point(0,0,0) cube1.calcBB() #cylinder cylvol = ocl.CylinderOCTVolume() cylvol.p2 = ocl.Point(3,4,-5) cylvol.radius= 2 cylvol.calcBB() # draw exact cylinder cp = 0.5*(cylvol.p1 + cylvol.p2) height = (cylvol.p2-cylvol.p1).norm() cylvolactor = camvtk.Cylinder(center=(cp.x, cp.y, cp.z-float(height)/2), radius = cylvol.radius, height=height, rotXYZ=(90,0,0)) cylvolactor.SetWireframe() #myscreen.addActor(cylvolactor) c = ocl.CylCutter(2) c.length = 3 print("cutter length=", c.length) p1 = ocl.Point(-1,-2,0) p2 = ocl.Point(1,2.0,0) g1vol = ocl.CylMoveOCTVolume(c, p1, p2) cyl1 = camvtk.Cylinder(center=(p1.x,p1.y,p1.z), radius=c.radius, height=c.length, rotXYZ=(90,0,0), color=camvtk.grey) cyl1.SetWireframe() myscreen.addActor(cyl1) cyl2 = camvtk.Cylinder(center=(p2.x,p2.y,p2.z), radius=c.radius, height=c.length, rotXYZ=(90,0,0), color=camvtk.grey) cyl2.SetWireframe() myscreen.addActor(cyl2) startp = camvtk.Sphere(center=(p1.x,p1.y,p1.z), radius=0.1, color=camvtk.green) myscreen.addActor(startp) endp = camvtk.Sphere(center=(p2.x,p2.y,p2.z), radius=0.1, color=camvtk.red) myscreen.addActor(endp) t.build( g1vol ) t2.build( cube1) print("calling diff()...",) dt = t2.operation(1,t) print("done.") # set Cylinde bounding-box """ cylvol.bb.maxx = 1.23 cylvol.bb.minx = -0.2 cylvol.bb.maxy = 1.23 cylvol.bb.miny = -0.2 cylvol.bb.maxz = 1.23 cylvol.bb.minz = -0.2 """ drawBB( myscreen, g1vol) #print cylvol.bb.maxx #print "t2 build()" #t2.build(cube1) #print " t2 after build() ", t2.size() #t2.condense() #print " t2 after condense() ", t2.size() # original trees drawTree2(myscreen,t,opacity=1, color=camvtk.green) drawTree2(myscreen,t2,opacity=1, color=camvtk.cyan) drawTree2(myscreen,dt,opacity=1, color=camvtk.cyan, offset=(5,0,0)) """ for n in range(0,30): tp = ocl.Point(2.5,2.5,2-n*0.3) tpc = camvtk.black if (cylvol.isInside(tp)): tpc = camvtk.red else: tpc = camvtk.cyan tp_sphere = camvtk.Sphere(center=(tp.x,tp.y,tp.z), radius=0.1, color= tpc) myscreen.addActor(tp_sphere) """ #drawTree(myscreen,t2,opacity=1, color=camvtk.red) #print " diff12()...", #t3 = t2.operation(1,t) #print "done." #print " diff21()...", #t4 = t2.operation(2,t) #print "done." #print " intersection()...", #t5 = t2.operation(3,t) #print "done." #print " sum()...", #t6 = t2.operation(4,t) #print "done." #print " difference 1-2 t3 (blue) =", t3.size() #print " difference 2-1 t4 (yellow)=", t4.size() #print " intersection t5 (pink) =", t5.size() #print " union t6 (grey) =", t6.size() #drawTree(myscreen,t3,opacity=1, color=camvtk.blue, offset=(0,15,0)) #drawTree(myscreen,t4,opacity=1, color=camvtk.yellow,offset=(0,-15,0)) #drawTree(myscreen,t5,opacity=1, color=camvtk.pink,offset=(-15,0,0)) #drawTree(myscreen,t6,opacity=1, color=camvtk.grey,offset=(-15,-15,0)) title = camvtk.Text() title.SetPos( (myscreen.width-350, myscreen.height-30) ) title.SetText("OpenCAMLib " + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")) myscreen.addActor(title) #st2 = camvtk.Text() #ytext = "Linear OCTree set operations: difference, intersection, union" #st2.SetText(ytext) #st2.SetPos( (50, myscreen.height-30) ) #myscreen.addActor( st2) #st3 = camvtk.Text() #text = "Original OCTrees\n Ball:%d nodes\n Cube: %d nodes" % ( t.size(), t2.size() ) #st3.SetText(text) #st3.SetPos( (50, 200) ) #myscreen.addActor( st3) #st4 = camvtk.Text() #un = " Union (grey): %d nodes\n" % (t6.size()) #int = " Intersection (pink): %d nodes\n" % (t5.size()) #diff1 = " difference Cube-Ball (blue): %d nodes\n" % (t3.size()) #diff2 = " difference Ball-Cube (yellow): %d nodes\n" % (t4.size()) #text= un+int+diff1+diff2 #st4.SetText(text) #st4.SetPos( (50, 100) ) #myscreen.addActor( st4) print(" render()...",) myscreen.render() print("done.") lwr.SetFileName(filename) time.sleep(0.2) #lwr.Write() myscreen.iren.Start()
def main(filename="frame/f.png", yc=6, n=0): print ocl.revision() f = ocl.Ocode() f.set_depth(7) f.set_scale(1) myscreen = camvtk.VTKScreen() myscreen.camera.SetPosition(50, 22, 40) myscreen.camera.SetFocalPoint(0, 0, 0) myscreen.camera.Azimuth(n * 0.5) # box around octree oct_cube = camvtk.Cube(center=(0, 0, 0), length=4 * f.get_scale(), color=camvtk.white) oct_cube.SetWireframe() myscreen.addActor(oct_cube) # screenshot writer w2if = vtk.vtkWindowToImageFilter() w2if.SetInput(myscreen.renWin) lwr = vtk.vtkPNGWriter() lwr.SetInput(w2if.GetOutput()) arrowcenter = (1, 2, 0) xar = camvtk.Arrow(color=camvtk.red, center=arrowcenter, rotXYZ=(0, 0, 0)) myscreen.addActor(xar) yar = camvtk.Arrow(color=camvtk.green, center=arrowcenter, rotXYZ=(0, 0, 90)) myscreen.addActor(yar) zar = camvtk.Arrow(color=camvtk.blue, center=arrowcenter, rotXYZ=(0, -90, 0)) myscreen.addActor(zar) t = ocl.LinOCT() t2 = ocl.LinOCT() t.init(0) #exit() t2.init(2) #drawTree2(myscreen, t, opacity=0.2) #myscreen.render() #myscreen.iren.Start() #exit() print " after init() t :", t.str() #print " after init() t2 :", t2.str() # sphere svol = ocl.SphereOCTVolume() svol.radius = 1 svol.center = ocl.Point(0, 0, 1) svol.calcBB() # cube cube1 = ocl.CubeOCTVolume() cube1.side = 2.123 cube1.center = ocl.Point(0, 0, 0) cube1.calcBB() #cylinder cylvol = ocl.CylinderOCTVolume() cylvol.p2 = ocl.Point(1, 5, -2) cylvol.radius = 0.4 cylvol.calcBB() # draw exact cylinder cp = 0.5 * (cylvol.p1 + cylvol.p2) height = (cylvol.p2 - cylvol.p1).norm() cylvolactor = camvtk.Cylinder(center=(cp.x, cp.y, cp.z - float(height) / 2), radius=cylvol.radius, height=height, rotXYZ=(90, 0, 0)) cylvolactor.SetWireframe() #myscreen.addActor(cylvolactor) c = ocl.CylCutter(1) c.length = 3 print "cutter length=", c.length p1 = ocl.Point(0.2, 0.2, 0) p2 = ocl.Point(1.5, 1.5, -1) g1vol = ocl.CylMoveOCTVolume(c, p1, p2) cyl1 = camvtk.Cylinder(center=(p1.x, p1.y, p1.z), radius=c.radius, height=c.length, rotXYZ=(90, 0, 0), color=camvtk.grey) cyl1.SetWireframe() myscreen.addActor(cyl1) cyl2 = camvtk.Cylinder(center=(p2.x, p2.y, p2.z), radius=c.radius, height=c.length, rotXYZ=(90, 0, 0), color=camvtk.grey) cyl2.SetWireframe() myscreen.addActor(cyl2) startp = camvtk.Sphere(center=(p1.x, p1.y, p1.z), radius=0.1, color=camvtk.green) myscreen.addActor(startp) endp = camvtk.Sphere(center=(p2.x, p2.y, p2.z), radius=0.1, color=camvtk.red) myscreen.addActor(endp) #t.build( g1vol ) t_before = time.time() #t.build( g1vol ) t.build(svol) t_after = time.time() print "build took ", t_after - t_before, " s" t_before = time.time() t2.build(cube1) t_after = time.time() print "build took ", t_after - t_before, " s" #t.sort() #t2.sort() print "calling diff()...", t_before = time.time() #dt = t2.operation(1,t) t2.diff(t) t_after = time.time() print "done." print "diff took ", t_after - t_before, " s" print "diff has ", t2.size(), " nodes" #drawBB( myscreen, g1vol) #print "drawBB() done" # original trees print "drawing trees" drawTree2(myscreen, t, opacity=1, color=camvtk.green) drawTree2(myscreen, t2, opacity=0.2, color=camvtk.cyan) drawTree2(myscreen, t2, opacity=1, color=camvtk.cyan, offset=(5, 0, 0)) # box-volume #cor = g1vol.box.corner #v1 = g1vol.box.v1 + cor #v2 = g1vol.box.v2 + cor #v3 = g1vol.box.v3 + cor #myscreen.addActor( camvtk.Sphere(center=(cor.x,cor.y,cor.z), radius=0.1, color=camvtk.red) ) #myscreen.addActor( camvtk.Sphere(center=(v1.x,v1.y,v1.z), radius=0.1, color=camvtk.blue) ) #myscreen.addActor( camvtk.Sphere(center=(v2.x,v2.y,v2.z), radius=0.1, color=camvtk.cyan) ) #myscreen.addActor( camvtk.Sphere(center=(v3.x,v3.y,v3.z), radius=0.1, color=camvtk.pink) ) # elliptical tube pmax = p1 + 1.5 * (p2 - p1) pmin = p1 - 0.5 * (p2 - p1) myscreen.addActor( camvtk.Sphere(center=(pmax.x, pmax.y, pmax.z), radius=0.1, color=camvtk.lgreen)) myscreen.addActor( camvtk.Sphere(center=(pmin.x, pmin.y, pmin.z), radius=0.1, color=camvtk.pink)) aaxis = pmin + ocl.Point(-0.353553, 0.353553, 0) baxis = pmin + ocl.Point(0.0243494, 0.0243494, 0.126617) myscreen.addActor( camvtk.Sphere(center=(aaxis.x, aaxis.y, aaxis.z), radius=0.1, color=camvtk.orange)) myscreen.addActor( camvtk.Sphere(center=(baxis.x, baxis.y, baxis.z), radius=0.1, color=camvtk.yellow)) ##camvtk.Cylinder(center=(pmin.x,pmin.y,pmin.z), radius=0.1, color=camvtk.pink) """ for n in xrange(0,30): tp = ocl.Point(2.5,2.5,2-n*0.3) tpc = camvtk.black if (cylvol.isInside(tp)): tpc = camvtk.red else: tpc = camvtk.cyan tp_sphere = camvtk.Sphere(center=(tp.x,tp.y,tp.z), radius=0.1, color= tpc) myscreen.addActor(tp_sphere) """ #drawTree(myscreen,t2,opacity=1, color=camvtk.red) #print " diff12()...", #t3 = t2.operation(1,t) #print "done." #print " diff21()...", #t4 = t2.operation(2,t) #print "done." #print " intersection()...", #t5 = t2.operation(3,t) #print "done." #print " sum()...", #t6 = t2.operation(4,t) #print "done." #print " difference 1-2 t3 (blue) =", t3.size() #print " difference 2-1 t4 (yellow)=", t4.size() #print " intersection t5 (pink) =", t5.size() #print " union t6 (grey) =", t6.size() #drawTree(myscreen,t3,opacity=1, color=camvtk.blue, offset=(0,15,0)) #drawTree(myscreen,t4,opacity=1, color=camvtk.yellow,offset=(0,-15,0)) #drawTree(myscreen,t5,opacity=1, color=camvtk.pink,offset=(-15,0,0)) #drawTree(myscreen,t6,opacity=1, color=camvtk.grey,offset=(-15,-15,0)) title = camvtk.Text() title.SetPos((myscreen.width - 350, myscreen.height - 30)) title.SetText("OpenCAMLib " + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")) myscreen.addActor(title) #st2 = camvtk.Text() #ytext = "Linear OCTree set operations: difference, intersection, union" #st2.SetText(ytext) #st2.SetPos( (50, myscreen.height-30) ) #myscreen.addActor( st2) #st3 = camvtk.Text() #text = "Original OCTrees\n Ball:%d nodes\n Cube: %d nodes" % ( t.size(), t2.size() ) #st3.SetText(text) #st3.SetPos( (50, 200) ) #myscreen.addActor( st3) #st4 = camvtk.Text() #un = " Union (grey): %d nodes\n" % (t6.size()) #int = " Intersection (pink): %d nodes\n" % (t5.size()) #diff1 = " difference Cube-Ball (blue): %d nodes\n" % (t3.size()) #diff2 = " difference Ball-Cube (yellow): %d nodes\n" % (t4.size()) #text= un+int+diff1+diff2 #st4.SetText(text) #st4.SetPos( (50, 100) ) #myscreen.addActor( st4) print " render()...", myscreen.render() print "done." lwr.SetFileName(filename) time.sleep(0.2) #lwr.Write() myscreen.iren.Start()
def main(filename="frame/f.png"): print(ocl.version()) myscreen = camvtk.VTKScreen() myscreen.camera.SetPosition(-15, -8, 15) myscreen.camera.SetFocalPoint(5, 5, 0) # axis arrows camvtk.drawArrows(myscreen, center=(-1, -1, 0)) # screenshot writer w2if = vtk.vtkWindowToImageFilter() w2if.SetInput(myscreen.renWin) lwr = vtk.vtkPNGWriter() lwr.SetInput(w2if.GetOutput()) c = ocl.CylCutter(1, 4) # cutter c.length = 3 print("cutter length=", c.length) # generate CL-points stl = camvtk.STLSurf("../stl/gnu_tux_mod.stl") polydata = stl.src.GetOutput() s = ocl.STLSurf() camvtk.vtkPolyData2OCLSTL(polydata, s) print("STL surface read,", s.size(), "triangles") print(s.getBounds()) #exit() minx = 0 dx = 0.1 maxx = 9 miny = 0 dy = 0.4 maxy = 12 z = -17 # this generates a list of CL-points in a grid clpoints = pyocl.CLPointGridZigZag(minx, dx, maxx, miny, dy, maxy, z) print("generated grid with", len(clpoints), " CL-points") # batchdropcutter bdc = ocl.BatchDropCutter() bdc.setSTL(s) bdc.setCutter(c) for p in clpoints: bdc.appendPoint(p) t_before = time.time() print("threads=", bdc.getThreads()) bdc.run() t_after = time.time() calctime = t_after - t_before print(" done in ", calctime, " s") clpoints = bdc.getCLPoints() # filter print("filtering. before filter we have", len(clpoints), "cl-points") t_before = time.time() f = ocl.LineCLFilter() f.setTolerance(0.001) for p in clpoints: f.addCLPoint(p) f.run() clpts = f.getCLPoints() calctime = time.time() - t_before print("after filtering we have", len(clpts), "cl-points") print(" done in ", calctime, " s") #exit() # stupid init code ocode = ocl.Ocode() tree_maxdepth = 10 ocode.set_depth(tree_maxdepth) # depth and scale set here. ocode.set_scale(10) # cube stockvol = ocl.BoxOCTVolume() stockvol.corner = ocl.Point(0, 0, -0.5) stockvol.v1 = ocl.Point(9, 0, 0) stockvol.v2 = ocl.Point(0, 12, 0) stockvol.v3 = ocl.Point(0, 0, 3.5) stockvol.calcBB() t_before = time.time() stock = ocl.LinOCT() stock.init(0) stock.build(stockvol) calctime = time.time() - t_before print(" stock built in ", calctime, " s, stock.size()=", stock.size()) # draw initial octree #tlist = pyocl.octree2trilist(stock) #surf = camvtk.STLSurf(triangleList=tlist) #myscreen.addActor(surf) # draw initial cutter #startp = ocl.Point(0,0,0) #cyl = camvtk.Cylinder(center=(startp.x,startp.y,startp.z), radius=c.radius, # height=c.length, # rotXYZ=(90,0,0), color=camvtk.grey) #cyl.SetWireframe() #myscreen.addActor(cyl) timetext = camvtk.Text() timetext.SetPos((myscreen.width - 300, myscreen.height - 30)) myscreen.addActor(timetext) ocltext = camvtk.Text() ocltext.SetPos((myscreen.width - 300, myscreen.height - 60)) myscreen.addActor(ocltext) ocltext.SetText("OpenCAMLib") octtext = camvtk.Text() octtext.SetPos((myscreen.width - 300, myscreen.height - 90)) myscreen.addActor(octtext) octtext.SetText("Octree cutting-simulation") infotext = camvtk.Text() infotext.SetPos((myscreen.width - 300, myscreen.height - 180)) myscreen.addActor(infotext) Nmoves = len(clpts) print(Nmoves, "CL-points to process") for n in range(0, Nmoves - 1): timetext.SetText(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")) #if n<Nmoves-1: print(n, " to ", n + 1, " of ", Nmoves) startp = clpts[n] # start of move endp = clpts[n + 1] # end of move #t_before = time.time() sweep = ocl.LinOCT() sweep.init(0) #calctime = time.time()-t_before #print " sweep-init done in ", calctime," s, sweep.size()=",sweep.size() g1vol = ocl.CylMoveOCTVolume(c, ocl.Point(startp.x, startp.y, startp.z), ocl.Point(endp.x, endp.y, endp.z)) t_before = time.time() sweep.build(g1vol) calctime = time.time() - t_before print(" sweep-build done in ", calctime, " s, sweep.size()=", sweep.size()) # draw cutter cyl1 = camvtk.Cylinder(center=(startp.x, startp.y, startp.z), radius=c.radius, height=c.length, rotXYZ=(90, 0, 0), color=camvtk.lgreen) cyl1.SetWireframe() #myscreen.addActor(cyl1) cyl2 = camvtk.Cylinder(center=(endp.x, endp.y, endp.z), radius=c.radius, height=c.length, rotXYZ=(90, 0, 0), color=camvtk.pink) cyl2.SetWireframe() #myscreen.addActor(cyl2) #camvtk.drawCylCutter(myscreen, c, startp) #camvtk.drawCylCutter(myscreen, c, endp) myscreen.addActor( camvtk.Line(p1=(startp.x, startp.y, startp.z), p2=(endp.x, endp.y, endp.z), color=camvtk.red)) #camvtk.drawTree2(myscreen,sweep,color=camvtk.red,opacity=0.5) t_before = time.time() stock.diff(sweep) calctime = time.time() - t_before print(" diff done in ", calctime, " s, stock.size()", stock.size()) info = "tree-depth:%i \nmove: %i \nstock-nodes: %i \nsweep-nodes: %i" % ( tree_maxdepth, n, stock.size(), sweep.size()) infotext.SetText(info) if ((n != 0 and n % 10 == 0) or n == Nmoves - 2): # draw only every m:th frame # sweep surface t_before = time.time() #sweep_tlist = pyocl.octree2trilist(sweep) sweep_tlist = sweep.get_triangles() sweepsurf = camvtk.STLSurf(triangleList=sweep_tlist) sweepsurf.SetColor(camvtk.red) sweepsurf.SetOpacity(0.1) myscreen.addActor(sweepsurf) calctime = time.time() - t_before print(" sweepsurf-render ", calctime, " s") # stock surface t_before = time.time() #tlist = pyocl.octree2trilist(stock) tlist = stock.get_triangles() stocksurf = camvtk.STLSurf(triangleList=tlist) stocksurf.SetColor(camvtk.cyan) stocksurf.SetOpacity(1.0) myscreen.addActor(stocksurf) calctime = time.time() - t_before print(" stocksurf-render ", calctime, " s") #time.sleep(1.1) # write screenshot to disk lwr.SetFileName("frames/tux_frame" + ('%06d' % n) + ".png") #lwr.SetFileName(filename) t_before = time.time() # time the render process myscreen.render() w2if.Modified() lwr.Write() calctime = time.time() - t_before print(" render ", calctime, " s") #myscreen.render() #time.sleep(0.1) myscreen.removeActor(sweepsurf) if n != (Nmoves - 2): myscreen.removeActor(stocksurf) #myscreen.removeActor(cyl1) #myscreen.removeActor(cyl2) #myscreen.render() #time.sleep(0.1) print(" render()...", ) myscreen.render() print("done.") #time.sleep(0.2) myscreen.iren.Start()