Skip to content

Commit

Permalink
Fix aspect ratio of logo image so it is not stretched or squashed
Browse files Browse the repository at this point in the history
  • Loading branch information
scottwittenburg committed Dec 19, 2018
1 parent 74761cf commit 0d0533a
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions vcs/VTKPlots.py
Original file line number Diff line number Diff line change
Expand Up @@ -1653,18 +1653,38 @@ def createLogo(self):
position = [0.895, 0.0]
position2 = [0.10, 0.05]

[renWinWidth, renWinHeight] = self.renWin.GetSize()
vpLowerLeftX = position[0] * renWinWidth
vpLowerLeftY = position[1] * renWinHeight
vpWidth = position2[0] * renWinWidth
vpHeight = position2[1] * renWinHeight

imgAspect = float(imgWidth) / imgHeight
vpAspect = vpWidth / vpHeight

if vpAspect > imgAspect:
# We'll use the full vp height and adjust it's width so that it's
# aspect ratio matches that of the image (so no stretching of the
# image occurs). The image should be centered, so we'll offset
# position x value by half the difference.
vpWidth = vpHeight * imgAspect
halfDiff = ((position2[0] * renWinWidth) - vpWidth) / 2.0
vpLowerLeftX += halfDiff
else:
# Similar to above, but in this case we choose to keep the vp width
# and adjust it's height.
vpHeight = vpWidth / imgAspect
halfDiff = ((position2[1] * renWinHeight) - vpHeight) / 2.0
vpLowerLeftY += halfDiff

view = self.contextView

area = vtk.vtkContextArea()
view.GetScene().AddItem(area)

[renWinWidth, renWinHeight] = self.renWin.GetSize()
dataBounds = vtk.vtkRectd(0.0, 0.0, imgWidth, imgHeight)
screenGeom = vtk.vtkRecti(
int(position[0] * renWinWidth),
int(position[1] * renWinHeight),
int(position2[0] * renWinWidth),
int(position2[1] * renWinHeight))
screenGeom = vtk.vtkRecti(int(vpLowerLeftX), int(vpLowerLeftY),
int(vpWidth), int(vpHeight))

vcs2vtk.configureContextArea(area, dataBounds, screenGeom)
area.GetDrawAreaItem().AddItem(item)
Expand Down

0 comments on commit 0d0533a

Please sign in to comment.