enthought / mayavi

3D visualization of scientific data in Python
http://docs.enthought.com/mayavi/mayavi/
Other
1.28k stars 282 forks source link

Error with VTK 9.3.0 #1286

Closed lciorciaro closed 3 weeks ago

lciorciaro commented 6 months ago

VTK version 9.3.0 produces an error in mayavi. The following code

from mayavi import mlab
import numpy as np

x = np.array([1, 1, 1, 2, 2, 2, 3, 3, 3])
y = np.array([11, 12, 13, 11, 12, 13, 11, 12, 13])
vs = np.array([5] * len(x))

fig = mlab.figure(1, fgcolor=(0, 0, 0), bgcolor=(1, 1, 1), size=(1400, 1900))

pts = mlab.points3d(x, y, vs, vs, scale_mode='none', scale_factor=0.2, figure=fig)

mlab.view(azimuth=8, elevation=65, distance=65)
mlab.show()

produces the error

Traceback (most recent call last):
  File "~/mayavi_test.py", line 10, in <module>
    pts = mlab.points3d(x, y, vs, vs, scale_mode='none', scale_factor=0.2, figure=fig)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/venv/lib/python3.11/site-packages/mayavi/tools/helper_functions.py", line 38, in the_function
    return pipeline(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/venv/lib/python3.11/site-packages/mayavi/tools/helper_functions.py", line 83, in __call__
    output = self.__call_internal__(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/venv/lib/python3.11/site-packages/mayavi/tools/helper_functions.py", line 178, in __call_internal__
    g = Pipeline.__call_internal__(self, *args, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/venv/lib/python3.11/site-packages/mayavi/tools/helper_functions.py", line 96, in __call_internal__
    return self.build_pipeline()
           ^^^^^^^^^^^^^^^^^^^^^
  File "~/venv/lib/python3.11/site-packages/mayavi/tools/helper_functions.py", line 124, in build_pipeline
    object = pipe(object, **this_kwargs)._target
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/venv/lib/python3.11/site-packages/mayavi/tools/modules.py", line 162, in __init__
    super(DataModuleFactory, self).__init__(*args, **kwargs)
  File "~/venv/lib/python3.11/site-packages/mayavi/tools/pipe_base.py", line 146, in __init__
    if issubclass(self._target.__class__, Filter):
                  ^^^^^^^^^^^^
  File "~/venv/lib/python3.11/site-packages/traits/trait_types.py", line 3673, in create_default_value
    return klass(*args[1:], **kw)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "~/venv/lib/python3.11/site-packages/mayavi/core/module.py", line 58, in __init__
    self.setup_pipeline()
  File "~/venv/lib/python3.11/site-packages/mayavi/modules/glyph.py", line 66, in setup_pipeline
    self.glyph = glyph.Glyph(scale_mode='scale_by_scalar',
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/venv/lib/python3.11/site-packages/mayavi/core/component.py", line 36, in __init__
    self.setup_pipeline()
  File "~/venv/lib/python3.11/site-packages/mayavi/components/glyph.py", line 157, in setup_pipeline
    self.glyph_source = glyph_source.GlyphSource()
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/venv/lib/python3.11/site-packages/mayavi/core/component.py", line 36, in __init__
    self.setup_pipeline()
  File "~/venv/lib/python3.11/site-packages/mayavi/components/glyph_source.py", line 128, in setup_pipeline
    self.glyph_source = self.glyph_dict['glyph_source2d']
                        ^^^^^^^^^^^^^^^
  File "~/venv/lib/python3.11/site-packages/mayavi/components/glyph_source.py", line 257, in _glyph_dict_default
    'cylinder_source': tvtk.CylinderSource(height=1.0, radius=0.15,
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "tvtk_classes/cylinder_source.py", line 55, in __init__
  File "~/venv/lib/python3.11/site-packages/tvtk/tvtk_base.py", line 432, in __init__
    self.update_traits()
  File "~/venv/lib/python3.11/site-packages/tvtk/tvtk_base.py", line 585, in update_traits
    setattr(self, name, val)
  File "~/venv/lib/python3.11/site-packages/traits/base_trait_handler.py", line 74, in error
    raise TraitError(
traits.trait_errors.TraitError: The 'lat_long_tessellation' trait of a CylinderSource instance must be 'f' or 'false' or 'n' or 'no' or 'off' or 'on' or 't' or 'true' or 'y' or 'yes' or -1 or 0 or 1, but a value of 32713 <class 'int'> was specified.

Under VTK version 9.2.6 everything works for me.

allucas commented 5 months ago

I am having the same issue, unfortunately if I go down to VTK 9.2.6, then I get a mismatch between TVTK (VTK=9.3) and VTK (VTK=9.2.6), and other parts of the application I have fail.

VoodooCode14 commented 5 months ago

I'm also facing this issue and I was able to isolate it to the "mayavi.mlab.points3d" call.

lciorciaro commented 3 weeks ago

Apologies for the inactivity. Fixed in release 4.8.2.