From 0f26daaf8119f78265b4ae3646e9c7fe19ae631d Mon Sep 17 00:00:00 2001 From: Dan Lipsa Date: Fri, 10 Jun 2016 14:21:31 -0400 Subject: [PATCH] BUG #1947: isofill does not handle out of bounds levels correctly. When smallest level is bigger than min scalar value or biggest level is smaller than max scalar value isofill creates the wrong image. Also, out of range (white color) was shown black. --- Packages/vcs/vcs/vcs2vtk.py | 25 +++++++++++++--------- Packages/vcs/vcs/vcsvtk/isofillpipeline.py | 8 ++++++- testing/vcs/CMakeLists.txt | 11 ++++++++++ testing/vcs/test_vcs_isofill_levels.py | 19 ++++++++++++++++ 4 files changed, 52 insertions(+), 11 deletions(-) create mode 100644 testing/vcs/test_vcs_isofill_levels.py diff --git a/Packages/vcs/vcs/vcs2vtk.py b/Packages/vcs/vcs/vcs2vtk.py index d07ca44cc2..1334e361df 100644 --- a/Packages/vcs/vcs/vcs2vtk.py +++ b/Packages/vcs/vcs/vcs2vtk.py @@ -94,15 +94,14 @@ def setArray(grid, array, arrayName, isCellData, isScalars): def putMaskOnVTKGrid(data, grid, actorColor=None, cellData=True, deep=True): - # Ok now looking msk = data.mask mapper = None if msk is not numpy.ma.nomask and not numpy.allclose(msk, False): if actorColor is not None: - flatIMask = msk.astype(numpy.int).flat + flatIMask = msk.astype(numpy.double).flat if grid.IsA("vtkStructuredGrid"): grid2 = vtk.vtkStructuredGrid() - vtkmask = numpy_to_vtk_wrapper(flatIMask, deep=deep) + vtkmask = numpy_to_vtk_wrapper(flatIMask, deep=deep, array_type=vtk.VTK_DOUBLE) attributes2 = grid2.GetCellData() if cellData else grid2.GetPointData() else: grid2 = vtk.vtkUnstructuredGrid() @@ -114,26 +113,32 @@ def putMaskOnVTKGrid(data, grid, actorColor=None, cellData=True, deep=True): attributes = grid.GetPointData() if (attributes.GetPedigreeIds()): attributes2.SetPedigreeIds(attributes.GetPedigreeIds()) - vtkmask = vtk.vtkIntArray() + pedigreeId = attributes2.GetPedigreeIds() + vtkmask = vtk.vtkDoubleArray() vtkmask.SetNumberOfTuples(attributes2.GetPedigreeIds().GetNumberOfTuples()) + for i in range(0, vtkmask.GetNumberOfTuples()): + vtkmask.SetValue(i, flatIMask[pedigreeId.GetValue(i)]) else: # the unstructured grid is not wrapped - vtkmask = numpy_to_vtk_wrapper(flatIMask, deep=deep) + vtkmask = numpy_to_vtk_wrapper(flatIMask, deep=deep, array_type=vtk.VTK_DOUBLE) vtkmask.SetName("scalar") attributes2.RemoveArray(vtk.vtkDataSetAttributes.GhostArrayName()) attributes2.SetScalars(vtkmask) grid2.CopyStructure(grid) - setArray(grid2, flatIMask, "scalar", isCellData=cellData, - isScalars=True) geoFilter = vtk.vtkDataSetSurfaceFilter() lut = vtk.vtkLookupTable() r, g, b, a = actorColor - lut.SetNumberOfTableValues(2) geoFilter.SetInputData(grid2) if not cellData: - lut.SetTableValue(0, r / 100., g / 100., b / 100., a / 100.) - lut.SetTableValue(1, r / 100., g / 100., b / 100., a / 100.) + pointToCell = vtk.vtkPointDataToCellData() + pointToCell.SetInputConnection(geoFilter.GetOutputPort()) + geoFilter = pointToCell + lut.SetNumberOfTableValues(256) + lut.SetTableValue(0, 1., 1., 1., 1.) + for i in range(1, 256): + lut.SetTableValue(i, r / 100., g / 100., b / 100., a / 100.) else: + lut.SetNumberOfTableValues(2) lut.SetTableValue(0, r / 100., g / 100., b / 100., 0.) lut.SetTableValue(1, r / 100., g / 100., b / 100., 1.) geoFilter.Update() diff --git a/Packages/vcs/vcs/vcsvtk/isofillpipeline.py b/Packages/vcs/vcs/vcsvtk/isofillpipeline.py index 887c6158c9..273376c090 100644 --- a/Packages/vcs/vcs/vcsvtk/isofillpipeline.py +++ b/Packages/vcs/vcs/vcsvtk/isofillpipeline.py @@ -67,7 +67,13 @@ def _plotInternal(self): lut.SetTableValue(j, 1., 1., 1., 0.) luts.append([lut, [0, len(l) - 1, True]]) mapper.SetLookupTable(lut) - mapper.SetScalarRange(0, len(l) - 1) + minRange = 0 + maxRange = len(l) - 1 + if (i == 0 and self._scalarRange[0] < l[0]): + # band 0 is from self._scalarRange[0] to l[0] + # we don't show band 0 + minRange += 1 + mapper.SetScalarRange(minRange, maxRange) mapper.SetScalarModeToUseCellData() mappers.append(mapper) diff --git a/testing/vcs/CMakeLists.txt b/testing/vcs/CMakeLists.txt index 127baf6f05..a3b3b155e0 100644 --- a/testing/vcs/CMakeLists.txt +++ b/testing/vcs/CMakeLists.txt @@ -877,6 +877,17 @@ cdat_add_test(test_vcs_settings_color_name_rgba --bigvalues "--source=${BASELINE_DIR}/test_vcs_basic_isofill_bigvalues.png" ) + + foreach(level 0 1 2) + cdat_add_test(test_vcs_isofill_level${level} + "${PYTHON_EXECUTABLE}" + ${cdat_SOURCE_DIR}/testing/vcs/test_vcs_isofill_levels.py + "${BASELINE_DIR}/test_vcs_isofill_level${level}.png" + "${UVCDAT_GIT_TESTDATA_DIR}/data/HadSST1870to99.nc" + ${level} + ) + endforeach() + cdat_add_test(test_vcs_issue_960_labels "${PYTHON_EXECUTABLE}" ${cdat_SOURCE_DIR}/testing/vcs/test_vcs_issue_960_labels.py diff --git a/testing/vcs/test_vcs_isofill_levels.py b/testing/vcs/test_vcs_isofill_levels.py new file mode 100644 index 0000000000..912178148b --- /dev/null +++ b/testing/vcs/test_vcs_isofill_levels.py @@ -0,0 +1,19 @@ +import cdms2 +import os +import sys +import testing.regression as regression +import vcs + +data = sys.argv[2] +level = sys.argv[3] +levels = {'0': range(-5,36,5), + '1': [-1000, -15, 35], + '2': [-300, -15, 0, 15, 25]} + +x=regression.init(bg=1) +f=cdms2.open(data) +s=f("sst") +iso=x.createisofill() +iso.levels=levels[level] +x.plot(s,iso) +regression.run(x, "test_vcs_isofill_level%s.png"%level)