Change default settings for Volume Rendering module

Hi!

I have been using the volume rendering module to visualise 3D volumes with maximum intensity projection technique. Due to the properties of my images, I always have to change the settings in “Volume properties” so that most of the “points” for “Scalar Color Mapping” are set to 0. However, the problem is that by default there are many control points for this setting, and everytime I have to spend a while dragging many control points to 0. I have to process many images, so doing this repeatedly is quite tedious. I am wondering if it is possible for me to change the default setting for this part so that I don’t have to change this setting manually every time? Many thanks in advance!

Current default:

What I want:

In the order of from simplest to slightly to more work:

You can save and reload the volume property you customized.
You can do bit of python scripting to have it automatically loaded into Slicer through slicerrc.py.
You can even register as a default preset.

All of those are possibilities.

Thank you. Your discussion on the forum here is also very helpful. I think for my purpose loading my volume property file (.vp) is sufficient, and I have managed to add the following code to my .slicerrc.py so that my .vp file is loaded automatically:

vp_file = '/path/to/myVolumeProperty.vp'
volRenLogic = slicer.modules.volumerendering.logic()
volRenLogic.AddVolumePropertyFromFile(vp_file)

However, I now still have to go to “Inputs” section in the volume rendering module to select this volume property every time. Do you know how I can set it as the default volume property in .slicerrc.py? I am really unfamiliar with writing python scripts for slicer and have found it very difficult to find the write function to use, so your help will be very much appreciated!

I will defer this to @lassoan @pieper. I know it is possible, but not sure.

We have MRML file where we define our custom presets. I imagine there is a some sort of weight that needs to be defined to make them the first choice (e.g., for 16 bit unsigned data).

I don’t know what you mean by ‘default volume property’. Perhaps you mean ‘change the default values of a given factory preset’. It’s probably possible, experts may have a valuable reply as @muratmaga said.

Nevertheless, I use this ugly hack in .slicerrc.py. It did not crash anything for years. You may add your custom presets in the combobox and select them like factory presets.

def loadCustomVolumeProperty(name):
    VolRenLogic = slicer.modules.volumerendering.logic()
    VolProp = VolRenLogic.GetPresetByName(name)
    if (VolProp is None):
        VolProp = VolRenLogic.AddVolumePropertyFromFile(/path/to/vp/file)
        vReader = vtk.vtkPNGReader()
        vReader.SetFileName(str(/path/to/png/file)
        vReader.Update()
        VolRenLogic.AddPreset(VolProp, vReader.GetOutput())
    
    # The loaded Volume Property is *sometimes* found as volume nodes, in Volume Rendering module only, not in Volumes module !
    alienNodes = slicer.mrmlScene.GetNodesByName(name)
    for node in alienNodes:
        # We are just removing the vtkMRMLVolumePropertyNode we just loaded, but it persists as a preset and is functional !!!
        # print(node.GetClassName())
        slicer.mrmlScene.RemoveNode(node)
        
loadCustomVolumeProperty(customVR1)
loadCustomVolumeProperty(customVR2)

If you want to modify an existing volume rendering preset or reorder volume rendering presets then you can use the code snippet above to remove a preset and then prepend it to the preset list.

If you want to use special volume rendering presets used by default for some special volume types then you can create a subject hierarchy plugin that recognizes and takes ownership of the special volume types.

However, what you probably actually want is a custom hanging protocol, which goes beyond just some volume rendering presets and customizes the view layout, select which volumes are displayed in what views, with what opacity, colormap, etc. These can be all easily set using a Python script that you can activate by a keyboard shortcut (see complete example here). If a keyboard shortcut is not convenient enough then you can observe newFileLoaded signal of the ioManager and detect if your custom hanging protocol is applicable to the loaded data and if yes then activate it automatically.

Sorry my question wasn’t very clear. What I meant was that when I load a volume into slicer and go to the Volume Rendering module, it will be visualised with a default ‘VolumeProperty’, as can be seen in the ‘Inputs’ section ‘Property’ box. After adding those few lines to my .slicerrc.py, I now automatically load my custom volume property ‘MIP_VolumeProperty’ to slicer and can see it in the options. However, to use my custom volume property, I still have to go to this section and select it every time. Thus, I was wondering if there is a way to let it automatically select my custom volume property to use when I do volume rendering. I am not registering my volume property as a preset at this moment.

Thanks to @lassoan for your input as well. However, I’m afraid that what you wrote about the “hierarchy plugin” and “hanging protocol” is a bit beyond my understanding. With my current clarification of my question, do you think those are what I need?
Screenshot 2024-02-16 at 11.43.16

Hanging protocol defines in a radiology workflow what images you show and where, in what orientation, with what settings.

Volume rendering preset is a just one of the details that you need to set up. So, instead of investing time into developing a custom subject hierarchy plugin (that is responsible for choosing the volume rendering preset), I would recommend to implement a short Python code snippet that sets the volume rendering preset and all other view options you want. You can run this script by a keyboard shortcut ir automatically when images are loaded.