Ejemplo n.º 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
Ejemplo n.º 2
0
def realize(i, p, d, axiom, rules, **params):
    ax = dtl.plot_axes(10)
    for piece in lsy.lgen(p, d, axiom, rules, i, **params):
        if isinstance(piece, tuple):
            ax = dtl.plot_edges(piece, ax, lw=2, col='k')
        elif isinstance(piece, vec3):
            ax = dtl.plot_point(piece, ax)
    plt.show()
Ejemplo n.º 3
0
    def test_spline(self):
        e = vec3(10, 10, 1)
        t1, t2 = vec3(1, 0, 0), vec3(0, -1, 0)
        pline = self.origin.spline(e, t1, t2, 5)

        ax = dtl.plot_axes(10)
        ax = dtl.plot_edges(pline, ax, lw=3, col='b')
        plt.show()
Ejemplo n.º 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()
Ejemplo n.º 5
0
def realize(i,p,d,axiom,rules,**params):
    ax = dtl.plot_axes(10)
    for piece in lsy.lgen(p,d,axiom,rules,i,**params):
        if isinstance(piece,tuple):
            ax = dtl.plot_edges(piece,ax,lw = 2,col = 'k')
        elif isinstance(piece,vec3):
            ax = dtl.plot_point(piece,ax)
    plt.show()
Ejemplo n.º 6
0
    def test_spline(self):
        e = vec3(10,10,1)
        t1,t2 = vec3(1,0,0),vec3(0,-1,0)
        pline = self.origin.spline(e,t1,t2,5)

        ax = dtl.plot_axes(10)
        ax = dtl.plot_edges(pline,ax,lw = 3,col = 'b')
        plt.show()
Ejemplo n.º 7
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()
Ejemplo n.º 8
0
 def plot(self,ax = None,l = 300,s = (vec3(-10000,0,0),vec3(10000,0,0))):
     if ax is None:ax = dtl.plot_axes(l)
     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)
     pv(self.root,ax)
     return ax
Ejemplo n.º 9
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()
Ejemplo n.º 10
0
 def plot(self,ax = None,l = 10,**kws):
     if ax is None:ax = dtl.plot_axes(l)
     for j in range(self.vcnt):
         i = self.vs[j]
         if i is None:continue
         ip = i[1]['p']
         ax = dtl.plot_point(ip,ax,col = 'r')
     for k in self.rings:
         vr = self.rings[k]
         for ov in vr:
             if vr[ov] is None:continue
             re = (self.vs[k][1]['p'].cp(),self.vs[ov][1]['p'].cp())
             rn = vec3(0,0,1).crs(re[0].tov(re[1])).nrm()
             re = (re[0].trn(rn),re[1].trn(rn))
             ax = dtl.plot_edges(re,ax,lw = 2,col = 'g')
     return ax
Ejemplo n.º 11
0
 def plot(self, ax=None, l=10, **kws):
     if ax is None: ax = dtl.plot_axes(l)
     for j in range(self.vcnt):
         i = self.vs[j]
         if i is None: continue
         ip = i[1]['p']
         ax = dtl.plot_point(ip, ax, col='r')
     for k in self.rings:
         vr = self.rings[k]
         for ov in vr:
             if vr[ov] is None: continue
             re = (self.vs[k][1]['p'].cp(), self.vs[ov][1]['p'].cp())
             rn = vec3(0, 0, 1).crs(re[0].tov(re[1])).nrm()
             re = (re[0].trn(rn), re[1].trn(rn))
             ax = dtl.plot_edges(re, ax, lw=2, col='g')
     return ax
Ejemplo n.º 12
0
 def plotmesh(self):
     mesh = self.mesh
     ax = dtl.plot_axes()
     for f in mesh.faces:                    
         for l in mesh.mask(2,None,None,None,f):
             hes = mesh.mask(6,None,None,l,None)
             p1 = self.pset.ps[hes[0].one[1]]
             p2 = self.pset.ps[hes[0].two[1]]
             ps = [p1,p2]
             for hx in range(1,len(hes)):
                 onep = self.pset.ps[hes[hx].one[1]]
                 twop = self.pset.ps[hes[hx].two[1]]
                 if   ps[-1].isnear(onep):ps.append(twop)
                 elif ps[-1].isnear(twop):ps.append(onep)
                 else:raise ValueError
             ax = dtl.plot_edges(ps,ax)
     plt.show()
Ejemplo n.º 13
0
 def plotmesh(self):
     mesh = self.mesh
     ax = dtl.plot_axes()
     for f in mesh.faces:
         for l in mesh.mask(2, None, None, None, f):
             hes = mesh.mask(6, None, None, l, None)
             p1 = self.pset.ps[hes[0].one[1]]
             p2 = self.pset.ps[hes[0].two[1]]
             ps = [p1, p2]
             for hx in range(1, len(hes)):
                 onep = self.pset.ps[hes[hx].one[1]]
                 twop = self.pset.ps[hes[hx].two[1]]
                 if ps[-1].isnear(onep): ps.append(twop)
                 elif ps[-1].isnear(twop): ps.append(onep)
                 else: raise ValueError
             ax = dtl.plot_edges(ps, ax)
     plt.show()
Ejemplo n.º 14
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
Ejemplo n.º 15
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
Ejemplo n.º 16
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
Ejemplo n.º 17
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
Ejemplo n.º 18
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
Ejemplo n.º 19
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
Ejemplo n.º 20
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
Ejemplo n.º 21
0
    def ____genregions(self, t, r):
        pg = ptg.partitiongraph()
        rpy = pym.pgtopy(r, 3)

        ax = dtl.plot_axes(200)
        #ax = pg.plotxy(ax)
        #for j in range(len(loops)):
        #    ax = dtl.plot_polygon_xy(loops[j],ax)
        if rpy: ax = dtl.plot_polygon_full(rpy, ax)
        plt.show()

        #rtl = t.al(rpy[0],t.locloop(rpy[0],1)[0])

        ### create the ocean vertex
        #b = t.root.loop
        b = t.boundary
        ov = pg.av(b=[b, []], p=vec3(0, 0, 0).com(b), t=['ocean'])

        ### create landmass vertices
        #ls = t.looptree.below(t.root)
        lmvs = []
        for l in t.landmasses:
            lv = pg.sv(ov, b, l.loop)
            pg.vs[lv][1]['t'] = ['natural']

            if not rpy is None:
                loops = pym.ebdxy(l.loop, rpy[0])

                '''#
                print('looooopeed',[len(l) for l in loops])
                ax = dtl.plot_axes_xy(100)
                ax = pg.plotxy(ax)
                for j in range(len(loops)):
                    ax = dtl.plot_polygon_xy(loops[j],ax)
                ax = dtl.plot_polygon_full_xy(rpy,ax)
                plt.show()
                '''#

                if len(loops) > 1:
                    for loop in loops[:-1]:
                        rv = pg.sv(lv, l.loop, loop)
                        pg.vs[rv][1]['t'] = ['natural']
                    rv = pg.sv(lv, loops[-1], rpy[0])
                    pg.vs[rv][1]['t'] = ['infrastructure']
                else:
                    rv = pg.sv(lv, loops[0], rpy[0])
                    pg.vs[rv][1]['t'] = ['infrastructure']

                for dpy in rpy[1]:
                    dv = pg.sv(rv, rpy[0], dpy)
                    pg.vs[dv][1]['t'] = ['developed']

                print('chea1')
                for dpy in rpy[1]:
                    rtv = t.al(dpy, t.locloop(dpy, 0)[0])
                print('chea2')

                '''#
                ax = dtl.plot_axes_xy(200)
                #ax = r.plotxy(ax)
                ax = pg.plotxy(ax)
                #ax = dtl.plot_polygon_full_xy(rpy,ax)
                plt.show()
                '''#

            lmvs.append(lv)

        ### create the details of each landmass vertex
        for lm in lmvs:
            self.genregion(t, r, lm, pg)

        ### attach the terrain mesh to the partition vertices...
        for vx in range(pg.vcnt):
            pv = pg.vs[vx]
            if pv is None: continue
            pv[1]['tmesh'] = t

        ### return partition graph
        return pg
Ejemplo n.º 22
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()
Ejemplo n.º 23
0
 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()
Ejemplo n.º 24
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()