In a scene, I want the zoom action to effectively change the rendered size of most of the actors in the scene (typically those built from vtkCubeSource), except some of them (for example, built from a vtkSphereSource) for which I would like to render them with a fixed size (ie. zoom action would not have any effect on them). Is it possible ?
Thanks in advance for your help.
Yes, it’s possible. The general idea is to figure out how 1 screen-space pixel corresponds to a world-space height. Once you know that, you can set your actor’s height to be that size multiplied by your desired pixel height.
Check out the implementation of getPixelHeightAtCoord. The parameters are computed from here.
Thanks @Forrest. I think I get it. Just one question, how can I get the “actor’s height” ? I guess you’re talking about actor’s height on screen ?
Yep. Suppose you want to have a sphere that has a pixel height (i.e. height of what is displayed on-screen) of 10 pixels. You’d get the result of
getPixelHeightAtCoord, then multiply that by 10 pixels. The resultant length should be what you set as the height of your sphere.
Thanks @Forrest! I managed to get it working doing something like this:
// s being an instance of vtkSphereSource
) * 10); // <-- the pixel height my spheres must be
And by registering some callbacks and doing a first explicit call:
oglrw.onModified(() => this.updateDisplayScaleParams());
this.renderer.getActiveCamera().onModified(() => this.updateDisplayScaleParams());