How to display volume node in view programatically

I would like to show in all view a volume node present in the subject hierarchy, just like i click on the eye.
I work in a loadable module in c++.

I searched for this function in Slicer sources, i found it in qSlicerSubjectHierarchyVolumesPlugin.
IE : qSlicerSubjectHierarchyVolumesPlugin::showVolumeInAllViews

But my problem is that i did not manage to link to this plugin and use this function in my code, i know how to link to the modules, but here it is a plugin in the volumes module.

So how to achieve that ? Maybe there is another way to show a volume node in all view ?

One way:

    appLogic = slicer.app.applicationLogic()
    selectionNode = appLogic.GetSelectionNode()
    selectionNode.SetActiveVolumeID(backgroundVolumeNodeID)
    appLogic.PropagateVolumeSelection()

Another way

    numberOfCompositeNodes = slicer.mrmlScene.GetNumberOfNodesByClass("vtkMRMLSliceCompositeNode")
    for i in range(numberOfCompositeNodes):
      compositeNode = slicer.mrmlScene.GetNthNodeByClass(i,"vtkMRMLSliceCompositeNode")
      compositeNode.SetBackgroundVolumeID(backgroundVolumeNodeID)
2 Likes