How to use the compas.datastructures.Network.from_obj function in compas

To help you get started, we’ve selected a few compas examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github compas-dev / compas / src / compas_rhino / modifiers / facemodifier.py View on Github external
"""
    return FaceModifier.update_vertex_attributes(mesh, fkeys, names=names)

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


if __name__ == "__main__":

    import compas

    from compas.datastructures import Network
    from compas_rhino.artists.networkartist import NetworkArtist

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

    artist = NetworkArtist(network)

    artist.clear()
    artist.draw_vertices()
    artist.draw_edges()
    artist.redraw()

    if FaceModifier.move_face(network, 0):
        artist.clear()
        artist.draw_vertices()
        artist.draw_edges()
        artist.redraw()
github compas-dev / compas / docs / reference / generated / compas-datastructures-network_embed_in_plane-1.py View on Github external
import compas

from compas.datastructures import Network
from compas.datastructures import network_embed_in_plane
from compas.visualization import NetworkPlotter

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

embedding = network.copy()

fix = (1, 12)

if network_embed_in_plane(embedding, fix=fix):

    plotter = NetworkPlotter(embedding)

    plotter.draw_xlines([{'start': network.vertex_coordinates(u, 'xy'),
                          'end': network.vertex_coordinates(v, 'xy'),
                          'color': '#cccccc'} for u, v in network.edges()])

    plotter.draw_vertices(radius=0.3,
                          text={key: key for key in embedding.vertices()},
                          facecolor={key: '#ff0000' for key in fix})
github compas-dev / compas / src / compas / numerical / algorithms / _fd_cpp / fd_cpp_check_rhino_interactive.py View on Github external
from Rhino.Geometry import Point3d
from Rhino.Geometry import Line

import compas
import compas_rhino

from compas.datastructures import Network
from compas.numerical import fd_cpp

from compas_rhino.helpers import NetworkArtist
from compas_rhino.helpers.selectors import VertexSelector
from compas_rhino.conduits import LinesConduit


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


vertices = network.get_vertices_attributes('xyz')
loads    = network.get_vertices_attributes(('px', 'py', 'pz'), (0.0, 0.0, 0.0))
fixed    = network.leaves()
free     = [i for i in range(len(vertices)) if i not in fixed]
edges    = list(network.edges())
q        = network.get_edges_attribute('q', 1.0)


artist = NetworkArtist(network, layer='Network')

artist.clear_layer()
artist.draw_edges(color='#cccccc')
artist.redraw()
github compas-dev / compas / src / compas_rhino / artists / networkartist.py View on Github external
other elements in the layer."""
        self.clear_vertices()
        self.clear_edges()


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

if __name__ == "__main__":

    import compas
    from compas.datastructures import Network
    from compas_rhino.artists.networkartist import NetworkArtist

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

    artist = NetworkArtist(network, layer='NetworkArtist')

    artist.clear_layer()

    artist.draw_vertices()
    artist.redraw(0.0)

    artist.draw_vertexlabels()
    artist.redraw(1.0)

    artist.draw_edges()
    artist.redraw(1.0)

    artist.draw_edgelabels()
    artist.redraw(1.0)
github compas-dev / compas / examples / network-equilibrium.py View on Github external
from compas.datastructures import Network
from compas.visualization.viewers.networkviewer import NetworkViewer

from compas.numerical import fd


__author__    = ['Tom Van Mele', ]
__copyright__ = 'Copyright 2017, BRG - ETH Zurich',
__license__   = 'MIT'
__email__     = 'van.mele@arch.ethz.ch'


# make a network from sample data

network = Network.from_obj(compas.get_data('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
github compas-dev / compas / src / compas_rhino / helpers / network.py View on Github external
* :func:`network_update_vertex_attributes`

    """
    return EdgeModifier.update_edge_attributes(network, keys, names=names)


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

if __name__ == "__main__":

    import compas
    from compas.datastructures import Network

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

    network_draw(network, layer='test', clear_layer=True)

    key = network_select_vertex(network)

    if network_move_vertex(network, key):
        network_draw(network, layer='test', clear_layer=True)
github compas-dev / compas / src / compas / plotters / networkplotter.py View on Github external
segments.append([self.datastructure.vertex_coordinates(u, 'xy'), self.datastructure.vertex_coordinates(v, 'xy')])
        self.edgecollection.set_segments(segments)


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

if __name__ == "__main__":

    import compas

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

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

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

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

    default = [plotter.defaults['vertex.facecolour'] for key in network.vertices()]
    highlight = '#ff0000'

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

        colours = default[:]
        colours[index] = highlight

        plotter.vertexcollection.set_facecolour(colours)
github compas-dev / compas / docs / reference / generated / compas-datastructures-network_dijkstra_path-1.py View on Github external
import compas

from compas.datastructures import Network
from compas.datastructures import network_dijkstra_path
from compas.visualization import NetworkPlotter

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

weight = dict(((u, v), network.edge_length(u, v)) for u, v in network.edges())
weight.update({(v, u): weight[(u, v)] for u, v in network.edges()})

start = 21
end = 22

path = network_dijkstra_path(network.adjacency, weight, start, end)

edges = []
for i in range(len(path) - 1):
    u = path[i]
    v = path[i + 1]
    if v not in network.edge[u]:
        u, v = v, u
    edges.append([u, v])