| 1 |
from opencamlib import ocl, camvtk |
| 2 |
import time |
| 3 |
|
| 4 |
def drawLoops(myscreen, loops, loopcolor): |
| 5 |
nloop = 0 |
| 6 |
for lop in loops: |
| 7 |
n = 0 |
| 8 |
N = len(lop) |
| 9 |
first_point=ocl.Point(-1,-1,5) |
| 10 |
previous=ocl.Point(-1,-1,5) |
| 11 |
for p in lop: |
| 12 |
if n==0: # don't draw anything on the first iteration |
| 13 |
previous=p |
| 14 |
first_point = p |
| 15 |
elif n== (N-1): # the last point |
| 16 |
myscreen.addActor( camvtk.Line(p1=(previous.x,previous.y,previous.z),p2=(p.x,p.y,p.z),color=loopcolor) ) # the normal line |
| 17 |
# and a line from p to the first point |
| 18 |
myscreen.addActor( camvtk.Line(p1=(p.x,p.y,p.z),p2=(first_point.x,first_point.y,first_point.z),color=loopcolor) ) |
| 19 |
else: |
| 20 |
myscreen.addActor( camvtk.Line(p1=(previous.x,previous.y,previous.z),p2=(p.x,p.y,p.z),color=loopcolor) ) |
| 21 |
previous=p |
| 22 |
n=n+1 |
| 23 |
print("rendered loop ",nloop, " with ", len(lop), " points") |
| 24 |
if len(lop) == 2: |
| 25 |
for p in lop: |
| 26 |
print(p) |
| 27 |
myscreen.addActor( camvtk.Sphere(center=(p.x,p.y,p.z),radius=0.1,color=camvtk.green) ) |
| 28 |
nloop = nloop+1 |
| 29 |
|
| 30 |
|
| 31 |
if __name__ == "__main__": |
| 32 |
print(ocl.version()) |
| 33 |
myscreen = camvtk.VTKScreen() |
| 34 |
#stl = camvtk.STLSurf("../../../stl/demo.stl") |
| 35 |
#stl = camvtk.STLSurf("../../../stl/gnu_tux_mod.stl") |
| 36 |
#stl = camvtk.STLSurf("../../../stl/porche.stl") |
| 37 |
#stl = camvtk.STLSurf("../../../stl/ktoolcav.stl") |
| 38 |
#stl = camvtk.STLSurf("../../../stl/ktoolcor.stl") |
| 39 |
stl = camvtk.STLSurf("../../../stl/sphere_cutout.stl") |
| 40 |
#myscreen.addActor(stl) |
| 41 |
#stl.SetWireframe() # render tux as wireframe |
| 42 |
#stl.SetSurface() # render tux as surface |
| 43 |
#stl.SetColor(camvtk.cyan) |
| 44 |
polydata = stl.src.GetOutput() # get polydata from vtk-surface |
| 45 |
s = ocl.STLSurf() |
| 46 |
camvtk.vtkPolyData2OCLSTL(polydata, s) #put triangles on ocl-surface |
| 47 |
#s.rotate(-math.pi/2,math.pi,0) |
| 48 |
stl2 = camvtk.STLSurf(triangleList= s.getTriangles() ) |
| 49 |
myscreen.addActor(stl2) |
| 50 |
stl2.SetSurface() |
| 51 |
stl2.SetColor(camvtk.cyan) |
| 52 |
print("STL surface read,", s.size(), "triangles") |
| 53 |
zh=-0.5 |
| 54 |
zheights=[ -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, -0.05] # for cavity |
| 55 |
zheights=[ -0.1, 0.0, 0.1, 0.2, 0.3, 0.4 , 0.5, 0.6, 0.7] # for core |
| 56 |
zheights=[ 10, 20, 30, 40, 50, 60] # for waterline1.stl |
| 57 |
diam = 6 |
| 58 |
length = 100 |
| 59 |
loops = [] |
| 60 |
|
| 61 |
#cutter = ocl.CylCutter( diam , length ) |
| 62 |
cutter = ocl.BallCutter( diam , length ) |
| 63 |
#cutter = ocl.BullCutter( diam , diam/5, length ) |
| 64 |
""" |
| 65 |
wl = ocl.Waterline() |
| 66 |
wl.setSTL(s) |
| 67 |
wl.setCutter(cutter) |
| 68 |
wl.setZ(zh) |
| 69 |
wl.setSampling(0.02) |
| 70 |
#wl.setThreads(5) |
| 71 |
t_before = time.time() |
| 72 |
wl.run2() |
| 73 |
t_after = time.time() |
| 74 |
calctime = t_after-t_before |
| 75 |
print(" Waterline done in ", calctime," s") |
| 76 |
cutter_loops = wl.getLoops() |
| 77 |
for l in cutter_loops: |
| 78 |
loops.append(l) |
| 79 |
""" |
| 80 |
sampling=1 |
| 81 |
minSampling=0.1 |
| 82 |
|
| 83 |
aloops = [] |
| 84 |
for zh in zheights: |
| 85 |
awl = ocl.AdaptiveWaterline() |
| 86 |
awl.setSTL(s) |
| 87 |
awl.setCutter(cutter) |
| 88 |
awl.setZ(zh) |
| 89 |
awl.setSampling(sampling) |
| 90 |
awl.setMinSampling(minSampling) |
| 91 |
#wl.setThreads(5) |
| 92 |
t_before = time.time() |
| 93 |
awl.run() |
| 94 |
t_after = time.time() |
| 95 |
calctime = t_after-t_before |
| 96 |
print(" AdaptiveWaterline done in ", calctime," s") |
| 97 |
acutter_loops = awl.getLoops() |
| 98 |
for l in acutter_loops: |
| 99 |
aloops.append(l) |
| 100 |
|
| 101 |
drawLoops(myscreen, aloops, camvtk.red) |
| 102 |
|
| 103 |
print("done.") |
| 104 |
myscreen.camera.SetPosition(185, 153, 167) |
| 105 |
myscreen.camera.SetFocalPoint(5, 5, 0) |
| 106 |
camvtk.drawArrows(myscreen,center=(0,-4,0)) |
| 107 |
camvtk.drawOCLtext(myscreen) |
| 108 |
myscreen.render() |
| 109 |
myscreen.iren.Start() |
| 110 |
#raw_input("Press Enter to terminate") |