File: pathdropcutter_test_1.py

package info (click to toggle)
opencamlib 2023.01.11-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 29,800 kB
  • sloc: cpp: 8,722; python: 5,530; sh: 604; javascript: 310; makefile: 209
file content (67 lines) | stat: -rw-r--r-- 2,181 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from opencamlib import ocl, camvtk
import time

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()
    print(dir(polydata))
    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")
    pdc.setSampling(0.0123)
    
    # some parameters for this "zigzig" pattern    
    ymin=0
    ymax=12
    Ny=40  # number of lines in the y-direction
    dy = float(ymax-ymin)/Ny  # the y step-over
    
    path = ocl.Path()                   # create an empty path object 
    # add Line objects to the path in this loop
    for n in range(0,Ny):
        y = ymin+n*dy
        p1 = ocl.Point(0,y,0)   # start-point of line
        p2 = ocl.Point(9,y,0)   # end-point of line
        l = ocl.Line(p1,p2)     # line-object
        path.append( l )        # add the line to the path

    print(" set the path for pdf ")
    pdc.setPath( path )
    
    print(" run the calculation ")
    t_before = time.time()
    pdc.run()                   # run drop-cutter on the path
    t_after = time.time()
    print("run took ", t_after-t_before," s")
    
    print("get the results ")
    clp = pdc.getCLPoints()     # get the cl-points from pdf
    
    print(" render the CL-points")
    camvtk.drawCLPointCloud(myscreen, clp)
    #myscreen.addActor( camvtk.PointCloud(pointlist=clp, collist=ccp)  )
    myscreen.camera.SetPosition(3, 23, 15)
    myscreen.camera.SetFocalPoint(5, 5, 0)
    myscreen.render()
    print(" All done.")
    myscreen.iren.Start()