Пример #1
0
def open_file(settings):
    if not settings["file.dir"]:
        filepath = compas_rhino.select_file(folder=HERE, filter="fofin")
    else:
        filepath = compas_rhino.select_file(folder=settings["file.dir"], filter="fofin")

    if not filepath:
        return

    file_dir = os.path.dirname(filepath)
    file_name = os.path.basename(filepath)

    settings["file.dir"] = file_dir
    settings["file.name"] = file_name

    if not file_name.endswith(".fofin"):
        print("The filename is invalid: {}".format(file_name))
        return

    filepath = os.path.join(file_dir, file_name)

    with open(filepath, "r") as f:
        data = json.load(f)

        if "settings" in data and data["settings"]:
            settings.update(data["settings"])

        if "cablenet" in data and data["cablenet"]:
            cablenet = Cablenet.from_data(data["cablenet"])
            cablenet.draw(layer=settings["layer"], clear_layer=True, settings=settings)
        else:
            cablenet = None

    return cablenet
Пример #2
0
def create_cablenet_from_lines(settings):
    guids = compas_rhino.select_lines()
    if not guids:
        return
    lines = compas_rhino.get_line_coordinates(guids)
    cablenet = Cablenet.from_lines(lines)
    return cablenet
Пример #3
0
def create_cablenet_from_json(settings):
    folder = settings["file.dir"] or HERE
    filepath = compas_rhino.select_file(folder=folder, filter="json")
    if not filepath:
        return
    cablenet = Cablenet.from_json(filepath)
    return cablenet
Пример #4
0
def cablenet_fd_rpc(data, **kwargs):
    """Convenience wrapper for ``cablenet_fd_numpy`` that can be used with ``RPC``.

    Parameters
    ----------
    data : dict
        The data dictionary representing a cablenet data structure.

    Returns
    -------
    dict
        A data dict with the same structure as the input dict.

    Notes
    -----
    For additional named parameters that can be passed to this function,
    see ``cablenet_fd_numpy``.

    Examples
    --------
    .. code-block:: python

        proxy = Proxy('compas_fofin.equilibrium')

        result = proxy.cablenet_fd_rpc(cablenet.to_data())
        cablenet.data = result

    """
    from compas_fofin.datastructures import Cablenet
    cablenet = Cablenet.from_data(data)
    cablenet_fd_numpy(cablenet)
    return cablenet.to_data()
Пример #5
0
def RunCommand(is_interactive):
    if "FoFin" not in sc.sticky:
        raise Exception("Initialise the plugin first!")

    settings = sc.sticky["FoFin"]['settings']

    filepath = compas_rhino.browse_for_file()
    if not filepath:
        return

    if not filepath.endswith('.json'):
        return

    cablenet = Cablenet.from_json(filepath)

    sc.sticky["FoFin"]["cablenet"] = cablenet

    artist = CablenetArtist(cablenet, layer=settings['layer'])
    artist.clear_layer()
    artist.draw_mesh()
    artist.draw_vertices()
    artist.draw_edges()
    artist.redraw()
Пример #6
0
from compas_fofin.datastructures import Cablenet
from compas_fofin.analysis import mesh_materialize_cables

from compas_plotters import MeshPlotter

# ==============================================================================
# Create a cablenet
# ==============================================================================

HERE = os.path.dirname(__file__)
FILE_I = os.path.join(HERE, 'hypar.json')
FILE_O = os.path.join(HERE, 'hypar_materialized.json')
FILE_P = os.path.join(HERE, 'hypar_materialized.png')

cablenet = Cablenet.from_json(FILE_I)

# ==============================================================================
# Materialize
# ==============================================================================

mesh_materialize_cables(cablenet)

# ==============================================================================
# Visualize
# ==============================================================================

edges = list(cablenet.edges_where({'is_edge': True}))

stress = [cablenet.stress(key) for key in edges]
cmap = Colormap(stress, 'rgb')
Пример #7
0
import os
from compas_fofin.datastructures import Cablenet
from compas_fofin.rhino import CablenetArtist
from compas_fofin.equilibrium import cablenet_fd_alglib

HERE = os.path.dirname(__file__)
DATA = os.path.join(HERE, '..', '..', 'data')
FILE = os.path.join(DATA, 'saddle.obj')

cablenet = Cablenet.from_obj(FILE)
cablenet.set_vertices_attribute('is_anchor',
                                True,
                                keys=cablenet.vertices_where(
                                    {'vertex_degree': 1}))

cablenet_fd_alglib(cablenet)

artist = CablenetArtist(cablenet, layer="FoFin::Cablenet")
artist.clear_layer()
artist.draw_vertices()
artist.draw_edges()
artist.draw_forces(scale=0.05)
artist.draw_loads()
artist.draw_reactions()
artist.redraw()
Пример #8
0
def update_xyz_proxy(data, *args, **kwargs):
    from compas_fofin.datastructures import Cablenet
    net = Cablenet.from_data(data)
    update_xyz_numpy(net, *args, **kwargs)
    return net.to_data()
Пример #9
0
def apply_loads_proxy(data, *args, **kwargs):
    from compas_fofin.datastructures import Cablenet
    cablenet = Cablenet.from_data(data)
    apply_loads_numpy(cablenet, *args, **kwargs)
    return cablenet.to_data()
Пример #10
0
# ==============================================================================
# Make a cablenet
# ==============================================================================

# FILE = compas.get('quadmesh.obj')
# cablenet = Cablenet.from_obj(FILE)

HERE = os.path.dirname(__file__)
FILE_I = os.path.join(HERE, 'lines.obj')
FILE_O = os.path.join(HERE, 'lines.json')

obj = OBJ(FILE_I)
lines = [[obj.vertices[u], obj.vertices[v]] for u, v in obj.lines]

cablenet = Cablenet.from_lines(lines, delete_boundary_face=True)

cablenet.edges_attribute('is_edge',
                         False,
                         keys=list(cablenet.edges_on_boundary()))

# ==============================================================================
# Select a starting edge
# ==============================================================================

start = random.choice(
    list(set(cablenet.edges()) - set(cablenet.edges_on_boundary())))

# ==============================================================================
# Continuous edges and parallel edges
# ==============================================================================
Пример #11
0
def create_cablenet_from_surface(settings):
    guid = compas_rhino.select_surface()
    if not guid:
        return
    cablenet = Cablenet.from_rhinosurface(guid)
    return cablenet
Пример #12
0
def create_cablenet_from_mesh(settings):
    guid = compas_rhino.select_mesh()
    if not guid:
        return
    cablenet = Cablenet.from_rhinomesh(guid)
    return cablenet
from compas_fofin.rhino import CablenetArtist
from compas_fofin.rhino import CablenetHelper


def draw():
    artist.clear_layer()
    artist.draw_vertices(color={
        key: (255, 0, 0)
        for key in cablenet.vertices_where({'is_anchor': True})
    })
    artist.draw_edges()
    artist.redraw()


cablenet = Cablenet.from_obj(compas.get('faces.obj'))

for key, attr in cablenet.vertices(True):
    attr['is_anchor'] = cablenet.vertex_degree(key) == 2

artist = CablenetArtist(cablenet, layer="Mesh::FD")

draw()

while True:
    selected = CablenetHelper.select_vertices(cablenet)
    if not selected:
        break

    if CablenetHelper.update_vertex_attributes(cablenet, selected):
        cablenet_fd(cablenet)
Пример #14
0
import os
import sys
from compas_fofin.datastructures import Cablenet
from compas_rhino.artists import MeshArtist
from compas.datastructures import Mesh
from compas.geometry import add_vectors
from compas.geometry import scale_vector
from compas.datastructures import mesh_flip_cycles
import compas.geometry as cg 


HERE = os.path.dirname(__file__)

FILE_I = os.path.join(HERE, 'data', 'cablenet.json')
FILE_O = os.path.join(HERE, 'data', 'blocks.json')
cablenet = Cablenet.from_json(FILE_I)
mesh_flip_cycles(cablenet)

# ==============================================================================
# Parameters
# ==============================================================================

OFFSET = 0.0500

# ==============================================================================
# Make block
# ==============================================================================
blocks = []


all_vertices = []