Exemple #1
0
 def from_vtk(cls, prefix, name):
     """
     read in a result object from available vtk files
     """
     obj = cls()
     obj.configuration = Configuration.from_vtk(prefix, name)
     spr = tvtk.StructuredPointsReader(
         file_name="%s_%s.vtk" % (prefix, name))
     spr.update()
     sp = spr.output    # may need to change to "get_output()" in updated mayavi.tvtk
     for i in range(sp.point_data.number_of_arrays):
         da = sp.point_data.get_array(i)
         name = da.name
         data = da.to_array()
         step = sp.spacing
         origin = sp.origin
         shape = tuple(sp.dimensions)
         dim = shape[::-1]
         if da.number_of_components > 1:
             dim += (da.number_of_components,)
         data = data.reshape(dim).T
         setattr(obj, name, data)
     # FIXME: only uses last array's data for grid
     center = origin+(np.array(shape)-1)/2.*step
     obj.grid = Grid(center=center, step=step, shape=shape)
     return obj
Exemple #2
0
    def make_data(self):
        script = self.script
        from mayavi.sources.vtk_data_source import VTKDataSource
        from tvtk.api import tvtk

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

        # Read a VTK (old style) data file.
        r = tvtk.StructuredPointsReader()
        r.file_name = get_example_data('heart.vtk')
        r.update()
        d = VTKDataSource(data=r.output)
        script.add_source(d)
Exemple #3
0
def zzz_reader(fname, engine):
    """Reader for .zzz files.

    Parameters:
    -----------

    fname -- Filename to be read.

    engine -- The engine the source will be associated with.
    """
    from tvtk.api import tvtk
    from mayavi.sources.vtk_data_source import VTKDataSource
    # Do your own reader stuff here, I'm just reading a VTK file with a
    # different extension here.
    r = tvtk.StructuredPointsReader(file_name=fname)
    r.update()

    src = VTKDataSource(data=r.output)
    return src
Exemple #4
0
    def from_vtk(cls, fil, maxderiv=4):
        """Load grid potential data from vtk StructuredPoints.

        .. note:: needs `tvtk`

        Parameters
        ----------
        fil : str
            File name of the VTK StructuredPoints file containing the
            gridded data.
        maxderiv : int
            Maximum derivative order to precompute.

        Returns
        -------
        GridElectrode
        """
        from tvtk.api import tvtk
        #sgr = tvtk.XMLImageDataReader(file_name=fil)
        sgr = tvtk.StructuredPointsReader(file_name=fil)
        sgr.update()
        sg = sgr.output
        pot = [None, None]
        for i in range(sg.point_data.number_of_arrays):
            name = sg.point_data.get_array_name(i)
            if "_pondpot" in name:
                continue  # not harmonic, do not use it
            elif name not in ("potential", "field"):
                continue
            sp = sg.point_data.get_array(i)
            data = sp.to_array()
            spacing = sg.spacing
            origin = sg.origin
            dimensions = tuple(sg.dimensions)
            dim = sp.number_of_components
            data = data.reshape(dimensions[::-1] + (dim, )).transpose(
                2, 1, 0, 3)
            pot[int((dim - 1) / 2)] = data
        obj = cls(origin=origin, spacing=spacing, data=pot)
        obj.generate(maxderiv)
        return obj