def testShutdownOrder(self): self.compileMandel() handle = fract4dc.pf_load(Test.pf_name) pfunc = fract4dc.pf_create(handle) pfunc2 = fract4dc.pf_create(handle) handle = None pfunc = None pfunc2 = None
def makeWorkerAndFunc(self, image, cmap): siteobj = FractalSite() site = fract4dc.site_create(siteobj) file = self.compileColorDiagonal() handle = fract4dc.pf_load(file) pfunc = fract4dc.pf_create(handle) fract4dc.pf_init(pfunc, pos_params, self.color_diagonal_params) fw = fract4dc.fw_create(1, pfunc, cmap, image, site) ff = fract4dc.ff_create( [0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 2, 100, 0, 1, pfunc, cmap, 0, 1, 0, image, site, fw, False, 1.0E-9) return (fw, ff, site, handle, pfunc)
def testBasic(self): self.compileMandel() handle = fract4dc.pf_load(Test.pf_name) pfunc = fract4dc.pf_create(handle) fract4dc.pf_init(pfunc, pos_params, [self.gradient, 4.0, 0.5]) # a point which doesn't bail out result = fract4dc.pf_calc(pfunc, [0.15, 0.0, 0.0, 0.0], 100, 0, 0, 0) self.assertEqual(result, (100, 32, 0.0, 0)) # one which does result = fract4dc.pf_calc(pfunc, [1.0, 1.0, 0.0, 0.0], 100, 0, 0, 0) self.assertEqual(result, (1, 0, 0.0, 0)) # one which is already out result = fract4dc.pf_calc(pfunc, [17.5, 14.0, 0.0, 0.0], 100, 0, 0, 0) self.assertEqual(result, (0, 0, 0.0, 0)) # without optional args result = fract4dc.pf_calc(pfunc, [17.5, 14.0, 0.0, 0.0], 100) self.assertEqual(result, (0, 0, 0.0, 0)) pfunc = None handle = None
def testBasic(self): self.compileMandel() handle = fract4dc.pf_load(Test.pf_name) pfunc = fract4dc.pf_create(handle) fract4dc.pf_init(pfunc,pos_params, [self.gradient, 4.0, 0.5]) # a point which doesn't bail out result = fract4dc.pf_calc(pfunc,[0.15, 0.0, 0.0, 0.0],100,0,0,0) self.assertEqual(result,(100, 32, 0.0,0)) # one which does result = fract4dc.pf_calc(pfunc,[1.0, 1.0, 0.0, 0.0],100,0,0,0) self.assertEqual(result,(1,0, 0.0,0)) # one which is already out result = fract4dc.pf_calc(pfunc,[17.5, 14.0, 0.0, 0.0],100,0,0,0) self.assertEqual(result,(0, 0, 0.0,0)) # without optional args result = fract4dc.pf_calc(pfunc,[17.5, 14.0, 0.0, 0.0],100) self.assertEqual(result,(0, 0, 0.0,0)) pfunc = None handle = None
def drawTwice(self, is_dirty, xsize): ysize = int(xsize * 3.0 / 4.0) im = image.T(xsize, ysize) siteobj = FractalSite() site = fract4dc.site_create(siteobj) file = self.compileColorMandel() handle = fract4dc.pf_load(file) pfunc = fract4dc.pf_create(handle) fract4dc.pf_init(pfunc, pos_params, self.color_mandel_params) cmap = fract4dc.cmap_create( [(1.0, 255, 255, 255, 255)]) fract4dc.calc( params=[0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], antialias=0, maxiter=100, yflip=0, nthreads=1, pfo=pfunc, cmap=cmap, auto_deepen=0, periodicity=1, render_type=0, image=im._img, site=site, dirty=is_dirty) # print "1st pass %s" % is_dirty #fract4dc.image_save(image, "/tmp/pass1%d.tga" % is_dirty) # self.print_fates(image,xsize,ysize) cmap = fract4dc.cmap_create( [(1.0, 76, 49, 189, 255)]) fract4dc.calc( params=[0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], antialias=0, maxiter=100, yflip=0, nthreads=1, pfo=pfunc, cmap=cmap, auto_deepen=0, periodicity=1, render_type=0, image=im._img, site=site, dirty=is_dirty) # print "2nd pass %s" % is_dirty # self.print_fates(image,xsize,ysize) im.save(os.path.join(Test.tmpdir.name, "pass2%d.tga" % is_dirty)) return [] # fract4dc.image_buffer(image)
def drawTwice(self,is_dirty,xsize): ysize = int(xsize * 3.0/4.0) im = image.T(xsize,ysize) siteobj = FractalSite() site = fract4dc.site_create(siteobj) file = self.compileColorMandel() handle = fract4dc.pf_load(file) pfunc = fract4dc.pf_create(handle) fract4dc.pf_init(pfunc,pos_params,self.color_mandel_params) cmap = fract4dc.cmap_create( [(1.0, 255, 255, 255, 255)]) fract4dc.calc( params=[0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], antialias=0, maxiter=100, yflip=0, nthreads=1, pfo=pfunc, cmap=cmap, auto_deepen=0, periodicity=1, render_type=0, image=im._img, site=site, dirty=is_dirty) #print "1st pass %s" % is_dirty #fract4dc.image_save(image, "/tmp/pass1%d.tga" % is_dirty) #self.print_fates(image,xsize,ysize) cmap = fract4dc.cmap_create( [(1.0, 76, 49, 189, 255)]) fract4dc.calc( params=[0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], antialias=0, maxiter=100, yflip=0, nthreads=1, pfo=pfunc, cmap=cmap, auto_deepen=0, periodicity=1, render_type=0, image=im._img, site=site, dirty=is_dirty) #print "2nd pass %s" % is_dirty #self.print_fates(image,xsize,ysize) im.save(os.path.join(Test.tmpdir.name, "pass2%d.tga" % is_dirty)) return [] # fract4dc.image_buffer(image)
def makeWorkerAndFunc(self, image, cmap): siteobj = FractalSite() site = fract4dc.site_create(siteobj) file = self.compileColorDiagonal() handle = fract4dc.pf_load(file) pfunc = fract4dc.pf_create(handle) fract4dc.pf_init(pfunc,pos_params, self.color_diagonal_params) fw = fract4dc.fw_create(1,pfunc,cmap,image,site) ff = fract4dc.ff_create( [0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 2, 100, 0, 1, pfunc, cmap, 0, 1, 0, image, site, fw, False, 1.0E-9) return (fw,ff,site,handle,pfunc)
def testBadCalc(self): self.compileMandel() handle = fract4dc.pf_load(Test.pf_name) pfunc = fract4dc.pf_create(handle) fract4dc.pf_init(pfunc, pos_params, []) self.assertRaises(ValueError,fract4dc.pf_calc,0,[1.0,2.0,3.0,4.0],100) self.assertRaises(TypeError,fract4dc.pf_calc,pfunc,[1.0,2.0,3.0],100) pfunc = None
def testCalc(self): xsize = 64 ysize = int(xsize * 3.0 / 4.0) im = image.T(xsize, ysize) siteobj = FractalSite() site = fract4dc.site_create(siteobj) file = self.compileColorMandel() handle = fract4dc.pf_load(file) pfunc = fract4dc.pf_create(handle) fract4dc.pf_init(pfunc, pos_params, self.color_mandel_params) cmap = fract4dc.cmap_create([(0.0, 0, 0, 0, 255), (1 / 256.0, 255, 255, 255, 255), (1.0, 255, 255, 255, 255)]) fract4dc.calc( params=[0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], antialias=0, maxiter=100, yflip=0, nthreads=1, pfo=pfunc, cmap=cmap, auto_deepen=0, periodicity=1, render_type=0, image=im._img, site=site) self.assertEqual(siteobj.progress_list[-1], 0.0) self.assertEqual(siteobj.progress_list[-2], 1.0) self.assertTrue(siteobj.image_list[-1] == (0, 0, xsize, ysize)) self.assertTrue(siteobj.status_list[0] == 1 and siteobj.status_list[-1] == 0) test2_tga = os.path.join(Test.tmpdir.name, "test2.tga") self.assertTrue(not os.path.exists(test2_tga)) im.save(test2_tga) self.assertTrue(os.path.exists(test2_tga)) # fate of all non-aa pixels should be known, aa-pixels unknown fate_buf = im.fate_buffer() i = 0 for byte in fate_buf: d = im.get_color_index( (i % (im.FATE_SIZE * xsize)) // im.FATE_SIZE, i // (im.FATE_SIZE * xsize), i % im.FATE_SIZE) if i % 4 == 0: # no-aa self.assertNotEqual(byte, 255, "pixel %d is %d" % (i, byte)) self.assertNotEqual("%g" % d, "inf") else: self.assertEqual(byte, 255) i += 1 self.assertPixelCount(xsize, ysize, siteobj)
def disabled_testGetDefaults(self): self.compileMandel() handle = fract4dc.pf_load(Test.pf_name) pfunc = fract4dc.pf_create(handle) ret = fract4dc.pf_defaults( pfunc,0.001,pos_params, [self.gradient, 0.0, 0.0]) self.assertTrue(isinstance(ret, list)) self.assertEqual(3,len(ret)) self.assertEqual([None,4.0,1.0],ret)
def disabled_testGetDefaults(self): self.compileMandel() handle = fract4dc.pf_load(Test.pf_name) pfunc = fract4dc.pf_create(handle) ret = fract4dc.pf_defaults( pfunc, 0.001, pos_params, [self.gradient, 0.0, 0.0]) self.assertTrue(isinstance(ret, list)) self.assertEqual(3, len(ret)) self.assertEqual([None, 4.0, 1.0], ret)
def testBadInit(self): self.compileMandel() handle = fract4dc.pf_load(Test.pf_name) pfunc = fract4dc.pf_create(handle) self.assertRaises(TypeError,fract4dc.pf_init,pfunc,pos_params,72) self.assertRaises(ValueError,fract4dc.pf_init,7,pos_params, [0.4]) self.assertRaises(ValueError,fract4dc.pf_init,pfunc,pos_params,[0.0]*201) self.assertRaises(ValueError,fract4dc.pf_init,pfunc,"fish",72) self.assertRaises(ValueError,fract4dc.pf_init,pfunc,[0.0]*12,72) pfunc = None handle = None
def testMiniTextRender(self): self.compileMandel() handle = fract4dc.pf_load(Test.pf_name) pfunc = fract4dc.pf_create(handle) fract4dc.pf_init(pfunc,pos_params,[0,4.0]) image = [] for y in range(-20,20): line = [] for x in range(-20,20): (iter,fate,dist,solid) = fract4dc.pf_calc(pfunc,[x/10.0,y/10.0,0,0],100) if(fate == 32): line.append("#") else: line.append(" ") image.append("".join(line)) printable_image = "\n".join(image) self.assertEqual(printable_image[0], " ", printable_image) self.assertEqual(printable_image[20*41+20],"#", printable_image) # in the middle
def testAACalc(self): xsize = 64 ysize = int(xsize * 3.0 / 4.0) im = image.T(xsize, ysize) siteobj = FractalSite() site = fract4dc.site_create(siteobj) file = self.compileColorMandel() handle = fract4dc.pf_load(file) pfunc = fract4dc.pf_create(handle) fract4dc.pf_init(pfunc, pos_params, self.color_mandel_params) cmap = fract4dc.cmap_create( [(0.0, 0, 0, 0, 255), (1 / 256.0, 255, 255, 255, 255), (1.0, 255, 255, 255, 255)]) fract4dc.calc( params=[0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], antialias=1, maxiter=100, yflip=0, nthreads=1, pfo=pfunc, cmap=cmap, auto_deepen=0, periodicity=1, render_type=0, image=im._img, site=site) # fate of all pixels should be known fate_buf = im.fate_buffer() i = 0 for byte in fate_buf: d = im.get_color_index( (i % (im.FATE_SIZE * xsize)) // im.FATE_SIZE, i // (im.FATE_SIZE * xsize), i % im.FATE_SIZE) self.assertNotEqual("%g" % d, "inf", "index %d is %g" % (i, d)) self.assertNotEqual(byte, 255, "pixel %d is %d" % (i, byte)) i += 1
def testAACalc(self): xsize = 64 ysize = int(xsize * 3.0/4.0) im = image.T(xsize,ysize) siteobj = FractalSite() site = fract4dc.site_create(siteobj) file = self.compileColorMandel() handle = fract4dc.pf_load(file) pfunc = fract4dc.pf_create(handle) fract4dc.pf_init(pfunc,pos_params,self.color_mandel_params) cmap = fract4dc.cmap_create( [(0.0,0,0,0,255), (1/256.0,255,255,255,255), (1.0, 255, 255, 255, 255)]) fract4dc.calc( params=[0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], antialias=1, maxiter=100, yflip=0, nthreads=1, pfo=pfunc, cmap=cmap, auto_deepen=0, periodicity=1, render_type=0, image=im._img, site=site) # fate of all pixels should be known fate_buf = im.fate_buffer() i = 0 for byte in fate_buf: d = im.get_color_index( (i % (im.FATE_SIZE * xsize)) // im.FATE_SIZE, i // (im.FATE_SIZE * xsize), i % im.FATE_SIZE) self.assertNotEqual("%g" % d,"inf", "index %d is %g" % (i,d)) self.assertNotEqual(byte, 255, "pixel %d is %d" % (i, byte)) i+= 1
def setUp(self): self.f = fractal.T(Test.g_comp) self.f.render_type = 2 self.f.set_formula("test.frm", "test_hypersphere") self.f.compile() handle = fract4dc.pf_load(self.f.outputfile) self.pfunc = fract4dc.pf_create(handle) self.cmap = fract4dc.cmap_create_gradient(self.f.get_gradient().segments) (r,g,b,a) = self.f.solids[0] fract4dc.cmap_set_solid(self.cmap,0,r,g,b,a) (r,g,b,a) = self.f.solids[1] fract4dc.cmap_set_solid(self.cmap,1,r,g,b,a) initparams = self.f.all_params() fract4dc.pf_init(self.pfunc,self.f.params,initparams) self.im = image.T(40,30) siteobj = FractalSite() self.fw = fract4dc.fw_create( 1,self.pfunc,self.cmap,self.im._img,self.f.site) self.ff = fract4dc.ff_create( [0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 2, 100, 0, 1, self.pfunc, self.cmap, 0, 1, 2, # 3D self.im._img, self.f.site, self.fw, False, 1.0E-9)
def setUp(self): self.f = fractal.T(Test.g_comp) self.f.render_type = 2 self.f.set_formula("test.frm", "test_hypersphere") self.f.compile() handle = fract4dc.pf_load(self.f.outputfile) self.pfunc = fract4dc.pf_create(handle) self.cmap = fract4dc.cmap_create_gradient( self.f.get_gradient().segments) (r, g, b, a) = self.f.solids[0] fract4dc.cmap_set_solid(self.cmap, 0, r, g, b, a) (r, g, b, a) = self.f.solids[1] fract4dc.cmap_set_solid(self.cmap, 1, r, g, b, a) initparams = self.f.all_params() fract4dc.pf_init(self.pfunc, self.f.params, initparams) self.im = image.T(40, 30) siteobj = FractalSite() self.fw = fract4dc.fw_create(1, self.pfunc, self.cmap, self.im._img, self.f.site) self.ff = fract4dc.ff_create( [0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 2, 100, 0, 1, self.pfunc, self.cmap, 0, 1, 2, # 3D self.im._img, self.f.site, self.fw, False, 1.0E-9)
def testIntInit(self): self.compileMandel() handle = fract4dc.pf_load(Test.pf_name) pfunc = fract4dc.pf_create(handle) fract4dc.pf_init(pfunc, pos_params, [1,2,3,4])
def testFDSite(self): xsize = 64 ysize = int(xsize * 3.0 / 4.0) im = image.T(xsize, ysize) (rfd, wfd) = os.pipe() site = fract4dc.fdsite_create(wfd) file = self.compileColorMandel() for x in range(2): handle = fract4dc.pf_load(file) pfunc = fract4dc.pf_create(handle) fract4dc.pf_init(pfunc, pos_params, self.color_mandel_params) cmap = fract4dc.cmap_create([(0.0, 0, 0, 0, 255), (1 / 256.0, 255, 255, 255, 255), (1.0, 255, 255, 255, 255)]) fract4dc.calc( params=[0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], antialias=0, maxiter=100, yflip=0, nthreads=1, pfo=pfunc, cmap=cmap, auto_deepen=0, periodicity=1, render_type=0, image=im._img, site=site, asynchronous=True) nrecved = 0 while True: if nrecved == x: # print "hit message count" fract4dc.interrupt(site) nb = 2 * 4 bytes = os.read(rfd, nb) if len(bytes) < nb: self.fail("bad message with length %s, value %s" % (len(bytes), bytes)) break (t, size) = struct.unpack("2i", bytes) # print "read %d, len %d" % (t,size) # read the rest of the message bytes = os.read(rfd, size) if len(bytes) < size: self.fail("bad message") break msg = messages.parse(t, bytes) # print "msg: %s" % msg.show() if msg.name == "Status" and msg.status == 0: # done # print "done" break nrecved += 1
def testIntInit(self): self.compileMandel() handle = fract4dc.pf_load(Test.pf_name) pfunc = fract4dc.pf_create(handle) fract4dc.pf_init(pfunc, pos_params, [1, 2, 3, 4])
def testVectors(self): siteobj = FractalSite() site = fract4dc.site_create(siteobj) file = self.compileColorDiagonal() handle = fract4dc.pf_load(file) pfunc = fract4dc.pf_create(handle) fract4dc.pf_init(pfunc,pos_params,self.color_diagonal_params) (w,h,tw,th) = (40,20,40,20) im = image.T(w,h) cmap = fract4dc.cmap_create([(1.0, 255, 255, 255, 255)]) fw = fract4dc.fw_create(1,pfunc,cmap,im._img,site) ff = fract4dc.ff_create( [0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 2, 100, 0, 1, pfunc, cmap, 0, 1, 0, im._img, site, fw, False, 1.0E-9) # check dx, dy and topleft dx = fract4dc.ff_get_vector(ff, fract4dc.DELTA_X) self.assertNearlyEqual(dx, [4.0/tw,0.0,0.0,0.0]) dy = fract4dc.ff_get_vector(ff, fract4dc.DELTA_Y); self.assertNearlyEqual(dy, [0.0,-2.0/th,0.0,0.0]) topleft = fract4dc.ff_get_vector(ff, fract4dc.TOPLEFT); self.assertNearlyEqual(topleft, [-2.0 + 4.0/(tw*2),1.0 - 2.0/(th*2),0.0,0.0]) # check they are updated if image is bigger (w,h,tw,th) = (40,20,400,200) im = image.T(w,h,tw,th) fw = fract4dc.fw_create(1,pfunc,cmap,im._img,site) ff = fract4dc.ff_create( [0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 2, 100, 0, 1, pfunc, cmap, 0, 1, 0, im._img, site, fw, False, 1.0E-9) # check dx, dy and topleft dx = fract4dc.ff_get_vector(ff, fract4dc.DELTA_X) self.assertNearlyEqual(dx, [4.0/tw,0.0,0.0,0.0]) dy = fract4dc.ff_get_vector(ff, fract4dc.DELTA_Y); self.assertNearlyEqual(dy, [0.0,-2.0/th,0.0,0.0]) topleft = fract4dc.ff_get_vector(ff, fract4dc.TOPLEFT); self.assertNearlyEqual(topleft, [-2.0 + 4.0/(tw*2),1.0 - 2.0/(th*2),0.0,0.0]) offx = 40 offy = 10 im.set_offset(offx, offy) fw = fract4dc.fw_create(1,pfunc,cmap,im._img,site) ff = fract4dc.ff_create( [0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 2, 100, 0, 1, pfunc, cmap, 0, 1, 0, im._img, site, fw, False, 1.0E-9) # check dx, dy and topleft dx = fract4dc.ff_get_vector(ff, fract4dc.DELTA_X) self.assertNearlyEqual(dx, [4.0/tw,0.0,0.0,0.0]) dy = fract4dc.ff_get_vector(ff, fract4dc.DELTA_Y); self.assertNearlyEqual(dy, [0.0,-2.0/th,0.0,0.0]) topleft = fract4dc.ff_get_vector(ff, fract4dc.TOPLEFT); self.assertNearlyEqual(topleft, [ -2.0 + dx[0] * (offx + 0.5), 1.0 + dy[1] * (offy + 0.5), 0.0,0.0])
def testCalc(self): xsize = 64 ysize = int(xsize * 3.0/4.0) im = image.T(xsize,ysize) siteobj = FractalSite() site = fract4dc.site_create(siteobj) file = self.compileColorMandel() handle = fract4dc.pf_load(file) pfunc = fract4dc.pf_create(handle) fract4dc.pf_init(pfunc,pos_params,self.color_mandel_params) cmap = fract4dc.cmap_create( [(0.0,0,0,0,255), (1/256.0,255,255,255,255), (1.0, 255, 255, 255, 255)]) fract4dc.calc( params=[0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], antialias=0, maxiter=100, yflip=0, nthreads=1, pfo=pfunc, cmap=cmap, auto_deepen=0, periodicity=1, render_type=0, image=im._img, site=site) self.assertEqual(siteobj.progress_list[-1], 0.0) self.assertEqual(siteobj.progress_list[-2], 1.0) self.assertTrue(siteobj.image_list[-1]==(0,0,xsize,ysize)) self.assertTrue(siteobj.status_list[0]== 1 and \ siteobj.status_list[-1]== 0) test2_tga = os.path.join(Test.tmpdir.name, "test2.tga") self.assertTrue(not os.path.exists(test2_tga)) im.save(test2_tga) self.assertTrue(os.path.exists(test2_tga)) # fate of all non-aa pixels should be known, aa-pixels unknown fate_buf = im.fate_buffer() i = 0 for byte in fate_buf: d = im.get_color_index( (i % (im.FATE_SIZE * xsize)) // im.FATE_SIZE, i // (im.FATE_SIZE * xsize), i % im.FATE_SIZE) if i % 4 == 0: # no-aa self.assertNotEqual(byte, 255, "pixel %d is %d" % (i,byte)) self.assertNotEqual("%g" % d,"inf") else: self.assertEqual(byte, 255) i+= 1 self.assertPixelCount(xsize,ysize,siteobj)
def testFDSite(self): xsize = 64 ysize = int(xsize * 3.0 / 4.0) im = image.T(xsize, ysize) (rfd, wfd) = os.pipe() site = fract4dc.fdsite_create(wfd) file = self.compileColorMandel() handle = fract4dc.pf_load(file) pfunc = fract4dc.pf_create(handle) for x in range(2): fract4dc.pf_init(pfunc, pos_params, self.color_mandel_params) cmap = fract4dc.cmap_create( [(0.0, 0, 0, 0, 255), (1 / 256.0, 255, 255, 255, 255), (1.0, 255, 255, 255, 255)]) fract4dc.calc( params=[0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], antialias=0, maxiter=100, yflip=0, nthreads=1, pfo=pfunc, cmap=cmap, auto_deepen=0, periodicity=1, render_type=0, image=im._img, site=site, asynchronous=True) while True: # read message type and size # we use a buffer here like in gtkfractal.py "onData" nb = 2 * 4 bytes = b"" while True: # wait up to 1 sec until we can read, otherwise we assume the counterpart is gone (an error ocurred on the C++ layer) r, w, e = select.select([rfd], [], [], 1) if rfd in r: temp = os.read(rfd, nb - len(bytes)) else: self.fail("no one on the other side") bytes = bytes + temp if (len(bytes) == nb): break elif temp == '': self.fail( "bad message with length %s, value %s" % (len(bytes), bytes)) (t, size) = struct.unpack("2i", bytes) # read the actual message bytes = os.read(rfd, size) if len(bytes) < size: self.fail("bad message") break msg = messages.parse(t, bytes) # if the fractal is done if msg.name == "Status" and msg.status == 0: # fract4dc.interrupt(site) break
def testFDSite(self): xsize = 64 ysize = int(xsize * 3.0/4.0) im = image.T(xsize,ysize) (rfd,wfd) = os.pipe() site = fract4dc.fdsite_create(wfd) file = self.compileColorMandel() for x in range(2): handle = fract4dc.pf_load(file) pfunc = fract4dc.pf_create(handle) fract4dc.pf_init(pfunc,pos_params,self.color_mandel_params) cmap = fract4dc.cmap_create( [(0.0,0,0,0,255), (1/256.0,255,255,255,255), (1.0, 255, 255, 255, 255)]) fract4dc.calc( params=[0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], antialias=0, maxiter=100, yflip=0, nthreads=1, pfo=pfunc, cmap=cmap, auto_deepen=0, periodicity=1, render_type=0, image=im._img, site=site, asynchronous=True) nrecved = 0 while True: if nrecved == x: #print "hit message count" fract4dc.interrupt(site) nb = 2*4 bytes = os.read(rfd,nb) if len(bytes) < nb: self.fail("bad message with length %s, value %s" % (len(bytes), bytes)) break (t,size) = struct.unpack("2i",bytes) #print "read %d, len %d" % (t,size) # read the rest of the message bytes = os.read(rfd,size) if len(bytes) < size: self.fail("bad message") break msg = messages.parse(t, bytes) #print "msg: %s" % msg.show() if msg.name == "Status" and msg.status == 0: #done #print "done" break nrecved += 1
def testVectors(self): siteobj = FractalSite() site = fract4dc.site_create(siteobj) file = self.compileColorDiagonal() handle = fract4dc.pf_load(file) pfunc = fract4dc.pf_create(handle) fract4dc.pf_init(pfunc, pos_params, self.color_diagonal_params) (w, h, tw, th) = (40, 20, 40, 20) im = image.T(w, h) cmap = fract4dc.cmap_create([(1.0, 255, 255, 255, 255)]) fw = fract4dc.fw_create(1, pfunc, cmap, im._img, site) ff = fract4dc.ff_create( [0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 2, 100, 0, 1, pfunc, cmap, 0, 1, 0, im._img, site, fw, False, 1.0E-9) # check dx, dy and topleft dx = fract4dc.ff_get_vector(ff, fract4dc.DELTA_X) self.assertNearlyEqual(dx, [4.0 / tw, 0.0, 0.0, 0.0]) dy = fract4dc.ff_get_vector(ff, fract4dc.DELTA_Y) self.assertNearlyEqual(dy, [0.0, -2.0 / th, 0.0, 0.0]) topleft = fract4dc.ff_get_vector(ff, fract4dc.TOPLEFT) self.assertNearlyEqual( topleft, [-2.0 + 4.0 / (tw * 2), 1.0 - 2.0 / (th * 2), 0.0, 0.0]) # check they are updated if image is bigger (w, h, tw, th) = (40, 20, 400, 200) im = image.T(w, h, tw, th) fw = fract4dc.fw_create(1, pfunc, cmap, im._img, site) ff = fract4dc.ff_create( [0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 2, 100, 0, 1, pfunc, cmap, 0, 1, 0, im._img, site, fw, False, 1.0E-9) # check dx, dy and topleft dx = fract4dc.ff_get_vector(ff, fract4dc.DELTA_X) self.assertNearlyEqual(dx, [4.0 / tw, 0.0, 0.0, 0.0]) dy = fract4dc.ff_get_vector(ff, fract4dc.DELTA_Y) self.assertNearlyEqual(dy, [0.0, -2.0 / th, 0.0, 0.0]) topleft = fract4dc.ff_get_vector(ff, fract4dc.TOPLEFT) self.assertNearlyEqual( topleft, [-2.0 + 4.0 / (tw * 2), 1.0 - 2.0 / (th * 2), 0.0, 0.0]) offx = 40 offy = 10 im.set_offset(offx, offy) fw = fract4dc.fw_create(1, pfunc, cmap, im._img, site) ff = fract4dc.ff_create( [0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 2, 100, 0, 1, pfunc, cmap, 0, 1, 0, im._img, site, fw, False, 1.0E-9) # check dx, dy and topleft dx = fract4dc.ff_get_vector(ff, fract4dc.DELTA_X) self.assertNearlyEqual(dx, [4.0 / tw, 0.0, 0.0, 0.0]) dy = fract4dc.ff_get_vector(ff, fract4dc.DELTA_Y) self.assertNearlyEqual(dy, [0.0, -2.0 / th, 0.0, 0.0]) topleft = fract4dc.ff_get_vector(ff, fract4dc.TOPLEFT) self.assertNearlyEqual(topleft, [ -2.0 + dx[0] * (offx + 0.5), 1.0 + dy[1] * (offy + 0.5), 0.0, 0.0])