Skip to content
Snippets Groups Projects
Commit cc055e99 authored by Andrew Maclean's avatar Andrew Maclean
Browse files

Added RandomGraphSource, SelectedVerticesAndEdges

parent a4c20bea
No related branches found
No related tags found
1 merge request!354All classes in Python are now represented in PythonicAPI
......@@ -312,8 +312,10 @@ This section includes ?vtkUnstructuredGrid?.
[CreateTree](/PythonicAPI/Graphs/CreateTree) | Create a tree and label the vertices and edges.
[GraphToPolyData](/PythonicAPI/Graphs/GraphToPolyData) | Convert a graph to a PolyData.
[LabelVerticesAndEdges](/PythonicAPI/Graphs/LabelVerticesAndEdges) | Label vertices and edges.
[RandomGraphSource](/PythonicAPI/Graphs/RandomGraphSource) | Create a random graph.
[SideBySideGraphs](/PythonicAPI/Graphs/SideBySideGraphs) | Display two graphs side by side.
[ScaleVertices](/PythonicAPI/Graphs/ScaleVertices) | Size/scale vertices based on a data array.
[SelectedVerticesAndEdges](/PythonicAPI/Graphs/SelectedVerticesAndEdges) |
[VisualizeDirectedGraph](/PythonicAPI/Graphs/VisualizeDirectedGraph) | Visualize a directed graph.
### Graph Conversions
......
#!/usr/bin/env python3
# noinspection PyUnresolvedReferences
import vtkmodules.vtkInteractionStyle
# noinspection PyUnresolvedReferences
import vtkmodules.vtkRenderingOpenGL2
from vtkmodules.vtkCommonColor import vtkNamedColors
from vtkmodules.vtkInfovisCore import vtkRandomGraphSource
# noinspection PyUnresolvedReferences
from vtkmodules.vtkInfovisLayout import vtkForceDirectedLayoutStrategy
from vtkmodules.vtkViewsInfovis import vtkGraphLayoutView
def main():
colors = vtkNamedColors()
# seed=123 ensures repeatable results for testing. Remove this off for real use.
random_graph_source = vtkRandomGraphSource(number_of_vertices=5, number_of_edges=4, seed=123)
random_graph_source.update()
# force_directed = vtkForceDirectedLayoutStrategy()
graph_layout_view = vtkGraphLayoutView()
graph_layout_view.AddRepresentationFromInput(random_graph_source.GetOutput())
# If we create a layout object directly, just set the pointer through this method.
# graph_layout_view.SetLayoutStrategy(force_directed)
graph_layout_view.SetLayoutStrategyToForceDirected()
graph_layout_view.renderer.background = colors.GetColor3d('Navy')
graph_layout_view.renderer.background2 = colors.GetColor3d('MidnightBlue')
graph_layout_view.render_window.window_name = 'RandomGraphSource'
graph_layout_view.Render()
graph_layout_view.ResetCamera()
graph_layout_view.interactor.Start()
if __name__ == '__main__':
main()
### Description
* Contributed by Eric Monson
#!/usr/bin/env python3
# noinspection PyUnresolvedReferences
import vtkmodules.vtkInteractionStyle
# noinspection PyUnresolvedReferences
import vtkmodules.vtkRenderingOpenGL2
from vtkmodules.vtkInfovisCore import vtkRandomGraphSource
from vtkmodules.vtkViewsInfovis import vtkGraphLayoutView
def selection_callback(caller, event):
# Use the shift key to select both nodes and edges.
# The nodes can either vertices or edges.
sel = caller.current_selection
node0 = sel.GetNode(0)
node0_field_type = node0.field_type
sel_list0 = caller.current_selection.GetNode(0).selection_list
node1 = sel.GetNode(1)
node1_field_type = node1.field_type
sel_list1 = caller.current_selection.GetNode(1).selection_list
if sel_list0.number_of_tuples > 0:
# print('node0:')
print_field_type(node0_field_type)
for ii in range(sel_list0.number_of_tuples):
print(' ', sel_list0.GetValue(ii))
if sel_list1.number_of_tuples > 0:
# print('node1:')
print_field_type(node1_field_type)
for ii in range(sel_list1.number_of_tuples):
print(' ', sel_list1.GetValue(ii))
print('- - -')
def print_field_type(field_type):
if field_type == 3:
print('Vertex Id(s) Selected:')
elif field_type == 4:
print('Edge Id(s) Selected:')
else:
print('Unknown type:')
def main():
source = vtkRandomGraphSource()
source.Update()
view = vtkGraphLayoutView()
view.AddRepresentationFromInputConnection(source.GetOutputPort())
rep = view.GetRepresentation(0)
# The vtkRenderedGraphRepresentation should already have a vtkAnnotationLink,
# so we just want to grab it and add an observer with our callback function
# attached
link = rep.GetAnnotationLink()
link.AddObserver('AnnotationChangedEvent', selection_callback)
view.GetRenderWindow().SetSize(600, 600)
view.ResetCamera()
view.Render()
view.GetInteractor().Start()
if __name__ == '__main__':
main()
src/Testing/Baseline/PythonicAPI/Graphs/TestRandomGraphSource.png

129 B

src/Testing/Baseline/PythonicAPI/Graphs/TestSelectedVerticesAndEdges.png

129 B

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment