Skip to content

Commit

Permalink
Fix put png on canvas (#167)
Browse files Browse the repository at this point in the history
* BUG: Fix offset computation for put_png

* BUG: Increasing priority for the colorbar puts a png on the top.

In a multi-plot with two rows, both having a png and a plot displyed in
the following order:
png, plot, png, plot

the second png ended up on top of the second plot because the colorbar raised the
png layer to 200+ while the plot layer stayed at 30+.
  • Loading branch information
danlipsa authored and doutriaux1 committed Apr 4, 2017
1 parent 0d98c80 commit 7259eb9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
35 changes: 20 additions & 15 deletions vcs/VTKPlots.py
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,8 @@ def put_png_on_canvas(
def put_img_on_canvas(
self, filename, zoom=1, xOffset=0, yOffset=0,
units="percent", fitToHeight=True, *args, **kargs):
self.createRenWin()
winSize = self.renWin.GetSize()
self.hideGUI()
readerFactory = vtk.vtkImageReader2Factory()
reader = readerFactory.CreateImageReader2(filename)
Expand All @@ -985,25 +987,28 @@ def put_img_on_canvas(
cam.ParallelProjectionOn()
width = (ext[1] - ext[0]) * spc[0]
height = (ext[3] - ext[2]) * spc[1]
if fitToHeight:
yd = height
else:
yd = winSize[1]
d = cam.GetDistance()
heightInWorldCoord = yd / zoom;
# window pixel in world (image) coordinates
pixelInWorldCoord = heightInWorldCoord / winSize[1]
if units[:7].lower() == "percent":
xoff = width * xOffset / zoom / 200.
yoff = height * yOffset / zoom / 200.
xoff = winSize[0] * (xOffset / 100.) * pixelInWorldCoord
yoff = winSize[1] * (yOffset / 100.) * pixelInWorldCoord
elif units[:6].lower() == "pixels":
xoff = xOffset / zoom
yoff = yOffset / zoom
xoff = xOffset * pixelInWorldCoord
yoff = yOffset * pixelInWorldCoord
else:
raise RuntimeError("vtk put image does not understand %s for offset units" % units)
xc = origin[0] + .5 * (ext[0] + ext[1]) * spc[0]
yc = origin[1] + .5 * (ext[2] + ext[3]) * spc[1]
if fitToHeight:
yd = (ext[3] - ext[2]) * spc[1]
else:
sz = self.renWin.GetSize()
yd = sz[1]
d = cam.GetDistance()
cam.SetParallelScale(.5 * yd / zoom)
cam.SetFocalPoint(xc + xoff, yc + yoff, 0.)
cam.SetPosition(xc + xoff, yc + yoff, d)
xc = origin[0] + .5 * width
yc = origin[1] + .5 * height
cam.SetParallelScale(heightInWorldCoord * 0.5)
cam.SetFocalPoint(xc - xoff, yc - yoff, 0.)
cam.SetPosition(xc - xoff, yc - yoff, d)

ren.AddActor(a)
layer = max(self.renWin.GetNumberOfLayers() - 2, 0)
ren.SetLayer(layer)
Expand Down
2 changes: 0 additions & 2 deletions vcs/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -2105,8 +2105,6 @@ def in_bounds(x):
txt = x.createtext(
To_source=self.legend.textorientation,
Tt_source=self.legend.texttable)
ln._priority = priority + 1
txt.priority = priority + 1
txt.string = St
if isinstance(legend, list):
if isHorizontal:
Expand Down

0 comments on commit 7259eb9

Please sign in to comment.