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

Opacity bug fix for point and sphere actors #351

Merged
merged 2 commits into from Jan 6, 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
21 changes: 13 additions & 8 deletions fury/actor.py
Expand Up @@ -1386,18 +1386,18 @@ def dots(points, color=(1, 0, 0), opacity=1, dot_size=5):
return aPolyVertexActor


def point(points, colors, _opacity=1., point_radius=0.1, theta=8, phi=8):
def point(points, colors, point_radius=0.1, phi=8, theta=8, opacity=1.):
"""Visualize points as sphere glyphs

Parameters
----------
points : ndarray, shape (N, 3)
colors : ndarray (N,3) or tuple (3,)
point_radius : float
theta : int
phi : int
theta : int
opacity : float, optional
Takes values from 0 (fully transparent) to 1 (opaque)
Takes values from 0 (fully transparent) to 1 (opaque). Default is 1.

Returns
-------
Expand All @@ -1413,12 +1413,12 @@ def point(points, colors, _opacity=1., point_radius=0.1, theta=8, phi=8):
>>> # window.show(scene)

"""
return sphere(centers=points, colors=colors, radii=point_radius,
theta=theta, phi=phi, vertices=None, faces=None)
return sphere(centers=points, colors=colors, radii=point_radius, phi=phi,
theta=theta, vertices=None, faces=None, opacity=opacity)


def sphere(centers, colors, radii=1., theta=16, phi=16,
vertices=None, faces=None):
def sphere(centers, colors, radii=1., phi=16, theta=16,
vertices=None, faces=None, opacity=1):
"""Visualize one or many spheres with different colors and radii

Parameters
Expand All @@ -1429,13 +1429,16 @@ def sphere(centers, colors, radii=1., theta=16, phi=16,
RGB or RGBA (for opacity) R, G, B and A should be at the range [0, 1]
radii : float or ndarray, shape (N,)
Sphere radius
theta : int
phi : int
theta : int
vertices : ndarray, shape (N, 3)
The point cloud defining the sphere.
faces : ndarray, shape (M, 3)
If faces is None then a sphere is created based on theta and phi angles
If not then a sphere is created with the provided vertices and faces.
opacity : float, optional
Takes values from 0 (fully transparent) to 1 (opaque). Default is 1.


Returns
-------
Expand All @@ -1462,6 +1465,8 @@ def sphere(centers, colors, radii=1., theta=16, phi=16,
active_scalars=radii, source=src,
vertices=vertices, faces=faces)

actor.GetProperty().SetOpacity(opacity)

return actor


Expand Down
8 changes: 6 additions & 2 deletions fury/tests/test_actors.py
Expand Up @@ -848,8 +848,9 @@ def test_dots(interactive=False):
def test_points(interactive=False):
points = np.array([[0, 0, 0], [0, 1, 0], [1, 0, 0]])
colors = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
opacity = 0.5

points_actor = actor.point(points, colors)
points_actor = actor.point(points, colors, opacity=opacity)

scene = window.Scene()
scene.add(points_actor)
Expand All @@ -860,6 +861,7 @@ def test_points(interactive=False):
window.show(scene, reset_camera=False)

npt.assert_equal(scene.GetActors().GetNumberOfItems(), 1)
npt.assert_equal(points_actor.GetProperty().GetOpacity(), opacity)

arr = window.snapshot(scene)
report = window.analyze_snapshot(arr,
Expand All @@ -886,10 +888,11 @@ def test_spheres(interactive=False):

xyzr = np.array([[0, 0, 0, 10], [100, 0, 0, 25], [200, 0, 0, 50]])
colors = np.array([[1, 0, 0, 0.3], [0, 1, 0, 0.4], [0, 0, 1., 0.99]])
opacity = 0.5

scene = window.Scene()
sphere_actor = actor.sphere(centers=xyzr[:, :3], colors=colors[:],
radii=xyzr[:, 3])
radii=xyzr[:, 3], opacity=opacity)
scene.add(sphere_actor)

if interactive:
Expand All @@ -899,6 +902,7 @@ def test_spheres(interactive=False):
report = window.analyze_snapshot(arr,
colors=colors)
npt.assert_equal(report.objects, 3)
npt.assert_equal(sphere_actor.GetProperty().GetOpacity(), opacity)

# test with an unique color for all centers
scene.clear()
Expand Down