Search in sources :

Example 56 with Length

use of ome.units.quantity.Length in project bioformats by openmicroscopy.

the class ROIHandler method storeText.

/**
 * Stores the text ROI into the metadata stored.
 *
 * @param roi The roi to convert.
 * @param store The store to handle.
 * @param roiNum The roi number
 * @param shape The index of the shape.
 * @param c The selected channel.
 * @param z The selected slice.
 * @param t The selected timepoint.
 */
private static void storeText(TextRoi roi, MetadataStore store, int roiNum, int shape, int c, int z, int t) {
    store.setLabelX(roi.getPolygon().getBounds().getX(), roiNum, shape);
    store.setLabelY(roi.getPolygon().getBounds().getY(), roiNum, shape);
    store.setLabelText(roi.getText().trim(), roiNum, shape);
    store.setLabelFontSize(new Length(roi.getCurrentFont().getSize(), UNITS.PIXEL), roiNum, shape);
    if (c >= 0) {
        store.setLabelTheC(unwrap(c), roiNum, shape);
    }
    if (z >= 0) {
        store.setLabelTheZ(unwrap(z), roiNum, shape);
    }
    if (t >= 0) {
        store.setLabelTheT(unwrap(t), roiNum, shape);
    }
    if (roi.getStrokeWidth() > 0) {
        store.setLabelStrokeWidth(new Length((roi.getStrokeWidth()), UNITS.PIXEL), roiNum, shape);
    }
    if (roi.getStrokeColor() != null) {
        store.setLabelStrokeColor(toOMExmlColor(roi.getStrokeColor()), roiNum, shape);
    }
    if (roi.getFillColor() != null) {
        store.setLabelFillColor(toOMExmlColor(roi.getFillColor()), roiNum, shape);
    }
}
Also used : Length(ome.units.quantity.Length)

Example 57 with Length

use of ome.units.quantity.Length in project bioformats by openmicroscopy.

the class ROIHandler method storePolygon.

/**
 * Stores the Polygon ROI into the specified metadata store.
 *
 * @param roi The roi to convert.
 * @param store The store to handle.
 * @param roiNum The roi number
 * @param shape The index of the shape.
 * @param c The selected channel.
 * @param z The selected slice.
 * @param t The selected timepoint.
 */
private static void storePolygon(PolygonRoi roi, MetadataStore store, int roiNum, int shape, int c, int z, int t) {
    int[] xCoordinates = roi.getPolygon().xpoints;
    int[] yCoordinates = roi.getPolygon().ypoints;
    String st1 = roi.getTypeAsString();
    String points = "1";
    for (int i = 0; i < xCoordinates.length; i++) {
        if (i == 0) {
            points = (xCoordinates[i] + "," + yCoordinates[i]);
        } else {
            points = (points + " " + xCoordinates[i] + "," + yCoordinates[i]);
        }
    }
    if (st1.matches("Polyline") || st1.matches("Freeline") || st1.matches("Angle")) {
        store.setPolylinePoints(points.toString(), roiNum, shape);
        store.setPolylineText(roi.getName(), roiNum, shape);
        if (c >= 0) {
            store.setPolylineTheC(unwrap(c), roiNum, shape);
        }
        if (z >= 0) {
            store.setPolylineTheZ(unwrap(z), roiNum, shape);
        }
        if (t >= 0) {
            store.setPolylineTheT(unwrap(t), roiNum, shape);
        }
        if (roi.getStrokeWidth() > 0) {
            store.setPolylineStrokeWidth(new Length((roi.getStrokeWidth()), UNITS.PIXEL), roiNum, shape);
        }
        if (roi.getStrokeColor() != null) {
            store.setPolylineStrokeColor(toOMExmlColor(roi.getStrokeColor()), roiNum, shape);
        }
        if (roi.getFillColor() != null) {
            store.setPolylineFillColor(toOMExmlColor(roi.getFillColor()), roiNum, shape);
        }
    } else if (st1.matches("Polygon") || st1.matches("Freehand") || st1.matches("Traced")) {
        store.setPolygonPoints(points.toString(), roiNum, shape);
        store.setPolygonText(roi.getName(), roiNum, shape);
        if (c >= 0) {
            store.setPolygonTheC(unwrap(c), roiNum, shape);
        }
        if (z >= 0) {
            store.setPolygonTheZ(unwrap(z), roiNum, shape);
        }
        if (t >= 0) {
            store.setPolygonTheT(unwrap(t), roiNum, shape);
        }
        if (roi.getStrokeWidth() > 0) {
            store.setPolygonStrokeWidth(new Length((roi.getStrokeWidth()), UNITS.PIXEL), roiNum, shape);
        }
        if (roi.getStrokeColor() != null) {
            store.setPolygonStrokeColor(toOMExmlColor(roi.getStrokeColor()), roiNum, shape);
        }
        if (roi.getFillColor() != null) {
            store.setPolygonFillColor(toOMExmlColor(roi.getFillColor()), roiNum, shape);
        }
    }
}
Also used : Length(ome.units.quantity.Length) Point(ome.xml.model.Point)

Example 58 with Length

use of ome.units.quantity.Length in project bioformats by openmicroscopy.

the class ROIHandler method storeOval.

/**
 * Stores the Oval ROI into the specified metadata store.
 *
 * @param roi The roi to convert.
 * @param store The store to handle.
 * @param roiNum The roi number
 * @param shape The index of the shape.
 * @param c The selected channel.
 * @param z The selected slice.
 * @param t The selected timepoint.
 */
private static void storeOval(OvalRoi roi, MetadataStore store, int roiNum, int shape, int c, int z, int t) {
    Rectangle vnRectBounds = roi.getPolygon().getBounds();
    int x = vnRectBounds.x;
    int y = vnRectBounds.y;
    double rx = vnRectBounds.getWidth();
    double ry = vnRectBounds.getHeight();
    store.setEllipseX(((double) x + rx / 2), roiNum, shape);
    store.setEllipseY(((double) y + ry / 2), roiNum, shape);
    store.setEllipseRadiusX((double) rx / 2, roiNum, shape);
    store.setEllipseRadiusY((double) ry / 2, roiNum, shape);
    store.setEllipseText(roi.getName(), roiNum, shape);
    if (c >= 0) {
        store.setEllipseTheC(unwrap(c), roiNum, shape);
    }
    if (z >= 0) {
        store.setEllipseTheZ(unwrap(z), roiNum, shape);
    }
    if (t >= 0) {
        store.setEllipseTheT(unwrap(t), roiNum, shape);
    }
    if (roi.getStrokeWidth() > 0) {
        store.setEllipseStrokeWidth(new Length((roi.getStrokeWidth()), UNITS.PIXEL), roiNum, shape);
    }
    if (roi.getStrokeColor() != null) {
        store.setEllipseStrokeColor(toOMExmlColor(roi.getStrokeColor()), roiNum, shape);
    }
    if (roi.getFillColor() != null) {
        store.setEllipseFillColor(toOMExmlColor(roi.getFillColor()), roiNum, shape);
    }
}
Also used : Length(ome.units.quantity.Length) Rectangle(java.awt.Rectangle) Point(ome.xml.model.Point)

Example 59 with Length

use of ome.units.quantity.Length in project bioformats by openmicroscopy.

the class FormatTools method getPhysicalSize.

public static Length getPhysicalSize(Double value, String unit) {
    if (value != null && value != 0 && value < Double.POSITIVE_INFINITY) {
        if (unit != null) {
            try {
                UnitsLength ul = UnitsLength.fromString(unit);
                int ordinal = ul.ordinal();
                Length returnLength = UnitsLength.create(value, ul);
                if (returnLength.value().doubleValue() > Constants.EPSILON && returnLength.value().doubleValue() < Double.POSITIVE_INFINITY) {
                    return returnLength;
                }
                // Using UnitsLength.values().length - 2 as a boundary so as not to include Pixel and Reference Frame as convertible units
                while (returnLength.value().doubleValue() < Constants.EPSILON && ordinal < (UnitsLength.values().length - 3)) {
                    ordinal++;
                    ul = UnitsLength.values()[ordinal];
                    Length tempLength = UnitsLength.create(0, ul);
                    returnLength = UnitsLength.create(returnLength.value(tempLength.unit()), ul);
                }
                if (returnLength.value().doubleValue() > Constants.EPSILON && returnLength.value().doubleValue() < Double.POSITIVE_INFINITY) {
                    return returnLength;
                } else {
                    LOGGER.debug("Expected positive value for PhysicalSize; got {}", value);
                    return null;
                }
            } catch (EnumerationException e) {
            }
        }
        return new Length(value, UNITS.MICROMETER);
    }
    LOGGER.debug("Expected positive value for PhysicalSize; got {}", value);
    return null;
}
Also used : UnitsLength(ome.xml.model.enums.UnitsLength) UnitsLength(ome.xml.model.enums.UnitsLength) Length(ome.units.quantity.Length) EnumerationException(ome.xml.model.enums.EnumerationException)

Example 60 with Length

use of ome.units.quantity.Length in project bioformats by openmicroscopy.

the class LociFunctions method getPixelsPhysicalSizeX.

public void getPixelsPhysicalSizeX(Double[] sizeX) {
    int imageIndex = r.getSeries();
    MetadataRetrieve retrieve = (MetadataRetrieve) r.getMetadataStore();
    Length x = retrieve.getPixelsPhysicalSizeX(imageIndex);
    if (x != null) {
        sizeX[0] = x.value(UNITS.MICROMETER).doubleValue();
    }
    if (sizeX[0] == null)
        sizeX[0] = new Double(Double.NaN);
}
Also used : Length(ome.units.quantity.Length) MetadataRetrieve(loci.formats.meta.MetadataRetrieve)

Aggregations

Length (ome.units.quantity.Length)154 MetadataStore (loci.formats.meta.MetadataStore)82 CoreMetadata (loci.formats.CoreMetadata)74 Timestamp (ome.xml.model.primitives.Timestamp)52 RandomAccessInputStream (loci.common.RandomAccessInputStream)48 Time (ome.units.quantity.Time)46 FormatException (loci.formats.FormatException)39 Location (loci.common.Location)34 ArrayList (java.util.ArrayList)29 IMetadata (loci.formats.meta.IMetadata)13 NonNegativeInteger (ome.xml.model.primitives.NonNegativeInteger)13 ServiceFactory (loci.common.services.ServiceFactory)12 IOException (java.io.IOException)11 DependencyException (loci.common.services.DependencyException)11 PositiveInteger (ome.xml.model.primitives.PositiveInteger)11 MetadataRetrieve (loci.formats.meta.MetadataRetrieve)10 ElectricPotential (ome.units.quantity.ElectricPotential)9 Test (org.testng.annotations.Test)9 Element (org.w3c.dom.Element)9 NodeList (org.w3c.dom.NodeList)9