Managing layers of data
This script lets you create different DataSurface objects, which are logical slices through a 3D dataset and each object may show different quantities or representations of the data in the surface. The data surfaces are implemented using DataLayer objects, which correspond to VisIt plots.
import random
#
# A "layer" of data that we map to a VisIt plot.
#
class DataLayer:
def __init__(self, parentId, layer, plotName, var):
self.parentId = parentId
self.layer = layer
self.visible = 0
self.slice = 0
self.sliceType = 0 # X
self.atts = IndexSelectAttributes()
# Make the plot but keep it hidden so
AddPlot(plotName, var)
SetPlotDescription(GetNumPlots()-1, self.Id())
HideActivePlots()
def Slice(self, slice, sliceType):
self.slice = slice
self.sliceType = sliceType
idx = self.GetPlotListIndex()
pL = GetPlotList()
if idx != -1:
SetActivePlots(idx)
AddOperator("IndexSelect")
self.atts = IndexSelectAttributes()
if self.sliceType == 0:
self.atts.xMin = slice
self.atts.xMax = slice
elif self.sliceType == 1:
self.atts.yMin = slice
self.atts.yMax = slice
else:
self.atts.zMin = slice
self.atts.zMax = slice
SetOperatorOptions(self.atts, 0, 0)
def SetPlotOptions(self, atts):
idx = self.GetPlotListIndex()
pL = GetPlotList()
if idx != -1:
SetActivePlots(idx)
SetPlotOptions(atts)
def SetVisible(self, vis):
idx = self.GetPlotListIndex()
pL = GetPlotList()
if idx != -1:
plot = pL.GetPlots(idx)
if self.visible != vis:
if vis:
# Turning the plot on.
SetActivePlots(idx)
if plot.hiddenFlag:
HideActivePlots()
if plot.stateType == plot.NewlyCreated:
self.DrawOnlyThisPlot()
else:
# Turning the plot off
SetActivePlots(idx)
if not plot.hiddenFlag:
HideActivePlots()
self.visible = vis
def DrawOnlyThisPlot(self):
idx = self.GetPlotListIndex()
pL = GetPlotList()
if idx != -1:
# Disable window redrawing
DisableRedraw()
# Hide all plots but this one
for i in range(pL.GetNumPlots()):
plot = pL.GetPlots(idx)
if not plot.hiddenFlag:
SetActivePlots(i)
HideActivePlots()
SetActivePlots(idx)
DrawPlots()
# Hide all plots but this one
for i in range(pL.GetNumPlots()):
plot = pL.GetPlots(idx)
if not plot.hiddenFlag:
SetActivePlots(i)
HideActivePlots()
# Redraw the window
RedrawWindow()
def Id(self):
return self.parentId + "," + str(self.layer)
def GetPlotListIndex(self):
pL = GetPlotList()
for i in range(pL.GetNumPlots()):
if pL.GetPlots(i).description == self.Id():
return i
return -1
#
# A container for different "layers" of data. All data is on a logical slice.
#
class DataSurface:
def __init__(self, meshVar, scalarVar, vectorVar, slice, sliceDim):
self.id = self.MakeId()
self.pc = DataLayer(self.id, 0, "Pseudocolor", scalarVar)
self.mesh = DataLayer(self.id, 1, "Mesh", meshVar)
self.vector = DataLayer(self.id, 2, "Vector", vectorVar)
self.contour = DataLayer(self.id, 3, "Contour", scalarVar)
self.pc.Slice(slice, sliceDim)
self.mesh.Slice(slice, sliceDim)
self.vector.Slice(slice, sliceDim)
self.contour.Slice(slice, sliceDim)
def MakeId(self):
name = ""
for i in xrange(8):
name = name + char(65 + int(random.random()*25)) # note: use chr instead of char
return name
def SetPCVisible(self, visible):
self.pc.SetVisible(visible)
def SetMeshVisible(self, visible):
self.mesh.SetVisible(visible)
def SetVectorVisible(self, visible):
self.vector.SetVisible(visible)
def SetContourVisible(self, visible):
self.contour.SetVisible(visible)
def SetTheView():
v = View3DAttributes()
v.viewNormal = (-0.544648, 0.336143, 0.768353)
v.focus = (0, 0, 0)
v.viewUp = (0.165063, 0.941207, -0.294759)
v.viewAngle = 30
v.parallelScale = 17.3205
v.nearPlane = -34.641
v.farPlane = 34.641
v.imagePan = (0, 0)
v.imageZoom = 1
v.perspective = 1
v.eyeAngle = 2
v.centerOfRotationSet = 0
v.centerOfRotation = (0, 0, 0)
v.axis3DScaleFlag = 0
v.axis3DScales = (1, 1, 1)
v.shear = (0, 0, 1)
SetView3D(v)
def main():
OpenDatabase("~/data/noise.silo")
ResizeWindow(1, 500, 500)
X_SLICE = 0
Y_SLICE = 1
Z_SLICE = 2
s1 = DataSurface("Mesh", "hardyglobal", "grad", 20, X_SLICE)
s2 = DataSurface("Mesh", "hardyglobal", "grad", 20, Y_SLICE)
s1.SetPCVisible(1)
SetTheView()
SaveWindow()
s2.SetPCVisible(1)
s2.SetMeshVisible(1)
SetTheView()
SaveWindow()
s1.SetPCVisible(0)
s1.SetVectorVisible(1)
SetTheView()
SaveWindow()
s1.SetContourVisible(1)
SetTheView()
SaveWindow()
main()