Ejemplo n.º 1
0
def add(a, b):
    # testing error report
    f = 12 / 0
    return a + b


@hops.component(
    "/pointat",
    name="PointAt",
    nickname="PtAt",
    description="Get point along curve",
    category="Curve",
    subcategory="Analysis",
    icon="examples/pointat.png",
    inputs=[
        hs.HopsCurve("Curve", "C", "Curve to evaluate"),
        hs.HopsNumber("t", "t", "Parameter on Curve to evaluate"),
    ],
    outputs=[
        hs.HopsPoint(
            "P",
            "P",
            "Point on curve at t",
        )
    ],
)
def pointat(curve, t):
    return curve.PointAt(t)


@hops.component(
Ejemplo n.º 2
0
def init_graph(edges: [Curve], edges_types: [str]):
    G = nx.Graph()
    for e, etype in zip(edges, edges_types):
        G.add_edge(p3d_to_tuple(e.From), p3d_to_tuple(e.To), type=etype, length=e.Length)
    return G


def extract_types(G):
    return list(nx.get_edge_attributes(G, 'type').values())


@hops.component(
    "/lines_14",
    name="Lines",
    inputs=[
        hs.HopsCurve("Edges", "E", access=hs.HopsParamAccess.LIST),
        hs.HopsString("EdgesTypes", "ET", access=hs.HopsParamAccess.LIST),
        hs.HopsPoint("AgentsCoordinates", "AC", access=hs.HopsParamAccess.LIST),
        hs.HopsString("AgentsTypes", "AT", access=hs.HopsParamAccess.LIST),
        hs.HopsNumber("Updater", "u"),
    ],
    outputs=[
        hs.HopsString("NewTypes", "NT", access=hs.HopsParamAccess.LIST)
    ]
)
def lines(edges: [Curve], edges_types: [str],
          agents_coordinates: [Point3d], agents_types: [str],
          _):
    G = init_graph(edges, edges_types)
    EdgeType.set_weight(G)
    city_graph = CityGraph(G, geo_graph=False)
Ejemplo n.º 3
0

#MST COMPONENT ---------------------
@hops.component(
    "/mst",
    name = "mst",
    inputs=[
        hs.HopsMesh("Input Mesh", "M", "Mesh"),
        hs.HopsNumber("Weigth", "W", "Weight per face", hs.HopsParamAccess.LIST)

    ],
    outputs=[
        #hs.HopsPoint("list of points","P","shortest path points", hs.HopsParamAccess.LIST),
        #hs.HopsInteger("list of faces indexes","F","shortest path face indexes", hs.HopsParamAccess.LIST),
        hs.HopsString("list of faces indexes","F","shortest path face indexes", hs.HopsParamAccess.LIST),
        hs.HopsCurve("lines", "L", "MST Lines", hs.HopsParamAccess.LIST)
    ]
)
def mst( mesh, weights):


    mstGraph = mp.graphFromMesh(mesh) #convert the mesh to a nx graph
    
    #plot = mu.plotGraphSave(mstGraph)
    
    #if no weights define, assign random weights
    if weights == None:
        mu.addRandomWeights(mstGraph,3,10)
    else:
        mu.addWeights(mstGraph, weights)
Ejemplo n.º 4
0
Archivo: app.py Proyecto: deKlerk/Hops
# register hops app as middleware
app = Flask(__name__)
hops: hs.HopsFlask = hs.Hops(app)

# flask app can be used for other stuff drectly
@app.route("/help")
def help():
    return "Welcome to Grashopper Hops for CPython!"

#-- Point At component --#
@hops.component(
    "/pointat",
    name="PointAt",
    description="Get a point along a curve",
    inputs=[
        hs.HopsCurve("Curve", "C", "Curve to evaluate"),
        hs.HopsNumber("t", "t", "Parameter on Curve to evaluate.")
    ],
    outputs=[
        hs.HopsPoint("P", "P", "Point on Curve at parameter t")
    ]
)
def pointat(curve: rh.Curve, t: float=0):
    pt = curve.PointAt(t)
    return pt


#-- Profile Levels component --#
@hops.component(
    "/plevels",
    name="ProfileLevels",