fury-gl / fury

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

tensor_slicer function has an issue with sphere argument #716

Closed Pedro-Filipe closed 1 year ago

Pedro-Filipe commented 1 year ago

Description

tensor_slicer function calls the function _tensor_slicer_mapper and passes the argument sphere but this variable is not handled properly.

For example if I call

scene.add(actor.tensor_slicer(evals, evecs))

Then I get:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/pf/mambaforge/envs/dipy/lib/python3.10/site-packages/fury/actor.py", line 1259, in tensor_slicer
    tensor_actor.display_extent(
  File "/Users/pf/mambaforge/envs/dipy/lib/python3.10/site-packages/fury/actor.py", line 1229, in display_extent
    self.mapper = _tensor_slicer_mapper(
  File "/Users/pf/mambaforge/envs/dipy/lib/python3.10/site-packages/fury/actor.py", line 1315, in _tensor_slicer_mapper
    faces = np.asarray(sphere.faces, dtype=int)
AttributeError: 'NoneType' object has no attribute 'faces'

The guilty line:

faces = np.asarray(sphere.faces, dtype=int)

Here we need an if statement to handle the case when sphere=None argument.

Not too complicated to solve, but if I do pass a sphere object:

sphere = get_sphere("repulsion200")
scene.add(actor.tensor_slicer(evals, evecs, sphere))

Then I get:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/pf/mambaforge/envs/dipy/lib/python3.10/site-packages/fury/actor.py", line 1259, in tensor_slicer
    tensor_actor.display_extent(
  File "/Users/pf/mambaforge/envs/dipy/lib/python3.10/site-packages/fury/actor.py", line 1229, in display_extent
    self.mapper = _tensor_slicer_mapper(
  File "/Users/pf/mambaforge/envs/dipy/lib/python3.10/site-packages/fury/actor.py", line 1313, in _tensor_slicer_mapper
    ijk = np.ascontiguousarray(apply_affine(affine, ijk))
  File "/Users/pf/mambaforge/envs/dipy/lib/python3.10/site-packages/fury/utils.py", line 852, in apply_affine
    rzs = aff[:-1, :-1]
IndexError: too many indices for array: array is 0-dimensional, but 2 were indexed

Error happens here:

    all_xyz = []
    all_faces = []
    for (k, center) in enumerate(ijk):
        ea = evals[tuple(center.astype(int))]
        if norm:
            ea /= ea.max()
        ea = np.diag(ea.copy())

        ev = evecs[tuple(center.astype(int))].copy()
        xyz = np.dot(ev, np.dot(ea, vertices.T))

        xyz = xyz.T
        all_xyz.append(scale * xyz + center)
        all_faces.append(faces + k * xyz.shape[0])

        cols[k, ...] = np.interp(
            cfa[tuple(center.astype(int))], [0, 1], [0, 255]
        ).astype("ubyte")

I am not really sure how to solve this. Any help is appreciated.

{'fury_version': '0.8.0', 'pkg_path': '/Users/pf/mambaforge/envs/dipy/lib/python3.10/site-packages/fury', 'commit_hash': 'b937ff3418e7c64b0fa89921a54c083ff78dc055', 'sys_version': '3.10.6 | packaged by conda-forge | (main, Aug 22 2022, 20:41:54) [Clang 13.0.1 ]', 'sys_executable': '/Users/pf/mambaforge/envs/dipy/bin/python', 'sys_platform': 'darwin', 'numpy_version': '1.23.4', 'scipy_version': '1.9.3', 'vtk_version': '9.2.2', 'matplotlib_version': '3.6.2', 'dipy_version': '1.5.0'}

Pedro-Filipe commented 1 year ago

Sorry, I was just inputing the wrong sphere. :/ Waste of time.