File: dimacs.py

package info (click to toggle)
paraview 5.0.0%2Bdfsg1-2~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 225,112 kB
  • sloc: cpp: 2,432,495; ansic: 204,338; python: 97,967; xml: 79,887; tcl: 46,936; fortran: 26,923; yacc: 4,926; java: 4,413; perl: 3,108; sh: 2,775; lex: 1,934; f90: 748; asm: 471; pascal: 228; makefile: 192; objc: 17
file content (58 lines) | stat: -rwxr-xr-x 1,499 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python
"""
Just a demo script to test out the DIMACS reader/writer function
"""
from __future__ import print_function
import time
from vtk import *

# generate a random graph
source = vtkRandomGraphSource()
source.SetNumberOfVertices(100)
source.SetAllowSelfLoops(False)
source.SetEdgeProbability(0.1)
source.SetUseEdgeProbability(True)
source.AllowParallelEdgesOff()
source.Update()

print("Original graph:")
print("\tnum_verts =", source.GetOutput().GetNumberOfVertices())
print("\tnum_edges =", source.GetOutput().GetNumberOfEdges())
print("")

# write the graph to a file
writer = vtkDIMACSGraphWriter()
writer.AddInputConnection(source.GetOutputPort())
writer.SetFileName("graph.gr")
writer.Update()
print("wrote graph to 'graph.gr'")

# let's pause a second to let the disk catch up <shrug/>
time.sleep(1)

# read the graph in from the file
reader = vtkDIMACSGraphReader()
reader.SetFileName("graph.gr")
reader.Update()
print("read graph from 'graph.gr'")

print("Graph from disk:")
print("\tnum_verts =", reader.GetOutput().GetNumberOfVertices())
print("\tnum_edges =", reader.GetOutput().GetNumberOfEdges())

view = vtkGraphLayoutView()
view.AddRepresentationFromInputConnection(reader.GetOutputPort())
view.SetLayoutStrategyToSimple2D()

theme = vtkViewTheme.CreateMellowTheme()
theme.SetLineWidth(1)
theme.SetPointSize(5)
view.ApplyViewTheme(theme)
theme.FastDelete()


view.GetRenderWindow().SetSize(600, 600)
view.ResetCamera()
view.Render()

view.GetInteractor().Start()