| 1 |
from opencamlib import ocl, camvtk |
| 2 |
|
| 3 |
def drawPoints(myscreen, clpoints, ccpoints): |
| 4 |
c=camvtk.PointCloud( pointlist=clpoints, collist=ccpoints) |
| 5 |
c.SetPoints() |
| 6 |
myscreen.addActor(c ) |
| 7 |
|
| 8 |
def drawFiber(myscreen, f, fibercolor=camvtk.red): |
| 9 |
inter = f.getInts() |
| 10 |
for i in inter: |
| 11 |
if not i.empty(): |
| 12 |
ip1 = f.point( i.lower ) |
| 13 |
ip2 = f.point( i.upper ) |
| 14 |
myscreen.addActor( camvtk.Line(p1=(ip1.x,ip1.y,ip1.z),p2=(ip2.x,ip2.y,ip2.z), color=fibercolor) ) |
| 15 |
myscreen.addActor( camvtk.Sphere(center=(ip1.x,ip1.y,ip1.z),radius=0.005, color=camvtk.clColor( i.lower_cc) ) ) |
| 16 |
myscreen.addActor( camvtk.Sphere(center=(ip2.x,ip2.y,ip2.z),radius=0.005, color=camvtk.clColor( i.upper_cc) ) ) |
| 17 |
cc1 = i.lower_cc |
| 18 |
cc2 = i.upper_cc |
| 19 |
myscreen.addActor( camvtk.Sphere(center=(cc1.x,cc1.y,cc1.z),radius=0.005, color=camvtk.lgreen ) ) |
| 20 |
myscreen.addActor( camvtk.Sphere(center=(cc2.x,cc2.y,cc2.z),radius=0.005, color=camvtk.lgreen ) ) |
| 21 |
# cutter circle |
| 22 |
#c1 = camvtk.Circle(center=(ip1.x,ip1.y,ip1.z), radius = 0.3/2, color=fibercolor) |
| 23 |
#myscreen.addActor(c1) |
| 24 |
#c2 = camvtk.Circle(center=(ip2.x,ip2.y,ip2.z), radius = 0.3/2, color=fibercolor) |
| 25 |
#myscreen.addActor(c2) |
| 26 |
|
| 27 |
def drawFiber_clpts(myscreen, f, fibercolor=camvtk.red): |
| 28 |
inter = f.getInts() |
| 29 |
for i in inter: |
| 30 |
if not i.empty(): |
| 31 |
ip1 = f.point( i.lower ) |
| 32 |
ip2 = f.point( i.upper ) |
| 33 |
myscreen.addActor( camvtk.Line(p1=(ip1.x,ip1.y,ip1.z),p2=(ip2.x,ip2.y,ip2.z), color=fibercolor) ) |
| 34 |
myscreen.addActor( camvtk.Sphere(center=(ip1.x,ip1.y,ip1.z),radius=0.005, color=camvtk.clColor( i.lower_cc) ) ) |
| 35 |
myscreen.addActor( camvtk.Sphere(center=(ip2.x,ip2.y,ip2.z),radius=0.005, color=camvtk.clColor( i.upper_cc) ) ) |
| 36 |
#cc1 = i.lower_cc |
| 37 |
#cc2 = i.upper_cc |
| 38 |
#myscreen.addActor( camvtk.Sphere(center=(cc1.x,cc1.y,cc1.z),radius=0.005, color=camvtk.lgreen ) ) |
| 39 |
#myscreen.addActor( camvtk.Sphere(center=(cc2.x,cc2.y,cc2.z),radius=0.005, color=camvtk.lgreen ) ) |
| 40 |
|
| 41 |
def yfiber(yvals,s,zh,myscreen): |
| 42 |
for y in yvals: |
| 43 |
f1 = ocl.Point(-20,y,zh) # start point of fiber |
| 44 |
f2 = ocl.Point(+20,y,zh) # end point of fiber |
| 45 |
f = ocl.Fiber( f1, f2) |
| 46 |
for t in s.getTriangles(): |
| 47 |
i = ocl.Interval() |
| 48 |
#cutter.vertexPush(f,i,t) |
| 49 |
#cutter.facetPush(f,i,t) |
| 50 |
#cutter.edgePush(f,i,t) |
| 51 |
cutter.pushCutter(f,i,t) |
| 52 |
f.addInterval(i) |
| 53 |
drawFiber_clpts(myscreen, f, camvtk.red) |
| 54 |
|
| 55 |
def xfiber(xvals,s,zh,myscreen): |
| 56 |
for x in xvals: |
| 57 |
f1 = ocl.Point(x,-20,zh) # start point of fiber |
| 58 |
f2 = ocl.Point(x,+20,zh) # end point of fiber |
| 59 |
f = ocl.Fiber( f1, f2) |
| 60 |
for t in s.getTriangles(): |
| 61 |
i = ocl.Interval() |
| 62 |
#cutter.vertexPush(f,i,t) |
| 63 |
#cutter.facetPush(f,i,t) |
| 64 |
#cutter.edgePush(f,i,t) |
| 65 |
cutter.pushCutter(f,i,t) |
| 66 |
f.addInterval(i) |
| 67 |
drawFiber_clpts(myscreen, f, camvtk.lblue) |
| 68 |
|
| 69 |
if __name__ == "__main__": |
| 70 |
print(ocl.version() ) |
| 71 |
myscreen = camvtk.VTKScreen() |
| 72 |
#stl = camvtk.STLSurf("../../stl/gnu_tux_mod.stl") |
| 73 |
stl = camvtk.STLSurf("../../../stl/demo.stl") |
| 74 |
myscreen.addActor(stl) |
| 75 |
stl.SetWireframe() |
| 76 |
stl.SetColor((1,1,1)) |
| 77 |
polydata = stl.src.GetOutput() |
| 78 |
s = ocl.STLSurf() |
| 79 |
camvtk.vtkPolyData2OCLSTL(polydata, s) |
| 80 |
print("STL surface read,", s.size(), "triangles") |
| 81 |
|
| 82 |
cutter = ocl.CylCutter(0.3, 6) |
| 83 |
print("length=", cutter.getLength()) |
| 84 |
print("fiber...",) |
| 85 |
fiber_range=30 |
| 86 |
Nmax = 200 |
| 87 |
yvals = [float(n-float(Nmax)/2)/Nmax*fiber_range for n in range(0,Nmax+1)] |
| 88 |
xvals = [float(n-float(Nmax)/2)/Nmax*fiber_range for n in range(0,Nmax+1)] |
| 89 |
zmin = -0.1 |
| 90 |
zmax = 0.5 |
| 91 |
zNmax = 2 |
| 92 |
dz = (zmax-zmin)/(zNmax-1) |
| 93 |
zvals=[] |
| 94 |
#for n in range(0,zNmax): |
| 95 |
# zvals.append(zmin+n*dz) |
| 96 |
zvals.append(0.1) |
| 97 |
#zvals = [ float(n-float(zNmax)/2)/zNmax*fiber_range for n in range(0,zNmax+1)] |
| 98 |
#print zvals |
| 99 |
#exit() |
| 100 |
#cc = ocl.CCPoint() |
| 101 |
#zh = -0.1 |
| 102 |
#zh = 0.2571567 |
| 103 |
|
| 104 |
for zh in zvals: |
| 105 |
print("fibers at z=",zh) |
| 106 |
yfiber(yvals,s,zh,myscreen) |
| 107 |
xfiber(xvals,s,zh,myscreen) |
| 108 |
|
| 109 |
print("done.") |
| 110 |
myscreen.camera.SetPosition(0.5, 3, 2) |
| 111 |
myscreen.camera.SetFocalPoint(0.5, 0.5, 0) |
| 112 |
camvtk.drawArrows(myscreen,center=(-0.5,-0.5,-0.5)) |
| 113 |
camvtk.drawOCLtext(myscreen) |
| 114 |
myscreen.render() |
| 115 |
#w2if = vtk.vtkWindowToImageFilter() |
| 116 |
#w2if.SetInput(myscreen.renWin) |
| 117 |
#lwr = vtk.vtkPNGWriter() |
| 118 |
#lwr.SetInput( w2if.GetOutput() ) |
| 119 |
myscreen.iren.Start() |
| 120 |
#raw_input("Press Enter to terminate") |