From b1043565c334e7fc6949663e012c48251facce53 Mon Sep 17 00:00:00 2001 From: Sam Fries Date: Tue, 7 Apr 2015 14:27:34 -0700 Subject: [PATCH 01/16] Fix for #1199 --- Packages/vcs/Lib/VTKPlots.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Packages/vcs/Lib/VTKPlots.py b/Packages/vcs/Lib/VTKPlots.py index 3ba9dd1003..986531a1f9 100644 --- a/Packages/vcs/Lib/VTKPlots.py +++ b/Packages/vcs/Lib/VTKPlots.py @@ -881,6 +881,7 @@ def plot2D(self,data1,data2,tmpl,gm,vtk_backend_grid=None,vtk_backend_geo=None): mapper.SetLabelVisibility(1) else: mapper.SetLookupTable(lut) + returned["vtk_backend_luts"] = [[lut, [0, len(levs) - 1, False]]] # Create text properties. if gm.label=="y": From 0b279febca0674fa356c9d1262106946c5617ef3 Mon Sep 17 00:00:00 2001 From: Charles Doutriaux Date: Tue, 7 Apr 2015 16:59:31 -0700 Subject: [PATCH 02/16] ok this actually updates the labels as well really fix #1199 --- Packages/vcs/Lib/VTKPlots.py | 50 ++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/Packages/vcs/Lib/VTKPlots.py b/Packages/vcs/Lib/VTKPlots.py index 986531a1f9..dd2abb30fc 100644 --- a/Packages/vcs/Lib/VTKPlots.py +++ b/Packages/vcs/Lib/VTKPlots.py @@ -879,9 +879,10 @@ def plot2D(self,data1,data2,tmpl,gm,vtk_backend_grid=None,vtk_backend_geo=None): if gm.label=="y": mapper.GetPolyDataMapper().SetLookupTable(lut) mapper.SetLabelVisibility(1) + returned["vtk_backend_labeled_luts"] = [[lut, [0, len(levs) - 1, False]]] else: mapper.SetLookupTable(lut) - returned["vtk_backend_luts"] = [[lut, [0, len(levs) - 1, False]]] + returned["vtk_backend_luts"] = [[lut, [0, len(levs) - 1, False]]] # Create text properties. if gm.label=="y": @@ -914,13 +915,12 @@ def plot2D(self,data1,data2,tmpl,gm,vtk_backend_grid=None,vtk_backend_geo=None): 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) + tprops = vtk.vtkTextProperty() + vcs2vtk.prepTextProperty(tprops, self.renWin.GetSize()) + mapper.SetTextProperty(tprops) + returned["vtk_backend_contours_labels_text_properties"]=tprops stripper = vtk.vtkStripper() stripper.SetInputConnection(cot.GetOutputPort()) @@ -1825,14 +1825,36 @@ 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) - if rg[2]: - mapper.SetScalarModeToUseCellData() - mapper.SetScalarRange(rg[0],rg[1]) + ## Labeled contours are a different king + if vtkobjects.has_key("vtk_backend_luts"): + print "not labeled" + lut,rg = vtkobjects["vtk_backend_luts"][i] + mapper = vtk.vtkPolyDataMapper() + elif vtkobjects.has_key("vtk_backend_labeled_luts"): + print "labeled" + lut,rg = vtkobjects["vtk_backend_labeled_luts"][i] + mapper = vtk.vtkLabeledContourMapper() + else: + print "OOOOPS" + if lut is None: + mapper.SetInputConnection(ports[i].GetOutputPort()) + else: + if mapper.IsA("vtkPolyDataMapper"): + mapper.SetInputConnection(ports[i].GetOutputPort()) + mapper.SetLookupTable(lut) + else: + print "labelled" + 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.SetLabelVisibility(1) + mapper.SetTextProperty(tprops) + #if rg[2]: + # mapper.SetScalarModeToUseCellData() + #mapper.SetScalarRange(rg[0],rg[1]) act.SetMapper(mapper) act = vcs2vtk.doWrap(a[0],wrp) a[0].SetMapper(act.GetMapper()) From d41792b6e3663172b8be99a45ab61a2cd7e14a2e Mon Sep 17 00:00:00 2001 From: Charles Doutriaux Date: Tue, 7 Apr 2015 17:02:43 -0700 Subject: [PATCH 03/16] removed prints --- Packages/vcs/Lib/VTKPlots.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Packages/vcs/Lib/VTKPlots.py b/Packages/vcs/Lib/VTKPlots.py index dd2abb30fc..0dae24a665 100644 --- a/Packages/vcs/Lib/VTKPlots.py +++ b/Packages/vcs/Lib/VTKPlots.py @@ -1827,15 +1827,11 @@ def update_input(self,vtkobjects,array1,array2=None,update=True): else: ## Labeled contours are a different king if vtkobjects.has_key("vtk_backend_luts"): - print "not labeled" lut,rg = vtkobjects["vtk_backend_luts"][i] mapper = vtk.vtkPolyDataMapper() elif vtkobjects.has_key("vtk_backend_labeled_luts"): - print "labeled" lut,rg = vtkobjects["vtk_backend_labeled_luts"][i] mapper = vtk.vtkLabeledContourMapper() - else: - print "OOOOPS" if lut is None: mapper.SetInputConnection(ports[i].GetOutputPort()) else: @@ -1843,7 +1839,6 @@ def update_input(self,vtkobjects,array1,array2=None,update=True): mapper.SetInputConnection(ports[i].GetOutputPort()) mapper.SetLookupTable(lut) else: - print "labelled" stripper = vtk.vtkStripper() stripper.SetInputConnection(ports[i].GetOutputPort()) mapper.SetInputConnection(stripper.GetOutputPort()) @@ -1852,9 +1847,9 @@ def update_input(self,vtkobjects,array1,array2=None,update=True): mapper.GetPolyDataMapper().SetLookupTable(lut) mapper.SetLabelVisibility(1) mapper.SetTextProperty(tprops) - #if rg[2]: - # mapper.SetScalarModeToUseCellData() - #mapper.SetScalarRange(rg[0],rg[1]) + if rg[2]: + mapper.SetScalarModeToUseCellData() + mapper.SetScalarRange(rg[0],rg[1]) act.SetMapper(mapper) act = vcs2vtk.doWrap(a[0],wrp) a[0].SetMapper(act.GetMapper()) From f6ad95ed462226703c61c97b9578f965dc1c56e9 Mon Sep 17 00:00:00 2001 From: Charles Doutriaux Date: Wed, 8 Apr 2015 09:31:18 -0700 Subject: [PATCH 04/16] Update VTKPlots.py fixed typo it is different kind not different king --- Packages/vcs/Lib/VTKPlots.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Packages/vcs/Lib/VTKPlots.py b/Packages/vcs/Lib/VTKPlots.py index 0dae24a665..e277bb3282 100644 --- a/Packages/vcs/Lib/VTKPlots.py +++ b/Packages/vcs/Lib/VTKPlots.py @@ -1825,7 +1825,7 @@ def update_input(self,vtkobjects,array1,array2=None,update=True): mapper = missingMapper2 wrp = a[2] else: - ## Labeled contours are a different king + ## Labeled contours are a different kind if vtkobjects.has_key("vtk_backend_luts"): lut,rg = vtkobjects["vtk_backend_luts"][i] mapper = vtk.vtkPolyDataMapper() From 6d9698b212e3b110a9b40709bc089bf8815a5661 Mon Sep 17 00:00:00 2001 From: Charles Doutriaux Date: Wed, 8 Apr 2015 17:15:52 -0700 Subject: [PATCH 05/16] went to quick didn't realize one bit was saying setTextProperty and oneSetTextProperties --- Packages/vcs/Lib/VTKPlots.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Packages/vcs/Lib/VTKPlots.py b/Packages/vcs/Lib/VTKPlots.py index e277bb3282..242742614a 100644 --- a/Packages/vcs/Lib/VTKPlots.py +++ b/Packages/vcs/Lib/VTKPlots.py @@ -915,11 +915,12 @@ def plot2D(self,data1,data2,tmpl,gm,vtk_backend_grid=None,vtk_backend_geo=None): tprops.AddItem(tprop) if colorOverride is not None: del(vcs.elements["texttable"][tt]) + mapper.SetTextProperties(tprops) else: # No text properties specified. Use the default: tprops = vtk.vtkTextProperty() vcs2vtk.prepTextProperty(tprops, self.renWin.GetSize()) - mapper.SetTextProperty(tprops) + mapper.SetTextProperty(tprops) returned["vtk_backend_contours_labels_text_properties"]=tprops stripper = vtk.vtkStripper() From 64fe05700a566c6f49baa7c399482a79b799ce97 Mon Sep 17 00:00:00 2001 From: Charles Doutriaux Date: Wed, 22 Apr 2015 13:36:39 -0700 Subject: [PATCH 06/16] preserve_pngs now also preserves when exiting python --- Packages/vcs/Lib/animate_helper.py | 8 +++++++- testing/vcs/test_vcs_basic_vectors.py | 1 - 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Packages/vcs/Lib/animate_helper.py b/Packages/vcs/Lib/animate_helper.py index ffcb9e075c..636ec12837 100644 --- a/Packages/vcs/Lib/animate_helper.py +++ b/Packages/vcs/Lib/animate_helper.py @@ -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 # @@ -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: diff --git a/testing/vcs/test_vcs_basic_vectors.py b/testing/vcs/test_vcs_basic_vectors.py index 9917424178..e6d5fac378 100644 --- a/testing/vcs/test_vcs_basic_vectors.py +++ b/testing/vcs/test_vcs_basic_vectors.py @@ -30,7 +30,6 @@ import MV2 import numpy - bg = not args.show x=vcs.init() From f0d0f23706a7d008b25b53a1cf3e69d7b6887f61 Mon Sep 17 00:00:00 2001 From: Charles Doutriaux Date: Wed, 22 Apr 2015 13:37:26 -0700 Subject: [PATCH 07/16] Adding test for animate isolines text labels --- .../vcs/test_animate_isoline_text_labels.py | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 testing/vcs/test_animate_isoline_text_labels.py diff --git a/testing/vcs/test_animate_isoline_text_labels.py b/testing/vcs/test_animate_isoline_text_labels.py new file mode 100644 index 0000000000..450fae2ccf --- /dev/null +++ b/testing/vcs/test_animate_isoline_text_labels.py @@ -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) From cef509822f3b7155061d760c6c96b0f821e9e58d Mon Sep 17 00:00:00 2001 From: Charles Doutriaux Date: Wed, 22 Apr 2015 13:45:37 -0700 Subject: [PATCH 08/16] ok fixed issue that @dlonie pointed out property vs properties --- Packages/vcs/Lib/VTKPlots.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Packages/vcs/Lib/VTKPlots.py b/Packages/vcs/Lib/VTKPlots.py index 9b6185eea7..1c198ee5ab 100644 --- a/Packages/vcs/Lib/VTKPlots.py +++ b/Packages/vcs/Lib/VTKPlots.py @@ -1872,7 +1872,10 @@ def update_input(self,vtkobjects,array1,array2=None,update=True): tprops = vtkobjects["vtk_backend_contours_labels_text_properties"] mapper.GetPolyDataMapper().SetLookupTable(lut) mapper.SetLabelVisibility(1) - mapper.SetTextProperty(tprops) + if tprops.IsA("vtkTextProperty"): + mapper.SetTextProperty(tprops) + else: + mapper.SetTextProperties(tprops) if rg[2]: mapper.SetScalarModeToUseCellData() mapper.SetScalarRange(rg[0],rg[1]) From fcf25146632d5f0b8f111c6610d4c51138367319 Mon Sep 17 00:00:00 2001 From: Charles Doutriaux Date: Wed, 22 Apr 2015 14:23:48 -0700 Subject: [PATCH 09/16] got line colors to work --- Packages/vcs/Lib/VTKPlots.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Packages/vcs/Lib/VTKPlots.py b/Packages/vcs/Lib/VTKPlots.py index 1c198ee5ab..ba3d21c872 100644 --- a/Packages/vcs/Lib/VTKPlots.py +++ b/Packages/vcs/Lib/VTKPlots.py @@ -882,14 +882,20 @@ def plot2D(self,data1,data2,tmpl,gm,vtk_backend_grid=None,vtk_backend_geo=None): 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) + mapper.GetPolyDataMapper().SetScalarRange(levs[0],levs[-1]) + mapper.GetPolyDataMapper().SetScalarModeToUsePointData() mapper.SetLabelVisibility(1) returned["vtk_backend_labeled_luts"] = [[lut, [0, len(levs) - 1, False]]] else: mapper.SetLookupTable(lut) + mapper.SetScalarRange(levs[0],levs[-1]) + mapper.SetScalarModeToUsePointData() returned["vtk_backend_luts"] = [[lut, [0, len(levs) - 1, False]]] # Create text properties. From a3db6946910e874e401a0f4a44fa5a1d2c0e19d7 Mon Sep 17 00:00:00 2001 From: Charles Doutriaux Date: Wed, 22 Apr 2015 14:24:25 -0700 Subject: [PATCH 10/16] Adding test for colored texts isolines --- ...est_animate_isoline_text_labels_colored.py | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 testing/vcs/test_animate_isoline_text_labels_colored.py diff --git a/testing/vcs/test_animate_isoline_text_labels_colored.py b/testing/vcs/test_animate_isoline_text_labels_colored.py new file mode 100644 index 0000000000..358304bce8 --- /dev/null +++ b/testing/vcs/test_animate_isoline_text_labels_colored.py @@ -0,0 +1,44 @@ +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=0) +raw_input("Press enter") +sys.exit(0) +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) From de3479c29eddf4177b5468764032a36a69532a7d Mon Sep 17 00:00:00 2001 From: Charles Doutriaux Date: Wed, 22 Apr 2015 14:24:46 -0700 Subject: [PATCH 11/16] Adding test for colored texts isolines --- testing/vcs/test_animate_isoline_text_labels_colored.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/testing/vcs/test_animate_isoline_text_labels_colored.py b/testing/vcs/test_animate_isoline_text_labels_colored.py index 358304bce8..aba466e5a1 100644 --- a/testing/vcs/test_animate_isoline_text_labels_colored.py +++ b/testing/vcs/test_animate_isoline_text_labels_colored.py @@ -25,8 +25,6 @@ iso.textcolors = cols iso.linecolors = cols x.plot(s,iso,bg=0) -raw_input("Press enter") -sys.exit(0) x.animate.create() print "Saving now" prefix= os.path.split(__file__)[1][:-3] From 950dd038ced7f544b880b277a4930ca1c4d70c30 Mon Sep 17 00:00:00 2001 From: Charles Doutriaux Date: Wed, 22 Apr 2015 14:38:51 -0700 Subject: [PATCH 12/16] anim labeled colored 'works' test added --- Packages/vcs/Lib/VTKPlots.py | 7 +++++-- testing/vcs/test_animate_isoline_text_labels_colored.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Packages/vcs/Lib/VTKPlots.py b/Packages/vcs/Lib/VTKPlots.py index ba3d21c872..247f071b3d 100644 --- a/Packages/vcs/Lib/VTKPlots.py +++ b/Packages/vcs/Lib/VTKPlots.py @@ -891,12 +891,12 @@ def plot2D(self,data1,data2,tmpl,gm,vtk_backend_grid=None,vtk_backend_geo=None): mapper.GetPolyDataMapper().SetScalarRange(levs[0],levs[-1]) mapper.GetPolyDataMapper().SetScalarModeToUsePointData() mapper.SetLabelVisibility(1) - returned["vtk_backend_labeled_luts"] = [[lut, [0, len(levs) - 1, False]]] + returned["vtk_backend_labeled_luts"] = [[lut, [levs[0],levs[-1], False]]] else: mapper.SetLookupTable(lut) mapper.SetScalarRange(levs[0],levs[-1]) mapper.SetScalarModeToUsePointData() - returned["vtk_backend_luts"] = [[lut, [0, len(levs) - 1, False]]] + returned["vtk_backend_luts"] = [[lut, [levs[0],levs[-1], False]]] # Create text properties. if gm.label=="y": @@ -1870,6 +1870,7 @@ def update_input(self,vtkobjects,array1,array2=None,update=True): if mapper.IsA("vtkPolyDataMapper"): mapper.SetInputConnection(ports[i].GetOutputPort()) mapper.SetLookupTable(lut) + mapper.SetScalarModeToUsePointData() else: stripper = vtk.vtkStripper() stripper.SetInputConnection(ports[i].GetOutputPort()) @@ -1877,6 +1878,8 @@ def update_input(self,vtkobjects,array1,array2=None,update=True): 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) if tprops.IsA("vtkTextProperty"): mapper.SetTextProperty(tprops) diff --git a/testing/vcs/test_animate_isoline_text_labels_colored.py b/testing/vcs/test_animate_isoline_text_labels_colored.py index aba466e5a1..8c7ca2788b 100644 --- a/testing/vcs/test_animate_isoline_text_labels_colored.py +++ b/testing/vcs/test_animate_isoline_text_labels_colored.py @@ -24,7 +24,7 @@ print cols iso.textcolors = cols iso.linecolors = cols -x.plot(s,iso,bg=0) +x.plot(s,iso,bg=1) x.animate.create() print "Saving now" prefix= os.path.split(__file__)[1][:-3] From c991108e052032b8bf821d66cb74fa6423b9c0d2 Mon Sep 17 00:00:00 2001 From: Charles Doutriaux Date: Wed, 22 Apr 2015 14:45:49 -0700 Subject: [PATCH 13/16] test anim isolines simple --- testing/vcs/test_animate_isoline.py | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 testing/vcs/test_animate_isoline.py diff --git a/testing/vcs/test_animate_isoline.py b/testing/vcs/test_animate_isoline.py new file mode 100644 index 0000000000..3ce2f67066 --- /dev/null +++ b/testing/vcs/test_animate_isoline.py @@ -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) From 1196f298ab5564d7f2cfa73b3da687e725a1583d Mon Sep 17 00:00:00 2001 From: Charles Doutriaux Date: Wed, 22 Apr 2015 14:48:58 -0700 Subject: [PATCH 14/16] should now have 4 anim isolines test' --- testing/vcs/CMakeLists.txt | 20 ++++++++++ testing/vcs/test_animate_isoline_colored.py | 41 +++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 testing/vcs/test_animate_isoline_colored.py diff --git a/testing/vcs/CMakeLists.txt b/testing/vcs/CMakeLists.txt index a6c3b4f296..721d1807f5 100644 --- a/testing/vcs/CMakeLists.txt +++ b/testing/vcs/CMakeLists.txt @@ -576,6 +576,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_isolines + "${PYTHON_EXECUTABLE}" + ${cdat_SOURCE_DIR}/testing/vcs/test_animate_isolines.py + ${BASELINE_DIR} + ) + cdat_add_test(vcs_test_animate_isolines_colored + "${PYTHON_EXECUTABLE}" + ${cdat_SOURCE_DIR}/testing/vcs/test_animate_isolines_colored.py + ${BASELINE_DIR} + ) + cdat_add_test(vcs_test_animate_isolines_text_labels + "${PYTHON_EXECUTABLE}" + ${cdat_SOURCE_DIR}/testing/vcs/test_animate_isolines_text_labels.py + ${BASELINE_DIR} + ) + cdat_add_test(vcs_test_animate_isolines_text_labels_colored + "${PYTHON_EXECUTABLE}" + ${cdat_SOURCE_DIR}/testing/vcs/test_animate_isolines_text_labels_colored.py + ${BASELINE_DIR} + ) endif() cdat_add_test(vcs_test_endconfigure diff --git a/testing/vcs/test_animate_isoline_colored.py b/testing/vcs/test_animate_isoline_colored.py new file mode 100644 index 0000000000..ee7fef5150 --- /dev/null +++ b/testing/vcs/test_animate_isoline_colored.py @@ -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) From 88d892e71b665656ff4b8844844b6ae91a3989d9 Mon Sep 17 00:00:00 2001 From: Charles Doutriaux Date: Wed, 22 Apr 2015 15:20:38 -0700 Subject: [PATCH 15/16] typo in script names --- testing/vcs/CMakeLists.txt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/testing/vcs/CMakeLists.txt b/testing/vcs/CMakeLists.txt index 721d1807f5..c6523426f4 100644 --- a/testing/vcs/CMakeLists.txt +++ b/testing/vcs/CMakeLists.txt @@ -576,24 +576,24 @@ 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_isolines + cdat_add_test(vcs_test_animate_isoline "${PYTHON_EXECUTABLE}" - ${cdat_SOURCE_DIR}/testing/vcs/test_animate_isolines.py + ${cdat_SOURCE_DIR}/testing/vcs/test_animate_isoline.py ${BASELINE_DIR} ) - cdat_add_test(vcs_test_animate_isolines_colored + cdat_add_test(vcs_test_animate_isoline_colored "${PYTHON_EXECUTABLE}" - ${cdat_SOURCE_DIR}/testing/vcs/test_animate_isolines_colored.py + ${cdat_SOURCE_DIR}/testing/vcs/test_animate_isoline_colored.py ${BASELINE_DIR} ) - cdat_add_test(vcs_test_animate_isolines_text_labels + cdat_add_test(vcs_test_animate_isoline_text_labels "${PYTHON_EXECUTABLE}" - ${cdat_SOURCE_DIR}/testing/vcs/test_animate_isolines_text_labels.py + ${cdat_SOURCE_DIR}/testing/vcs/test_animate_isoline_text_labels.py ${BASELINE_DIR} ) - cdat_add_test(vcs_test_animate_isolines_text_labels_colored + cdat_add_test(vcs_test_animate_isoline_text_labels_colored "${PYTHON_EXECUTABLE}" - ${cdat_SOURCE_DIR}/testing/vcs/test_animate_isolines_text_labels_colored.py + ${cdat_SOURCE_DIR}/testing/vcs/test_animate_isoline_text_labels_colored.py ${BASELINE_DIR} ) endif() From 90a282a4eda96386d75a7d2a069d8edc999e924d Mon Sep 17 00:00:00 2001 From: "David C. Lonie" Date: Thu, 23 Apr 2015 16:06:34 -0400 Subject: [PATCH 16/16] Use vtkContourLabeledMapper::TextPropertyMapping. Explicitly associates the contour values to the text properties. Also some logic simplification. --- Packages/vcs/Lib/VTKPlots.py | 115 +++++++++++++++-------------- testing/vcs/test_isoline_labels.py | 39 ++++++++-- 2 files changed, 94 insertions(+), 60 deletions(-) diff --git a/Packages/vcs/Lib/VTKPlots.py b/Packages/vcs/Lib/VTKPlots.py index 247f071b3d..1e1b3a64ed 100644 --- a/Packages/vcs/Lib/VTKPlots.py +++ b/Packages/vcs/Lib/VTKPlots.py @@ -876,71 +876,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(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) - mapper.GetPolyDataMapper().SetScalarRange(levs[0],levs[-1]) - mapper.GetPolyDataMapper().SetScalarModeToUsePointData() + # 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)