Search in sources :

Example 1 with ImageData

use of omero.gateway.model.ImageData in project imagej-omero by imagej.

the class DefaultOMEROService method uploadTable.

@Override
public long uploadTable(final OMEROCredentials credentials, final String name, final Table<?, ?> imageJTable, final long imageID) throws ServerError, PermissionDeniedException, CannotCreateSessionException, ExecutionException, DSOutOfServiceException, DSAccessException {
    final TableData omeroTable = convertOMEROTable(imageJTable);
    long id = -1;
    try (final OMEROSession session = new DefaultOMEROSession(credentials)) {
        // Get image
        final BrowseFacility browseFacility = session.getGateway().getFacility(BrowseFacility.class);
        final ImageData image = browseFacility.getImage(session.getSecurityContext(), imageID);
        // attach table to image
        final TablesFacility tablesFacility = session.getGateway().getFacility(TablesFacility.class);
        final TableData stored = tablesFacility.addTable(session.getSecurityContext(), image, name, omeroTable);
        id = stored.getOriginalFileId();
    }
    return id;
}
Also used : TablesFacility(omero.gateway.facility.TablesFacility) ImageData(omero.gateway.model.ImageData) TableData(omero.gateway.model.TableData) BrowseFacility(omero.gateway.facility.BrowseFacility)

Example 2 with ImageData

use of omero.gateway.model.ImageData in project imagej-omero by imagej.

the class DefaultOMEROSession method createPixels.

@Override
public RawPixelsStorePrx createPixels(final OMEROFormat.Metadata meta) throws ServerError, FormatException {
    // create a new Image which will house the written pixels
    final ImageData newImage = createImage(meta);
    final long imageID = newImage.getId();
    meta.setImageID(imageID);
    // configure the raw pixels store
    final RawPixelsStorePrx store = session.createRawPixelsStore();
    final long pixelsID = newImage.getDefaultPixels().getId();
    store.setPixelsId(pixelsID, false);
    meta.setPixelsID(pixelsID);
    return store;
}
Also used : ImageData(omero.gateway.model.ImageData) RawPixelsStorePrx(omero.api.RawPixelsStorePrx)

Example 3 with ImageData

use of omero.gateway.model.ImageData in project imagej-omero by imagej.

the class ModuleAdapter method createOutputLinks.

/**
 * Attempts to attach the outputs to the appropriate items.
 */
private void createOutputLinks(final HashMap<String, Object> inputMap, final HashMap<String, TableData> tables) throws ExecutionException, ServerError, DSOutOfServiceException, DSAccessException {
    final ExperimenterData user = createUser();
    final BrowseFacility browse = gateway.getFacility(BrowseFacility.class);
    final DataManagerFacility dm = gateway.getFacility(DataManagerFacility.class);
    final SecurityContext ctx = new SecurityContext(user.getGroupId());
    final List<ImageData> outImages = getOutputImages(user.getId(), browse, ctx);
    final List<ImageData> inputImages = getInputImages(inputMap, browse, ctx);
    if (!outImages.isEmpty()) {
        attachImagesToDatasets(inputImages, outImages, dm, browse, ctx);
    }
    if (!tables.isEmpty()) {
        if (inputImages.isEmpty())
            throw new IllegalArgumentException("Input image(s) required to upload table to OMERO");
        attachTablesToImages(inputImages, tables, ctx, dm);
    }
}
Also used : ExperimenterData(omero.gateway.model.ExperimenterData) ImageData(omero.gateway.model.ImageData) SecurityContext(omero.gateway.SecurityContext) DataManagerFacility(omero.gateway.facility.DataManagerFacility) BrowseFacility(omero.gateway.facility.BrowseFacility)

Example 4 with ImageData

use of omero.gateway.model.ImageData in project imagej-omero by imagej.

the class ModuleAdapter method attachImagesToDatasets.

/**
 * Attaches the given output images to the datasets of the given input images.
 */
private void attachImagesToDatasets(final List<ImageData> inputImages, final List<ImageData> outputImages, final DataManagerFacility dm, final BrowseFacility browse, SecurityContext ctx) throws DSOutOfServiceException, DSAccessException {
    final HashMap<Long, DatasetData> datasets = new HashMap<>();
    // Get all datasets related to the input images
    // FIXME: ImageData has a getDatasets() method, but it is null since the
    // underlying ImageI is unloaded.
    final Collection<DatasetData> allDatasets = browse.getDatasets(ctx);
    for (DatasetData d : allDatasets) {
        Collection<ImageData> allImages = browse.getImagesForDatasets(ctx, Collections.singleton(d.getId()));
        for (ImageData image : allImages) {
            for (ImageData input : inputImages) {
                if (input.getId() == image.getId())
                    datasets.put(d.getId(), d);
            }
        }
    }
    // attach all output images to these datasets
    if (!datasets.isEmpty()) {
        for (Long id : datasets.keySet()) dm.addImagesToDataset(ctx, outputImages, datasets.get(id));
    }
}
Also used : DatasetData(omero.gateway.model.DatasetData) HashMap(java.util.HashMap) ImageData(omero.gateway.model.ImageData) RLong(omero.RLong)

Example 5 with ImageData

use of omero.gateway.model.ImageData in project imagej-omero by imagej.

the class DefaultOMEROSession method createImage.

// -- Helper methods --
private ImageData createImage(final OMEROFormat.Metadata meta) throws ServerError, FormatException {
    // create a new Image
    final ImageMetadata imageMeta = meta.get(0);
    final int xLen = axisLength(imageMeta, Axes.X);
    final int yLen = axisLength(imageMeta, Axes.Y);
    final int zLen = axisLength(imageMeta, Axes.Z);
    final int tLen = axisLength(imageMeta, Axes.TIME);
    final int cLen = axisLength(imageMeta, Axes.CHANNEL);
    final int sizeX = xLen == 0 ? 1 : xLen;
    final int sizeY = yLen == 0 ? 1 : yLen;
    final int sizeZ = zLen == 0 ? 1 : zLen;
    final int sizeT = tLen == 0 ? 1 : tLen;
    final int sizeC = cLen == 0 ? 1 : cLen;
    final List<Integer> channelList = new ArrayList<Integer>(sizeC);
    for (int c = 0; c < sizeC; c++) {
        // TODO: Populate actual emission wavelengths?
        channelList.add(c);
    }
    final int pixelType = imageMeta.getPixelType();
    final PixelsType pixelsType = getPixelsType(pixelType);
    final String name = meta.getName();
    final String description = meta.getName();
    final RLong id = session.getPixelsService().createImage(sizeX, sizeY, sizeZ, sizeT, channelList, pixelsType, name, description);
    if (id == null)
        throw new FormatException("Cannot create image");
    // retrieve the newly created Image
    final List<Image> results = session.getContainerService().getImages(Image.class.getName(), Arrays.asList(id.getValue()), null);
    return new ImageData(results.get(0));
}
Also used : ImageMetadata(io.scif.ImageMetadata) ImageData(omero.gateway.model.ImageData) ArrayList(java.util.ArrayList) PixelsType(omero.model.PixelsType) RLong(omero.RLong) Image(omero.model.Image) FormatException(io.scif.FormatException)

Aggregations

ImageData (omero.gateway.model.ImageData)9 RLong (omero.RLong)4 ArrayList (java.util.ArrayList)3 TableData (omero.gateway.model.TableData)3 HashMap (java.util.HashMap)2 BrowseFacility (omero.gateway.facility.BrowseFacility)2 FormatException (io.scif.FormatException)1 ImageMetadata (io.scif.ImageMetadata)1 Expectations (mockit.Expectations)1 Dataset (net.imagej.Dataset)1 GenericTable (net.imagej.table.GenericTable)1 RawPixelsStorePrx (omero.api.RawPixelsStorePrx)1 SecurityContext (omero.gateway.SecurityContext)1 DataManagerFacility (omero.gateway.facility.DataManagerFacility)1 TablesFacility (omero.gateway.facility.TablesFacility)1 DataObject (omero.gateway.model.DataObject)1 DatasetData (omero.gateway.model.DatasetData)1 ExperimenterData (omero.gateway.model.ExperimenterData)1 TableDataColumn (omero.gateway.model.TableDataColumn)1 Image (omero.model.Image)1