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
示例#2
0
 def setup_pipeline(self):
     mask = MaskPoints()
     mask.filter.set(generate_vertices=True, random_mode=True)
     self.mask = mask
     v = UserDefined(filter=tvtk.SelectVisiblePoints(),
                     name='VisiblePoints')
     self.visible_points = Optional(filter=v, enabled=False)
     mapper = tvtk.LabeledDataMapper()
     self.mapper = mapper
     self.actor = Actor2D(mapper=mapper)
     self.property = mapper.label_text_property
     self.property.on_trait_change(self.render)
     self.components = [self.mask, self.visible_points, self.actor]
def make_user_defined_filter():
    from mayavi.filters.user_defined import UserDefined
    f = UserDefined()
    f.setup_filter()
    return f
示例#4
0
文件: metadata.py 项目: B-Rich/mayavi
def make_user_defined_filter():
    from mayavi.filters.user_defined import UserDefined
    f = UserDefined()
    f.setup_filter()
    return f
示例#5
0
# environment variable to qt4, to tell Traits that we will use Qt.
os.environ['ETS_TOOLKIT'] = 'qt4'
# print os.getenv("ETS_TOOLKIT")
from mayavi import mlab
import mayavi
import sys
import matplotlib
from matplotlib.cm import datad, get_cmap
import numpy as np
from tvtk.api import tvtk
from mayavi.filters.user_defined import UserDefined

# -----------------------------------------------------------------------------

# Define and apply a UserDefined:CellCenters filter
CellCenter = UserDefined(filter=tvtk.CellCenters())

# -----------------------------------------------------------------------------

fig = mlab.figure(bgcolor=(1, 1, 1), fgcolor=(0, 0, 0), size=(1500, 800))

# Read the last file from the base directory
base_dir = '../fidimag_2D_D2d_vtks/'
data = mlab.pipeline.open(base_dir + os.listdir(base_dir)[-1])

vtres = mlab.pipeline.threshold(data)
try:
    vtres.lower_threshold = 0.01
except:
    print('No points with zero vector norm')
# Extract vec comp and plot
示例#6
0
    def do(self):
        ############################################################
        # Imports.
        from mayavi.filters.optional import Optional
        from mayavi.filters.user_defined import UserDefined
        from mayavi.filters.api import (CellToPointData, ExtractVectorNorm,
                                        ExtractVectorComponents)
        from mayavi.modules.api import ScalarCutPlane
        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.
        # 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)