def split(self,sv,nvloop,svloop = None,**kws): '''add two child loops of sv''' print('former sv method... NEEDS CODE FROM DILAP.TOPOLOGY.PARTITIONGRAPH') print('par.loop becomes ebdxy of par.loop and nv.loop') nsvs = [] nv1holes,nv2holes = sv.holes[:],[] if svloop is None: svloop = sv.loop[:] if pym.binbxy(nvloop,svloop): nv1holes.append(nvloop) nsvs.append(dtp.topography.avert( self,sv,loop = svloop,holes = nv1holes)) elif pym.binbxy(svloop,nvloop): nv2holes.append(svloop) nsvs.append(dtp.topography.avert( self,sv,loop = svloop,holes = nv1holes)) elif pym.bintbxy(nvloop,svloop,ie = False): svloop = pym.ebdxy(svloop,nvloop) if len(svloop) > 1: for svl in svloop[:-1]: nsvs.append(dtp.topography.avert( self,sv,loop = svl,holes = nv1holes)) svloop = svloop[-1] nsvs.append(dtp.topography.avert( self,sv,loop = svloop,holes = nv1holes)) nv = dtp.topography.avert(self,sv,loop = nvloop,holes = nv2holes) for k in kws: for nsv in nsvs: nsv.__setattr__(k,sv.__getattribute__(k)) nv.__setattr__(k,kws[k]) self.plot() plt.show() return nsvs,nv
def ajagged(b,epsilon): j = random.randint(0,len(b)-1) l = b[j-1].d(b[j]) t = random.uniform(0,2.0*numpy.pi) n = random.randint(3,8) stamp = b[j-1].mid(b[j]).pring(l/2.0,n) q = quat(1,0,0,0).av(t,vec3(0,0,1)) q.rotps(stamp) if pym.bintbxy(b,stamp,col = False,ie = False): nbs = pym.ebdxy(b,stamp,epsilon) nbas = [pym.bareaxy(nb) for nb in nbs] nb = nbs[nbas.index(max(nbas))] nb = pym.aggregate(nb,1) if pym.bvalidxy(nb) > 0:b = nb bval = pym.bvalidxy(b) if bval == -1:b.reverse() if not pym.bvalidxy(b) > 0: ax = dtl.plot_axes_xy(700) ax = dtl.plot_polygon_xy(b,ax,lw = 4,col = 'b') ax = dtl.plot_points_xy(b,ax,number = True) ax = dtl.plot_polygon_xy(stamp,ax,lw = 2,col = 'r') plt.show() #pdb.set_trace() raise ValueError return b
def chunk(b,epsilon,lscl = 1.0,j1 = None,j2 = None,edge = False): if j1 is None:j1 = random.randint(0,len(b)-1) if j2 is None:j2 = j1-1 l = b[j1].d(b[j2])*lscl t = random.uniform(0,2.0*numpy.pi) n = random.randint(3,8) if edge: stamp = b[j1].mid(b[j2]).pring(l/2.0,n) else: stamp = vec3( random.randint(int(l/4),int(l)), random.randint(int(l/4),int(l)), 0).com(b).pring(l/2.0,n) q = quat(1,0,0,0).av(t,vec3(0,0,1)) q.rotps(stamp) if pym.binbxy(stamp,b): return stamp elif pym.bintbxy(b,stamp,col = False,ie = False): nbs = pym.ebixy(b,stamp,epsilon) nbas = [pym.bareaxy(nb) for nb in nbs] nb = nbs[nbas.index(max(nbas))] nb = pym.aggregate(nb,1) if pym.bvalidxy(nb) > 0: return nb else: ax = dtl.plot_axes_xy(200) ax = dtl.plot_polygon_xy(b,ax,col = 'r',lw = 2) ax = dtl.plot_polygon_xy(stamp,ax,col = 'b',lw = 2) plt.show() raise ValueError
def ajagged(b, epsilon): j = random.randint(0, len(b) - 1) l = b[j - 1].d(b[j]) t = random.uniform(0, 2.0 * numpy.pi) n = random.randint(3, 8) stamp = b[j - 1].mid(b[j]).pring(l / 2.0, n) q = quat(1, 0, 0, 0).av(t, vec3(0, 0, 1)) q.rotps(stamp) if pym.bintbxy(b, stamp, col=False, ie=False): nbs = pym.ebdxy(b, stamp, epsilon) nbas = [pym.bareaxy(nb) for nb in nbs] nb = nbs[nbas.index(max(nbas))] nb = pym.aggregate(nb, 1) if pym.bvalidxy(nb) > 0: b = nb bval = pym.bvalidxy(b) if bval == -1: b.reverse() if not pym.bvalidxy(b) > 0: ax = dtl.plot_axes_xy(700) ax = dtl.plot_polygon_xy(b, ax, lw=4, col='b') ax = dtl.plot_points_xy(b, ax, number=True) ax = dtl.plot_polygon_xy(stamp, ax, lw=2, col='r') plt.show() #pdb.set_trace() raise ValueError return b
def chunk(b, epsilon, lscl=1.0, j1=None, j2=None, edge=False): if j1 is None: j1 = random.randint(0, len(b) - 1) if j2 is None: j2 = j1 - 1 l = b[j1].d(b[j2]) * lscl t = random.uniform(0, 2.0 * numpy.pi) n = random.randint(3, 8) if edge: stamp = b[j1].mid(b[j2]).pring(l / 2.0, n) else: stamp = vec3(random.randint(int(l / 4), int(l)), random.randint(int(l / 4), int(l)), 0).com(b).pring(l / 2.0, n) q = quat(1, 0, 0, 0).av(t, vec3(0, 0, 1)) q.rotps(stamp) if pym.binbxy(stamp, b): return stamp elif pym.bintbxy(b, stamp, col=False, ie=False): nbs = pym.ebixy(b, stamp, epsilon) nbas = [pym.bareaxy(nb) for nb in nbs] nb = nbs[nbas.index(max(nbas))] nb = pym.aggregate(nb, 1) if pym.bvalidxy(nb) > 0: return nb else: ax = dtl.plot_axes_xy(200) ax = dtl.plot_polygon_xy(b, ax, col='r', lw=2) ax = dtl.plot_polygon_xy(stamp, ax, col='b', lw=2) plt.show() raise ValueError
def splotch(vb, easement=10): # WIP vbes = [(vb[0][x - 1], vb[0][x]) for x in range(len(vb[0]))] vbels = [vb[0][x - 1].d(vb[0][x]) for x in range(len(vb[0]))] vbe_primary = vbels.index(max(vbels)) vbe_primary_tn = vb[0][vbe_primary - 1].tov(vb[0][vbe_primary]).nrm() bq = quat(0, 0, 0, 1).uu(vec3(1, 0, 0), vbe_primary_tn) if not bq: bq = quat(1, 0, 0, 0) vbcon = pym.aggregate(pym.contract(vb[0], easement), 5) vbxpj = vbe_primary_tn.prjps(vb[0]) vbypj = vbe_primary_tn.cp().zrot(gtl.PI2).prjps(vb[0]) vbxl, vbyl = vbxpj[1] - vbxpj[0], vbypj[1] - vbypj[0] dx, dy = 20, 20 xn, yn = int(1.5 * vbxl / dx), int(1.5 * vbyl / dy) print('xn,yn', xn, yn) o = vec3(0, 0, 0).com(vbcon) vgrid = [ o.cp().xtrn(dx * (x - (xn / 2.0))).ytrn(dy * (y - (yn / 2.0))) for x in range(xn) for y in range(yn) ] #vgrid = [p for p in vgrid if abs(p.x-10) > 10] boxes = [ p.cp().trn(o.flp()).rot(bq).trn(o.flp()).sq(dx, dy) for p in vgrid ] for b in boxes: bcom = vec3(0, 0, 0).com(b).flp() bcom.trnos(b) bq.rotps(b) bcom.flp().trnos(b) boxes = [b for b in boxes if pym.binbxy(b, vbcon)] for ib in vb[1]: boxes = [ b for b in boxes if not pym.bintbxy(b, ib) and not b[0].inbxy(ib) and not ib[0].inbxy(b[0]) ] blgfps = pym.ebuxy_special(boxes, 5, 4) ps = [vec3(0, 0, 0).com(blgfp) for blgfp in blgfps] qs = [bq.cp() for blgfp in blgfps] ss = [vec3(1, 1, 1) for blgfp in blgfps] for p, q, s, blgfp in zip(ps, qs, ss, blgfps): p.cpxy().flp().trnos(blgfp) q.cpf().rotps(blgfp) return zip(ps, qs, ss, blgfps)
def correct_loops(v,l): lswollen = [p.cp().ztrn(v.loop[0].z-p.z) for p in l] #lswollen = pym.contract(lswollen,abs(l[0].z-v.loop[0].z)/mingrad) #ax = dtl.plot_axes(300) #ax = dtl.plot_polygon(lswollen,ax,lw = 3,col = 'b') #ax = dtl.plot_polygon(v.loop,ax,lw = 3,col = 'r') #plt.show() newloops = pym.ebdxy(v.loop,lswollen) v.loop = newloops[0] if len(newloops) > 1: for nl in newloops[1:]: nv = self.avert(self.above(v),loop = nl) for ch in self.below(v): if pym.bintbxy(lswollen,ch.loop): correct_loops(ch,lswollen)
def splotch(vb,easement = 10): # WIP vbes = [(vb[0][x-1],vb[0][x]) for x in range(len(vb[0]))] vbels = [vb[0][x-1].d(vb[0][x]) for x in range(len(vb[0]))] vbe_primary = vbels.index(max(vbels)) vbe_primary_tn = vb[0][vbe_primary-1].tov(vb[0][vbe_primary]).nrm() bq = quat(0,0,0,1).uu(vec3(1,0,0),vbe_primary_tn) if not bq:bq = quat(1,0,0,0) vbcon = pym.aggregate(pym.contract(vb[0],easement),5) vbxpj = vbe_primary_tn.prjps(vb[0]) vbypj = vbe_primary_tn.cp().zrot(gtl.PI2).prjps(vb[0]) vbxl,vbyl = vbxpj[1]-vbxpj[0],vbypj[1]-vbypj[0] dx,dy = 20,20 xn,yn = int(1.5*vbxl/dx),int(1.5*vbyl/dy) print('xn,yn',xn,yn) o = vec3(0,0,0).com(vbcon) vgrid = [o.cp().xtrn(dx*(x-(xn/2.0))).ytrn(dy*(y-(yn/2.0))) for x in range(xn) for y in range(yn)] #vgrid = [p for p in vgrid if abs(p.x-10) > 10] boxes = [p.cp().trn(o.flp()).rot(bq).trn(o.flp()).sq(dx,dy) for p in vgrid] for b in boxes: bcom = vec3(0,0,0).com(b).flp() bcom.trnos(b) bq.rotps(b) bcom.flp().trnos(b) boxes = [b for b in boxes if pym.binbxy(b,vbcon)] for ib in vb[1]: boxes = [b for b in boxes if not pym.bintbxy(b,ib) and not b[0].inbxy(ib) and not ib[0].inbxy(b[0])] blgfps = pym.ebuxy_special(boxes,5,4) ps = [vec3(0,0,0).com(blgfp) for blgfp in blgfps] qs = [bq.cp() for blgfp in blgfps] ss = [vec3(1,1,1) for blgfp in blgfps] for p,q,s,blgfp in zip(ps,qs,ss,blgfps): p.cpxy().flp().trnos(blgfp) q.cpf().rotps(blgfp) return zip(ps,qs,ss,blgfps)
def locloop(self,l,override = 0,mingrad = 1.0): # modify the loop of v (and its children) to respect new loop l def correct_loops(v,l): lswollen = [p.cp().ztrn(v.loop[0].z-p.z) for p in l] #lswollen = pym.contract(lswollen,abs(l[0].z-v.loop[0].z)/mingrad) #ax = dtl.plot_axes(300) #ax = dtl.plot_polygon(lswollen,ax,lw = 3,col = 'b') #ax = dtl.plot_polygon(v.loop,ax,lw = 3,col = 'r') #plt.show() newloops = pym.ebdxy(v.loop,lswollen) v.loop = newloops[0] if len(newloops) > 1: for nl in newloops[1:]: nv = self.avert(self.above(v),loop = nl) for ch in self.below(v): if pym.bintbxy(lswollen,ch.loop): correct_loops(ch,lswollen) lst = None unfn = [self.root] while unfn: v = unfn.pop(0) if pym.binbxy(l,v.loop): chs = self.below(v) unfn.extend(chs) lst = v,chs elif pym.bintbxy(l,v.loop): # modify the existing loop to accomodate the new loop if override == 1: correct_loops(v,l) chs = self.below(v) unfn.extend(chs) lst = self.above(v),chs # modify the new loop to accomodate the existing loop elif override == 2: raise NotImplemented return v,[] # modify neither loop (likely causes poor results) else:return v,[] if lst is None:lst = self.root,[] return lst
def split(self, sv, nvloop, svloop=None, **kws): '''add two child loops of sv''' print( 'former sv method... NEEDS CODE FROM DILAP.TOPOLOGY.PARTITIONGRAPH' ) print('par.loop becomes ebdxy of par.loop and nv.loop') nsvs = [] nv1holes, nv2holes = sv.holes[:], [] if svloop is None: svloop = sv.loop[:] if pym.binbxy(nvloop, svloop): nv1holes.append(nvloop) nsvs.append( dtp.topography.avert(self, sv, loop=svloop, holes=nv1holes)) elif pym.binbxy(svloop, nvloop): nv2holes.append(svloop) nsvs.append( dtp.topography.avert(self, sv, loop=svloop, holes=nv1holes)) elif pym.bintbxy(nvloop, svloop, ie=False): svloop = pym.ebdxy(svloop, nvloop) if len(svloop) > 1: for svl in svloop[:-1]: nsvs.append( dtp.topography.avert(self, sv, loop=svl, holes=nv1holes)) svloop = svloop[-1] nsvs.append( dtp.topography.avert(self, sv, loop=svloop, holes=nv1holes)) nv = dtp.topography.avert(self, sv, loop=nvloop, holes=nv2holes) for k in kws: for nsv in nsvs: nsv.__setattr__(k, sv.__getattribute__(k)) nv.__setattr__(k, kws[k]) self.plot() plt.show() return nsvs, nv
def atest_bintbxy(self): def pl(b1,b2): ax = dtl.plot_axes_xy(10) ax = dtl.plot_polygon_xy(b1,ax,lw = 2.0,col = 'g') ax = dtl.plot_polygon_xy(b2,ax,lw = 2.0,col = 'b') plt.show() b1 = vec3(0,0,0).pring(8,8) b2 = vec3(4,0,0).pring(4,8) self.assertTrue(pym.bintbxy(b1,b2)) #pl(b1,b2) self.assertFalse(pym.bintbxy(b1,b2,col = False)) b1 = vec3(0,0,0).pring(8,8) b2 = vec3(1,0,0).pring(4,8) self.assertFalse(pym.bintbxy(b1,b2)) self.assertFalse(pym.bintbxy(b1,b2,ie = False)) #pl(b1,b2) b1 = vec3(0,0,0).pring(8,8) b2 = vec3(5,0,0).pring(4,8) self.assertTrue(pym.bintbxy(b1,b2)) self.assertTrue(pym.bintbxy(b1,b2,ie = False)) #pl(b1,b2) b1 = vec3(-4,0,0).pring(2,8) b2 = vec3(4,0,0).pring(4,8) self.assertFalse(pym.bintbxy(b1,b2)) self.assertFalse(pym.bintbxy(b1,b2,ie = False)) #pl(b1,b2) b1 = vec3(-4,0,0).pring(4,8) b2 = vec3(4,0,0).pring(4,8) self.assertTrue(pym.bintbxy(b1,b2)) self.assertFalse(pym.bintbxy(b1,b2,col = False)) #pl(b1,b2) b1 = vec3(-4,0,0).pring(4,8) b2 = vec3(4,2,0).pring(4,8) self.assertTrue(pym.bintbxy(b1,b2)) self.assertFalse(pym.bintbxy(b1,b2,col = False)) #pl(b1,b2) b1 = vec3(-4,0,0).pring(4,8) b2 = vec3(4,4,0).pring(4,8) self.assertFalse(pym.bintbxy(b1,b2)) self.assertFalse(pym.bintbxy(b1,b2,ie = False)) #pl(b1,b2) b1 = vec3(-4,0,0).pring(4,8) b2 = vec3(4,2.0*4.0*numpy.tan(numpy.pi/8.0),0).pring(4,8) self.assertTrue(pym.bintbxy(b1,b2)) self.assertFalse(pym.bintbxy(b1,b2,ie = False))
def atest_bintbxy(self): def pl(b1, b2): ax = dtl.plot_axes_xy(10) ax = dtl.plot_polygon_xy(b1, ax, lw=2.0, col='g') ax = dtl.plot_polygon_xy(b2, ax, lw=2.0, col='b') plt.show() b1 = vec3(0, 0, 0).pring(8, 8) b2 = vec3(4, 0, 0).pring(4, 8) self.assertTrue(pym.bintbxy(b1, b2)) #pl(b1,b2) self.assertFalse(pym.bintbxy(b1, b2, col=False)) b1 = vec3(0, 0, 0).pring(8, 8) b2 = vec3(1, 0, 0).pring(4, 8) self.assertFalse(pym.bintbxy(b1, b2)) self.assertFalse(pym.bintbxy(b1, b2, ie=False)) #pl(b1,b2) b1 = vec3(0, 0, 0).pring(8, 8) b2 = vec3(5, 0, 0).pring(4, 8) self.assertTrue(pym.bintbxy(b1, b2)) self.assertTrue(pym.bintbxy(b1, b2, ie=False)) #pl(b1,b2) b1 = vec3(-4, 0, 0).pring(2, 8) b2 = vec3(4, 0, 0).pring(4, 8) self.assertFalse(pym.bintbxy(b1, b2)) self.assertFalse(pym.bintbxy(b1, b2, ie=False)) #pl(b1,b2) b1 = vec3(-4, 0, 0).pring(4, 8) b2 = vec3(4, 0, 0).pring(4, 8) self.assertTrue(pym.bintbxy(b1, b2)) self.assertFalse(pym.bintbxy(b1, b2, col=False)) #pl(b1,b2) b1 = vec3(-4, 0, 0).pring(4, 8) b2 = vec3(4, 2, 0).pring(4, 8) self.assertTrue(pym.bintbxy(b1, b2)) self.assertFalse(pym.bintbxy(b1, b2, col=False)) #pl(b1,b2) b1 = vec3(-4, 0, 0).pring(4, 8) b2 = vec3(4, 4, 0).pring(4, 8) self.assertFalse(pym.bintbxy(b1, b2)) self.assertFalse(pym.bintbxy(b1, b2, ie=False)) #pl(b1,b2) b1 = vec3(-4, 0, 0).pring(4, 8) b2 = vec3(4, 2.0 * 4.0 * numpy.tan(numpy.pi / 8.0), 0).pring(4, 8) self.assertTrue(pym.bintbxy(b1, b2)) self.assertFalse(pym.bintbxy(b1, b2, ie=False))
def vblgsplotch(self, v, pg, easement=10): vb = v[1]['b'] vbes = [(vb[0][x - 1], vb[0][x]) for x in range(len(vb[0]))] vbels = [vb[0][x - 1].d(vb[0][x]) for x in range(len(vb[0]))] vbe_primary = vbels.index(max(vbels)) vbe_primary_tn = vb[0][vbe_primary - 1].tov(vb[0][vbe_primary]).nrm() bq = quat(0, 0, 0, 1).uu(vec3(1, 0, 0), vbe_primary_tn) if not bq: bq = quat(1, 0, 0, 0) #bq = quat(1,0,0,0) vbcon = pym.aggregate(pym.contract(vb[0], easement), 5) #vbcon = pym.aggregate(pym.contract(vb[0],0),5) #ax = dtl.plot_axes_xy(120) #ax = dtl.plot_polygon_xy(vbcon,ax,lw = 3,col = 'g') #plt.show() #if len(fbnd) > 3:fbnd = pinchb(fbnd,epsilon) vbxpj = vbe_primary_tn.prjps(vb[0]) vbypj = vbe_primary_tn.cp().zrot(gtl.PI2).prjps(vb[0]) vbxl, vbyl = vbxpj[1] - vbxpj[0], vbypj[1] - vbypj[0] dx, dy = 20, 20 xn, yn = int(1.5 * vbxl / dx), int(1.5 * vbyl / dy) print('xn,yn', xn, yn) #do = vec3(-dx*xn/2.0,-dy*yn/2.0,0) o = vec3(0, 0, 0).com(vbcon) vgrid = [ o.cp().xtrn(dx * (x - (xn / 2.0))).ytrn(dy * (y - (yn / 2.0))) for x in range(xn) for y in range(yn) ] boxes = [ p.cp().trn(o.flp()).rot(bq).trn(o.flp()).sq(dx, dy) for p in vgrid ] #boxes = [p.cp().trn(o.flp()).rot(bq).trn(o.flp()).sq(dx,dy) # for p in vgrid if abs(p.x - o.x) > dx] for b in boxes: bcom = vec3(0, 0, 0).com(b).flp() bcom.trnos(b) bq.rotps(b) bcom.flp().trnos(b) boxes = [b for b in boxes if pym.binbxy(b, vbcon)] for ib in vb[1]: boxes = [ b for b in boxes if not pym.bintbxy(b, ib) and not b[0].inbxy(ib) and not ib[0].inbxy(b[0]) ] '''# ax = dtl.plot_axes_xy(400) ax = dtl.plot_point_xy(o,ax) ax = dtl.plot_polygon_xy(vb[0],ax,lw = 2,col = 'b') ax = dtl.plot_polygon_xy(vbcon,ax,ls = '--',lw = 2,col = 'r') #ax = dtl.plot_polygon_xy(box,ax,lw = 2,col = 'r') for b in boxes:ax = dtl.plot_polygon_xy(b,ax,lw = 2,col = 'g') plt.show() '''# #blgfps = pym.bsuxy(boxes) blgfps = pym.ebuxy_special(boxes, 5, 4) ps = [vec3(0, 0, 0).com(blgfp) for blgfp in blgfps] qs = [bq.cp() for blgfp in blgfps] ss = [vec3(1, 1, 1) for blgfp in blgfps] for p, q, s, blgfp in zip(ps, qs, ss, blgfps): p.cpxy().flp().trnos(blgfp) q.cpf().rotps(blgfp) '''# ax = dtl.plot_axes_xy(700) ax = dtl.plot_point_xy(o,ax) ax = dtl.plot_polygon_xy(vb[0],ax,lw = 2,col = 'b') #ax = dtl.plot_polygon_xy(box,ax,lw = 2,col = 'r') for b in boxes:ax = dtl.plot_polygon_xy(b,ax,lw = 2,col = 'g') for b in blgfps:ax = dtl.plot_polygon_xy(b,ax,lw = 2,col = 'r') plt.show() '''# '''# bx,by,sx,sy = -30,30,30,30 r = abs(random.random())*20 bz = v[1]['tmesh'](bx,by)+r blgfps.append(vec3(bx,by,bz).sq(sx,sy)) bx,by,sx,sy = 30,30,50,30 r = abs(random.random())*20 bz = v[1]['tmesh'](bx,by)+r blgfps.append(vec3(bx,by,bz).sq(sx,sy)) bx,by,sx,sy = 30,-30,40,60 r = abs(random.random())*20 bz = v[1]['tmesh'](bx,by)+r blgfps.append(vec3(bx,by,bz).sq(sx,sy)) '''# #blgfps.append(vec3(bx,by,v[1]['tmesh'](bx,by)).sq(sx,sy)) #bx,by,sx,sy = 30,30,50,30 #blgfps.append(vec3(bx,by,v[1]['tmesh'](bx,by)).sq(sx,sy)) #bx,by,sx,sy = 30,-30,40,60 #blgfps.append(vec3(bx,by,v[1]['tmesh'](bx,by)).sq(sx,sy)) #for blgfp in blgfps: # r = v[1]['b'][0][0].z+abs(random.random())*20 # for p in blgfp: # p.ztrn(r) return zip(ps, qs, ss, blgfps)