Debian Codegraph @

examples/python/fiber/fiber_06_batch_stl.py

raw
1 from opencamlib import ocl, camvtk
2 import time
3
4 def generateRange(zmin,zmax,zNmax):
5 dz = (float(zmax)-float(zmin))/(zNmax-1)
6 zvals=[]
7 for n in range(0,zNmax):
8 zvals.append(zmin+n*dz)
9 return zvals
10
11
12 if __name__ == "__main__":
13 print(ocl.version())
14
15 myscreen = camvtk.VTKScreen()
16 #stl = camvtk.STLSurf("../../stl/demo.stl")
17 stl = camvtk.STLSurf("../../../stl/gnu_tux_mod.stl")
18 myscreen.addActor(stl)
19 #stl.SetWireframe()
20 stl.SetSurface()
21 stl.SetColor(camvtk.cyan)
22 polydata = stl.src.GetOutput()
23 s = ocl.STLSurf()
24 camvtk.vtkPolyData2OCLSTL(polydata, s)
25 print("STL surface read,", s.size(), "triangles")
26 bounds = s.getBounds()
27 print("STLSurf.Bounds()=", bounds)
28 cutter = ocl.CylCutter(0.3,6)
29 #cutter = ocl.BallCutter(0.3,6)
30
31 cutter.length = 4.0
32 print(cutter)
33 xmin=-1
34 xmax=15
35 N=100
36 ymin=-1
37 ymax=15
38 yvals = generateRange(ymin,ymax,N)
39 xvals = generateRange(xmin,xmax,N)
40 #print xvals
41 zmin = -0.1
42 zmax = 2.75
43 zNmax = 7
44 zvals = generateRange(zmin,zmax,zNmax)
45 print(" calculating waterlines at ", len(zvals)," different z-heights")
46 #print zvals
47 bpc_x = ocl.BatchPushCutter()
48 bpc_y = ocl.BatchPushCutter()
49 bpc_x.setXDirection()
50 bpc_y.setYDirection()
51 bpc_x.setSTL(s)
52 bpc_y.setSTL(s)
53 bpc_x.setCutter(cutter)
54 bpc_y.setCutter(cutter)
55 # create fibers
56 nfibers=0
57 for zh in zvals:
58 for y in yvals:
59 f1 = ocl.Point(xmin,y,zh) # start point of fiber
60 f2 = ocl.Point(xmax,y,zh) # end point of fiber
61 f = ocl.Fiber( f1, f2)
62 bpc_x.appendFiber(f)
63
64 nfibers=nfibers+1
65 for x in xvals:
66 f1 = ocl.Point(x,ymin,zh) # start point of fiber
67 f2 = ocl.Point(x,ymax,zh) # end point of fiber
68 f = ocl.Fiber( f1, f2)
69 bpc_y.appendFiber(f)
70
71 nfibers=nfibers+1
72 # run
73 #t_before = time.time()
74 #bpc2.pushCutter2()
75 #t_after = time.time()
76 #push_calctime = t_after-t_before
77 #print " BPC done in ", push_calctime," s", bpc2.nCalls," push-calls"
78 #print (push_calctime/bpc2.nCalls)*1e6, " us/call"
79
80 t_before = time.time()
81 bpc_x.run()
82 bpc_y.run()
83 t_after = time.time()
84 push_calctime = t_after-t_before
85 print(" BPC 3 done in ", push_calctime," s", bpc_x.getCalls()," push-calls" )
86
87
88 clpoints = bpc_x.getCLPoints()
89 clp2 = bpc_y.getCLPoints()
90 clpoints+=clp2
91 print("got ", len(clpoints), " CL-points")
92 print("rendering raw CL-points.")
93
94 # draw the CL-points
95 camvtk.drawCLPointCloud(myscreen, clpoints)
96 for p in clpoints:
97 myscreen.addActor( camvtk.Sphere(center=(p.x,p.y,p.z),radius=0.02, color=camvtk.clColor( p.cc() ) ) )
98
99
100
101
102 print("done.")
103 myscreen.camera.SetPosition(0.5, 3, 2)
104 myscreen.camera.SetFocalPoint(0.5, 0.5, 0)
105 camvtk.drawArrows(myscreen,center=(-0.5,-0.5,-0.5))
106 camvtk.drawOCLtext(myscreen)
107
108 myscreen.render()
109
110 myscreen.iren.Start()
111 #raw_input("Press Enter to terminate")