Open andrew2hart opened 7 years ago
from mayavi import mlab
import numpy as np
my=np.array([[1,2,3],[4,5,6],[7,8,9]])
src=mlab.pipeline.scalar_field(my)
mlab.pipeline.volume(src)
Is enough to cause it.
I am experiencing the same with VTK 7.1. Trying the volumetric rendering example of mayavi
import numpy as np
x,y,z = np.ogrid[-10:10:20j,-10:10:20j,-10:10:20j]
s = np.sin(x*y*z)/(x*y*z)
from mayavi import mlab
mlab.pipeline.volume(mlab.pipeline.scalar_field(s))
mlab.show()
produces
Generic Warning: In /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_graphics_vtk/vtk/work/VTK-7.1.0/Common/ExecutionModel/vtkAlgorithm.cxx, line 1808
vtkAlgorithm::SetUpdateExtent was deprecated for VTK 7.1 and will be removed in a future version.
Generic Warning: In /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_graphics_vtk/vtk/work/VTK-7.1.0/Common/ExecutionModel/vtkAlgorithm.cxx, line 1796
vtkAlgorithm::SetUpdateExtent was deprecated for VTK 7.1 and will be removed in a future version.
Generic Warning: In /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_graphics_vtk/vtk/work/VTK-7.1.0/Common/ExecutionModel/vtkStreamingDemandDrivenPipeline.cxx, line 1531
vtkStreamingDemandDrivenPipeline::SetUpdateExtent was deprecated for VTK 7.1 and will be removed in a future version.
Traceback (most recent call last):
File "volume.py", line 7, in <module>
mlab.pipeline.volume(mlab.pipeline.scalar_field(s))
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mayavi/tools/pipe_base.py", line 38, in the_function
factory = factory_class(*args, **kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mayavi/tools/pipe_base.py", line 146, in __init__
if issubclass(self._target.__class__, Filter):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/traits/trait_types.py", line 2801, in create_default_value
return klass( *args[1:], **kw )
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mayavi/core/module.py", line 58, in __init__
self.setup_pipeline()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mayavi/modules/volume.py", line 318, in setup_pipeline
available_mappers = find_volume_mappers()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mayavi/modules/volume.py", line 53, in find_volume_mappers
inst = klass()
File "tvtk_classes/smart_volume_mapper.py", line 108, in __init__
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tvtk/tvtk_base.py", line 341, in __init__
self.update_traits()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tvtk/tvtk_base.py", line 496, in update_traits
setattr(self, name, val)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/traits/trait_handlers.py", line 172, in error
value )
traits.trait_errors.TraitError: The 'vector_component' trait of a SmartVolumeMapper instance must be 0 <= an integer <= 3, but a value of 557520968 <type 'int'> was specified.
Yes, your code crashed the third time I ran it.(python 3.5.1, vtk 7.1.1, linux)
Ok. I should maybe add that I am on Mac OS X, Sierra (10.12.4) with MacPorts py27-mayavi.
[~] $ python
Python 2.7.13 (default, Dec 18 2016, 05:36:03)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
[~] $ python -c "import mayavi.version; print mayavi.version.version"
4.5.0
[~] $ port installed | grep vtk
vtk @7.1.0_0+python27 (active)
But as far as I understand this seems to be an issue with the VTK 7.1 library?
Any developer out there?
This is an issue for me under Python 3.6, VTK 7.1 with certain failure under OSX, and Linux. Under Windows, the problem is intermittent. On Linux, changing the definition of vector_component in tvtk.tvtk_classes.smart_volume_mapper.py of the install directory from
-vector_component = traits.Trait(2037150581, 2037150581, traits.Range(0, 3, enter_set=True, auto_set=False), help=\
+vector_component = traits.Trait(-1, help=\
allows it to run with (so far) no failures. It's not desirable, nor an easy change to make if the folder is zipped, but it might shed some light on the source of the problem.
I can reproduce it with VTK 7.1, Python 2.7 on GNU/Linux.
I added a while loop to your test code and for me it works after some (2 to 7) failures. My configuration: Linux, python 3.6 (virtualenv) + git version of mayavi + vtk 8.1.0 (git verion).
import numpy as np
x,y,z = np.ogrid[-10:10:20j,-10:10:20j,-10:10:20j]
s = np.sin(x*y*z)/(x*y*z)
from mayavi import mlab
while 1:
try:
mlab.pipeline.volume(mlab.pipeline.scalar_field(s))
break
except:
print('Nope :(')
mlab.show()
Same script fails on MacOS Sierra + python 3.5 + mayavi 4.5.0 + vtk 7.1.1
MacOS mayavi-master python 3.6 VTK-8.0.1 raises TypeError
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mayavi/tools/pipe_base.py", line 38, in the_function
factory = factory_class(*args, **kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mayavi/tools/pipe_base.py", line 146, in __init__
if issubclass(self._target.__class__, Filter):
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/traits/trait_types.py", line 2800, in create_default_value
return klass( *args[1:], **kw )
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mayavi/core/module.py", line 58, in __init__
self.setup_pipeline()
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mayavi/modules/volume.py", line 307, in setup_pipeline
self._ctf = ctf = default_CTF(0, 255)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mayavi/modules/volume.py", line 125, in default_CTF
mode='sqrt')
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mayavi/modules/volume.py", line 103, in make_CTF
ctf.add_rgb_point(mins+x*ds, r, g, b)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tvtk/util/ctf.py", line 210, in add_rgb_point
self.nodes.sort()
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/traits/trait_handlers.py", line 2566, in sort
list.sort( self, cmp = cmp, key = key, reverse = reverse )
TypeError: sort() takes at most 2 arguments (3 given)
I'm facing the same issue when using the mlab.pipeline.volume() Setup: Win 10 64bits, Python 2.7, VTK 7.1, mayavi 4.5.0
The workaround proposed by @braidedlogix is working well for me. Thanks very much.
I'm facing exactly the same issue when using mlab.pipeline.volume() Setup: Fedora27, Python3.6, VTK7.1, mayavi 4.5.0, virtualenv
@braidedlogix's method also works for me. Thx.
This code gives an intermittent error with vtk > 6.3
traits.trait_errors.TraitError: The 'vector_component' trait of a SmartVolumeMapper instance must be 0 <= a long integer <= 3, but a value of 1750425008 <class 'int'> was specified. The number is not always the same and some times there is no error. Changing to vtk 6.3 fixes the problem and it occurs in python 2 and 3. This is code cut down to show the error. I also tried similar code in fedora rawhide which is the only one with vtk7.1 as yet.