Esempio n. 1
0
def graphFromMesh(mesh):

    g = nx.Graph()
    m = mesh

    #create a node per each of the faces of the mesh
    for i in range(m.Faces.Count):

        face_center = mu.getFaceCenter(m, m.Faces[i])

        #add a node to the graph per face
        g.add_node(i, point=face_center, face=i)

        #finding the neighbors of this face
        neighbors = mu.getAdjancentFaces(
            mesh, i)  #returns a list of face indexes which are neighbors

        for n in neighbors:
            if n > i:
                p1 = mu.getFaceCenter(m, m.Faces[i])
                p2 = mu.getFaceCenter(m, m.Faces[n])
                line = rg.Line(p1, p2)
                w = line.Length
                g.add_edge(i, n, weight=w, line=line)

    return g
Esempio n. 2
0
def DecodeToLine(item):
    if item is None:
        return None
    if isinstance(item, list):
        return [DecodeToLine(x) for x in item]
    start = DecodeToPoint3d(item['From'])
    end = DecodeToPoint3d(item['To'])
    return rhino3dm.Line(start, end)
Esempio n. 3
0
def getFaceCenterTri(mesh, meshFace):  #i think only for triangles
    faceVertex = []
    for i in range(len(meshFace)):
        p3f = mesh.Vertices[meshFace[i]]
        faceVertex.append(rg.Point3d(p3f.X, p3f.Y, p3f.Z))

    mid1 = rg.Point3d((faceVertex[0].X + faceVertex[1].X) / 2,
                      (faceVertex[0].Y + faceVertex[1].Y) / 2,
                      (faceVertex[0].Z + faceVertex[1].Z) / 2)
    mid2 = rg.Point3d((faceVertex[1].X + faceVertex[2].X) / 2,
                      (faceVertex[1].Y + faceVertex[2].Y) / 2,
                      (faceVertex[1].Z + faceVertex[2].Z) / 2)
    line1 = rg.Line(mid1, faceVertex[2])
    line2 = rg.Line(mid2, faceVertex[0])

    center_parameter = rg.Intersection.LineLine(line1, line2)[1]
    center = rg.Line.PointAt(line1, center_parameter)
    return center
Esempio n. 4
0
def graphFromMesh(mesh, weightMode="edgeLength"):

    # Create graph
    g = nx.Graph()
    a = mesh
    meshtype = mu.getMeshType(mesh)

    #Get the full graph
    for i in range(a.Faces.Count):

        if meshtype == "tri":
            face_center = mu.getFaceCenterTri(a, a.Faces[i])
        elif meshtype == "quad":
            face_center = mu.getFaceCenter(a, a.Faces[i])

        # Add node to graph and get its neighbours
        g.add_node(i, point=face_center, face=i)
        neighbours = mu.getAdjancentFaces(a, i)

        # Add edges to graph
        for n in neighbours:
            if n > i:
                p1 = face_center
                if meshtype == "tri":
                    p2 = mu.getFaceCenterTri(a, a.Faces[n])
                elif meshtype == "quad":
                    p2 = mu.getFaceCenter(a, a.Faces[n])

                line = rg.Line(p1, p2)
                if weightMode == "edgeLength":
                    w = line.Length
                elif weightMode == "sameWeight":
                    w = 1
                g.add_edge(i, n, weight=w, line=line)

    return g