mirror of
https://github.com/OpenFOAM/ThirdParty-6.git
synced 2025-12-08 06:57:43 +00:00
ParaView-5.0.1: Added the source-tree to ThirdParty-dev and patched as described in the README file
Resolves bug-report http://bugs.openfoam.org/view.php?id=2098
This commit is contained in:
61
ParaView-5.0.1/VTK/Examples/Infovis/Python/csv_to_graph.py
Executable file
61
ParaView-5.0.1/VTK/Examples/Infovis/Python/csv_to_graph.py
Executable file
@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from vtk import *
|
||||
|
||||
FILENAME_VERT_TABLE = "nodes.csv"
|
||||
FILENAME_EDGE_TABLE = "edges.csv"
|
||||
|
||||
|
||||
# Load the vertex table from CSV file
|
||||
csv_vert_source = vtkDelimitedTextReader()
|
||||
csv_vert_source.SetFieldDelimiterCharacters(",")
|
||||
csv_vert_source.DetectNumericColumnsOn()
|
||||
csv_vert_source.SetHaveHeaders(True)
|
||||
csv_vert_source.SetFileName(FILENAME_VERT_TABLE)
|
||||
|
||||
# Load the edge table from CSV
|
||||
csv_edge_source = vtkDelimitedTextReader()
|
||||
csv_edge_source.SetFieldDelimiterCharacters(",")
|
||||
csv_edge_source.DetectNumericColumnsOn()
|
||||
csv_edge_source.SetHaveHeaders(True)
|
||||
csv_edge_source.SetFileName(FILENAME_EDGE_TABLE)
|
||||
|
||||
# Create a graph from the vertex and edge tables
|
||||
tbl2graph = vtkTableToGraph()
|
||||
tbl2graph.SetDirected(True)
|
||||
tbl2graph.AddInputConnection(csv_edge_source.GetOutputPort())
|
||||
tbl2graph.AddLinkVertex("source", "label", False)
|
||||
tbl2graph.AddLinkVertex("target", "label", False)
|
||||
tbl2graph.AddLinkEdge("source", "target")
|
||||
tbl2graph.SetVertexTableConnection(csv_vert_source.GetOutputPort())
|
||||
|
||||
#
|
||||
# Draw the graph
|
||||
#
|
||||
view = vtkGraphLayoutView()
|
||||
view.AddRepresentationFromInputConnection(tbl2graph.GetOutputPort())
|
||||
|
||||
# Label vertices with the contents in the "label" column
|
||||
view.SetVertexLabelArrayName("label")
|
||||
view.SetVertexLabelVisibility(True)
|
||||
|
||||
# Set vertex coloring based on the "intVal" column in nodes.csv
|
||||
view.SetVertexColorArrayName("intVal")
|
||||
view.SetColorVertices(True)
|
||||
|
||||
# Set edge labels and colors
|
||||
view.SetEdgeLabelArrayName("lbl")
|
||||
view.SetEdgeLabelVisibility(True)
|
||||
view.SetEdgeColorArrayName("value")
|
||||
view.SetColorEdges(True)
|
||||
|
||||
theme = vtkViewTheme.CreateMellowTheme()
|
||||
view.ApplyViewTheme(theme)
|
||||
|
||||
# set the layout strategy
|
||||
view.SetLayoutStrategyToSimple2D()
|
||||
|
||||
view.GetRenderWindow().SetSize(600, 600)
|
||||
view.ResetCamera()
|
||||
view.Render()
|
||||
view.GetInteractor().Start()
|
||||
Reference in New Issue
Block a user