Skip to content

Commit

Permalink
BUG #1947: isofill does not handle out of bounds levels correctly.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
danlipsa committed Jun 15, 2016
1 parent b403c72 commit 0f26daa
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 11 deletions.
25 changes: 15 additions & 10 deletions Packages/vcs/vcs/vcs2vtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
8 changes: 7 additions & 1 deletion Packages/vcs/vcs/vcsvtk/isofillpipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
11 changes: 11 additions & 0 deletions testing/vcs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions testing/vcs/test_vcs_isofill_levels.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 0f26daa

Please sign in to comment.