| 1 |
from opencamlib import ocl, camvtk |
| 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 |
a = ocl.Point(0,1,0.3) |
| 15 |
#myscreen.addActor(camvtk.Point(center=(a.x,a.y,a.z), color=(1,0,1))) |
| 16 |
b = ocl.Point(1,0.5,0.3) |
| 17 |
#myscreen.addActor(camvtk.Point(center=(b.x,b.y,b.z), color=(1,0,1))) |
| 18 |
c = ocl.Point(0,0,0.1) |
| 19 |
#myscreen.addActor(camvtk.Point(center=(c.x,c.y,c.z), color=(1,0,1))) |
| 20 |
#myscreen.addActor( camvtk.Line(p1=(a.x,a.y,a.z),p2=(c.x,c.y,c.z)) ) |
| 21 |
#myscreen.addActor( camvtk.Line(p1=(c.x,c.y,c.z),p2=(b.x,b.y,b.z)) ) |
| 22 |
#myscreen.addActor( camvtk.Line(p1=(a.x,a.y,a.z),p2=(b.x,b.y,b.z)) ) |
| 23 |
|
| 24 |
# a second triangle |
| 25 |
offset=ocl.Point(0.51,0.51,0) |
| 26 |
a2 = a+ offset |
| 27 |
b2 = b+ offset |
| 28 |
c2 = c+ offset |
| 29 |
t2 = ocl.Triangle(b2,c2,a2) |
| 30 |
|
| 31 |
t = ocl.Triangle(b,c,a) |
| 32 |
s = ocl.STLSurf() |
| 33 |
s.addTriangle(t) # a one-triangle STLSurf |
| 34 |
s.addTriangle(t2) |
| 35 |
|
| 36 |
cutter = ocl.CylCutter(0.3, 5) |
| 37 |
#cutter = ocl.BallCutter(0.4, 5) |
| 38 |
#cutter = ocl.BullCutter(0.4, 0.1, 5) |
| 39 |
|
| 40 |
print("fiber...") |
| 41 |
fiber_range=7 |
| 42 |
Nmax = 200 |
| 43 |
yvals = [float(n-float(Nmax)/2)/Nmax*float(fiber_range) for n in range(0,Nmax+1)] |
| 44 |
xvals = [float(n-float(Nmax)/2)/Nmax*float(fiber_range) for n in range(0,Nmax+1)] |
| 45 |
|
| 46 |
zvals=[ 0.23] |
| 47 |
|
| 48 |
|
| 49 |
bpc_x = ocl.BatchPushCutter() |
| 50 |
bpc_y = ocl.BatchPushCutter() |
| 51 |
bpc_x.setXDirection() |
| 52 |
bpc_y.setYDirection() |
| 53 |
bpc_x.setSTL(s) |
| 54 |
bpc_y.setSTL(s) |
| 55 |
bpc_x.setCutter(cutter) |
| 56 |
bpc_y.setCutter(cutter) |
| 57 |
# create fibers |
| 58 |
for zh in zvals: |
| 59 |
for y in yvals: |
| 60 |
f1 = ocl.Point(-5.5,y,zh) # start point of fiber |
| 61 |
f2 = ocl.Point(5.5,y,zh) # end point of fiber |
| 62 |
f = ocl.Fiber( f1, f2) |
| 63 |
bpc_x.appendFiber(f) |
| 64 |
for x in xvals: |
| 65 |
f1 = ocl.Point(x,-5.5,zh) # start point of fiber |
| 66 |
f2 = ocl.Point(x,5.5,zh) # end point of fiber |
| 67 |
f = ocl.Fiber( f1, f2) |
| 68 |
bpc_y.appendFiber(f) |
| 69 |
|
| 70 |
# run |
| 71 |
bpc_x.run() |
| 72 |
bpc_y.run() |
| 73 |
#clpoints = bpc_x.getCLPoints() |
| 74 |
#clp2 = bpc_y.getCLPoints() |
| 75 |
#clpoints+=clp2 |
| 76 |
xfibers = bpc_x.getFibers() |
| 77 |
yfibers = bpc_y.getFibers() |
| 78 |
fibers = xfibers+yfibers |
| 79 |
print(" got ",len(xfibers)," xfibers") |
| 80 |
print(" got ",len(yfibers)," yfibers") |
| 81 |
print("rendering fibers and CL-points.") |
| 82 |
w = ocl.Weave() |
| 83 |
print("push fibers to Weave...",) |
| 84 |
for f in fibers: |
| 85 |
w.addFiber(f) |
| 86 |
print("done.") |
| 87 |
print("Weave build()...",) |
| 88 |
#w.build() |
| 89 |
w.build() |
| 90 |
print("done") |
| 91 |
print("face_traverse...") |
| 92 |
w.face_traverse() |
| 93 |
print("done.") |
| 94 |
w_clpts = w.getCLVertices() |
| 95 |
w_ipts = w.getINTVertices() |
| 96 |
w_edges = w.getEdges() |
| 97 |
w_loop = w.getLoops() |
| 98 |
vertexRadius = 0.007 |
| 99 |
drawVertices(myscreen, w, ocl.WeaveVertexType.CL, vertexRadius, camvtk.red) |
| 100 |
drawVertices(myscreen, w, ocl.WeaveVertexType.INT, vertexRadius, camvtk.orange) |
| 101 |
drawVertices(myscreen, w, ocl.WeaveVertexType.FULLINT, vertexRadius, camvtk.yellow) |
| 102 |
drawVertices(myscreen, w, ocl.WeaveVertexType.ADJ, vertexRadius, camvtk.green) |
| 103 |
drawVertices(myscreen, w, ocl.WeaveVertexType.TWOADJ, vertexRadius, camvtk.lblue) |
| 104 |
|
| 105 |
print(" got: ", len(w_edges), " edges") |
| 106 |
print(" got: ", len(w_loop), " loop points") |
| 107 |
|
| 108 |
|
| 109 |
previous = 0 |
| 110 |
# draw the loop as a yellow line |
| 111 |
for loop in w_loop: |
| 112 |
np = 0 |
| 113 |
for p in loop: |
| 114 |
#myscreen.addActor( camvtk.Sphere(center=(p.x,p.y,p.z+zoffset2), radius=0.006, color=camvtk.pink ) ) |
| 115 |
if np is not 0: |
| 116 |
myscreen.addActor( camvtk.Line( p1=(previous.x,previous.y, previous.z), |
| 117 |
p2=(p.x,p.y,p.z), color=camvtk.yellow) ) |
| 118 |
np=np+1 |
| 119 |
previous = p |
| 120 |
|
| 121 |
# draw edges of weave |
| 122 |
ne = 0 |
| 123 |
zoffset=0.0 # 1 |
| 124 |
dzoffset = 0.000 # 5 |
| 125 |
for e in w_edges: |
| 126 |
p1 = e[0] |
| 127 |
p2 = e[1] |
| 128 |
myscreen.addActor( camvtk.Line( p1=( p1.x,p1.y,p1.z+zoffset+ne*dzoffset), p2=(p2.x,p2.y,p2.z+zoffset+ne*dzoffset) ) ) |
| 129 |
ne = ne+1 |
| 130 |
|
| 131 |
print("done.") |
| 132 |
myscreen.camera.SetPosition(0.8051, 0.8051, 3.5) |
| 133 |
myscreen.camera.SetFocalPoint(0.805, 0.805, 0) |
| 134 |
camvtk.drawArrows(myscreen,center=(-0.5,-0.5,-0.5)) |
| 135 |
camvtk.drawOCLtext(myscreen) |
| 136 |
myscreen.render() |
| 137 |
myscreen.iren.Start() |
| 138 |
#raw_input("Press Enter to terminate") |