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);
}
}
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);
}
}
}
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);
}
}
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;
}
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);
}
Aggregations