Example #1
0
def csgtest():
    plc1 = dtl.box(5, 5, 5)
    #plc2 = dtl.icosphere(2,1)
    plc2 = dtl.box(5, 3, 4).translate(dpv.vector(2, 2, -0.5))
    #plc2 = dtl.box(5,2,2).translate(dpv.vector(0,0,1.5))
    #plc2 = dtl.box(5,2,2).translate(dpv.vector(0,0,1.5))
    #plc2.translate(dpv.vector(0,0,5.0))
    #plc2.translate(dpv.vector(0,0,-3.0))
    #plc2.rotate(dpq.q_from_av(dpr.PI/6.0,dpv.x()))
    #plc2.translate(dpv.vector(0,0, 3.0))
    #plc1.triangulate()
    #plc2.triangulate()

    print('union input')
    ax = dtl.plot_axes()
    ax = plc1.plot(ax)
    ax = plc2.plot(ax)
    plt.show()

    plc3 = pwc.union(plc1, plc2)
    #plc3 = pwc.intersection(plc1,plc2)
    #plc3 = pwc.difference(plc1,plc2)

    print('union output')
    ax = dtl.plot_axes()
    ax = plc3.plot(ax)
    plt.show()
Example #2
0
def csgtest():
    plc1 = dtl.box(5,5,5)
    #plc2 = dtl.icosphere(2,1)
    plc2 = dtl.box(5,3,4).translate(dpv.vector(2,2,-0.5))
    #plc2 = dtl.box(5,2,2).translate(dpv.vector(0,0,1.5))
    #plc2 = dtl.box(5,2,2).translate(dpv.vector(0,0,1.5))
    #plc2.translate(dpv.vector(0,0,5.0))
    #plc2.translate(dpv.vector(0,0,-3.0))
    #plc2.rotate(dpq.q_from_av(dpr.PI/6.0,dpv.x()))
    #plc2.translate(dpv.vector(0,0, 3.0))
    #plc1.triangulate()
    #plc2.triangulate()

    print('union input')
    ax = dtl.plot_axes()
    ax = plc1.plot(ax)
    ax = plc2.plot(ax)
    plt.show()

    plc3 = pwc.union(plc1,plc2)
    #plc3 = pwc.intersection(plc1,plc2)
    #plc3 = pwc.difference(plc1,plc2)

    print('union output')
    ax = dtl.plot_axes()
    ax = plc3.plot(ax)
    plt.show()
Example #3
0
 def plot(self,ax = None):
     if ax is None:ax = dtl.plot_axes()
     np1 = self.one.p
     np2 = self.two.p
     dtl.plot_edges([np1,np2],ax)
     dtl.plot_edges(self.rpts,ax)
     return ax
Example #4
0
 def plot(self, ax=None):
     if ax is None: ax = dtl.plot_axes()
     np1 = self.one.p
     np2 = self.two.p
     dtl.plot_edges([np1, np2], ax)
     dtl.plot_edges(self.rpts, ax)
     return ax
Example #5
0
def opass():
    g = graph()

    bnd = dpr.square(100,100)
    oprgn1 = grg.overpass(bnd)
    oprgn1._graph(g)

    bnd = dpr.square(100,100,dpv.vector(500,0,0),dpr.rad(75))
    oprgn2 = grg.overpass(bnd)
    oprgn2._graph(g)

    bnd = dpr.square(100,100,dpv.vector(250,200,0),dpr.rad(35))
    oprgn3 = grg.overpass(bnd)
    oprgn3._graph(g)

    oprgn1._connect(oprgn2,g)
    oprgn2._connect(oprgn3,g)
    oprgn3._connect(oprgn1,g)

    g._update()

    ax = dtl.plot_axes()
    ax = oprgn1.plot(ax)
    ax = oprgn2.plot(ax)
    ax = oprgn3.plot(ax)
    ax = g.plot(ax)
    ax.set_zlim([0,40])

    plt.show()

    return g
Example #6
0
 def plot(self,ax = None):
     if ax is None:ax = dtl.plot_axes()
     plotp = self.p.copy()
     dtl.plot_point(plotp,ax)
     for d in self.ring.keys():
         f = plotp.copy().translate(self.spikes[d])
         dtl.plot_edges([plotp,f],ax)
     return ax
Example #7
0
 def plot(self, ax=None):
     if ax is None: ax = dtl.plot_axes()
     self.plot_rgraph(ax)
     self.plot_rgraph(ax)
     dtl.plot_polygon(self.boundary, ax)
     r = self.radius()
     ax.set_xlim([-r, r])
     ax.set_ylim([-r, r])
     ax.set_zlim([-r, r])
     return ax
Example #8
0
 def plot(self,ax = None):
     if ax is None:ax = dtl.plot_axes()
     self.plot_rgraph(ax)
     self.plot_rgraph(ax)
     dtl.plot_polygon(self.boundary,ax)
     r = self.radius()
     ax.set_xlim([-r,r])
     ax.set_ylim([-r,r])
     ax.set_zlim([-r,r])
     return ax
Example #9
0
 def plot(self, ax=None):
     if ax is None: ax = dtl.plot_axes()
     for n in self.nodes:
         if not n is None: n.plot(ax)
     for e in self.edges:
         if not e is None: e.plot(ax)
     r = self.radius()
     ax.set_xlim([-r, r])
     ax.set_ylim([-r, r])
     ax.set_zlim([-r, r])
     return ax
Example #10
0
def clean_polygon(eb,ibs):
    clean = False
    neb = eb[:]
    #nibs = [ib[:] for ib in ibs]

    flag = False

    while not clean:
        icnt = len(ibs)
        nibs = []
        if icnt == 0:clean = True
        else:
            for x in range(icnt):
                ib = ibs[x]
                isect = dpr.concaves_intersect(neb,ib)
                ins = dpr.inconcave_xy(ib[0],neb)
                if isect:
                    neb = dtl.polygon_difference((neb,()),(ib,()))[0]

                    print('polygon hole intersects boundary',x)
                    ax = dtl.plot_axes()
                    ax = dtl.plot_polygon_full((neb,()),ax)
                    plt.show()
                    flag = True

                    break
                elif ins:nibs.append(ib)
                else:print('polygon hole found outside of boundary',x)

                print('wtf',x,icnt)

                if x == icnt - 1:clean = True

    if flag:
        tns = [dpv.distance(neb[t-1],neb[t]) for t in range(len(neb))]
        print('exit CLEANPOLYGON',tns)
        ax = dtl.plot_axes()
        ax = dtl.plot_polygon_full((neb,nibs),ax)
        plt.show()

    return neb,nibs
Example #11
0
 def plot(self,ax = None):
     if ax is None:ax = dtl.plot_axes()
     for n in self.nodes:
         if not n is None:
             n.plot(ax)
     for eg in self.edges:
         if not eg is None:
             eg.plot(ax)
     ax.set_xlim([-100,100])
     ax.set_ylim([-100,100])
     ax.set_zlim([-100,100])
     return ax
Example #12
0
 def plot(self,ax = None):
     if ax is None:
         l = self.radius()
         ax = dtl.plot_axes(x = l)
     ax = dtl.plot_points(self.points.ps,ax)
     for edx in range(len(self.edges)):
         e = self.edges[edx]
         if e is None:continue
         dtl.plot_edges(self.points.get_points(*e),ax)
     for smp in self.simplices:dtl.plot_polygon(list(smp),ax)
     for gst in self.ghostbnds:dtl.plot_edges(gst,ax,lw = 5.0)
     return ax
Example #13
0
 def plot(self,ax = None):
     if ax is None:ax = dtl.plot_axes()
     for n in self.mesh.nodes:
         dtl.plot_point(self.geom.points.ps[n.px],ax)
     for e in self.mesh.edges:
         if e is None:continue
         eps = self.geom.points.ps[e.one.px],self.geom.points.ps[e.two.px]
         dtl.plot_edges(eps,ax)
     r = self.geom.radius()
     ax.set_xlim([-r,r])
     ax.set_ylim([-r,r])
     ax.set_zlim([-r,r])
     return ax
Example #14
0
 def plot(self,ax = None,limit = 250):
     if ax is None:ax = dtl.plot_axes()
     for pg in self.plugs:
         edx,epos,elay = pg
         e0,e1 = edx,edx+1 if edx+1<len(self.boundary) else 0
         s,e = self.boundary[e0],self.boundary[e1]
         pgp = s.linterpolate(e,epos).translate_z(20*elay)
         ndkey = (pgp.x,pgp.y,elay)
         dtl.plot_point(pgp,ax)
     for l in self._layers():self.plot_boundary(l,ax)
     ax.set_xlim([-limit,limit])
     ax.set_ylim([-limit,limit])
     ax.set_zlim([0,40])
     for ch in self.children:ax = ch.plot(ax,limit = limit)
     return ax
Example #15
0
def teststage(**kwargs):
    mod = dmo.model()

    #mod = tridome(mod)
    mod = house(mod)

    ax = dtl.plot_axes()
    for gmesh in mod.gfxmeshes:
        for f in gmesh.faces:
            ps = mod.gvps(gmesh, f)
            ax = dtl.plot_polygon(ps, ax)
    plt.show()

    print('build2 cube now')
    build2(mod, **kwargs)
Example #16
0
def teststage(**kwargs):
    mod = dmo.model()

    #mod = tridome(mod)
    mod = house(mod)

    ax = dtl.plot_axes()
    for gmesh in mod.gfxmeshes:
        for f in gmesh.faces:
            ps = mod.gvps(gmesh,f)
            ax = dtl.plot_polygon(ps,ax)
    plt.show()

    print('build2 cube now')
    build2(mod,**kwargs)
Example #17
0
 def plot(self, ax=None, limit=250):
     if ax is None: ax = dtl.plot_axes()
     for pg in self.plugs:
         edx, epos, elay = pg
         e0, e1 = edx, edx + 1 if edx + 1 < len(self.boundary) else 0
         s, e = self.boundary[e0], self.boundary[e1]
         pgp = s.linterpolate(e, epos).translate_z(20 * elay)
         ndkey = (pgp.x, pgp.y, elay)
         dtl.plot_point(pgp, ax)
     for l in self._layers():
         self.plot_boundary(l, ax)
     ax.set_xlim([-limit, limit])
     ax.set_ylim([-limit, limit])
     ax.set_zlim([0, 40])
     for ch in self.children:
         ax = ch.plot(ax, limit=limit)
     return ax
Example #18
0
    def chew1_subdivide_polygon(self,px):
        elengs = self.edge_lengths()
        poly = self.polygons[px]
        polyes = poly[0][:]
        for ib in poly[1]:polyes += ib[:]

        es,erng = self.edges,range(self.edgecount)
        unfinished = [es[x] for x in erng if x in polyes]

        ax = dtl.plot_axes()
        for u in unfinished:
            vu,vv = self.points.get_points(*u)
            ax = dtl.plot_edges([vu,vv],ax)
        plt.show()

        hmin = min([elengs[x] for x in elengs if x in unfinished])

        print('hmin:',hmin)
        if hmin < 0.1:
            print('hmin probelm?',hmin)
            pdb.set_trace()

        while unfinished:
            unfin = unfinished.pop(0)
            if unfin is None:continue
            ex1,ex2 = unfin
            ep1,ep2 = self.points.get_points(ex1,ex2)
            eleng = elengs[unfin]
            m = 1
            while eleng/m > sqrt3*hmin:m += 1
            divpts = dpr.point_line(ep1,ep2,m)[1:-1]
            curr = ex1
            for dpt in divpts:
                ne1,ne2 = self.split_edge(curr,ex2,dpt)
                curr = ne1[1]
        return hmin
Example #19
0
 def plot(self, ax=None):
     if ax is None: ax = dtl.plot_axes()
     plotp = self.p.copy()
     dtl.plot_point(plotp, ax)
     return ax
Example #20
0
 def plot_boundary(self,layer,ax = None):
     if ax is None:ax = dtl.plot_axes()
     bnd = [b.copy().translate_z(20*layer) for b in self.boundary]
     dtl.plot_polygon(bnd,ax)
     return ax
Example #21
0
 def plot(self,ax = None):
     if ax is None:ax = dtl.plot_axes()
     plotp = self.p.copy()
     dtl.plot_point(plotp,ax)
     return ax
Example #22
0
def break_polygon(py,p2s,subop = 'union'):
    breakers = [x for x in range(len(p2s))]
    broken = [dpr.copy_polygon(py)]
    pieces = []

    while broken:
        piece = broken.pop(0)
        eb1,ibs1 = piece
        ebn1 = dpr.polygon_normal(eb1)

        brokeone = False
        for x in breakers:
            breaker = p2s[x]
            eb2,ibs2 = breaker
            ebn2 = dpr.polygon_normal(eb2)
            pj1 = dpv.project_coords(list(eb1),ebn1)
            pj2 = dpv.project_coords(list(eb2),ebn1)

            if dpr.isnear(pj2.x,pj2.y):
                if not dpr.isnear(pj1.x,pj2.x):
                    print('disjoint polygons!')
                else:
                    if subop == 'union':
                        pu = dtl.polygon_union(piece,breaker)
                    elif subop == 'intersection':
                        pu = dtl.polygon_intersection(piece,breaker)
                    elif subop == 'difference':
                        pu = dtl.polygon_difference(piece,breaker)
                    else:print('unknown subop!',subop)
                    print('known subop!',subop)
                    print('coplanar polygons!',pu)

                    if not pu is None:

                        ax = dtl.plot_axes()
                        #dtl.plot_polygon_full(piece,ax)
                        #dtl.plot_polygon_full(breaker,ax)
                        dtl.plot_polygon(list(pu[0]),ax,lw = 5.0)
                        dtl.plot_polygon(list(pu[1][0]),ax,lw = 1.0)
                        plt.show()

                        #broken.append(pu)
                        pieces.append(pu)
                        print("breaker will continue to intersect this guy...")
                        brokeone = True
                        break
            else:
                print('skew polygons')
                plintersect = dtl.planes_intersection(ebn1,eb1[0],ebn2,eb2[0])
                if not plintersect is None:
                    pli1,pli2 = plintersect

                    intins = subop == 'difference'
                    #intins = dpr.inconcave_xy(dpv.midpoint(pli1,pli2),eb2)

                    #print('inis',subop,intins)
                    breakersect = dtl.line_intersects_polygon_at(
                                        pli1,pli2,breaker,intins)
                    if not breakersect is None:

                        if not len(breakersect) == 2:
                            print('breakersect is confusing!!')

                            ax = dtl.plot_axes()
                            dtl.plot_polygon_full(breaker,ax)
                            dtl.plot_line(pli1,pli2,25,ax,lw = 4.0)
                            for x in range(len(breakersect)):
                                dtl.plot_point(breakersect[x],ax)
                            plt.show()

                            pdb.set_trace()
                        
                        b1,b2 = breakersect
                        lsp = dtl.segment_split_polygon(b1,b2,piece)
                        if not lsp is None:
                            
                            '''#
                            print('lsssspppp',len(lsp))
                            ax = dtl.plot_axes()
                            dtl.plot_line(b1,b2,25,ax,lw = 8.0)
                            for ls in lsp:
                                ax = dtl.plot_polygon_full(ls,ax,lw = 1.0)
                            ax = dtl.plot_polygon_full(breaker,ax,lw = 3.0)
                            plt.show()
                            '''#

                            broken.extend(lsp)
                            brokeone = True
                            #pdb.set_trace()
                            break
        if not brokeone:
            pieces.append(piece)
            print('nice piece',len(pieces))
    
    '''#
    if len(pieces) > 1:
      print('broke some shit??')
      ax = dtl.plot_axes()
      for p in pieces:dtl.plot_polygon_full(p,ax)
      plt.show()
    '''#
  
    return pieces
Example #23
0
    def plot_regions(self,ax = None):
        if ax is None:ax = dtl.plot_axes()

        pdb.set_trace()
Example #24
0
 def plot_boundary(self, layer, ax=None):
     if ax is None: ax = dtl.plot_axes()
     bnd = [b.copy().translate_z(20 * layer) for b in self.boundary]
     dtl.plot_polygon(bnd, ax)
     return ax