Skip to content

Commit

Permalink
BUG #26: If masking reduces the bounds of a dataset, plots look incom…
Browse files Browse the repository at this point in the history
…plete. (#27)

We use 'vtk_dataset_bounds_no_mask', the dataset bounds before masking
instead of the dataset bounds for fitToViewport.
  • Loading branch information
danlipsa authored and doutriaux1 committed Nov 2, 2016
1 parent 91a9501 commit cf99af4
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 27 deletions.
9 changes: 6 additions & 3 deletions vcs/VTKPlots.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def __init__(self, canvas, renWin=None, debug=False, bg=None, geometry=None):
# the same as vcs.utils.getworldcoordinates for now. getworldcoordinates uses
# gm.datawc_... or, if that is not set, it uses data axis margins (without bounds).
'plotting_dataset_bounds',
# dataset bounds before masking
'vtk_dataset_bounds_no_mask',
'renderer',
'vtk_backend_grid',
# vtkGeoTransform used for geographic transformation
Expand Down Expand Up @@ -596,8 +598,9 @@ def plot(self, data1, data2, template, gtype, gname, bg, *args, **kargs):
ren = kargs["renderer"]

vtk_backend_grid = kargs.get("vtk_backend_grid", None)
vtk_dataset_bounds_no_mask = kargs.get("vtk_dataset_bounds_no_mask", None)
vtk_backend_geo = kargs.get("vtk_backend_geo", None)
bounds = vtk_backend_grid.GetBounds() if vtk_backend_grid else None
bounds = vtk_dataset_bounds_no_mask if vtk_dataset_bounds_no_mask else None

pipeline = vcsvtk.createPipeline(gm, self)
if pipeline is not None:
Expand Down Expand Up @@ -802,11 +805,11 @@ def plotContinents(self, wc, projection, wrap, vp, priority, **kargs):

# Stippling
vcs2vtk.stippleLine(line_prop, contLine.type[0])
vtk_backend_grid = kargs.get("vtk_backend_grid", None)
vtk_dataset_bounds_no_mask = kargs.get("vtk_dataset_bounds_no_mask", None)
return self.fitToViewport(contActor,
vp,
wc=wc, geo=geo,
geoBounds=vtk_backend_grid.GetBounds(),
geoBounds=vtk_dataset_bounds_no_mask,
priority=priority,
create_renderer=True)

Expand Down
9 changes: 9 additions & 0 deletions vcs/vcs2vtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ def removeHiddenPoints(grid):
if (vectorNorm < minVectorNorm):
minVector = vector
minVectorNorm = vectorNorm
hiddenScalars = False
hiddenVectors = False
for i in range(pts.GetNumberOfPoints()):
if (ghost.GetValue(i) & vtk.vtkDataSetAttributes.HIDDENPOINT):
cells = vtk.vtkIdList()
Expand All @@ -277,9 +279,16 @@ def removeHiddenPoints(grid):
# hidden points are not removed. This causes problems
# because it changes the scalar range.
if(scalars):
hiddenScalars = True
scalars.SetValue(i, minScalar)
if(vectors):
hiddenVectors = True
vectors.SetTypedTuple(i, minVector)
# SetValue does not call modified - we'll have to call it after all calls.
if (hiddenScalars):
scalars.Modified()
if (hiddenVectors):
vectors.Modified()
# ensure that GLOBALIDS are copied
attributes = grid.GetCellData()
attributes.SetActiveAttribute(-1, attributes.GLOBALIDS)
Expand Down
9 changes: 4 additions & 5 deletions vcs/vcsvtk/boxfillpipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def _plotInternal(self):
# (we need one for each mapper because of camera flips)
dataset_renderer, xScale, yScale = self._context().fitToViewport(
act, vp,
wc=plotting_dataset_bounds, geoBounds=self._vtkDataSet.GetBounds(),
wc=plotting_dataset_bounds, geoBounds=self._vtkDataSetBoundsNoMask,
geo=self._vtkGeoTransform,
priority=self._template.data.priority,
create_renderer=(dataset_renderer is None))
Expand All @@ -130,7 +130,7 @@ def _plotInternal(self):
# why so sticking to many mappers
self._context().fitToViewport(
act, vp,
wc=plotting_dataset_bounds, geoBounds=self._vtkDataSet.GetBounds(),
wc=plotting_dataset_bounds, geoBounds=self._vtkDataSetBoundsNoMask,
geo=self._vtkGeoTransform,
priority=self._template.data.priority,
create_renderer=True)
Expand All @@ -146,6 +146,7 @@ def _plotInternal(self):
kwargs = {"vtk_backend_grid": self._vtkDataSet,
"dataset_bounds": self._vtkDataSetBounds,
"plotting_dataset_bounds": plotting_dataset_bounds,
"vtk_dataset_bounds_no_mask": self._vtkDataSetBoundsNoMask,
"vtk_backend_geo": self._vtkGeoTransform}
if ("ratio_autot_viewport" in self._resultDict):
kwargs["ratio_autot_viewport"] = vp
Expand Down Expand Up @@ -200,9 +201,7 @@ def _plotInternal(self):
continents_renderer, xScale, yScale = self._context().plotContinents(
plotting_dataset_bounds, projection,
self._dataWrapModulo,
vp, self._template.data.priority,
vtk_backend_grid=self._vtkDataSet,
dataset_bounds=self._vtkDataSetBounds)
vp, self._template.data.priority, **kwargs)

def _plotInternalBoxfill(self):
"""Implements the logic to render a non-custom boxfill."""
Expand Down
9 changes: 4 additions & 5 deletions vcs/vcsvtk/isofillpipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,14 @@ def _plotInternal(self):
# (we need one for each mapper because of cmaera flips)
dataset_renderer, xScale, yScale = self._context().fitToViewport(
act, vp,
wc=plotting_dataset_bounds, geoBounds=self._vtkDataSet.GetBounds(),
wc=plotting_dataset_bounds, geoBounds=self._vtkDataSetBoundsNoMask,
geo=self._vtkGeoTransform,
priority=self._template.data.priority,
create_renderer=(mapper is self._maskedDataMapper or dataset_renderer is None))
for act in patternActors:
self._context().fitToViewport(
act, vp,
wc=plotting_dataset_bounds, geoBounds=self._vtkDataSet.GetBounds(),
wc=plotting_dataset_bounds, geoBounds=self._vtkDataSetBoundsNoMask,
geo=self._vtkGeoTransform,
priority=self._template.data.priority,
create_renderer=True)
Expand All @@ -176,6 +176,7 @@ def _plotInternal(self):
kwargs = {"vtk_backend_grid": self._vtkDataSet,
"dataset_bounds": self._vtkDataSetBounds,
"plotting_dataset_bounds": plotting_dataset_bounds,
"vtk_dataset_bounds_no_mask": self._vtkDataSetBoundsNoMask,
"vtk_backend_geo": self._vtkGeoTransform}
if ("ratio_autot_viewport" in self._resultDict):
kwargs["ratio_autot_viewport"] = vp
Expand Down Expand Up @@ -221,6 +222,4 @@ def _plotInternal(self):
continents_renderer, xScale, yScale = self._context().plotContinents(
plotting_dataset_bounds, projection,
self._dataWrapModulo,
vp, self._template.data.priority,
vtk_backend_grid=self._vtkDataSet,
dataset_bounds=self._vtkDataSetBounds)
vp, self._template.data.priority, **kwargs)
9 changes: 4 additions & 5 deletions vcs/vcsvtk/isolinepipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def _plotInternal(self):
# (we need one for each mapper because of cmaera flips)
dataset_renderer, xScale, yScale = self._context().fitToViewport(
act, vp,
wc=plotting_dataset_bounds, geoBounds=self._vtkDataSet.GetBounds(),
wc=plotting_dataset_bounds, geoBounds=self._vtkDataSetBoundsNoMask,
geo=self._vtkGeoTransform,
priority=self._template.data.priority,
create_renderer=(dataset_renderer is None))
Expand All @@ -283,7 +283,7 @@ def _plotInternal(self):
# (we need one for each mapper because of cmaera flips)
self._context().fitToViewport(
act, vp,
wc=plotting_dataset_bounds, geoBounds=self._vtkDataSet.GetBounds(),
wc=plotting_dataset_bounds, geoBounds=self._vtkDataSetBoundsNoMask,
geo=self._vtkGeoTransform,
priority=self._template.data.priority,
create_renderer=True)
Expand All @@ -298,6 +298,7 @@ def _plotInternal(self):
kwargs = {"vtk_backend_grid": self._vtkDataSet,
"dataset_bounds": self._vtkDataSetBounds,
"plotting_dataset_bounds": plotting_dataset_bounds,
"vtk_dataset_bounds_no_mask": self._vtkDataSetBoundsNoMask,
"vtk_backend_geo": self._vtkGeoTransform}
if ("ratio_autot_viewport" in self._resultDict):
kwargs["ratio_autot_viewport"] = vp
Expand All @@ -313,6 +314,4 @@ def _plotInternal(self):
continents_renderer, xScale, yScale = self._context().plotContinents(
plotting_dataset_bounds, projection,
self._dataWrapModulo,
vp, self._template.data.priority,
vtk_backend_grid=self._vtkDataSet,
dataset_bounds=self._vtkDataSetBounds)
vp, self._template.data.priority, **kwargs)
9 changes: 4 additions & 5 deletions vcs/vcsvtk/meshfillpipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def _plotInternal(self):
# (we need one for each mapper because of cmaera flips)
dataset_renderer, xScale, yScale = self._context().fitToViewport(
act, vp,
wc=plotting_dataset_bounds, geoBounds=self._vtkDataSet.GetBounds(),
wc=plotting_dataset_bounds, geoBounds=self._vtkDataSetBoundsNoMask,
geo=self._vtkGeoTransform,
priority=self._template.data.priority,
create_renderer=(dataset_renderer is None))
Expand All @@ -195,7 +195,7 @@ def _plotInternal(self):
# why so sticking to many mappers
self._context().fitToViewport(
act, vp,
wc=plotting_dataset_bounds, geoBounds=self._vtkDataSet.GetBounds(),
wc=plotting_dataset_bounds, geoBounds=self._vtkDataSetBoundsNoMask,
geo=self._vtkGeoTransform,
priority=self._template.data.priority,
create_renderer=True)
Expand All @@ -210,6 +210,7 @@ def _plotInternal(self):
kwargs = {"vtk_backend_grid": self._vtkDataSet,
"dataset_bounds": self._vtkDataSetBounds,
"plotting_dataset_bounds": plotting_dataset_bounds,
"vtk_dataset_bounds_no_mask": self._vtkDataSetBoundsNoMask,
"vtk_backend_geo": self._vtkGeoTransform}
if ("ratio_autot_viewport" in self._resultDict):
kwargs["ratio_autot_viewport"] = vp
Expand Down Expand Up @@ -265,9 +266,7 @@ def _plotInternal(self):
continents_renderer, xScale, yScale = self._context().plotContinents(
plotting_dataset_bounds, projection,
self._dataWrapModulo,
vp, self._template.data.priority,
vtk_backend_grid=self._vtkDataSet,
dataset_bounds=self._vtkDataSetBounds)
vp, self._template.data.priority, **kwargs)

def getPlottingBounds(self):
"""gm.datawc if it is set or dataset_bounds
Expand Down
7 changes: 6 additions & 1 deletion vcs/vcsvtk/pipeline2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ class IPipeline2D(Pipeline):
pipeline.
- _vtkDataSetBounds: The bounds of _vtkDataSet, in lon/lat space, as
tuple(float xMin, float xMax, float yMin, float yMax)
- _vtkDataSetBoundsNoMask : The bounds of _vtkDataSet in Cartesian space
before masking. These are used instead of the dataset bounds
because masking can change the dataset bounds which results in a dataset
that looks incomplete.
- _vtkPolyDataFilter: A vtkAlgorithm that produces a polydata
representation of the data.
- _colorMap: The vcs colormap object used to color the scalar data.
Expand Down Expand Up @@ -296,6 +300,7 @@ def plot(self, data1, data2, tmpl, grid, transform, **kargs):
self._updateContourLevelsAndColors()

# Generate a mapper to render masked data:
self._vtkDataSetBoundsNoMask = self._vtkDataSet.GetBounds()
self._createMaskedDataMapper()

# Create the polydata filter:
Expand Down Expand Up @@ -367,7 +372,7 @@ def _createPolyDataFilter(self):
plotting_dataset_bounds = self.getPlottingBounds()
surface_renderer, xScale, yScale = self._context().fitToViewport(
act, vp,
wc=plotting_dataset_bounds, geoBounds=self._vtkDataSet.GetBounds(),
wc=plotting_dataset_bounds, geoBounds=self._vtkDataSetBoundsNoMask,
geo=self._vtkGeoTransform,
priority=self._template.data.priority,
create_renderer=True)
Expand Down
5 changes: 2 additions & 3 deletions vcs/vcsvtk/vectorpipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ def _plotInternal(self):
kwargs = {'vtk_backend_grid': self._vtkDataSet,
'dataset_bounds': self._vtkDataSetBounds,
'plotting_dataset_bounds': plotting_dataset_bounds,
"vtk_dataset_bounds_no_mask": self._vtkDataSetBoundsNoMask,
'vtk_backend_geo': self._vtkGeoTransform}
if ('ratio_autot_viewport' in self._resultDict):
kwargs["ratio_autot_viewport"] = vp
Expand All @@ -232,9 +233,7 @@ def _plotInternal(self):
if self._useContinents:
continents_renderer, xScale, yScale = self._context().plotContinents(
plotting_dataset_bounds, projection,
self._dataWrapModulo, vp, self._template.data.priority,
vtk_backend_grid=self._vtkDataSet,
dataset_bounds=self._vtkDataSetBounds)
self._dataWrapModulo, vp, self._template.data.priority, **kwargs)
self._resultDict["vtk_backend_actors"] = [[act, plotting_dataset_bounds]]
self._resultDict["vtk_backend_glyphfilters"] = [glyphFilter]
self._resultDict["vtk_backend_luts"] = [[None, None]]
Expand Down

0 comments on commit cf99af4

Please sign in to comment.