Exemplo n.º 1
0
def process_node(vtknode, node):
    num_children = input.GetNumberOfChildren(vtknode)
    if num_children > 0:
        node["children"] = []
    for c in range(num_children):
        vtkchild = input.GetChild(vtknode, c)
        v = vtkrow_to_dict(input.GetVertexData(), vtkchild)
        edge = vtk.vtkGraphEdge()
        input.GetInEdge(vtkchild, 0, edge)
        vtkparentedge = edge.GetId()
        e = vtkrow_to_dict(input.GetEdgeData(), vtkparentedge)
        n = {"edge_data": e, "node_data": v}
        process_node(vtkchild, n)
        node["children"].append(n)
Exemplo n.º 2
0
from romanesco.plugins.vtk import vtkrow_to_dict

output = {"fields": [], "rows": []}
for c in range(input.GetNumberOfColumns()):
    output["fields"].append(input.GetColumnName(c))
for r in range(input.GetNumberOfRows()):
    output["rows"].append(vtkrow_to_dict(input.GetRowData(), r))
Exemplo n.º 3
0
import vtk
import networkx as nx
from romanesco.plugins.vtk import vtkrow_to_dict

directed = isinstance(input, vtk.vtkMutableDirectedGraph)
output = nx.DiGraph() if directed else nx.Graph()

# Add nodes
for node in range(input.GetNumberOfVertices()):
    output.add_node(node, vtkrow_to_dict(input.GetVertexData(), node))

# Add edges
for edge in range(input.GetNumberOfEdges()):
    output.add_edge(input.GetSourceVertex(edge),
                    input.GetTargetVertex(edge),
                    attr_dict=vtkrow_to_dict(input.GetEdgeData(), edge))
Exemplo n.º 4
0
        node["children"] = []
    for c in range(num_children):
        vtkchild = input.GetChild(vtknode, c)
        v = vtkrow_to_dict(input.GetVertexData(), vtkchild)
        edge = vtk.vtkGraphEdge()
        input.GetInEdge(vtkchild, 0, edge)
        vtkparentedge = edge.GetId()
        e = vtkrow_to_dict(input.GetEdgeData(), vtkparentedge)
        n = {"edge_data": e, "node_data": v}
        process_node(vtkchild, n)
        node["children"].append(n)


node_fields = []
for c in range(input.GetVertexData().GetNumberOfArrays()):
    node_fields.append(input.GetVertexData().GetAbstractArray(c).GetName())

edge_fields = []
for c in range(input.GetEdgeData().GetNumberOfArrays()):
    edge_fields.append(input.GetEdgeData().GetAbstractArray(c).GetName())

vtkroot = input.GetRoot()

output = {
    "node_fields": node_fields,
    "edge_fields": edge_fields,
    "node_data": vtkrow_to_dict(input.GetVertexData(), vtkroot)
}

process_node(vtkroot, output)