def main(param_a, param_b, param_c, param_d, param_e, cageOrig, cageNew): loadCSV = True field2 = np.zeros((N, N, Nz)).astype(np.uint8) field3 = np.zeros((N, N, Nz)).astype(np.uint8) Ires = 0 pp = 110 I = Image.new("L", (N, Nz * N), 0.0) I3 = Image.new("L", (N - 2 * pp, (N - 2 * pp) * (Nz)), 0.0) t2 = t1 = t3 = 0 p = int(N / 4) eps = 10.0 * np.nextafter(0, 1) nSize = len(cageOrig) k = float(10.0) cageNew = np.array(map(lambda i: np.array(i), cageNew)) if not os.path.isdir("warp2"): os.mkdir("warp2") if not os.path.isdir("warp2/baked"): os.mkdir("warp2/baked") if not os.path.isdir("warp2/warped"): os.mkdir("warp2/warped") print "Proving..." t = time.clock() field = proving.proving(param_a, param_b, param_c, param_d, param_e, N, Nz) print "Proving Time: ", time.clock() - t if loadCSV: arr = readCSV("exps/baking.csv") else: arr = calc() gx, gy = np.gradient(arr) print "Proving..." t = time.clock() field2 = cbaking.cbaking(field, N, k, gx, gy, Nz) print "Baking Time: ", time.clock() - t print "Warping..." a = np.array(cageOrig).astype(np.int32) cageOrig_buf = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=a) a = np.array(cageNew).astype(np.int32) cageNew_buf = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=a) s = np.zeros((nSize, 2)).astype(np.float32) s_buf = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=a) p = 0 xn = np.zeros(((N - 2 * p) * (N - 2 * p))).astype(np.int32) d2 = np.zeros((nSize)).astype(np.float32) d = np.zeros((nSize)).astype(np.float32) dest_xn_buf = cl.Buffer(ctx, mf.WRITE_ONLY, xn.nbytes) t = time.clock() prg.main( queue, (N - 2 * p, N - 2 * p), None, cageOrig_buf, cageNew_buf, dest_xn_buf, np.int32(nSize), np.float32(eps), np.int32(p), np.int32(N), ) cl.enqueue_read_buffer(queue, dest_xn_buf, xn).wait() field3 = cmvc3.cmvc(field2, N, xn, Nz, p) print "Warping time: ", time.clock() - t print "Saving Image..." Ires = 0 for w in range(Nz): II = Image.frombuffer( "L", (N - 2 * pp, N - 2 * pp), np.array(field3[pp : N - pp, pp : N - pp, w]).astype(np.uint8), "raw", "L", 0, 1, ) II.save("warp2/warped/warpedslice" + str(w) + ".png") I3.paste(II, (0, (N - 2 * pp) * w)) I3.save("warp2/warped.png") print "Image warp2/warped.png saved" return Ires, pp, k
def pipeline(param_a,param_b,param_c,param_d,param_e): loadCSV = False createFolders() # BEGIN # MIXING + PROVING + KNEADING + 2ND PROVING # SIMULATED: BUBBLING + INTERSECTION + DEFORM ############################## print "Bubbling..." t = time.clock() # field #(Nx,Ny,Nz) # density #(Nx,Ny,Nz) field,density = proving.proving(param_a,param_b,param_c,param_d,param_e,N,Nz) #import poisson3D #field = poisson3D.main() print "Bubbling Time: ", time.clock()-t # INTERSECTION # input geometry print "Loading..." t = time.clock() # geom #(256,256,256) geom = np.array(load_obj('otherbread.binvox')).astype(np.uint8) print "Loading Time: ", time.clock()-t print "Intersecting..." t = time.clock() # field #(Nx,Ny,Nz) # dfield #(256,256,256) # geom #(Nx,Ny,Nz) # crust #(256,256,256) field,dfield,geom,crust,density = cloadobj.intersect(field, geom,density,N,Nz) print "Intersect Time: ", time.clock()-t saveField(2*orientate(density.astype(np.uint8),N,Nz),"density","density.png") # END # MIXING + PROVING + KNEADING + 2ND PROVING ############################## # 3D BAKING WITH CRUST FORMATION print "Baking..." t = time.clock() # baking effect parameter k = 5.0 #saveField(fieldf,"accumulated","bread.png") if(accumulatedBaking): bake = True if(bake): temperatures = bk.getTemperaturesArray(20) t2 = time.clock() # deform bubbles with temperature print "cbake.." saveField(255*orientate(field,N,Nz),"accumulated/pre","bread.png") print "Max, min: ", np.max(density), np.min(density) # bakedField #(Nx,Ny,Nz) # geomD #(Nx,Ny,Nz) bakedField,geomD,dfieldDeformed = cbake.bake(255*field,dfield,255*geom,density,temperatures,N,Nz,k) field = orientate(bakedField,N,Nz) saveField(field,"postbaking","postbaking.png") #exit() print "Crumb..." crumbD = np.array(dfieldDeformed>thresh).astype(np.uint8) print "New Crust..." crust = geomD/255-crumbD crust = ndimage.filters.gaussian_filter(255*(orientate(resize(crust,N,Nz),N,Nz)),1) saveField(crust,"accumulated","crust.png") # geomD #(Nx,Ny,Nz) print "New geomD..." geomD = orientate(resize(geomD,N,Nz),N,Nz) saveField(geomD,"accumulated","postbakingGeom.png") print "Specific field..." field = np.array(1.0*field*((cloadobj.orientatef(cloadobj.resizef(dfieldDeformed,N,Nz),N,Nz) > thresh/8.0))).astype(np.uint8) else: field = cloadobj.orientate(255*field,N,Nz) #saveField(field,"accumulated","finalbread.png") print "Baking time: ", time.clock()-t # loadtexOcclusion print "Computing ambient Occlusion..." arr=cprint.cprint2(0,Nz,N,field,15) saveField(arr,"accumulated","aocclusion.png") print "Resizing crust and Exporting Field to OGRE: warpedC.field " printFile(crust ,"Ogre/output/media/fields/warpedC.field") print "Exporting Field to OGRE: warpedO.field " printFile(arr,'Ogre/output/media/fields/warpedO.field') print "Exporting Field to OGRE: warped.field " printFile(field,'Ogre/output/media/fields/warped.field') else: temperatures = bk.getTemperatures() sphere = struct(20) for w in xrange(1,180): t2 = time.clock() diff = temperatures[w]-temperatures[w-1] # deform bubbles with temperature # geom = scipy.ndimage.binary_closing(fieldf,structure=sphere).astype(np.uint8) fieldf = cbake.bake(fieldf,geom,diff,N,Nz,k) print w, "Time: ", time.clock()-t2 saveField(fieldf,"warp2","warped.png") print "Baking Time: ", time.clock()-t