Debian Codegraph @

examples/python/fiber/fiber_15_conecutter_anim.py

raw
1 from opencamlib import ocl, camvtk
2 import math
3 import os
4
5 def drawFiber_clpts(myscreen, f, fibercolor=camvtk.red):
6 inter = f.getInts()
7 #print "fiber has ", len(inter) , " intervals"
8 for i in inter:
9 if not i.empty():
10 ip1 = f.point( i.lower )
11 ip2 = f.point( i.upper )
12 #myscreen.addActor( camvtk.Line(p1=(ip1.x,ip1.y,ip1.z),p2=(ip2.x,ip2.y,ip2.z), color=fibercolor) )
13 myscreen.addActor( camvtk.Sphere(center=(ip1.x,ip1.y,ip1.z),radius=0.005, color=camvtk.clColor( i.lower_cc) ) )
14 myscreen.addActor( camvtk.Sphere(center=(ip2.x,ip2.y,ip2.z),radius=0.005, color=camvtk.clColor( i.upper_cc) ) )
15 #cc1 = i.lower_cc
16 #cc2 = i.upper_cc
17 #myscreen.addActor( camvtk.Sphere(center=(cc1.x,cc1.y,cc1.z),radius=0.005, color=camvtk.pink ) )
18 #myscreen.addActor( camvtk.Sphere(center=(cc2.x,cc2.y,cc2.z),radius=0.005, color=camvtk.pink ) )
19
20 # colors from camvtk.py:
21 # ocl.CCType.VERTEX: col = red
22 # ocl.CCType.EDGE_HORIZ: col = orange
23 # ocl.CCType.EDGE_SHAFT: col = mag
24
25 def yfiber(cutter,yvals,t,zh,myscreen):
26 for y in yvals:
27 f1 = ocl.Point(-5.5,y,zh) # start point of fiber
28 f2 = ocl.Point(5.5,y,zh) # end point of fiber
29 f = ocl.Fiber( f1, f2)
30 i = ocl.Interval()
31 cutter.pushCutter(f,i,t)
32 f.addInterval(i)
33 drawFiber_clpts(myscreen, f, camvtk.red)
34
35 def xfiber(cutter,xvals,t,zh,myscreen):
36 for x in xvals:
37 f1 = ocl.Point(x,-5.5,zh) # start point of fiber
38 f2 = ocl.Point(x,5.5,zh) # end point of fiber
39 f = ocl.Fiber( f1, f2)
40 i = ocl.Interval()
41 cutter.pushCutter(f,i,t)
42 f.addInterval(i)
43 drawFiber_clpts(myscreen, f, camvtk.lblue)
44
45 def drawScreen(a,b,c,filename,write_flag):
46 print(ocl.version())
47 myscreen = camvtk.VTKScreen()
48 z_hi = a.z
49 if b.z > z_hi:
50 z_hi = b.z
51 if c.z > z_hi:
52 z_hi = c.z
53
54 z_lo = a.z
55 if b.z < z_lo:
56 z_lo = b.z
57 if c.z < z_lo:
58 z_lo = c.z
59 #z_hi = 0.3 # this is the shallow case
60 #ztri = 0.8 # this produces the steep case where we hit the circular rim
61
62 #z_lo = 0.1
63 #a = ocl.Point(0,1,ztri)
64 #b = ocl.Point(1,0.5,ztri)
65 #c = ocl.Point(0.2,0.2,ztri_lo)
66
67 myscreen.addActor(camvtk.Point(center=(a.x,a.y,a.z), color=(1,0,1)))
68 myscreen.addActor(camvtk.Point(center=(b.x,b.y,b.z), color=(1,0,1)))
69 myscreen.addActor(camvtk.Point(center=(c.x,c.y,c.z), color=(1,0,1)))
70 myscreen.addActor( camvtk.Line(p1=(a.x,a.y,a.z),p2=(c.x,c.y,c.z)) )
71 myscreen.addActor( camvtk.Line(p1=(c.x,c.y,c.z),p2=(b.x,b.y,b.z)) )
72 myscreen.addActor( camvtk.Line(p1=(a.x,a.y,a.z),p2=(b.x,b.y,b.z)) )
73 t = ocl.Triangle(b,c,a)
74 angle = math.pi/5
75 diameter=0.3
76 length=5
77 #cutter = ocl.BallCutter(diameter, length)
78 #cutter = ocl.CylCutter(diameter, length)
79 #cutter = ocl.BullCutter(diameter, diameter/4, length)
80 cutter = ocl.ConeCutter(diameter, angle, length)
81 #cutter = cutter.offsetCutter( 0.1 )
82
83 print("cutter= ", cutter)
84 print("length=", cutter.getLength())
85 print("fiber...")
86 fiber_range=2
87 Nmax = 100
88 yvals = [float(n-float(Nmax)/2)/Nmax*fiber_range for n in range(0,Nmax+1)]
89 xvals = [float(n-float(Nmax)/2)/Nmax*fiber_range for n in range(0,Nmax+1)]
90 zmin = z_lo - 0.3
91 zmax = z_hi
92 zNmax = 20
93 dz = (zmax-zmin)/(zNmax-1)
94 zvals=[]
95 for n in range(0,zNmax):
96 zvals.append(zmin+n*dz)
97 for zh in zvals:
98 yfiber(cutter,yvals,t,zh,myscreen)
99 xfiber(cutter,xvals,t,zh,myscreen)
100 print("done.")
101 myscreen.camera.SetPosition(-2, -1, 3)
102 myscreen.camera.SetFocalPoint(1.0, 0.0, -0.5)
103 camvtk.drawArrows(myscreen,center=(-0.5,-0.5,-0.5))
104 camvtk.drawOCLtext(myscreen)
105 myscreen.render()
106 """
107 w2if = vtk.vtkWindowToImageFilter()
108 w2if.SetInput(myscreen.renWin)
109 lwr = vtk.vtkPNGWriter()
110 lwr.SetInput( w2if.GetOutput() )
111 w2if.Modified()
112 lwr.SetFileName(filename)
113 if write_flag:
114 lwr.Write()
115 print("wrote ",filename)
116 """
117
118 #myscreen.iren.Start()
119 #raw_input("Press Enter to terminate")
120
121 if __name__ == "__main__":
122 ztri = 0.3 # this is the shallow case
123 #ztri = 0.8 # this produces the steep case where we hit the circular rim
124 ztri_lo = 0.1
125 Nmax = 300
126 thetamax = 2*math.pi
127 for n in range(0,Nmax):
128 theta=thetamax/Nmax
129 a = ocl.Point(0,1,ztri)
130 a.xRotate(theta*n)
131 b = ocl.Point(1,0.0,0)
132 b.xRotate(theta*n)
133 c = ocl.Point(0.2,0.0,ztri)
134 c.xRotate(theta*n)
135 current_dir = os.getcwd()
136 filename = current_dir + "/frames/conecutter_"+ ('%05d' % n)+".png"
137 drawScreen(a,b,c,filename, 1)
138