MCPcopy Create free account
hub / github.com/Kitware/VTK / DisplayGraph

Function DisplayGraph

Utilities/Maintenance/VisualizeModuleDependencies.py:239–304  ·  view source on GitHub ↗

Display the graph.

(graph)

Source from the content-addressed store, hash-verified

237 return g
238
239def DisplayGraph(graph):
240 '''
241 Display the graph.
242 '''
243 theme = vtkViewTheme()
244 theme.SetBackgroundColor(0, 0, .1)
245 theme.SetBackgroundColor2(0, 0, .5)
246
247 # Layout the graph
248 # Pick a strategy you like.
249 # strategy = vtk.vtkCircularLayoutStrategy()
250 strategy = vtkSimple2DLayoutStrategy()
251 # strategy = vtk.vtkRandomLayoutStrategy()
252 layout = vtkGraphLayout()
253 layout.SetLayoutStrategy(strategy)
254 layout.SetInputData(graph)
255
256 view = vtkGraphLayoutView()
257 view.AddRepresentationFromInputConnection(layout.GetOutputPort())
258 # Tell the view to use the vertex layout we provide.
259 view.SetLayoutStrategyToPassThrough()
260 view.SetEdgeLabelVisibility(True)
261 view.SetVertexLabelArrayName("Labels")
262 view.SetVertexLabelVisibility(True)
263 view.ApplyViewTheme(theme)
264
265 # Manually create an actor containing the glyphed arrows.
266 # Get the edge geometry
267 edgeGeom = vtkGraphToPolyData()
268 edgeGeom.SetInputConnection(layout.GetOutputPort())
269 edgeGeom.EdgeGlyphOutputOn()
270
271 # Set the position (0: edge start, 1: edge end) where
272 # the edge arrows should go.
273# edgeGeom.SetEdgeGlyphPosition(0.8)
274 edgeGeom.SetEdgeGlyphPosition(0.85)
275
276 # Make a simple edge arrow for glyphing.
277# arrowSource = vtk.vtkGlyphSource2D()
278# arrowSource.SetGlyphTypeToEdgeArrow()
279# arrowSource.SetScale(0.075)
280 # Or use a cone.
281 coneSource = vtkConeSource()
282 coneSource.SetRadius(0.025)
283 coneSource.SetHeight(0.1)
284 coneSource.SetResolution(12)
285
286 # Use Glyph3D to repeat the glyph on all edges.
287 arrowGlyph = vtkGlyph3D()
288 arrowGlyph.SetInputConnection(0, edgeGeom.GetOutputPort(1))
289# arrowGlyph.SetInputConnection(1, arrowSource.GetOutputPort())
290 arrowGlyph.SetInputConnection(1, coneSource.GetOutputPort())
291
292 # Add the edge arrow actor to the view.
293 arrowMapper = vtkPolyDataMapper()
294 arrowMapper.SetInputConnection(arrowGlyph.GetOutputPort())
295 arrowActor = vtkActor()
296 arrowActor.SetMapper(arrowMapper)

Callers 1

mainFunction · 0.85

Calls 15

SetBackgroundColor2Method · 0.80
RenderMethod · 0.65
vtkViewThemeClass · 0.50
vtkGraphLayoutFunction · 0.50
vtkGraphLayoutViewClass · 0.50
vtkGraphToPolyDataClass · 0.50
vtkConeSourceClass · 0.50
vtkGlyph3DClass · 0.50
vtkPolyDataMapperClass · 0.50
vtkActorClass · 0.50

Tested by

no test coverage detected