| 1 |
from opencamlib import ocl, camvtk, procmemory |
| 2 |
import csv |
| 3 |
import gc |
| 4 |
|
| 5 |
# 2018.08: Weave not wrapped |
| 6 |
|
| 7 |
def drawVertices(myscreen, weave, vertexType, vertexRadius, vertexColor): |
| 8 |
pts = weave.getVertices( vertexType ) |
| 9 |
print(" got ",len(pts)," of type ", vertexType) |
| 10 |
for p in pts: |
| 11 |
myscreen.addActor( camvtk.Sphere(center=(p.x,p.y,p.z), radius=vertexRadius, color=vertexColor ) ) |
| 12 |
|
| 13 |
def getWeaveRAM(Nmax,weave2_flag): |
| 14 |
#stl = camvtk.STLSurf("../../stl/demo.stl") |
| 15 |
stl = camvtk.STLSurf("../../../stl/gnu_tux_mod.stl") |
| 16 |
polydata = stl.src.GetOutput() |
| 17 |
s = ocl.STLSurf() |
| 18 |
camvtk.vtkPolyData2OCLSTL(polydata, s) |
| 19 |
cutter = ocl.CylCutter(0.3, 5) |
| 20 |
fiber_range=30 |
| 21 |
#Nmax = 400 |
| 22 |
yvals = [float(n-float(Nmax)/2)/Nmax*float(fiber_range) for n in range(0,Nmax+1)] |
| 23 |
xvals = [float(n-float(Nmax)/2)/Nmax*float(fiber_range) for n in range(0,Nmax+1)] |
| 24 |
zvals=[ 1.6523] |
| 25 |
bpc_x = ocl.BatchPushCutter() |
| 26 |
bpc_y = ocl.BatchPushCutter() |
| 27 |
bpc_x.setXDirection() |
| 28 |
bpc_y.setYDirection() |
| 29 |
bpc_x.setSTL(s) |
| 30 |
bpc_y.setSTL(s) |
| 31 |
bpc_x.setCutter(cutter) |
| 32 |
bpc_y.setCutter(cutter) |
| 33 |
# create fibers |
| 34 |
for zh in zvals: |
| 35 |
for y in yvals: |
| 36 |
f1 = ocl.Point(-15.5,y,zh) # start point of fiber |
| 37 |
f2 = ocl.Point(15.5,y,zh) # end point of fiber |
| 38 |
f = ocl.Fiber( f1, f2) |
| 39 |
bpc_x.appendFiber(f) |
| 40 |
for x in xvals: |
| 41 |
f1 = ocl.Point(x,-15.5,zh) # start point of fiber |
| 42 |
f2 = ocl.Point(x,15.5,zh) # end point of fiber |
| 43 |
f = ocl.Fiber( f1, f2) |
| 44 |
bpc_y.appendFiber(f) |
| 45 |
|
| 46 |
# run |
| 47 |
bpc_x.run() |
| 48 |
bpc_y.run() |
| 49 |
xfibers = bpc_x.getFibers() |
| 50 |
yfibers = bpc_y.getFibers() |
| 51 |
fibers = xfibers+yfibers |
| 52 |
print(" got ",len(xfibers)," xfibers") |
| 53 |
print(" got ",len(yfibers)," yfibers") |
| 54 |
fibercount = len(xfibers) + len(yfibers) |
| 55 |
print("rendering fibers and CL-points.") |
| 56 |
w = ocl.Weave() |
| 57 |
print("push fibers to Weave...",) |
| 58 |
for f in fibers: |
| 59 |
w.addFiber(f) |
| 60 |
print("done.") |
| 61 |
print("Weave build()...",) |
| 62 |
mem1 = procmemory.memory() |
| 63 |
if weave2_flag==1: |
| 64 |
w.build2() |
| 65 |
else: |
| 66 |
w.build() |
| 67 |
mem2 = procmemory.memory() |
| 68 |
#print "after ", float(mem2)/float(1024*1024), " MB" |
| 69 |
megabytes = float(mem2-mem1)/float(1024*1024) |
| 70 |
megabytes2 = float(mem2)/float(1024*1024) |
| 71 |
verts = w.numVertices() |
| 72 |
print(" before: ", float(mem1)/float(1024*1024)) |
| 73 |
print(" after: ", float(mem2)/float(1024*1024)) |
| 74 |
print(" build() memory: ",megabytes," MB") |
| 75 |
print("done") |
| 76 |
print("face_traverse...") |
| 77 |
w.face_traverse() |
| 78 |
print("done.") |
| 79 |
w_clpts = w.getCLVertices() |
| 80 |
w_ipts = w.getINTVertices() |
| 81 |
w_edges = w.getEdges() |
| 82 |
w_loop = w.getLoops() |
| 83 |
|
| 84 |
|
| 85 |
print(" got: ", len(w_edges), " edges") |
| 86 |
print(" got: ", len(w_loop), " loops") |
| 87 |
out=[] |
| 88 |
out.append(fibercount) |
| 89 |
out.append(verts) |
| 90 |
return out |
| 91 |
|
| 92 |
if __name__ == "__main__": |
| 93 |
writer = csv.writer( open('weave2ram_6.csv','wb'), delimiter=',') |
| 94 |
|
| 95 |
#Nmax=400 |
| 96 |
Nmaxlist = [100,200,400,800, 1600, 3200] |
| 97 |
|
| 98 |
for Nmax in Nmaxlist: |
| 99 |
mb = getWeaveRAM(Nmax,0) |
| 100 |
mb2 = getWeaveRAM(Nmax,1) |
| 101 |
#print mb2 |
| 102 |
print(mb[0], " :=> ", mb[1], " MB") |
| 103 |
writer.writerow(mb+mb2) |
| 104 |
gc.collect() |
| 105 |
|
| 106 |
raw_input("Press Enter to terminate") |