I have a scenario where I’m dynamically updating a scalar float volume with a modified numpy array with every update of a slider. Specifically, I’m masking various regions of the original volume with NANs. I’m using NANs rather than a specific real value for the transparency in the slice views. The reason I’m doing this thing with NANs rather than using the mask volume segment editor effect is so that the volume quickly updates without the delay of creating a new volume, and to get around the organization overhead of creating and managing new volumes for each different way I mask the volume.
The problem here is that updating the volume data, which changes the scalar range of the volume, also seems to update the bounds of the threshold in the qSlicerScalarVolumeDisplayWidget automatically, even with the threshold in manual mode. I don’t want the bounds of threshold slider flying around while I’m using my widget to update the volume.
Does anyone know of a way around this? Is there any observer I can disable to stop the threshold widget from updating with the volume data?
It would be practically impossible to write all the code in a software application to be prepared to work with NaN values - it would extremely costly to implement, hard to maintain (all features would need to be tested with NaN values occurring in various places), and the resulting code would be slower (as you would need to implement lots of extra checks to deal with NaNs). NaN values are usually occur as a side effect of computation errors and - except very special circumstances in specific parts of an application - you should avoid using them.
Specifically, in 3D Slicer, behavior is undefined if you add NaN values in a volume. If you have value that contains NaN then it is your responsibility to replace them by valid values before you set it in voxels of a volume.
Instead of setting values, to NaN, set values that you would like to mask out to a value that is higher or lower then values in the normal range. You can then use threshold feature of Volumes module to make those values transparent.
You can disable automatic scalar range computation by calling volumeDisplayNode->AutoWindowLevelOff() - see example here.