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
  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
    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
 def _setCamera(self):
   script = self.script
   vtk_geometry.setCamera(script.engine.current_scene.scene.camera)
   return
  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