fsleyes_widgets.utils.layout
Utility functions for calculating canvas sizes and laying them out.
This module implements a simple layout manager, for laying out canvases and
associated orientation labels. It is used primarily by the render
application, for off-screen rendering.
You can use the following classes to define a layout:
A class which encapsulates a RGBA bitmap, assumed to be a |
|
A class which represents empty space of a specific width/height. |
|
A class which contains items to be laid out horizontally. |
|
A class which contains items to be laid out vertically. |
And the following functions to generate layouts and bitmaps:
Builds a layout containing the given canvas bitmaps, label bitmaps, and colour bar bitmap. |
|
Builds a layout containing the given canvas bitmap, and orientation labels (if |
|
Pads the given bitmap with zeros along the secondary axis (specified with the |
|
Recursively turns the given |
A few functions are also provided for calculating the display size, in pixels, of one or more canvases which are displaying a defined coordinate system. The canvas sizes are calculated so that their aspect ratio, relative to the respective horizontal/vertical display axes, are maintained, and that the canvases are sized proportionally with respect to each other. The following size calculation functions are available:
Convenience function which, based upon whether the layout argument is |
|
Calculates the size of three canvases so that they are laid out in a grid, i.e.: |
|
Calculates the size of up to three canvases so they are laid out horizontally. |
|
Calculates the size of up to three canvases so they are laid out vertically. |
|
Given the dimensions of a space to be displayed, and the available height in pixels, calculates the required pixel width. |
|
Given the dimensions of a space to be displayed, and the available width in pixels, calculates the required pixel height. |
- class fsleyes_widgets.utils.layout.Bitmap(bitmap)[source]
Bases:
object
A class which encapsulates a RGBA bitmap, assumed to be a
numpy.uint8
array of shape \(height \times width \times 4\)).Warning
Note the unusual array shape - height is the first axis, and width the second!
A
Bitmap
instance has the following attributes:bitmap
: The bitmap datawidth
: Bitmap width in pixelsheight
: Bitmap height in pixels
Create a
Bitmap
.- Parameters:
bitmap –
numpy
array containing the bitmap data.
- class fsleyes_widgets.utils.layout.Space(width, height)[source]
Bases:
object
A class which represents empty space of a specific width/height.
A
Space
instance has the following attributes:width
: Width in pixels.height
: Height in pixels.
Creat a
Space
.- Parameters:
width – Width in pixels.
height – Height in pixels.
- class fsleyes_widgets.utils.layout.HBox(items=None)[source]
Bases:
object
A class which contains items to be laid out horizontally.
After creation, new items should be added via the
append()
method.A
HBox
instance has the following attributes:width
: Total width in pixels.height
: Total height in pixels.items
: List of items in thisHBox
.
Create a
HBox
.- Parameters:
items – List of items contained in this
HBox
.
- class fsleyes_widgets.utils.layout.VBox(items=None)[source]
Bases:
object
A class which contains items to be laid out vertically.
After creation, new items can be added via the
append()
method.A
VBox
instance has the following attributes:width
: Total width in pixels.height
: Total height in pixels.items
: List of items in thisVBox
.
Create a
VBox
.- Parameters:
items – List of items contained in this
VBox
.
- fsleyes_widgets.utils.layout.padBitmap(bitmap, width, height, vert, bgColour)[source]
Pads the given bitmap with zeros along the secondary axis (specified with the
vert
parameter), so that it fits in the givenwidth
/height
.- Parameters:
bitmap – A
numpy.array
of size \(x \times y \times 4\) containing a RGBA bitmap.width – Desired width in pixels.
height – Desired height in pixels.
vert – If
vert
isTrue
, the bitmap is padded horizontally to fitwidth
. Otherwise, the bitmap is padded vertically to fitheight
.bgColour – Background colour to use for padding. Must be a
(r, g, b, a)
tuple with each channel in the range[0 - 255]
.
- fsleyes_widgets.utils.layout.layoutToBitmap(layout, bgColour=None)[source]
Recursively turns the given
layout
object into a bitmap.
- fsleyes_widgets.utils.layout.buildCanvasBox(canvasBmp, labelBmps, showLabels, labelSize)[source]
Builds a layout containing the given canvas bitmap, and orientation labels (if
showLabels
isTrue
).- Parameters:
canvasBmp – A
numpy.uint8
array containing a bitmap.labelBmps – Only used if
showLabels
isTrue
.numpy.uint8
arrays containing label bitmaps. Must be a dictionary of{side : numpy.uint8}
mappings, and must have keystop
,bottom
,left
andright
.showLabels – If
True
, the orientation labels provided inlabelBmps
are added to the layout.labelSize – Label sizes - the
left
/right
label widths, andtop
/bottom
label heights are padded to this size usingSpace
objects.
- Returns:
- fsleyes_widgets.utils.layout.buildOrthoLayout(canvasBmps, labelBmps, layout, showLabels, labelSize)[source]
Builds a layout containing the given canvas bitmaps, label bitmaps, and colour bar bitmap.
- Parameters:
canvasBmps – A list of
numpy.uint8
arrays containing the canvas bitmaps to be laid out.layout – One of
'horizontal'
,'vertical'
, or'grid'
.
See the
buildCanvasBox()
for details on the other parameters.
- fsleyes_widgets.utils.layout.calcSizes(layout, canvasaxes, bounds, width, height)[source]
Convenience function which, based upon whether the layout argument is
'horizontal'
,'vertical'
, or'grid'
, respectively calls one of:- Parameters:
layout – String specifying the layout type.
canvsaxes – A list of tuples, one for each canvas to be laid out. Each tuple contains two values,
(i, j)
, wherei
is an index, intobounds
, specifying the canvas width, andj
is an index intobounds
, specifying the canvas height, in the display coordinate system.bounds – A list of three values specifying the size of the display space.
width – Maximum width in pixels.
height – Maximum height in pixels.
- Returns:
A list of
(width, height)
tuples, one for each canvas, each specifying the canvas width and height in pixels.
- fsleyes_widgets.utils.layout.calcGridSizes(canvasaxes, bounds, width, height)[source]
Calculates the size of three canvases so that they are laid out in a grid, i.e.:
0 1
2
It is assumed that the
canvasaxes
parameters are ordered such that adjacent canvases share common axes in the world coordinate system. In other words, in the above diagram, the horizontal axes of canvases0
and2
are equal, and the vertical axes of canvases0
and1
must be equal.Note
If less than three canvases are specified, they are passed to the
calcHorizontalLayout()
function.See
calcSizes()
for details on the arguments.
- fsleyes_widgets.utils.layout.calcVerticalSizes(canvasaxes, bounds, width, height)[source]
Calculates the size of up to three canvases so they are laid out vertically.
See
calcSizes()
for details on the arguments.
- fsleyes_widgets.utils.layout.calcHorizontalSizes(canvasaxes, bounds, width, height)[source]
Calculates the size of up to three canvases so they are laid out horizontally.
See
calcSizes()
for details on the arguments.
- fsleyes_widgets.utils.layout.calcPixWidth(wldWidth, wldHeight, pixHeight)[source]
Given the dimensions of a space to be displayed, and the available height in pixels, calculates the required pixel width.
- Parameters:
wldWidth – Width of the display coordinate system
wldHeight – Height of the display coordinate system
pixHeight – Available height in pixels.
- Returns:
The required width in pixels.
- fsleyes_widgets.utils.layout.calcPixHeight(wldWidth, wldHeight, pixWidth)[source]
Given the dimensions of a space to be displayed, and the available width in pixels, calculates the required pixel height.
- Parameters:
wldWidth – Width of the display coordinate system
wldHeight – Height of the display coordinate system
pixWidth – Available width in pixels.
- Returns:
The required height in pixels.