Vtk-js: Renderer's `resetCamera()` is biased to height when calculating zoom

Created on 11 Dec 2019  路  6Comments  路  Source: Kitware/vtk-js

I've noticed that there is a render bias for fitting the bounds in the render viewport when using renderer.resetCamera(). Note that these examples are with Parallel enabled, but I can try to reproduce with normal perspective as well.

Example:
Wide viewport scales to fit:
image
VS
Narrow viewport crops significantly
image

rendering bug 馃悶

All 6 comments

Any tips for getting wide volumes in tall viewports to render well? @jourdain?

Renderer.resetCamera() does not take into account the viewport size (nor ratio).

Instead it fits the bounding sphere of the scene into a square frustum viewport.
It seems to work fine because it the vertical axis is always correctly fitted (it could be improved by not using a bounding sphere but the actual bounds).

A solution is to create your own resetCamera function that takes into account the viewer size ratio.

There is useful documentation in code:
https://github.com/Kitware/vtk-js/blob/0a4f91d0adbedb31d21338a8737b9ec2f28a561d/Sources/Rendering/Core/Renderer/index.js#L411-L421

If the bounding sphere is supposed to fit in the view frustum, wouldn't you expect the sphere to always fit, regardless of the viewport frustum ratio? The point of the sphere is to account for the potential oblong-ness or arbitrary orientation of the volume itself, right? So the Sphere is the correct way to go, because as long as the sphere fits, the bounds will be included.

If it's only checking the vertical axis, and that's the one that seems to work all the time, I think a quick check on the frustum to determine if it should use the vertical or horizontal axis would be an easy fix here.

C++ implementation takes into account aspect ratio:
https://gitlab.kitware.com/vtk/vtk/-/blob/master/Rendering/Core/vtkRenderer.cxx#L1138-1157

Interestingly, it used to be possible (though bugged?) to choose wether sphere is fit horizontally or vertically:
https://github.com/Kitware/vtk-js/commit/b9956c73cd51947edcd36234c03818802209df9a

Best is to ask original author: @martinken WDYT ?

We can add an option to resetCamera() to fit vertically or horizontally.

I would recommend adopting the c++ logic that calculates the viewport ratio and fits to the smaller dimension, by default.

Manual COULD be nice, but the goal of reset is "fit the content in the viewport", and should be ratio agnostic.

As a developer, I shouldn't have to manually track what the viewport ratio is.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

truongleit picture truongleit  路  6Comments

rlizzo picture rlizzo  路  3Comments

rjsgml5698 picture rjsgml5698  路  4Comments

doczoidberg picture doczoidberg  路  5Comments

mix3d picture mix3d  路  5Comments