예제 #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

        # Read the multi-block plot3d file.
        r = PLOT3DReader()
        r.reader.set(has_byte_count=True, multi_grid=True,
                     byte_order='little_endian')
        r.initialize(get_example_data('tiny.xyz'),
                     get_example_data('tiny.q'), 
                     configure=False)

        e.add_source(r)
        # Add the filter.
        f = SelectOutput()
        e.add_filter(f)

        # Create an outline for the data.
        o = Outline()
        e.add_module(o)
        o.render()
        self.o=o
        self.r=r
        self.e=e
        self.scene = e.current_scene
        return
예제 #2
0
    def test_multipe_readers(self):
        "Test if reader conflict is resolved"
        # Testing two files with same extensions but have to be read
        # by different readers
	reader = registry.get_file_reader(get_example_data('tiny.xyz'))
        callable = reader.get_callable()
        self.assertEqual(callable.__name__, 'PLOT3DReader')
 
        reader = registry.get_file_reader(get_example_data('thio3xx.xyz'))
        callable = reader.get_callable()
        self.assertEqual(callable.__name__, 'PolyDataReader')
예제 #3
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
예제 #4
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

        # Read a VTK (old style) data file.
        r = VTKXMLFileReader()
        r.initialize(get_example_data("pyramid_ug.vtu"))
        e.add_source(r)

        # Create the filters.
        # CellDerivatives
        cd = tvtk.CellDerivatives()
        ud = UserDefined(filter=cd)
        e.add_filter(ud)
        ctp = CellToPointData()
        ctp.filter.pass_cell_data = False
        e.add_filter(ctp)
        evn = ExtractVectorNorm()
        e.add_filter(evn)
        evc = ExtractVectorComponents(component="y-component")
        o = Optional(filter=evc)
        e.add_filter(o)
        e.add_module(ScalarCutPlane())
        self.scene = e.current_scene
        s = self.scene
        return
예제 #5
0
    def test_no_valid_reader(self):
        """Test that if there is no reader which can read the file with 
        assurity, the registry returns the last one of the readers
        which dont have a can_read_test and claim to read the file with
        the given extension"""
        open_dummy = SourceMetadata(
                id            = "DummyFile",
                class_name    = "enthought.mayavi.tests.test_registry.DummyReader",
                menu_name     = "&PLOT3D file",
                tooltip       = "Open a PLOT3D data data",
                desc        = "Open a PLOT3D data data",
                help        = "Open a PLOT3D data data",
                extensions = ['xyz'],
                wildcard = 'PLOT3D files (*.xyz)|*.xyz',
                can_read_test = 'enthought.mayavi.tests.test_registry:DummyReader.check_read',
                output_info = PipelineInfo(datasets=['structured_grid'],
                    attribute_types=['any'],
                    attributes=['any'])
                )
        registry.sources.append(open_dummy)

        # Remove the poly data reader.
        for index, src in enumerate(registry.sources[:]):
            if src.id == 'PolyDataFile':
                poly = src
                registry.sources.remove(src)
                break
        
        reader = registry.get_file_reader(get_example_data('tiny.xyz'))
        callable = reader.get_callable()
        self.assertEqual(callable.__name__, 'PLOT3DReader')

        # Add back the poly data reader.
        registry.sources.insert(index, poly)
        registry.sources.remove(open_dummy)
예제 #6
0
    def test_with_unstructured_data(self):
        e = self.e

        # Read a AVSUCD data file.
        r = UnstructuredGridReader()
        r.initialize(get_example_data('cellsnd.ascii.inp'))
        e.add_source(r)

        self.check()
    def setup_reader(self):

        """"Setup the reader in here.  This is called after the engine
        has been created and started.  The engine is available as
        self.e.  This method is called by setUp().
        """
        # Read a Exodus data file.
        r = UnstructuredGridReader()
        r.initialize(get_example_data('disk_out_ref.ex2'))
        self.e.add_source(r)
예제 #8
0
    def setup_reader(self):

        """"Setup the reader in here.  This is called after the engine
        has been created and started.  The engine is available as
        self.e.  This method is called by setUp().
        """
        # Read a SLC data file.
        r = PolyDataReader()
        r.initialize(get_example_data('nut.slc'))
        self.e.add_source(r)
        self.bounds =  (0.0, 67.0, 0.0, 40.0, 0.0, 58.0)
예제 #9
0
    def setup_reader(self):

        """"Setup the reader in here.  This is called after the engine
        has been created and started.  The engine is available as
        self.e.  This method is called by setUp().
        """
        # Read a STL data file.
        r = PolyDataReader()
        r.initialize(get_example_data('humanoid_tri.stla'))
        self.e.add_source(r)
        self.bounds =  (0.60, 3.47, -3.96, 3.95, 3.05, 17.39)
예제 #10
0
    def setup_reader(self):

        """"Setup the reader in here.  This is called after the engine
        has been created and started.  The engine is available as
        self.e.  This method is called by setUp().
        """
        # Read a AVSUCD data file.
        r = UnstructuredGridReader()
        r.initialize(get_example_data('cellsnd.ascii.inp'))
        self.e.add_source(r)
        self.bounds =(-2.0, 2.0, -2.0, 2.0, 0.0, 0.0)
예제 #11
0
 def setup_reader(self):
     
     """"Setup the reader in here.  This is called after the engine 
     has been created and started.  The engine is available as 
     self.e.  This method is called by setUp().
     """
      # Read a DEM Image file.
     r = ImageReader()
     r.initialize(get_example_data('example.dem'))
     self.e.add_source(r)
     self.bounds =(557945.0, 567725.0, 5107991.5, 5121971.5, 682.0, 682.0)
예제 #12
0
    def setup_reader(self):

        """"Setup the reader in here.  This is called after the engine
        has been created and started.  The engine is available as
        self.e.  This method is called by setUp().
        """
        # Read a OBJ data file.
        r = PolyDataReader()
        r.initialize(get_example_data('shuttle.obj'))
        self.e.add_source(r)
        self.bounds = (-7.65, 7.04, -4.68, 4.68, -1.35, 4.16)
예제 #13
0
 def setup_reader(self):
     
     """"Setup the reader in here.  This is called after the engine 
     has been created and started.  The engine is available as 
     self.e.  This method is called by setUp().
     """
      # Read a Meta Image file.
     r = ImageReader()
     r.initialize(get_example_data('foot.mha'))
     self.e.add_source(r)
     self.bounds =(0.0, 255.0, 0.0, 255.0, 0.0, 0.0)
예제 #14
0
    def setup_reader(self):

        """"Setup the reader in here.  This is called after the engine
        has been created and started.  The engine is available as
        self.e.  This method is called by setUp().
        """
        # Read a Gambit data file.
        r = UnstructuredGridReader()
        r.initialize(get_example_data('prism.neu'))
        self.e.add_source(r)
        self.bounds = (-1.0, 1.0, -1.0, 1.0, 0.0, 1.0)
예제 #15
0
    def setup_reader(self):

        """"Setup the reader in here.  This is called after the engine
        has been created and started.  The engine is available as
        self.e.  This method is called by setUp().
        """
        # Read a Facet data file.
        r = PolyDataReader()
        r.initialize(get_example_data('clown.facet'))
        self.e.add_source(r)
        self.bounds = (-0.5, 0.69, -0.49, 0.49, -1.09, 0.5)
예제 #16
0
    def setup_reader(self):

        """"Setup the reader in here.  This is called after the engine
        has been created and started.  The engine is available as
        self.e.  This method is called by setUp().
        """
        # Read a BYU data file.
        r = PolyDataReader()
        r.initialize(get_example_data('cow.g'))
        self.e.add_source(r)
        self.bounds = (-4.445, 5.998, -3.608, 2.760, -1.690, 1.690)
예제 #17
0
    def setup_reader(self):

        """"Setup the reader in here.  This is called after the engine
        has been created and started.  The engine is available as
        self.e.  This method is called by setUp().
        """
        # Read a PDB data file.
        r = PolyDataReader()
        r.initialize(get_example_data('caffeine.pdb'))
        self.e.add_source(r)
        self.bounds = (3.10, 10.78, -2.39, 4.03, -10.60, -6.31)
예제 #18
0
    def setup_reader(self):

        """"Setup the reader in here.  This is called after the engine
        has been created and started.  The engine is available as
        self.e.  This method is called by setUp().
        """
        # Read a Particle data file.
        r = PolyDataReader()
        r.initialize(get_example_data('Particles.raw'))
        self.e.add_source(r)
        r.reader.set(data_byte_order='big_endian', data_type='float', file_type='binary')
        self.bounds = (817.33, 826.09, 545.02, 571.02, 1443.48, 1511.18)
예제 #19
0
    def make_data(self):
        script = self.script
        from enthought.mayavi.sources.vtk_xml_file_reader import VTKXMLFileReader

        ############################################################
        # Create a new scene and set up the visualization.
        s = self.new_scene()

        # Read a VTK XML data file.
        r = VTKXMLFileReader()
        r.initialize(get_example_data('heart.vti'))
        script.add_source(r)
예제 #20
0
    def make_data(self):
        script = self.script
        from mayavi.sources.vtk_xml_file_reader import VTKXMLFileReader

        ############################################################
        # Create a new scene and set up the visualization.
        s = self.new_scene()

        # Read a VTK XML data file.
        r = VTKXMLFileReader()
        r.initialize(get_example_data('heart.vti'))
        script.add_source(r)
예제 #21
0
    def setup_reader(self):

        """"Setup the reader in here.  This is called after the engine
        has been created and started.  The engine is available as
        self.e.  This method is called by setUp().
        """
        # Read a Particle data file.
        r = PolyDataReader()
        r.initialize(get_example_data('Particles.raw'))
        self.e.add_source(r)
        r.reader.set(data_byte_order='big_endian', data_type='float', file_type='binary')
        self.bounds = (817.33, 826.09, 545.02, 571.02, 1443.48, 1511.18)
예제 #22
0
    def test_multiple_valid_readers(self):
        """Test if the fixture works fine if there are multiple readers
        capable of reading the file properly"""
        # Inserting a dummy reader into the registry also capable of 
        # reading files with extension 'xyz'
        open_dummy = SourceMetadata(
                id            = "DummyFile",
                class_name    = "enthought.mayavi.tests.test_registry.DummyReader",
                menu_name     = "&PLOT3D file",
                tooltip       = "Open a PLOT3D data data",
                desc        = "Open a PLOT3D data data",
                help        = "Open a PLOT3D data data",
                extensions = ['xyz'],
                wildcard = 'PLOT3D files (*.xyz)|*.xyz',
                can_read_test = 'enthought.mayavi.tests.test_registry:DummyReader.check_read',
                output_info = PipelineInfo(datasets=['structured_grid'],
                    attribute_types=['any'],
                    attributes=['any'])
                )
        registry.sources.append(open_dummy)
	reader = registry.get_file_reader(get_example_data('tiny.xyz'))
        callable = reader.get_callable()
        self.assertEqual(callable.__name__, 'PLOT3DReader')

        # Removing existing readers for .xyz extensions to check if the Dummy 
        # reader now reads it.
        remove = []
        for index, src in enumerate(registry.sources[:]):
            if 'xyz' in src.extensions and src.id != 'DummyFile':
                remove.append((index, src))
                registry.sources.remove(src)
        
        reader = registry.get_file_reader(get_example_data('tiny.xyz'))
        callable = reader.get_callable()
        self.assertEqual(callable.__name__, 'DummyReader')

        for index, src in remove:
            registry.sources.insert(index, src)
        registry.sources.remove(open_dummy)
예제 #23
0
    def test_multiple_valid_readers(self):
        """Test if the fixture works fine if there are multiple readers
        capable of reading the file properly"""
        # Inserting a dummy reader into the registry also capable of
        # reading files with extension 'xyz'
        open_dummy = SourceMetadata(
            id="DummyFile",
            class_name="enthought.mayavi.tests.test_registry.DummyReader",
            menu_name="&PLOT3D file",
            tooltip="Open a PLOT3D data data",
            desc="Open a PLOT3D data data",
            help="Open a PLOT3D data data",
            extensions=['xyz'],
            wildcard='PLOT3D files (*.xyz)|*.xyz',
            can_read_test=
            'enthought.mayavi.tests.test_registry:DummyReader.check_read',
            output_info=PipelineInfo(datasets=['structured_grid'],
                                     attribute_types=['any'],
                                     attributes=['any']))
        registry.sources.append(open_dummy)
        reader = registry.get_file_reader(get_example_data('tiny.xyz'))
        callable = reader.get_callable()
        self.assertEqual(callable.__name__, 'PLOT3DReader')

        # Removing existing readers for .xyz extensions to check if the Dummy
        # reader now reads it.
        remove = []
        for index, src in enumerate(registry.sources[:]):
            if 'xyz' in src.extensions and src.id != 'DummyFile':
                remove.append((index, src))
                registry.sources.remove(src)

        reader = registry.get_file_reader(get_example_data('tiny.xyz'))
        callable = reader.get_callable()
        self.assertEqual(callable.__name__, 'DummyReader')

        for index, src in remove:
            registry.sources.insert(index, src)
        registry.sources.remove(open_dummy)
예제 #24
0
    def make_data(self):
        script = self.script
        from mayavi.sources.vtk_data_source import VTKDataSource
        from tvtk.api import tvtk

        ############################################################
        # Create a new scene and set up the visualization.
        s = self.new_scene()

        # Read a VTK (old style) data file.
        r = tvtk.StructuredPointsReader()
        r.file_name = get_example_data('heart.vtk')
        r.update()
        d = VTKDataSource(data=r.output)
        script.add_source(d)
예제 #25
0
    def make_data(self):
        script = self.script
        from mayavi.sources.vtk_data_source import VTKDataSource
        from tvtk.api import tvtk

        ############################################################
        # Create a new scene and set up the visualization.
        s = self.new_scene()

        # Read a VTK (old style) data file.
        r = tvtk.StructuredPointsReader()
        r.file_name = get_example_data('heart.vtk')
        r.update()
        d = VTKDataSource(data=r.output)
        script.add_source(d)
예제 #26
0
    def do(self):
        script = self.script

        ############################################################
        # Create a new scene and set up the visualization.
        scene = self.new_scene()

        # Read a VTK (old style) data file.
        source = VTKFileReader()
        source.initialize(get_example_data('heart.vtk'))
        script.add_source(source)

        script.add_module(Surface())

        # In order to test the restoration of visualization properly
        # we should modify the camera
        view(130., 44., 65., [14., 14., 14.])
        
        ############################################################
        # Test if saving a visualization and restoring it works.

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

        # This is the old camera state
        old_camera_state = get_state(scene.scene.camera)

        # Remove existing scene.
        engine = script.engine
        engine.close_scene(scene)

        # Load visualization
        script.load_visualization(f)
        scene = engine.current_scene

        # Now do the check.
        new_camera_state = get_state(scene.scene.camera)

        for attr, new_value in new_camera_state.items():
            if attr.startswith("_"):
                continue
            new_value = array(new_value)
            old_value = array(old_camera_state[attr])
            assert (new_value == old_value).all()
예제 #27
0
    def setUp(self):
        
        e = NullEngine()
        # Uncomment to see visualization for debugging etc.
        #e = Engine()
        e.start()
        e.new_scene()
        self.e=e
        
        # Read a VTK XML data file.
        r = VTKXMLFileReader()
        r.initialize(get_example_data('cube.vti'))
        e.add_source(r)

        # Create an outline for the data.
        o = Outline()
        e.add_module(o)

        # Create one ContourGridPlane normal to the 'x' axis.
        cgp1 = ContourGridPlane()
        e.add_module(cgp1)
        # Set the position to the middle of the data.
        cgp1.grid_plane.position = 1

        # Another with filled contours normal to 'y' axis.
        cgp2 = ContourGridPlane()
        cgp2.contour.filled_contours = True
        # Set the axis and position to the middle of the data.
        cgp2.grid_plane.axis = 'y'
        cgp2.grid_plane.position = 1
        e.add_module(cgp2)

        # An interactive scalar cut plane.
        cp = ScalarCutPlane()
        e.add_module(cp)
        ip = cp.implicit_plane
        ip.normal = 0,0,1
        ip.origin = 0.5, 0.5, 1.0  
        # Since this is running offscreen this seems necessary.
        ip.widget.origin = 0.5, 0.5, 1.0
        ip.widget.enabled = False
        self.scene = e.current_scene
        self.cgp2=cgp2
        self.cp=cp
        return
예제 #28
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

        # Read a VTK (old style) data file.
        r = VTKXMLFileReader()
        r.initialize(get_example_data('pyramid_ug.vtu'))
        e.add_source(r)

        # Create the filters.
        idp = ImageDataProbe()
        idp.rescale_scalars = True
        e.add_filter(idp)
        cgp = ContourGridPlane(enable_contours=False)
        e.add_module(cgp)
        cgp.grid_plane.axis = 'z'
        cgp.grid_plane.position = 1
        self.scene = e.current_scene
        return
예제 #29
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

        # Read a VTK (old style) data file.
        r = VTKXMLFileReader()
        r.initialize(get_example_data('pyramid_ug.vtu'))
        e.add_source(r)

        # Create the filters.
        idp = ImageDataProbe()
        idp.rescale_scalars = True
        e.add_filter(idp)
        cgp = ContourGridPlane(enable_contours=False)
        e.add_module(cgp)
        cgp.grid_plane.axis = 'z'
        cgp.grid_plane.position = 1
        self.scene = e.current_scene
        return
예제 #30
0
    def do(self):
        ############################################################
        # Imports.
        script = self.script
        from mayavi.sources.vtk_file_reader import VTKFileReader
        from mayavi.modules.outline import Outline
        from mayavi.modules.iso_surface import IsoSurface
        from mayavi.modules.contour_grid_plane \
             import ContourGridPlane
        from mayavi.modules.scalar_cut_plane import ScalarCutPlane

        ############################################################
        # Create a new scene and set up the visualization.
        s = self.new_scene()

        # Read a VTK (old style) data file.
        r = VTKFileReader()
        r.initialize(get_example_data('heart.vtk'))

        script.add_source(r)

        # Create an outline for the data.
        o = Outline()
        script.add_module(o)

        # Create one ContourGridPlane normal to the 'x' axis.
        cgp1 = ContourGridPlane()
        script.add_module(cgp1)
        # Set the position to the middle of the data.
        cgp1.grid_plane.position = 15

        # Another with filled contours normal to 'y' axis.
        cgp2 = ContourGridPlane()
        cgp2.contour.filled_contours = True
        # Set the axis and position to the middle of the data.
        cgp2.grid_plane.axis = 'y'
        cgp2.grid_plane.position = 15
        script.add_module(cgp2)

        # An isosurface module.
        iso = IsoSurface(compute_normals=True)
        script.add_module(iso)
        iso.contour.contours = [200.0]

        # An interactive scalar cut plane.
        cp = ScalarCutPlane()
        script.add_module(cp)
        ip = cp.implicit_plane
        ip.normal = 0, 0, 1
        ip.origin = 0, 0, 5
        ip.widget.enabled = False

        # Set the scene to an isometric view.
        s.scene.isometric_view()

        # Now test.
        self.check()

        ############################################################
        # Test if the modules respond correctly when the components
        # are changed.
        ctr = cgp2.contour
        cgp2.contour = ctr.__class__()
        cgp2.contour = ctr
        cgp2.actor = cgp2.actor.__class__()

        iso.contour = iso.contour.__class__()
        iso.contour.contours = [200.0]
        iso.actor = iso.actor.__class__()
        iso.normals = iso.normals.__class__()

        ip = cp.implicit_plane
        cp.implicit_plane = cp.implicit_plane.__class__()
        cp.implicit_plane = ip
        ip.widget.enabled = False
        cp.contour = cp.contour.__class__()
        cp.cutter = cp.cutter.__class__()
        cp.actor = cp.actor.__class__()

        s.render()

        # Now check.
        self.check()

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

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

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

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

        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 set the enabled status of the widget, this is impossible
        # to get correctly.
        cp = source.children[0].children[-1]
        cp.implicit_plane.widget.enabled = False

        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
        cp = source1.children[0].children[-1]
        cp.implicit_plane.widget.enabled = False
        self.check()
예제 #31
0
    def do(self):
        ############################################################
        # Imports.
        script = self.script
        from mayavi.sources.plot3d_reader import PLOT3DReader
        from mayavi.filters.select_output import SelectOutput
        from mayavi.modules.outline import Outline

        ############################################################
        # Create a new scene and set up the visualization.
        s = self.new_scene()

        # Read the multi-block plot3d file.
        r = PLOT3DReader()
        r.reader.set(has_byte_count=True, multi_grid=True,
                     byte_order='little_endian')
        r.initialize(get_example_data('tiny.xyz'),
                     get_example_data('tiny.q'),
                     configure=False)

        script.add_source(r)

        # Add the filter.
        f = SelectOutput()
        script.add_filter(f)

        # Create an outline for the data.
        o = Outline()
        script.add_module(o)

        # Check the bounds of the outline.
        assert o.outline_filter.output.bounds == (1.0, 2.0, 1.0, 2.0, 1.0, 2.0)

        # Copy the reader to see if it does not pop up the UI.
        r1 = copy.deepcopy(r)
        script.add_source(r1)
        s.render()

        o1 = r1.children[0].children[0].children[0]
        assert o1.outline_filter.output.bounds == (1.0, 2.0, 1.0, 2.0, 1.0, 2.0)
        r1.children[0].output_index = 1
        assert o1.outline_filter.output.bounds == (2.0, 3.0, 1.0, 2.0, 1.0, 2.0)

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

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

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

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

        o = s.children[0].children[0].children[0].children[0]
        o1 = s.children[1].children[0].children[0].children[0]

        assert o.outline_filter.output.bounds == (1.0, 2.0, 1.0, 2.0, 1.0, 2.0)
        assert o1.outline_filter.output.bounds == (2.0, 3.0, 1.0, 2.0, 1.0, 2.0)

        # If we have come this far, we are golden!
        return
예제 #32
0
    def do(self):
        ############################################################
        # Imports.
        script = self.script
        from mayavi.filters.optional import Optional
        from mayavi.filters.warp_scalar import WarpScalar
        from mayavi.filters.cut_plane import CutPlane
        from mayavi.components.poly_data_normals import PolyDataNormals
        from mayavi.components.contour import Contour
        from mayavi.components.actor import Actor
        from mayavi.modules.generic_module import GenericModule
        from mayavi.sources.vtk_xml_file_reader import VTKXMLFileReader

        ############################################################
        # Create a new scene and set up the visualization.
        s = self.new_scene()

        # Read a VTK (old style) data file.
        r = VTKXMLFileReader()
        r.initialize(get_example_data('fire_ug.vtu'))
        script.add_source(r)

        # We now create the complete equivalent of a ScalarCutPlane in
        # the next block!
        cp = CutPlane()
        w = WarpScalar()
        warper = Optional(filter=w, label_text='Enable warping', enabled=False)
        c = Contour()
        ctr = Optional(filter=c, label_text='Enable contours', enabled=False)
        p = PolyDataNormals(name='Normals')
        normals = Optional(filter=p,
                           label_text='Compute normals',
                           enabled=False)
        a = Actor()
        components = [cp, warper, ctr, normals, a]
        m = GenericModule(name='ScalarCutPlane',
                          components=components,
                          contour=c,
                          actor=a)

        script.add_module(m)
        s.scene.isometric_view()

        ########################################
        # do the testing.
        def check(mod):
            """Check if test status is OK for the given module."""
            cut, warper, ctr, normals, a = mod.components
            c = ctr.filter
            # The intermediate ones are disabled.
            assert normals.outputs[0] is cut.outputs[0]
            # Enable the contours.
            ctr.enabled = True
            assert ctr.outputs[0] is c.outputs[0]
            assert ctr.outputs[0] is normals.outputs[0]
            n_output = self._get_output(normals.outputs[0])
            rng = n_output.point_data.scalars.range
            assert (rng[1] - rng[0]) < 1e-4
            # Turn on auto-contours
            c.auto_contours = True
            # Increase number of contours and the range should change.
            c.number_of_contours = 10
            n_output = self._get_output(normals.outputs[0])
            assert len(n_output.points) != 0
            rng = n_output.point_data.scalars.range
            assert rng[0] < rng[1]
            # Check if pipeline_changed is correctly propagated.
            old = self._get_output(normals.outputs[0])
            assert a.mapper.scalar_mode == 'default'
            c.filled_contours = True
            n_output = self._get_output(normals.outputs[0])
            c_output = self._get_output(c.outputs[0])
            assert n_output != old
            assert n_output is c_output
            # Check if the actor responds correctly to the
            # filled_contour change.
            assert a.mapper.scalar_mode == 'use_cell_data'

            # Set back everything to original state.
            c.filled_contours = False
            assert a.mapper.scalar_mode == 'default'
            c.number_of_contours = 1
            c.auto_contours = False
            ctr.enabled = False
            assert normals.outputs[0] is cut.outputs[0]

        check(m)

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

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

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

        # Load visualization
        script.load_visualization(f)
        s = engine.current_scene
        s.scene.isometric_view()

        # Now do the check.
        m = s.children[0].children[0].children[0]
        check(m)

        ############################################################
        # 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.
        m = s.children[0].children[0].children[0]
        s.scene.isometric_view()
        check(m)

        # 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.
        m = s.children[0].children[0].children[0]
        s.scene.isometric_view()
        check(m)
예제 #33
0
 def test_unstructured_grid_file(self):
     self.src.initialize(get_example_data('UGridEx.vtk'))
     self.check(27, 12)
예제 #34
0
    def do_profile(self):
        ############################################################
        # Imports.
        ############################################################
        script = self.script
        from mayavi.sources.vtk_file_reader import VTKFileReader
        from mayavi.modules.outline import Outline
        from mayavi.modules.iso_surface import IsoSurface
        from mayavi.modules.contour_grid_plane \
             import ContourGridPlane
        from mayavi.modules.scalar_cut_plane import ScalarCutPlane

        ############################################################
        # Create a new scene and set up the visualization.
        ############################################################
        s = self.new_scene()

        # Read a VTK (old style) data file.
        r = VTKFileReader()
        r.initialize(get_example_data('heart.vtk'))

        script.add_source(r)

        # Create an outline for the data.
        o = Outline()
        script.add_module(o)

        # Create one ContourGridPlane normal to the 'x' axis.
        cgp1 = ContourGridPlane()
        script.add_module(cgp1)
        # Set the position to the middle of the data.
        cgp1.grid_plane.position = 15

        # Another with filled contours normal to 'y' axis.
        cgp2 = ContourGridPlane()
        cgp2.contour.filled_contours = True
        # Set the axis and position to the middle of the data.
        cgp2.grid_plane.axis = 'y'
        cgp2.grid_plane.position = 15
        script.add_module(cgp2)

        # An isosurface module.
        iso = IsoSurface(compute_normals=True)
        script.add_module(iso)
        iso.contour.contours = [200.0]

        # An interactive scalar cut plane.
        cp = ScalarCutPlane()
        script.add_module(cp)
        ip = cp.implicit_plane
        ip.normal = 0, 0, 1
        ip.origin = 0, 0, 5
        ip.widget.enabled = False

        # Set the scene to an isometric view.
        s.scene.isometric_view()

        s.render()

        # Remove existing scene.
        engine = script.engine
        engine.close_scene(s)
예제 #35
0
    def do(self):
        ############################################################
        # Imports.
        from mayavi.modules.api import ScalarCutPlane
        from mayavi.modules.labels import Labels
        from mayavi.sources.vtk_xml_file_reader import VTKXMLFileReader

        ############################################################
        # Create a new scene and set up the visualization.
        s = self.new_scene()
        script = mayavi = self.script

        # Read a VTK (old style) data file.
        r = VTKXMLFileReader()
        r.initialize(get_example_data('fire_ug.vtu'))
        script.add_source(r)

        # Create the filters.
        cp = ScalarCutPlane()
        script.add_module(cp)
        l = Labels(object=cp)
        script.add_module(l)

        s.scene.isometric_view()
        GUI.process_events()
        self.check(saved=False)
        ############################################################
        # Test if saving a visualization and restoring it works.

        # Save visualization.
        f = BytesIO()
        f.name = abspath('test.mv2')  # We simulate a file.
        script.save_visualization(f)
        f.seek(0)

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

        # Load visualization
        script.load_visualization(f)
        s = engine.current_scene
        s.scene.isometric_view()

        # Seems to be needed for the test to pass. :(  Just flushes the
        # pipeline.
        s.children[0].pipeline_changed = True
        GUI.process_events()

        # Check.
        # Now do the check.
        self.check(saved=True)

        ############################################################
        # 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)
        GUI.process_events()

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

        # 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
        GUI.process_events()

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

        GUI.process_events()
예제 #36
0
    def do(self):
        ############################################################
        # Imports.
        from mayavi.filters.image_data_probe import ImageDataProbe
        from mayavi.modules.api import ContourGridPlane
        from mayavi.sources.vtk_xml_file_reader import VTKXMLFileReader

        ############################################################
        # Create a new scene and set up the visualization.
        s = self.new_scene()
        script = mayavi = self.script

        # Read a VTK (old style) data file.
        r = VTKXMLFileReader()
        r.initialize(get_example_data('fire_ug.vtu'))
        script.add_source(r)

        # Create the filters.
        idp = ImageDataProbe()
        script.add_filter(idp)
        cgp = ContourGridPlane(enable_contours=False)
        script.add_module(cgp)
        cgp.grid_plane.axis = 'z'
        cgp.grid_plane.position = 2
        s.scene.isometric_view()

        # Check.
        self.check(saved=False)
        ############################################################
        # Test if saving a visualization and restoring it works.

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

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

        # Load visualization
        script.load_visualization(f)
        s = engine.current_scene
        s.scene.isometric_view()

        # Now do the check.
        self.check(saved=True)

        ############################################################
        # 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.
        s.scene.isometric_view()
        self.check(saved=True)

        # 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(saved=True)
예제 #37
0
    def do(self):
        ############################################################
        # Imports.
        from mayavi.sources.api import VTKXMLFileReader,\
                VRMLImporter
        from mayavi.modules.api import ScalarCutPlane,\
                IsoSurface

        ############################################################
        # Create a new scene and set up the visualization.
        s = self.new_scene()
        script = mayavi = self.script

        # Read a VRML file.
        w = VRMLImporter()
        w.initialize(get_example_data('room_vis.wrl'))
        script.add_source(w)

        # Read a VTK data file.
        r = VTKXMLFileReader()
        r.initialize(get_example_data('fire_ug.vtu'))
        script.add_source(r)

        # Create the modules.
        scp = ScalarCutPlane()
        script.add_module(scp)

        iso = IsoSurface()
        script.add_module(iso)

        # Check.
        self.check(saved=False)

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

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

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

        # Load visualization
        script.load_visualization(f)
        s = engine.current_scene
        s.scene.isometric_view()

        # Now do the check.
        self.check(saved=True)

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

        # Pop the source object.
        sources = s.children
        s.children = []
        # Add it back to see if that works without error.
        s.children.extend(sources)
        # Now do the check.
        s.scene.isometric_view()
        self.check(saved=True)

        # 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.
        sources1 = copy.deepcopy(sources)
        s.children[:] = sources1
        # Now do the check.
        s.scene.isometric_view()
        self.check(saved=True)
    def do(self):
        ############################################################
        # Imports.
        script = self.script
        from mayavi.sources.vtk_file_reader import VTKFileReader
        from mayavi.filters.contour import Contour
        from mayavi.filters.optional import Optional
        from mayavi.filters.collection import Collection
        from mayavi.filters.api import PolyDataNormals
        from mayavi.modules.api import Surface

        ############################################################
        # Create a new scene and set up the visualization.
        s = self.new_scene()

        # Read a VTK (old style) data file.
        r = VTKFileReader()
        r.initialize(get_example_data('heart.vtk'))
        script.add_source(r)

        c = Contour()
        # `name` is used for the notebook tabs.
        n = PolyDataNormals(name='Normals')
        o = Optional(filter=n, label_text='Compute normals')
        coll = Collection(filters=[c, o], name='IsoSurface')
        script.add_filter(coll)
        s = Surface()
        script.add_module(s)

        ########################################
        # do the testing.
        def check(coll):
            """Check if test status is OK given the collection."""
            c, o = coll.filters
            c = c.filter
            n = o.filter
            assert coll.outputs[0].point_data.scalars.range == (127.5, 127.5)
            # Adding a contour should create the appropriate output in
            # the collection.
            c.contours.append(200)
            assert coll.outputs[0].point_data.scalars.range == (127.5, 200.0)
            # the collection's output should be that of the normals.
            assert coll.outputs[0] is n.outputs[0]
            # disable the optional filter and check.
            o.enabled = False
            assert 'disabled' in o.name
            assert coll.outputs[0] is c.outputs[0]
            # Set back everything to original state.
            c.contours.pop()
            o.enabled = True
            assert coll.outputs[0].point_data.scalars.range == (127.5, 127.5)
            assert coll.outputs[0] is n.outputs[0]
            assert 'disabled' not in o.name

        check(coll)

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

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

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

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

        # Now do the check.
        coll = s.children[0].children[0]
        check(coll)

        ############################################################
        # 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.
        coll = s.children[0].children[0]
        check(coll)

        # 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.
        coll = s.children[0].children[0]
        check(coll)
예제 #39
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()
예제 #40
0
 def test_structured_points_file(self):
     self.src.initialize(get_example_data('texThres2.vtk'))
     self.check(128, 127)
예제 #41
0
 def test_polydata_file(self):
     self.src.initialize(get_example_data('polyEx.vtk'))
     self.check(8, 6)
예제 #42
0
 def test_rectiliner_grid_file(self):
     self.src.initialize(get_example_data('RectGrid2.vtk'))
     self.check(17061, 14720)
예제 #43
0
 def test_unique_reader(self):
     "Check if a file with a unique reader in Mayavi2 can be read"
     e = self.e
     reader = e.open(get_example_data('prism.neu'))
     self.assertNotEqual(reader, None)
예제 #44
0
 def test_structured_grid_file(self):
     self.src.initialize(get_example_data('SampleStructGrid.vtk'))
     self.check(24000, 21489)
예제 #45
0
    def do(self):
        ############################################################
        # Imports.
        from enthought.mayavi.filters.optional import Optional
        from enthought.mayavi.filters.user_defined import UserDefined
        from enthought.mayavi.filters.api import (CellToPointData,
                ExtractVectorNorm, ExtractVectorComponents)
        from enthought.mayavi.modules.api import ScalarCutPlane
        from enthought.mayavi.sources.vtk_xml_file_reader import VTKXMLFileReader

        ############################################################
        # Create a new scene and set up the visualization.
        s = self.new_scene()
        script = mayavi = self.script

        # Read a VTK (old style) data file.
        r = VTKXMLFileReader()
        r.initialize(get_example_data('fire_ug.vtu'))
        script.add_source(r)

        # Create the filters.
        # CellDerivatives
        cd = tvtk.CellDerivatives()
        ud = UserDefined(filter=cd)
        script.add_filter(ud)
        ctp = CellToPointData()
        ctp.filter.pass_cell_data = False
        script.add_filter(ctp)
        evn = ExtractVectorNorm()
        script.add_filter(evn)
        evc = ExtractVectorComponents(component='y-component')
        o = Optional(filter=evc)
        script.add_filter(o)

        script.add_module(ScalarCutPlane())
        s.scene.isometric_view()

        # Check.
        self.check(saved=False)
        ############################################################
        # Test if saving a visualization and restoring it works.

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

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

        # Load visualization
        script.load_visualization(f)
        s = engine.current_scene
        s.scene.isometric_view()

        # Now do the check.
        self.check(saved=True)

        ############################################################
        # 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.
        s.scene.isometric_view()
        self.check(saved=True)

        # 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(saved=True)
예제 #46
0
 def test_field_file(self):
     self.src.initialize(get_example_data('fieldfile.vtk'))
     self.check(18, 3)
예제 #47
0
    def do(self):
        ############################################################
        # Imports.
        script = self.script
        from mayavi.sources.vtk_file_reader import VTKFileReader
        from mayavi.modules.outline import Outline
        from mayavi.modules.grid_plane import GridPlane

        ############################################################
        # Create a new scene and set up the visualization.
        s = self.new_scene()

        # Read a VTK (old style) data file.
        r = VTKFileReader()
        r.initialize(get_example_data('heart.vtk'))
        script.add_source(r)

        # Create an outline for the data.
        o = Outline()
        script.add_module(o)

        # Create three simple grid plane modules.
        # First normal to 'x' axis.
        gp1 = GridPlane()
        script.add_module(gp1)
        # Second normal to 'y' axis.
        gp2 = GridPlane()
        # We'll test how robust things are by setting attributes
        # *before* we add it to the scene.
        gp2.grid_plane.axis = 'y'
        gp2.grid_plane.position = 16
        script.add_module(gp2)
        # Third normal to 'z' axis.
        gp3 = GridPlane()
        script.add_module(gp3)
        gp3.grid_plane.axis = 'z'
        gp3.grid_plane.position = 6

        for gp in (gp1, gp2, gp3):
            gp.actor.property.set(ambient=1.0)

        # Set the scene to an isometric view.
        s.scene.isometric_view()

        self.check()

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

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

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

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

        self.check()

        ############################################################
        # Test if the MayaVi2 visualization can be deepcopied.

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

        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

        self.check()