Filters switching current attribute of render view

Let’s take the “Calculator” filter as an example: after entering a result attribute name and a formula and pressing Apply - not only the formula is evaluated!

On top of that, the render view switches to showing the new result attribute as current attribute for the display.

This is very nice and userfriendly, and I would like to add this behaviour also to some of my own filters. However: so far I was not able to figure out where exactly this is happening! I have written filters, with and without custom property widgets, and I know that communication between filters (server) and views (client) is always a bit tricky, but neither in the filter class code nor in the custom property widget code I found any “suspicious activity”…

Best regards and many thanks for helpful hints! Cornelis

If a data set has one of its fields marked as “active scalars,” then ParaView will automatically color by that field when it is first viewed. In the implementation of your filter, you can set the active scalars with code that looks like this (in C++):

output->GetPointData->SetActiveScalars("Result");

Of course, replace "Result" with the name of whatever field you you want to show by default. And of course use GetCellData if you have a cell field instead of a point field.

Thanks a lot!

Looks much easier than what I expected - and I was following completely different tracks!

There seems to be one restriction that I see: It works only the first time! Or more specifically:

  1. add filter and choose or adapt properties, including attribute name, say “Result”
  2. press “Apply” -> view will show “Result”
  3. change again some properties, and change “Result” to “OtherResult”
  4. press “Apply” -> changes will happen, but the view will still try to show “Result” which is now unknown

Perfection would be in my case: make it show “OtherResult” after step 4.!

If possible…

Finally I made it happen! The method is however a bit “shooting from behind through the chest into the eye” - like we are saying in German…

Basically it all goes through a custom widget that directly addresses the “Variables” combo box and finds the interesting attribute by comparing a list of attributes “before Apply” and “after Apply”.

The point is that I have there a number of filters that actually add an attribute, but do it in such a way interactive that I had to introduce some “initialization Apply” run - at a time that the name of that new attribute is not known yet. But then the “real Apply” is not the first but the second - and the call to SetActiveScalars does not have an effect any more.