在VTK中创建图形

问题描述 投票:0回答:1

我想使用VTK类https://lorensen.github.io/VTKExamples/site/Python/Graphs/ConstructGraph/创建图形

def main():
    g = vtk.vtkMutableUndirectedGraph()

    v1 = g.AddVertex()
    v2 = g.AddVertex()

    g.AddEdge ( v1, v2 )
    print ('Number of vertices:', g.GetNumberOfVertices())
    print ("Number of edges:", g.GetNumberOfEdges())

    g.AddEdge ( v1, v2 )
    print ('Number of vertices:', g.GetNumberOfVertices())
    print ('Number of edges:', g.GetNumberOfEdges())
    graphLayoutView = vtk.vtkGraphLayoutView()
    graphLayoutView.AddRepresentationFromInput(g)
    graphLayoutView.ResetCamera()
    graphLayoutView.Render()
    graphLayoutView.GetInteractor().Start()

是已定义的功能。但我不太确定该如何使用。

例如,在networkx中我会这样做

t = [0, 2, 4, 5, 6, 8, 9, 11, 13, 1, 10, 1, 3, 7]
h= [1, 3, 3, 1, 7, 7, 10, 12, 12, 14, 14, 12, 14, 10]
ed_ls = [(x, y) for x, y in zip(tail, head)]
G = nx.OrderedGraph()
G.add_edges_from(ed_ls)
nx.draw(G)

有关如何在VTK中创建相同图形的建议会有所帮助

python-3.x networkx vtk
1个回答
1
投票

您已经找到正确的API。只需使用它。有点像

g = vtk.vtkMutableUndirectedGraph()

# add your 15 vertices
for i in range(15):
    g.AddVertex()

t = [0, 2, 4, 5, 6, 8, 9, 11, 13, 1, 10, 1, 3, 7]
h= [1, 3, 3, 1, 7, 7, 10, 12, 12, 14, 14, 12, 14, 10]

for start, end in zip(t,h):
    g.AddEdge( start, end )
© www.soinside.com 2019 - 2024. All rights reserved.