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 argument for point doesn't seem to work #335

Closed
3 tasks done
SunTzunami opened this issue Oct 31, 2020 · 9 comments · Fixed by #351
Closed
3 tasks done

_opacity argument for point doesn't seem to work #335

SunTzunami opened this issue Oct 31, 2020 · 9 comments · Fixed by #351
Labels
good first issue Good for newcomers type:Bug Fix Something isn't working
Milestone

Comments

@SunTzunami
Copy link
Member

Description

The "_opacity" argument for fury.actor.point doesn't seem to work. Manipulating the values for the _opacity doesn't seem to change the opacity of the rendered points.
From what I could figure from the documentation, this occurs as the function which generates the points (fury.actor.point) utilises the sphere function (fury.actor.sphere) in generating the points and the function for generating spheres doesn't have any means to manipulate the opacity of the spheres that it generates.

Way to reproduce

  • Code example
from fury import window, actor
import numpy as np

scene = window.Scene()
coor1 = np.array([[0, 0, 0]])
coor2 = np.array([[1, 0, 0]])
point_actor1 = actor.point(coor1, window.colors.coral, _opacity=0.00, point_radius=0.2)          #point on the left
point_actor2 = actor.point(coor2, window.colors.coral, _opacity=1.00, point_radius=0.2)          #point on the right
scene.add(point_actor1)
scene.add(point_actor2)
window.show(scene)
window.record(scene, size=(300, 300), out_path="vr.png")

From the code, it's evident that the desired output requires that the point on the left be transparent (opacity=0) and the point on the right be opaque. But the output rendered has both the points as opaque.

  • Relevant images (if any)

vr

  • Operating system and versions
    {'fury_version': '0.6.1', 'pkg_path': "C:\Users\Tzu's Pc\AppData\Local\Programs\Python\Python38\lib\site-packages\fury", 'commit_hash': 'ee4e85c8f1358105700c156b20ba1db83a004261', 'sys_version': '3.8.6 (tags/v3.8.6:db45529, Sep 23 2020, 15:52:53) [MSC v.1927 64 bit (AMD64)]', 'sys_executable': "C:\Users\Tzu's Pc\AppData\Local\Programs\Python\Python38\python.exe", 'sys_platform': 'win32', 'numpy_version': '1.19.2', 'scipy_version': '1.5.3', 'vtk_version': '9.0.1', 'matplotlib_version': '3.3.2'}
@skoudoro skoudoro added this to the v0.7.0 milestone Nov 21, 2020
@skoudoro skoudoro added good first issue Good for newcomers type:Bug Fix Something isn't working labels Nov 21, 2020
@sparkingdark
Copy link

Is this _opacity argument work to fade the color of the particles?
and another question are you test it in other os like ubuntu or any other os?

@SunTzunami
Copy link
Member Author

@sparkingdark opacity is meant to basically manipulate the transparency of the points. Points with opacity = 1 will be fully opaque and points with opacity = 0 will be fully transparent (we'll be able to see through them)
I haven't tested it on other OS but I don't think the results would be any different on other OS as the function that generates points does so by making use of the function that generates spheres and the function that generates spheres has no way of manipulating the opacity thus the point function technically has no way of manipulating the opacity.

@sparkingdark
Copy link

sparkingdark commented Nov 25, 2020 via email

@sparkingdark
Copy link

I think the problem is coming from the _opacity variable in actor.py and similar problem going after changing to 0.0 as you told.

@sparkingdark
Copy link

sparkingdark commented Nov 25, 2020

I don't see anything which take _opacity value and pass to sphere function,sphere function takes only centers, colors, radii=1., theta=16, phi=16,vertices=None, faces=None parameter.I think there something need to add to make it work.


def point(points, colors, _opacity=1., point_radius=0.1, theta=8, phi=8):
    """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
    opacity : float, optional
        Takes values from 0 (fully transparent) to 1 (opaque)

    Returns
    -------
    vtkActor

    Examples
    --------
    >>> from fury import window, actor
    >>> scene = window.Scene()
    >>> pts = np.random.rand(5, 3)
    >>> point_actor = actor.point(pts, window.colors.coral)
    >>> scene.add(point_actor)
    >>> # window.show(scene)

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


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

    Parameters
    ----------
    centers : ndarray, shape (N, 3)
        Spheres positions
    colors : ndarray (N,3) or (N, 4) or tuple (3,) or tuple (4,)
        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
    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.

    Returns
    -------
    vtkActor

    Examples
    --------
    >>> from fury import window, actor
    >>> scene = window.Scene()
    >>> centers = np.random.rand(5, 3)
    >>> sphere_actor = actor.sphere(centers, window.colors.coral)
    >>> scene.add(sphere_actor)
    >>> # window.show(scene)

    """
    src = vtk.vtkSphereSource() if faces is None else None

    if src is not None:
        src.SetRadius(1)
        src.SetThetaResolution(theta)
        src.SetPhiResolution(phi)

    actor = repeat_sources(centers=centers, colors=colors,
                           active_scalars=radii, source=src,
                           vertices=vertices, faces=faces)

    return actor

@SunTzunami
Copy link
Member Author

SunTzunami commented Nov 26, 2020

Thanks @sparkingdark. I think I've fixed it. Earlier, with opacity=0.2 and 1.0 respectively:
1

Now, with opacity=0.2 and 1.0 respectively:
vr

@skoudoro Should I make a PR?

@skoudoro
Copy link
Contributor

Yes, go ahead, do not forget to add a unittest. 👍

@sparkingdark
Copy link

sparkingdark commented Nov 27, 2020 via email

@SunTzunami
Copy link
Member Author

SunTzunami commented Nov 27, 2020

@sparkingdark sure
As I mentioned in my issue's description, the point function made use of the sphere function to generate points and sphere function had no way of assigning opacity to the actor. I knew that line actor's opacity argument worked thus I checked the documentation for it to see how it worked and extrapolated its working to ensure that sphere function's and point function's opacity too worked. I hope this answers your question! If you want, you can see #351 for the code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers type:Bug Fix Something isn't working
Projects
None yet
3 participants