Esempio n. 1
0
def test_buildCanvasBox_noLabels():

    canvasbmp = np.ones((5, 5, 4))

    box = fsllayout.buildCanvasBox(canvasbmp, None, False, 0)

    bmp = fsllayout.layoutToBitmap(box)

    assert np.all(bmp == canvasbmp)
Esempio n. 2
0
def test_buildCanvasBox_withLabels():

    labelbmps = {
        'left': np.zeros((5, 5, 4)),
        'right': np.zeros((5, 5, 4)),
        'top': np.zeros((5, 5, 4)),
        'bottom': np.zeros((5, 5, 4))
    }

    canvasbmp = np.ones((20, 20, 4))
    expected = np.zeros((30, 30, 4))
    expected[5:25, 5:25, :] = canvasbmp

    box = fsllayout.buildCanvasBox(canvasbmp, labelbmps, True, 0)
    bmp = fsllayout.layoutToBitmap(box)

    assert np.all(bmp == expected)
Esempio n. 3
0
def test_buildOrthoLayout_vertical():

    canvasbmps = [
        np.zeros((10, 10, 4)),
        np.zeros((10, 10, 4)),
        np.zeros((10, 10, 4))
    ]

    canvasbmps[0][:] = 1
    canvasbmps[1][:] = 2
    canvasbmps[2][:] = 3

    expected = np.vstack(canvasbmps)

    result = fsllayout.buildOrthoLayout(canvasbmps, None, 'vertical', False, 0)
    result = fsllayout.layoutToBitmap(result)

    assert np.all(result == expected)
Esempio n. 4
0
def test_buildOrthoLayout_grid():

    canvasbmps = [
        np.zeros((10, 10, 4)),
        np.zeros((10, 10, 4)),
        np.zeros((10, 10, 4))
    ]

    canvasbmps[0][:] = 1
    canvasbmps[1][:] = 2
    canvasbmps[2][:] = 3

    expected = np.zeros((20, 20, 4))
    expected[:10, :10, :] = canvasbmps[0]
    expected[:10, 10:, :] = canvasbmps[1]
    expected[10:, :10, :] = canvasbmps[2]

    result = fsllayout.buildOrthoLayout(canvasbmps, None, 'grid', False, 0)
    result = fsllayout.layoutToBitmap(result)

    assert np.all(result == expected)
Esempio n. 5
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])