예제 #1
0
  def _renderScene(self, data):

    script = self.script
    w = script.get_active_window()
    w.size = self.windowSize
    script.new_scene()
    scene = script.engine.current_scene.scene
    scene.disable_render = True
    scene.anti_aliasing_frames = self.aaframes
    scene.background = self.colorBg
    scene.foreground = self.colorFg

    script.add_source(VTKDataSource(data=data))
    objTop = script.engine.current_object
    script.engine.current_object.name = "fault"

    warp = WarpVector()
    warp.filter.scale_factor = warpScale
    script.add_filter(warp)

    surf = Surface()
    script.add_module(surf)

    colorbar = script.engine.current_object.module_manager.scalar_lut_manager
    colorbar.data_name = "Velocity (m/s)"
    colorbar.lut_mode = self.lut
    colorbar.reverse_lut = self.lutReverse
    colorbar.scalar_bar.label_format = "%4.2f"
    colorbar.scalar_bar.label_text_property.font_size = 18
    colorbar.scalar_bar.label_text_property.shadow = True
    colorbar.scalar_bar.label_text_property.italic = False
    colorbar.scalar_bar.title_text_property.italic = False
    colorbar.scalar_bar.title_text_property.shadow = True
    colorbar.show_scalar_bar = False
    colorbar.data_range = (0.0, 1.0)
    #colorbar.number_of_labels = 0

    colorbar.scalar_bar.orientation = "horizontal"
    scalar_bar = colorbar.scalar_bar_widget.representation
    scalar_bar.position2 = (0.33, 0.12)
    scalar_bar.position = (0.01, 0.02)

    surf = Surface()
    script.add_module(surf)

    

    return
예제 #2
0
    def setUp(self):

        e = NullEngine()
        # Uncomment to see visualization for debugging etc.
        #e = Engine()
        e.start()
        s = e.new_scene()

        image_data = BuiltinImage()
        e.add_source(image_data)

        outline = Outline()
        e.add_module(outline)

        surface = Surface()
        e.add_module(surface)

        image_data.data_source.radius = array([80., 80., 80.])
        image_data.data_source.center = array([150., 150., 0.])
        image_data.data_source.whole_extent = array([10, 245, 10, 245, 0, 0])

        self.e = e
        self.scene = e.current_scene

        return
예제 #3
0
    def test_2d_data(self):
        """Generic tests for 2D data arrays."""
        d = self.data
        sc, vec = self.make_2d_data()
        d.origin = (-1, -1, 0)
        d.scalar_data = sc
        d.vector_data = vec
        d.start()  # Start the object so it flushes the pipeline etc.

        # Create an outline for the data.
        o = Outline()
        d.add_child(o)
        o.start()
        self.assertEqual(tuple(o.actor.actor.bounds), 
                         (-1., 0., -1., 0., 0., 0.))
        # Create a surface module.
        surf = Surface()
        d.add_child(surf)
        self.assertEqual(surf.running, True)

        tps = numpy.transpose
        expect = [tps(sc), tps(vec, (1, 0, 2))]
        sc1 = surf.actor.mapper.input.point_data.scalars.to_array()
        self.assertEqual(numpy.allclose(sc1.flatten(),
                         expect[0].flatten()), True)
        vec1 = surf.actor.mapper.input.point_data.vectors.to_array()
        self.assertEqual(numpy.allclose(vec1.flatten(),
                         expect[1].flatten()), True)
예제 #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()
        s = e.new_scene()

        poly_data = BuiltinSurface()
        e.add_source(poly_data)

        outline = Outline()
        e.add_module(outline)

        surface = Surface()
        e.add_module(surface)

        poly_data.data_source.shaft_radius = 0.05
        poly_data.data_source.shaft_resolution = 7
        poly_data.data_source.tip_radius = 0.1

        self.e = e
        self.scene = e.current_scene

        return
예제 #5
0
def surf_regular(source):
    """Now visualize the data as done in mlab.
    """
    w = WarpScalar()
    source.add_child(w)
    s = Surface()
    w.add_child(s)
예제 #6
0
    def test_3d_data(self):
        "Test for 3D data arrays."
        # Add a 3D data source
        d = self.data
        sc, vec = self.make_3d_data()
        d.scalar_data = sc
        d.vector_data = vec
        d.start()  # Start the object so it flushes the pipeline etc.

        # Create an outline for the data.
        o = Outline()
        d.add_child(o)
        o.start()
        self.assertEqual(tuple(o.actor.actor.bounds), 
                         (0, 1., 0., 1., 0., 1.))
        # Create a surface module.
        surf = Surface()
        d.add_child(surf)
        self.assertEqual(surf.running, True)

        tps = numpy.transpose
        expect = [tps(sc),  tps(vec, (2,1,0,3))]
        sc2 = surf.actor.mapper.input.point_data.scalars.to_array()
        self.assertEqual(numpy.allclose(sc2.flatten(),
                         expect[0].flatten()), True)
        vec2 = surf.actor.mapper.input.point_data.vectors.to_array()
        self.assertEqual(numpy.allclose(vec2.flatten(), 
                         expect[1].flatten()), True)
예제 #7
0
def view():
    col0 = numpy.arange(0, numpts - 1, 1)
    col1 = numpy.arange(1, numpts, 1)
    lines = array([col0, col1]).transpose()

    curve = tvtk.PolyData(points=points, lines=lines)
    # assign temperature in sequence so that we now the "direction" of the curve
    curve.point_data.scalars = numpy.arange(0, numpts, 1)
    curve.point_data.scalars.name = 'temperature'

    from enthought.mayavi.sources.vtk_data_source import VTKDataSource
    #from enthought.mayavi.modules.outline import Outline
    from enthought.mayavi.modules.surface import Surface
    from enthought.mayavi.modules.axes import Axes
    from enthought.mayavi.modules.text import Text

    scene = mayavi.new_scene()
    scene.scene.background = (1.0, 1.0, 1.0)
    scene.scene.foreground = (0.0, 0.0, 0.0)

    src = VTKDataSource(data=curve)
    mayavi.add_source(src)
    #mayavi.add_module(Outline())
    s = Surface()
    mayavi.add_module(s)
    s.actor.property.set(representation='p', color=(0., 1., 0.), line_width=2)
예제 #8
0
def view_data(color):
		s = Surface()
		mayavi.add_module(s)
		if (color == "black"):
			s.actor.property.specular_color = (0.0, 0.0, 0.0)
			s.actor.property.diffuse_color = (0.0, 0.0, 0.0)
			s.actor.property.ambient_color = (0.0, 0.0, 0.0)
			s.actor.property.color = (0.0, 0.0, 0.0)
예제 #9
0
def surf_regular():
    """Now visualize the data as done in mlab.
    """
    w = WarpScalar()
    mayavi.add_filter(w)
    o = Outline()
    s = Surface()
    mayavi.add_module(o)
    mayavi.add_module(s)
예제 #10
0
def view():
    from enthought.mayavi.sources.vtk_data_source import VTKDataSource
    from enthought.mayavi.modules.surface import Surface

    mayavi.new_scene()
    src = VTKDataSource(data=mesh)
    mayavi.add_source(src)
    s = Surface()
    mayavi.add_module(s)
예제 #11
0
def view():
    from enthought.mayavi.sources.vtk_data_source import VTKDataSource
    from enthought.mayavi.modules.outline import Outline
    from enthought.mayavi.modules.surface import Surface
    from enthought.mayavi.modules.vectors import Vectors

    mayavi.new_scene()
    # The single type one
    src = VTKDataSource(data=ug1)
    mayavi.add_source(src)
    mayavi.add_module(Outline())
    mayavi.add_module(Surface())
    mayavi.add_module(Vectors())

    # Mixed types.
    src = VTKDataSource(data=ug2)
    mayavi.add_source(src)
    mayavi.add_module(Outline())
    mayavi.add_module(Surface())
    mayavi.add_module(Vectors())
예제 #12
0
    def addmodules(self, idx, addTextIndexer):
        #add Outline module
        o = Outline()
        mayavi.add_module(o)
        #add OrientationAxes module
        oa = OrientationAxes()
        mayavi.add_module(oa)
        """
        #add IsoSurface module if requested
        i = IsoSurface()
        mayavi.add_module(i)
        """

        #add Surface module if requested
        s = Surface()
        s.enable_contours = True
        s.actor.property.opacity = 0.5
        mayavi.add_module(s)

        #add Text module if requested
        t1 = Text()
        t1.text = self.title
        t1.actor.scaled_text = False
        t1.actor.text_property.font_size = 18
        mayavi.add_module(t1)
        t1.width = 1.0 * t1.actor.mapper.get_width(
            t1.scene.renderer) / t1.scene.renderer.size[0]
        height = 1.0 * t1.actor.mapper.get_height(
            t1.scene.renderer) / t1.scene.renderer.size[1]
        t1.x_position = 0.5 - t1.width / 2
        t1.y_position = 1 - height

        if (addTextIndexer):
            #add default Text module for indicating scene index
            self.sceneTextCount = Text()
            self.sceneTextCount.text = "0"
            mayavi.add_module(self.sceneTextCount)
            self.sceneTextCount.actor.scaled_text = False
            self.sceneTextCount.actor.text_property.font_size = 24
            self.sceneTextCount.x_position = .95
            self.sceneTextCount.y_position = .05
예제 #13
0
 def add_source_data(self, data):
     from enthought.mayavi.filters.poly_data_normals import PolyDataNormals
     d = VTKDataSource()
     d.data = data
     obj = self.scene.add_child(d)
     w = WarpScalar()
     d.add_child(w)
     n = PolyDataNormals()
     n.filter.feature_angle = 45
     w.add_child(n)
     s = Surface()
     n.add_child(s)
예제 #14
0
def view():
    from enthought.mayavi.sources.vtk_data_source import VTKDataSource
    from enthought.mayavi.filters.warp_scalar import WarpScalar
    from enthought.mayavi.filters.poly_data_normals import PolyDataNormals
    from enthought.mayavi.modules.surface import Surface

    mayavi.new_scene()
    src = VTKDataSource(data = spoints)
    mayavi.add_source(src)
    mayavi.add_filter(WarpScalar())
    mayavi.add_filter(PolyDataNormals())
    s = Surface()
    mayavi.add_module(s)
예제 #15
0
    def run(self):
        from enthought.mayavi.sources.vtk_data_source import VTKDataSource
        from enthought.mayavi.modules.surface import Surface

        self._setupScene(showFault=False, showMaterials=False)
        mesh = self._readMesh()

        script = self.script
        script.add_source(VTKDataSource(data=mesh))
        script.engine.current_object.name = "Mesh"

        surf = Surface()
        script.add_module(surf)
        surf.actor.property.color = (0, 1, 0)

        surf = Surface()
        script.add_module(surf)
        surf.actor.property.representation = 'wireframe'

        import vtk_geometry
        vtk_geometry.setCamera(script.engine.current_scene.scene.camera)
        return
예제 #16
0
  def run(self):    
    from enthought.mayavi.sources.vtk_data_source import VTKDataSource
    from enthought.mayavi.filters.threshold import Threshold
    from enthought.mayavi.modules.surface import Surface
    from enthought.mayavi.modules.scalar_cut_plane import ScalarCutPlane

    self._setupScene()
    data = self._readData()

    script = self.script
    script.add_source(VTKDataSource(data=data))
    script.engine.current_object.name = "Error"
    error = script.engine.current_object

    threshold = Threshold()
    script.add_filter(threshold)
    threshold.lower_threshold = -3.0
    
    surf = Surface()
    script.add_filter(surf)

    if showSlice:
      surf.actor.property.opacity = 0.3
      script.engine.current_object = error
      slice = ScalarCutPlane()
      script.add_module(slice)
      slice.actor.property.opacity = 0.5
      slice.implicit_plane.origin = (12.0, 12.0, -12.0)
      slice.implicit_plane.normal = (0, -1.0, 0.0)

    for obj in [slice, surf]:
      colorbar = obj.module_manager.scalar_lut_manager
      colorbar.data_range = (threshold.lower_threshold, -2.0)
      colorbar.lut_mode = "hot"
      colorbar.reverse_lut = True
    colorbar.show_scalar_bar = True
    colorbar.number_of_labels = 6
    colorbar.scalar_bar.label_format = "%-3.1f"
    w,h = colorbar.scalar_bar.position2
    colorbar.scalar_bar.position2 = (w, 0.1)

    light = script.engine.current_scene.scene.light_manager.lights[0]
    light.elevation = 20.0
    light.azimuth = -45.0

    import vtk_geometry
    vtk_geometry.setCamera(script.engine.current_scene.scene.camera)
    return
예제 #17
0
 def add_lines(self, points):
     np = len(points) - 1
     lines = scipy.zeros((np, 2), "l")
     lines[:, 0] = scipy.arange(0, np - 0.5, 1, "l")
     lines[:, 1] = scipy.arange(1, np + 0.5, 1, "l")
     pd = tvtk.PolyData(points=points, lines=lines)
     d = VTKDataSource()
     d.data = pd
     self.scene.add_child(d)
     filter = tvtk.TubeFilter(number_of_sides=6)
     filter.radius = 0.01
     f = FilterBase(filter=filter, name="TubeFilter")
     d.add_child(f)
     s = Surface()
     s.actor.mapper.scalar_visibility = False
     d.add_child(s)
예제 #18
0
def view_model():
		"""Sets up the mayavi pipeline for the visualization.
		"""
		# 'mayavi' is always defined on the interpreter.
		s = Surface()
		mayavi.add_module(s)
		
		#Move legend to the bottom, rename it, and chg scale
		s.module_manager.scalar_lut_manager.lut_mode = 'RdBu'
		s.module_manager.scalar_lut_manager.show_scalar_bar = True
		s.module_manager.scalar_lut_manager.show_legend = True
		s.module_manager.scalar_lut_manager.scalar_bar_representation.orientation = 0
		s.module_manager.scalar_lut_manager.scalar_bar_representation.position = array([ 0.1, 0.0])
		s.module_manager.scalar_lut_manager.scalar_bar_representation.position2 = array([ 0.8 ,  0.17])
		s.module_manager.scalar_lut_manager.use_default_name = False
		s.module_manager.scalar_lut_manager.scalar_bar.title = 'density anomaly'
		s.module_manager.scalar_lut_manager.data_name = u'density anomaly'
예제 #19
0
    def test_pickle(self):
        "Test if pickling works."

        # Test if saving a visualization and restoring it works.
        d = self.data
        sc, vec = self.make_3d_data()
        d.scalar_data = sc
        d.vector_data = vec
        d.spacing = [1, 2, 3]
        d.origin  = [4, 5, 6]
        d.start()  # Start the object so it flushes the pipeline etc.

        # Create an outline for the data.
        o = Outline()
        d.add_child(o)
        o.start()
        # Create a surface module.
        surf = Surface()
        d.add_child(surf)

        data = pickle.dumps(d)
        del d, surf, o
        d = pickle.loads(data)
        # We must explicitly start the object.
        d.start()
        mm = d.children[0]
        o, surf = mm.children

        # Test the unpciked state.
        self.assertEqual(tuple(o.actor.actor.bounds), 
                         (4., 5., 5., 7., 6., 9.))
        self.assertEqual(surf.running, True)
        self.assertEqual(o.running, True)
        self.assertEqual(d.running, True)
        self.assertEqual(numpy.allclose(d.spacing, [1, 2, 3]), True)
        self.assertEqual(numpy.allclose(d.origin,  [4, 5, 6]), True)

        tps = numpy.transpose
        expect = [tps(sc),  tps(vec, (2,1,0,3))]
        sc2 = surf.actor.mapper.input.point_data.scalars.to_array()
        self.assertEqual(numpy.allclose(sc2.flatten(),
                         expect[0].flatten()), True)
        vec2 = surf.actor.mapper.input.point_data.vectors.to_array()
        self.assertEqual(numpy.allclose(vec2.flatten(), 
                         expect[1].flatten()), True)
예제 #20
0
  def run(self):    
    from enthought.mayavi.sources.vtk_data_source import VTKDataSource
    from enthought.mayavi.filters.warp_vector import WarpVector
    from enthought.mayavi.filters.extract_vector_norm import ExtractVectorNorm
    from enthought.mayavi.modules.surface import Surface
    from enthought.mayavi.modules.glyph import Glyph

    self._setupScene(showFault=False, showMaterials=False)
    data = self._readData()

    script = self.script
    script.add_source(VTKDataSource(data=data))
    script.engine.current_object.name = "Solution"

    warp = WarpVector()
    warp.filter.scale_factor = scaleFactor
    script.add_filter(warp)

    norm = ExtractVectorNorm()
    script.add_filter(norm)
    
    surf = Surface()
    script.add_module(surf)

    glyph = Glyph()
    script.add_module(glyph)
    glyph.actor.property.color = (1,1,1)
    glyph.actor.mapper.scalar_visibility = False
    glyph.glyph.glyph_position = 'tail'
    glyph.glyph.glyph.scale_factor = scaleFactor
    glyph.glyph.glyph_source = glyph.glyph.glyph_list[1]
    
    colorbar = script.engine.current_object.module_manager.scalar_lut_manager
    colorbar.show_scalar_bar = True
    colorbar.data_range = (0.0, 0.5)
    colorbar.number_of_labels = 6
    colorbar.scalar_bar.label_format = "%3.1f"
    w,h = colorbar.scalar_bar.position2
    colorbar.scalar_bar.position2 = (w, 0.1)
    colorbar.data_name = "Displacement [m]"
    
    import vtk_geometry
    vtk_geometry.setCamera(script.engine.current_scene.scene.camera)
    return
예제 #21
0
  def _plotScene(self):
    from enthought.mayavi.sources.vtk_data_source import VTKDataSource
    from enthought.mayavi.filters.extract_vector_norm import ExtractVectorNorm
    from enthought.mayavi.modules.outline import Outline
    from enthought.mayavi.modules.axes import Axes
    from enthought.mayavi.modules.surface import Surface
    from enthought.tvtk.api import tvtk

    script = self.script
    script.new_scene()
    w = script.get_active_window()
    w.size = self.windowSize
    scene = script.engine.current_scene.scene
    scene.disable_render = True
    scene.background = self.colorBg
    scene.foreground = self.colorFg

    t = 0.0
    self.dataVtk = self.surfdata.toVtk(t)
    script.engine.current_object.name = "Velocity"

    script.add_source(VTKDataSource(data=self.dataVtk))
    surf = Surface()
    surf.actor.property.representation = "wireframe"
    script.add_module(surf)

    colorbar = script.engine.current_object.module_manager.scalar_lut_manager
    colorbar.show_scalar_bar = True
    colorbar.scalar_bar.label_format = "%3.1f"
    colorbar.use_default_range = False
    colorbar.data_range = (-3, 1)
    colorbar.number_of_labels = 4
    colorbar.data_name = "Velocity (m/s)"
    colorbar.lut_mode = "hot"
    colorbar.reverse_lut = self.lutReverse

    scalar_bar = colorbar.scalar_bar_widget.representation
    scalar_bar.position2 = (0.05, 0.33)
    scalar_bar.position = (0.05, 0.05)


    return
예제 #22
0
def main():
    # Create some random points to view.
    pd = tvtk.PolyData()
    pd.points = np.random.random((1000, 3))
    verts = np.arange(0, 1000, 1)
    verts.shape = (1000, 1)
    pd.verts = verts
    pd.point_data.scalars = np.random.random(1000)
    pd.point_data.scalars.name = 'scalars'

    # Now visualize it using mayavi2.
    from enthought.mayavi.sources.vtk_data_source import VTKDataSource
    from enthought.mayavi.modules.outline import Outline
    from enthought.mayavi.modules.surface import Surface

    mayavi.new_scene()
    d = VTKDataSource()
    d.data = pd
    mayavi.add_source(d)
    mayavi.add_module(Outline())
    s = Surface()
    mayavi.add_module(s)
    s.actor.property.set(representation='p', point_size=2)
# module, you should set opacity to a value below 1, in order to see all
# isosurfaces.
#
# Using Surface module is straightforward:
#
# <codecell>

from enthought.mayavi.modules.surface import Surface

# <markdowncell>

# then
#
# <codecell>

s = Surface()
s.enable_contours = True  # we want contours enabled
s.contour.auto_contours = True  # we want isovalues automatically well-defined
s.contour.number_of_contours = 10  # self-explanatory ;-)
s.actor.property.opacity = 0.2
script.add_module(s)
s.contour.minimum_contour = 0
s.contour.maximum_contour = 1
s.module_manager.scalar_lut_manager.data_range = [0, 1]

# <markdowncell>

# The scene should look like this:
#
# ![](files/MayaVi(2f)ScriptingMayavi2(2f)MainModules_attachments/module_surface.png
#
예제 #24
0
        savename = filename

        scene = engine.new_scene()
        scene.scene.off_screen_rendering = True
        vtk_file_reader = engine.open(filename, scene)

        scene.scene.background = (1.0, 1.0, 1.0)

        from enthought.mayavi.filters.contour import Contour
        contour = Contour()
        engine.add_filter(contour, obj=None)
        from enthought.mayavi.filters.set_active_attribute import SetActiveAttribute
        set_active_attribute = SetActiveAttribute()
        engine.add_filter(set_active_attribute, obj=None)
        from enthought.mayavi.modules.surface import Surface
        surface = Surface()
        engine.add_module(surface, obj=None)

        ##Orientation axes
        orientation_axes = OrientationAxes()
        engine.add_module(orientation_axes, obj=None)
        orientation_axes.text_property.shadow_offset = array([1, -1])
        orientation_axes.text_property.font_family = 'times'
        orientation_axes.text_property.shadow_offset = array([1, -1])
        orientation_axes.text_property.font_size = 15
        orientation_axes.axes.axis_labels = False
        ##

        if os.path.isdir(dir + save_mname) == False:
            os.mkdir(dir + save_mname)
예제 #25
0
    def test_script_recording(self):
        "Does script recording work correctly."
        # Create a mayavi pipeline and record it.
        tape = self.tape
        e = NullEngine()
        e.start()
        # Start recording.
        tape.recording = True
        tape.register(e, known=True, script_id="engine")
        e.new_scene()
        # print tape.script
        self.assertEqual(tape.lines[-1], "dummy_viewer = engine.new_scene()")

        src = ParametricSurface()
        e.add_source(src)
        expect = "from enthought.mayavi.sources.parametric_surface " "import ParametricSurface"
        self.assertEqual(tape.lines[-3], expect)
        self.assertEqual(tape.lines[-2], "parametric_surface = ParametricSurface()")
        self.assertEqual(tape.lines[-1], "engine.add_source(parametric_surface)")

        src.function = "dini"
        self.assertEqual(tape.lines[-1], "parametric_surface.function = 'dini'")

        o = Outline()
        e.add_module(o)
        expect = "from enthought.mayavi.modules.outline import Outline"
        self.assertEqual(tape.lines[-3], expect)
        self.assertEqual(tape.lines[-2], "outline = Outline()")
        self.assertEqual(tape.lines[-1], "engine.add_module(outline)")

        o.actor.property.color = (1, 0, 0)
        self.assertEqual(tape.lines[-1], "outline.actor.property.color = (1.0, 0.0, 0.0)")

        s = Surface()
        e.add_module(s)
        expect = "from enthought.mayavi.modules.surface import Surface"
        self.assertEqual(tape.lines[-3], expect)
        self.assertEqual(tape.lines[-2], "surface = Surface()")
        self.assertEqual(tape.lines[-1], "engine.add_module(surface)")

        s.actor.property.representation = "wireframe"
        self.assertEqual(tape.lines[-1], "surface.actor.property.representation = 'wireframe'")

        o.actor.property.representation = "wireframe"
        self.assertEqual(tape.lines[-1], "outline.actor.property.representation = 'wireframe'")

        s.actor.property.opacity = 0.5
        self.assertEqual(tape.lines[-1], "surface.actor.property.opacity = 0.5")

        s.actor.mapper.scalar_visibility = False
        self.assertEqual(tape.lines[-1], "surface.actor.mapper.scalar_visibility = False")

        # print tape.script

        # Stop recording and test.
        tape.unregister(e)
        tape.record("#end")  # Placeholder
        o.actor.property.opacity = 0.5
        self.assertEqual(tape.lines[-1], "#end")
        s.actor.property.color = (1, 0, 0)
        self.assertEqual(tape.lines[-1], "#end")
        s.enable_contours = True
        self.assertEqual(tape.lines[-1], "#end")
        src.function = "klein"
        self.assertEqual(tape.lines[-1], "#end")
예제 #26
0
def view():
    from enthought.mayavi.sources.vtk_data_source import VTKDataSource
    #from enthought.mayavi.modules.outline import Outline
    from enthought.mayavi.modules.surface import Surface
    from enthought.mayavi.modules.axes import Axes
    from enthought.mayavi.modules.text import Text

    scene = mayavi.new_scene()
    scene.scene.background = (1.0, 1.0, 1.0)
    scene.scene.foreground = (0.0, 0.0, 0.0)
    trj_src = VTKDataSource(data=trj_curve)
    mayavi.add_source(trj_src)
    # mayavi.add_module(Outline())
    s = Surface()
    mayavi.add_module(s)
    s.actor.property.set(representation='w', color=(1., 0., 0.), line_width=1)

    gt_src = VTKDataSource(data=gt_curve)
    mayavi.add_source(gt_src)
    #mayavi.add_module(Outline())
    s = Surface()
    mayavi.add_module(s)
    s.actor.property.set(representation='w', color=(0., 1., 0.), line_width=2)

    # skeleton nodes
    if draw_skeleton:
        # draw the nodes
        skel_node_src = VTKDataSource(data=skel_nodes_pts)
        mayavi.add_source(skel_node_src)
        #mayavi.add_module(Outline())
        s = Surface()
        mayavi.add_module(s)
        s.actor.property.set(representation='p',
                             point_size=4,
                             color=(0., 0., 1.0))

        # draw edges between nodes
        skel_curve_src = VTKDataSource(data=skel_curve)
        mayavi.add_source(skel_curve_src)
        #mayavi.add_module(Outline())
        s = Surface()
        mayavi.add_module(s)
        s.actor.property.set(representation='w',
                             color=(1., 0., 1.0),
                             line_width=2)

        # draw the links
        skel_edge_src = VTKDataSource(data=skel_edges)
        mayavi.add_source(skel_edge_src)
        #mayavi.add_module(Outline())
        s = Surface()
        mayavi.add_module(s)
        s.actor.property.set(representation='w',
                             color=(0., 0., 1.),
                             line_width=1)

    a = Axes()
    mayavi.add_module(a)
    # Put up some text.
    t = Text(text='VSLAM vs PhaseSpace',
             x_position=0.2,
             y_position=0.9,
             width=0.8)
    t.property.color = 1, 1, 0  # Bright yellow, yeah!
    mayavi.add_module(t)
# <markdowncell>

# then
# 
# <codecell>


### for the metallic parallellepiped
script.engine.current_object = src  # current object must be set to the source
eug1 = ExtractUnstructuredGrid()
script.add_filter(eug1)
eug1.filter.cell_clipping = True
eug1.filter.cell_minimum = 342881
eug1.filter.cell_maximum = 345966
s = Surface()                       # the metallic is displayed using Surface module
eug1.add_module(s)                  # the module must be added to the current filter
s.actor.mapper.scalar_visibility = False
s.actor.property.color = (0.509804, 0.5098040, 0.5490196) # grey color for the metallic parallellepiped

### we need also extract the required cells for and only for the vaccum
script.engine.current_object = src  # current object must be set to the source
eug2 = ExtractUnstructuredGrid()
script.add_filter(eug2)
eug2.filter.cell_clipping = True
eug2.filter.cell_minimum = 0
eug2.filter.cell_maximum = 342880

### here, we can display the EM field using ScalarCutPlane/VectorCutPlane,
### Surface, Vectors modules as usual
.../...
예제 #28
0
def f(x, y):
    return numpy.sin(x * y) / (x * y)


x = numpy.arange(-7., 7.05, 0.1)
y = numpy.arange(-5., 5.05, 0.05)
from enthought.tvtk.tools import mlab
s = mlab.SurfRegular(x, y, f)
from enthought.mayavi.sources.vtk_data_source import VTKDataSource
d = VTKDataSource()
d.data = s.data
mayavi.add_source(d)
from enthought.mayavi.filters.warp_scalar import WarpScalar
w = WarpScalar()
mayavi.add_filter(w)
from enthought.mayavi.modules.outline import Outline
from enthought.mayavi.modules.surface import Surface
o = Outline()
s = Surface()
mayavi.add_module(o)
mayavi.add_module(s)

# <markdowncell>

# You can run this script by running "mayavi2 -n -x script.py", loading it
# through the menu (File -\> Open File), and pressing Ctrl+R, or entering
# "execfile('script.py') in the python shell.
#
# ![](files/MayaVi(2f)Surf_attachments/surf.png
#
# 
# Using Surface module is straightforward:
# 
# <codecell>


from enthought.mayavi.modules.surface import Surface

# <markdowncell>

# then
# 
# <codecell>


s = Surface()
s.enable_contours = True # we want contours enabled
s.contour.auto_contours = True # we want isovalues automatically well-defined
s.contour.number_of_contours = 10 # self-explanatory ;-)
s.actor.property.opacity = 0.2
script.add_module(s)
s.contour.minimum_contour = 0
s.contour.maximum_contour = 1
s.module_manager.scalar_lut_manager.data_range = [0, 1]

# <markdowncell>

# The scene should look like this:
# 
# ![](files/MayaVi(2f)ScriptingMayavi2(2f)MainModules_attachments/module_surface.png
# 
예제 #30
0
    def _setupScene(self,
                    showFault=True,
                    showMaterials=True,
                    showFaultTaper=False):
        """
    Plot axes, fault surface, and materials.
    """

        from enthought.mayavi.modules.outline import Outline
        from enthought.mayavi.modules.axes import Axes
        from enthought.mayavi.modules.surface import Surface

        # Create rendering scene
        script = self.script
        script.new_scene()
        script.engine.current_scene.scene.background = (1, 1, 1)
        script.engine.current_scene.scene.foreground = (0, 0, 0)
        vtk_geometry.setCamera(script.engine.current_scene.scene.camera)

        # Domain (axes and outline)
        script.add_source(VTKDataSource(data=vtk_geometry.domain()))
        script.engine.current_object.name = "Domain"
        outline = Outline()
        script.add_module(outline)
        outline.actor.property.opacity = 0.2
        axes = Axes()
        axes.axes.x_label = "X (km)"
        axes.axes.y_label = "Y (km)"
        axes.axes.z_label = "Z (km)"
        axes.axes.label_format = "%-0.1f"
        script.add_module(axes)

        # Fault surface
        if showFault:
            srcs = vtk_geometry.fault(showTaper=showFaultTaper)
            for src in srcs:
                script.add_source(VTKDataSource(data=src['object']))
                script.engine.current_object.name = "Fault %s" % src['name']
                surf = Surface()
                script.add_module(surf)
                surf.actor.property.color = (1, 0, 0)
                if src['name'] == "taper":
                    surf.actor.property.opacity = 0.1
                else:
                    surf.actor.property.opacity = 0.3

        # Materials
        if showMaterials:
            srcs = vtk_geometry.materials()
            for src in srcs:
                script.add_source(VTKDataSource(data=src['object']))
                script.engine.current_object.name = "Material %s" % src['name']
                surf = Surface()
                script.add_module(surf)
                surf.actor.property.opacity = 0.1
                if src['name'] == "elastic":
                    surf.actor.property.color = (1, 1, 0)
                elif src['name'] == "viscoelastic":
                    surf.actor.property.color = (0, 1, 1)

        return
from enthought.mayavi.filters.extract_unstructured_grid import ExtractUnstructuredGrid

# <markdowncell>

# then
#
# <codecell>

### for the metallic parallellepiped
script.engine.current_object = src  # current object must be set to the source
eug1 = ExtractUnstructuredGrid()
script.add_filter(eug1)
eug1.filter.cell_clipping = True
eug1.filter.cell_minimum = 342881
eug1.filter.cell_maximum = 345966
s = Surface()  # the metallic is displayed using Surface module
eug1.add_module(s)  # the module must be added to the current filter
s.actor.mapper.scalar_visibility = False
s.actor.property.color = (0.509804, 0.5098040, 0.5490196
                          )  # grey color for the metallic parallellepiped

### we need also extract the required cells for and only for the vaccum
script.engine.current_object = src  # current object must be set to the source
eug2 = ExtractUnstructuredGrid()
script.add_filter(eug2)
eug2.filter.cell_clipping = True
eug2.filter.cell_minimum = 0
eug2.filter.cell_maximum = 342880

### here, we can display the EM field using ScalarCutPlane/VectorCutPlane,
### Surface, Vectors modules as usual
예제 #32
0
    def do(self):
        ############################################################
        # Imports.
        script = self.script
        from enthought.mayavi.sources.array_source import ArraySource
        from enthought.mayavi.modules.outline import Outline
        from enthought.mayavi.modules.surface import Surface
        from enthought.mayavi.modules.vectors import Vectors        
        
        ############################################################
        # Create a new scene and set up the visualization.
        s = self.new_scene()

        d = ArraySource()
        self.check_input_validation(d)
        sc, vec = self.make_2d_data()
        d.origin = (-1, -1, 0)
        d.scalar_data = sc
        d.vector_data = vec

        script.add_source(d)

        # Create an outline for the data.
        o = Outline()
        script.add_module(o)
        # View the data.
        s = Surface()
        script.add_module(s)        
        v = Vectors()
        script.add_module(v)        

        # Add a 3D data source
        d = ArraySource()
        sc, vec = self.make_3d_data()
        d.scalar_data = sc
        d.vector_data = vec
        script.add_source(d)
        # Create an outline for the data.
        o = Outline()
        script.add_module(o)
        # View a slice.
        s = Surface()
        script.add_module(s)        
        v = Vectors()
        script.add_module(v)        

        # Set the scene to a suitable view.
        s.scene.z_plus_view()
        c = s.scene.camera
        c.azimuth(-30)
        c.elevation(30)
       
        self.check()

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

        bg = s.scene.background
        # 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

        # Set the scene to a suitable view.
        s.scene.z_plus_view()
        c = s.scene.camera
        c.azimuth(-30)
        c.elevation(30)
        s.scene.background = bg

        self.check()

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

        # Pop the source object.
        sources = s.children
        s.children = []
        # Add it back to see if that works without error.
        s.children.extend(sources)

        s.scene.reset_zoom()
        
        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.
        sources1 = copy.deepcopy(sources)
        s.children[:] = sources
        s.scene.reset_zoom()
        self.check()