当前位置: 首页>>代码示例>>Python>>正文


Python mlab.get_engine函数代码示例

本文整理汇总了Python中mayavi.mlab.get_engine函数的典型用法代码示例。如果您正苦于以下问题:Python get_engine函数的具体用法?Python get_engine怎么用?Python get_engine使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_engine函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: render

    def render(self, scale_factor=1.0, text_scale=1.0, **kwargs):
        import mayavi.mlab as mlab
        # disabling the rendering greatly speeds up this for loop
        self.figure.scene.disable_render = True
        positions = []
        for label in self.lmark_group:
            p = self.lmark_group[label]
            for i, p in enumerate(p.points):
                positions.append(p)
                l = '%s_%d' % (label, i)
                # TODO: This is due to a bug in mayavi that won't allow
                # rendering text to an empty figure
                mlab.points3d(p[0], p[1], p[2], scale_factor=scale_factor)
                mlab.text3d(p[0], p[1], p[2], l, figure=self.figure,
                            scale=text_scale)
        positions = np.array(positions)
        os = np.zeros_like(positions)
        os[:, 2] = 1
        mlab.quiver3d(positions[:, 0], positions[:, 1], positions[:, 2],
                      os[:, 0], os[:, 1], os[:, 2], figure=self.figure)
        self.figure.scene.disable_render = False

        # Ensure everything fits inside the camera viewport
        mlab.get_engine().current_scene.scene.reset_zoom()

        return self
开发者ID:Loubnar,项目名称:menpo3d,代码行数:26,代码来源:viewmayavi.py

示例2: show

def show(cuds):
    """ Show the cuds objects using the default visualisation.

     Parameters
     ----------
     cuds :
         A top level cuds object (e.g. a mesh). The method will detect
         the type of object and create the appropriate visualisation.

    """
    if isinstance(cuds, (ABCMesh, ABCParticles, ABCLattice)):
        source = CUDSSource(cuds=cuds)
    else:
        msg = 'Provided object {} is not of any known cuds type'
        raise TypeError(msg.format(type(cuds)))

    modules = default_module(source)

    # ensure that a new scene is made
    mayavi_engine = mlab.get_engine()
    mayavi_engine.new_scene()

    # add source
    mayavi_engine.add_source(source)

    # add default modules
    for module in modules:
        mayavi_engine.add_module(module)

    mlab.show()
开发者ID:simphony,项目名称:simphony-mayavi,代码行数:30,代码来源:show.py

示例3: __init__

    def __init__(self, engine_name="", engine=None, mayavi_engine=None):
        '''
        Parameters
        ----------
        engine_name : str
            Name of the Simphony Modeling Engine wrapper

        engine : ABCModelingEngine
            Simphony Modeling Engine wrapper

        mayavi_engine : mayavi.api.engine
            Default to be mayavi.mlab.get_engine()

        '''
        # Traits initialisation
        HasTraits.__init__(self)

        if mayavi_engine is None:
            # Standalone Mayavi Engine
            mayavi_engine = mlab.get_engine()
        else:
            mayavi_engine = mayavi_engine

        # Add panels
        self.panels = TabbedPanelCollection.create(
            add_engine=AddEnginePanel(engine_manager=self),
            add_source=AddSourcePanel(engine_name=self.engine_name,
                                      engine=self.engine,
                                      mayavi_engine=mayavi_engine),
            run_and_animate=RunAndAnimatePanel(engine=self.engine,
                                               mayavi_engine=mayavi_engine))

        if engine and engine_name:
            self.add_engine(engine_name, engine)
开发者ID:simphony,项目名称:simphony-mayavi,代码行数:34,代码来源:engine_manager_standalone_ui.py

示例4: picker_callback

def picker_callback(picker):
    """ Picker callback: this get called when on pick events.
    """
    

    engine = mlab.get_engine()
    scene = engine.scenes[0]
    vtk_scene = scene.scene
    interactor = vtk_scene.interactor
    original_mouse_position = interactor.event_position
    render_window = vtk_scene.render_window
    #print(original_mouse_position)

    while(True):
        current_mouse_posiiton = interactor.event_position
        print(current_mouse_posiiton)
        wx.Yield()
        num_shaded_pixels = (abs(current_mouse_posiiton[0] - original_mouse_position[0]) + 1)*(abs(current_mouse_posiiton[1] - original_mouse_position[1]) + 1)
        render_window.set_pixel_data(original_mouse_position[0], original_mouse_position[1], current_mouse_posiiton[0], current_mouse_posiiton[1], [1,1,1]*num_shaded_pixels, 1)
        


    if picker.actor in red_glyphs.actor.actors:
        # Find which data point corresponds to the point picked:
        # we have to account for the fact that each data point is
        # represented by a glyph with several points
        point_id = picker.point_id/glyph_points.shape[0]
        # If the no points have been selected, we have '-1'
        if point_id != -1:
            # Retrieve the coordinnates coorresponding to that data
            # point
            x, y, z = x1[point_id], y1[point_id], z1[point_id]
开发者ID:sniyaz,项目名称:ASL,代码行数:32,代码来源:select_red_balls.py

示例5: mayavi_scraper

def mayavi_scraper(block, block_vars, gallery_conf):
    """Scrape Mayavi images.

    Parameters
    ----------
    block : tuple
        A tuple containing the (label, content, line_number) of the block.
    block_vars : dict
        Dict of block variables.
    gallery_conf : dict
        Contains the configuration of Sphinx-Gallery

    Returns
    -------
    rst : str
        The ReSTructuredText that will be rendered to HTML containing
        the images. This is often produced by
        :func:`sphinx_gallery.gen_rst.figure_rst`.
    """
    from mayavi import mlab
    image_path_iterator = block_vars['image_path_iterator']
    image_paths = list()
    e = mlab.get_engine()
    for scene, image_path in zip(e.scenes, image_path_iterator):
        mlab.savefig(image_path, figure=scene)
        # make sure the image is not too large
        scale_image(image_path, image_path, 850, 999)
        image_paths.append(image_path)
    mlab.close(all=True)
    return figure_rst(image_paths, gallery_conf['src_dir'])
开发者ID:Titan-C,项目名称:sphinx-gallery,代码行数:30,代码来源:scrapers.py

示例6: test_figure

    def test_figure(self):
        """ Various tests for mlab.figure().
        """
        # Test when specifying figure instances
        f1 = mlab.figure()
        e = mlab.get_engine()
        self.assertTrue(e.current_scene is f1)
        f2 = mlab.figure()
        self.assertTrue(e.current_scene is f2)
        mlab.figure(f1)
        self.assertTrue(e.current_scene is f1)

        # Test when specifying figure numbers
        f1 = mlab.figure(3)
        self.assertTrue(e.current_scene is f1)
        f2 = mlab.figure(4)
        self.assertTrue(e.current_scene is f2)
        mlab.figure(3)
        self.assertTrue(e.current_scene is f1)

        # Test when specifying figure names
        f1 = mlab.figure('Test 1')
        self.assertTrue(e.current_scene is f1)
        f2 = mlab.figure('Test 2')
        self.assertTrue(e.current_scene is f2)
        mlab.figure('Test 1')
        self.assertTrue(e.current_scene is f1)
开发者ID:enthought,项目名称:mayavi,代码行数:27,代码来源:test_mlab_integration.py

示例7: setUp

    def setUp(self):
        # set up source
        sgrid = datasets.generateStructuredGrid()
        source = VTKDataSource(data=sgrid)

        self.engine = mlab.get_engine()

        # set up scene, first scene is empty
        # second scene has the settings we want to restore
        for _ in range(2):
            fig = mlab.figure()
            fig.scene.off_screen_rendering = True

        # add source
        self.engine.add_source(source)

        # add more modules
        self.engine.add_module(IsoSurface())
        self.engine.add_module(Text3D())
        self.modules = source.children[0].children

        # set camera
        self.view = (25., 14., 20., [0., 0., 2.5])
        mlab.view(*self.view)

        # save the visualisation
        self.temp_dir = tempfile.mkdtemp()
        self.filename = os.path.join(self.temp_dir, "test_vis.mv2")
        self.engine.save_visualization(self.filename)

        # save the scene as an image for comparison later
        self.ref_saved_filename = os.path.join(self.temp_dir, "ref_saved.png")
        mlab.savefig(self.ref_saved_filename)
开发者ID:simphony,项目名称:simphony-mayavi,代码行数:33,代码来源:test_restore_scene.py

示例8: new_func

 def new_func(test_case):
     try:
         func(test_case)
     finally:
         num_scenes = len(mlab.get_engine().scenes)
         test_case.assertNotEqual(num_scenes, 0,
                                  "No scene is opened")
         # close everything
         mlab.close(all=True)
开发者ID:simphony,项目名称:simphony-mayavi,代码行数:9,代码来源:test_show.py

示例9: tearDown

 def tearDown(self):
     # Check that the NullEngine is still the mlab engine
     if not mlab.get_engine() is self.e:
         raise AssertionError, \
                 "The NullEngine has been overridden"
     engine_manager.current_engine = None
     # Unregistering the engine, to avoid side-effects between tests
     self.e.stop()
     registry.unregister_engine(self.e)
开发者ID:GaelVaroquaux,项目名称:mayavi,代码行数:9,代码来源:test_mlab_integration.py

示例10: test_save_load_visualization_with_mlab

    def test_save_load_visualization_with_mlab(self):
        # test mlab.get_engine
        engine = mlab.get_engine()

        try:
            self.check_save_load_visualization(engine)
        finally:
            mlab.clf()
            mlab.close(all=True)
开发者ID:simphony,项目名称:simphony-mayavi,代码行数:9,代码来源:test_cuds_source.py

示例11: serve_udp

def serve_udp(engine=None, port=9007, logto=sys.stdout):
    """Serve the `M2UDP` protocol using the given `engine` on the
    specified `port` logging messages to given `logto` which is a
    file-like object.  This function will block till the service is
    closed.  There is no need to call `mlab.show()` after or before
    this.  The Mayavi UI will be fully responsive.

    **Parameters**

     :engine: Mayavi engine to use. If this is `None`,
              `mlab.get_engine()` is used to find an appropriate engine.

     :port: int: port to serve on.

     :logto: file : File like object to log messages to.  If this is
                    `None` it disables logging.

    **Examples**

    Here is a very simple example::

        from mayavi import mlab
        from mayavi.tools import server
        mlab.test_plot3d()
        server.serve_udp()

    Test it like so::

        import socket
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.bind(('', 9008))
        s.sendto('camera.azimuth(10)', ('', 9007))

    **Warning**

    Data sent is exec'd so this is a security hole.
    """

    from mayavi import mlab
    e = engine or mlab.get_engine()
    # Setup the protocol with the right attributes.
    proto = M2UDP()
    proto.engine = e
    proto.scene = e.current_scene.scene
    proto.mlab = mlab

    if logto is not None:
        log.startLogging(logto)
    log.msg('Serving Mayavi2 UDP server on port', port)
    log.msg('Using Engine', e)

    # Register the running wxApp.
    reactor.registerWxApp(wx.GetApp())
    # Listen on port 9007 using above protocol.
    reactor.listenUDP(port, proto)
    # Run the server + app.  This will block.
    reactor.run()
开发者ID:PerryZh,项目名称:mayavi,代码行数:57,代码来源:server.py

示例12: tearDown

 def tearDown(self):
     # Check that the NullEngine was not set as the default mlab engine.
     if not mlab.get_engine() is self._non_null_engine:
         raise AssertionError("The NullEngine has overridden the default one")
     engine_manager.current_engine = None
     # Unregistering all unused engines.
     registry.unregister_engine(self._non_null_engine)
     for engine in list(registry.engines):
         registry.unregister_engine(engine)
开发者ID:PerryZh,项目名称:mayavi,代码行数:9,代码来源:test_mlab_null_engine.py

示例13: close

def close():
    """Close the scene."""
    f = mlab.gcf()
    e = mlab.get_engine()
    e.window.workbench.prompt_on_exit = False
    e.window.close()
    mlab.options.backend = 'auto'
    # Hack: on Linux the splash screen does not go away so we force it.
    GUI.invoke_after(500, e.window.workbench.application.gui.stop_event_loop)
开发者ID:B-Rich,项目名称:mayavi,代码行数:9,代码来源:test_mlab_envisage.py

示例14: __init__

    def __init__(self, hex_list, np_file='/tmp/magnetic_ground_truth.np', robot_height=40, width=800, height=600,
                 start_point=(0, 0, 0), message='experiment default message...'):
        self.debug = False
        self.animator = None
        self.movement_mode = 0
        self.start_point = start_point
        self.robot_height = robot_height
        self.message = message

        self.start_time = int(time.time() * 1000)

        self.width = width
        self.height = height

        self.f = mlab.figure(size=(self.width, self.height))
        visual.set_viewer(self.f)

        v = mlab.view(270, 180)
        #print v

        engine = mlab.get_engine()
        self.s = engine.current_scene
        self.s.scene.interactor.add_observer('KeyPressEvent', self.keypress_callback)

        self.robots = []

        colors = list(PathBatterySimulator.color_codes)

        for key, local_hex_list in sorted(hex_list['internal_routes'].items()):
            color = colors.pop(0)

            ball = visual.sphere(color=color, radius=PathBatterySimulator.ball_radius)
            ball.x = self.start_point[0]
            ball.y = self.start_point[1]
            ball.z = self.start_point[2]

            r, g, b = color
            rt = r + (0.25 * (1 - r))
            gt = g + (0.25 * (1 - g))
            bt = b + (0.25 * (1 - b))
            curve_color = (rt, gt, bt)

            curve = visual.curve(color=curve_color, radius=PathBatterySimulator.curve_radius)

            r_ball = RobotBall(key, local_hex_list, hex_list['external_routes'][key], ball, curve)
            self.robots.append(r_ball)

        x = np.linspace(0, self.width, 1)
        y = np.linspace(0, self.height, 1)

        z = np.loadtxt(np_file)
        z *= 255.0/z.max()
        mlab.surf(x, y, z)

        self.master_cmd = MasterCommand(self.robots)
开发者ID:h3ct0r,项目名称:RouteHexagonSim,代码行数:55,代码来源:path_battery_simulator.py

示例15: tearDown

 def tearDown(self):
     # Check that the NullEngine is still the mlab engine
     current_engine = mlab.get_engine()
     engine_overridden = current_engine is not self.e
     engine_manager.current_engine = None
     self.e.stop()
     registry.unregister_engine(self.e)
     if engine_overridden:
         current_engine.stop()
         registry.unregister_engine(current_engine)
         raise AssertionError("The NullEngine has been overridden")
开发者ID:enthought,项目名称:mayavi,代码行数:11,代码来源:test_mlab_integration.py


注:本文中的mayavi.mlab.get_engine函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。