示例#1
0
    #     self.draw_edges(
    #         color={(u, v): '#ff0000' for u, v in edges},
    #         width={(u, v): 5.0 for u, v in edges}
    #     )


# ==============================================================================
# Main
# ==============================================================================

if __name__ == "__main__":

    import compas
    from compas.datastructures import Network

    network = Network.from_obj(compas.get('grid_irregular.obj'))

    plotter = NetworkPlotter(network, figsize=(10, 8))

    plotter.draw_nodes(radius=0.1, picker=10)
    plotter.draw_edges()

    default = [plotter.defaults['node.facecolor'] for key in network.nodes()]
    highlight = '#ff0000'

    def on_pick(event):
        index = event.ind[0]

        colors = default[:]
        colors[index] = highlight
示例#2
0
    def __init__(self, data, dtype='f'):
        m = len(data)
        rows = range(m)
        super(SparseDiagonal, self).__init__((rows, rows, data), (m, m), dtype)


# ==============================================================================
# Main
# ==============================================================================

if __name__ == "__main__":

    import compas
    from compas.datastructures import Network

    network = Network.from_obj(compas.get('lines.obj'))

    e = network.number_of_edges()
    v = network.number_of_vertices()

    vertices = network.vertices_attributes('xyz')
    edges = list(network.edges())

    xyz = Array(vertices, (v, 3))

    shape = e, v

    rows, cols, data = [], [], []

    for i, (u, v) in enumerate(edges):
        rows.append(i)
# define a callback function
# for plotting the intermediate configurations of the DR process
def callback(k, xyz, crits, args):
    print(k)
    plotter.update_vertices()
    plotter.update_edges()
    plotter.update(pause=0.001)
    for key, attr in network.vertices(True):
        attr['x'] = xyz[key][0]
        attr['y'] = xyz[key][1]
        attr['z'] = xyz[key][2]


# make a network
network = Network.from_obj(FILE)

# identify the fixed vertices
network.set_vertices_attribute('is_fixed',
                               True,
                               keys=network.vertices_where(
                                   {'vertex_degree': 1}))

# assign random prescribed force densities to the edges
for uv in network.edges():
    network.set_edge_attribute(uv, 'qpre', 1.0 * random.randint(1, 7))

# make a plotter for (dynamic) visualization
plotter = NetworkPlotter(network, figsize=(10, 7))

# plot the starting configuration
import bpy
import compas
import compas_blender
from compas_blender.artists import NetworkArtist
from compas.datastructures import Network
from compas.numerical import fd_numpy

# make a network from sample data

network = Network.from_obj(compas.get('saddle.obj'))

# set default vertex and edge attributes

dva = {'is_anchor': False, 'px': 0.0, 'py': 0.0, 'pz': 0.0}
dea = {'q': 1.0}

network.update_default_vertex_attributes(dva)
network.update_default_edge_attributes(dea)

# identify *anchored* vertices

for key in network.vertices():
    network.vertex[key]['is_anchor'] = network.is_vertex_leaf(key)

# convert network data to numerical data

xyz = network.get_vertices_attributes(('x', 'y', 'z'))
loads = network.get_vertices_attributes(('px', 'py', 'pz'))
q = network.get_edges_attribute('q')

# use a key-index map to reference items in the numerical data
示例#5
0
文件: planarity.py 项目: tclim/compas
    return True


# ==============================================================================
# Main
# ==============================================================================

if __name__ == '__main__':

    import compas

    from compas.datastructures import Network
    from compas.plotters import NetworkPlotter

    network = Network.from_obj(compas.get('fink.obj'))

    crossings = network_find_crossings(network)

    print(network_count_crossings(network))
    print(crossings)
    print(len(crossings))

    ecolor = {}
    for e1, e2 in crossings:
        ecolor[e1] = '#ff0000'
        ecolor[e2] = '#ff0000'

    plotter = NetworkPlotter(network, figsize=(10, 7))

    plotter.draw_vertices()
示例#6
0
import compas

from compas.datastructures import Network
from compas_plotters import NetworkPlotter

structure = Network.from_obj(compas.get('lines.obj'))
structure.update_default_vertex_attributes({'is_fixed': False, 'P': [1, 1, 0]})
structure.update_default_edge_attributes({'E': 10, 'A': 1, 'ct': 't'})
structure.vertices_attributes(['is_fixed', 'B'], [True, [0, 0, 0]],
                              structure.leaves())

lines = []
for u, v in structure.edges():
    lines.append({
        'start': structure.vertex_coordinates(u, 'xy'),
        'end': structure.vertex_coordinates(v, 'xy'),
        'color': '#cccccc'
    })

plotter = NetworkPlotter(structure, figsize=(10, 7))
plotter.draw_vertices(facecolor={
    key: '#ff0000'
    for key in structure.vertices_where({'is_fixed': True})
})
plotter.draw_lines(lines)
plotter.draw_edges()


def callback(X, k_i):

    for key in structure.vertices():