Slice open animation

This Python class can be used to make an animation that takes the current plots and cuts them at X=50% and then rotates the 2 halves back so the interior can be seen.

Sliceopen.png MPEG movie

Using the Script

To make a movie of the animation, use the visit -movie script:

visit -movie -scriptfile SliceOpen.py -format mpeg -geometry 400x400 -output sliceopen

Script

############################################################################
# Class: SliceOpen
#
# Purpose: This class replicates plots and slices them open, making an
#          animation of the process.
#
# Programmer: Brad Whitlock
# Date: Thu May  3 17:30:51 PDT 2012
#
# Modifications:
#
############################################################################

class SliceOpen:
    def __init__(self):
        self.nFrames = 0
        self.activePlots = ()
        self.originalPlots = []
        self.newPlots = []
        self.extents = ()
        self.pivot = (0,0,0)

    def Start(self, nframes = 10):
        self.nFrames = nframes
        activePlots = []
        pL = GetPlotList()
        for i in xrange(GetNumPlots()):
            plot = pL.GetPlots(i)
            if plot.activeFlag:
               activePlots.append(i)
        self.activePlots = tuple(activePlots)

        Query("SpatialExtents")
        self.extents = GetQueryOutputValue()
        self.pivot = ((self.extents[0] + self.extents[1]) / 2.,
                      0,
                      self.extents[4])

        # Add some operators to the existing plots.
        self.originalPlots = tuple(range(GetNumPlots()))
        SetActivePlots(self.originalPlots)
        AddOperator("Clip", 1)
        AddOperator("Transform", 1)

        # Duplicate all existing plots
        g = GetGlobalAttributes()
        srcwin = g.windows[g.activeWindow]
        AddWindow()
        DeleteAllPlots()
        g = GetGlobalAttributes()
        destwin = g.windows[g.activeWindow]
        CopyPlotsToWindow(srcwin, destwin)
        CopyPlotsToWindow(destwin, srcwin)
        DeleteWindow()
        SetActiveWindow(srcwin)
        for i in xrange(GetNumPlots()):
            if not i in self.originalPlots:
                self.newPlots.append(i)
        self.newPlots = tuple(self.newPlots)

        # Turn off legends on the duplicate plots.
        for i in self.newPlots:
            SetActivePlots(i)
            plot = GetPlotList().GetPlots(i)
            plotType = PlotPlugins()[plot.plotType]
            try:
                atts = eval("%sAttributes(1)" % plotType)
                if "SetLegendFlag" in dir(atts):
                    atts.SetLegendFlag(0)
                    SetPlotOptions(atts)
                elif "SetUseLegend" in dir(atts):
                    atts.SetUseLegend(0)
                    SetPlotOptions(atts)
                elif "SetShowLegend" in dir(atts):
                    atts.SetShowLegend(0)
                    SetPlotOptions(atts)
            except:
                pass

    def Step(self, index):
        t = float(index) / float(self.nFrames-1)
        ClearWindow()

        c = ClipAttributes()
        c.plane1Status = 1
        c.plane1Origin = self.pivot
        c.plane1Normal = (1,0,0)
        self.ApplyOperatorOptions(self.originalPlots, -2, c)

        ta = TransformAttributes()
        ta.doRotate = 1
        ta.rotateOrigin = self.pivot
        ta.rotateAxis = (0,1,0)
        ta.rotateType = ta.Deg
        ta.rotateAmount = t * -90.
        self.ApplyOperatorOptions(self.originalPlots, -1, ta)
        
        c = ClipAttributes()
        c.plane1Status = 1
        c.plane1Origin = self.pivot
        c.plane1Normal = (-1,0,0)
        self.ApplyOperatorOptions(self.newPlots, -2, c)

        ta = TransformAttributes()
        ta.doRotate = 1
        ta.rotateOrigin = self.pivot
        ta.rotateAxis = (0,1,0)
        ta.rotateType = ta.Deg
        ta.rotateAmount = t * 90.
        self.ApplyOperatorOptions(self.newPlots, -1, ta)
        DrawPlots()

    def ApplyOperatorOptions(self, plots, index, atts):
        pL = GetPlotList()
        for p in plots:
            SetActivePlots(p)
            plot = pL.GetPlots(p)
            nOps = len(plot.operators)
            if index < 0:
                opIndex = nOps + index
            else:
                opIndex = index
            if opIndex >= 0 and opIndex < nOps:
                SetOperatorOptions(atts, opIndex)

    def End(self):
        SetActivePlots(self.newPlots)
        DeleteActivePlots()
        SetActivePlots(self.originalPlots)
        RemoveLastOperator()
        RemoveLastOperator()
        DrawPlots()
        SetActivePlots(self.activePlots)

# Set up some plots.
OpenDatabase("~/data/noise.silo")
AddPlot("Pseudocolor", "hardyglobal")
#AddPlot("Mesh", "Mesh")
AddOperator("Isosurface", 1)
iso = IsosurfaceAttributes()
iso.variable = "hardyglobal"
SetOperatorOptions(iso, 0, 1)

AddPlot("FilledBoundary", "mat1")
AddOperator("Clip")
c = ClipAttributes()
c.plane1Status = 1
c.plane1Origin = (0,0,0)
c.plane1Normal = (0,0,1)
SetOperatorOptions(c)

DrawPlots()
ResizeWindow(1, 400, 400)

def SetTheView():
    v = View3DAttributes()
    v.viewNormal = (0, 0.34202, 0.939693)
    v.focus = (0, 0, -10)
    v.viewUp = (0, 0.939693, -0.34202)
    v.viewAngle = 30
    v.parallelScale = 24.4949
    v.nearPlane = -48.9898
    v.farPlane = 48.9898
    v.imagePan = (0, 0)
    v.imageZoom = 1
    v.perspective = 1
    v.eyeAngle = 2
    v.centerOfRotationSet = 0
    v.centerOfRotation = (0, 0, -10)
    v.axis3DScaleFlag = 0
    v.axis3DScales = (1, 1, 1)
    v.shear = (0, 0, 1)
    SetView3D(v)

# Use the SliceOpen class to make an animation using the current plots.
s = SliceOpen()
nFrames = 10
s.Start(nFrames)
for i in xrange(nFrames):
    s.Step(i)
    SetTheView()
    SaveWindow()
s.End()