Search in sources :

Example 1 with OME

use of ome.xml.model.OME in project bioformats by openmicroscopy.

the class XMLAnnotationTest method setUp.

@BeforeClass
public void setUp() throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder parser = factory.newDocumentBuilder();
    Document document = parser.parse(this.getClass().getResourceAsStream("XMLAnnotationTest.ome"));
    OMEModel model = new OMEModelImpl();
    // Read string XML in as a DOM tree and parse into the object hierarchy
    ome = new OME(document.getDocumentElement(), model);
    model.resolveReferences();
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) OME(ome.xml.model.OME) Document(org.w3c.dom.Document) OMEModel(ome.xml.model.OMEModel) OMEModelImpl(ome.xml.model.OMEModelImpl) BeforeClass(org.testng.annotations.BeforeClass)

Example 2 with OME

use of ome.xml.model.OME in project bioformats by openmicroscopy.

the class GenericExcitationMapTest method testGenericExcitationSourceMapContent.

@Test
public void testGenericExcitationSourceMapContent() throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder parser = factory.newDocumentBuilder();
    Document document = parser.newDocument();
    // Produce a valid OME DOM element hierarchy
    Element root = ome.asXMLElement(document);
    SPWModelMock.postProcess(root, document, false);
    OMEModel model = new OMEModelImpl();
    ome = new OME(document.getDocumentElement(), model);
    model.resolveReferences();
    assertNotNull(ome);
    assertEquals(ome.getImage(0).getPixels().getChannel(0).getLightSourceSettings().getID(), "LightSource:0");
    assertNotNull(ome.getInstrument(0).getLightSource(0));
    GenericExcitationSource geSource = (GenericExcitationSource) ome.getInstrument(0).getLightSource(0);
    List<MapPair> dataMap = geSource.getMap();
    assertEquals(6, dataMap.size());
    assertPair(dataMap, 0, "a", "1");
    assertPair(dataMap, 1, "d", "2");
    assertPair(dataMap, 2, "c", "3");
    assertPair(dataMap, 3, "b", "4");
    assertPair(dataMap, 4, "e", "5");
    assertPair(dataMap, 5, "c", "6");
}
Also used : MapPair(ome.xml.model.MapPair) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) GenericExcitationSource(ome.xml.model.GenericExcitationSource) DocumentBuilder(javax.xml.parsers.DocumentBuilder) OME(ome.xml.model.OME) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) OMEModel(ome.xml.model.OMEModel) OMEModelImpl(ome.xml.model.OMEModelImpl) Test(org.testng.annotations.Test)

Example 3 with OME

use of ome.xml.model.OME in project bioformats by openmicroscopy.

the class GenericExcitationMapTest method testGenericExcitationSourceValid.

@Test
public void testGenericExcitationSourceValid() throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder parser = factory.newDocumentBuilder();
    Document document = parser.newDocument();
    // Produce a valid OME DOM element hierarchy
    Element root = ome.asXMLElement(document);
    SPWModelMock.postProcess(root, document, false);
    OMEModel model = new OMEModelImpl();
    ome = new OME(document.getDocumentElement(), model);
    model.resolveReferences();
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) OME(ome.xml.model.OME) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) OMEModel(ome.xml.model.OMEModel) OMEModelImpl(ome.xml.model.OMEModelImpl) Test(org.testng.annotations.Test)

Example 4 with OME

use of ome.xml.model.OME in project bioformats by openmicroscopy.

the class ImagingEnvironmentMapTest method testGenericExcitationSourceMapContent.

@Test
public void testGenericExcitationSourceMapContent() throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder parser = factory.newDocumentBuilder();
    Document document = parser.newDocument();
    // Produce a valid OME DOM element hierarchy
    Element root = ome.asXMLElement(document);
    SPWModelMock.postProcess(root, document, false);
    OMEModel model = new OMEModelImpl();
    ome = new OME(document.getDocumentElement(), model);
    model.resolveReferences();
    assertNotNull(ome);
    assertEquals(ome.getImage(0).getPixels().getID(), "Pixels:0");
    assertNotNull(ome.getImage(0).getImagingEnvironment());
    ImagingEnvironment imagingEnvironment = ome.getImage(0).getImagingEnvironment();
    List<MapPair> dataMap = imagingEnvironment.getMap();
    assertEquals(6, dataMap.size());
    assertPair(dataMap, 0, "a", "1");
    assertPair(dataMap, 1, "d", "2");
    assertPair(dataMap, 2, "c", "3");
    assertPair(dataMap, 3, "b", "4");
    assertPair(dataMap, 4, "e", "5");
    assertPair(dataMap, 5, "c", "6");
}
Also used : MapPair(ome.xml.model.MapPair) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) OME(ome.xml.model.OME) Element(org.w3c.dom.Element) ImagingEnvironment(ome.xml.model.ImagingEnvironment) Document(org.w3c.dom.Document) OMEModel(ome.xml.model.OMEModel) OMEModelImpl(ome.xml.model.OMEModelImpl) Test(org.testng.annotations.Test)

Example 5 with OME

use of ome.xml.model.OME in project bioformats by openmicroscopy.

the class ROIHandler method openROIs.

/**
 * Opens the rois and converts them into ImageJ Rois.
 *
 * @param retrieve The OMEXML store.
 * @param images The imageJ object.
 * @param isOMERO <code>true</code> if data stored in OMERO,
 *        <code>false</code> otherwise.
 * @param roisMode Determines whether to import Rois to overlay or RoiManager
 */
public static void openROIs(IMetadata retrieve, ImagePlus[] images, boolean isOMERO, String roisMode) {
    if (!(retrieve instanceof OMEXMLMetadata))
        return;
    int nextRoi = 0;
    RoiManager manager = RoiManager.getInstance();
    OME root = (OME) retrieve.getRoot();
    Roi roi;
    Float sw;
    Color sc;
    Color fc;
    int imageCount = images.length;
    for (int imageNum = 0; imageNum < imageCount; imageNum++) {
        int roiCount = root.sizeOfROIList();
        if (roiCount > 0 && manager == null && roisMode.equals(ImporterOptions.ROIS_MODE_MANAGER)) {
            manager = new RoiManager();
        }
        for (int roiNum = 0; roiNum < roiCount; roiNum++) {
            Union shapeSet = root.getROI(roiNum).getUnion();
            int shapeCount = shapeSet.sizeOfShapeList();
            for (int shape = 0; shape < shapeCount; shape++) {
                Shape shapeObject = shapeSet.getShape(shape);
                roi = null;
                sw = null;
                sc = null;
                fc = null;
                int c = 0;
                int z = 0;
                int t = 0;
                if (shapeObject instanceof Ellipse) {
                    Ellipse ellipse = (Ellipse) shapeObject;
                    int cx = ellipse.getX().intValue();
                    int cy = ellipse.getY().intValue();
                    int rx = ellipse.getRadiusX().intValue();
                    int ry = ellipse.getRadiusY().intValue();
                    roi = new OvalRoi(cx - rx, cy - ry, rx * 2, ry * 2);
                    if (ellipse.getStrokeColor() != null) {
                        ome.xml.model.primitives.Color StrokeColor = ellipse.getStrokeColor();
                        sc = new Color(StrokeColor.getRed(), StrokeColor.getGreen(), StrokeColor.getBlue(), StrokeColor.getAlpha());
                        if (isOMERO) {
                            sc = new Color(StrokeColor.getGreen(), StrokeColor.getBlue(), StrokeColor.getAlpha(), StrokeColor.getRed());
                        }
                    }
                    if (ellipse.getFillColor() != null) {
                        ome.xml.model.primitives.Color FillColor = ellipse.getFillColor();
                        fc = new Color(FillColor.getRed(), FillColor.getGreen(), FillColor.getBlue(), FillColor.getAlpha());
                        if (isOMERO) {
                            fc = new Color(FillColor.getGreen(), FillColor.getBlue(), FillColor.getAlpha(), FillColor.getRed());
                        }
                    }
                    if (ellipse.getStrokeWidth() != null) {
                        sw = ellipse.getStrokeWidth().value().floatValue();
                    }
                } else if (shapeObject instanceof ome.xml.model.Line) {
                    ome.xml.model.Line line = (ome.xml.model.Line) shapeObject;
                    int x1 = line.getX1().intValue();
                    int x2 = line.getX2().intValue();
                    int y1 = line.getY1().intValue();
                    int y2 = line.getY2().intValue();
                    roi = new Line(x1, y1, x2, y2);
                    if (line.getStrokeColor() != null) {
                        ome.xml.model.primitives.Color StrokeColor = line.getStrokeColor();
                        sc = new Color(StrokeColor.getRed(), StrokeColor.getGreen(), StrokeColor.getBlue(), StrokeColor.getAlpha());
                        if (isOMERO) {
                            sc = new Color(StrokeColor.getGreen(), StrokeColor.getBlue(), StrokeColor.getAlpha(), StrokeColor.getRed());
                        }
                    }
                    if (line.getFillColor() != null) {
                        ome.xml.model.primitives.Color FillColor = line.getFillColor();
                        fc = new Color(FillColor.getRed(), FillColor.getGreen(), FillColor.getBlue(), FillColor.getAlpha());
                        if (isOMERO) {
                            fc = new Color(FillColor.getGreen(), FillColor.getBlue(), FillColor.getAlpha(), FillColor.getRed());
                        }
                    }
                    if (line.getStrokeWidth() != null) {
                        sw = line.getStrokeWidth().value().floatValue();
                    }
                } else if (shapeObject instanceof Point) {
                    Point point = (Point) shapeObject;
                    int x = point.getX().intValue();
                    int y = point.getY().intValue();
                    roi = new PointRoi(x, y);
                    if (point.getStrokeColor() != null) {
                        ome.xml.model.primitives.Color StrokeColor = point.getStrokeColor();
                        sc = new Color(StrokeColor.getRed(), StrokeColor.getGreen(), StrokeColor.getBlue(), StrokeColor.getAlpha());
                        if (isOMERO) {
                            sc = new Color(StrokeColor.getGreen(), StrokeColor.getBlue(), StrokeColor.getAlpha(), StrokeColor.getRed());
                        }
                    }
                    if (point.getFillColor() != null) {
                        ome.xml.model.primitives.Color FillColor = point.getFillColor();
                        fc = new Color(FillColor.getRed(), FillColor.getGreen(), FillColor.getBlue(), FillColor.getAlpha());
                        if (isOMERO) {
                            fc = new Color(FillColor.getGreen(), FillColor.getBlue(), FillColor.getAlpha(), FillColor.getRed());
                        }
                    }
                    if (point.getStrokeWidth() != null) {
                        sw = point.getStrokeWidth().value().floatValue();
                    }
                } else if (shapeObject instanceof Polyline) {
                    Polyline polyline = (Polyline) shapeObject;
                    String points = polyline.getPoints();
                    int[][] coordinates = parsePoints(points);
                    roi = new PolygonRoi(coordinates[0], coordinates[1], coordinates[0].length, Roi.POLYLINE);
                    if (polyline.getStrokeColor() != null) {
                        ome.xml.model.primitives.Color StrokeColor = polyline.getStrokeColor();
                        sc = new Color(StrokeColor.getRed(), StrokeColor.getGreen(), StrokeColor.getBlue(), StrokeColor.getAlpha());
                        if (isOMERO) {
                            sc = new Color(StrokeColor.getGreen(), StrokeColor.getBlue(), StrokeColor.getAlpha(), StrokeColor.getRed());
                        }
                    }
                    if (polyline.getFillColor() != null) {
                        ome.xml.model.primitives.Color FillColor = polyline.getFillColor();
                        fc = new Color(FillColor.getRed(), FillColor.getGreen(), FillColor.getBlue(), FillColor.getAlpha());
                        if (isOMERO) {
                            fc = new Color(FillColor.getGreen(), FillColor.getBlue(), FillColor.getAlpha(), FillColor.getRed());
                        }
                    }
                    if (polyline.getStrokeWidth() != null) {
                        sw = polyline.getStrokeWidth().value().floatValue();
                    }
                } else if (shapeObject instanceof Polygon) {
                    Polygon polygon = (Polygon) shapeObject;
                    String points = polygon.getPoints();
                    int[][] coordinates = parsePoints(points);
                    roi = new PolygonRoi(coordinates[0], coordinates[1], coordinates[0].length, Roi.POLYGON);
                    if (polygon.getStrokeColor() != null) {
                        ome.xml.model.primitives.Color StrokeColor = polygon.getStrokeColor();
                        sc = new Color(StrokeColor.getRed(), StrokeColor.getGreen(), StrokeColor.getBlue(), StrokeColor.getAlpha());
                        if (isOMERO) {
                            sc = new Color(StrokeColor.getGreen(), StrokeColor.getBlue(), StrokeColor.getAlpha(), StrokeColor.getRed());
                        }
                    }
                    if (polygon.getFillColor() != null) {
                        ome.xml.model.primitives.Color FillColor = polygon.getFillColor();
                        fc = new Color(FillColor.getRed(), FillColor.getGreen(), FillColor.getBlue(), FillColor.getAlpha());
                        if (isOMERO) {
                            fc = new Color(FillColor.getGreen(), FillColor.getBlue(), FillColor.getAlpha(), FillColor.getRed());
                        }
                    }
                    if (polygon.getStrokeWidth() != null) {
                        sw = polygon.getStrokeWidth().value().floatValue();
                    }
                } else if (shapeObject instanceof ome.xml.model.Label) {
                    // add support for TextROI's
                    ome.xml.model.Label label = (ome.xml.model.Label) shapeObject;
                    double x = label.getX().doubleValue();
                    double y = label.getY().doubleValue();
                    String labelText = label.getText();
                    int size = label.getFontSize().value().intValue();
                    Font font = new Font(labelText, Font.PLAIN, size);
                    roi = new TextRoi((int) x, (int) y, labelText, font);
                    if (label.getStrokeColor() != null) {
                        ome.xml.model.primitives.Color StrokeColor = label.getStrokeColor();
                        sc = new Color(StrokeColor.getRed(), StrokeColor.getGreen(), StrokeColor.getBlue(), StrokeColor.getAlpha());
                        if (isOMERO) {
                            sc = new Color(StrokeColor.getGreen(), StrokeColor.getBlue(), StrokeColor.getAlpha(), StrokeColor.getRed());
                        }
                    }
                    if (label.getFillColor() != null) {
                        ome.xml.model.primitives.Color FillColor = label.getFillColor();
                        fc = new Color(FillColor.getRed(), FillColor.getGreen(), FillColor.getBlue(), FillColor.getAlpha());
                        if (isOMERO) {
                            fc = new Color(FillColor.getGreen(), FillColor.getBlue(), FillColor.getAlpha(), FillColor.getRed());
                        }
                    }
                    if (label.getStrokeWidth() != null) {
                        sw = label.getStrokeWidth().value().floatValue();
                    }
                } else if (shapeObject instanceof ome.xml.model.Rectangle) {
                    ome.xml.model.Rectangle rectangle = (ome.xml.model.Rectangle) shapeObject;
                    int x = rectangle.getX().intValue();
                    int y = rectangle.getY().intValue();
                    int w = rectangle.getWidth().intValue();
                    int h = rectangle.getHeight().intValue();
                    roi = new Roi(x, y, w, h);
                    if (rectangle.getStrokeColor() != null) {
                        ome.xml.model.primitives.Color StrokeColor = rectangle.getStrokeColor();
                        sc = new Color(StrokeColor.getRed(), StrokeColor.getGreen(), StrokeColor.getBlue(), StrokeColor.getAlpha());
                        if (isOMERO) {
                            sc = new Color(StrokeColor.getGreen(), StrokeColor.getBlue(), StrokeColor.getAlpha(), StrokeColor.getRed());
                        }
                    }
                    if (rectangle.getFillColor() != null) {
                        ome.xml.model.primitives.Color FillColor = rectangle.getFillColor();
                        fc = new Color(FillColor.getRed(), FillColor.getGreen(), FillColor.getBlue(), FillColor.getAlpha());
                        if (isOMERO) {
                            fc = new Color(FillColor.getGreen(), FillColor.getBlue(), FillColor.getAlpha(), FillColor.getRed());
                        }
                    }
                    if (rectangle.getStrokeWidth() != null) {
                        sw = rectangle.getStrokeWidth().value().floatValue();
                    }
                }
                if (roi != null) {
                    String roiLabel = shapeObject.getText();
                    if (roiLabel == null) {
                        roiLabel = shapeObject.getID();
                    }
                    roi.setName(roiLabel);
                    if (Prefs.showAllSliceOnly) {
                        if (shapeObject.getTheC() != null) {
                            c = shapeObject.getTheC().getValue();
                        }
                        if (shapeObject.getTheZ() != null) {
                            z = shapeObject.getTheZ().getValue();
                        }
                        if (shapeObject.getTheT() != null) {
                            t = shapeObject.getTheT().getValue();
                        }
                        // ImageJ expects 1-based indexing, opposed to
                        // 0-based indexing in OME
                        // Roi positions differ between hyperstacks and normal stacks
                        ImagePlus imp = images[imageNum];
                        if (imp.getNChannels() > 1) {
                            c++;
                        }
                        if (imp.getNSlices() > 1) {
                            z++;
                        }
                        if (imp.getNFrames() > 1) {
                            t++;
                        }
                        if (c == 0)
                            c = 1;
                        if (t == 0)
                            t = 1;
                        if (z == 0)
                            z = 1;
                        if (imp.getNChannels() == 1 && imp.getNSlices() == 1) {
                            roi.setPosition(t);
                        } else if (imp.getNChannels() == 1 && imp.getNFrames() == 1) {
                            roi.setPosition(z);
                        } else if (imp.getNSlices() == 1 && imp.getNFrames() == 1) {
                            roi.setPosition(c);
                        } else if (imp.isHyperStack()) {
                            roi.setPosition(c, z, t);
                        }
                    }
                    if (sw == null) {
                        roi.setStrokeWidth((float) 1);
                    }
                    if (sw != null) {
                        if (sw == 0) {
                            sw = (float) 1;
                        }
                        roi.setStrokeWidth(sw);
                    }
                    if (sc != null) {
                        roi.setStrokeColor(sc);
                    }
                    if (roisMode.equals(ImporterOptions.ROIS_MODE_MANAGER)) {
                        manager.add(images[imageNum], roi, nextRoi++);
                    } else if (roisMode.equals(ImporterOptions.ROIS_MODE_OVERLAY)) {
                        Overlay overlay = images[imageNum].getOverlay();
                        if (overlay == null) {
                            overlay = new Overlay(roi);
                            images[imageNum].setOverlay(overlay);
                        } else {
                            overlay.add(roi);
                        }
                    }
                }
            }
        }
        if (roiCount > 0 && manager != null) {
            manager.setAlwaysOnTop(true);
            manager.runCommand("show all with labels");
        }
    }
}
Also used : Ellipse(ome.xml.model.Ellipse) Shape(ome.xml.model.Shape) Rectangle(java.awt.Rectangle) TextRoi(ij.gui.TextRoi) OvalRoi(ij.gui.OvalRoi) Union(ome.xml.model.Union) Font(java.awt.Font) PolygonRoi(ij.gui.PolygonRoi) Polygon(ome.xml.model.Polygon) Overlay(ij.gui.Overlay) PointRoi(ij.gui.PointRoi) OME(ome.xml.model.OME) Color(java.awt.Color) Point(ome.xml.model.Point) PolygonRoi(ij.gui.PolygonRoi) TextRoi(ij.gui.TextRoi) OvalRoi(ij.gui.OvalRoi) PointRoi(ij.gui.PointRoi) EllipseRoi(ij.gui.EllipseRoi) ShapeRoi(ij.gui.ShapeRoi) Roi(ij.gui.Roi) ImagePlus(ij.ImagePlus) Point(ome.xml.model.Point) RoiManager(ij.plugin.frame.RoiManager) Line(ij.gui.Line) OMEXMLMetadata(loci.formats.ome.OMEXMLMetadata) Polyline(ome.xml.model.Polyline)

Aggregations

OME (ome.xml.model.OME)14 Test (org.testng.annotations.Test)9 DocumentBuilder (javax.xml.parsers.DocumentBuilder)8 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)8 OMEModel (ome.xml.model.OMEModel)8 OMEModelImpl (ome.xml.model.OMEModelImpl)8 Document (org.w3c.dom.Document)8 Element (org.w3c.dom.Element)7 MapPair (ome.xml.model.MapPair)3 Point (ome.xml.model.Point)3 ImagePlus (ij.ImagePlus)2 EllipseRoi (ij.gui.EllipseRoi)2 Line (ij.gui.Line)2 OvalRoi (ij.gui.OvalRoi)2 PointRoi (ij.gui.PointRoi)2 PolygonRoi (ij.gui.PolygonRoi)2 Roi (ij.gui.Roi)2 ShapeRoi (ij.gui.ShapeRoi)2 TextRoi (ij.gui.TextRoi)2 OMEXMLMetadata (loci.formats.ome.OMEXMLMetadata)2