Debian Codegraph @

examples/python/fiber/fiber_16_weave2_STL.py

raw
1 from opencamlib import ocl, camvtk, procmemory
2
3 # 2018.08: Weave not wrapped
4
5 def drawVertices(myscreen, weave, vertexType, vertexRadius, vertexColor):
6 pts = weave.getVertices( vertexType )
7 print(" got ",len(pts)," of type ", vertexType)
8 for p in pts:
9 myscreen.addActor( camvtk.Sphere(center=(p.x,p.y,p.z), radius=vertexRadius, color=vertexColor ) )
10
11 if __name__ == "__main__":
12 print(ocl.version())
13 myscreen = camvtk.VTKScreen()
14 #stl = camvtk.STLSurf("../../stl/demo.stl")
15 stl = camvtk.STLSurf("../../../stl/gnu_tux_mod.stl")
16 myscreen.addActor(stl)
17 stl.SetWireframe()
18 #stl.SetSurface()
19 stl.SetColor(camvtk.grey)
20 polydata = stl.src.GetOutput()
21 s = ocl.STLSurf()
22 camvtk.vtkPolyData2OCLSTL(polydata, s)
23
24 cutter = ocl.CylCutter(0.3, 5)
25 #cutter = ocl.BallCutter(0.4, 5)
26 #cutter = ocl.BullCutter(0.4, 0.1, 5)
27
28 print("fiber...")
29 fiber_range=30
30 Nmax = 400
31 yvals = [float(n-float(Nmax)/2)/Nmax*float(fiber_range) for n in range(0,Nmax+1)]
32 xvals = [float(n-float(Nmax)/2)/Nmax*float(fiber_range) for n in range(0,Nmax+1)]
33
34 zvals=[ 1.6523]
35
36
37 bpc_x = ocl.BatchPushCutter()
38 bpc_y = ocl.BatchPushCutter()
39 bpc_x.setXDirection()
40 bpc_y.setYDirection()
41 bpc_x.setSTL(s)
42 bpc_y.setSTL(s)
43 bpc_x.setCutter(cutter)
44 bpc_y.setCutter(cutter)
45 # create fibers
46 for zh in zvals:
47 for y in yvals:
48 f1 = ocl.Point(-15.5,y,zh) # start point of fiber
49 f2 = ocl.Point(15.5,y,zh) # end point of fiber
50 f = ocl.Fiber( f1, f2)
51 bpc_x.appendFiber(f)
52 for x in xvals:
53 f1 = ocl.Point(x,-15.5,zh) # start point of fiber
54 f2 = ocl.Point(x,15.5,zh) # end point of fiber
55 f = ocl.Fiber( f1, f2)
56 bpc_y.appendFiber(f)
57
58 # run
59 bpc_x.run()
60 bpc_y.run()
61
62 xfibers = bpc_x.getFibers()
63 yfibers = bpc_y.getFibers()
64 fibers = xfibers+yfibers
65 print(" got ",len(xfibers)," xfibers")
66 print(" got ",len(yfibers)," yfibers")
67 print("rendering fibers and CL-points.")
68 w = ocl.Weave()
69 print("push fibers to Weave...",)
70 for f in fibers:
71 w.addFiber(f)
72 print("done.")
73 print("Weave build()...",)
74 mem1 = procmemory.resident()
75 print("before ", mem1)
76 w.build()
77 #w.build2()
78 mem2 = procmemory.resident()
79 print("after ", float(mem2)/float(1024*1024), " MB")
80 print(" build() memory: ",float(mem2-mem1)/float(1024*1024)," MB")
81 print("done")
82 print("face_traverse...")
83 w.face_traverse()
84 print("done.")
85 w_clpts = w.getCLVertices()
86 w_ipts = w.getINTVertices()
87 w_edges = w.getEdges()
88 w_loop = w.getLoops()
89 vertexRadius = 0.007
90 drawVertices(myscreen, w, ocl.WeaveVertexType.CL, vertexRadius, camvtk.red)
91 drawVertices(myscreen, w, ocl.WeaveVertexType.INT, vertexRadius, camvtk.orange)
92 drawVertices(myscreen, w, ocl.WeaveVertexType.FULLINT, vertexRadius, camvtk.yellow)
93 drawVertices(myscreen, w, ocl.WeaveVertexType.ADJ, vertexRadius, camvtk.green)
94 drawVertices(myscreen, w, ocl.WeaveVertexType.TWOADJ, vertexRadius, camvtk.lblue)
95
96 print(" got: ", len(w_edges), " edges")
97 print(" got: ", len(w_loop), " loops")
98
99 # draw the loops
100
101 nloop = 0
102 for lop in w_loop:
103 n = 0
104 N = len(lop)
105 first_point=ocl.Point(-1,-1,5)
106 previous=ocl.Point(-1,-1,5)
107 for p in lop:
108 if n==0: # don't draw anything on the first iteration
109 previous=p
110 first_point = p
111 elif n== (N-1): # the last point
112 myscreen.addActor( camvtk.Line(p1=(previous.x,previous.y,previous.z),p2=(p.x,p.y,p.z),color=camvtk.yellow) ) # the normal line
113 # and a line from p to the first point
114 myscreen.addActor( camvtk.Line(p1=(p.x,p.y,p.z),p2=(first_point.x,first_point.y,first_point.z),color=camvtk.yellow) )
115 else:
116 myscreen.addActor( camvtk.Line(p1=(previous.x,previous.y,previous.z),p2=(p.x,p.y,p.z),color=camvtk.yellow) )
117 previous=p
118 n=n+1
119 print("rendered loop ",nloop, " with ", len(lop), " points")
120 nloop = nloop+1
121
122
123 # draw edges of weave
124 ne = 0
125 zoffset=0.0 # 1
126 dzoffset = 0.000 # 5
127 for e in w_edges:
128 p1 = e[0]
129 p2 = e[1]
130 myscreen.addActor( camvtk.Line( p1=( p1.x,p1.y,p1.z+zoffset+ne*dzoffset), p2=(p2.x,p2.y,p2.z+zoffset+ne*dzoffset) ) )
131 ne = ne+1
132
133 print("done.")
134 myscreen.camera.SetPosition(0.8051, 0.8051, 3.5)
135 myscreen.camera.SetFocalPoint(0.805, 0.805, 0)
136 camvtk.drawArrows(myscreen,center=(-0.5,-0.5,-0.5))
137 camvtk.drawOCLtext(myscreen)
138 myscreen.render()
139 myscreen.iren.Start()
140 #raw_input("Press Enter to terminate")