fury-gl / fury

FURY - Free Unified Rendering in pYthon.
https://fury.gl
Other
226 stars 165 forks source link

Routine sphere no longer functions when specifying radii with an array #583

Open Sassafrass6 opened 2 years ago

Sassafrass6 commented 2 years ago

Somebody broke the sphere source behavior when passing arrays to specify multiple sphere objects.

This Tutorial no longer functions: introductory-vis-timers-py Line 1576 creating the "scales" array with np.multiply fails if radii is not a number (and likely has undefined behavior if radii is a numpy array with 3 elements).

Although the way that scales is constructed is most likely incorrect, it actually is not the only reason that the Tutorial fails... The real culprit is a new argument 'use_primitive' in actors.py:sphere that selects whether the sphere source or primitive sphere should be taken. Personally, I believe 'use_primitive' should default to False, since this would preserve the original behavior of the code. If the goal was to replace sphere source with the primitive sphere, then the routine just needs an update to properly handle a list of N radii.

-Frank

skoudoro commented 2 years ago

Thank you for the feedback @Sassafrass6.

I confirm that the goal is to replace the sphere source with the primitive sphere in the close future. It should be the case for all actors.

We would like to be less dependent on VTK and have other backends to permit the user to choose it. We try to slowly anticipate some future big issues on macOS (Opengl /metal /vulkan).

For now, we will switch use_primitive to False until the primitive fix.

xtanion commented 2 years ago

Changing scales=np.multiply(radii, [1,1,1]) to scales=np.array(radii) fixes the array of radii issue. However I noticed sphere source (or any other actor using repeat_sources) doesn't scale properly for radii < 1.

xyz = np.random.randn(2, 3)
cols = np.random.randn(2, 3)
radii = [1.2, 0.2]
s1 = actor.sphere(centers=xyz, colors=cols, radii=radii, use_primitive=True)
s2 = actor.sphere(centers=xyz, colors=(1, 1, 1, 0.4), radii=radii, use_primitive=False)

# using box actor for Reference
# while box is centered at xyz, we are scaling box to diameter of sphere
scales = np.multiply(radii, 2)
b1 = actor.box(centers=xyz, directions=(1, 0, 0), colors=(1, 0, 0, 0.3), scales=scales)

scene.add(s1)
scene.add(s2)
scene.add(b1)

results: image