示例#1
0
def test_calcSizes():

    # calcSizes  is just a wrapper around the
    # calcGrid/Horizontal/VerticalSizes functions

    # For grid layout, canvas edges have
    # to line up - see calcGridSizes docs
    gaxes = [(0, 2), (1, 2), (0, 1)]
    axes = [(0, 1), (0, 2), (1, 2)]

    # bounds, width, height
    testcases = [([1.0, 1.0, 1.0], 200, 200), ([1.0, 1.0, 1.0], 100, 200),
                 ([1.0, 1.0, 1.0], 200, 100), ([1.0, 2.0, 3.0], 200, 200)]

    for testcase in testcases:

        bounds, width, height = testcase

        hexp = fsllayout.calcHorizontalSizes(axes, bounds, width, height)
        vexp = fsllayout.calcVerticalSizes(axes, bounds, width, height)
        gexp = fsllayout.calcGridSizes(gaxes, bounds, width, height)
        hres = fsllayout.calcSizes('horizontal', axes, bounds, width, height)
        vres = fsllayout.calcSizes('vertical', axes, bounds, width, height)
        gres = fsllayout.calcSizes('grid', gaxes, bounds, width, height)

        assert np.all(np.isclose(hexp, hres))
        assert np.all(np.isclose(vexp, vres))
        assert np.all(np.isclose(gexp, gres))
示例#2
0
def calculateOrthoCanvasSizes(overlayList, displayCtx, width, height,
                              canvasAxes, layout):
    """Calculates the sizes, in pixels, for each canvas to be displayed in an
    orthographic layout.

    :arg overlayList: The :class:`.OverlayList`.

    :arg displayCtx:  The :class:`.DisplayContext`.

    :arg width:       Available width in pixels.

    :arg height:      Available height in pixels.

    :arg canvasAxes:  A sequence of ``(xax, yax)`` indices, one for each
                      bitmap in ``canvasBmps``.

    :arg layout:      Either ``'horizontal'``, ``'vertical'``, or ``'grid'``,
                      describing the canvas layout.

    :returns:         A list of ``(width, height)`` tuples, one for each
                      canvas, each specifying the canvas width and height in
                      pixels.
    """

    bounds = displayCtx.bounds
    axisLens = [bounds.xlen, bounds.ylen, bounds.zlen]

    # Grid layout only makes sense if we're
    # displaying all three canvases
    if layout == 'grid' and len(canvasAxes) <= 2:
        raise ValueError('Grid layout only supports 3 canvases')

    # Distribute the height across canvas heights
    return fsllayout.calcSizes(layout, canvasAxes, axisLens, width, height)
示例#3
0
    def __calcCanvasSizes(self, *a):
        """Sets the size for each displayed :class:`.SliceCanvas`.

        The minimum/maximum size of each canvas is fixed so that they are
        scaled proportionally to each other, thus preserving the aspect ratio.
        The :mod:~fsl.utils.layout` module is used to perform the canvas size
        calculation.
        """

        opts   = self.sceneOpts
        layout = opts.layout

        width, height = self.contentPanel.GetClientSize().Get()

        show     = [opts.showXCanvas,  opts.showYCanvas,  opts.showZCanvas]
        canvases = [self.__xcanvas,    self.__ycanvas,    self.__zcanvas]

        if width == 0 or height == 0:  return
        if len(self.overlayList) == 0: return
        if not any(show):              return

        canvases = [c for (c, s) in zip(canvases, show) if s]

        # Grid layout with 2 or less canvases displayed
        # is identical to horizontal layout
        if layout == 'grid' and len(canvases) <= 2:
            layout = 'horizontal'

        # Grid layout canvas
        # order is YXZ
        if layout == 'grid':
            canvases = [canvases[1], canvases[0], canvases[2]]

        # Distribute the available width/height
        # to each of the displayed canvases -
        # fsleyes_widgets.utils.layout (a.k.a.
        # fsllayout) provides functions to do
        # this for us
        canvasaxes = [(c.opts.xax, c.opts.yax) for c in canvases]
        axisLens   = [self.displayCtx.bounds.xlen,
                      self.displayCtx.bounds.ylen,
                      self.displayCtx.bounds.zlen]

        sizes = fsllayout.calcSizes(layout,
                                    canvasaxes,
                                    axisLens,
                                    width,
                                    height)

        for canvas, size in zip(canvases, sizes):
            canvas.SetMinSize(size)
            canvas.SetMaxSize(size)