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] Propagate update_actor #387

Merged
merged 5 commits into from Feb 26, 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
5 changes: 1 addition & 4 deletions README.md
Expand Up @@ -9,10 +9,7 @@
</h4>

<p align="center">
<a href="https://travis-ci.com/fury-gl/fury">
<img src="https://travis-ci.com/fury-gl/fury.svg?branch=master" alt="Fury Travis">
</a>
<a href="https://dev.azure.com/fury-gl/fury/_build/latest?definitionId=1&branchName=master"><img src="https://dev.azure.com/fury-gl/fury/_apis/build/status/fury-gl.fury?branchName=master">
<a href="https://dev.azure.com/fury-gl/fury/_build/latest?definitionId=1&branchName=master"><img src="https://dev.azure.com/fury-gl/fury/_apis/build/status/fury-gl.fury?branchName=master">
</a>
<a href="https://pypi.python.org/pypi/fury"><img src="https://img.shields.io/pypi/v/fury.svg"></a>
<a href="https://anaconda.org/conda-forge/fury"><img src="https://anaconda.org/conda-forge/fury/badges/version.svg"></a>
Expand Down
20 changes: 20 additions & 0 deletions fury/tests/test_utils.py
Expand Up @@ -335,7 +335,27 @@ def test_vertices_from_actor(interactive=False):
scene.add(actr)
window.show(scene)
res_vertices = vertices_from_actor(actr)
res_vertices_vtk = vertices_from_actor(actr, as_vtk=True)

npt.assert_array_almost_equal(expected, res_vertices)
npt.assert_equal(isinstance(res_vertices_vtk, vtk.vtkDoubleArray), True)

# test colors_from_actor:
l_colors = utils.colors_from_actor(actr)
l_colors_vtk = utils.colors_from_actor(actr, as_vtk=True)
l_colors_none = utils.colors_from_actor(actr, array_name='col')

npt.assert_equal(l_colors_none, None)
npt.assert_equal(isinstance(l_colors_vtk, vtk.vtkUnsignedCharArray), True)
npt.assert_equal(np.unique(l_colors, axis=0).shape, colors.shape)

l_array = utils.array_from_actor(actr, 'colors')
l_array_vtk = utils.array_from_actor(actr, 'colors', as_vtk=True)
l_array_none = utils.array_from_actor(actr, 'col')

npt.assert_array_equal(l_array, l_colors)
npt.assert_equal(l_array_none, None)
npt.assert_equal(isinstance(l_array_vtk, vtk.vtkUnsignedCharArray), True)


def test_get_actor_from_primitive():
Expand Down
56 changes: 47 additions & 9 deletions fury/utils.py
Expand Up @@ -1008,41 +1008,70 @@ def fix_winding_order(vertices, triangles, clockwise=False):
return corrected_triangles


def vertices_from_actor(actor):
def vertices_from_actor(actor, as_vtk=False):
"""Access to vertices from actor.

Parameters
----------
actor : actor
as_vtk: bool, optional
by default, ndarray is returned.

Returns
-------
vertices : ndarray

"""
return numpy_support.vtk_to_numpy(actor.GetMapper().GetInput().
GetPoints().GetData())
vtk_array = actor.GetMapper().GetInput().GetPoints().GetData()
if as_vtk:
return vtk_array

return numpy_support.vtk_to_numpy(vtk_array)

def colors_from_actor(actor, array_name='colors'):

def colors_from_actor(actor, array_name='colors', as_vtk=False):
"""Access colors from actor which uses polydata.

Parameters
----------
actor : actor
array_name: str
as_vtk: bool, optional
by default, numpy array is returned.

Returns
-------
output : array (N, 3)
Colors

"""
vtk_colors = \
return array_from_actor(actor, array_name=array_name,
as_vtk=as_vtk)


def array_from_actor(actor, array_name, as_vtk=False):
"""Access array from actor which uses polydata.

Parameters
----------
actor : actor
array_name: str
as_vtk_type: bool, optional
by default, ndarray is returned.

Returns
-------
output : array (N, 3)

"""
vtk_array = \
actor.GetMapper().GetInput().GetPointData().GetArray(array_name)
if vtk_colors is None:
if vtk_array is None:
return None
if as_vtk:
return vtk_array

return numpy_support.vtk_to_numpy(vtk_colors)
return numpy_support.vtk_to_numpy(vtk_array)


def compute_bounds(actor):
Expand All @@ -1056,15 +1085,24 @@ def compute_bounds(actor):
actor.GetMapper().GetInput().ComputeBounds()


def update_actor(actor):
def update_actor(actor, all_arrays=True):
"""Update actor.

Parameters
----------
actor : actor
all_arrays: bool, optional
if False, only vertices are updated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if True ...

if True, all arrays associated to the actor are updated
Default: True

"""
actor.GetMapper().GetInput().GetPoints().GetData().Modified()
pd = actor.GetMapper().GetInput()
pd.GetPoints().GetData().Modified()
if all_arrays:
nb_array = pd.GetPointData().GetNumberOfArrays()
for i in range(nb_array):
pd.GetPointData().GetArray(i).Modified()


def get_bounds(actor):
Expand Down