"Volume Information" in "Volumes" module not updated for modified volumes

When I clone a volume node and then modify the array values, the “Volume Information” section shows outdated information and I can’t find a way to get it to update.

volNode = getNode('vtkMRMLScalarVolume1')
newVolNode = slicer.modules.volumes.logic().CloneVolume(slicer.mrmlScene, volNode, 'copiedVolume')
newVolArray = slicer.util.arrayFromVolume(newVolNode)
newVolArray[newVolArray>0] = 0
newVolNode.Modified()

After this code, the newVolumeNode() has a maximum value of 0, but “Volume Information” still shows it to have a “Scalar Range” up to whatever value the original volNode had. The actual display of the volume in the slice views shows the modified voxel values, and in all other relevant ways the volume is updated, but there seems to be nothing which updates the “Volume Information”.

You need to call slicer.util.arrayFromVolumeModified(newVolNode) to indicate that you have finished with your modifications. See documentation for details.

1 Like

Thanks, I saw the call to volNode.Modified() somewhere, and thought that was all I needed to do to trigger updates. My mistake! Thanks for your help!

1 Like

volNode.Modified() only indicates that metadata stored in the volume node’s attributes are changed (but not that pixels are changed).

1 Like

Hello, i kind of have a similar problem but i use C++ and after a long search in the documentation I failed to find the C++ counterpart of slicer.util.arrayFromVolumeModified(newVolNode)

Does it really exist ? Or have a different name ?

No, it doesn’t exist. You can just look at the corresponding python implementation and make the same calls. Usually it’s just one or two Modified() calls. Note you only need this if you change the array directly. If you work with VTK pipelines it’s typically automatic.

1 Like

A great side-effect of Slicer (and libraries it uses) being open, along with all documentation, discussion, etc. is that all information is indexed by search engines. So, if you need documentation or source code then you can simply do a web search. For example if you google for arrayFromVolumeModified then for me the second hit in the search result is the source code.

1 Like

I though that was what i needed, but in fact it is not.

So, i received data via webSocket, created a node, updated his data, displayed it using something like :

selectionNode->SetActiveVolumeID(node.GetID());
appLogic->PropagateVolumeSelection();

And i would like that the volume information section update with his data.

So the node is selected (the eye icon is on) but it seems that the update of the volume information section is triggered by highlighting a node in the hierarchy tree. After some research on the vtkMRMLSelectionNode or vtkMRMLSubjectHierarchyNode i couldn’t find what i was looking for.

I also tried something like :

    QString errorMsg;
    qSlicerAbstractCoreModule* volumeModule = qSlicerCoreApplication::application()->moduleManager()->module("Volumes");
    if (!volumeModule)
    {
        errorMsg += "VolumesModule module is not found. ";
        qCritical() << "VolumesModule module is not found";
        return;
    }
    vtkSlicerVolumesLogic* volumeLogic = vtkSlicerVolumesLogic::SafeDownCast(volumeModule->logic());
    if (!volumeLogic)
    {
        errorMsg += "VolumesModule logic is not found. ";
        qCritical() << "VolumesModule logic is not found";
        return;
    }
    volumeLogic->SetActiveVolumeNode(node);

But it did’nt have any effect, i miss an update or something ? Any hint ?

You can change the currently selected node in Volumes module GUI by calling:

slicer.modules.volumes.widgetRepresentation().setEditedNode(volumeNode)

This feature is used when you right-click on a node and choose “Edit node…”. This API should not be necessary for implementing a custom workflow. Instead, the recommended way to implement workflows is not to switch between modules at all, just put all the widgets that you need into your own module GUI.

For example, if you want to show volume information in your module, just add a qMRMLVolumeInfoWidget to your module GUI. You can try this easily from the Python console:

w=slicer.qMRMLVolumeInfoWidget()
w.setMRMLScene(slicer.mrmlScene)
w.setVolumeNode(volumeNode)
w.show()

All the other parts of the Volumes module are widgets that you can reuse (and customize) in your module. For example, you can show/edit volume display options by adding a slicer.qSlicerScalarVolumeDisplayWidget() to your module GUI. Similarly, all other Slicer core module GUI is assembled from widgets that you can reuse in your own module. There could be some exceptions, where some shortcuts were taken and some parts of a module GUI is not a reusable widget. If you encounter anything like that then you can file a bug report.

slicer.modules.volumes.widgetRepresentation().setEditedNode(volumeNode)

Did not have any effect, i would like to try the solution you advised :

w=slicer.qMRMLVolumeInfoWidget()
w.setMRMLScene(slicer.mrmlScene)
w.setVolumeNode(volumeNode)
w.show()

But i did not manage to get the qMRMLVolumeInfoWidget as i work in C++, i could not find any example of use in the source. How should i access it ?

It does what I described above: changes the currently selected node in Volumes module GUI.

You can use the Volumes module as an example. It displays this widget in its module GUI. The module GUI is designed in Qt Designer, so the best is to view/edit the GUI there.

Developing modules in C++ is for advanced users. It is recommended to first get to know Slicer using Python scripting.