Search in sources :

Example 1 with MaskPredicate

use of net.imglib2.roi.MaskPredicate in project imagej-omero by imagej.

the class DefaultOMEROService method toOMERO.

@Override
public Object toOMERO(final omero.client client, final Object value) throws omero.ServerError, IOException, ExecutionException, DSOutOfServiceException, DSAccessException, NumberFormatException, URISyntaxException {
    if (value == null)
        return null;
    if (value instanceof Dataset) {
        // upload image to OMERO, returning the resultant image ID
        final Dataset d = (Dataset) value;
        final long imageID = uploadImage(client, d);
        // TODO: upload or update?
        if (d.getProperties().get("rois") != null)
            uploadROIs(createCredentials(client), (TreeNode<?>) d.getProperties().get("rois"), imageID);
        // TODO: Modify tables to implement Named??
        if (d.getProperties().get("tables") != null) {
            @SuppressWarnings("unchecked") final List<Table<?, ?>> tables = (List<Table<?, ?>>) d.getProperties().get("tables");
            final OMEROLocation cred = createCredentials(client);
            for (final Table<?, ?> table : tables) uploadTable(cred, d.getName() + "-table", table, imageID);
        }
        return toOMERO(client, imageID);
    }
    if (convertService.supports(value, Dataset.class))
        return toOMERO(client, convertService.convert(value, Dataset.class));
    if (value instanceof DatasetView) {
        final DatasetView datasetView = (DatasetView) value;
        // TODO: Verify whether any view-specific metadata can be preserved.
        return toOMERO(client, datasetView.getData());
    }
    if (value instanceof ImageDisplay) {
        final ImageDisplay imageDisplay = (ImageDisplay) value;
        // TODO: Support more aspects of image displays; e.g., multiple datasets.
        return toOMERO(client, imageDisplayService.getActiveDataset(imageDisplay));
    }
    if (value instanceof Table)
        return convertOMEROTable((Table<?, ?>) value);
    if (value instanceof TableDisplay)
        return toOMERO(client, ((TableDisplay) value).get(0));
    if (convertService.supports(value, Table.class))
        return toOMERO(client, convertService.convert(value, Table.class));
    if (value instanceof TreeNode) {
        return convertOMEROROI((TreeNode<?>) value, null);
    }
    if (value instanceof MaskPredicate) {
        final Object o = toOMERO(client, new DefaultTreeNode<>(value, null));
        return ((List<?>) o).get(0);
    }
    if (convertService.supports(value, TreeNode.class))
        return toOMERO(client, convertService.convert(value, TreeNode.class));
    if (convertService.supports(value, MaskPredicate.class))
        return toOMERO(client, convertService.convert(value, MaskPredicate.class));
    return toOMERO(value);
}
Also used : Table(org.scijava.table.Table) GenericTable(org.scijava.table.GenericTable) DatasetView(net.imagej.display.DatasetView) Dataset(net.imagej.Dataset) MaskPredicate(net.imglib2.roi.MaskPredicate) DefaultTreeNode(org.scijava.util.DefaultTreeNode) TreeNode(org.scijava.util.TreeNode) TableDisplay(org.scijava.table.TableDisplay) List(java.util.List) ArrayList(java.util.ArrayList) DataObject(omero.gateway.model.DataObject) ImageDisplay(net.imagej.display.ImageDisplay)

Example 2 with MaskPredicate

use of net.imglib2.roi.MaskPredicate in project imagej-omero by imagej.

the class DefaultOMEROService method convertOMEROROI.

@Override
public List<ROIData> convertOMEROROI(final TreeNode<?> dataNodeRois, final Interval interval) {
    final List<ROIData> omeroROIs = new ArrayList<>();
    final List<TreeNode<?>> roiTreeNodes = collectROITreeNodes(dataNodeRois);
    for (final TreeNode<?> dn : roiTreeNodes) {
        ROIData oR;
        // interval if non-null
        if (!(dn.data() instanceof Interval) && !(dn.data() instanceof RealInterval) && dn.data() instanceof MaskPredicate && interval != null)
            oR = convertService.convert(interval((MaskPredicate<?>) dn.data(), interval), ROIData.class);
        else
            // else convert directly
            oR = convertService.convert(dn, ROIData.class);
        if (oR == null)
            throw new IllegalArgumentException("Unsupported type: " + dn.data().getClass());
        omeroROIs.add(oR);
    }
    return omeroROIs;
}
Also used : ROIData(omero.gateway.model.ROIData) MaskPredicate(net.imglib2.roi.MaskPredicate) DefaultTreeNode(org.scijava.util.DefaultTreeNode) TreeNode(org.scijava.util.TreeNode) ArrayList(java.util.ArrayList) RealInterval(net.imglib2.RealInterval) RealInterval(net.imglib2.RealInterval) FinalInterval(net.imglib2.FinalInterval) Interval(net.imglib2.Interval) RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval)

Example 3 with MaskPredicate

use of net.imglib2.roi.MaskPredicate in project imagej-omero by imagej.

the class AbstractTreeNodeToROIData method convert.

@Override
@SuppressWarnings("unchecked")
public <T> T convert(final Object src, final Class<T> dest) {
    if (src == null || dest == null)
        throw new NullPointerException();
    if (!getInputType().isInstance(src)) {
        throw new IllegalArgumentException("Expected: " + getInputType().getSimpleName() + " Received: " + src.getClass().getSimpleName());
    }
    if (!dest.isAssignableFrom(getOutputType())) {
        throw new IllegalArgumentException("Expected: " + getOutputType().getSimpleName() + " Received: " + dest.getSimpleName());
    }
    MaskPredicate<?> mp = null;
    final ROIData r = new ROIData();
    final ShapeData s = convert.convert(((TreeNode<?>) src).data(), ShapeData.class);
    if (src instanceof IntervalView) {
        final RandomAccessible<?> ra = ((IntervalView<?>) src).getSource();
        if (ra instanceof RandomAccessibleOnRealRandomAccessible) {
            final RealRandomAccessible<?> rra = ((RandomAccessibleOnRealRandomAccessible<?>) ra).getSource();
            mp = convert.convert(rra, MaskPredicate.class);
        } else
            mp = convert.convert(ra, MaskPredicate.class);
    }
    if (((TreeNode<?>) src).data() instanceof MaskPredicate)
        mp = (MaskPredicate<?>) ((TreeNode<?>) src).data();
    if (omero.getROIMapping(mp) != null) {
        final ROIData prev = omero.getROIMapping(mp);
        r.setId(prev.getId());
        // Assume there's only one shape, since only ROIData with one ShapeData is
        // equivalent to MaskPredicate
        s.setId(prev.getIterator().next().iterator().next().getId());
    }
    r.addShapeData(s);
    return (T) r;
}
Also used : IntervalView(net.imglib2.view.IntervalView) ROIData(omero.gateway.model.ROIData) MaskPredicate(net.imglib2.roi.MaskPredicate) RandomAccessibleOnRealRandomAccessible(net.imglib2.view.RandomAccessibleOnRealRandomAccessible) ShapeData(omero.gateway.model.ShapeData)

Aggregations

MaskPredicate (net.imglib2.roi.MaskPredicate)3 ArrayList (java.util.ArrayList)2 ROIData (omero.gateway.model.ROIData)2 DefaultTreeNode (org.scijava.util.DefaultTreeNode)2 TreeNode (org.scijava.util.TreeNode)2 List (java.util.List)1 Dataset (net.imagej.Dataset)1 DatasetView (net.imagej.display.DatasetView)1 ImageDisplay (net.imagej.display.ImageDisplay)1 FinalInterval (net.imglib2.FinalInterval)1 Interval (net.imglib2.Interval)1 RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)1 RealInterval (net.imglib2.RealInterval)1 IntervalView (net.imglib2.view.IntervalView)1 RandomAccessibleOnRealRandomAccessible (net.imglib2.view.RandomAccessibleOnRealRandomAccessible)1 DataObject (omero.gateway.model.DataObject)1 ShapeData (omero.gateway.model.ShapeData)1 GenericTable (org.scijava.table.GenericTable)1 Table (org.scijava.table.Table)1 TableDisplay (org.scijava.table.TableDisplay)1