Animate a Programmable Filter using GetActiveCamera

I need to do something odd. I want to compute field quantities based on the active camera position and orientation. I have a prototype working, where I use a Programmable Filter to compute these quantities based on GetActiveCamera().GetViewPlaneNormal() from VTK. The problem is, camera motion doesn’t trigger an evaluation of the filter. Is there a way to fake things so that I can force the animation to trigger a filter evaluation? The best idea I’ve had so far is to add a Transform filter upstream of the Programmable Filter and just do a very small translation.

This is indeed not really in the VTK philosophy… The content of a filter is intended to be rendering-agnostic.

To achieve that, I think you should have some external code that observes the camera and call some setters on your filter.
So:

  • create a filter proxy (this can be based on programmable filter with some property, or with a python plugin)
  • create a pvpython code (like a macro) that observes the camera and update your filter accordingly

See Utkarsh’s message for an example Scale Scalar Value in Animation - #6 by reox

This uses a “Python” animation track where you have access to all the filters and camera as well. In ParaView 5.12, you can add a “Python” animation track in the Time Manager (the Animation View is gone).

This looks like it will work well for what I need. I noticed when trying to save an animation that GetActiveCamera seems to refer to the RenderView, which may not be what the animation is using. How would I get the Camera as defined in the Time Manager?

I suspect you are asking about the camera as it is interpolated in a Camera track in the Time Manager. The camera track sets the camera in the RenderView associated with the track. So if you access that view’s camera (perhaps with paraview.simple.FindView()) in the Python cue, you can access the parameters of the camera track in the Time Manager.

I’ve tried to approach this using the Python Animations referenced in Utkarsh’s answer, and it’s working mostly well. My testing has revealed that the Camera track and the Python track are out of sync with each other, though. The computed values from Python are correct for the previous camera position, not the current one.

I speculate that the animation is advancing the Python track first, then the Camera track. Is there any way to control this? Should I try to move the camera controls into the Python track?

@cory.quammen @utkarsh.ayachit