| 1 |
from opencamlib import ocl, camvtk |
| 2 |
import time |
| 3 |
|
| 4 |
def DrawLoops(myscreen, loops): |
| 5 |
# draw the loops |
| 6 |
nloop=0 |
| 7 |
for lop in loops: |
| 8 |
n = 0 |
| 9 |
N = len(lop) |
| 10 |
first_point=ocl.Point(-1,-1,5) |
| 11 |
previous=ocl.Point(-1,-1,5) |
| 12 |
for p in lop: |
| 13 |
if n==0: # don't draw anything on the first iteration |
| 14 |
previous=p |
| 15 |
first_point = p |
| 16 |
elif n== (N-1): # the last point |
| 17 |
myscreen.addActor( camvtk.Line(p1=(previous.x,previous.y,previous.z),p2=(p.x,p.y,p.z),color=camvtk.yellow) ) # the normal line |
| 18 |
# and a line from p to the first point |
| 19 |
myscreen.addActor( camvtk.Line(p1=(p.x,p.y,p.z),p2=(first_point.x,first_point.y,first_point.z),color=camvtk.yellow) ) |
| 20 |
else: |
| 21 |
myscreen.addActor( camvtk.Line(p1=(previous.x,previous.y,previous.z),p2=(p.x,p.y,p.z),color=camvtk.yellow) ) |
| 22 |
previous=p |
| 23 |
n=n+1 |
| 24 |
print("rendered loop ",nloop, " with ", len(lop), " points") |
| 25 |
nloop = nloop+1 |
| 26 |
|
| 27 |
def drawOutput(myscreen, pts, stepOver): |
| 28 |
for p in pts: |
| 29 |
myscreen.addActor( camvtk.Sphere(center=(p.x,p.y,p.z), radius=stepOver/5, color=camvtk.red) ) |
| 30 |
|
| 31 |
if __name__ == "__main__": |
| 32 |
print(ocl.version()) |
| 33 |
myscreen = camvtk.VTKScreen() |
| 34 |
a = ocl.Point(0,1,0.3) |
| 35 |
myscreen.addActor(camvtk.Point(center=(a.x,a.y,a.z), color=(1,0,1))) |
| 36 |
b = ocl.Point(1,0.5,0.3) |
| 37 |
myscreen.addActor(camvtk.Point(center=(b.x,b.y,b.z), color=(1,0,1))) |
| 38 |
c = ocl.Point(0,0,0) |
| 39 |
myscreen.addActor(camvtk.Point(center=(c.x,c.y,c.z), color=(1,0,1))) |
| 40 |
myscreen.addActor( camvtk.Line(p1=(a.x,a.y,a.z),p2=(c.x,c.y,c.z)) ) |
| 41 |
myscreen.addActor( camvtk.Line(p1=(c.x,c.y,c.z),p2=(b.x,b.y,b.z)) ) |
| 42 |
myscreen.addActor( camvtk.Line(p1=(a.x,a.y,a.z),p2=(b.x,b.y,b.z)) ) |
| 43 |
t = ocl.Triangle(b,c,a) |
| 44 |
s = ocl.STLSurf() |
| 45 |
s.addTriangle(t) # a one-triangle STLSurf |
| 46 |
zheight=0.15 # the z-coordinate for the waterline |
| 47 |
diam = 0.6 |
| 48 |
length = 5 |
| 49 |
loops = [] |
| 50 |
#cutter = ocl.CylCutter( 1 , 1 ) |
| 51 |
|
| 52 |
cutter = ocl.CylCutter( diam , length ) |
| 53 |
#cutter = ocl.BallCutter( diam , length ) |
| 54 |
#cutter = ocl.BullCutter( diam , diam/5, length ) |
| 55 |
wl = ocl.Waterline() |
| 56 |
#wl.setThreads(1) |
| 57 |
wl.setSTL(s) |
| 58 |
wl.setCutter(cutter) |
| 59 |
wl.setZ(zheight) |
| 60 |
wl.setSampling(0.1) |
| 61 |
t_before = time.time() |
| 62 |
wl.run() |
| 63 |
t_after = time.time() |
| 64 |
calctime = t_after-t_before |
| 65 |
print(" Waterline done in ", calctime," s") |
| 66 |
cutter_loops = wl.getLoops() |
| 67 |
for l in cutter_loops: |
| 68 |
loops.append(l) |
| 69 |
#print loops |
| 70 |
print("All waterlines done. Got", len(loops)," loops in total.") |
| 71 |
DrawLoops(myscreen, loops) |
| 72 |
|
| 73 |
z = ocl.ZigZag() |
| 74 |
z.setOrigin( ocl.Point(0,0) ) |
| 75 |
z.setDirection( ocl.Point(1,1) ) |
| 76 |
stepOver = 0.021 |
| 77 |
z.setStepOver( stepOver ) |
| 78 |
for lop in loops: |
| 79 |
for p in lop: |
| 80 |
z.addPoint(p) |
| 81 |
z.run() |
| 82 |
print(z) |
| 83 |
out = z.getOutput() |
| 84 |
print("got ",len(out)," output points") |
| 85 |
drawOutput(myscreen, out, stepOver ) |
| 86 |
|
| 87 |
print("done.") |
| 88 |
myscreen.camera.SetPosition(2, 2, 2) |
| 89 |
myscreen.camera.SetFocalPoint(0.5, 0.5, 0) |
| 90 |
camvtk.drawArrows(myscreen,center=(-0.5,-0.5,-0.5)) |
| 91 |
camvtk.drawOCLtext(myscreen) |
| 92 |
myscreen.render() |
| 93 |
myscreen.iren.Start() |
| 94 |
#raw_input("Press Enter to terminate") |