Exemplo n.º 1
0
 def __init__(self):
     self.fig = mlab.figure()
     self.scene = self.fig.scene
     src = ArraySource(transpose_input_array=False)
     src.scalar_data = np.random.randn(10,10,10)
     src.origin = [-50,-50,-50]
     src.spacing = [10,10,10]
     mlab.pipeline.image_plane_widget(src, figure=self.fig)
Exemplo n.º 2
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()
        self.e = e
        self.s = s

        ############################################################
        # Create a new scene and set up the visualization.

        d = ArraySource()
        sc, vec = self.make_data()
        d.origin = (-5, -5, -5)
        d.scalar_data = sc
        d.vector_data = vec

        e.add_source(d)

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

        # View the data.
        st = Streamline()
        e.add_module(st)
        widget = st.seed.widget
        widget.set(radius=1.0,
                   center=(-4.0, -4.0, -4.0),
                   theta_resolution=4,
                   phi_resolution=4)

        st = Streamline(streamline_type='ribbon')
        seed = st.seed
        seed.widget = seed.widget_list[1]
        e.add_module(st)
        seed.widget.set(point1=(-5.0, -4.5, -4.0), point2=(-5.0, -4.5, 4.0))
        st.ribbon_filter.width = 0.25

        st = Streamline(streamline_type='tube')
        seed = st.seed
        seed.widget = seed.widget_list[2]
        e.add_module(st)
        seed.widget.set(center=(-5.0, 1.5, -2.5))
        st.tube_filter.radius = 0.15

        st = Streamline(streamline_type='tube')
        seed = st.seed
        seed.widget = seed.widget_list[3]
        e.add_module(st)
        seed.widget.position = (-5.0, 3.75, 3.75)
        st.tube_filter.radius = 0.2
        self.st = st
        self.scene = e.current_scene
        return
Exemplo n.º 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()
        s=e.new_scene()
        self.e=e
        self.s=s

        ############################################################
        # Create a new scene and set up the visualization.

        d = ArraySource()
        sc, vec = self.make_data()
        d.origin = (-5, -5, -5)
        d.scalar_data = sc
        d.vector_data = vec

        e.add_source(d)

        # Create an outline for the data.
        o = Outline()
        e.add_module(o)
        
        # View the data.
        st = Streamline()
        e.add_module(st)
        widget = st.seed.widget
        widget.set(radius=1.0, center=(-4.0, -4.0, -4.0),
                   theta_resolution=4, phi_resolution=4)

        st = Streamline(streamline_type='ribbon')
        seed = st.seed
        seed.widget = seed.widget_list[1]
        e.add_module(st)
        seed.widget.set(point1=(-5.0, -4.5, -4.0), point2=(-5.0, -4.5, 4.0))
        st.ribbon_filter.width = 0.25

        st = Streamline(streamline_type='tube')
        seed = st.seed
        seed.widget = seed.widget_list[2]
        e.add_module(st)
        seed.widget.set(center=(-5.0, 1.5, -2.5))
        st.tube_filter.radius = 0.15

        st = Streamline(streamline_type='tube')
        seed = st.seed
        seed.widget = seed.widget_list[3]
        e.add_module(st)
        seed.widget.position=(-5.0, 3.75, 3.75)
        st.tube_filter.radius = 0.2
        self.st = st
        self.scene = e.current_scene
        return
Exemplo n.º 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()
        self.e=e
        self.s=s

        ############################################################
        # Create a new scene and set up the visualization.

        d = ArraySource()
        sc, vec = self.make_data()
        d.origin = (-5, -5, -5)
        d.scalar_data = sc
        d.vector_data = vec

        e.add_source(d)

        # Create an outline for the data.
        o = Outline()
        e.add_module(o)
        # Glyphs for the scalars
        g = Glyph()
        e.add_module(g)
        g.glyph.glyph_source.glyph_position = 'center'
        g.glyph.glyph.vector_mode = 'use_normal'
        g.glyph.glyph.scale_factor = 0.5
        g.actor.property.line_width = 1.0

        v = VectorCutPlane()
        glyph = v.glyph
        gs = glyph.glyph_source
        gs.glyph_position = 'tail'
        gs.glyph_source = gs.glyph_list[1]
        e.add_module(v)
        v.implicit_plane.set(normal=(0, 1, 0), origin=(0, 3, 0))
        
        v = VectorCutPlane()
        glyph = v.glyph
        gs = glyph.glyph_source
        gs.glyph_source = gs.glyph_list[2]
        gs.glyph_position = 'head'
        e.add_module(v)
        v.implicit_plane.set(normal=(0, 1, 0), origin=(0, -2, 0))
        self.g=g
        self.v=v
        self.scene = e.current_scene
        return
Exemplo n.º 5
0
def view_numpy():
    
    if 0:
    
        """Example showing how to view a 3D numpy array in mayavi2.
        """
        # 'mayavi' is always defined on the interpreter.
        mayavi.new_scene()
        #print mayavi.new_scene()
        print mayavi.new_scene.__doc__
        print type(mayavi)
        print type(mayavi.get_active_window())
        # Make the data and add it to the pipeline.
        data = make_data()
        src = ArraySource(transpose_input_array=False)
        src.scalar_data = data    
        mayavi.add_source(src)
        # Visualize the data.
        o = Outline()
        mayavi.add_module(o)
        ipw = ImagePlaneWidget()
        mayavi.add_module(ipw)
        ipw.module_manager.scalar_lut_manager.show_scalar_bar = True
    
        ipw_y = ImagePlaneWidget()
        mayavi.add_module(ipw_y)
        ipw_y.ipw.plane_orientation = 'y_axes'




#    # Create the data.
#    from numpy import pi, sin, cos, mgrid
#    dphi, dtheta = pi/250.0, pi/250.0
#    [phi,theta] = mgrid[0:pi+dphi*1.5:dphi,0:2*pi+dtheta*1.5:dtheta]
#    m0 = 4; m1 = 3; m2 = 2; m3 = 3; m4 = 6; m5 = 2; m6 = 6; m7 = 4;
#    r = sin(m0*phi)**m1 + cos(m2*phi)**m3 + sin(m4*theta)**m5 + cos(m6*theta)**m7
#    x = r*sin(phi)*cos(theta)
#    y = r*cos(phi)
#    z = r*sin(phi)*sin(theta)
#    
#    # View it.
#    from enthought.mayavi import mlab
#    s = mlab.mesh(x, y, z)
#    #mlab.show()





    my_test_molecule()
Exemplo n.º 6
0
def contour(i, x):
    """The script itself.  We needn't have defined a function but
    having a function makes this more reusable.
    """
    # 'mayavi' is always defined on the interpreter.
    # Create a new scene.
    mayavi.new_scene()

    # Read in datacube
    fd = open("output/output-cube-%.8d-%.3d" % (i, 0))
    rho, rhovx, rhovz, rhovy = numpy.fromfile(file=fd,
                                              dtype=numpy.float32).reshape(
                                                  (4, x, x, x))
    src = ArraySource(transpose_input_array=False)
    src.scalar_data = numpy.log10(rho).T.copy()
    mayavi.add_source(src)

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

    # Create one ContourGridPlane normal to the 'x' axis.
    cgp = ContourGridPlane()
    mayavi.add_module(cgp)
    # Set the position to the middle of the data.
    cgp.grid_plane.position = 0

    # Another normal to 'y' axis.
    cgp = ContourGridPlane()
    mayavi.add_module(cgp)
    # Set the axis and position to the middle of the data.
    cgp.grid_plane.axis = 'y'
    cgp.grid_plane.position = 0

    # Another normal to 'z' axis.
    cgp = ContourGridPlane()
    mayavi.add_module(cgp)
    # Set the axis and position to the middle of the data.
    cgp.grid_plane.axis = 'z'
    cgp.grid_plane.position = 0

    # An isosurface module.
    iso = IsoSurface(compute_normals=False)
    mayavi.add_module(iso)
    iso.contour.contours = [220.0]

    # An interactive scalar cut plane.
    cp = ScalarCutPlane()
    mayavi.add_module(cp)
    cp.implicit_plane.normal = 0, 0, 1
def contour(i,x):
    """The script itself.  We needn't have defined a function but
    having a function makes this more reusable.
    """
    # 'mayavi' is always defined on the interpreter.
    # Create a new scene.
    mayavi.new_scene()

    # Read in datacube
    fd = open("output/output-cube-%.8d-%.3d"%(i,0))
    rho, rhovx, rhovz, rhovy = numpy.fromfile(file=fd,dtype=numpy.float32).reshape((4,x,x,x))
    src = ArraySource(transpose_input_array=False)
    src.scalar_data = numpy.log10(rho).T.copy()
    mayavi.add_source(src)

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

    # Create one ContourGridPlane normal to the 'x' axis.
    cgp = ContourGridPlane()
    mayavi.add_module(cgp)
    # Set the position to the middle of the data.
    cgp.grid_plane.position = 0

    # Another normal to 'y' axis.
    cgp = ContourGridPlane()
    mayavi.add_module(cgp)
    # Set the axis and position to the middle of the data.
    cgp.grid_plane.axis = 'y'
    cgp.grid_plane.position = 0
    
    # Another normal to 'z' axis.
    cgp = ContourGridPlane()
    mayavi.add_module(cgp)
    # Set the axis and position to the middle of the data.
    cgp.grid_plane.axis = 'z'
    cgp.grid_plane.position = 0

    # An isosurface module.
    iso = IsoSurface(compute_normals=False)
    mayavi.add_module(iso)
    iso.contour.contours = [220.0]

    # An interactive scalar cut plane.
    cp = ScalarCutPlane()
    mayavi.add_module(cp)
    cp.implicit_plane.normal = 0,0,1
Exemplo n.º 8
0
 def _create_data_fired(self):
     mayavi = self.get_mayavi()
     from enthought.mayavi.sources.array_source import ArraySource
     s = self._make_data()
     src = ArraySource(transpose_input_array=False, scalar_data=s)
     self.source = src
     mayavi.add_source(src)
Exemplo n.º 9
0
 def _mk_image_data(self):
     """ Creates an ImageData VTK data set and the associated ArraySource 
         using the factory's attributes.
     """
     self._mayavi_source = ArraySource(transpose_input_array=True,
                                       scalar_data=self.scalar_data,
                                       origin=[0., 0., 0],
                                       spacing=[1, 1, 1])
     self._vtk_source = self._mayavi_source.image_data
Exemplo n.º 10
0
def view_numpy():
    """Example showing how to view a 3D numpy array in mayavi2.
    """
    # 'mayavi' is always defined on the interpreter.
    mayavi.new_scene()
    # Make the data and add it to the pipeline.
    data = make_data()
    src = ArraySource(transpose_input_array=False)
    src.scalar_data = data    
    mayavi.add_source(src)
    # Visualize the data.
    o = Outline()
    mayavi.add_module(o)
    ipw = ImagePlaneWidget()
    mayavi.add_module(ipw)
    ipw.module_manager.scalar_lut_manager.show_scalar_bar = True

    ipw_y = ImagePlaneWidget()
    mayavi.add_module(ipw_y)
    ipw_y.ipw.plane_orientation = 'y_axes'
Exemplo n.º 11
0
    def reset(self, **traits):
        """Creates the dataset afresh or resets existing data source."""

        # First set the attributes without really doing anything since
        # the notification handlers are not called.
        self.set(trait_change_notify=False, **traits)

        vectors = self.vectors
        scalars = self.scalars
        x, y, z = [np.atleast_3d(a) for a in self.x, self.y, self.z]
    
        u, v, w = self.u, self.v, self.w
        if 'vectors' in traits:
            u=vectors[:,0].ravel()
            v=vectors[:,1].ravel()
            w=vectors[:,2].ravel()
            self.set(u=u,v=v,w=w,trait_change_notify=False)

        else:
            if u is not None and len(u) > 0:
                #vectors = np.concatenate([u[..., np.newaxis],
                #                             v[..., np.newaxis],
                #                             w[..., np.newaxis] ],
                #                axis=3)
                vectors = np.c_[u.ravel(), v.ravel(),
                                   w.ravel()].ravel()
                vectors.shape = (u.shape[0] , u.shape[1], w.shape[2], 3)
                self.set(vectors=vectors, trait_change_notify=False)

        if vectors is not None and len(vectors) > 0 and scalars is not None:
            assert len(scalars) == len(vectors)

        if x.shape[0] <= 1:
            dx = 1
        else:
            dx = x[1, 0, 0] - x[0, 0, 0]
        if y.shape[1] <= 1:
            dy = 1
        else:
            dy = y[0, 1, 0] - y[0, 0, 0]
        if z.shape[2] <= 1:
            dz = 1
        else:
            dz = z[0, 0, 1] - z[0, 0, 0]
        
        if self.m_data is None:
            ds = ArraySource(transpose_input_array=True)
        else:
            ds = self.m_data
        old_scalar = ds.scalar_data
        ds.set(vector_data=vectors,
               origin=[x.min(), y.min(), z.min()],
               spacing=[dx, dy, dz],
               scalar_data=scalars)
        if scalars is old_scalar:
            ds._scalar_data_changed(scalars)

        self.dataset = ds.image_data
        self.m_data = ds 
Exemplo n.º 12
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()
        self.e=e
        self.s=s

        ############################################################
        # Create a new scene and set up the visualization.

        d = ArraySource()
        sc = self.make_data()
        d.scalar_data = sc

        e.add_source(d)
        self.t = Text3D()
        e.add_module(self.t)

        self.scene = e.current_scene
        return
Exemplo n.º 13
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()
        self.e=e
        self.s=s

        ############################################################
        # Create a new scene and set up the visualization.

        d = ArraySource()
        
        sc = self.make_data()
        d.scalar_data = sc

        e.add_source(d)

        # Create an outline for the data.
        o = Outline()
        e.add_module(o)
        # ImagePlaneWidgets for the scalars
        ipw = ImagePlaneWidget()
        e.add_module(ipw)

        ipw_y = ImagePlaneWidget()
        e.add_module(ipw_y)
        ipw_y.ipw.plane_orientation = 'y_axes'

        ipw_z = ImagePlaneWidget()
        e.add_module(ipw_z)
        ipw_z.ipw.plane_orientation = 'z_axes'
        self.scene = e.current_scene
        return
Exemplo n.º 14
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()
        self.e = e
        self.s = s

        ############################################################
        # Create a new scene and set up the visualization.

        d = ArraySource()

        sc = self.make_data()
        d.scalar_data = sc

        e.add_source(d)

        # Create an outline for the data.
        o = Outline()
        e.add_module(o)
        # ImagePlaneWidgets for the scalars
        ipw = ImagePlaneWidget()
        e.add_module(ipw)

        ipw_y = ImagePlaneWidget()
        e.add_module(ipw_y)
        ipw_y.ipw.plane_orientation = 'y_axes'

        ipw_z = ImagePlaneWidget()
        e.add_module(ipw_z)
        ipw_z.ipw.plane_orientation = 'z_axes'
        self.scene = e.current_scene
        return
Exemplo n.º 15
0
    def reset(self, **traits):
        """Creates the dataset afresh or resets existing data source."""

        # First set the attributes without really doing anything since
        # the notification handlers are not called.
        self.set(trait_change_notify=False, **traits)    
        x, y, mask = self.x, self.y, self.mask
        scalars = self.scalars 
        
        # We may have used this without specifying x and y at all in
        # which case we set them from the shape of scalars.
        nx, ny = scalars.shape       
        
        #Build X and Y from shape of Scalars if they are none
        if x is None and y is None:           
            x, y = np.mgrid[-nx/2.:nx/2, -ny/2.:ny/2]           

        if mask is not None and len(mask) > 0:
            scalars[mask.astype('bool')] = np.nan
            # The NaN trick only works with floats.
            scalars = scalars.astype('float')
            self.set(scalars=scalars, trait_change_notify=False)

        z = np.array([0])     
              
        self.set(x=x, y=y, z=z, trait_change_notify=False)
        # Do some magic to extract the first row/column, independently of
        # the shape of x and y

        x = np.atleast_2d(x.squeeze().T)[0, :].squeeze()
        y = np.atleast_2d(y.squeeze())[0, :].squeeze()    
        
        if x.ndim == 0:
            dx = 1
        else:
            dx = x[1] - x[0]
        if y.ndim == 0:
            dy = 1
        else:
            dy = y[1] - y[0]
        if self.m_data is None:
            ds = ArraySource(transpose_input_array=True)
        else:
            ds = self.m_data
        old_scalar = ds.scalar_data
        ds.set(origin=[x.min(), y.min(), 0],
               spacing=[dx, dy, 1],
               scalar_data=scalars)
        if old_scalar is scalars:
            ds._scalar_data_changed(scalars)
        
        self.dataset = ds.image_data
        self.m_data = ds 
Exemplo n.º 16
0
    def _show_data(self):
        if self.source is not None:
            return
        mayavi = self.get_mayavi()
        if mayavi.engine.current_scene is None:
            mayavi.new_scene()
        from enthought.mayavi.sources.array_source import ArraySource
        vol = self.volume
        origin = vol[::2]
        spacing = (vol[1::2] - origin) / (self.dimensions - 1)
        src = ArraySource(transpose_input_array=False,
                          scalar_data=self.data,
                          origin=origin,
                          spacing=spacing)
        self.source = src
        mayavi.add_source(src)

        from enthought.mayavi.modules.outline import Outline
        from enthought.mayavi.modules.image_plane_widget import ImagePlaneWidget
        from enthought.mayavi.modules.axes import Axes
        # Visualize the data.
        o = Outline()
        mayavi.add_module(o)
        a = Axes()
        mayavi.add_module(a)
        self._ipw1 = ipw = ImagePlaneWidget()
        mayavi.add_module(ipw)
        ipw.module_manager.scalar_lut_manager.show_scalar_bar = True

        self._ipw2 = ipw_y = ImagePlaneWidget()
        mayavi.add_module(ipw_y)
        ipw_y.ipw.plane_orientation = 'y_axes'

        self._ipw3 = ipw_z = ImagePlaneWidget()
        mayavi.add_module(ipw_z)
        ipw_z.ipw.plane_orientation = 'z_axes'
Exemplo n.º 17
0
  data.buf.shape = (data.nx, data.ny, data.nz)
  max_ib=numpy.argmax(data.buf)
  ix,iy,iz=data.get_ix_iy_iz(max_ib)


  

  # 'mayavi' is always defined on the interpreter.
  e = OffScreenEngine()
  #e = Engine()
  e.start()
  win = e.new_scene(magnification=1)
  win.scene.isometric_view()
  
  # Make the data and add it to the pipeline.
  src = ArraySource(transpose_input_array=True)
  src.scalar_data = data.buf
  src.spacing=(data.dx, data.dy, -data.dz)
  src.origin=(data.x_orig, data.y_orig, -data.z_orig)
  #print src.all_trait_names()
#  e.add_source(src)

  # Visualize the data.
#  o = Outline()
#  e.add_module(o)

#  lut=e.scenes[0].children[0].children[0].scalar_lut_manager
#  lut.data_range=[-1,600]
#  lut.show_legend = True
#  lut.data_name = 'Stack'
Exemplo n.º 18
0
    def add_cortical_surf(self):
        # lifted from Gael Varoquax

        # this is fairly brittle-- don't know what will result if
        # the brain is not skull-stripped

        # brain_image is (currently) a copy of the integer indices
        # (not the "real valued" scalars)
        brain_image = self.master_src.blender.main.image_arr.copy()
        np.putmask(brain_image, brain_image>255, 0)

        # since this is skull stripped from BET, the boundary will be
        # wherever the image drops off to 0
        arr = ndimage.gaussian_filter(
            (brain_image > 0).astype('d'), 6
            )
        mask = ndimage.binary_fill_holes(arr > .5)
        # iterations x voxel size ~= erosion depth??
        mask = ndimage.binary_erosion(mask, iterations=5)
        
        arr_blurred = ndimage.gaussian_filter(
            mask.astype('d'), 2
            )

        # This AA filter will rather dangle off the pipeline..
        # it will be the "source" of the ProbeFilter, but we want
        # to keep it pipeline-enabled so that we can dynamically
        # change colors
        point_scalars = surf_to_component[self.surface_component]
        surf_colors = mlab.pipeline.set_active_attribute(
            self.master_src, point_scalars=point_scalars
            )

        # Now, make a new ArraySource with the attributes copied
        # from master_src
        anat_blurred = ArraySource(transpose_input_array=False)
        anat_blurred.scalar_data = arr_blurred
        anat_blurred.scalar_name = 'blurred'
        anat_blurred.origin = self.master_src.data.origin
        anat_blurred.spacing = self.master_src.data.spacing
        anat_blurred = mlab.pipeline.add_dataset(anat_blurred)
        
##         anat_blurred.update_pipeline()
        contour = mlab.pipeline.contour(anat_blurred)
        decimated = mlab.pipeline.decimate_pro(contour)
        extracted = mlab.pipeline.user_defined(
            decimated, filter=self.poly_extractor
            )

        sampler = tvtk.ProbeFilter()
        sampler.source = surf_colors.outputs[0]

        surf_points = mlab.pipeline.user_defined(extracted, filter=sampler)

        self.cortical_surf = mlab.pipeline.surface(
            surf_points,
            opacity=.95
            )
        self.cortical_surf.actor.property.backface_culling = True
        self.bcontour = contour
        self.surf_colors = surf_colors
Exemplo n.º 19
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.glyph import Glyph
        from enthought.mayavi.modules.vector_cut_plane import VectorCutPlane
        
        ############################################################
        # Create a new scene and set up the visualization.
        s = self.new_scene()

        d = ArraySource()
        sc, vec = self.make_data()
        d.origin = (-5, -5, -5)
        d.scalar_data = sc
        d.vector_data = vec

        script.add_source(d)

        # Create an outline for the data.
        o = Outline()
        script.add_module(o)
        # Glyphs for the scalars
        g = Glyph()
        script.add_module(g)
        g.glyph.glyph_source.glyph_position = 'center'
        g.glyph.glyph.vector_mode = 'use_normal'
        g.glyph.glyph.scale_factor = 0.5
        g.actor.property.line_width = 1.0

        v = VectorCutPlane()
        glyph = v.glyph
        gs = glyph.glyph_source
        gs.glyph_position = 'tail'
        gs.glyph_source = gs.glyph_list[1]
        script.add_module(v)
        v.implicit_plane.set(normal=(0, 1, 0), origin=(0, 3, 0))
        
        v = VectorCutPlane()
        glyph = v.glyph
        gs = glyph.glyph_source
        gs.glyph_source = gs.glyph_list[2]
        gs.glyph_position = 'head'
        script.add_module(v)
        v.implicit_plane.set(normal=(0, 1, 0), origin=(0, -2, 0))
        
        # Set the scene to a suitable view.
        self.set_view(s)

        self.check()

        ############################################################
        # Test if the modules respond correctly when the components
        # are changed.
        
        g.actor = g.actor.__class__()
        glyph = g.glyph
        g.glyph = glyph.__class__()
        g.glyph = glyph

        glyph = v.glyph
        v.glyph = glyph.__class__()
        v.glyph = glyph
        v.actor = v.actor.__class__()
        v.cutter = v.cutter.__class__()
        ip = v.implicit_plane
        v.implicit_plane = ip.__class__()
        v.implicit_plane = ip

        s.render()

        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
        # Set the scene to a suitable view.
        self.set_view(s)

        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)

        self.set_view(s)

        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

        self.set_view(s)
        self.check()
Exemplo n.º 20
0
 def setUp(self):
     """Initial setting up of test fixture, automatically called by TestCase before any other test method is invoked"""
     d = ArraySource() 
     self.data = d
Exemplo n.º 21
0
def plot_slice_mayavi(dat_filename,output_file,hyp_x,hyp_y,hyp_z,search_grid_file_name,max_stack_value):

  base_path=os.getenv('WAVELOC_PATH')
  lib_path="%s/lib"%base_path

  # grid geometry
  hdr_file=lib_path + os.sep + search_grid_file_name

  # detection
  detection=50

  # stations
  stations_file="%s/coord_stations_piton"%lib_path
  sta=StationList()
  sta.read_from_file(stations_file)

  # create the object to contain the stations
  pd = tvtk.PolyData()
  pd.points = [[s.x/1000.0, s.y/1000.0, -s.elev/1000.0] for s in sta.stations.values()]

  # create the object to contain the stations
  try:
    pd_hyp = tvtk.PolyData()
    pd_hyp.points=[[hyp_x,hyp_y,hyp_z]]
  except TypeError:
    pass

  # read the dat file
  print dat_filename
  data=QDGrid()
  data.read_NLL_hdr_file(hdr_file)
  data.buf=numpy.fromfile(dat_filename, dtype=numpy.int16)
  max_ib=numpy.argmax(data.buf)
  print max_ib
  max_val=data.buf[max_ib]
  ix,iy,iz=data.get_ix_iy_iz(max_ib)
  #data.buf=numpy.array(data.buf, dtype=numpy.float)
  data.buf.shape = (data.nx, data.ny, data.nz)


  # 'mayavi' is always defined on the interpreter.
  e = OffScreenEngine()
  #e = Engine()
  e.start()
  win = e.new_scene(magnification=1)
  e.current_scene.scene.off_screen_rendering = True
  win.scene.isometric_view()
  
  # Make the data and add it to the pipeline.
  src = ArraySource(transpose_input_array=True)
  src.scalar_data = data.buf
  src.spacing=(data.dx, data.dy, -data.dz)
  src.origin=(data.x_orig, data.y_orig, -data.z_orig)
  e.add_source(src)

  # Visualize the data.
  o = Outline()
  e.add_module(o)

  lut=e.scenes[0].children[0].children[0].scalar_lut_manager
  lut.data_range=[-1,max_stack_value]
  lut.show_legend = True
  lut.data_name = 'Stack'


  # Create one ContourGridPlane normal to the 'x' axis.
  cgp = ContourGridPlane()
  e.add_module(cgp)
  # Set the position to the middle of the data.
  if max_val > detection:
    cgp.grid_plane.position = ix
  else:
    cgp.grid_plane.position = data.nx/2
  cgp.contour.filled_contours = True
  cgp.actor.property.opacity = 0.6
  output=cgp.grid_plane.outputs[0]
  x_data=numpy.array(output.point_data.scalars.to_array())

  # Another with filled contours normal to 'y' axis.
  cgp = ContourGridPlane()
  e.add_module(cgp)
  # Set the axis and position to the middle of the data.
  cgp.grid_plane.axis = 'y'
  if max_val > detection:
    cgp.grid_plane.position = iy
  else:
    cgp.grid_plane.position = data.ny/2
  cgp.contour.filled_contours = True
  cgp.actor.property.opacity = 0.6
  output=cgp.grid_plane.outputs[0]
  y_data=numpy.array(output.point_data.scalars.to_array())

  # Another with filled contours normal to 'z' axis.
  cgp = ContourGridPlane()
  e.add_module(cgp)
  # Set the axis and position to the middle of the data.
  cgp.grid_plane.axis = 'z'
  if max_val > detection:
    cgp.grid_plane.position = iz
  else:
    cgp.grid_plane.position = data.nz/2
  cgp.contour.filled_contours = True
  cgp.actor.property.opacity = 0.6
  output=cgp.grid_plane.outputs[0]
  z_data=numpy.array(output.point_data.scalars.to_array())

  a=Axes()
  e.add_module(a)

  d=VTKDataSource()
  d.data=pd
  e.add_source(d)
  
  g=Glyph()
  e.add_module(g)
  g.glyph.glyph_source.glyph_source=g.glyph.glyph_source.glyph_list[4]
  g.glyph.glyph_source.glyph_source.radius=0.1

  d=VTKDataSource()
  d.data=pd_hyp
  e.add_source(d)
  
  g=Glyph()
  e.add_module(g)
  g.glyph.glyph_source.glyph_source=g.glyph.glyph_source.glyph_list[4]
  g.glyph.glyph_source.glyph_source.radius=0.5
  g.actor.property.color=(0.0,0.0,0.0)



  #view(azimuth=-60,elevation=60,distance=120)
  win.scene.save(output_file,size=(800,800))

  e.stop()
  del win
  del e

  return (x_data, y_data, z_data)
Exemplo n.º 22
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()
Exemplo n.º 23
0
def plot_slice_mayavi(dat_filename, output_file, hyp_x, hyp_y, hyp_z,
                      search_grid_file_name, max_stack_value):

    base_path = os.getenv('WAVELOC_PATH')
    lib_path = "%s/lib" % base_path

    # grid geometry
    hdr_file = lib_path + os.sep + search_grid_file_name

    # detection
    detection = 50

    # stations
    stations_file = "%s/coord_stations_piton" % lib_path
    sta = StationList()
    sta.read_from_file(stations_file)

    # create the object to contain the stations
    pd = tvtk.PolyData()
    pd.points = [[s.x / 1000.0, s.y / 1000.0, -s.elev / 1000.0]
                 for s in sta.stations.values()]

    # create the object to contain the stations
    try:
        pd_hyp = tvtk.PolyData()
        pd_hyp.points = [[hyp_x, hyp_y, hyp_z]]
    except TypeError:
        pass

    # read the dat file
    print dat_filename
    data = QDGrid()
    data.read_NLL_hdr_file(hdr_file)
    data.buf = numpy.fromfile(dat_filename, dtype=numpy.int16)
    max_ib = numpy.argmax(data.buf)
    print max_ib
    max_val = data.buf[max_ib]
    ix, iy, iz = data.get_ix_iy_iz(max_ib)
    #data.buf=numpy.array(data.buf, dtype=numpy.float)
    data.buf.shape = (data.nx, data.ny, data.nz)

    # 'mayavi' is always defined on the interpreter.
    e = OffScreenEngine()
    #e = Engine()
    e.start()
    win = e.new_scene(magnification=1)
    e.current_scene.scene.off_screen_rendering = True
    win.scene.isometric_view()

    # Make the data and add it to the pipeline.
    src = ArraySource(transpose_input_array=True)
    src.scalar_data = data.buf
    src.spacing = (data.dx, data.dy, -data.dz)
    src.origin = (data.x_orig, data.y_orig, -data.z_orig)
    e.add_source(src)

    # Visualize the data.
    o = Outline()
    e.add_module(o)

    lut = e.scenes[0].children[0].children[0].scalar_lut_manager
    lut.data_range = [-1, max_stack_value]
    lut.show_legend = True
    lut.data_name = 'Stack'

    # Create one ContourGridPlane normal to the 'x' axis.
    cgp = ContourGridPlane()
    e.add_module(cgp)
    # Set the position to the middle of the data.
    if max_val > detection:
        cgp.grid_plane.position = ix
    else:
        cgp.grid_plane.position = data.nx / 2
    cgp.contour.filled_contours = True
    cgp.actor.property.opacity = 0.6
    output = cgp.grid_plane.outputs[0]
    x_data = numpy.array(output.point_data.scalars.to_array())

    # Another with filled contours normal to 'y' axis.
    cgp = ContourGridPlane()
    e.add_module(cgp)
    # Set the axis and position to the middle of the data.
    cgp.grid_plane.axis = 'y'
    if max_val > detection:
        cgp.grid_plane.position = iy
    else:
        cgp.grid_plane.position = data.ny / 2
    cgp.contour.filled_contours = True
    cgp.actor.property.opacity = 0.6
    output = cgp.grid_plane.outputs[0]
    y_data = numpy.array(output.point_data.scalars.to_array())

    # Another with filled contours normal to 'z' axis.
    cgp = ContourGridPlane()
    e.add_module(cgp)
    # Set the axis and position to the middle of the data.
    cgp.grid_plane.axis = 'z'
    if max_val > detection:
        cgp.grid_plane.position = iz
    else:
        cgp.grid_plane.position = data.nz / 2
    cgp.contour.filled_contours = True
    cgp.actor.property.opacity = 0.6
    output = cgp.grid_plane.outputs[0]
    z_data = numpy.array(output.point_data.scalars.to_array())

    a = Axes()
    e.add_module(a)

    d = VTKDataSource()
    d.data = pd
    e.add_source(d)

    g = Glyph()
    e.add_module(g)
    g.glyph.glyph_source.glyph_source = g.glyph.glyph_source.glyph_list[4]
    g.glyph.glyph_source.glyph_source.radius = 0.1

    d = VTKDataSource()
    d.data = pd_hyp
    e.add_source(d)

    g = Glyph()
    e.add_module(g)
    g.glyph.glyph_source.glyph_source = g.glyph.glyph_source.glyph_list[4]
    g.glyph.glyph_source.glyph_source.radius = 0.5
    g.actor.property.color = (0.0, 0.0, 0.0)

    #view(azimuth=-60,elevation=60,distance=120)
    win.scene.save(output_file, size=(800, 800))

    e.stop()
    del win
    del e

    return (x_data, y_data, z_data)
Exemplo n.º 24
0
 def make_src(self, nan=False):
     data = np.empty((3, 3, 3))
     if nan:
         data[0] = np.nan
     data.flat[:] = np.arange(data.size)
     return ArraySource(scalar_data=data)
Exemplo n.º 25
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.streamline import Streamline

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

        d = ArraySource()
        sc, vec = self.make_data()
        d.origin = (-5, -5, -5)
        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.
        st = Streamline()
        script.add_module(st)
        widget = st.seed.widget
        widget.set(radius=1.0,
                   center=(-4.0, -4.0, -4.0),
                   theta_resolution=4,
                   phi_resolution=4)

        st = Streamline(streamline_type='ribbon')
        seed = st.seed
        seed.widget = seed.widget_list[1]
        script.add_module(st)
        seed.widget.set(point1=(-5.0, -4.5, -4.0), point2=(-5.0, -4.5, 4.0))
        st.ribbon_filter.width = 0.25

        st = Streamline(streamline_type='tube')
        seed = st.seed
        seed.widget = seed.widget_list[2]
        script.add_module(st)
        seed.widget.set(center=(-5.0, 1.5, -2.5))
        st.tube_filter.radius = 0.15

        st = Streamline(streamline_type='tube')
        seed = st.seed
        seed.widget = seed.widget_list[3]
        script.add_module(st)
        seed.widget.position = (-5.0, 3.75, 3.75)
        st.tube_filter.radius = 0.2

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

        # Now compare the image.
        self.compare_image(s, 'images/test_streamline.png')

        ############################################################
        # Test if the modules respond correctly when the components
        # are changed.

        tf = st.tube_filter
        st.tube_filter = tf.__class__()
        st.tube_filter = tf
        st.ribbon_filter = st.ribbon_filter.__class__()
        seed = st.seed
        st.seed = seed.__class__()
        st.seed = seed
        st.actor = st.actor.__class__()
        tracer = st.stream_tracer
        st.stream_tracer = tracer.__class__()
        st.stream_tracer = tracer

        s.render()
        # Now compare the image.
        self.compare_image(s, 'images/test_streamline.png')
        s.render()

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

        # Now compare the image.
        self.compare_image(s, 'images/test_streamline.png')

        ############################################################
        # 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()
        # Now compare the image.
        self.compare_image(s, 'images/test_streamline.png')

        # 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.compare_image(s, 'images/test_streamline.png')
Exemplo n.º 26
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.streamline import Streamline
        
        ############################################################
        # Create a new scene and set up the visualization.
        s = self.new_scene()

        d = ArraySource()
        sc, vec = self.make_data()
        d.origin = (-5, -5, -5)
        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.
        st = Streamline()
        script.add_module(st)
        widget = st.seed.widget
        widget.set(radius=1.0, center=(-4.0, -4.0, -4.0),
                   theta_resolution=4, phi_resolution=4)

        st = Streamline(streamline_type='ribbon')
        seed = st.seed
        seed.widget = seed.widget_list[1]
        script.add_module(st)
        seed.widget.set(point1=(-5.0, -4.5, -4.0), point2=(-5.0, -4.5, 4.0))
        st.ribbon_filter.width = 0.25

        st = Streamline(streamline_type='tube')
        seed = st.seed
        seed.widget = seed.widget_list[2]
        script.add_module(st)
        seed.widget.set(center=(-5.0, 1.5, -2.5))
        st.tube_filter.radius = 0.15

        st = Streamline(streamline_type='tube')
        seed = st.seed
        seed.widget = seed.widget_list[3]
        script.add_module(st)
        seed.widget.position=(-5.0, 3.75, 3.75)
        st.tube_filter.radius = 0.2

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

        # Now compare the image.
        self.compare_image(s, 'images/test_streamline.png')

        ############################################################
        # Test if the modules respond correctly when the components
        # are changed.

        tf = st.tube_filter
        st.tube_filter = tf.__class__()
        st.tube_filter = tf
        st.ribbon_filter = st.ribbon_filter.__class__()
        seed = st.seed
        st.seed = seed.__class__()
        st.seed = seed
        st.actor = st.actor.__class__()
        tracer = st.stream_tracer
        st.stream_tracer = tracer.__class__()
        st.stream_tracer = tracer

        s.render()
        # Now compare the image.
        self.compare_image(s, 'images/test_streamline.png')
        s.render()

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

        # Now compare the image.
        self.compare_image(s, 'images/test_streamline.png')

        ############################################################
        # 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()
        # Now compare the image.
        self.compare_image(s, 'images/test_streamline.png')

        # 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.compare_image(s, 'images/test_streamline.png')
Exemplo n.º 27
0
ny = 100
nz = 60

# Import Array

# electrostatics information
data = numpy.loadtxt(field)

row1 = data[:,3]


# Adjust the shape of the data
plotdata = row1.reshape((nx,ny))


src1 = ArraySource(transpose_input_array=True)
src1.name = u'Daten'
src1.scalar_data = plotdata
mayavi.add_source(src1)

# ------------------------------------------- 
#array_source = engine.scenes[0].children[0]
#engine.add_filter(<enthought.mayavi.modules.iso_surface.IsoSurface object at 0xa1a8059c>, array_source)
# ------------------------------------------- 
#from enthought.mayavi.tools.show import show
#show()

iso_surface = IsoSurface()
array_source = engine.scenes[0].children[0]
engine.add_filter(iso_surface, array_source)
Lx = 1
Ly = 1
Lz = 1

x, y, z = ogrid[0:Lx:(Nx+1)*1j,0:Ly:(Ny+1)*1j,0:Lz:(Nz+1)*1j]

# Strictly speaking, H is the magnetic field of the "transverse electric" eigenmode m=n=p=1
# of a rectangular resonator cavity, with dimensions Lx, Ly, Lz
Hx = sin(x*pi/Lx)*cos(y*pi/Ly)*cos(z*pi/Lz)
Hy = cos(x*pi/Lx)*sin(y*pi/Ly)*cos(z*pi/Lz)
Hz = cos(x*pi/Lx)*cos(y*pi/Ly)*sin(z*pi/Lz)
Hv_scal = sqrt(Hx**2 + Hy**2 + Hz**2)

# We want to load a scalars data (Hv_scal) as magnitude of a given 3D vector (Hv = {Hx, Hy, Hz})
# Hv_scal is a 3D scalars data, Hv is a 4D scalars data
src = ArraySource()
src.scalar_data = Hv_scal # load scalars data

# To load vectors data
# src.vector_data = Hv

# <markdowncell>

# Loading data from file using FileReader methods
# -----------------------------------------------
# 
# To load a VTK data file, say heart.vtk file in mayavi/examples/data/
# directory, simply type:
# 
# <codecell>
Exemplo n.º 29
0
    data.buf = numpy.fromfile(data_file, dtype=numpy.int16)
    data.buf = numpy.array(data.buf, dtype=numpy.float)
    print data.buf.min(), data.buf.max()
    data.buf.shape = (data.nx, data.ny, data.nz)
    max_ib = numpy.argmax(data.buf)
    ix, iy, iz = data.get_ix_iy_iz(max_ib)

    # 'mayavi' is always defined on the interpreter.
    e = OffScreenEngine()
    #e = Engine()
    e.start()
    win = e.new_scene(magnification=1)
    win.scene.isometric_view()

    # Make the data and add it to the pipeline.
    src = ArraySource(transpose_input_array=True)
    src.scalar_data = data.buf
    src.spacing = (data.dx, data.dy, -data.dz)
    src.origin = (data.x_orig, data.y_orig, -data.z_orig)
    #print src.all_trait_names()
    #  e.add_source(src)

    # Visualize the data.
    #  o = Outline()
    #  e.add_module(o)

    #  lut=e.scenes[0].children[0].children[0].scalar_lut_manager
    #  lut.data_range=[-1,600]
    #  lut.show_legend = True
    #  lut.data_name = 'Stack'
Exemplo n.º 30
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.glyph import Glyph
        from enthought.mayavi.modules.vector_cut_plane import VectorCutPlane

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

        d = ArraySource()
        sc, vec = self.make_data()
        d.origin = (-5, -5, -5)
        d.scalar_data = sc
        d.vector_data = vec

        script.add_source(d)

        # Create an outline for the data.
        o = Outline()
        script.add_module(o)
        # Glyphs for the scalars
        g = Glyph()
        script.add_module(g)
        g.glyph.glyph_source.glyph_position = 'center'
        g.glyph.glyph.vector_mode = 'use_normal'
        g.glyph.glyph.scale_factor = 0.5
        g.actor.property.line_width = 1.0

        v = VectorCutPlane()
        glyph = v.glyph
        gs = glyph.glyph_source
        gs.glyph_position = 'tail'
        gs.glyph_source = gs.glyph_list[1]
        script.add_module(v)
        v.implicit_plane.set(normal=(0, 1, 0), origin=(0, 3, 0))

        v = VectorCutPlane()
        glyph = v.glyph
        gs = glyph.glyph_source
        gs.glyph_source = gs.glyph_list[2]
        gs.glyph_position = 'head'
        script.add_module(v)
        v.implicit_plane.set(normal=(0, 1, 0), origin=(0, -2, 0))

        # Set the scene to a suitable view.
        self.set_view(s)

        self.check()

        ############################################################
        # Test if the modules respond correctly when the components
        # are changed.

        g.actor = g.actor.__class__()
        glyph = g.glyph
        g.glyph = glyph.__class__()
        g.glyph = glyph

        glyph = v.glyph
        v.glyph = glyph.__class__()
        v.glyph = glyph
        v.actor = v.actor.__class__()
        v.cutter = v.cutter.__class__()
        ip = v.implicit_plane
        v.implicit_plane = ip.__class__()
        v.implicit_plane = ip

        s.render()

        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
        # Set the scene to a suitable view.
        self.set_view(s)

        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)

        self.set_view(s)

        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

        self.set_view(s)
        self.check()
Exemplo n.º 31
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.image_plane_widget import ImagePlaneWidget
        
        ############################################################
        # Create a new scene and set up the visualization.
        s = self.new_scene()

        d = ArraySource()
        sc = self.make_data()
        d.scalar_data = sc

        script.add_source(d)

        # Create an outline for the data.
        o = Outline()
        script.add_module(o)
        # ImagePlaneWidgets for the scalars
        ipw = ImagePlaneWidget()
        script.add_module(ipw)

        ipw_y = ImagePlaneWidget()
        script.add_module(ipw_y)
        ipw_y.ipw.plane_orientation = 'y_axes'

        ipw_z = ImagePlaneWidget()
        script.add_module(ipw_z)
        ipw_z.ipw.plane_orientation = 'z_axes'
        
        # Set the scene to a suitable view.
        self.set_view(s)

        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
        # Set the scene to a suitable view.
        self.set_view(s)

        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)

        self.set_view(s)

        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

        self.set_view(s)

        self.check()