| 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/gnu_tux_mod.stl") |
| 9 |
print("STL surface read") |
| 10 |
myscreen.addActor(stl) |
| 11 |
stl.SetWireframe() |
| 12 |
polydata = stl.src.GetOutput() |
| 13 |
print(dir(polydata)) |
| 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 |
print(cutter) |
| 21 |
|
| 22 |
print("creating PathDropCutter()") |
| 23 |
pdc = ocl.PathDropCutter() # create a pdc |
| 24 |
print("set STL surface") |
| 25 |
pdc.setSTL(s) |
| 26 |
print("set cutter") |
| 27 |
pdc.setCutter(cutter) # set the cutter |
| 28 |
print("set minimumZ") |
| 29 |
pdc.minimumZ = -1 # set the minimum Z-coordinate, or "floor" for drop-cutter |
| 30 |
print("set the sampling interval") |
| 31 |
pdc.setSampling(0.0123) |
| 32 |
|
| 33 |
# some parameters for this "zigzig" pattern |
| 34 |
ymin=0 |
| 35 |
ymax=12 |
| 36 |
Ny=40 # number of lines in the y-direction |
| 37 |
dy = float(ymax-ymin)/Ny # the y step-over |
| 38 |
|
| 39 |
path = ocl.Path() # create an empty path object |
| 40 |
# add Line objects to the path in this loop |
| 41 |
for n in range(0,Ny): |
| 42 |
y = ymin+n*dy |
| 43 |
p1 = ocl.Point(0,y,0) # start-point of line |
| 44 |
p2 = ocl.Point(9,y,0) # end-point of line |
| 45 |
l = ocl.Line(p1,p2) # line-object |
| 46 |
path.append( l ) # add the line to the path |
| 47 |
|
| 48 |
print(" set the path for pdf ") |
| 49 |
pdc.setPath( path ) |
| 50 |
|
| 51 |
print(" run the calculation ") |
| 52 |
t_before = time.time() |
| 53 |
pdc.run() # run drop-cutter on the path |
| 54 |
t_after = time.time() |
| 55 |
print("run took ", t_after-t_before," s") |
| 56 |
|
| 57 |
print("get the results ") |
| 58 |
clp = pdc.getCLPoints() # get the cl-points from pdf |
| 59 |
|
| 60 |
print(" render the CL-points") |
| 61 |
camvtk.drawCLPointCloud(myscreen, clp) |
| 62 |
#myscreen.addActor( camvtk.PointCloud(pointlist=clp, collist=ccp) ) |
| 63 |
myscreen.camera.SetPosition(3, 23, 15) |
| 64 |
myscreen.camera.SetFocalPoint(5, 5, 0) |
| 65 |
myscreen.render() |
| 66 |
print(" All done.") |
| 67 |
myscreen.iren.Start() |