Open jweine opened 2 years ago
As far as I am aware, we are "correctly" setting up the underlying VTK algorithm to process on the specified scalars array with this line:
which makes me wonder if the underlying vtkImageGaussianSmooth
filter has a bug where it processes the active scalars rather than the set array to process. After some surface level digging, this does appear to be the case at this line in the vtkImageGaussianSmooth
filter: https://github.com/Kitware/VTK/blob/6a9c565da01bcd6295d0bcbb66c0a9d0d2eaa69e/Imaging/General/vtkImageGaussianSmooth.cxx#L324
The filter is fetching a pointer to the active array, not what is specified to process by the algorithm -- I'm pretty sure this is a bug and would reccomend opening an issue with VTK over it.
To work around this in PyVista, we could have some sort of context manager to set the active scalars to what is specified in PyVista's gaussian_smooth
method then reset when complete (because processing on an array should not set it as active). We may have to do some testing to see if this has any side effects -- I do know that if the source uniform grid is plotter somewhere, like in the pyvistaqt.BackgroundPlotter
, setting and resetting the active scalars will have visual side effects.
I would be willing to contribute, and the Idea of locally setting and resetting the active scalar seems relatively straight forward. If welcome, I could look into seeting up some test cases.
Any contributions you could provide for this would be greatly appreciated!
Describe the bug, what's wrong, and what you expect: Found behaviour:
When calling the dataset filter
gaussian_smooth
on a UniformGrid instance while specifying a non-active scalar as keyword argument, the smoothing is applied to the active scalar and saved to a data array with the specified name.Expected behaviour:
When specifying the keyword argument 'scalars' the correct scalar field should be set as active and the gaussian smoothing should be applied accordingly. After applying the filter, the active scalar of the UniformGrid instance should be the same as before the application.
To Reproduce
The example below, produces a 3D gaussian random distribution and creates a 3D histogram, which is saved as cell data to a UniformGrid whose dimensions match the histogram bins (Image 1). Then the density is estimated by applying the gaussian_smooth filter, which produces the expected result (Image 2).
When creating an arbitrary additional data array and thereby changing the active scalar of the grid before filtering, the filter uses the dummy field (image 3).
Screenshots
System Information: