Debian Codegraph @

examples/python/pathdropcutter_test_2.py

raw
1 from opencamlib import ocl, camvtk
2 import time
3
4 if __name__ == "__main__":
5 print(ocl.version())
6
7 myscreen = camvtk.VTKScreen()
8 stl = camvtk.STLSurf("../../stl/demo.stl")
9 #stl = camvtk.STLSurf("../../stl/pycam-textbox.stl")
10 print("STL surface read")
11 myscreen.addActor(stl)
12 stl.SetWireframe()
13 polydata = stl.src.GetOutput()
14 s= ocl.STLSurf()
15 camvtk.vtkPolyData2OCLSTL(polydata, s)
16 print("STLSurf with ", s.size(), " triangles")
17
18 # define a cutter
19 #cutter = ocl.CylCutter(0.6, 5)
20 cutter = ocl.BullCutter(0.6, 0.01, 5)
21 print(cutter)
22 pdc = ocl.PathDropCutter() # create a pdc
23 apdc = ocl.AdaptivePathDropCutter()
24 pdc.setSTL(s)
25 apdc.setSTL(s)
26 pdc.setCutter(cutter) # set the cutter
27 apdc.setCutter(cutter)
28 #print "set minimumZ"
29 #pdc.minimumZ = -1 # set the minimum Z-coordinate, or "floor" for drop-cutter
30 #apdc.minimumZ = -1
31 #print "set the sampling interval"
32 pdc.setSampling(0.4)
33 apdc.setSampling(0.4)
34 apdc.setMinSampling(0.0008)
35 print(" apdc sampling = ", apdc.getSampling())
36 # some parameters for this "zigzig" pattern
37 ymin=0
38 ymax=12
39 Ny=10 # number of lines in the y-direction
40 dy = float(ymax-ymin)/Ny # the y step-over
41
42 path = ocl.Path() # create an empty path object
43 path2 = ocl.Path()
44 # add Line objects to the path in this loop
45 for n in range(0,Ny):
46 y = ymin+n*dy
47 p1 = ocl.Point(0,y,0) # start-point of line
48 p2 = ocl.Point(10,y,0) # end-point of line
49 l = ocl.Line(p1,p2) # line-object
50 l2 = ocl.Line(p1,p2)
51 path.append( l ) # add the line to the path
52 path2.append( l2 )
53
54 print(" set the path for pdf ")
55 pdc.setPath( path )
56 apdc.setPath( path2 )
57
58 print(" run the calculation ")
59 t_before = time.time()
60 pdc.run() # run drop-cutter on the path
61 t_after = time.time()
62 print(" pdc run took ", t_after-t_before," s")
63
64 print(" run the calculation ")
65 t_before = time.time()
66 apdc.run() # run drop-cutter on the path
67 t_after = time.time()
68 print(" apdc run took ", t_after-t_before," s")
69
70
71 print("get the results ")
72 clp = pdc.getCLPoints() # get the cl-points from pdf
73 aclp = apdc.getCLPoints()
74 print("got ", len(aclp) ," adaptive points")
75
76 aclp_lifted=[]
77 for p in aclp:
78 p2 = ocl.Point(p.x,p.y,p.z) + ocl.Point(0,0,1)
79 aclp_lifted.append(p2)
80
81 # filter the adaptively sampled toolpaths
82
83 print("filtering. before filter we have", len(aclp_lifted),"cl-points")
84 t_before = time.time()
85 f = ocl.LineCLFilter()
86 f.setTolerance(0.001)
87 for p in aclp_lifted:
88 p2 = ocl.CLPoint(p.x,p.y,p.z)
89 f.addCLPoint(p2)
90
91 f.run()
92 t_after = time.time()
93 calctime = t_after-t_before
94 print(" done in ", calctime," s")
95 cl_filtered = f.getCLPoints()
96 print(" after filter we have", len(cl_filtered),"cl-points")
97
98 aclp_lifted2=[]
99 for p in cl_filtered:
100 p2 = ocl.Point(p.x,p.y,p.z) + ocl.Point(0,0,1)
101 aclp_lifted2.append(p2)
102
103
104 print(" render the CL-points")
105 camvtk.drawCLPointCloud(myscreen, clp)
106 camvtk.drawCLPointCloud(myscreen, aclp_lifted)
107 camvtk.drawCLPointCloud(myscreen, aclp_lifted2)
108 #myscreen.addActor( camvtk.PointCloud(pointlist=clp, collist=ccp) )
109 myscreen.camera.SetPosition(3, 23, 15)
110 myscreen.camera.SetFocalPoint(5, 5, 0)
111 myscreen.render()
112 print(" All done.")
113 myscreen.iren.Start()