| 1 |
from opencamlib import ocl, camvtk |
| 2 |
import time |
| 3 |
|
| 4 |
if __name__ == "__main__": |
| 5 |
print(ocl.version()) |
| 6 |
myscreen = camvtk.VTKScreen() |
| 7 |
a = ocl.Point(0,1,0.3) |
| 8 |
myscreen.addActor(camvtk.Point(center=(a.x,a.y,a.z), color=(1,0,1))) |
| 9 |
b = ocl.Point(1,0.5,0.3) |
| 10 |
myscreen.addActor(camvtk.Point(center=(b.x,b.y,b.z), color=(1,0,1))) |
| 11 |
c = ocl.Point(0,0,0) |
| 12 |
myscreen.addActor(camvtk.Point(center=(c.x,c.y,c.z), color=(1,0,1))) |
| 13 |
myscreen.addActor( camvtk.Line(p1=(a.x,a.y,a.z),p2=(c.x,c.y,c.z)) ) |
| 14 |
myscreen.addActor( camvtk.Line(p1=(c.x,c.y,c.z),p2=(b.x,b.y,b.z)) ) |
| 15 |
myscreen.addActor( camvtk.Line(p1=(a.x,a.y,a.z),p2=(b.x,b.y,b.z)) ) |
| 16 |
t = ocl.Triangle(b,c,a) |
| 17 |
s = ocl.STLSurf() |
| 18 |
s.addTriangle(t) # a one-triangle STLSurf |
| 19 |
zheights=[-0.3, -0.2, -0.1, -0.05, 0.0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.26, 0.27, 0.28, 0.29 ] # the z-coordinates for the waterlines |
| 20 |
zheights=[-0.8, -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, -0.05, 0.0, 0.05, 0.1, 0.15, 0.2, 0.28 ] |
| 21 |
zheights=[ -0.35, -0.3, -0.25, -0.2, -0.15, -0.1, -0.05, 0.0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.28] |
| 22 |
cutter_diams = [0.6] # run the thing for all these cutter diameters |
| 23 |
length = 5 |
| 24 |
loops = [] |
| 25 |
cutter = ocl.CylCutter( 1 , 1 ) |
| 26 |
|
| 27 |
t_total = time.time() |
| 28 |
for zh in zheights: |
| 29 |
for diam in cutter_diams: |
| 30 |
cutter = ocl.CylCutter( diam , length ) |
| 31 |
cutter = ocl.BallCutter( diam , length ) |
| 32 |
#cutter = ocl.BullCutter( diam , diam/5, length ) |
| 33 |
#cutter = ocl.ConeCutter( diam , math.pi/5, length ) |
| 34 |
wl = ocl.Waterline() |
| 35 |
#wl.setThreads(1) |
| 36 |
wl.setSTL(s) |
| 37 |
wl.setCutter(cutter) |
| 38 |
wl.setZ(zh) |
| 39 |
wl.setSampling(0.02) |
| 40 |
wl.setThreads(1) |
| 41 |
t_before = time.time() |
| 42 |
wl.run() |
| 43 |
t_after = time.time() |
| 44 |
calctime = t_after-t_before |
| 45 |
print(" Waterline done in ", calctime," s") |
| 46 |
cutter_loops = wl.getLoops() |
| 47 |
for l in cutter_loops: |
| 48 |
loops.append(l) |
| 49 |
print(" ALL Waterlines done in ", time.time()-t_total," s") |
| 50 |
#print loops |
| 51 |
print("All waterlines done. Got", len(loops)," loops in total.") |
| 52 |
# draw the loops |
| 53 |
nloop=0 |
| 54 |
for lop in loops: |
| 55 |
n = 0 |
| 56 |
N = len(lop) |
| 57 |
first_point=ocl.Point(-1,-1,5) |
| 58 |
previous=ocl.Point(-1,-1,5) |
| 59 |
for p in lop: |
| 60 |
if n==0: # don't draw anything on the first iteration |
| 61 |
previous=p |
| 62 |
first_point = p |
| 63 |
elif n== (N-1): # the last point |
| 64 |
myscreen.addActor( camvtk.Line(p1=(previous.x,previous.y,previous.z),p2=(p.x,p.y,p.z),color=camvtk.yellow) ) # the normal line |
| 65 |
# and a line from p to the first point |
| 66 |
myscreen.addActor( camvtk.Line(p1=(p.x,p.y,p.z),p2=(first_point.x,first_point.y,first_point.z),color=camvtk.yellow) ) |
| 67 |
else: |
| 68 |
myscreen.addActor( camvtk.Line(p1=(previous.x,previous.y,previous.z),p2=(p.x,p.y,p.z),color=camvtk.yellow) ) |
| 69 |
previous=p |
| 70 |
n=n+1 |
| 71 |
print("rendered loop ",nloop, " with ", len(lop), " points") |
| 72 |
nloop = nloop+1 |
| 73 |
|
| 74 |
print("done.") |
| 75 |
myscreen.camera.SetPosition(2, 2, 2) |
| 76 |
myscreen.camera.SetFocalPoint(0.5, 0.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") |