| 1 |
from opencamlib import ocl, camvtk |
| 2 |
|
| 3 |
def drawLoops(myscreen, loops, loopcolor): |
| 4 |
nloop = 0 |
| 5 |
for lop in loops: |
| 6 |
n = 0 |
| 7 |
N = len(lop) |
| 8 |
first_point=ocl.Point(-1,-1,5) |
| 9 |
previous=ocl.Point(-1,-1,5) |
| 10 |
for p in lop: |
| 11 |
if n==0: # don't draw anything on the first iteration |
| 12 |
previous=p |
| 13 |
first_point = p |
| 14 |
elif n== (N-1): # the last point |
| 15 |
myscreen.addActor( camvtk.Line(p1=(previous.x,previous.y,previous.z),p2=(p.x,p.y,p.z),color=loopcolor) ) # the normal line |
| 16 |
# and a line from p to the first point |
| 17 |
myscreen.addActor( camvtk.Line(p1=(p.x,p.y,p.z),p2=(first_point.x,first_point.y,first_point.z),color=loopcolor) ) |
| 18 |
else: |
| 19 |
myscreen.addActor( camvtk.Line(p1=(previous.x,previous.y,previous.z),p2=(p.x,p.y,p.z),color=loopcolor) ) |
| 20 |
previous=p |
| 21 |
n=n+1 |
| 22 |
print("rendered loop ",nloop, " with ", len(lop), " points") |
| 23 |
nloop = nloop+1 |
| 24 |
|
| 25 |
def getWaterline(s, cutter, zh): |
| 26 |
wl = ocl.Waterline() |
| 27 |
#wl.setThreads(1) # single thread for easier debug |
| 28 |
wl.setSTL(s) |
| 29 |
wl.setCutter(cutter) |
| 30 |
wl.setZ(zh) |
| 31 |
wl.setSampling(1) |
| 32 |
wl.run() |
| 33 |
loops = wl.getLoops() |
| 34 |
return loops |
| 35 |
|
| 36 |
if __name__ == "__main__": |
| 37 |
print(ocl.version()) |
| 38 |
myscreen = camvtk.VTKScreen() |
| 39 |
#stl = camvtk.STLSurf("../../../stl/demo.stl") |
| 40 |
#stl = camvtk.STLSurf("../../../stl/30sphere.stl") |
| 41 |
stl = camvtk.STLSurf("../../../stl/failedinpycam.stl") |
| 42 |
myscreen.addActor(stl) |
| 43 |
stl.SetWireframe() # render tux as wireframe |
| 44 |
#stl.SetSurface() # render tux as surface |
| 45 |
stl.SetColor(camvtk.cyan) |
| 46 |
polydata = stl.src.GetOutput() |
| 47 |
s = ocl.STLSurf() |
| 48 |
camvtk.vtkPolyData2OCLSTL(polydata, s) |
| 49 |
print("STL surface read,", s.size(), "triangles") |
| 50 |
zh=[29,28,25,20,15,10,5,0,-5,-10,-15,-20] |
| 51 |
#zh=[15] |
| 52 |
diam = 3 |
| 53 |
length = 50 |
| 54 |
loops = [] |
| 55 |
|
| 56 |
cutter = ocl.CylCutter( diam , length ) |
| 57 |
#cutter = ocl.BallCutter( diam , length ) |
| 58 |
#cutter = ocl.BullCutter( diam , diam/5, length ) |
| 59 |
|
| 60 |
loops = [] |
| 61 |
for z in zh: |
| 62 |
z_loops = getWaterline(s, cutter, z) |
| 63 |
for l in z_loops: |
| 64 |
loops.append(l) |
| 65 |
|
| 66 |
#for l in cutter_loops: |
| 67 |
# loops.append(l) |
| 68 |
|
| 69 |
print("All waterlines done. Got", len(loops)," loops in total.") |
| 70 |
# draw the loops |
| 71 |
drawLoops(myscreen, loops, camvtk.yellow) |
| 72 |
#drawLoops(myscreen, aloops, camvtk.red) |
| 73 |
|
| 74 |
print("done.") |
| 75 |
myscreen.camera.SetPosition(15, 13, 7) |
| 76 |
myscreen.camera.SetFocalPoint(5, 5, 0) |
| 77 |
camvtk.drawArrows(myscreen,center=(-0.5,-0.5,-0.5)) |
| 78 |
camvtk.drawOCLtext(myscreen) |
| 79 |
myscreen.render() |
| 80 |
myscreen.iren.Start() |
| 81 |
#raw_input("Press Enter to terminate") |