In a programmable filter, I’d like to be able to get the name of the source that feeds the programmable filter. But I’m having trouble figuring out how to get to the actual source through the filter. If I get the input to the programmable filter, it only has the data object that comes from the source, not the pipeline source.
I’ve tried getting both the “input” and the “inputconnection”, but both are of the data (though are subtly different), and while I’m not quite sure what the difference is, neither seems to allow me to get to the source. I thought perhaps if I used GetSources I could map the input to a source, but that fails as well.
For example, I’ve tried:
sources = paraview.simple.GetSources()
reader1 = self.GetInput()
source1 = sources.keys()[sources.values().index(reader1)]
# the above fails with a no value match
reader2 = self.GetInputConnection(0,0)
source2 = sources.keys()[sources.values().index(reader2)]
# likewise fails with a no value match
My goal is to get the filename of what was read in the source feeding the programmable filter.
So what I want to do is read some metadata that will be used to alter the transformation display property of some data. Specifically I have NIFTI data that I convert to TIFF for reading into ParaView, but I can extract the metadata from the original NIFTI file, and so I have a programmable filter that reads the metadata and then alters it’s own display property with that transformation information – and passes through the original TIFF data.
Ideally, I’d like the programmable filter to not actually “filter” (ie. pass-through) the data, but to instead alter the display property of the TIFF reader source, and so I wanted to go backwards through the pipieline chain until I got to the source and then make the alteration.
So eventually, I did manage to figure out (thanks to Google) how to get the proxy for the programmable filter, and then it can change it’s own display properties, and as I say pass through the data.
proxies = sm.ProxyManager().GetProxiesInGroup("sources").values()
selfProxy = [p for p in proxies if p.GetClientSideObject() is self]
dispProp = GetDisplayProperties(selfProxy)
dispProp.Position = translation_values
But then I decided I could do something simpler, and just provide a name for the pipeline elements, and do “FindSource()” inside the programmable filter to alter whichever pipeline element I want – meaning the programmable filter isn’t really filtering anything.
It’s all a bit hackish, I admit, but I only have limited time to make the project do what I want – or I’d have written a programmable source to read the NIFTI file itself!