Esempio n. 1
0
    def generate(self,worn = 0):
        self.layout_infrastructure()
        for tpoly in self.igraph.tpolygons:
            tarea = dar.area(boundary = tpoly)
            self._consume(tarea.generate())

        rplc = pwc.piecewise_linear_complex(refine = True,smooth = True)
        rplc.add_polygons(*self.igraph.rpolygons)
        rplc.triangulate()
        rpelt = rplc.pelt()
        rnode = self._node_wrap(rpelt)
        self._nodes_to_graph(rnode)

        # add water models to scenegraph
        '''#
        wl = lscape.landbb.x.y - lscape.landbb.x.x + 100.0
        ww = lscape.landbb.y.y - lscape.landbb.y.x + 100.0
        wr = max([wl,ww])
        water = dcyl.cylinder(n = 8).translate_z(-0.5)
        water.scale_x(wr).scale_y(wr).scale_z(20)
        water.translate_z(self.sealevel)
        water.translate(lscape.landbb._center().xy())
        wnode = self._node_wrap(water)
        self._nodes_to_graph(wnode)
        '''#
        return self
Esempio n. 2
0
def profile_triangulation():
    import dilap.mesh.piecewisecomplex as pwc

    ps1 = tuple(dpr.point_ring(100,32))
    ps2 = tuple(dpr.point_ring(20,8))
    ps3 = tuple(dpr.point_ring(100,64))
    ps4 = tuple([p.copy() for p in ps2])
    q = dpq.q_from_av(numpy.pi/2.0,dpv.xhat)
    for p in ps1:p.rotate(q)
    for p in ps2:p.rotate(q)
    dpv.translate_coords(list(ps1),dpv.vector(0,100,0))
    dpv.translate_coords(list(ps2),dpv.vector(0,100,0))
    dpv.translate_coords(list(ps3),dpv.vector(0,0,-100))
    dpv.translate_coords(list(ps4),dpv.vector(0,0,-100))

    polygons = ((ps1,(ps2,)),(ps3,()))
    #polygons = ((ps3,(ps4,)),)
    #polygons = ((ps3,()),)

    plc = pwc.piecewise_linear_complex()
    plc.add_polygons(*polygons)
    
    dprf.profile_function(plc.triangulate)
    #dprf.profile_function(plc.triangulate_xy)

    ax = plc.plot()
    plt.show()
Esempio n. 3
0
    def generate(self, worn=0):

        polygon = (tuple(x.copy() for x in self.boundary), ())
        plc = pwc.piecewise_linear_complex()
        plc.add_polygons(polygon)
        plc.extrude_polygon(0, dpv.vector(0, 0, 10))
        plc.triangulate()

        #plc.plot()
        #plt.show()

        pelt = plc.pelt()
        node = self._node_wrap(pelt)
        self._nodes_to_graph(node)
        return self

        self.fplan.plan()
        for x in range(self.stories):
            self.fplan.plan_specific(x)
            self.fplan.sgraph.nodes = []
            # need to get bboxes for the floorplan?
            self.fplan.generate(self.wheights[x], worn)
            if x == 0: self.generate_stoop(worn)
            self.generate_story(x, worn)
        for s in self.fplan.generate_shafts(worn):
            self._consume(s)
        self._consume(self.fplan.generate_roof(worn))
        return self
Esempio n. 4
0
def profile_triangulation():
    import dilap.mesh.piecewisecomplex as pwc

    ps1 = tuple(dpr.point_ring(100, 32))
    ps2 = tuple(dpr.point_ring(20, 8))
    ps3 = tuple(dpr.point_ring(100, 64))
    ps4 = tuple([p.copy() for p in ps2])
    q = dpq.q_from_av(numpy.pi / 2.0, dpv.xhat)
    for p in ps1:
        p.rotate(q)
    for p in ps2:
        p.rotate(q)
    dpv.translate_coords(list(ps1), dpv.vector(0, 100, 0))
    dpv.translate_coords(list(ps2), dpv.vector(0, 100, 0))
    dpv.translate_coords(list(ps3), dpv.vector(0, 0, -100))
    dpv.translate_coords(list(ps4), dpv.vector(0, 0, -100))

    polygons = ((ps1, (ps2, )), (ps3, ()))
    #polygons = ((ps3,(ps4,)),)
    #polygons = ((ps3,()),)

    plc = pwc.piecewise_linear_complex()
    plc.add_polygons(*polygons)

    dprf.profile_function(plc.triangulate)
    #dprf.profile_function(plc.triangulate_xy)

    ax = plc.plot()
    plt.show()
Esempio n. 5
0
def facade():
    import dilap.mesh.piecewisecomplex as pwc
    rim = [
        dpv.vector(0, 0, 0),
        dpv.vector(15, 0, 0),
        dpv.vector(15, 0, 4),
        dpv.vector(0, 0, 4)
    ]

    door = [
        dpv.vector(-1, 0, 0.2),
        dpv.vector(1, 0, 0.2),
        dpv.vector(1, 0, 3),
        dpv.vector(-1, 0, 3)
    ]
    dpv.translate_coords(door, dpv.vector(10, 0, 0))

    wspline = dpv.vector_spline(dpv.vector(2, 0, 3), dpv.vector(1.8, 0, 3.2),
                                dpv.vector(-1.8, 0, 3.2), dpv.vector(-2, 0, 3),
                                10)
    window = [
        dpv.vector(-2, 0, 0.5),
        dpv.vector(2, 0, 0.5),
        dpv.vector(2, 0, 3)
    ] + wspline + [dpv.vector(-2, 0, 3)]
    dpv.translate_coords(window, dpv.vector(5, 0, 0))

    beam = [
        dpv.vector(1, 0, 1),
        dpv.vector(2, 0, 1),
        dpv.vector(2, 0, 9),
        dpv.vector(1, 0, 9)
    ]

    #fac = (rim,(door,window,beam)),(beam,())
    fac = (rim, (door, window, beam)),

    plc = pwc.piecewise_linear_complex()
    plc.add_polygons(*fac)

    #plc.translate_polygon(2,dpv.vector(0,0,10))
    #plc.extrude_polygon(1,dpv.vector(0,1,0))

    plc.triangulate()

    #ax = plc.plot_xy()
    #ax = plc.plot()

    #plt.show()
    return plc
Esempio n. 6
0
    def generate(self):
        self.populate()
        self.place_lots()
        tplc = pwc.piecewise_linear_complex(refine = True,smooth = False)
        tplc.add_polygons(self.boundary)

        dprf.profile_function(tplc.triangulate)
        tpelt = tplc.pelt()
        tnode = self._node_wrap(tpelt)
        self._nodes_to_graph(tnode)

        #plantmodel = dflg.plant().model()
        #plantnode = self._node_wrap(plantmodel)
        #self._nodes_to_graph(plantnode)

        return self
Esempio n. 7
0
    def generate(self):
        self.populate()
        self.place_lots()
        tplc = pwc.piecewise_linear_complex(refine=True, smooth=False)
        tplc.add_polygons(self.boundary)

        dprf.profile_function(tplc.triangulate)
        tpelt = tplc.pelt()
        tnode = self._node_wrap(tpelt)
        self._nodes_to_graph(tnode)

        #plantmodel = dflg.plant().model()
        #plantnode = self._node_wrap(plantmodel)
        #self._nodes_to_graph(plantnode)

        return self
Esempio n. 8
0
def roof():
    import dilap.mesh.piecewisecomplex as pwc
    plc = pwc.piecewise_linear_complex()

    h = 5
    ebnd = (dpv.vector(0, 0, 0), dpv.vector(10, 0, 0), dpv.vector(10, 10, 0),
            dpv.vector(20, 10, 0), dpv.vector(20, 20, 0), dpv.vector(0, 20, 0))
    ibnd = (dpv.vector(2, 2, h), dpv.vector(8, 2, h), dpv.vector(8, 12, h),
            dpv.vector(18, 12, h), dpv.vector(18, 18, h), dpv.vector(2, 18, h))
    polygons = ((ebnd, (ibnd, )), )

    plc.add_polygons(*polygons)
    dprf.profile_function(plc.triangulate)
    ax = plc.plot()
    plt.show()
    return plc
Esempio n. 9
0
def triang():

    #pts = dpr.dice_edges(dpr.square(50,10),2)
    hpts = [dpv.vector(5,-2,3)]
    hpts.append(hpts[-1].copy().translate(dpv.vector(0,5,0)))
    hpts.append(hpts[-1].copy().translate(dpv.vector(-10,0,0)))
    hpts.append(hpts[-1].copy().translate(dpv.vector(0,-3,0)))
    hpts.append(hpts[-1].copy().translate(dpv.vector(5,0,0)))
    hpts.append(hpts[-1].copy().translate(dpv.vector(0,-2,0)))
    hpts2 = [h.copy().translate_x(-12).translate_z(-6) for h in hpts]
    pts = dpr.inflate([h.copy().translate_x(-6).translate_z(-3) for h in hpts],14)

    #pts  = dpv.translate_coords(dpr.square(50,10),dpv.vector(-30,-12,0))
    pts2 = dpv.translate_coords(dpr.square(30,10),dpv.vector(30,20,0))
    pts3 = dpv.translate_coords(dpr.square(20,10),dpv.vector(-30,-20,0))

    pts2.insert(1,dpv.vector(25,15,0))
    pts2.insert(1,dpv.vector(25,20,0))
    pts2.insert(1,dpv.vector(20,20,0))
    pts2.insert(1,dpv.vector(20,15,0))
    #pts2 = dpr.point_ring(100,16)

    ax = dtl.plot_axes_xy()
    ax = dtl.plot_points_xy(pts2,ax,number = True)
    plt.show()

    points = []
    edges = []
    polygons = [(pts,(hpts,hpts2)),(pts2,()),(pts3,())]
    #polygons = [(pts2,())]
    #polygons = [(pts,(hpts,hpts2))]
    #polygons = [(pts,()),(pts2,())]
    polyhedra = []

    plc = pwc.piecewise_linear_complex(
        refine = True,smooth = False)
    plc.add_points(*points)
    plc.add_edges(*edges)
    plc.add_polygons(*polygons)
    #plc.add_polyhedra(*polyhedra)
    plc.triangulate()

    #ax = plc.plot_xy()
    ax = plc.plot()
    plt.show()

    '''#
Esempio n. 10
0
def triang():

    #pts = dpr.dice_edges(dpr.square(50,10),2)
    hpts = [dpv.vector(5, -2, 3)]
    hpts.append(hpts[-1].copy().translate(dpv.vector(0, 5, 0)))
    hpts.append(hpts[-1].copy().translate(dpv.vector(-10, 0, 0)))
    hpts.append(hpts[-1].copy().translate(dpv.vector(0, -3, 0)))
    hpts.append(hpts[-1].copy().translate(dpv.vector(5, 0, 0)))
    hpts.append(hpts[-1].copy().translate(dpv.vector(0, -2, 0)))
    hpts2 = [h.copy().translate_x(-12).translate_z(-6) for h in hpts]
    pts = dpr.inflate([h.copy().translate_x(-6).translate_z(-3) for h in hpts],
                      14)

    #pts  = dpv.translate_coords(dpr.square(50,10),dpv.vector(-30,-12,0))
    pts2 = dpv.translate_coords(dpr.square(30, 10), dpv.vector(30, 20, 0))
    pts3 = dpv.translate_coords(dpr.square(20, 10), dpv.vector(-30, -20, 0))

    pts2.insert(1, dpv.vector(25, 15, 0))
    pts2.insert(1, dpv.vector(25, 20, 0))
    pts2.insert(1, dpv.vector(20, 20, 0))
    pts2.insert(1, dpv.vector(20, 15, 0))
    #pts2 = dpr.point_ring(100,16)

    ax = dtl.plot_axes_xy()
    ax = dtl.plot_points_xy(pts2, ax, number=True)
    plt.show()

    points = []
    edges = []
    polygons = [(pts, (hpts, hpts2)), (pts2, ()), (pts3, ())]
    #polygons = [(pts2,())]
    #polygons = [(pts,(hpts,hpts2))]
    #polygons = [(pts,()),(pts2,())]
    polyhedra = []

    plc = pwc.piecewise_linear_complex(refine=True, smooth=False)
    plc.add_points(*points)
    plc.add_edges(*edges)
    plc.add_polygons(*polygons)
    #plc.add_polyhedra(*polyhedra)
    plc.triangulate()

    #ax = plc.plot_xy()
    ax = plc.plot()
    plt.show()

    '''#
Esempio n. 11
0
def tetra():
    pts = dpr.dice_edges(dpr.square(5, 5), 1)
    pts.extend([d.copy().translate_z(10) for d in pts])

    plc = pwc.piecewise_linear_complex()
    plcxs = plc.add_points(*pts)

    for x in range(8):
        y = x + 1 if x < 7 else 0
        plc.add_edge(x, y)

    print('input plc')
    plc.plot()
    plt.show()
    print('begin tetra')
    plc.tetrahedralize()
    print('end tetra')
    print('output plc')
    plc.plot()
    plt.show()
Esempio n. 12
0
def roof():
    import dilap.mesh.piecewisecomplex as pwc
    plc = pwc.piecewise_linear_complex()

    h = 5
    ebnd = (
        dpv.vector(0,0,0),dpv.vector(10,0,0),
        dpv.vector(10,10,0),dpv.vector(20,10,0),
        dpv.vector(20,20,0),dpv.vector(0,20,0))
    ibnd = (
        dpv.vector(2,2,h),dpv.vector(8,2,h),
        dpv.vector(8,12,h),dpv.vector(18,12,h),
        dpv.vector(18,18,h),dpv.vector(2,18,h))
    polygons = ((ebnd,(ibnd,)),)

    plc.add_polygons(*polygons)
    dprf.profile_function(plc.triangulate)
    ax = plc.plot()
    plt.show()
    return plc
Esempio n. 13
0
def facade():
    import dilap.mesh.piecewisecomplex as pwc
    rim = [
        dpv.vector(0,0,0),dpv.vector(15,0,0),
        dpv.vector(15,0,4),dpv.vector(0,0,4)]

    door = [
        dpv.vector(-1,0,0.2),dpv.vector(1,0,0.2),
        dpv.vector(1,0,3),dpv.vector(-1,0,3)]
    dpv.translate_coords(door,dpv.vector(10,0,0))

    wspline = dpv.vector_spline(
        dpv.vector(2,0,3),dpv.vector(1.8,0,3.2),
        dpv.vector(-1.8,0,3.2),dpv.vector(-2,0,3),10)
    window = [
        dpv.vector(-2,0,0.5),dpv.vector(2,0,0.5),
        dpv.vector(2,0,3)]+wspline+[dpv.vector(-2,0,3)]
    dpv.translate_coords(window,dpv.vector(5,0,0))

    beam = [
        dpv.vector(1,0,1),dpv.vector(2,0,1),
        dpv.vector(2,0,9),dpv.vector(1,0,9)]

    #fac = (rim,(door,window,beam)),(beam,())
    fac = (rim,(door,window,beam)),
    
    plc = pwc.piecewise_linear_complex()
    plc.add_polygons(*fac)

    #plc.translate_polygon(2,dpv.vector(0,0,10))
    #plc.extrude_polygon(1,dpv.vector(0,1,0))

    plc.triangulate()

    #ax = plc.plot_xy()
    #ax = plc.plot()

    #plt.show()
    return plc
Esempio n. 14
0
def tetra():
    pts = dpr.dice_edges(dpr.square(5,5),1)
    pts.extend([d.copy().translate_z(10) for d in pts])

    plc = pwc.piecewise_linear_complex()
    plcxs = plc.add_points(*pts)

    for x in range(8):
        y = x+1 if x < 7 else 0
        plc.add_edge(x,y)



    print('input plc')
    plc.plot()
    plt.show()
    print('begin tetra')
    plc.tetrahedralize()
    print('end tetra')
    print('output plc')
    plc.plot()
    plt.show()
Esempio n. 15
0
def box(l = 1,w = 1,h = 2):
    import dilap.mesh.piecewisecomplex as pwc
    plc = pwc.piecewise_linear_complex()

    pts = []
    pts.append(dpv.vector( 0, 0, 0))
    pts.append(dpv.vector( l, 0, 0))
    pts.append(dpv.vector( l, w, 0))
    pts.append(dpv.vector( 0, w, 0))
    pts.append(dpv.vector( 0, 0, h))
    pts.append(dpv.vector( l, 0, h))
    pts.append(dpv.vector( l, w, h))
    pts.append(dpv.vector( 0, w, h))
    dpv.translate_coords(pts,dpv.vector(-0.5*l,-0.5*w,0.0))

    polygons = ((3,2,1,0),(4,5,6,7),(0,1,5,4),(1,2,6,5),(2,3,7,6),(3,0,4,7))
    polygons = tuple((tuple(pts[x].copy() for x in p),()) for p in polygons)

    plc.add_polygons(*polygons)
    #dprf.profile_function(plc.triangulate)
    #ax = plc.plot()
    #plt.show()
    return plc
Esempio n. 16
0
def box(l=1, w=1, h=2):
    import dilap.mesh.piecewisecomplex as pwc
    plc = pwc.piecewise_linear_complex()

    pts = []
    pts.append(dpv.vector(0, 0, 0))
    pts.append(dpv.vector(l, 0, 0))
    pts.append(dpv.vector(l, w, 0))
    pts.append(dpv.vector(0, w, 0))
    pts.append(dpv.vector(0, 0, h))
    pts.append(dpv.vector(l, 0, h))
    pts.append(dpv.vector(l, w, h))
    pts.append(dpv.vector(0, w, h))
    dpv.translate_coords(pts, dpv.vector(-0.5 * l, -0.5 * w, 0.0))

    polygons = ((3, 2, 1, 0), (4, 5, 6, 7), (0, 1, 5, 4), (1, 2, 6, 5),
                (2, 3, 7, 6), (3, 0, 4, 7))
    polygons = tuple((tuple(pts[x].copy() for x in p), ()) for p in polygons)

    plc.add_polygons(*polygons)
    #dprf.profile_function(plc.triangulate)
    #ax = plc.plot()
    #plt.show()
    return plc
Esempio n. 17
0
 def __init__(self,boundary,**kwargs):
     self.boundary = boundary
     self.graph = dst.graph(boundary)
     self.plc = pwc.piecewise_linear_complex()
Esempio n. 18
0
def icosphere(r = 1,n = 1):
    import dilap.mesh.piecewisecomplex as pwc
    plc = pwc.piecewise_linear_complex()

    # create 12 vertices of a icosahedron
    t = (1.0+math.sqrt(5.0))/2.0
    pts = []
    pts.append(dpv.vector(-1, t, 0))
    pts.append(dpv.vector( 1, t, 0))
    pts.append(dpv.vector(-1,-t, 0))
    pts.append(dpv.vector( 1,-t, 0))
    pts.append(dpv.vector( 0,-1, t))
    pts.append(dpv.vector( 0, 1, t))
    pts.append(dpv.vector( 0,-1,-t))
    pts.append(dpv.vector( 0, 1,-t))
    pts.append(dpv.vector( t, 0,-1))
    pts.append(dpv.vector( t, 0, 1))
    pts.append(dpv.vector(-t, 0,-1))
    pts.append(dpv.vector(-t, 0, 1))
    dpv.translate_coords(pts,dpv.center_of_mass(pts).flip())

    triangles = []
    # 5 faces around point 0
    triangles.append((0,11,5))
    triangles.append((0,5,1))
    triangles.append((0,1,7))
    triangles.append((0,7,10))
    triangles.append((0,10,11))
    # 5 adjacent faces
    triangles.append((1,5,9))
    triangles.append((5,11,4))
    triangles.append((11,10,2))
    triangles.append((10,7,6))
    triangles.append((7,1,8))
    # 5 faces around point 3
    triangles.append((3,9,4))
    triangles.append((3,4,2))
    triangles.append((3,2,6))
    triangles.append((3,6,8))
    triangles.append((3,8,9))
    # 5 adjacent faces
    triangles.append((4,9,5))
    triangles.append((2,4,11))
    triangles.append((6,2,10))
    triangles.append((8,6,7))
    triangles.append((9,8,1))

    def esplit(lk,u,v):
        k = (u,v)
        if not k in lk:
            pts.append(dpv.midpoint(pts[u],pts[v]))
            lk[k] = len(pts)-1
        return lk[k]
    def tsplit(lk,u,v,w):
        m1 = esplit(lk,u,v)
        m2 = esplit(lk,v,w)
        m3 = esplit(lk,w,u)
        return (m1,m3,u),(m2,m1,v),(m3,m2,w),(m1,m2,m3)
    def split(itris):
        otris = []
        nwpts = {}
        for t in itris:otris.extend(tsplit(nwpts,*t))
        return otris
    for nx in range(n):triangles = split(triangles)
    for p in pts:p.normalize().scale_u(r)

    polygons = tuple((tuple(pts[x].copy() for x in t),()) for t in triangles)
    plc.add_polygons(*polygons)

    #dprf.profile_function(plc.triangulate)
    #plc.simplices = [(pts[u],pts[v],pts[w]) for u,v,w in triangles]
    #plc.ghostbnds = []
    #ax = plc.plot()
    #plt.show()
    return plc
Esempio n. 19
0
def icosphere(r=1, n=1):
    import dilap.mesh.piecewisecomplex as pwc
    plc = pwc.piecewise_linear_complex()

    # create 12 vertices of a icosahedron
    t = (1.0 + math.sqrt(5.0)) / 2.0
    pts = []
    pts.append(dpv.vector(-1, t, 0))
    pts.append(dpv.vector(1, t, 0))
    pts.append(dpv.vector(-1, -t, 0))
    pts.append(dpv.vector(1, -t, 0))
    pts.append(dpv.vector(0, -1, t))
    pts.append(dpv.vector(0, 1, t))
    pts.append(dpv.vector(0, -1, -t))
    pts.append(dpv.vector(0, 1, -t))
    pts.append(dpv.vector(t, 0, -1))
    pts.append(dpv.vector(t, 0, 1))
    pts.append(dpv.vector(-t, 0, -1))
    pts.append(dpv.vector(-t, 0, 1))
    dpv.translate_coords(pts, dpv.center_of_mass(pts).flip())

    triangles = []
    # 5 faces around point 0
    triangles.append((0, 11, 5))
    triangles.append((0, 5, 1))
    triangles.append((0, 1, 7))
    triangles.append((0, 7, 10))
    triangles.append((0, 10, 11))
    # 5 adjacent faces
    triangles.append((1, 5, 9))
    triangles.append((5, 11, 4))
    triangles.append((11, 10, 2))
    triangles.append((10, 7, 6))
    triangles.append((7, 1, 8))
    # 5 faces around point 3
    triangles.append((3, 9, 4))
    triangles.append((3, 4, 2))
    triangles.append((3, 2, 6))
    triangles.append((3, 6, 8))
    triangles.append((3, 8, 9))
    # 5 adjacent faces
    triangles.append((4, 9, 5))
    triangles.append((2, 4, 11))
    triangles.append((6, 2, 10))
    triangles.append((8, 6, 7))
    triangles.append((9, 8, 1))

    def esplit(lk, u, v):
        k = (u, v)
        if not k in lk:
            pts.append(dpv.midpoint(pts[u], pts[v]))
            lk[k] = len(pts) - 1
        return lk[k]

    def tsplit(lk, u, v, w):
        m1 = esplit(lk, u, v)
        m2 = esplit(lk, v, w)
        m3 = esplit(lk, w, u)
        return (m1, m3, u), (m2, m1, v), (m3, m2, w), (m1, m2, m3)

    def split(itris):
        otris = []
        nwpts = {}
        for t in itris:
            otris.extend(tsplit(nwpts, *t))
        return otris

    for nx in range(n):
        triangles = split(triangles)
    for p in pts:
        p.normalize().scale_u(r)

    polygons = tuple((tuple(pts[x].copy() for x in t), ()) for t in triangles)
    plc.add_polygons(*polygons)

    #dprf.profile_function(plc.triangulate)
    #plc.simplices = [(pts[u],pts[v],pts[w]) for u,v,w in triangles]
    #plc.ghostbnds = []
    #ax = plc.plot()
    #plt.show()
    return plc