def write_zig_gcode_file(filename, n_triangles, t1,n1,tol,t2,n2, toolpath): ngc_writer.clearance_height= 5 # XY rapids at this height ngc_writer.feed_height = 3 # use z plunge-feed below this height ngc_writer.feed = 200 # feedrate ngc_writer.plunge_feed = 100 # plunge feedrate ngc_writer.metric = False # metric/inch flag ngc_writer.comment( " OpenCAMLib %s" % ocl.version() ) # git version-tag # it is probably useful to include this in all g-code output, so that bugs/problems can be tracked ngc_writer.comment( " STL surface: %s" % filename ) ngc_writer.comment( " triangles: %d" % n_triangles ) ngc_writer.comment( " OpenCamLib::AdaptivePathDropCutter run took %.2f s" % t1 ) ngc_writer.comment( " got %d raw CL-points " % n1 ) ngc_writer.comment( " filtering to tolerance %.4f " % ( tol ) ) ngc_writer.comment( " got %d filtered CL-points. Filter done in %.3f s " % ( n2 , t2 ) ) ngc_writer.preamble() # a "Zig" or one-way parallel finish path # 1) lift to clearance height # 2) XY rapid to start of path # 3) plunge to correct z-depth # 4) feed along path until end for path in toolpath: ngc_writer.pen_up() first_pt = path[0] ngc_writer.xy_rapid_to( first_pt.x, first_pt.y ) ngc_writer.pen_down( first_pt.z ) for p in path[1:]: ngc_writer.line_to(p.x,p.y,p.z) ngc_writer.postamble() # end of program
def write_zig_gcode_file(filename, n_triangles, t1, n1, tol, t2, n2, toolpath): ngc_writer.clearance_height = 5 # XY rapids at this height ngc_writer.feed_height = 3 # use z plunge-feed below this height ngc_writer.feed = 200 # feedrate ngc_writer.plunge_feed = 100 # plunge feedrate ngc_writer.metric = False # metric/inch flag ngc_writer.comment(" OpenCAMLib %s" % ocl.version()) # git version-tag # it is probably useful to include this in all g-code output, so that bugs/problems can be tracked ngc_writer.comment(" STL surface: %s" % filename) ngc_writer.comment(" triangles: %d" % n_triangles) ngc_writer.comment(" OpenCamLib::AdaptivePathDropCutter run took %.2f s" % t1) ngc_writer.comment(" got %d raw CL-points " % n1) ngc_writer.comment(" filtering to tolerance %.4f " % (tol)) ngc_writer.comment(" got %d filtered CL-points. Filter done in %.3f s " % (n2, t2)) ngc_writer.preamble() # a "Zig" or one-way parallel finish path # 1) lift to clearance height # 2) XY rapid to start of path # 3) plunge to correct z-depth # 4) feed along path until end for path in toolpath: ngc_writer.pen_up() first_pt = path[0] ngc_writer.xy_rapid_to(first_pt.x, first_pt.y) ngc_writer.pen_down(first_pt.z) for p in path[1:]: ngc_writer.line_to(p.x, p.y, p.z) ngc_writer.postamble() # end of program
def drawScreen(a, b, c, filename, write_flag): print(ocl.version()) myscreen = camvtk.VTKScreen() #a = ocl.Point(0,1,0.3) myscreen.addActor(camvtk.Point(center=(a.x, a.y, a.z), color=(1, 0, 1))) #b = ocl.Point(1,0.5,0.3) myscreen.addActor(camvtk.Point(center=(b.x, b.y, b.z), color=(1, 0, 1))) #c = ocl.Point(-0.1,0.3,0.0) myscreen.addActor(camvtk.Point(center=(c.x, c.y, c.z), color=(1, 0, 1))) myscreen.addActor(camvtk.Line(p1=(a.x, a.y, a.z), p2=(c.x, c.y, c.z))) myscreen.addActor(camvtk.Line(p1=(c.x, c.y, c.z), p2=(b.x, b.y, b.z))) myscreen.addActor(camvtk.Line(p1=(a.x, a.y, a.z), p2=(b.x, b.y, b.z))) t = ocl.Triangle(b, c, a) s = ocl.STLSurf() s.addTriangle(t) # a one-triangle STLSurf zheights = [ -0.3, -0.2, -0.1, -0.05, 0.0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.26, 0.27, 0.28, 0.29 ] # the z-coordinates for the waterlines zheights = [ -0.8, -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, -0.05, 0.0, 0.05, 0.1, 0.15, 0.2, 0.28 ] zheights = [ -0.35, -0.3, -0.25, -0.2, -0.15, -0.1, -0.05, 0.0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.28 ] zheights = [] Nmax = 20 zmin = -0.5 zmax = -0.05 dz = (zmax - zmin) / float(Nmax - 1) z = zmin for n in range(Nmax): zheights.append(z) z = z + dz zheights = [] zheights.append(-0.25) #zheights=[ -0.35, -0.25, -0.15, -0.05, 0.05, 0.15, 0.25] #zheights=[ 0.1] length = 10 diam = 0.6 cutter1 = ocl.CylCutter(diam, length) cutter2 = ocl.BallCutter(diam, length) cutter3 = ocl.BullCutter(diam, diam / 5, length) cutter4 = ocl.ConeCutter(diam, math.pi / 5, length) for zh in zheights: #loops = calcWaterline(zh, cutter1, s) #drawLoops(myscreen, loops[0], camvtk.yellow) #loops = calcWaterline(zh, cutter2, s) #drawLoops(myscreen, loops[0], camvtk.green) #loops = calcWaterline(zh, cutter3, s) #drawLoops(myscreen, loops[0], camvtk.yellow) loops = calcWaterline(zh, cutter4, s) drawLoops(myscreen, loops[0], camvtk.pink) #for f in loops[1]: # drawFiber(myscreen, f, camvtk.red) #for f in loops[2]: # drawFiber(myscreen, f, camvtk.lblue) print("done.") myscreen.camera.SetPosition(1, -1, 3) myscreen.camera.SetFocalPoint(0.5, 0.5, 0) camvtk.drawArrows(myscreen, center=(-0.5, -0.5, -0.5)) camvtk.drawOCLtext(myscreen) myscreen.render() """ w2if = vtk.vtkWindowToImageFilter() w2if.SetInput(myscreen.renWin) lwr = vtk.vtkPNGWriter() lwr.SetInput( w2if.GetOutput() ) w2if.Modified() lwr.SetFileName(filename) if write_flag: lwr.Write() print("wrote ",filename) """ time.sleep(1)
apdc.setSTL(s) apdc.setCutter(cutter) apdc.setZ( -20 ) apdc.setSampling(sampling) apdc.setMinSampling(sampling/700) path = ocl.Path() p1 = ocl.Point(x, -1.52*cutter.getDiameter() , -111) # start-point of line p2 = ocl.Point(x, +1.52*cutter.getDiameter(), -111) # end-point of line l = ocl.Line(p1,p2) # line-object path.append( l ) apdc.setPath( path ) apdc.run() return apdc.getCLPoints() if __name__ == "__main__": print(ocl.version()) # revision() myscreen = camvtk.VTKScreen() #stl = camvtk.STLSurf("../stl/demo.stl") #stl = camvtk.STLSurf("../stl/30sphere.stl") #myscreen.addActor(stl) base=0.1 tip=10 a=ocl.Point(base,0,-tip) myscreen.addActor(camvtk.Point(center=(a.x,a.y,a.z), color=(1,0,1))); b=ocl.Point(-base,0,-tip) myscreen.addActor(camvtk.Point(center=(b.x,b.y,b.z), color=(1,0,1))); c=ocl.Point(0,0,0) myscreen.addActor( camvtk.Point(center=(c.x,c.y,c.z), color=(1,0,1))); #myscreen.addActor( camvtk.Line(p1=(1,0,0),p2=(0,0,0.3)) ) #myscreen.addActor( camvtk.Line(p1=(0,0,0.3),p2=(0,1,0)) )
apdc.setZ(-20) apdc.setSampling(sampling) apdc.setMinSampling(sampling / 700) path = ocl.Path() p1 = ocl.Point(x, -1.52 * cutter.getDiameter(), -111) # start-point of line p2 = ocl.Point(x, +1.52 * cutter.getDiameter(), -111) # end-point of line l = ocl.Line(p1, p2) # line-object path.append(l) apdc.setPath(path) apdc.run() return apdc.getCLPoints() if __name__ == "__main__": print ocl.version() # revision() myscreen = camvtk.VTKScreen() #stl = camvtk.STLSurf("../stl/demo.stl") #stl = camvtk.STLSurf("../stl/30sphere.stl") #myscreen.addActor(stl) base = 0.1 tip = 10 a = ocl.Point(base, 0, -tip) myscreen.addActor(camvtk.Point(center=(a.x, a.y, a.z), color=(1, 0, 1))) b = ocl.Point(-base, 0, -tip) myscreen.addActor(camvtk.Point(center=(b.x, b.y, b.z), color=(1, 0, 1))) c = ocl.Point(0, 0, 0) myscreen.addActor(camvtk.Point(center=(c.x, c.y, c.z), color=(1, 0, 1))) #myscreen.addActor( camvtk.Line(p1=(1,0,0),p2=(0,0,0.3)) ) #myscreen.addActor( camvtk.Line(p1=(0,0,0.3),p2=(0,1,0)) )
# and a line from p to the first point myscreen.addActor( camvtk.Line(p1=(p.x,p.y,p.z+zofz),p2=(first_point.x,first_point.y,first_point.z+zofz),color=loopColor) ) else: myscreen.addActor( camvtk.Line(p1=(previous.x,previous.y,previous.z+zofz),p2=(p.x,p.y,p.z+zofz),color=loopColor) ) previous=p n=n+1 zofz = zofz +0.00 print("rendered loop ",nloop, " with ", len(lop), " points at zofz=",zofz) if len(lop)==2: for p in lop: print(p) myscreen.addActor( camvtk.Sphere(center=(p.x,p.y,p.z+zofz),radius=0.0005, color=camvtk.pink ) ) nloop = nloop+1 if __name__ == "__main__": print(ocl.version()) myscreen = camvtk.VTKScreen() a = ocl.Point(0,1,0.3) myscreen.addActor(camvtk.Point(center=(a.x,a.y,a.z), color=(1,0,1))) b = ocl.Point(1,0.5,0.3) myscreen.addActor(camvtk.Point(center=(b.x,b.y,b.z), color=(1,0,1))) c = ocl.Point(-0.1,0.3,0.0) myscreen.addActor(camvtk.Point(center=(c.x,c.y,c.z), color=(1,0,1))) myscreen.addActor( camvtk.Line(p1=(a.x,a.y,a.z),p2=(c.x,c.y,c.z)) ) myscreen.addActor( camvtk.Line(p1=(c.x,c.y,c.z),p2=(b.x,b.y,b.z)) ) myscreen.addActor( camvtk.Line(p1=(a.x,a.y,a.z),p2=(b.x,b.y,b.z)) ) t = ocl.Triangle(b,c,a) s = ocl.STLSurf() s.addTriangle(t) # a one-triangle STLSurf zheights=[-0.3, -0.2, -0.1, -0.05, 0.0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.26, 0.27, 0.28, 0.29 ] # the z-coordinates for the waterlines zheights=[-0.8, -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, -0.05, 0.0, 0.05, 0.1, 0.15, 0.2, 0.28 ]
import ocl import pyocl import camvtk import vtk import math if __name__ == "__main__": print(ocl.version()) # print out git version tag # set up VTK visualization myscreen = camvtk.VTKScreen() myscreen.setAmbient(20,20,20) myscreen.camera.SetPosition(4, 4, 3) myscreen.camera.SetFocalPoint(0.6, 0.6, 0) myscreen.setAmbient(1,1,1) #camvtk.drawArrows(myscreen) # three corners of a triangle a = ocl.Point(1,0,-0.000010) b = ocl.Point(0,1,+0.0) c = ocl.Point(0.001,0,+0.3001) #c = ocl.Point(0,0,0.3) t = ocl.Triangle(a,b,c) # draw the triangle with VTK myscreen.addActor( camvtk.Point(center=(a.x,a.y,a.z), color=(1,0,1))); myscreen.addActor( camvtk.Point(center=(b.x,b.y,b.z), color=(1,0,1))); myscreen.addActor( camvtk.Point(center=(c.x,c.y,c.z), color=(1,0,1))); myscreen.addActor( camvtk.Line(p1=(a.x,a.y,a.z),p2=(c.x,c.y,c.z)) ) myscreen.addActor( camvtk.Line(p1=(c.x,c.y,c.z),p2=(b.x,b.y,b.z)) )
import ocl import pyocl import camvtk import vtk import math if __name__ == "__main__": print ocl.version() # print out git version tag # set up VTK visualization myscreen = camvtk.VTKScreen() myscreen.setAmbient(20, 20, 20) myscreen.camera.SetPosition(4, 4, 3) myscreen.camera.SetFocalPoint(0.6, 0.6, 0) myscreen.setAmbient(1, 1, 1) #camvtk.drawArrows(myscreen) # three corners of a triangle a = ocl.Point(1, 0, -0.000010) b = ocl.Point(0, 1, +0.0) c = ocl.Point(0.001, 0, +0.3001) #c = ocl.Point(0,0,0.3) t = ocl.Triangle(a, b, c) # draw the triangle with VTK myscreen.addActor(camvtk.Point(center=(a.x, a.y, a.z), color=(1, 0, 1))) myscreen.addActor(camvtk.Point(center=(b.x, b.y, b.z), color=(1, 0, 1))) myscreen.addActor(camvtk.Point(center=(c.x, c.y, c.z), color=(1, 0, 1))) myscreen.addActor(camvtk.Line(p1=(a.x, a.y, a.z), p2=(c.x, c.y, c.z))) myscreen.addActor(camvtk.Line(p1=(c.x, c.y, c.z), p2=(b.x, b.y, b.z)))
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()
import ocl import pyocl import camvtk import vtk import math if __name__ == "__main__": print(ocl.version()) # print out git version tag # set up VTK visualization myscreen = camvtk.VTKScreen() myscreen.setAmbient(20, 20, 20) myscreen.camera.SetPosition(4, 4, 3) myscreen.camera.SetFocalPoint(0.6, 0.6, 0) myscreen.setAmbient(1, 1, 1) #camvtk.drawArrows(myscreen) # three corners of a triangle a = ocl.Point(1, 0, -0.000010) b = ocl.Point(0, 1, +0.0) c = ocl.Point(0.001, 0, +0.3001) #c = ocl.Point(0,0,0.3) t = ocl.Triangle(a, b, c) # draw the triangle with VTK myscreen.addActor(camvtk.Point(center=(a.x, a.y, a.z), color=(1, 0, 1))) myscreen.addActor(camvtk.Point(center=(b.x, b.y, b.z), color=(1, 0, 1))) myscreen.addActor(camvtk.Point(center=(c.x, c.y, c.z), color=(1, 0, 1))) myscreen.addActor(camvtk.Line(p1=(a.x, a.y, a.z), p2=(c.x, c.y, c.z))) myscreen.addActor(camvtk.Line(p1=(c.x, c.y, c.z), p2=(b.x, b.y, b.z)))
def main(): print(ocl.version()) myscreen = camvtk.VTKScreen() myscreen.camera.SetPosition(-8, -4, 25) myscreen.camera.SetFocalPoint(0, 0, 0) arpos = -1.5 camvtk.drawArrows(myscreen, center=(arpos, arpos, arpos)) camvtk.drawOCLtext(myscreen) octtext = camvtk.Text() octtext.SetPos((70, myscreen.height - 600)) myscreen.addActor(octtext) octtext.SetText("Octree") vertex = [ ocl.Point(1, 1, -1), #// 0 ocl.Point(-1, 1, -1), #// 1 ocl.Point(-1, -1, -1), #// 2 ocl.Point(1, -1, -1), #// 3 ocl.Point(1, 1, 1), #// 4 ocl.Point(-1, 1, 1), #// 5 ocl.Point(-1, -1, 1), #// 6 ocl.Point(1, -1, 1) #// 7 ] n = 0 for v in vertex: myscreen.addActor( camvtk.Sphere(center=(v.x, v.y, v.z), radius=0.1, color=camvtk.red)) v = v t = camvtk.Text3D(color=camvtk.red, center=(v.x + 0.1, v.y + 0.1, v.z), text=str(n), scale=0.2, camera=myscreen.camera) myscreen.addActor(t) n = n + 1 edgeTable = [ [0, 1], [1, 2], [2, 3], [3, 0], [4, 5], [5, 6], [6, 7], [7, 4], [0, 4], [1, 5], [2, 6], [3, 7], ] # draw the edges as tubes ne = 0 for e in edgeTable: ep1 = vertex[e[0]] ep2 = vertex[e[1]] tu = camvtk.Tube(p1=(ep1.x, ep1.y, ep1.z), p2=(ep2.x, ep2.y, ep2.z), radius=0.051, color=camvtk.green) myscreen.addActor(tu) mid = 0.5 * (ep1 + ep2) t = camvtk.Text3D(color=camvtk.green, center=(mid.x + 0.1, mid.y + 0.1, mid.z), text=str(ne), scale=0.2, camera=myscreen.camera) myscreen.addActor(t) ne = ne + 1 # number the faces face = [ [2, 3, 6, 7], [0, 3, 4, 7], [0, 1, 4, 5], [1, 2, 5, 6], [0, 1, 2, 3], [4, 5, 6, 7], ] nf = 0 for f in face: mid = ocl.Point() for v in f: mid = mid + vertex[v] mid = 0.25 * mid t = camvtk.Text3D(color=camvtk.blue, center=(mid.x, mid.y, mid.z), text=str(nf), scale=0.2, camera=myscreen.camera) myscreen.addActor(t) nf = nf + 1 myscreen.render() print("All done.") myscreen.iren.Start()
apdc.setCutter(cutter) # set the minimum Z-coordinate, or "floor" for drop-cutter #apdc.minimumZ = -1 apdc.setSampling(0.04) apdc.setMinSampling(0.0008) apdc.setPath(path) apdc.run() return apdc.getCLPoints() if __name__ == "__main__": root = Tkinter.Tk() filename = tkFileDialog.askopenfilename(title='Choose an STL file') #filename = "data/gnu_tux_mod.stl" print "( OpenCAMLib ", ocl.version(), " )" #print os.getcwd() #filename="gnu_tux_mod.stl" #exit() stl = camvtk.STLSurf(filename) polydata = stl.src.GetOutput() s = ocl.STLSurf() camvtk.vtkPolyData2OCLSTL(polydata, s) print "( STL surface: read ", s.size(), "triangles from ", filename, " )" angle = math.pi / 4 diameter = 2 length = 50 # choose a cutter for the operation:
apdc.setZ(-20) apdc.setSampling(sampling) apdc.setMinSampling(sampling / 700) path = ocl.Path() p1 = ocl.Point(x, -1.52 * cutter.getDiameter(), -111) # start-point of line p2 = ocl.Point(x, +1.52 * cutter.getDiameter(), -111) # end-point of line l = ocl.Line(p1, p2) # line-object path.append(l) apdc.setPath(path) apdc.run() return apdc.getCLPoints() if __name__ == "__main__": print(ocl.version()) # revision() myscreen = camvtk.VTKScreen() #stl = camvtk.STLSurf("../stl/demo.stl") #stl = camvtk.STLSurf("../stl/30sphere.stl") #myscreen.addActor(stl) base = 0.1 tip = 10 a = ocl.Point(base, 0, -tip) myscreen.addActor(camvtk.Point(center=(a.x, a.y, a.z), color=(1, 0, 1))) b = ocl.Point(-base, 0, -tip) myscreen.addActor(camvtk.Point(center=(b.x, b.y, b.z), color=(1, 0, 1))) c = ocl.Point(0, 0, 0) myscreen.addActor(camvtk.Point(center=(c.x, c.y, c.z), color=(1, 0, 1))) #myscreen.addActor( camvtk.Line(p1=(1,0,0),p2=(0,0,0.3)) ) #myscreen.addActor( camvtk.Line(p1=(0,0,0.3),p2=(0,1,0)) )
def main(): print(ocl.version()) myscreen = camvtk.VTKScreen() myscreen.camera.SetPosition(-8, -4, 25) myscreen.camera.SetFocalPoint(0,0, 0) arpos=-1.5 camvtk.drawArrows(myscreen,center=(arpos,arpos,arpos)) camvtk.drawOCLtext(myscreen) octtext = camvtk.Text() octtext.SetPos( (70, myscreen.height-600) ) myscreen.addActor( octtext) octtext.SetText("Octree") vertex = [ ocl.Point( 1, 1,-1), #// 0 ocl.Point(-1, 1,-1), #// 1 ocl.Point(-1,-1,-1), #// 2 ocl.Point( 1,-1,-1), #// 3 ocl.Point( 1, 1, 1), #// 4 ocl.Point(-1, 1, 1), #// 5 ocl.Point(-1,-1, 1), #// 6 ocl.Point( 1,-1, 1) #// 7 ] n=0 for v in vertex: myscreen.addActor( camvtk.Sphere(center=(v.x,v.y,v.z), radius=0.1,color=camvtk.red)) v=v t = camvtk.Text3D(color=camvtk.red, center=(v.x+0.1,v.y+0.1,v.z), text=str(n), scale=0.2, camera=myscreen.camera) myscreen.addActor(t) n=n+1 edgeTable = [ [0,1] , [1,2] , [2,3] , [3,0] , [4,5] , [5,6] , [6,7] , [7,4] , [0,4] , [1,5] , [2,6] , [3,7] , ] # draw the edges as tubes ne = 0 for e in edgeTable: ep1 = vertex[ e[0] ] ep2 = vertex[ e[1] ] tu = camvtk.Tube( p1=(ep1.x,ep1.y,ep1.z), p2=(ep2.x,ep2.y,ep2.z), radius=0.051, color=camvtk.green ) myscreen.addActor(tu) mid = 0.5*(ep1 + ep2) t = camvtk.Text3D(color=camvtk.green, center=(mid.x+0.1,mid.y+0.1,mid.z), text=str(ne), scale=0.2, camera=myscreen.camera) myscreen.addActor(t) ne=ne+1 # number the faces face = [ [2,3,6,7] , [0,3,4,7] , [0,1,4,5] , [1,2,5,6] , [0,1,2,3] , [4,5,6,7] , ] nf=0 for f in face: mid = ocl.Point() for v in f: mid = mid+vertex[v] mid=0.25*mid t = camvtk.Text3D(color=camvtk.blue, center=(mid.x,mid.y,mid.z), text=str(nf), scale=0.2, camera=myscreen.camera) myscreen.addActor(t) nf=nf+1 myscreen.render() print("All done.") myscreen.iren.Start()
apdc.setSTL(s) apdc.setCutter(cutter) # set the minimum Z-coordinate, or "floor" for drop-cutter #apdc.minimumZ = -1 apdc.setSampling(0.04) apdc.setMinSampling(0.0008) apdc.setPath( path ) apdc.run() return apdc.getCLPoints() if __name__ == "__main__": root = Tkinter.Tk() filename = tkFileDialog.askopenfilename(title='Choose an STL file') #filename = "data/gnu_tux_mod.stl" print "( OpenCAMLib ",ocl.version()," )" #print os.getcwd() #filename="gnu_tux_mod.stl" #exit() stl = camvtk.STLSurf(filename) polydata = stl.src.GetOutput() s = ocl.STLSurf() camvtk.vtkPolyData2OCLSTL(polydata, s) print "( STL surface: read ", s.size(), "triangles from ",filename," )" angle = math.pi/4 diameter=2 length=50 # choose a cutter for the operation:
apdc.setSTL(s) apdc.setCutter(cutter) apdc.setZ( -20 ) apdc.setSampling(sampling) apdc.setMinSampling(sampling/700) path = ocl.Path() p1 = ocl.Point(x, -1.52*cutter.getDiameter() , -111) # start-point of line p2 = ocl.Point(x, +1.52*cutter.getDiameter(), -111) # end-point of line l = ocl.Line(p1,p2) # line-object path.append( l ) apdc.setPath( path ) apdc.run() return apdc.getCLPoints() if __name__ == "__main__": print ocl.version() # revision() myscreen = camvtk.VTKScreen() #stl = camvtk.STLSurf("../stl/demo.stl") #stl = camvtk.STLSurf("../stl/30sphere.stl") #myscreen.addActor(stl) base=0.1 tip=10 a=ocl.Point(base,0,-tip) myscreen.addActor(camvtk.Point(center=(a.x,a.y,a.z), color=(1,0,1))); b=ocl.Point(-base,0,-tip) myscreen.addActor(camvtk.Point(center=(b.x,b.y,b.z), color=(1,0,1))); c=ocl.Point(0,0,0) myscreen.addActor( camvtk.Point(center=(c.x,c.y,c.z), color=(1,0,1))); #myscreen.addActor( camvtk.Line(p1=(1,0,0),p2=(0,0,0.3)) ) #myscreen.addActor( camvtk.Line(p1=(0,0,0.3),p2=(0,1,0)) )
def drawScreen(a, b, c, filename, write_flag): print ocl.version() myscreen = camvtk.VTKScreen() z_hi = a.z if b.z > z_hi: z_hi = b.z if c.z > z_hi: z_hi = c.z z_lo = a.z if b.z < z_lo: z_lo = b.z if c.z < z_lo: z_lo = c.z #z_hi = 0.3 # this is the shallow case #ztri = 0.8 # this produces the steep case where we hit the circular rim #z_lo = 0.1 #a = ocl.Point(0,1,ztri) #b = ocl.Point(1,0.5,ztri) #c = ocl.Point(0.2,0.2,ztri_lo) myscreen.addActor(camvtk.Point(center=(a.x, a.y, a.z), color=(1, 0, 1))) myscreen.addActor(camvtk.Point(center=(b.x, b.y, b.z), color=(1, 0, 1))) myscreen.addActor(camvtk.Point(center=(c.x, c.y, c.z), color=(1, 0, 1))) myscreen.addActor(camvtk.Line(p1=(a.x, a.y, a.z), p2=(c.x, c.y, c.z))) myscreen.addActor(camvtk.Line(p1=(c.x, c.y, c.z), p2=(b.x, b.y, b.z))) myscreen.addActor(camvtk.Line(p1=(a.x, a.y, a.z), p2=(b.x, b.y, b.z))) t = ocl.Triangle(b, c, a) angle = math.pi / 5 diameter = 0.3 length = 5 #cutter = ocl.BallCutter(diameter, length) #cutter = ocl.CylCutter(diameter, length) #cutter = ocl.BullCutter(diameter, diameter/4, length) cutter = ocl.ConeCutter(diameter, angle, length) #cutter = cutter.offsetCutter( 0.1 ) print "cutter= ", cutter print "length=", cutter.getLength() print "fiber..." range = 2 Nmax = 100 yvals = [ float(n - float(Nmax) / 2) / Nmax * range for n in xrange(0, Nmax + 1) ] xvals = [ float(n - float(Nmax) / 2) / Nmax * range for n in xrange(0, Nmax + 1) ] zmin = z_lo - 0.3 zmax = z_hi zNmax = 20 dz = (zmax - zmin) / (zNmax - 1) zvals = [] for n in xrange(0, zNmax): zvals.append(zmin + n * dz) for zh in zvals: yfiber(cutter, yvals, t, zh, myscreen) xfiber(cutter, xvals, t, zh, myscreen) print "done." myscreen.camera.SetPosition(-2, -1, 3) myscreen.camera.SetFocalPoint(1.0, 0.0, -0.5) camvtk.drawArrows(myscreen, center=(-0.5, -0.5, -0.5)) camvtk.drawOCLtext(myscreen) myscreen.render() """
def drawScreen(a,b,c,filename,write_flag): print(ocl.version()) myscreen = camvtk.VTKScreen() #a = ocl.Point(0,1,0.3) myscreen.addActor(camvtk.Point(center=(a.x,a.y,a.z), color=(1,0,1))) #b = ocl.Point(1,0.5,0.3) myscreen.addActor(camvtk.Point(center=(b.x,b.y,b.z), color=(1,0,1))) #c = ocl.Point(-0.1,0.3,0.0) myscreen.addActor(camvtk.Point(center=(c.x,c.y,c.z), color=(1,0,1))) myscreen.addActor( camvtk.Line(p1=(a.x,a.y,a.z),p2=(c.x,c.y,c.z)) ) myscreen.addActor( camvtk.Line(p1=(c.x,c.y,c.z),p2=(b.x,b.y,b.z)) ) myscreen.addActor( camvtk.Line(p1=(a.x,a.y,a.z),p2=(b.x,b.y,b.z)) ) t = ocl.Triangle(b,c,a) s = ocl.STLSurf() s.addTriangle(t) # a one-triangle STLSurf zheights=[-0.3, -0.2, -0.1, -0.05, 0.0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.26, 0.27, 0.28, 0.29 ] # the z-coordinates for the waterlines zheights=[-0.8, -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, -0.05, 0.0, 0.05, 0.1, 0.15, 0.2, 0.28 ] zheights=[ -0.35, -0.3, -0.25, -0.2, -0.15, -0.1, -0.05, 0.0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.28] zheights=[] Nmax=20 zmin=-0.5 zmax= -0.05 dz = (zmax-zmin)/float(Nmax-1) z = zmin for n in range(Nmax): zheights.append(z) z=z+dz zheights=[] zheights.append(-0.25) #zheights=[ -0.35, -0.25, -0.15, -0.05, 0.05, 0.15, 0.25] #zheights=[ 0.1] length = 10 diam = 0.6 cutter1 = ocl.CylCutter( diam , length ) cutter2 = ocl.BallCutter( diam , length ) cutter3 = ocl.BullCutter( diam , diam/5, length ) cutter4 = ocl.ConeCutter( diam , math.pi/5, length ) for zh in zheights: #loops = calcWaterline(zh, cutter1, s) #drawLoops(myscreen, loops[0], camvtk.yellow) #loops = calcWaterline(zh, cutter2, s) #drawLoops(myscreen, loops[0], camvtk.green) #loops = calcWaterline(zh, cutter3, s) #drawLoops(myscreen, loops[0], camvtk.yellow) loops = calcWaterline(zh, cutter4, s) drawLoops(myscreen, loops[0], camvtk.pink) #for f in loops[1]: # drawFiber(myscreen, f, camvtk.red) #for f in loops[2]: # drawFiber(myscreen, f, camvtk.lblue) print("done.") myscreen.camera.SetPosition(1, -1, 3) myscreen.camera.SetFocalPoint(0.5, 0.5, 0) camvtk.drawArrows(myscreen,center=(-0.5,-0.5,-0.5)) camvtk.drawOCLtext(myscreen) myscreen.render() """ w2if = vtk.vtkWindowToImageFilter() w2if.SetInput(myscreen.renWin) lwr = vtk.vtkPNGWriter() lwr.SetInput( w2if.GetOutput() ) w2if.Modified() lwr.SetFileName(filename) if write_flag: lwr.Write() print("wrote ",filename) """ time.sleep(1)
def drawScreen(a,b,c,filename,write_flag): print(ocl.version()) myscreen = camvtk.VTKScreen() z_hi = a.z if b.z > z_hi: z_hi = b.z if c.z > z_hi: z_hi = c.z z_lo = a.z if b.z < z_lo: z_lo = b.z if c.z < z_lo: z_lo = c.z #z_hi = 0.3 # this is the shallow case #ztri = 0.8 # this produces the steep case where we hit the circular rim #z_lo = 0.1 #a = ocl.Point(0,1,ztri) #b = ocl.Point(1,0.5,ztri) #c = ocl.Point(0.2,0.2,ztri_lo) myscreen.addActor(camvtk.Point(center=(a.x,a.y,a.z), color=(1,0,1))) myscreen.addActor(camvtk.Point(center=(b.x,b.y,b.z), color=(1,0,1))) myscreen.addActor(camvtk.Point(center=(c.x,c.y,c.z), color=(1,0,1))) myscreen.addActor( camvtk.Line(p1=(a.x,a.y,a.z),p2=(c.x,c.y,c.z)) ) myscreen.addActor( camvtk.Line(p1=(c.x,c.y,c.z),p2=(b.x,b.y,b.z)) ) myscreen.addActor( camvtk.Line(p1=(a.x,a.y,a.z),p2=(b.x,b.y,b.z)) ) t = ocl.Triangle(b,c,a) angle = math.pi/5 diameter=0.3 length=5 #cutter = ocl.BallCutter(diameter, length) #cutter = ocl.CylCutter(diameter, length) #cutter = ocl.BullCutter(diameter, diameter/4, length) cutter = ocl.ConeCutter(diameter, angle, length) #cutter = cutter.offsetCutter( 0.1 ) print("cutter= ", cutter) print("length=", cutter.getLength()) print("fiber...") fiber_range=2 Nmax = 100 yvals = [float(n-float(Nmax)/2)/Nmax*fiber_range for n in range(0,Nmax+1)] xvals = [float(n-float(Nmax)/2)/Nmax*fiber_range for n in range(0,Nmax+1)] zmin = z_lo - 0.3 zmax = z_hi zNmax = 20 dz = (zmax-zmin)/(zNmax-1) zvals=[] for n in range(0,zNmax): zvals.append(zmin+n*dz) for zh in zvals: yfiber(cutter,yvals,t,zh,myscreen) xfiber(cutter,xvals,t,zh,myscreen) print("done.") myscreen.camera.SetPosition(-2, -1, 3) myscreen.camera.SetFocalPoint(1.0, 0.0, -0.5) camvtk.drawArrows(myscreen,center=(-0.5,-0.5,-0.5)) camvtk.drawOCLtext(myscreen) myscreen.render() """
import ocl import camvtk import time import vtk if __name__ == "__main__": print(ocl.version()) myscreen = camvtk.VTKScreen() stl = camvtk.STLSurf("../stl/gnu_tux_mod.stl") print("STL surface read") myscreen.addActor(stl) stl.SetWireframe() polydata = stl.src.GetOutput() s = ocl.STLSurf() camvtk.vtkPolyData2OCLSTL(polydata, s) print("STLSurf with ", s.size(), " triangles") # define a cutter cutter = ocl.CylCutter(0.6, 5) print(cutter) print("creating PathDropCutter()") pdc = ocl.PathDropCutter() # create a pdc print("set STL surface") pdc.setSTL(s) print("set cutter") pdc.setCutter(cutter) # set the cutter print("set minimumZ") pdc.minimumZ = -1 # set the minimum Z-coordinate, or "floor" for drop-cutter print("set the sampling interval")
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()
# and a line from p to the first point myscreen.addActor( camvtk.Line(p1=(p.x,p.y,p.z+zofz),p2=(first_point.x,first_point.y,first_point.z+zofz),color=loopColor) ) else: myscreen.addActor( camvtk.Line(p1=(previous.x,previous.y,previous.z+zofz),p2=(p.x,p.y,p.z+zofz),color=loopColor) ) previous=p n=n+1 zofz = zofz +0.00 print "rendered loop ",nloop, " with ", len(lop), " points at zofz=",zofz if len(lop)==2: for p in lop: print p myscreen.addActor( camvtk.Sphere(center=(p.x,p.y,p.z+zofz),radius=0.0005, color=camvtk.pink ) ) nloop = nloop+1 if __name__ == "__main__": print ocl.version() myscreen = camvtk.VTKScreen() a = ocl.Point(0,1,0.3) myscreen.addActor(camvtk.Point(center=(a.x,a.y,a.z), color=(1,0,1))) b = ocl.Point(1,0.5,0.3) myscreen.addActor(camvtk.Point(center=(b.x,b.y,b.z), color=(1,0,1))) c = ocl.Point(-0.1,0.3,0.0) myscreen.addActor(camvtk.Point(center=(c.x,c.y,c.z), color=(1,0,1))) myscreen.addActor( camvtk.Line(p1=(a.x,a.y,a.z),p2=(c.x,c.y,c.z)) ) myscreen.addActor( camvtk.Line(p1=(c.x,c.y,c.z),p2=(b.x,b.y,b.z)) ) myscreen.addActor( camvtk.Line(p1=(a.x,a.y,a.z),p2=(b.x,b.y,b.z)) ) t = ocl.Triangle(b,c,a) s = ocl.STLSurf() s.addTriangle(t) # a one-triangle STLSurf zheights=[-0.3, -0.2, -0.1, -0.05, 0.0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.26, 0.27, 0.28, 0.29 ] # the z-coordinates for the waterlines zheights=[-0.8, -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, -0.05, 0.0, 0.05, 0.1, 0.15, 0.2, 0.28 ]
import ocl import pyocl import camvtk import vtk import math if __name__ == "__main__": print ocl.version() # print out git version tag # set up VTK visualization myscreen = camvtk.VTKScreen() myscreen.setAmbient(20,20,20) myscreen.camera.SetPosition(4, 4, 3) myscreen.camera.SetFocalPoint(0.6, 0.6, 0) myscreen.setAmbient(1,1,1) #camvtk.drawArrows(myscreen) # three corners of a triangle a = ocl.Point(1,0,-0.000010) b = ocl.Point(0,1,+0.0) c = ocl.Point(0.001,0,+0.3001) #c = ocl.Point(0,0,0.3) t = ocl.Triangle(a,b,c) # draw the triangle with VTK myscreen.addActor( camvtk.Point(center=(a.x,a.y,a.z), color=(1,0,1))); myscreen.addActor( camvtk.Point(center=(b.x,b.y,b.z), color=(1,0,1))); myscreen.addActor( camvtk.Point(center=(c.x,c.y,c.z), color=(1,0,1))); myscreen.addActor( camvtk.Line(p1=(a.x,a.y,a.z),p2=(c.x,c.y,c.z)) ) myscreen.addActor( camvtk.Line(p1=(c.x,c.y,c.z),p2=(b.x,b.y,b.z)) )