Git Product home page Git Product logo

Comments (7)

mluessi avatar mluessi commented on July 16, 2024

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.

itohnobue avatar itohnobue commented on July 16, 2024

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.

itohnobue avatar itohnobue commented on July 16, 2024

Forgot to mention, I'm using text3d() not text(), but problem is the same.

from mayavi.

itohnobue avatar itohnobue commented on July 16, 2024

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.

stefanoborini avatar stefanoborini commented on July 16, 2024

Confirmed as still present. The provided code does not solve the issue. Investigating.

from mayavi.

stefanoborini avatar stefanoborini commented on July 16, 2024

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.

moosekaka avatar moosekaka commented on July 16, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.