Take the vertices and edge list in the graph parameter and return a VTK graph.
(graph)
| 209 | return graph |
| 210 | |
| 211 | def GenerateVTKGraph(graph): |
| 212 | ''' |
| 213 | Take the vertices and edge list in the graph parameter |
| 214 | and return a VTK graph. |
| 215 | ''' |
| 216 | g = vtkMutableDirectedGraph() |
| 217 | # Label the vertices |
| 218 | labels = vtkStringArray() |
| 219 | labels.SetNumberOfComponents(1) |
| 220 | labels.SetName("Labels") |
| 221 | |
| 222 | index = dict() |
| 223 | l = list(graph[0]) |
| 224 | # Make the vertex labels and create a dictionary with the |
| 225 | # keys as labels and the vertex ids as the values. |
| 226 | for i in range(0, len(l)): |
| 227 | # Set the vertex labels |
| 228 | labels.InsertNextValue(l[i]) |
| 229 | index[l[i]] = g.AddVertex() |
| 230 | g.GetVertexData().AddArray(labels) |
| 231 | # Add edges |
| 232 | l = list(graph[1]) |
| 233 | for i in range(0, len(l)): |
| 234 | ll = list(l[i]) |
| 235 | g.AddGraphEdge(index[ll[0]], index[ll[1]]) |
| 236 | # g.Dump() |
| 237 | return g |
| 238 | |
| 239 | def DisplayGraph(graph): |
| 240 | ''' |
no test coverage detected