Skip to content

Commit

Permalink
Fix shifted plots, and add sparse dots (#377)
Browse files Browse the repository at this point in the history
* Fixes plots shifted down and to the left

By computing screen geometries in floating point, but then truncating
them instead of rounding first, we were inadvertently shifting all
plot components down and to the left.  One effect of this fix is that
we longer see the ~1px gaps between the plot contents and the plot
border on the top and left of the plot.

* Expose a "sparse-dot" stipple option, make sure it gets tested
  • Loading branch information
scottwittenburg authored and doutriaux1 committed Dec 20, 2018
1 parent dadf5d0 commit f83696d
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 45 deletions.
4 changes: 2 additions & 2 deletions tests/test_vcs_line_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ def __init__(self, *args, **kwargs):
def testVCSLinePatterns(self):
s = self.clt('clt')
iso = self.x.createisoline()
iso.level = [5, 50, 70, 95]
iso.linetypes = ['dot', 'dash', 'dash-dot', 'long-dash']
iso.level = [5, 25, 50, 70, 95]
iso.linetypes = ['dot', 'sparse-dot', 'dash', 'dash-dot', 'long-dash']
self.x.plot(s, iso, continents=0, bg=self.bg)
name = "test_vcs_line_patterns.png"
self.checkImage(name)
4 changes: 3 additions & 1 deletion vcs/VCS_validation_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,12 +915,14 @@ def checkLineType(self, name, value):
hvalue = 'dash-dot'
elif value in ('long-dash', 4):
hvalue = 'long-dash'
elif value in ('sparse-dot', 5):
hvalue = 'sparse-dot'
else:
checkedRaise(
self,
value,
ValueError,
'Expecting ("solid", "dash", "dot", "dash-dot", "long-dash") or (0, 1, 2, 3, 4)')
'Expecting ("solid", "dash", "dot", "dash-dot", "long-dash", "sparse-dot") or (0, 1, 2, 3, 4, 5)')
return hvalue


Expand Down
38 changes: 20 additions & 18 deletions vcs/VTKPlots.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,10 +900,10 @@ def plot(self, data1, data2, template, gtype, gname, bg, *args, **kargs):
wc = self.canvas._worldcoordinate

[renWinWidth, renWinHeight] = self.renWin.GetSize()
geom = vtk.vtkRecti(int(vp[0] * renWinWidth),
int(vp[2] * renWinHeight),
int((vp[1] - vp[0]) * renWinWidth),
int((vp[3] - vp[2]) * renWinHeight))
geom = vtk.vtkRecti(int(round(vp[0] * renWinWidth)),
int(round(vp[2] * renWinHeight)),
int(round((vp[1] - vp[0]) * renWinWidth)),
int(round((vp[3] - vp[2]) * renWinHeight)))

rect = vtk.vtkRectd(0.0, 0.0, float(renWinWidth), float(renWinHeight))

Expand Down Expand Up @@ -931,10 +931,10 @@ def plot(self, data1, data2, template, gtype, gname, bg, *args, **kargs):
wc = gm.worldcoordinate

[renWinWidth, renWinHeight] = self.renWin.GetSize()
geom = vtk.vtkRecti(int(vp[0] * renWinWidth),
int(vp[2] * renWinHeight),
int((vp[1] - vp[0]) * renWinWidth),
int((vp[3] - vp[2]) * renWinHeight))
geom = vtk.vtkRecti(int(round(vp[0] * renWinWidth)),
int(round(vp[2] * renWinHeight)),
int(round((vp[1] - vp[0]) * renWinWidth)),
int(round((vp[3] - vp[2]) * renWinHeight)))

xScale, yScale, xc, yc, yd, flipX, flipY = self.computeScaleToFitViewport(
vp,
Expand Down Expand Up @@ -1063,10 +1063,10 @@ def plotContinents(self, continentType, wc, projection, wrap, vp, priority, **ka
view.GetScene().AddItem(area)

[renWinWidth, renWinHeight] = self.renWin.GetSize()
geom = vtk.vtkRecti(int(vp[0] * renWinWidth),
int(vp[2] * renWinHeight),
int((vp[1] - vp[0]) * renWinWidth),
int((vp[3] - vp[2]) * renWinHeight))
geom = vtk.vtkRecti(int(round(vp[0] * renWinWidth)),
int(round(vp[2] * renWinHeight)),
int(round((vp[1] - vp[0]) * renWinWidth)),
int(round((vp[3] - vp[2]) * renWinHeight)))

vcs2vtk.configureContextArea(area, contBounds, geom)

Expand Down Expand Up @@ -1112,10 +1112,10 @@ def renderTemplate(self, tmpl, data, gm, taxis,
vp = self.canvas._viewport

[renWinWidth, renWinHeight] = self.renWin.GetSize()
geom = vtk.vtkRecti(int(vp[0] * renWinWidth),
int(vp[2] * renWinHeight),
int((vp[1] - vp[0]) * renWinWidth),
int((vp[3] - vp[2]) * renWinHeight))
geom = vtk.vtkRecti(int(round(vp[0] * renWinWidth)),
int(round(vp[2] * renWinHeight)),
int(round((vp[1] - vp[0]) * renWinWidth)),
int(round((vp[3] - vp[2]) * renWinHeight)))

rect = vtk.vtkRectd(0.0, 0.0, float(renWinWidth), float(renWinHeight))

Expand Down Expand Up @@ -1692,8 +1692,10 @@ def createLogo(self):
view.GetScene().AddItem(area)

dataBounds = vtk.vtkRectd(0.0, 0.0, imgWidth, imgHeight)
screenGeom = vtk.vtkRecti(int(vpLowerLeftX), int(vpLowerLeftY),
int(vpWidth), int(vpHeight))
screenGeom = vtk.vtkRecti(int(round(vpLowerLeftX)),
int(round(vpLowerLeftY)),
int(round(vpWidth)),
int(round(vpHeight)))

vcs2vtk.configureContextArea(area, dataBounds, screenGeom)
area.GetDrawAreaItem().AddItem(item)
Expand Down
2 changes: 2 additions & 0 deletions vcs/vcs2vtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -2011,6 +2011,8 @@ def getStipple(line_type):
"""
if line_type == 'long-dash':
return vtk.vtkPen.DASH_DOT_DOT_LINE
elif line_type == 'sparse-dot':
return vtk.vtkPen.DOT_LINE
elif line_type == 'dot':
return vtk.vtkPen.DENSE_DOT_LINE
elif line_type == 'dash':
Expand Down
8 changes: 4 additions & 4 deletions vcs/vcsvtk/boxfillpipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ def _plotInternal(self):

[renWinWidth, renWinHeight] = self._context().renWin.GetSize()
# vp = vcs2vtk.adjustBounds(vp, 0.9, 0.9)
geom = vtk.vtkRecti(int(vp[0] * renWinWidth),
int(vp[2] * renWinHeight),
int((vp[1] - vp[0]) * renWinWidth),
int((vp[3] - vp[2]) * renWinHeight))
geom = vtk.vtkRecti(int(round(vp[0] * renWinWidth)),
int(round(vp[2] * renWinHeight)),
int(round((vp[1] - vp[0]) * renWinWidth)),
int(round((vp[3] - vp[2]) * renWinHeight)))

vcs2vtk.configureContextArea(area, drawAreaBounds, geom)

Expand Down
8 changes: 4 additions & 4 deletions vcs/vcsvtk/isofillpipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ def _plotInternal(self):
drawAreaBounds = vcs2vtk.computeDrawAreaBounds(adjusted_plotting_bounds)

[renWinWidth, renWinHeight] = self._context().renWin.GetSize()
geom = vtk.vtkRecti(int(vp[0] * renWinWidth),
int(vp[2] * renWinHeight),
int((vp[1] - vp[0]) * renWinWidth),
int((vp[3] - vp[2]) * renWinHeight))
geom = vtk.vtkRecti(int(round(vp[0] * renWinWidth)),
int(round(vp[2] * renWinHeight)),
int(round((vp[1] - vp[0]) * renWinWidth)),
int(round((vp[3] - vp[2]) * renWinHeight)))

vcs2vtk.configureContextArea(area, drawAreaBounds, geom)

Expand Down
8 changes: 4 additions & 4 deletions vcs/vcsvtk/isolinepipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ def _plotInternal(self):
drawAreaBounds = vcs2vtk.computeDrawAreaBounds(adjusted_plotting_bounds)

[renWinWidth, renWinHeight] = self._context().renWin.GetSize()
geom = vtk.vtkRecti(int(vp[0] * renWinWidth),
int(vp[2] * renWinHeight),
int((vp[1] - vp[0]) * renWinWidth),
int((vp[3] - vp[2]) * renWinHeight))
geom = vtk.vtkRecti(int(round(vp[0] * renWinWidth)),
int(round(vp[2] * renWinHeight)),
int(round((vp[1] - vp[0]) * renWinWidth)),
int(round((vp[3] - vp[2]) * renWinHeight)))

vcs2vtk.configureContextArea(area, drawAreaBounds, geom)

Expand Down
8 changes: 4 additions & 4 deletions vcs/vcsvtk/meshfillpipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ def _plotInternal(self):
drawAreaBounds = vcs2vtk.computeDrawAreaBounds(adjusted_plotting_bounds)

[renWinWidth, renWinHeight] = self._context().renWin.GetSize()
geom = vtk.vtkRecti(int(vp[0] * renWinWidth),
int(vp[2] * renWinHeight),
int((vp[1] - vp[0]) * renWinWidth),
int((vp[3] - vp[2]) * renWinHeight))
geom = vtk.vtkRecti(int(round(vp[0] * renWinWidth)),
int(round(vp[2] * renWinHeight)),
int(round((vp[1] - vp[0]) * renWinWidth)),
int(round((vp[3] - vp[2]) * renWinHeight)))

vcs2vtk.configureContextArea(area, drawAreaBounds, geom)

Expand Down
8 changes: 4 additions & 4 deletions vcs/vcsvtk/streamlinepipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ def _plotInternal(self):
self._context_flipX, self._context_flipY)

[renWinWidth, renWinHeight] = self._context().renWin.GetSize()
geom = vtk.vtkRecti(int(vp[0] * renWinWidth),
int(vp[2] * renWinHeight),
int((vp[1] - vp[0]) * renWinWidth),
int((vp[3] - vp[2]) * renWinHeight))
geom = vtk.vtkRecti(int(round(vp[0] * renWinWidth)),
int(round(vp[2] * renWinHeight)),
int(round((vp[1] - vp[0]) * renWinWidth)),
int(round((vp[3] - vp[2]) * renWinHeight)))

vcs2vtk.configureContextArea(area, drawAreaBounds, geom)

Expand Down
8 changes: 4 additions & 4 deletions vcs/vcsvtk/vectorpipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ def _plotInternal(self):
self._context_flipX, self._context_flipY)

[renWinWidth, renWinHeight] = self._context().renWin.GetSize()
geom = vtk.vtkRecti(int(vp[0] * renWinWidth),
int(vp[2] * renWinHeight),
int((vp[1] - vp[0]) * renWinWidth),
int((vp[3] - vp[2]) * renWinHeight))
geom = vtk.vtkRecti(int(round(vp[0] * renWinWidth)),
int(round(vp[2] * renWinHeight)),
int(round((vp[1] - vp[0]) * renWinWidth)),
int(round((vp[3] - vp[2]) * renWinHeight)))

vcs2vtk.configureContextArea(area, drawAreaBounds, geom)

Expand Down

0 comments on commit f83696d

Please sign in to comment.