Problem in render a volume on import

Hey guys, I’ve been trying to do a very simple task on Slicer.

Just to display the rendered model on drag n drop import.

It rarely works, but in most cases I got the error:

Warning: In /work/Stable/Slicer-0/Modules/Loadable/VolumeRendering/Logic/vtkSlicerVolumeRenderingLogic.cxx, line 674
vtkSlicerVolumeRenderingLogic (0x7825480): CopyDisplayToVolumeRenderingDisplayNode: No display node to copy.

I used this on start of my module: Script repository — 3D Slicer documentation

[ image deleted per request ]

There have been some recent improvements in volume rendering initilization. Please try with the latest Slicer Preview Release and let us know it the issue persists.

1 Like

Hello Andras! Thanks for reaching out!
I’m currently using the 5.2.2 version, I’ve managed to solve this issue by raising the time value of qt.QTimer.singleShot then dinamically checking if it was loaded and increasing the load time using volRenLogic.SetRecommendedVolumeRenderingProperties(displayNode)

    def showVolumeRendering(self, volumeNode):
        volRenLogic = slicer.modules.volumerendering.logic()

        # Check if node exists, if not create a new one
        displayNode = slicer.mrmlScene.GetFirstNodeByName('VolumeRendering')
        if displayNode is None:
            displayNode = volRenLogic.CreateVolumeRenderingDisplayNode()
            slicer.mrmlScene.AddNode(displayNode)

        # Set recommended volume rendering properties will return False if the
        if not volRenLogic.SetRecommendedVolumeRenderingProperties(displayNode):
            # If already using the largest loading time, print error message and return
            if len(self.loading_time) == 1:
                print('Failed to load volume! Please, drag it manually from Data.')
                return
            # If not, increase the loading time and try again 
            else:
                self.loading_time.pop(0)
                print('Failed to load volume! Increasing loading to ' + str(self.loading_time[0]) + 'ms.')
                qt.QTimer.singleShot(self.loading_time[0], lambda: self.showVolumeRendering(volumeNode))

        # ensure the display node is visible
        displayNode.SetVisibility(True)

        # add the volume to the display node
        volumeNode.AddAndObserveDisplayNodeID(displayNode.GetID())
        volRenLogic.UpdateDisplayNodeFromVolumeNode(displayNode, volumeNode)

        # update the preset based on the volume scalar range
        scalarRange = volumeNode.GetImageData().GetScalarRange()
        if scalarRange[1]-scalarRange[0] < 1500:
            # Small dynamic range, probably MRI
            displayNode.GetVolumePropertyNode().Copy(volRenLogic.GetPresetByName("MR-Default"))
        else:
            # Larger dynamic range, probably CT
            displayNode.GetVolumePropertyNode().Copy(volRenLogic.GetPresetByName("CT-Chest-Contrast-Enhanced"))