Пример #1
0
    def test_pickle(self):
        """Test if pickler works correctly with FilePaths.
        """
        t = Test()
        t.f.set('t.vtk')
        cwd = os.getcwd()

        # Create a dummy file in the parent dir.
        s = StringIO.StringIO()
        # Spoof its location.
        s.name = abspath(join(cwd, os.pardir, 't.mv2'))
        # Dump into it
        state_pickler.dump(t, s)

        # Rewind the stream
        s.seek(0)
        # "Move" the file elsewhere
        s.name = join(cwd, 'foo', 'test', 't.mv2')
        state = state_pickler.load_state(s)
        self.assertEqual(state.f.abs_pth,
                         join(cwd, 'foo', 'test', 'tests', 't.vtk'))

        # Create a dummy file in a subdir.
        s = StringIO.StringIO()
        # Spoof its location.
        s.name = abspath(join(cwd, 'data', 't.mv2'))
        # Dump into it.
        state_pickler.dump(t, s)

        # Rewind the stream
        s.seek(0)
        # "Move" the file elsewhere
        s.name = join(cwd, 'foo', 'test', 't.mv2')
        state = state_pickler.load_state(s)
        self.assertEqual(state.f.abs_pth, join(cwd, 'foo', 't.vtk'))
Пример #2
0
 def load_visualization(self, file_or_fname):
     """Given a file/file name this loads the visualization."""
     # Save the state of VTK's global warning display.
     o = vtk.vtkObject
     w = o.GetGlobalWarningDisplay()
     o.SetGlobalWarningDisplay(0)  # Turn it off.
     try:
         # Get the state from the file.
         state = state_pickler.load_state(file_or_fname)
         state_pickler.update_state(state)
         # Add the new scenes.
         for scene_state in state.scenes:
             self.new_scene()
             scene = self.scenes[-1]
             # Disable rendering initially.
             if scene.scene is not None:
                 scene.scene.disable_render = True
             # Update the state.
             state_pickler.update_state(scene_state)
             scene.__set_pure_state__(scene_state)
             # Setting the state will automatically reset the
             # disable_render.
             scene.render()
     finally:
         # Reset the warning state.
         o.SetGlobalWarningDisplay(w)
Пример #3
0
 def load_visualization(self, file_or_fname):
     """Given a file/file name this loads the visualization."""
     # Save the state of VTK's global warning display.
     o = vtk.vtkObject
     w = o.GetGlobalWarningDisplay()
     o.SetGlobalWarningDisplay(0) # Turn it off.
     try:
         # Get the state from the file.
         state = state_pickler.load_state(file_or_fname)
         state_pickler.update_state(state)
         # Add the new scenes.
         for scene_state in state.scenes:
             self.new_scene()
             scene = self.scenes[-1]
             # Disable rendering initially.
             if scene.scene is not None:
                 scene.scene.disable_render = True
             # Update the state.
             state_pickler.update_state(scene_state)
             scene.__set_pure_state__(scene_state)
             # Setting the state will automatically reset the
             # disable_render.                                
             scene.render()
     finally:
         # Reset the warning state.
         o.SetGlobalWarningDisplay(w)
Пример #4
0
    def test_pickle(self):
        """Test if pickler works correctly with FilePaths.
        """
        t = Test()
        t.f.set('t.vtk')
        cwd = os.getcwd()

        # Create a dummy file in the parent dir.
        s = StringIO.StringIO()
        # Spoof its location.
        s.name = abspath(join(cwd, os.pardir, 't.mv2'))
        # Dump into it
        state_pickler.dump(t, s)

        # Rewind the stream
        s.seek(0)
        # "Move" the file elsewhere
        s.name = join(cwd, 'foo', 'test', 't.mv2')
        state = state_pickler.load_state(s)
        self.assertEqual(state.f.abs_pth,
                         join(cwd, 'foo', 'test', 'tests', 't.vtk'))


        # Create a dummy file in a subdir.
        s = StringIO.StringIO()
        # Spoof its location.
        s.name = abspath(join(cwd, 'data', 't.mv2'))
        # Dump into it.
        state_pickler.dump(t, s)

        # Rewind the stream
        s.seek(0)
        # "Move" the file elsewhere
        s.name = join(cwd, 'foo', 'test', 't.mv2')
        state = state_pickler.load_state(s)
        self.assertEqual(state.f.abs_pth,
                         join(cwd, 'foo', 't.vtk'))
Пример #5
0
import subprocess

# Enthought library imports.
from enthought.traits.api import Instance, Range, Bool, Array, \
     Str, Property, Enum, Button
from enthought.traits.ui.api import FileEditor, auto_close_message
from enthought.persistence import state_pickler
from enthought.tvtk.api import tvtk

# Local imports.
from enthought.mayavi.core.base import Base
from enthought.mayavi.core.common import error

from enthought.mayavi.core import lut
lut_image_dir = os.path.dirname(lut.__file__)
pylab_luts = state_pickler.load_state(
    os.path.join(lut_image_dir, 'pylab_luts.pkl'))


#################################################################
# Utility functions.
#################################################################
def set_lut(vtk_lut, lut_lst):
    """Setup the tvtk.LookupTable (`vtk_lut`) using the passed list of
    lut values."""
    n_col = len(lut_lst)
    vtk_lut.number_of_colors = n_col
    vtk_lut.build()
    for i in range(0, n_col):
        lt = lut_lst[i]
        vtk_lut.set_table_value(i, lt[0], lt[1], lt[2], lt[3])
Пример #6
0

# Enthought library imports.
from enthought.traits.api import Instance, Range, Bool, Array, \
     Str, Property, Enum, Button
from enthought.traits.ui.api import FileEditor, auto_close_message
from enthought.persistence import state_pickler
from enthought.tvtk.api import tvtk

# Local imports.
from enthought.mayavi.core.base import Base
from enthought.mayavi.core.common import error

from enthought.mayavi.core import lut 
lut_image_dir = os.path.dirname(lut.__file__)
pylab_luts = state_pickler.load_state(os.path.join(lut_image_dir, 
                                                'pylab_luts.pkl'))

#################################################################
# Utility functions.
#################################################################
def set_lut(vtk_lut, lut_lst):
    """Setup the tvtk.LookupTable (`vtk_lut`) using the passed list of
    lut values."""
    n_col = len(lut_lst)
    vtk_lut.number_of_colors = n_col
    vtk_lut.build()
    for i in range(0, n_col):
        lt = lut_lst[i]
        vtk_lut.set_table_value(i, lt[0], lt[1], lt[2], lt[3])

    return vtk_lut