Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the sdf bug by checking the arguments passed #346

Merged
merged 4 commits into from Jan 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions fury/actor.py
@@ -1,5 +1,6 @@
"""Module that provide actors to render."""

import warnings
import os.path as op
import numpy as np
import vtk
Expand Down Expand Up @@ -2545,9 +2546,9 @@ def sdf(centers, directions=(1, 0, 0), colors=(1, 0, 0), primitives='torus',
RGB or RGBA (for opacity) R, G, B and A should be at the range [0, 1]
directions : ndarray, shape (N, 3)
The orientation vector of the SDF primitive.
primitives : str
primitives : str, list, tuple, np.ndarray
The primitive of choice to be rendered.
Options are sphere and torus. Default is torus
Options are sphere and torus. Default is torus.
scales : float
The size of the SDF primitive

Expand All @@ -2569,6 +2570,10 @@ def sdf(centers, directions=(1, 0, 0), colors=(1, 0, 0), primitives='torus',

if isinstance(primitives, (list, tuple, np.ndarray)):
primlist = [prims[prim] for prim in primitives]
if len(primitives) < len(centers):
primlist = primlist + [2] * (len(centers) - len(primitives))
warnings.warn("Not enough primitives provided,\
defaulting to torus", category=UserWarning)
rep_prims = np.repeat(primlist, verts.shape[0])
else:
rep_prims = np.repeat(prims[primitives], rep_centers.shape[0], axis=0)
Expand Down
48 changes: 48 additions & 0 deletions fury/tests/test_actors.py
Expand Up @@ -1350,3 +1350,51 @@ def test_sdf_actor(interactive=False):
arr = window.snapshot(scene)
report = window.analyze_snapshot(arr, colors=colors)
npt.assert_equal(report.objects, 3)

# Draw 3 spheres as the primitive type is str
scene.clear()
primitive = 'sphere'
sdf_actor = actor.sdf(centers, directions,
colors, primitive, scales)
scene.add(sdf_actor)
scene.add(actor.axes())
if interactive:
window.show(scene)

arr = window.snapshot(scene)
report = window.analyze_snapshot(arr, colors=colors)
npt.assert_equal(report.objects, 3)

# A sphere and default back to two torus
# as the primitive type is list
scene.clear()
primitive = ['sphere']
with npt.assert_warns(UserWarning):
sdf_actor = actor.sdf(centers, directions, colors,
primitive, scales)

scene.add(sdf_actor)
scene.add(actor.axes())
if interactive:
window.show(scene)

arr = window.snapshot(scene)
report = window.analyze_snapshot(arr, colors=colors)
npt.assert_equal(report.objects, 3)

# One sphere and ellipsoid each
# Default to torus
scene.clear()
primitive = ['sphere', 'ellipsoid']
with npt.assert_warns(UserWarning):
sdf_actor = actor.sdf(centers, directions,
colors, primitive, scales)

scene.add(sdf_actor)
scene.add(actor.axes())
if interactive:
window.show(scene)

arr = window.snapshot(scene)
report = window.analyze_snapshot(arr, colors=colors)
npt.assert_equal(report.objects, 3)