示例#1
0
def buildColourBarLayout(canvasLayout,
                         cbarBmp,
                         cbarLocation,
                         cbarLabelSide):
    """Given a layout object containing the rendered canvas bitmaps,
    creates a new layout which incorporates the given colour bar bitmap.

    :arg canvasLayout:  An object describing the canvas layout (see
                        :mod:`fsleyes_widgets.utils.layout`)

    :arg cbarBmp:       A bitmap containing a rendered colour bar.

    :arg cbarLocation:  Colour bar location (see :func:`buildColourBarBitmap`).

    :arg cbarLabelSide: Colour bar label side (see
                        :func:`buildColourBarBitmap`).
    """

    cbarBmp = fsllayout.Bitmap(cbarBmp)

    if   cbarLocation in ('top',    'left'):  items = [cbarBmp, canvasLayout]
    elif cbarLocation in ('bottom', 'right'): items = [canvasLayout, cbarBmp]

    if   cbarLocation in ('top', 'bottom'): return fsllayout.VBox(items)
    elif cbarLocation in ('left', 'right'): return fsllayout.HBox(items)
示例#2
0
def render(namespace, overlayList, displayCtx, sceneOpts):
    """Renders the scene, and returns a bitmap.

    :arg namespace:   ``argparse.Namespace`` object containing command line
                      arguments.

    :arg overlayList: The :class:`.OverlayList` instance.
    :arg displayCtx:  The :class:`.DisplayContext` instance.
    :arg sceneOpts:   The :class:`.SceneOpts` instance.
    """

    # Calculate canvas and colour bar sizes
    # so that the entire scene will fit in
    # the width/height specified by the user
    width, height = namespace.size
    (width, height), (cbarWidth, cbarHeight) = \
        adjustSizeForColourBar(width,
                               height,
                               sceneOpts.showColourBar,
                               sceneOpts.colourBarLocation)

    # Lightbox view -> only one canvas
    if namespace.scene == 'lightbox':
        c = createLightBoxCanvas(namespace, width, height, overlayList,
                                 displayCtx, sceneOpts)
        canvases = [c]

    # Ortho view -> up to three canvases
    elif namespace.scene == 'ortho':
        canvases = createOrthoCanvases(namespace, width, height, overlayList,
                                       displayCtx, sceneOpts)
        labelMgr = ortholabels.OrthoLabels(overlayList, displayCtx, sceneOpts,
                                           *canvases)
        labelMgr.refreshLabels()

    # 3D -> one 3D canvas
    elif namespace.scene == '3d':
        c = create3DCanvas(namespace, width, height, overlayList, displayCtx,
                           sceneOpts)

        canvases = [c]

    # Do we need to do a neuro/radio l/r flip?
    if namespace.scene in ('ortho', 'lightbox'):
        inRadio = displayCtx.displaySpaceIsRadiological()
        lrFlip = displayCtx.radioOrientation != inRadio

        if lrFlip:
            for c in canvases:
                if c.opts.zax in (1, 2):
                    c.opts.invertX = True

    # fix orthographic projection if
    # showing an ortho grid layout.
    # Note that, if the user chose 'grid',
    # but also chose to hide one or more
    # canvases, the createOrthoCanvases
    # function will have adjusted the
    # value of sceneOpts.layout. So
    # if layout == grid, we definitely
    # have three canvases.
    #
    # The createOrthoCanvases also
    # re-orders the canvases, which
    # we're assuming knowledge of,
    # by indexing canvases[1].
    if namespace.scene == 'ortho' and sceneOpts.layout == 'grid':
        canvases[1].opts.invertX = True

    # Configure each of the canvases (with those
    # properties that are common to both ortho and
    # lightbox canvases) and render them one by one
    canvasBmps = []

    for i, c in enumerate(canvases):

        c.opts.pos = displayCtx.location

        c.draw()

        canvasBmps.append(c.getBitmap())

    # layout the bitmaps
    if namespace.scene in ('lightbox', '3d'):
        layout = fsllayout.Bitmap(canvasBmps[0])
    elif len(canvasBmps) > 0:
        layout = fsllayout.buildOrthoLayout(canvasBmps, None, sceneOpts.layout,
                                            False, 0)
    else:
        layout = fsllayout.Space(width, height)

    # Render a colour bar if required
    if sceneOpts.showColourBar:
        cbarBmp = buildColourBarBitmap(overlayList, displayCtx, cbarWidth,
                                       cbarHeight, sceneOpts.colourBarLocation,
                                       sceneOpts.colourBarLabelSide,
                                       sceneOpts.bgColour, sceneOpts.fgColour)
        if cbarBmp is not None:
            layout = buildColourBarLayout(layout, cbarBmp,
                                          sceneOpts.colourBarLocation,
                                          sceneOpts.colourBarLabelSide)

    # Turn the layout tree into a bitmap image
    return fsllayout.layoutToBitmap(layout,
                                    [c * 255 for c in sceneOpts.bgColour])