use of ome.xml.model.OME in project bioformats by openmicroscopy.
the class ROIHandler method saveROIs.
/**
* Save ROIs in the ROI manager to the given MetadataStore.
*
* @param store Where to store the rois.
*/
public static void saveROIs(MetadataStore store) {
Roi[] rois = readFromOverlays();
if (rois == null || rois.length == 0) {
rois = readFromRoiManager();
}
if (rois == null || rois.length == 0)
return;
List<String> discardList = new ArrayList<String>();
String roiID = null;
OME root = (OME) store.getRoot();
int roicount = root.sizeOfROIList();
int cntr = roicount;
ImagePlus imp = WindowManager.getCurrentImage();
for (int i = 0; i < rois.length; i++) {
String polylineID = MetadataTools.createLSID("Shape", cntr, 0);
roiID = MetadataTools.createLSID("ROI", cntr, 0);
Roi ijRoi = rois[i];
int c = ijRoi.getCPosition() - 1;
int z = ijRoi.getZPosition() - 1;
int t = ijRoi.getTPosition() - 1;
ImagePlus image = WindowManager.getImage(ijRoi.getImageID());
if (image == null) {
// pick the current image in that case
image = imp;
}
int pos = ijRoi.getPosition();
if (imp != null) {
if (imp.getNChannels() == 1 && imp.getNSlices() == 1) {
t = pos - 1;
} else if (imp.getNChannels() == 1 && imp.getNFrames() == 1) {
z = pos - 1;
} else if (imp.getNSlices() == 1 && imp.getNFrames() == 1) {
c = pos - 1;
}
if (t > imp.getNFrames() - 1 || c > imp.getNChannels() - 1 || z > imp.getNSlices() - 1) {
//
continue;
}
}
if (ijRoi.isDrawingTool()) {
// Checks if the given roi is a Text box/Arrow/Rounded Rectangle
if (ijRoi.getTypeAsString().matches("Text")) {
if (ijRoi instanceof TextRoi) {
store.setLabelID(polylineID, cntr, 0);
storeText((TextRoi) ijRoi, store, cntr, 0, c, z, t);
}
} else if (ijRoi.getTypeAsString().matches("Rectangle")) {
if (ijRoi instanceof Roi) {
store.setRectangleID(polylineID, cntr, 0);
storeRectangle(ijRoi, store, cntr, 0, c, z, t);
}
} else {
roiID = null;
String type = ijRoi.getName();
IJ.log("ROI ID : " + type + " ROI type : " + "Arrow (Drawing Tool) is not supported");
}
} else if (ijRoi instanceof OvalRoi) {
// Check if its an oval or ellipse ROI
store.setEllipseID(polylineID, cntr, 0);
storeOval((OvalRoi) ijRoi, store, cntr, 0, c, z, t);
} else if (ijRoi instanceof Line) {
// Check if its a Line or Arrow ROI
boolean checkpoint = ijRoi.isDrawingTool();
if (!checkpoint) {
store.setLineID(polylineID, cntr, 0);
storeLine((Line) ijRoi, store, cntr, 0, c, z, t);
} else {
roiID = null;
String type = ijRoi.getName();
IJ.log("ROI ID : " + type + " ROI type : " + "Arrow (Drawing Tool) is not supported");
}
} else if (ijRoi instanceof PolygonRoi || ijRoi instanceof EllipseRoi) {
if (ijRoi.getTypeAsString().matches("Polyline") || ijRoi.getTypeAsString().matches("Freeline") || ijRoi.getTypeAsString().matches("Angle")) {
store.setPolylineID(polylineID, cntr, 0);
storePolygon((PolygonRoi) ijRoi, store, cntr, 0, c, z, t);
} else if (ijRoi.getTypeAsString().matches("Point")) {
store.setPointID(polylineID, cntr, 0);
storePoint((PointRoi) ijRoi, store, cntr, 0, c, z, t);
} else if (ijRoi.getTypeAsString().matches("Polygon") || ijRoi.getTypeAsString().matches("Freehand") || ijRoi.getTypeAsString().matches("Traced") || ijRoi.getTypeAsString().matches("Oval")) {
store.setPolygonID(polylineID, cntr, 0);
storePolygon((PolygonRoi) ijRoi, store, cntr, 0, c, z, t);
}
} else if (ijRoi instanceof ShapeRoi) {
Roi[] subRois = ((ShapeRoi) ijRoi).getRois();
for (int q = 0; q < subRois.length; q++) {
polylineID = MetadataTools.createLSID("Shape", cntr, q);
roiID = MetadataTools.createLSID("ROI", cntr, q);
Roi ijShape = subRois[q];
if (ijShape.isDrawingTool()) {
// Checks if the given roi is a Text box/Arrow/Rounded Rectangle
if (ijShape.getTypeAsString().matches("Text")) {
if (ijShape instanceof TextRoi) {
store.setLabelID(polylineID, cntr, q);
storeText((TextRoi) ijShape, store, cntr, q, c, z, t);
}
} else if (ijShape.getTypeAsString().matches("Rectangle")) {
if (ijShape instanceof Roi) {
store.setRectangleID(polylineID, cntr, q);
storeRectangle(ijShape, store, cntr, q, c, z, t);
}
} else {
roiID = null;
String type = ijShape.getName();
IJ.log("ROI ID : " + type + " ROI type : " + "Arrow (Drawing Tool) is not supported");
}
} else if (ijShape instanceof Line) {
boolean checkpoint = ijShape.isDrawingTool();
if (!checkpoint) {
store.setLineID(polylineID, cntr, 0);
storeLine((Line) ijShape, store, cntr, 0, c, z, t);
} else {
roiID = null;
String type1 = ijShape.getName();
discardList.add(type1);
IJ.log("ROI ID : " + type1 + " ROI type : " + "Arrow (DrawingTool) is not supported");
}
} else if (ijShape instanceof OvalRoi) {
store.setEllipseID(polylineID, cntr, q);
storeOval((OvalRoi) ijShape, store, cntr, q, c, z, t);
} else if (ijShape instanceof PolygonRoi || ijShape instanceof EllipseRoi) {
if (ijShape.getTypeAsString().matches("Polyline") || ijShape.getTypeAsString().matches("Freeline") || ijShape.getTypeAsString().matches("Angle")) {
store.setPolylineID(polylineID, cntr, q);
storePolygon((PolygonRoi) ijShape, store, cntr, q, c, z, t);
} else if (ijShape.getTypeAsString().matches("Point")) {
store.setPointID(polylineID, cntr, q);
storePoint((PointRoi) ijShape, store, cntr, q, c, z, t);
} else if (ijShape.getTypeAsString().matches("Polygon") || ijShape.getTypeAsString().matches("Freehand") || ijShape.getTypeAsString().matches("Traced") || ijShape.getTypeAsString().matches("Oval")) {
store.setPolygonID(polylineID, cntr, q);
storePolygon((PolygonRoi) ijShape, store, cntr, q, c, z, t);
}
} else if (ijShape.getTypeAsString().matches("Rectangle")) {
store.setRectangleID(polylineID, cntr, q);
storeRectangle(ijShape, store, cntr, q, c, z, t);
} else {
roiID = null;
String type = ijShape.getName();
IJ.log("ROI ID : " + type + " ROI type : " + ijShape.getTypeAsString() + "is not supported");
}
}
} else if (ijRoi.getTypeAsString().matches("Rectangle")) {
// Check if its a Rectangle or Rounded Rectangle ROI
store.setRectangleID(polylineID, cntr, 0);
storeRectangle(ijRoi, store, cntr, 0, c, z, t);
} else {
roiID = null;
String type = ijRoi.getName();
IJ.log("ROI ID : " + type + " ROI type : " + rois[cntr].getTypeAsString() + "is not supported");
}
// Save Roi's using ROIHandler
if (roiID != null) {
store.setROIID(roiID, cntr);
store.setImageROIRef(roiID, 0, cntr);
cntr++;
}
}
}
use of ome.xml.model.OME in project bioformats by openmicroscopy.
the class PumpWithLightSourceSettingsTest method testLightSourceType.
@Test
public void testLightSourceType() 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();
}
use of ome.xml.model.OME in project bioformats by openmicroscopy.
the class MapAnnotationTest method testMapAnnotationValueContent.
@Test
public void testMapAnnotationValueContent() 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).getLinkedAnnotation(0));
MapAnnotation mapAnnotation = (MapAnnotation) ome.getImage(0).getLinkedAnnotation(0);
List<MapPair> dataMap = mapAnnotation.getValue();
assertEquals(6, dataMap.size());
assertEquals("a", dataMap.get(0).getName());
assertEquals("1", dataMap.get(0).getValue());
assertEquals("d", dataMap.get(1).getName());
assertEquals("2", dataMap.get(1).getValue());
assertEquals("c", dataMap.get(2).getName());
assertEquals("3", dataMap.get(2).getValue());
assertEquals("b", dataMap.get(3).getName());
assertEquals("4", dataMap.get(3).getValue());
assertEquals("e", dataMap.get(4).getName());
assertEquals("5", dataMap.get(4).getValue());
assertEquals("c", dataMap.get(5).getName());
assertEquals("6", dataMap.get(5).getValue());
}
use of ome.xml.model.OME in project bioformats by openmicroscopy.
the class MapAnnotationTest method testMapAnnotationValid.
@Test
public void testMapAnnotationValid() 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();
}
use of ome.xml.model.OME in project bioformats by openmicroscopy.
the class OMEXMLServiceTest method testOriginalMetadata.
@Test
public void testOriginalMetadata() throws ServiceException {
OMEXMLMetadata metadata = service.createOMEXMLMetadata();
service.populateOriginalMetadata(metadata, "testKey", "testValue");
Hashtable metadataTable = service.getOriginalMetadata(metadata);
assertEquals(metadataTable.size(), 1);
assertTrue("testValue".equals(metadataTable.get("testKey")));
OME root = (OME) metadata.getRoot();
StructuredAnnotations annotations = root.getStructuredAnnotations();
assertEquals(annotations.sizeOfXMLAnnotationList(), 1);
XMLAnnotation xmlAnn = annotations.getXMLAnnotation(0);
String txt = "<OriginalMetadata><Key>testKey</Key><Value>testValue</Value></OriginalMetadata>";
assertEquals(txt, xmlAnn.getValue());
OriginalMetadataAnnotation omAnn = (OriginalMetadataAnnotation) xmlAnn;
assertEquals("testValue", omAnn.getValueForKey());
}
Aggregations