ParaView/Python/SavePipelineAsGraph: Difference between revisions
From KitwarePublic
< ParaView
Jump to navigationJump to search
(Created page with "= Summary = The simple API provides functions to manipulate the sources, using graphviz we can save and even show the current Pipeline as a graph, in order to obtain images li...") |
JPouderoux (talk | contribs) mNo edit summary |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 2: | Line 2: | ||
The simple API provides functions to manipulate the sources, using graphviz we can save and even show the current Pipeline as a graph, in order to obtain images like this | The simple API provides functions to manipulate the sources, using graphviz we can save and even show the current Pipeline as a graph, in order to obtain images like this | ||
<ImageLink>https://gitlab.kitware.com/paraview/paraview/uploads/9f22d50401eb0eca25aea454aca7cf82/2018-10-12-165330_1307x692_scrot.png</ImageLink> | |||
==Script== | ==Script== | ||
Line 8: | Line 8: | ||
def SavePipelineGraph(path, format="png", view=False): | def SavePipelineGraph(path, format="png", view=False): | ||
"""Save the state of the pipelines (aka Sources and Filters) as a graph. | """Save the state of the pipelines (aka Sources and Filters) as a graph. | ||
Specify the path to save the graph to, Optionaly, specify the format to save it to | Specify the path to save the graph to, Optionaly, specify the format to save it to, | ||
default is "png" but it can be "pdf" for instance. If you want to show it right away, | |||
This method is using graphviz and will save two | set view parameter to True, default is False. | ||
This method is using graphviz and will save two files. One will be save in the graphviz | |||
format (.gv), the other one to the specified format. | |||
""" | """ | ||
try: | try: | ||
Line 38: | Line 39: | ||
d.render(path, view=view) | d.render(path, view=view) | ||
</source> | </source> | ||
Then simply call it: | |||
<source lang="python"> | |||
SavePipelineGraph("~/pipeline", "pdf") | |||
</source> | |||
Back to [[ParaView/PythonRecipes]]. | |||
{{ParaView/Template/Footer}} |
Latest revision as of 18:34, 16 October 2018
Summary
The simple API provides functions to manipulate the sources, using graphviz we can save and even show the current Pipeline as a graph, in order to obtain images like this
Script
<source lang="python"> def SavePipelineGraph(path, format="png", view=False):
"""Save the state of the pipelines (aka Sources and Filters) as a graph. Specify the path to save the graph to, Optionaly, specify the format to save it to, default is "png" but it can be "pdf" for instance. If you want to show it right away, set view parameter to True, default is False. This method is using graphviz and will save two files. One will be save in the graphviz format (.gv), the other one to the specified format. """ try: import graphviz except ImportError: print("Graphviz could not be imported", file=sys.stderr) return
d = graphviz.Digraph() activeSource = GetActiveSource() sources = GetSources() if len(sources) == 0: print("Pipeline is empty") else: for item in sources.items(): key = item[0] source = item[1] color = "red" if source == activeSource else "black" d.node(key[1], label=key[0], color=color) proxy = source.SMProxy for i in range(proxy.GetNumberOfProducers()): prod = proxy.GetProducerProxy(i) if prod.IsTypeOf("vtkSMSourceProxy"): d.edge(str(proxy.GetProducerProxy(i).GetGlobalID()), str(key[1])) d.format = format d.render(path, view=view)
</source>
Then simply call it: <source lang="python">
SavePipelineGraph("~/pipeline", "pdf")
</source>
Back to ParaView/PythonRecipes.