Scan Tile Tools


To facilitate the creation of Scan Tiles, the Tile feature has tool function interface. The default tool at feature release is a rectangular Draw Tile Exapnse tool which allows the user to draw an initial tTle shape and then create copies of that are spread out in X and Y. Upon applying the tool the system will create Scan Tiles at those locations. See the following Demonstration


Creating A Tool


Users can also create their own tools. Tools are class objects and should inherit from the tools parent class. Tools must have an activate, deactivate, and apply function and should take a handle to the Tile View as a constructor argument in order to understand the spatial area in which the tool is active. How the tools determine how to create Tiles if tool specific. Once the appropriate data is configured they should call a Tile Generator function to create and add Tiles to the Tile Manager which will then populate them in the view.

The workflow for this is that a tool is responsible for collecting information on how the Tiles should be drawn, while the Tile Generator function is responsible for parsing that raw information into Tile object constructor arguments and then constructing, and returning, the Tile objects. For example, the default tool collects information on the number of tiles, their sizes, and their positions based on a grid around the initial drawn tile area, and then sends that data to the generator to spit out a number of Tile objects. However, a another tool might only collect information on the initial draw area and then send that area to a different generator which might parse that area into a grid automatically.

Tile Generator functions should be able to operate on either ScanImage ROI data objects or on a set of parameters which be used either directly or indirectly to ascertain the necessary constructor arguments for the Tile object. These include, at a minimum, the following:

  • tileCenter [X Y]

  • tileSize [X Y]

  • zPos as a discrete value

  • channel(s)

  • X-Y Resolutions as [X Y]

  • ImageData (optional). ImageData can be empty or absent as is the case with Scan Tiles.

Further information on Tile Generators can be found here.

Tools and Generators will likely require access to the Coordinate Systems in order to properly transform spatial data. Access can come through the Tile View itself, as input argument, or by using the new Resource Store. Tile tools should be added to +scanimage+components+tileTools whereas Generator functions should be added to +scanimage+components+tileTools+tileGeneratorFcns

hCoordinateSystems = hTileView.hSI.hCoordinateSystems;

% OR

hResourceStore = dabs.resources.ResourceStore();
hSI = hResourceStore.filterByClass('scanimage.SI');
hSI = hSI{1};
hCoordinateSystems = hSI.hCoordinateSystems;

Here is an overview of the default Tile Expanse Tool (pseudo-code only - see the tool file in ScanImage).

% Inherits from the tileTool class - used to fill in available tools
classdef tileExpanseTool < scanimage.components.tileTools.tileTool

% Has an activate and deactivate function

function activateTool(obj)
    % Makes it so when you click the view you start drawing an outline of the initial tile
    obj.hAxes.ButtonDownFcn = @obj.drawTileArea;
    % Turns the pointer into a cross hair
    obj.hFig.Pointer = 'crosshair';
    % Disabels clickability of other elements which might impede drawing
    obj.disableTileSurfHitTest();
end

function deactivateTool(obj)
    % Restores pointer
    obj.hFig.Pointer = 'arrow';
    % Restores normal pan and scroll functions
    set(obj.hFig,'WindowButtonMotionFcn',[],'WindowButtonUpFcn',[]);
    set(obj.hAxes, 'ButtonDownFcn', []);
    % Restores clickability of elements
    obj.enableTileSurfHitTest();
end

....

% This is the drawing function - your tool may do something else
% This function is set ass the call back for click and drag operations on
% the Tile View in the activate function. It uses persisten variables to keep
% track of the drawn area.
function drawTileArea(obj, stop, varargin)

    % Gets the pointer location - made persistent and only updated in certain cases to keep track
    % of movement. This is only done on initial click. Otherwise a new pointer location is grabbed
    % and used to compute area.
    hAx = obj.hTileView.hFovAxes;
    ptrLocation =  hAx.CurrentPoint(1, 1:2);

end


....


% Apply function takes tool parameters and makes tiles
function apply(obj, tileParams)
    tiles = scanimage.components.tiles.tile.empty(0,1);

    .
    .
    .

    % Generate the Tile objects
    for i=1:numTilesAsDecidedByTool
        tiles(i) = obj.makeScanTile(tileParamsBrokenOutAndSorted)
    end

    .
    .
    .

    % Add the tile objects via the manager
    obj.hTileView.hModel.hTileManager.addScanTile(tiles);
end

% This function makes tiles using the generator
function tile = makeScanTile(obj, hSI, tileCenter, tileCornerPts, zPos, channel, XYRes)
    hCoordinateSystems = hSI.hCoordinateSystems;
    sizeX = tileCornerPts(2,1) - tileCornerPts(1,1);
    sizeY = tileCornerPts(4,2) - tileCornerPts(1,2);
    tileSize = [sizeX sizeY];
    imageData = [];

    tileParams = {tileCenter, tileSize, zPos, channel, XYRes, imageData};

    tile = scanimage.components.tileTools.tileGeneratorFcns.defaultTileGenerator(hCoordinateSystems, false, tileParams, []);
end