Ejemplo n.º 1
0
    def setUp(self):
        """Initial setting up of test fixture, automatically called by TestCase before any other test method is invoked"""
        e = NullEngine()
        # Uncomment to see visualization for debugging etc.
        #e = Engine()
        e.start()
        e.new_scene()
        self.e = e

        r = VTKXMLFileReader()
        r.initialize(get_example_data('pyramid_ug.vtu'))
        e.add_source(r)
        r.point_scalars_name = 'temperature'
        o = Outline()
        e.add_module(o)
        c = Contour()
        e.add_filter(c)
        n = PolyDataNormals()
        e.add_filter(n)
        aa = SetActiveAttribute()
        e.add_filter(aa)
        aa.point_scalars_name = 'pressure'
        s = Surface()
        e.add_module(s)
        self.scene = e.current_scene
        return
Ejemplo n.º 2
0
def main():
    # Create the MayaVi engine and start it.
    e = Engine()
    # Starting the engine registers the engine with the registry and
    # notifies others that the engine is ready.
    e.start()

    # Do this if you need to see the MayaVi tree view UI.
    ev = EngineView(engine=e)
    ui = ev.edit_traits()

    # Create a new scene.
    scene = e.new_scene()
    # Now create a new scene just for kicks.
    scene1 = e.new_scene()

    # Now setup a normal MayaVi pipeline.
    src = VTKXMLFileReader()
    src.initialize(join(get_data_dir(abspath(__file__)),
                        'fire_ug.vtu'))
    e.add_source(src)
    e.add_module(Outline())
    e.add_module(ScalarCutPlane())
    e.add_module(Streamline())
    return e, ui
Ejemplo n.º 3
0
 def generate_data_mayavi(self):
     """Shows how you can generate data using mayavi instead of mlab."""
     from mayavi.sources.api import ParametricSurface
     from mayavi.modules.api import Outline, Surface
     e = self.scene.engine
     s = ParametricSurface()
     e.add_source(s)
     e.add_module(Outline())
     e.add_module(Surface())
Ejemplo n.º 4
0
    def xregister_mv_pipelines(self, e):
        '''Register as a source in the pipelane
        '''
        # Remarks[rch]:
        #
        # Pipeline construction
        # ---------------------
        # Maybe this should be done only on demand
        # when the visualization is requested either by the update
        # event triggered here, or by the user. For a batch-like
        # simulation no scenes would be necessary.
        #
        # In that case, the engine could be simply registered and
        # the pipeline construction can be deffered to the explicit
        # request.
        #
        # Further question concerns the multiplicity of the relations.
        # One tracer can construct several sources. The source can be
        # for example the standard array source or parametric surface.
        # There should be no link back to the tracer.
        #
        # Links between tracers and scenes
        # --------------------------------
        # On the other hand, several tracers can contribute to a single
        # scene. Then the tracer explicitly specifies the name
        # of the scene it is contributing to. This type of sharing makes
        # sence if the spatial context of the tracer is the same.
        #
        # The scene management is a separate issue, no general
        # rules can be formulated at this time.
        #
        scene = e.new_scene()
        scene.name = 'Polar domain'

        # Construct the source
        from mayavi.sources.vtk_data_source import VTKDataSource
        from tvtk.api import tvtk

        self._mv_src = VTKDataSource(name='Time-Strain Cylinder',
                                     data=tvtk.PolyData())
        e.add_source(self._mv_src)

        # Construct the warp filter
        if self.var_warp_on:
            from mayavi.filters.api import WarpVector
            e.add_filter(WarpVector())

        # Construct visualization modules
        from mayavi.modules.api import Outline, Surface
        s = Surface()
        e.add_module(Outline())
        e.add_module(s)
        s.module_manager.scalar_lut_manager.show_scalar_bar = True
        s.module_manager.scalar_lut_manager.reverse_lut = True
Ejemplo n.º 5
0
    def __init__(self, **kw):

        e = get_engine()

        super(MVPolyData, self).__init__(**kw)
        from mayavi.modules.api import Outline, Surface, Labels

        self.src = VTKDataSource(name=self.name, data=self.pd)
        e.add_source(self.src)

        o = Outline()
        e.add_module(o)
        s = Surface()
        e.add_module(s)
Ejemplo n.º 6
0
def view():
    from mayavi.sources.vtk_data_source import VTKDataSource
    from mayavi.modules.api import Outline, GridPlane

    mayavi.new_scene()
    src = VTKDataSource(data=sgrid)
    mayavi.add_source(src)
    mayavi.add_module(Outline())
    g = GridPlane()
    g.grid_plane.axis = 'x'
    mayavi.add_module(g)
    g = GridPlane()
    g.grid_plane.axis = 'y'
    mayavi.add_module(g)
    g = GridPlane()
    g.grid_plane.axis = 'z'
    mayavi.add_module(g)
Ejemplo n.º 7
0
def view3d(sgrid):
    from mayavi.sources.vtk_data_source import VTKDataSource
    from mayavi.modules.api import Outline, GridPlane
    from mayavi.api import Engine
    from mayavi.core.ui.engine_view import EngineView
    e=Engine()
    e.start()
    s = e.new_scene()
     # Do this if you need to see the MayaVi tree view UI.
    ev = EngineView(engine=e)
    ui = ev.edit_traits()

#    mayavi.new_scene()
    src = VTKDataSource(data=sgrid)
    e.add_source(src)
    e.add_module(Outline())
    g = GridPlane()
    g.grid_plane.axis = 'x'
    e.add_module(g)
Ejemplo n.º 8
0
def main():
    # Create the MayaVi offscreen engine and start it.
    e = OffScreenEngine()
    # Starting the engine registers the engine with the registry and
    # notifies others that the engine is ready.
    e.start()

    # Create a new scene.
    win = e.new_scene()

    # Now setup a normal MayaVi pipeline.
    src = VTKXMLFileReader()
    src.initialize(
        join(get_data_dir(dirname(abspath(__file__))), 'fire_ug.vtu'))
    e.add_source(src)
    e.add_module(Outline())
    e.add_module(ScalarCutPlane())
    e.add_module(Streamline())
    win.scene.isometric_view()
    # Change the size argument to anything you want.
    win.scene.save('offscreen.png', size=(800, 800))
Ejemplo n.º 9
0
def main():
    mayavi.new_scene()

    # Read the example data: fire_ug.vtu.
    r = VTKXMLFileReader()
    filename = join(mayavi2.get_data_dir(dirname(abspath(__file__))),
                    'fire_ug.vtu')
    r.initialize(filename)
    mayavi.add_source(r)
    # Set the active point scalars to 'u'.
    r.point_scalars_name = 'u'

    # Simple outline for the data.
    o = Outline()
    mayavi.add_module(o)

    # Branch the pipeline with a contour -- the outline above is
    # directly attached to the source whereas the contour below is a
    # filter and will branch the flow of data.   An isosurface in the
    # 'u' data attribute is generated and normals generated for it.

    c = Contour()
    mayavi.add_filter(c)
    n = PolyDataNormals()
    mayavi.add_filter(n)

    # Now we want to show the temperature 't' on the surface of the 'u'
    # iso-contour.  This is easily done by using the SetActiveAttribute
    # filter below.

    aa = SetActiveAttribute()
    mayavi.add_filter(aa)
    aa.point_scalars_name = 't'

    # Now view the iso-contours of 't' with a Surface filter.
    s = Surface(enable_contours=True)
    mayavi.add_module(s)
Ejemplo n.º 10
0
def contour():
    mayavi.new_scene()

    r = VTKFileReader()
    r.initialize('heart.vtk')
    mayavi.add_source(r)

    o = Outline()
    mayavi.add_module(o)

    gp = GridPlane()
    mayavi.add_module(gp)
    gp = GridPlane()
    mayavi.add_module(gp)
    gp.grid_plane.axis = 'y'
    gp = GridPlane()
    mayavi.add_module(gp)
    gp.grid_plane.axis = 'z'

    cgp = ContourGridPlane()
    mayavi.add_module(cgp)
    cgp.grid_plane.position = 15

    cgp = ContourGridPlane()
    mayavi.add_module(cgp)
    cgp.grid_plane.axis = 'y'
    cgp.grid_plane.position = 15
    cgp.contour.filled_contours = True

    iso = IsoSurface(compute_normals=True)
    mayavi.add_module(iso)
    iso.contour.contours = [220.0]

    cp = ScalarCutPlane()
    mayavi.add_module(cp)
    cp.implicit_plane.normal = 0, 0, 1
        self._engine.add_module(module)

    def add_filter(self, filter):
        self._engine.add_module(filter)

    def clear(self):
        self._engine.current_scene.scene.disable_render = True
        self._engine.current_scene.children[:] = []
        self._engine.current_scene.scene.disable_render = False

    #-----------------------------------------------------------------------
    # Private API
    #-----------------------------------------------------------------------

    def __engine_default(self):
        e = Engine()
        e.start()
        e.new_scene(self._scene)
        return e

if __name__ == '__main__':
    from pyface.api import GUI
    from mayavi.sources.api import ParametricSurface
    from mayavi.modules.api import Outline, Surface
    pw = PreviewWindow()
    pw.add_source(ParametricSurface())
    pw.add_module(Outline())
    pw.add_module(Surface())

    pw.edit_traits()
Ejemplo n.º 12
0
    def do(self):
        """Test for the SetActiveAttribute filter.
        """
        from mayavi.sources.api import VTKXMLFileReader
        from mayavi.filters.contour import Contour
        from mayavi.filters.api import PolyDataNormals
        from mayavi.filters.set_active_attribute import SetActiveAttribute
        from mayavi.modules.api import Surface, Outline

        mayavi = script = self.script

        scene = self.new_scene()
        r = VTKXMLFileReader()
        r.initialize(get_example_data('fire_ug.vtu'))
        mayavi.add_source(r)
        r.point_scalars_name = 'u'
        o = Outline()
        mayavi.add_module(o)
        c = Contour()
        mayavi.add_filter(c)
        n = PolyDataNormals()
        mayavi.add_filter(n)
        aa = SetActiveAttribute()
        mayavi.add_filter(aa)
        aa.point_scalars_name = 't'
        s = Surface()
        mayavi.add_module(s)

        scene.scene.isometric_view()
        # Check if things are OK.
        self.check()

        ############################################################
        # Test if saving a visualization and restoring it works.

        # Save visualization.
        f = BytesIO()
        f.name = abspath('test.mv2')  # We simulate a file.
        mayavi.save_visualization(f)
        f.seek(0)  # So we can read this saved data.

        # Remove existing scene.
        engine = mayavi.engine
        engine.close_scene(s)

        # Load visualization
        mayavi.load_visualization(f)
        s = engine.current_scene

        # Now do the check.
        s.scene.isometric_view()
        self.check()

        ############################################################
        # Test if the Mayavi2 visualization can be deep-copied.

        # Pop the source object.
        source = s.children.pop()
        # Add it back to see if that works without error.
        s.children.append(source)
        # Now do the check.
        self.check()

        # Now deepcopy the source and replace the existing one with
        # the copy.  This basically simulates cutting/copying the
        # object from the UI via the right-click menu on the tree
        # view, and pasting the copy back.
        source1 = copy.deepcopy(source)
        s.children[0] = source1
        # Now do the check.
        s.scene.isometric_view()
        self.check()