Comments (7)
My first attempt on fixing this issue is here:
https://github.com/mluessi/mayavi/tree/multifig_text
Unfortunately, it still doesn't work. find_figure_engine() finds the right engine, but the text still gets added to the wrong figure.
PS: Is there a reason why find_figure_engine() throws and exception if the engine is not found? I think it would be nicer if it returned None.
from mayavi.
Same here, just run into it yesterday. I even tried to separate the engines as described here - http://docs.enthought.com/mayavi/mayavi/auto/example_multiple_engines.html#example-multiple-engines but still no luck.
from mayavi.
Forgot to mention, I'm using text3d() not text(), but problem is the same.
from mayavi.
All right, I've found the way how to fix it (not sure if it is the right way to do it, but it works like a charm now).
Here is the fixed init() function of the PipeFactory class from mayavi.tools.pipe_base.py:
def __init__(self, parent, **kwargs):
# We are not passing the traits to the parent class
super(PipeFactory, self).__init__()
# Try to find the right engine and scene to work with
override_figure = None
if 'figure' in kwargs and kwargs['figure'] is not None:
override_figure = kwargs['figure']
ancester = parent
while hasattr(ancester, 'parent'):
ancester = getattr(ancester, 'parent')
if isinstance(ancester, Scene):
self._scene = override_figure if override_figure else ancester
break
else:
if override_figure:
self._scene = override_figure
elif self.figure is not None:
self._scene = self.figure
else:
self._scene = tools.gcf()
self._engine = get_engine()
if not self._engine: self._engine = self._scene.parent
scene = self._scene.scene
if self.figure is not None and self.figure is not self._scene:
warnings.warn('Trying to add a module on the wrong scene')
if isinstance(parent, (Source, tvtk.DataSet)) \
and not isinstance(parent, Filter) and scene is not None:
# Search the current scene to see if the source is already
# in it, if not add it.
if not parent in self._scene.children:
parent = tools.add_dataset(parent, figure=self._scene)
if scene is not None:
self._do_redraw = not scene.disable_render
scene.disable_render = True
if issubclass(self._target.__class__, Filter):
self._engine.add_filter(self._target, obj=parent)
else:
self.add_module(parent, kwargs)
# Inject the magical mlab source trait.
if hasattr(parent, 'mlab_source'):
ms = parent.mlab_source
self._target.add_trait('mlab_source', Instance(ms.__class__))
self._target.mlab_source = ms
traits = self.get(self.class_trait_names())
[traits.pop(key) for key in traits.keys()
if key[0]=='_' or key is None]
traits.update(kwargs)
# Now calling the traits setter, so that traits handlers are
# called
self.set(**traits)
if scene is not None:
scene.disable_render = not self._do_redraw
from mayavi.
Confirmed as still present. The provided code does not solve the issue. Investigating.
from mayavi.
After investigation, the problem is the following.
The PipeFactory (in its specific instance for the TextFactory), calls add_module, which in turn works on the only available engine calling engine.add_module(), which in turns calls add_filter() which in turn wants an object of the pipeline. If an object is not present, it uses the current one.
The problem occurs because the current one is the second Surface we create.
So now I am in a conundrum. Do we have this problem because there's only one engine (while there should actually be two, one per each scene) or is it because we have one, but the current object should be replaced with the first surface? If the second, the problem is that we don't pass the surface object, we pass the destination scene. How are we supposed to obtain the surface object and are we allowed to replace current_object in the engine?
I can't proceed further until the proper design assumptions are clarified, I need @prabhuramachandran to weigh in.
I will leave this issue open and move to something else.
from mayavi.
I hope this issue gets fixed, I spent way too much time trying to figure out why mlab kept adding a surface object to the wrong scene (scene 2 instead of scene 1 for a two MlabSceneModel object).
Finally saw stefanoborini's post, gave up trying to add using mlab pipeline and directly added the actor using tvtk.
from mayavi.
Related Issues (20)
- How to volume render a transparent space with mlab.pipleine.volume() and mlab.pipleine.scalar_field() as a data source?? HOT 1
- Error with VTK 9.3.0 HOT 3
- Failed Cython compilation (Cython > 3.0) HOT 2
- mlab.savefig saves wrong resolution (for first two images in loop)
- Potential issue with upcoming changes in VTK
- itkwidgets error in Jupyter Notebook
- Update a mayavi plot programmatically
- Release? HOT 6
- Warnings reported in the Mayavi testsuite
- Warnings and errors reported by the tvtk testsuite
- ImportError: Could not import backend for traitsui.
- Moving the cursor into a mayavi window causes a crash
- pip install not working HOT 2
- [regression in 4.8.2] TVTK not built properly. HOT 1
- Mayavi example protein.py not working, plus the solution
- Scalar filed is not volume rendered with a colormap HOT 1
- GUI stutters when running an animation
- Problem getting started with Mayavi HOT 1
- When use mlab.figure, got error "AttributeError: type object 'Unimplemented' has no attribute 'process_events'" HOT 1
- wxPython not supported
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mayavi.