Exemple #1
0
 def plot(self, ax=None):
     scale = vec3(1, 0, 0).prjps(self.footprint)
     scale = scale[1] - scale[0]
     if ax is None: ax = dtl.plot_axes(scale)
     for vx in range(self.vcnt):
         v = self.vs[vx]
         if v is None: continue
         vb = v[1]['fp']
         vrtls = '--' if 'natural' in v[1]['type'] else '-'
         ax = dtl.plot_polygon(pym.contract(vb, 0.01 * scale),
                               ax,
                               lw=2,
                               ls=vrtls,
                               col=None)
         vbc = vec3(0, 0, 0).com(vb)
         for ve in v[1]['edges']:
             if self.vs[ve] is None: continue
             ovbc = vec3(0, 0, 0).com(self.vs[ve][1]['fp'])
             ax = dtl.plot_edges((vbc, ovbc), ax, lw=3, col='c')
         for ep in v[1]['exits']:
             ax = dtl.plot_point(ep, ax, mk='s', col='r')
     top = [p.cp().ztrn(self.height) for p in self.footprint]
     ax = dtl.plot_polygon(self.footprint, ax, lw=1, col='g')
     ax = dtl.plot_polygon(top, ax, lw=1, col='b')
     return ax
Exemple #2
0
 def pv(v,ax):
     dtl.plot_polygon(v.loop,ax,lw = 2)
     vp = v.loop[0]
     for c in self.below(v):
         cp = c.loop[0]
         dtl.plot_points((vp,cp),ax)
         dtl.plot_edges((vp,cp),ax,lw = 3,col = 'b')
         pv(c,ax)
Exemple #3
0
 def pl():
     ax = rg.plot()
     for lp in loops:
         lpps = [rg.vs[j][1]['p'] for j in lp]
         lpps = pym.contract(lpps,2)
         ax = dtl.plot_polygon(lpps,ax,lw = 3,col = 'b')
     plt.show()
Exemple #4
0
 def plotmesh(self):
     mesh = self.mesh
     ax = dtl.plot_axes()
     for f in mesh.faces:
         pxs = (mesh.verts[vx][0] for vx in f)
         ps = self.pset.gps(pxs)
         ax = dtl.plot_polygon(ps, ax)
     plt.show()
Exemple #5
0
 def plotmesh(self):
     mesh = self.mesh
     ax = dtl.plot_axes()
     for f in mesh.faces:
         pxs = (mesh.verts[vx][0] for vx in f)
         ps = self.pset.gps(pxs)
         ax = dtl.plot_polygon(ps,ax)
     plt.show()
Exemple #6
0
 def plot(self,ax = None):
     if ax is None:ax = dtl.plot_axes(300)
     for v,depth in self.enum(False):
         if self.below(v):col = 'g'
         else:col = 'b'
         vloop = [p.ztrn(depth*10) for p in pym.contract(v.loop,2)]
         #vloop = [p.cp().ztrn(depth*10) for p in v.loop]
         vanchor = vloop[0]
         if depth > 0:
             panchor = self.above(v).loop[0].cp().ztrn((depth-1)*10)
         else:panchor = vec3(0,0,0)
         ax = dtl.plot_polygon(vloop,ax,lw = 3,col = col)
         ax = dtl.plot_edges((vanchor,panchor),ax,col = col,lw = 5)
         for hole in v.holes:
             hole = [p.ztrn(depth*10) for p in pym.contract(hole,-2)]
             #hole = [p.cp().ztrn(depth*10) for p in hole]
             ax = dtl.plot_polygon(hole,ax,lw = 2,col = 'r')
     return ax
Exemple #7
0
def pepper(t, tip, e=2):
    print('pepper')

    c = vec3(0, 0, 0).com(tip.loop)
    d = vec3(1, 0, 0).uscl(1000)
    s1, s2 = c.cp().trn(d.flp()), c.cp().trn(d.flp())
    ch = lambda b: pyg.chunk(
        b, e, random.random() + 0.2, edge=random.randint(0, 1))
    bs = [ch(tip.loop) for x in range(10)]
    bs = pym.bsuxy(bs, e)

    #ax = dtl.plot_axes_xy(200)
    #for b in bs:
    #    dtl.plot_polygon_xy(b,ax,lw = 2)
    #plt.show()

    newtips = []
    for sb in bs:
        if not pym.bccw(sb): sb.reverse()

        sb = pyg.ajagged(sb, 2)
        sb = pyg.ajagged(sb, 2)
        sb = pyg.ajagged(sb, 2)
        #sb = pyg.ajagged(sb,2)

        #for x in range(3):b = pyg.ajagged(b,e)
        sb = pym.bisectb(sb)
        #sb = pym.smoothxy(sb,0.5,e)
        sb = pym.smoothxy(sb, 0.5, e)
        sb = pym.aggregate(sb, 4)
        #sb = pym.blimithmin(sb,2,50)

        for p in sb:
            p.ztrn(2)
        newtips.append(t.al(sb, tip))

    ax = dtl.plot_axes(200)
    ax = dtl.plot_polygon(t.root.loop, ax, ls='--', lw=2, col='k')
    ax = dtl.plot_polygon(tip.loop, ax, lw=3, col='r')
    for b in bs:
        ax = dtl.plot_polygon(b, ax, lw=3, col='g')
    plt.show()

    return newtips
Exemple #8
0
 def plot(self, ax=None):
     if ax is None: ax = dtl.plot_axes(300)
     for v, depth in self.enum(False):
         if self.below(v): col = 'g'
         else: col = 'b'
         vloop = [p.ztrn(depth * 10) for p in pym.contract(v.loop, 2)]
         #vloop = [p.cp().ztrn(depth*10) for p in v.loop]
         vanchor = vloop[0]
         if depth > 0:
             panchor = self.above(v).loop[0].cp().ztrn((depth - 1) * 10)
         else:
             panchor = vec3(0, 0, 0)
         ax = dtl.plot_polygon(vloop, ax, lw=3, col=col)
         ax = dtl.plot_edges((vanchor, panchor), ax, col=col, lw=5)
         for hole in v.holes:
             hole = [p.ztrn(depth * 10) for p in pym.contract(hole, -2)]
             #hole = [p.cp().ztrn(depth*10) for p in hole]
             ax = dtl.plot_polygon(hole, ax, lw=2, col='r')
     return ax
Exemple #9
0
def pepper(t,tip,e = 2):
    print('pepper')

    c = vec3(0,0,0).com(tip.loop)
    d = vec3(1,0,0).uscl(1000)
    s1,s2 = c.cp().trn(d.flp()),c.cp().trn(d.flp())
    ch = lambda b : pyg.chunk(b,e,random.random()+0.2,edge = random.randint(0,1))
    bs = [ch(tip.loop) for x in range(10)]
    bs = pym.bsuxy(bs,e)

    #ax = dtl.plot_axes_xy(200)
    #for b in bs:
    #    dtl.plot_polygon_xy(b,ax,lw = 2)
    #plt.show()

    newtips = []
    for sb in bs:
        if not pym.bccw(sb):sb.reverse()

        sb = pyg.ajagged(sb,2)
        sb = pyg.ajagged(sb,2)
        sb = pyg.ajagged(sb,2)
        #sb = pyg.ajagged(sb,2)

        #for x in range(3):b = pyg.ajagged(b,e)
        sb = pym.bisectb(sb)
        #sb = pym.smoothxy(sb,0.5,e)
        sb = pym.smoothxy(sb,0.5,e)
        sb = pym.aggregate(sb,4)
        #sb = pym.blimithmin(sb,2,50)

        for p in sb:p.ztrn(2)
        newtips.append(t.al(sb,tip))

    ax = dtl.plot_axes(200)
    ax = dtl.plot_polygon(t.root.loop,ax,ls = '--',lw = 2,col = 'k')
    ax = dtl.plot_polygon(tip.loop,ax,lw = 3,col = 'r')
    for b in bs:
        ax = dtl.plot_polygon(b,ax,lw = 3,col = 'g')
    plt.show()

    return newtips
Exemple #10
0
 def plot(self,ax = None):
     scale = vec3(1,0,0).prjps(self.footprint)
     scale = scale[1]-scale[0]
     if ax is None:ax = dtl.plot_axes(scale)
     for vx in range(self.vcnt):
         v = self.vs[vx]
         if v is None:continue
         vb = v[1]['fp']
         vrtls = '--' if 'natural' in v[1]['type'] else '-'
         ax = dtl.plot_polygon(
             pym.contract(vb,0.01*scale),ax,lw = 2,ls = vrtls,col = None)
         vbc = vec3(0,0,0).com(vb)
         for ve in v[1]['edges']:
             if self.vs[ve] is None:continue
             ovbc = vec3(0,0,0).com(self.vs[ve][1]['fp'])
             ax = dtl.plot_edges((vbc,ovbc),ax,lw = 3,col = 'c')
         for ep in v[1]['exits']:
             ax = dtl.plot_point(ep,ax,mk = 's',col = 'r')
     top = [p.cp().ztrn(self.height) for p in self.footprint]
     ax = dtl.plot_polygon(self.footprint,ax,lw = 1,col = 'g')
     ax = dtl.plot_polygon(top,ax,lw = 1,col = 'b')
     return ax
Exemple #11
0
    def partition(self, terr, roads, e):
        '''partition the space spanned by a topography
         - the boundary to the first set of topo loops is the ocean
         - the first set of topo loops are the landmasses
         - partition each landmass based upon infrastructure bounds
        '''
        blgfps = roads.footprints
        rpy = pym.pgtopy(roads.roads, 5)

        ax = dtl.plot_axes(200)
        ax = dtl.plot_polygon(rpy[0], ax, lw=3, col='b')
        ax = dtl.plot_points(rpy[0], ax)
        plt.show()

        rpy = None
        for lmtv in terr.natural.below(terr.natural.root):
            rootpvs, lmpv = self.split(self.root,
                                       lmtv.loop,
                                       None,
                                       style='land')
            if not rpy is None:
                lmpvs, rdpv = self.split(lmpv, rpy[0], style='infrastructure')
                for fp in blgfps[0]:
                    fnd = False
                    for lmpv in lmpvs:
                        if pym.binbxy(fp[0], lmpv.loop):
                            #blgpvs,blgpv = self.split(lmpv,fp[0],style = 'structure')
                            #found = True
                            #break
                            pass
                    if fnd: break
                if len(rpy[1]) > 0:
                    irdpvs, irdpv = self.split(rdpv,
                                               rpy[1][0],
                                               style='bounded')
                if len(rpy[1]) > 1:
                    for irpy in rpy[1][1:]:
                        irdpvs, irdpv = self.split(irdpvs[0],
                                                   irpy,
                                                   style='bounded')
                rtv = terr.natural.avert(terr.natural.locloop(rpy[0], 1)[0],
                                         loop=rpy[0])
                for dpy in rpy[1]:
                    rtv = terr.natural.avert(terr.natural.locloop(dpy, 1)[0],
                                             loop=dpy)

        print('... the continent ...')
        self.plot()
        plt.show()
Exemple #12
0
 def plot(self,fp = None,ax = None):
     if ax is None:ax = dtl.plot_axes(50)
     for rmv in self.vs:
         if rmv is None:continue
         ax = dtl.plot_polygon(rmv[2]['bound'],ax,lw = 4)
         rc = vec3(0,0,0).com(rmv[2]['bound'])
         rs = str(rmv[0])+','+str(rmv[1])
         ax = dtl.plot_point(rc,dtl.plot_point_xy_annotate(rc,ax,rs))
         if rmv[1]:
             for re in rmv[1]:
                 if self.vs[re] is None:continue
                 rt = (rc,vec3(0,0,0).com(self.vs[re][2]['bound']))
                 ax = dtl.plot_edges(rt,ax,col = 'g')
         for exit in rmv[2]['exits']:
             if exit is True:
                 exitp = rc
                 ax = dtl.plot_point(exitp,
                     dtl.plot_point_xy_annotate(exitp,ax,'exit'))
             else:
                 ax = dtl.plot_point(exit,
                     dtl.plot_point_xy_annotate(exit,ax,'exit'))
     if not fp is None:
         ax = dtl.plot_polygon(fp,ax,lw = 2,col = 'r')
     return ax
Exemple #13
0
 def plot(self, fp=None, ax=None):
     if ax is None: ax = dtl.plot_axes(50)
     for rmv in self.vs:
         if rmv is None: continue
         ax = dtl.plot_polygon(rmv[2]['bound'], ax, lw=4)
         rc = vec3(0, 0, 0).com(rmv[2]['bound'])
         rs = str(rmv[0]) + ',' + str(rmv[1])
         ax = dtl.plot_point(rc, dtl.plot_point_xy_annotate(rc, ax, rs))
         if rmv[1]:
             for re in rmv[1]:
                 if self.vs[re] is None: continue
                 rt = (rc, vec3(0, 0, 0).com(self.vs[re][2]['bound']))
                 ax = dtl.plot_edges(rt, ax, col='g')
         for exit in rmv[2]['exits']:
             if exit is True:
                 exitp = rc
                 ax = dtl.plot_point(
                     exitp, dtl.plot_point_xy_annotate(exitp, ax, 'exit'))
             else:
                 ax = dtl.plot_point(
                     exit, dtl.plot_point_xy_annotate(exit, ax, 'exit'))
     if not fp is None:
         ax = dtl.plot_polygon(fp, ax, lw=2, col='r')
     return ax
Exemple #14
0
    def split(self,v,s,z,rad,epsilon):
        sp = vec3(0,0,0).com(v.loop)
        sd = vec3(0,1,0) if random.random() > 0.5 else vec3(1,0,0)
        s1 = sp.cp().trn(sd.cp().uscl( 10000))
        s2 = sp.cp().trn(sd.cp().uscl(-10000))
        loops = pym.bsegsxy(v.loop,s1,s2,0.1)

        lvs = []
        for el in loops:
            if not pym.bccw(el):el.reverse()
            el = pym.blimithmin(el,2,50)
            el = pym.aggregate(el,2)
            #el = pym.smoothxy(el,0.5,epsilon)
            nv = self.grow(v,z,rad,epsilon,el)
            lvs.append(nv)

        ax = self.plot()
        for el in loops:
            ax = dtl.plot_polygon(el,ax,lw = 2,col = 'r')
        plt.show()

        return lvs
Exemple #15
0
 def pl(il):
     ilp = [rg.vs[j][1]['p'] for j in il]
     ilp = pym.contract(ilp,2.0)
     ax = rg.plot()
     ax = dtl.plot_polygon(ilp,ax,col = 'b',lw = 4)
     plt.show()
Exemple #16
0
 def plot(self, mesh):
     ax = dtl.plot_axes()
     for f in mesh.faces:
         ps = self.mod.gvps(mesh, f)
         ax = dtl.plot_polygon(ps, ax)
     plt.show()
Exemple #17
0
 def plot(self,mesh):
     ax = dtl.plot_axes()
     for f in mesh.faces:
         ps = self.mod.gvps(mesh,f)
         ax = dtl.plot_polygon(ps,ax)
     plt.show()
 def show(self,tris,bnds):
     ax = dtl.plot_axes()
     for t in tris:dtl.plot_polygon(t,ax,True,lw = 2,col = 'g')
     for b in bnds:dtl.plot_edges(b,ax,True,lw = 5,col = 'b')
     if self.doshow:plt.show()
Exemple #19
0
def checkseq(pg, fp, seq, show=False):
    print('check-pseq:', seq)
    easement = 2

    def trimtofp(p1, p2, r=5):
        ips = pym.sintbxyp(p1, p2, fp)
        if len(ips) > 0:
            for ip in ips:
                if ip.isnear(p1): continue
                p2 = p1.lerp(ip, 1 - r / p1.d(ip))
        return p2

    # place a pair of vertices on the edge of the footprint
    # pointing inward, constituting an exit from the region
    def seed(rg, ss):
        print('SEED', ss)
        exp = fp[-1].lerp(fp[0], 0.5)
        exn = vec3(0, 0, 1).crs(fp[-1].tov(fp[0])).nrm()
        ex1 = exp.cp()
        ex2 = ex1.cp().trn(exn.cp().uscl(easement))
        i1 = rg.av(p=ex1, l=0)
        i2, r1 = rg.mev(i1, {'p': ex2, 'l': 0}, {})
        return [i2]

    # make an edge and a vertex attached to an existing vertex
    def grow(rg, ss):
        print('GROW', ss)
        tip = nvs[-1]
        tv = rg.vs[tip]
        avs = [rg.vs[k] for k in rg.orings[tip]]
        if len(avs) == 1:
            op = tv[1]['p']
            nptn = avs[0][1]['p'].tov(op).nrm().uscl(100)
            np = op.cp().trn(nptn)
            np = trimtofp(op, np, easement + 10)
            nv, nr = rg.mev(tip, {'p': np, 'l': 0}, {})
        return [nv]

    def loop(rg, ss):
        print('LOOP', ss)

    grammer = {
        'S': seed,
        'G': grow,
        'L': loop,
    }

    scnt = len(seq)
    sx = 0
    while sx < scnt:
        c = seq[sx]
        if c in grammer:
            ex = db.seqread(seq, sx)
            nvs = grammer[c](pg, seq[sx + 2:ex])
        else:
            ex = sx + 1
        sx = ex
    if show:
        ax = pg.plot()
        ax = dtl.plot_polygon(fp, ax, col='r')
        plt.show()
    return pg
Exemple #20
0
def checkseq(pg,fp,seq,show = False):
    print('check-pseq:',seq)
    easement = 2

    def trimtofp(p1,p2,r = 5):
        ips = pym.sintbxyp(p1,p2,fp)
        if len(ips) > 0:
            for ip in ips:
                if ip.isnear(p1):continue
                p2 = p1.lerp(ip,1-r/p1.d(ip))
        return p2

    # place a pair of vertices on the edge of the footprint
    # pointing inward, constituting an exit from the region
    def seed(rg,ss):
        print('SEED',ss)
        exp = fp[-1].lerp(fp[0],0.5)
        exn = vec3(0,0,1).crs(fp[-1].tov(fp[0])).nrm()
        ex1 = exp.cp()
        ex2 = ex1.cp().trn(exn.cp().uscl(easement))
        i1 = rg.av(p = ex1,l = 0)
        i2,r1 = rg.mev(i1,{'p':ex2,'l':0},{})
        return [i2]

    # make an edge and a vertex attached to an existing vertex
    def grow(rg,ss):
        print('GROW',ss)
        tip = nvs[-1]
        tv = rg.vs[tip]
        avs = [rg.vs[k] for k in rg.orings[tip]]
        if len(avs) == 1:
            op = tv[1]['p']
            nptn = avs[0][1]['p'].tov(op).nrm().uscl(100)
            np = op.cp().trn(nptn)
            np = trimtofp(op,np,easement+10)
            nv,nr = rg.mev(tip,{'p':np,'l':0},{})
        return [nv]

    def loop(rg,ss):
        print('LOOP',ss)

    grammer = {
        'S':seed,
        'G':grow,
        'L':loop,
            }

    scnt = len(seq)
    sx = 0
    while sx < scnt:
        c = seq[sx]
        if c in grammer:
            ex = db.seqread(seq,sx)
            nvs = grammer[c](pg,seq[sx+2:ex])
        else:ex = sx+1
        sx = ex
    if show:
        ax = pg.plot()
        ax = dtl.plot_polygon(fp,ax,col = 'r')
        plt.show()
    return pg
 def pl():
     ax = rg.plot()
     ax = dtl.plot_polygon(fp,ax,col = 'b')
     ax = dtl.plot_point(ex,ax,col = 'r')
     plt.show()
Exemple #22
0
 def pl():
     ax = rg.plot()
     ax = dtl.plot_polygon(fp, ax, col='b')
     ax = dtl.plot_point(ex, ax, col='r')
     plt.show()