Esempio n. 1
0
def find(generic_laminate):
    generic = generic_laminate.geoms
    layerdef = generic_laminate.layerdef
    from popupcad.filetypes.laminate import Laminate

    layer_dict = dict([(geom.id, layer) for layer, geoms in generic.items()
                       for geom in geoms])
    geom_dict = dict([(geom.id, geom) for layer, geoms in generic.items()
                      for geom in geoms])
    geom_dict_whole = geom_dict.copy()

    laminates = []
    values = []
    while len(geom_dict) > 0:
        laminate = Laminate(layerdef)
        key = list(geom_dict.keys())[0]
        gs = findallconnectedneighborgeoms(key, generic_laminate, geom_dict,
                                           layerdef)
        geom_mins = numpy.array(
            [find_minimum_xy(geom_dict_whole[geom_id]) for geom_id in gs])
        values.append(tuple(geom_mins.min(0)))
        for item_id in gs:
            geom = geom_dict_whole[item_id]
            if geom.is_valid_bool():
                laminate.insertlayergeoms(layer_dict[item_id],
                                          [geom.to_shapely()])
        laminates.append(laminate)
    laminates = sort_lams(laminates, values)
    return laminates
Esempio n. 2
0
def find(generic_laminate):
    generic = generic_laminate.geoms
    layerdef = generic_laminate.layerdef
    from popupcad.filetypes.laminate import Laminate

    layer_dict = dict([(geom.id, layer) for layer, geoms in generic.items() for geom in geoms])
    geom_dict = dict([(geom.id, geom) for layer, geoms in generic.items() for geom in geoms])
    geom_dict_whole = geom_dict.copy()

    laminates = []
    values = []
    while len(geom_dict) > 0:
        laminate = Laminate(layerdef)
        key = list(geom_dict.keys())[0]
        gs = findallconnectedneighborgeoms(key,generic_laminate,geom_dict,layerdef)
        geom_mins = numpy.array(
            [find_minimum_xy(geom_dict_whole[geom_id]) for geom_id in gs])
        values.append(tuple(geom_mins.min(0)))
        for item_id in gs:
            geom = geom_dict_whole[item_id]
            if geom.is_valid_bool():
                laminate.insertlayergeoms(layer_dict[item_id], [geom.to_shapely()])
        laminates.append(laminate)
    laminates = sort_lams(laminates, values)
    return laminates
Esempio n. 3
0
 def operate(self, design):
     layerdef = design.return_layer_definition()
     csg = Laminate(layerdef)
     for layer in layerdef.layers:
         shapelygeoms = [geom.to_shapely() for geom in self.generic.geoms[layer] if geom.is_valid_bool()]
         csg.insertlayergeoms(layer, shapelygeoms)
     return csg
Esempio n. 4
0
    def generate(self,design):
        import popupcad_manufacturing_plugins.algorithms.bodydetection as bodydetection
        
        generic = design.op_from_ref(self.operation_link1).output[self.getoutputref()].generic_geometry_2d()
        layerdef = design.return_layer_definition()

        layer_dict = dict([(geom.id,layer) for layer,geoms in generic.items() for geom in geoms])
        geom_dict = dict([(geom.id,geom) for layer,geoms in generic.items() for geom in geoms])
        geom_dict_whole = geom_dict.copy()
        
        laminates = []
        values = []
        layerdef = design.return_layer_definition()
        while len(geom_dict)>0:
            laminate = Laminate(layerdef)
            key = list(geom_dict.keys())[0]
            gs = bodydetection.findallconnectedneighborgeoms(key,generic,geom_dict,layerdef)
            geom_mins = numpy.array([find_minimum_xy(geom_dict_whole[geom_id]) for geom_id in gs])
            values.append(tuple(geom_mins.min(0)))
            for item_id in gs:
                geom = geom_dict_whole[item_id]
                laminate.insertlayergeoms(layer_dict[item_id], [geom.outputshapely()])
            laminates.append(laminate)
            
        laminates = sort_lams(laminates,values)
        
        self.output = []
        for ii,item in enumerate(laminates):
            self.output.append(OperationOutput(item,'Body {0:d}'.format(ii),self))
        self.output.insert(0,self.output[0])
Esempio n. 5
0
 def operate(self, design):
     layerdef = design.return_layer_definition()
     csg = Laminate(layerdef)
     for layer in layerdef.layers:
         shapelygeoms = [
             geom.to_shapely(scaling=popupcad.csg_processing_scaling)
             for geom in self.generic.geoms[layer] if geom.is_valid_bool()
         ]
         csg.insertlayergeoms(layer, shapelygeoms)
     return csg
Esempio n. 6
0
    def generate(self,design):
        from popupcad.materials.materials import Rigid

        generic = design.op_from_ref(self.operation_link1).output[self.getoutputref()].generic_geometry_2d()
        
        layerdef = design.return_layer_definition()

        layer_dict = dict([(geom.id,layer) for layer,geoms in generic.items() for geom in geoms])
        geom_dict = dict([(geom.id,geom) for layer,geoms in generic.items() for geom in geoms])
#        csg_dict = dict([(geom.id,geom.outputshapely()) for layer,geoms in generic.items() for geom in geoms])

        layerdef = design.return_layer_definition()
        rigid_geoms = []    
        
        connections = []
        source_geoms= [{'id':None,'csg':sg.Polygon()}]
        for layer in layerdef.layers:
            if isinstance(layer,Rigid):
                rigid_geoms.extend(generic[layer])
                while not not source_geoms: 
                    source_geom = source_geoms.pop()
                    new_geoms = [dict([('csg',geom.outputshapely()),('id',geom.id)]) for geom in generic[layer]]
                    for new_geom in new_geoms:
                        connection = source_geom['csg'].intersection(new_geom['csg'])
                        if not (connection.is_empty):
                            connections.append((source_geom['id'],new_geom['id']))
                source_geoms = new_geoms
            else: 
                new_source_geoms = []
                while not not source_geoms: 
                    source_geom = source_geoms.pop()
                    layer_geoms = [geom.outputshapely() for geom in generic[layer]]
                    for layer_geom in layer_geoms:
                        new_geom = source_geom['csg'].intersection(layer_geom)
                        if not (new_geom.is_empty):
                            new_source_geoms.append({'id':source_geom['id'],'csg':new_geom})                        
                source_geoms = new_source_geoms
        
#        print(connections)
        
        ids = [geom.id for geom in rigid_geoms]
        m = len(ids)
        C = numpy.zeros((m,m),dtype = bool)
        for id1,id2 in connections:
            ii = ids.index(id1)
            jj = ids.index(id2)
            C[ii,jj]=True
            C[jj,ii]=True

        done = False
        D_last = C.copy()

        while not done:
            D = D_last.dot(C)+C
            done = (D==D_last).all()
            D_last = D
#        print(D)

        rigid_bodies = []
        rigid_geoms_set = set(rigid_geoms[:])
        while not not rigid_geoms_set:
            geom = list(rigid_geoms_set)[0]
            ii = ids.index(geom.id)
            a = list(set((D[ii,:]==True).nonzero()[0].tolist()+[ii]))
            b = set(numpy.array(rigid_geoms)[a])    
            rigid_geoms_set-=b
            rigid_bodies.append(list(b))
        
#        print(rigid_bodies)

        values = [tuple((numpy.array([find_minimum_xy(geom) for geom in body])).min(0)) for body in rigid_bodies]
        rigid_bodies = sort_lams(rigid_bodies,values)

        new_csgs = []
        for rigid_body in rigid_bodies:
            new_csg = Laminate(layerdef)
            for geom in rigid_body:
                new_csg.insertlayergeoms(layer_dict[geom.id],[geom.outputshapely()])
            new_csgs.append(new_csg)
        
        self.output = []
        for ii,item in enumerate(new_csgs):
            self.output.append(OperationOutput(item,'Rigid Body {0:d}'.format(ii),self))
        self.output.insert(0,self.output[0])
        return Laminate(design.return_layer_definition())
def find_rigid(generic, layerdef):
    layer_dict = dict([(geom.id, layer) for layer, geoms in generic.geoms.items() for geom in geoms])
    rigid_geoms = []
    connections = []
    source_geoms = [{"id": None, "csg": sg.Polygon()}]
    for layer in layerdef.layers:
        if layer.is_rigid:
            rigid_geoms.extend(generic.geoms[layer])
            while not not source_geoms:
                source_geom = source_geoms.pop()
                new_geoms = [dict([("csg", geom.to_shapely()), ("id", geom.id)]) for geom in generic.geoms[layer]]
                for new_geom in new_geoms:
                    connection = source_geom["csg"].intersection(new_geom["csg"])
                    if not (connection.is_empty):
                        connections.append((source_geom["id"], new_geom["id"]))
            source_geoms = new_geoms
        else:
            new_source_geoms = []
            while not not source_geoms:
                source_geom = source_geoms.pop()
                layer_geoms = [geom.to_shapely() for geom in generic.geoms[layer]]
                for layer_geom in layer_geoms:
                    new_geom = source_geom["csg"].intersection(layer_geom)
                    if not (new_geom.is_empty):
                        new_source_geoms.append({"id": source_geom["id"], "csg": new_geom})
            source_geoms = new_source_geoms

    ids = [geom.id for geom in rigid_geoms]
    m = len(ids)
    C = numpy.zeros((m, m), dtype=bool)
    for id1, id2 in connections:
        ii = ids.index(id1)
        jj = ids.index(id2)
        C[ii, jj] = True
        C[jj, ii] = True

    done = False
    D_last = C.copy()

    while not done:
        D = D_last.dot(C) + C
        done = (D == D_last).all()
        D_last = D

    rigid_bodies = []
    rigid_geoms_set = set(rigid_geoms[:])
    while not not rigid_geoms_set:
        geom = list(rigid_geoms_set)[0]
        ii = ids.index(geom.id)
        a = list(set((D[ii, :] == True).nonzero()[0].tolist() + [ii]))
        b = set(numpy.array(rigid_geoms)[a])
        rigid_geoms_set -= b
        rigid_bodies.append(list(b))

    values = [
        tuple((numpy.array([popupcad.algorithms.body_detection.find_minimum_xy(geom) for geom in body])).min(0))
        for body in rigid_bodies
    ]
    rigid_bodies = popupcad.algorithms.body_detection.sort_lams(rigid_bodies, values)

    new_csgs = []
    for rigid_body in rigid_bodies:
        new_csg = Laminate(layerdef)
        for geom in rigid_body:
            new_csg.insertlayergeoms(layer_dict[geom.id], [geom.to_shapely()])
        new_csgs.append(new_csg)
    return new_csgs
def find_rigid(generic, layerdef):
    layer_dict = dict([(geom.id, layer)
                       for layer, geoms in generic.geoms.items()
                       for geom in geoms])
    rigid_geoms = []
    connections = []
    source_geoms = [{'id': None, 'csg': sg.Polygon()}]
    for layer in layerdef.layers:
        if layer.is_rigid:
            rigid_geoms.extend(generic.geoms[layer])
            while not not source_geoms:
                source_geom = source_geoms.pop()
                new_geoms = [
                    dict([('csg', geom.to_shapely()), ('id', geom.id)])
                    for geom in generic.geoms[layer]
                ]
                for new_geom in new_geoms:
                    connection = source_geom['csg'].intersection(
                        new_geom['csg'])
                    if not (connection.is_empty):
                        connections.append((source_geom['id'], new_geom['id']))
            source_geoms = new_geoms
        else:
            new_source_geoms = []
            while not not source_geoms:
                source_geom = source_geoms.pop()
                layer_geoms = [
                    geom.to_shapely() for geom in generic.geoms[layer]
                ]
                for layer_geom in layer_geoms:
                    new_geom = source_geom['csg'].intersection(layer_geom)
                    if not (new_geom.is_empty):
                        new_source_geoms.append({
                            'id': source_geom['id'],
                            'csg': new_geom
                        })
            source_geoms = new_source_geoms

    ids = [geom.id for geom in rigid_geoms]
    m = len(ids)
    C = numpy.zeros((m, m), dtype=bool)
    for id1, id2 in connections:
        ii = ids.index(id1)
        jj = ids.index(id2)
        C[ii, jj] = True
        C[jj, ii] = True

    done = False
    D_last = C.copy()

    while not done:
        D = D_last.dot(C) + C
        done = (D == D_last).all()
        D_last = D

    rigid_bodies = []
    rigid_geoms_set = set(rigid_geoms[:])
    while not not rigid_geoms_set:
        geom = list(rigid_geoms_set)[0]
        ii = ids.index(geom.id)
        a = list(set((D[ii, :] == True).nonzero()[0].tolist() + [ii]))
        b = set(numpy.array(rigid_geoms)[a])
        rigid_geoms_set -= b
        rigid_bodies.append(list(b))

    values = [
        tuple((numpy.array([
            popupcad.algorithms.body_detection.find_minimum_xy(geom)
            for geom in body
        ])).min(0)) for body in rigid_bodies
    ]
    rigid_bodies = popupcad.algorithms.body_detection.sort_lams(
        rigid_bodies, values)

    new_csgs = []
    for rigid_body in rigid_bodies:
        new_csg = Laminate(layerdef)
        for geom in rigid_body:
            new_csg.insertlayergeoms(layer_dict[geom.id], [geom.to_shapely()])
        new_csgs.append(new_csg)
    return new_csgs