| 1 |
from opencamlib import ocl, camvtk |
| 2 |
import math |
| 3 |
|
| 4 |
def drawPoints(myscreen, clpoints, ccpoints): |
| 5 |
c=camvtk.PointCloud( pointlist=clpoints, collist=ccpoints) |
| 6 |
c.SetPoints() |
| 7 |
myscreen.addActor(c ) |
| 8 |
|
| 9 |
def drawFiber(myscreen, f, fibercolor): |
| 10 |
inter = f.getInts() |
| 11 |
print("fiber has ", len(inter) , " intervals") |
| 12 |
for i in inter: |
| 13 |
if not i.empty(): |
| 14 |
ip1 = f.point( i.lower ) |
| 15 |
ip2 = f.point( i.upper ) |
| 16 |
myscreen.addActor( camvtk.Line(p1=(ip1.x,ip1.y,ip1.z),p2=(ip2.x,ip2.y,ip2.z), color=fibercolor) ) |
| 17 |
myscreen.addActor( camvtk.Sphere(center=(ip1.x,ip1.y,ip1.z),radius=0.005, color=camvtk.clColor( i.lower_cc) ) ) |
| 18 |
myscreen.addActor( camvtk.Sphere(center=(ip2.x,ip2.y,ip2.z),radius=0.005, color=camvtk.clColor( i.upper_cc) ) ) |
| 19 |
#cc1 = i.lower_cc |
| 20 |
#cc2 = i.upper_cc |
| 21 |
#myscreen.addActor( camvtk.Sphere(center=(cc1.x,cc1.y,cc1.z),radius=0.005, color=camvtk.lgreen ) ) |
| 22 |
#myscreen.addActor( camvtk.Sphere(center=(cc2.x,cc2.y,cc2.z),radius=0.005, color=camvtk.lgreen ) ) |
| 23 |
# cutter circle |
| 24 |
#c1 = camvtk.Circle(center=(ip1.x,ip1.y,ip1.z), radius = 0.3/2, color=fibercolor) |
| 25 |
#myscreen.addActor(c1) |
| 26 |
#c2 = camvtk.Circle(center=(ip2.x,ip2.y,ip2.z), radius = 0.3/2, color=fibercolor) |
| 27 |
#myscreen.addActor(c2) |
| 28 |
|
| 29 |
def drawFiber_clpts(myscreen, f, clcolor): |
| 30 |
inter = f.getInts() |
| 31 |
#print "fiber has ", len(inter) , " intervals" |
| 32 |
for i in inter: |
| 33 |
if not i.empty(): |
| 34 |
ip1 = f.point( i.lower ) |
| 35 |
ip2 = f.point( i.upper ) |
| 36 |
#myscreen.addActor( camvtk.Line(p1=(ip1.x,ip1.y,ip1.z),p2=(ip2.x,ip2.y,ip2.z), color=fibercolor) ) |
| 37 |
sphcolor = camvtk.clColor( i.lower_cc) |
| 38 |
myscreen.addActor( camvtk.Sphere(center=(ip1.x,ip1.y,ip1.z),radius=0.005, color=sphcolor ) ) |
| 39 |
sphcolor = camvtk.clColor( i.upper_cc) |
| 40 |
myscreen.addActor( camvtk.Sphere(center=(ip2.x,ip2.y,ip2.z),radius=0.005, color=sphcolor ) ) |
| 41 |
#cc1 = i.lower_cc |
| 42 |
#cc2 = i.upper_cc |
| 43 |
#myscreen.addActor( camvtk.Sphere(center=(cc1.x,cc1.y,cc1.z),radius=0.005, color=camvtk.pink ) ) |
| 44 |
#myscreen.addActor( camvtk.Sphere(center=(cc2.x,cc2.y,cc2.z),radius=0.005, color=camvtk.pink ) ) |
| 45 |
|
| 46 |
def yfiber(yvals,t,zh,myscreen,cutter,color): |
| 47 |
for y in yvals: |
| 48 |
f1 = ocl.Point(-0.5,y,zh) # start point of fiber |
| 49 |
f2 = ocl.Point(1.5,y,zh) # end point of fiber |
| 50 |
f = ocl.Fiber( f1, f2) |
| 51 |
i = ocl.Interval() |
| 52 |
#cutter.vertexPush(f,i,t) |
| 53 |
#cutter.facetPush(f,i,t) |
| 54 |
#cutter.edgePush(f,i,t) |
| 55 |
cutter.pushCutter(f,i,t) |
| 56 |
f.addInterval(i) |
| 57 |
drawFiber_clpts(myscreen, f, color) |
| 58 |
|
| 59 |
def xfiber(xvals,t,zh,myscreen,cutter,color): |
| 60 |
for x in xvals: |
| 61 |
f1 = ocl.Point(x,-0.5,zh) # start point of fiber |
| 62 |
f2 = ocl.Point(x,1.5,zh) # end point of fiber |
| 63 |
f = ocl.Fiber( f1, f2) |
| 64 |
i = ocl.Interval() |
| 65 |
#cutter.vertexPush(f,i,t) |
| 66 |
#cutter.facetPush(f,i,t) |
| 67 |
#cutter.edgePush(f,i,t) |
| 68 |
cutter.pushCutter(f,i,t) |
| 69 |
f.addInterval(i) |
| 70 |
drawFiber_clpts(myscreen, f, color) |
| 71 |
|
| 72 |
def oneCutterWaterline(myscreen, cutter, zh, color): |
| 73 |
fiber_range=2 |
| 74 |
Nmax = 100 |
| 75 |
yvals = [float(n-float(Nmax)/2)/Nmax*fiber_range for n in range(0,Nmax+1)] |
| 76 |
xvals = [float(n-float(Nmax)/2)/Nmax*fiber_range for n in range(0,Nmax+1)] |
| 77 |
yfiber(yvals,t,zh,myscreen,cutter, color) |
| 78 |
xfiber(xvals,t,zh,myscreen,cutter, color) |
| 79 |
|
| 80 |
if __name__ == "__main__": |
| 81 |
print(ocl.version()) |
| 82 |
myscreen = camvtk.VTKScreen() |
| 83 |
myscreen.camera.SetPosition(0.5, 3, 2) |
| 84 |
myscreen.camera.SetFocalPoint(0.5, 0.5, 0) |
| 85 |
camvtk.drawArrows(myscreen,center=(-0.5,-0.5,-0.5)) |
| 86 |
camvtk.drawOCLtext(myscreen) |
| 87 |
|
| 88 |
a = ocl.Point(0,1,0.2) |
| 89 |
b = ocl.Point(1,0.5,0.0) |
| 90 |
c = ocl.Point(0.1,0.1,0.0) |
| 91 |
myscreen.addActor(camvtk.Point(center=(a.x,a.y,a.z), color=(1,0,1))) |
| 92 |
myscreen.addActor(camvtk.Point(center=(b.x,b.y,b.z), color=(1,0,1))) |
| 93 |
myscreen.addActor(camvtk.Point(center=(c.x,c.y,c.z), color=(1,0,1))) |
| 94 |
myscreen.addActor( camvtk.Line(p1=(a.x,a.y,a.z),p2=(c.x,c.y,c.z)) ) |
| 95 |
myscreen.addActor( camvtk.Line(p1=(c.x,c.y,c.z),p2=(b.x,b.y,b.z)) ) |
| 96 |
myscreen.addActor( camvtk.Line(p1=(a.x,a.y,a.z),p2=(b.x,b.y,b.z)) ) |
| 97 |
t = ocl.Triangle(b,c,a) |
| 98 |
angle = math.pi/4 |
| 99 |
diameter=0.3 |
| 100 |
length=5 |
| 101 |
cutter1 = ocl.BallCutter(diameter, length) |
| 102 |
cutter2 = ocl.CylCutter(diameter, length) |
| 103 |
cutter3 = ocl.BullCutter(diameter, diameter/4, length) |
| 104 |
cutter4 = ocl.ConeCutter(diameter, angle, length) |
| 105 |
#cutter = cutter.offsetCutter( 0.1 ) |
| 106 |
|
| 107 |
|
| 108 |
fiber_range=2 |
| 109 |
Nmax = 50 |
| 110 |
yvals = [float(n-float(Nmax)/2)/Nmax*fiber_range for n in range(0,Nmax+1)] |
| 111 |
xvals = [float(n-float(Nmax)/2)/Nmax*fiber_range for n in range(0,Nmax+1)] |
| 112 |
zmin = -0.1 |
| 113 |
zmax = 0.25 |
| 114 |
zNmax =5 |
| 115 |
dz = (zmax-zmin)/(zNmax-1) |
| 116 |
zvals=[] |
| 117 |
for n in range(0,zNmax): |
| 118 |
zvals.append(zmin+n*dz) |
| 119 |
|
| 120 |
for zh in zvals: |
| 121 |
oneCutterWaterline(myscreen, cutter1, zh, camvtk.yellow) |
| 122 |
oneCutterWaterline(myscreen, cutter2, zh, camvtk.cyan) |
| 123 |
oneCutterWaterline(myscreen, cutter3, zh, camvtk.mag) |
| 124 |
oneCutterWaterline(myscreen, cutter4, zh, camvtk.mag) |
| 125 |
#yfiber(yvals,t,zh,myscreen) |
| 126 |
#xfiber(xvals,t,zh,myscreen) |
| 127 |
|
| 128 |
print("done.") |
| 129 |
|
| 130 |
myscreen.render() |
| 131 |
#w2if = vtk.vtkWindowToImageFilter() |
| 132 |
#w2if.SetInput(myscreen.renWin) |
| 133 |
#lwr = vtk.vtkPNGWriter() |
| 134 |
#lwr.SetInput( w2if.GetOutput() ) |
| 135 |
|
| 136 |
myscreen.iren.Start() |
| 137 |
#raw_input("Press Enter to terminate") |