Skip to content

Commit

Permalink
Merge pull request #1203 from UV-CDAT/isoline_anim_labeled_or_not_1199
Browse files Browse the repository at this point in the history
Isoline anim labeled or not 1199
  • Loading branch information
aashish24 committed Apr 25, 2015
2 parents a3ec8a0 + 90a282a commit 17b86d0
Show file tree
Hide file tree
Showing 9 changed files with 300 additions and 60 deletions.
142 changes: 90 additions & 52 deletions Packages/vcs/Lib/VTKPlots.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,63 +879,81 @@ def plot2D(self,data1,data2,tmpl,gm,vtk_backend_grid=None,vtk_backend_geo=None):
cot.SetValue(i,levs[i])
cot.SetValue(Nlevs,levs[-1])
cot.Update()
mappers = []
if gm.label=="y":
mapper = vtk.vtkLabeledContourMapper()
else:
mapper = vtk.vtkPolyDataMapper()

lut = vtk.vtkLookupTable()
lut.SetNumberOfTableValues(1)
lut.SetTableValue(0, 0, 0, 0)
lut.SetNumberOfTableValues(len(cols))
for icol,col in enumerate(cols):
r,g,b = cmap.index[col]
lut.SetTableValue(icol,r/100.,g/100.,b/100.)

if gm.label=="y":
mapper.GetPolyDataMapper().SetLookupTable(lut)
# Setup label mapping array:
tpropMap = vtk.vtkDoubleArray()
tpropMap.SetNumberOfComponents(1)
tpropMap.SetNumberOfTuples(Nlevs)
for i, val in enumerate(levs):
tpropMap.SetTuple(i, [val,])

# Prep text properties:
tprops = vtk.vtkTextPropertyCollection()
if gm.text or gm.textcolors:
colorOverrides = gm.textcolors if gm.textcolors else [None] * len(gm.text)
texts = gm.text if gm.text else [None] * len(gm.textcolors)
while len(texts) < Nlevs:
texts.append(texts[-1])
while len(colorOverrides)<Nlevs:
colorOverrides.append(colorOverrides[-1])
for tc,colorOverride in zip(texts, colorOverrides):
if vcs.queries.istextcombined(tc):
tt, to = tuple(tc.name.split(":::"))
elif tc is None:
tt = "default"
to = "default"
elif vcs.queries.istexttable(tc):
tt = tc.name
to = "default"
elif vcs.queries.istextorientation(tc):
to = tc.name
tt = "default"
if colorOverride is not None:
tt = vcs.createtexttable(None, tt)
tt.color = colorOverride
tt = tt.name
tprop = vtk.vtkTextProperty()
vcs2vtk.prepTextProperty(tprop, self.renWin.GetSize(), to, tt)
tprops.AddItem(tprop)
if colorOverride is not None:
del(vcs.elements["texttable"][tt])
else:
# No text properties specified. Use the default:
tprop = vtk.vtkTextProperty()
vcs2vtk.prepTextProperty(tprop, self.renWin.GetSize())
tprops.AddItem(tprop)
returned["vtk_backend_contours_labels_text_properties"] = tprops

mapper = vtk.vtkLabeledContourMapper()
mapper.SetTextProperties(tprops)
mapper.SetTextPropertyMapping(tpropMap)
mapper.SetLabelVisibility(1)

pdMapper = mapper.GetPolyDataMapper()

returned["vtk_backend_labeled_luts"] = [[lut, [levs[0], levs[-1],
False]]]
else:
mapper.SetLookupTable(lut)
mapper = vtk.vtkPolyDataMapper()
pdMapper = mapper
returned["vtk_backend_luts"] = [[lut, [levs[0],levs[-1], False]]]

# Create text properties.
if gm.label=="y":
if gm.text or gm.textcolors:
colorOverrides = gm.textcolors if gm.textcolors else [None] * len(gm.text)
texts = gm.text if gm.text else [None] * len(gm.textcolors)
while len(texts)<Nlevs:
texts.append(texts[-1])
while len(colorOverrides)<Nlevs:
colorOverrides.append(colorOverrides[-1])
tprops = vtk.vtkTextPropertyCollection()
for tc,colorOverride in zip(texts, colorOverrides):
if vcs.queries.istextcombined(tc):
tt,to = tuple(tc.name.split(":::"))
elif tc is None:
tt="default"
to="default"
elif vcs.queries.istexttable(tc):
tt=tc.name
to="default"
elif vcs.queries.istextorientation(tc):
to=tc.name
tt="default"
if colorOverride is not None:
tt=vcs.createtexttable(None,tt)
tt.color = colorOverride
tt=tt.name
tprop = vtk.vtkTextProperty()
vcs2vtk.prepTextProperty(tprop, self.renWin.GetSize(), to, tt)
tprops.AddItem(tprop)
if colorOverride is not None:
del(vcs.elements["texttable"][tt])

mapper.SetTextProperties(tprops)
else:
# No text properties specified. Use the default:
tprop = vtk.vtkTextProperty()
vcs2vtk.prepTextProperty(tprop, self.renWin.GetSize())
mapper.SetTextProperty(tprop)
pdMapper.SetLookupTable(lut)
pdMapper.SetScalarRange(levs[0], levs[-1])
pdMapper.SetScalarModeToUsePointData()

stripper = vtk.vtkStripper()
stripper.SetInputConnection(cot.GetOutputPort())
mapper.SetInputConnection(stripper.GetOutputPort())
stripper.Update()
mappers = []
mappers.append([mapper,])
returned["vtk_backend_contours"]=[cot,]
else:
Expand Down Expand Up @@ -1852,11 +1870,31 @@ def update_input(self,vtkobjects,array1,array2=None,update=True):
mapper = missingMapper2
wrp = a[2]
else:
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(ports[i].GetOutputPort())
lut,rg = vtkobjects["vtk_backend_luts"][i]
if lut is not None:
mapper.SetLookupTable(lut)
## Labeled contours are a different kind
if vtkobjects.has_key("vtk_backend_luts"):
lut,rg = vtkobjects["vtk_backend_luts"][i]
mapper = vtk.vtkPolyDataMapper()
elif vtkobjects.has_key("vtk_backend_labeled_luts"):
lut,rg = vtkobjects["vtk_backend_labeled_luts"][i]
mapper = vtk.vtkLabeledContourMapper()
if lut is None:
mapper.SetInputConnection(ports[i].GetOutputPort())
else:
if mapper.IsA("vtkPolyDataMapper"):
mapper.SetInputConnection(ports[i].GetOutputPort())
mapper.SetLookupTable(lut)
mapper.SetScalarModeToUsePointData()
else:
stripper = vtk.vtkStripper()
stripper.SetInputConnection(ports[i].GetOutputPort())
mapper.SetInputConnection(stripper.GetOutputPort())
stripper.Update()
tprops = vtkobjects["vtk_backend_contours_labels_text_properties"]
mapper.GetPolyDataMapper().SetLookupTable(lut)
mapper.GetPolyDataMapper().SetScalarModeToUsePointData()
mapper.GetPolyDataMapper().SetScalarRange(rg[0],rg[1])
mapper.SetLabelVisibility(1)
mapper.SetTextProperties(tprops)
if rg[2]:
mapper.SetScalarModeToUseCellData()
mapper.SetScalarRange(rg[0],rg[1])
Expand Down
8 changes: 7 additions & 1 deletion Packages/vcs/Lib/animate_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def __init__(self, vcs_self):
self.run_flg = 0
self.continents_value = 0
self.continents_hold_value = 1
## We need to store this because if user close
## anim with preserve_pngs = True
## it still gets deleted at python exit time
self.preserve_pngs = False

##############################################################################
# Create the animation images. If min or max is None, then #
Expand Down Expand Up @@ -559,7 +563,9 @@ def close( self, preserve_pngs = False ):
png_names=glob.glob(
os.path.join(os.environ["HOME"],".uvcdat",self._unique_prefix,"anim_*.png")
)
if not preserve_pngs:
if preserve_pngs:
self.preserve_pngs = True
if not self.preserve_pngs:
for f in png_names:
os.remove(f)
if len(png_names)>0:
Expand Down
20 changes: 20 additions & 0 deletions testing/vcs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,26 @@ cdat_add_test(vcs_test_taylor_2_quads
${BASELINE_DIR}/test_vcs_issue_960_labels_1.png
${BASELINE_DIR}/test_vcs_issue_960_labels_2.png
)
cdat_add_test(vcs_test_animate_isoline
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_animate_isoline.py
${BASELINE_DIR}
)
cdat_add_test(vcs_test_animate_isoline_colored
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_animate_isoline_colored.py
${BASELINE_DIR}
)
cdat_add_test(vcs_test_animate_isoline_text_labels
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_animate_isoline_text_labels.py
${BASELINE_DIR}
)
cdat_add_test(vcs_test_animate_isoline_text_labels_colored
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_animate_isoline_text_labels_colored.py
${BASELINE_DIR}
)
endif()

cdat_add_test(vcs_test_endconfigure
Expand Down
33 changes: 33 additions & 0 deletions testing/vcs/test_animate_isoline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import vcs
import cdms2
import os
import sys
import time
pth = os.path.join(os.path.dirname(__file__),"..")
sys.path.append(pth)
import checkimage

f=cdms2.open(os.path.join(vcs.prefix,"sample_data","clt.nc"))
s=f("clt",slice(0,12)) # read only 12 times steps to speed up things

x=vcs.init()
x.drawlogooff()
x.setbgoutputdimensions(1200,1091,units="pixels")

iso=x.createisoline()
x.plot(s,iso,bg=1)
x.animate.create()
print "Saving now"
prefix= os.path.split(__file__)[1][:-3]
x.animate.save("%s.mp4"%prefix)
pngs = x.animate.close(preserve_pngs = True) # so we can look at them again
src_pth = sys.argv[1]
pth = os.path.join(src_pth,prefix)
ret = 0
for p in pngs:
print "Checking:",p
ret += checkimage.check_result_image(p,os.path.join(pth,os.path.split(p)[1]),checkimage.defaultThreshold)
if ret == 0:
os.removedirs(os.path.split(p)[0])
os.remove("%s.mp4" % prefix)
sys.exit(ret)
41 changes: 41 additions & 0 deletions testing/vcs/test_animate_isoline_colored.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import vcs
import cdms2
import os
import sys
import time
pth = os.path.join(os.path.dirname(__file__),"..")
sys.path.append(pth)
import checkimage

f=cdms2.open(os.path.join(vcs.prefix,"sample_data","clt.nc"))
s=f("clt",slice(0,12)) # read only 12 times steps to speed up things

x=vcs.init()
x.drawlogooff()
x.setbgoutputdimensions(1200,1091,units="pixels")

iso=x.createisoline()
levs = range(0,101,10)
iso.level=levs
# add dummy values to levs to get the correct number of cols
cols=vcs.getcolors(levs+[56,])
print levs
print cols
iso.textcolors = cols
iso.linecolors = cols
x.plot(s,iso,bg=1)
x.animate.create()
print "Saving now"
prefix= os.path.split(__file__)[1][:-3]
x.animate.save("%s.mp4"%prefix)
pngs = x.animate.close(preserve_pngs = True) # so we can look at them again
src_pth = sys.argv[1]
pth = os.path.join(src_pth,prefix)
ret = 0
for p in pngs:
print "Checking:",p
ret += checkimage.check_result_image(p,os.path.join(pth,os.path.split(p)[1]),checkimage.defaultThreshold)
if ret == 0:
os.removedirs(os.path.split(p)[0])
os.remove("%s.mp4" % prefix)
sys.exit(ret)
34 changes: 34 additions & 0 deletions testing/vcs/test_animate_isoline_text_labels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import vcs
import cdms2
import os
import sys
import time
pth = os.path.join(os.path.dirname(__file__),"..")
sys.path.append(pth)
import checkimage

f=cdms2.open(os.path.join(vcs.prefix,"sample_data","clt.nc"))
s=f("clt",slice(0,12)) # read only 12 times steps to speed up things

x=vcs.init()
x.drawlogooff()
x.setbgoutputdimensions(1200,1091,units="pixels")

iso=x.createisoline()
iso.label='y'
x.plot(s,iso,bg=1)
x.animate.create()
print "Saving now"
prefix= os.path.split(__file__)[1][:-3]
x.animate.save("%s.mp4"%prefix)
pngs = x.animate.close(preserve_pngs = True) # so we can look at them again
src_pth = sys.argv[1]
pth = os.path.join(src_pth,prefix)
ret = 0
for p in pngs:
print "Checking:",p
ret += checkimage.check_result_image(p,os.path.join(pth,os.path.split(p)[1]),checkimage.defaultThreshold)
if ret == 0:
os.removedirs(os.path.split(p)[0])
os.remove("%s.mp4" % prefix)
sys.exit(ret)
42 changes: 42 additions & 0 deletions testing/vcs/test_animate_isoline_text_labels_colored.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import vcs
import cdms2
import os
import sys
import time
pth = os.path.join(os.path.dirname(__file__),"..")
sys.path.append(pth)
import checkimage

f=cdms2.open(os.path.join(vcs.prefix,"sample_data","clt.nc"))
s=f("clt",slice(0,12)) # read only 12 times steps to speed up things

x=vcs.init()
x.drawlogooff()
x.setbgoutputdimensions(1200,1091,units="pixels")

iso=x.createisoline()
iso.label='y'
levs = range(0,101,10)
iso.level=levs
# add dummy values to levs to get the correct number of cols
cols=vcs.getcolors(levs+[56,])
print levs
print cols
iso.textcolors = cols
iso.linecolors = cols
x.plot(s,iso,bg=1)
x.animate.create()
print "Saving now"
prefix= os.path.split(__file__)[1][:-3]
x.animate.save("%s.mp4"%prefix)
pngs = x.animate.close(preserve_pngs = True) # so we can look at them again
src_pth = sys.argv[1]
pth = os.path.join(src_pth,prefix)
ret = 0
for p in pngs:
print "Checking:",p
ret += checkimage.check_result_image(p,os.path.join(pth,os.path.split(p)[1]),checkimage.defaultThreshold)
if ret == 0:
os.removedirs(os.path.split(p)[0])
os.remove("%s.mp4" % prefix)
sys.exit(ret)
Loading

0 comments on commit 17b86d0

Please sign in to comment.