Search in sources :

Example 6 with MapPair

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

the class FakeReader method fillAnnotations.

private void fillAnnotations(MetadataStore store, int imageIndex) {
    int annotationRefCount = 0;
    String annotationID;
    for (int i = 0; i < annBool; i++) {
        annotationID = ANNOTATION_PREFIX + annotationCount;
        store.setBooleanAnnotationID(annotationID, annotationBoolCount);
        store.setBooleanAnnotationNamespace(ANNOTATION_NAMESPACE, annotationBoolCount);
        store.setBooleanAnnotationValue(ANN_BOOLEAN_VALUE, annotationBoolCount);
        store.setImageAnnotationRef(annotationID, imageIndex, annotationRefCount);
        annotationBoolCount++;
        annotationCount++;
        annotationRefCount++;
    }
    for (int i = 0; i < annComment; i++) {
        annotationID = ANNOTATION_PREFIX + annotationCount;
        store.setCommentAnnotationID(annotationID, annotationCommentCount);
        store.setCommentAnnotationNamespace(ANNOTATION_NAMESPACE, annotationCommentCount);
        store.setCommentAnnotationValue(ANN_COMMENT_VALUE + (annotationCount + 1), annotationCommentCount);
        store.setImageAnnotationRef(annotationID, imageIndex, annotationRefCount);
        annotationCommentCount++;
        annotationCount++;
        annotationRefCount++;
    }
    for (int i = 0; i < annDouble; i++) {
        annotationID = ANNOTATION_PREFIX + annotationCount;
        store.setDoubleAnnotationID(annotationID, annotationDoubleCount);
        store.setDoubleAnnotationNamespace(ANNOTATION_NAMESPACE, annotationDoubleCount);
        store.setDoubleAnnotationValue(ANN_DOUBLE_VALUE * (annotationCount + 1), annotationDoubleCount);
        store.setImageAnnotationRef(annotationID, imageIndex, annotationRefCount);
        annotationDoubleCount++;
        annotationCount++;
        annotationRefCount++;
    }
    for (int i = 0; i < annLong; i++) {
        annotationID = ANNOTATION_PREFIX + annotationCount;
        store.setLongAnnotationID(annotationID, annotationLongCount);
        store.setLongAnnotationNamespace(ANNOTATION_NAMESPACE, annotationLongCount);
        store.setLongAnnotationValue(ANN_LONG_VALUE + annotationCount, annotationLongCount);
        store.setImageAnnotationRef(annotationID, imageIndex, annotationRefCount);
        annotationLongCount++;
        annotationCount++;
        annotationRefCount++;
    }
    for (int i = 0; i < annMap; i++) {
        annotationID = ANNOTATION_PREFIX + annotationCount;
        store.setMapAnnotationID(annotationID, annotationMapCount);
        store.setMapAnnotationNamespace(ANNOTATION_NAMESPACE, annotationMapCount);
        List<MapPair> mapValue = new ArrayList<MapPair>();
        for (int keyNum = 0; keyNum < 10; keyNum++) {
            mapValue.add(new MapPair("keyS" + imageIndex + "N" + keyNum, "val" + (keyNum + 1) * (annotationCount + 1)));
        }
        store.setMapAnnotationValue(mapValue, annotationMapCount);
        store.setImageAnnotationRef(annotationID, imageIndex, annotationRefCount);
        annotationMapCount++;
        annotationCount++;
        annotationRefCount++;
    }
    for (int i = 0; i < annTag; i++) {
        annotationID = ANNOTATION_PREFIX + annotationCount;
        store.setTagAnnotationID(annotationID, annotationTagCount);
        store.setTagAnnotationNamespace(ANNOTATION_NAMESPACE, annotationTagCount);
        store.setTagAnnotationValue(ANN_TAG_VALUE + (annotationCount + 1), annotationTagCount);
        store.setImageAnnotationRef(annotationID, imageIndex, annotationRefCount);
        annotationTagCount++;
        annotationCount++;
        annotationRefCount++;
    }
    for (int i = 0; i < annTerm; i++) {
        annotationID = ANNOTATION_PREFIX + annotationCount;
        store.setTermAnnotationID(annotationID, annotationTermCount);
        store.setTermAnnotationNamespace(ANNOTATION_NAMESPACE, annotationTermCount);
        store.setTermAnnotationValue(ANN_TERM_VALUE + (annotationCount + 1), annotationTermCount);
        store.setImageAnnotationRef(annotationID, imageIndex, annotationRefCount);
        annotationTermCount++;
        annotationCount++;
        annotationRefCount++;
    }
    for (int i = 0; i < annTime; i++) {
        annotationID = ANNOTATION_PREFIX + annotationCount;
        store.setTimestampAnnotationID(annotationID, annotationTimeCount);
        store.setTimestampAnnotationNamespace(ANNOTATION_NAMESPACE, annotationTimeCount);
        store.setTimestampAnnotationValue(ANN_TIME_VALUE, annotationTimeCount);
        store.setImageAnnotationRef(annotationID, imageIndex, annotationRefCount);
        annotationTimeCount++;
        annotationCount++;
        annotationRefCount++;
    }
    for (int i = 0; i < annXml; i++) {
        annotationID = ANNOTATION_PREFIX + annotationCount;
        store.setXMLAnnotationID(annotationID, annotationXmlCount);
        store.setXMLAnnotationNamespace(ANNOTATION_NAMESPACE, annotationXmlCount);
        store.setXMLAnnotationValue(ANN_XML_VALUE_START + (annotationCount + 1) + ANN_XML_VALUE_END, annotationXmlCount);
        store.setImageAnnotationRef(annotationID, imageIndex, annotationRefCount);
        annotationXmlCount++;
        annotationCount++;
        annotationRefCount++;
    }
}
Also used : MapPair(ome.xml.model.MapPair) ArrayList(java.util.ArrayList)

Example 7 with MapPair

use of ome.xml.model.MapPair 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());
}
Also used : MapPair(ome.xml.model.MapPair) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) MapAnnotation(ome.xml.model.MapAnnotation) 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 8 with MapPair

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

the class GenericExcitationMapTest method setUp.

@BeforeClass
public void setUp() throws Exception {
    Instrument instrument = new Instrument();
    instrument.setID("Instrument:0");
    // Add a GenericExcitationSource with an Map
    GenericExcitationSource geSource = new GenericExcitationSource();
    geSource.setID("LightSource:0");
    List<MapPair> dataMap = new ArrayList<MapPair>();
    dataMap.add(new MapPair("a", "1"));
    dataMap.add(new MapPair("d", "2"));
    dataMap.add(new MapPair("c", "3"));
    dataMap.add(new MapPair("b", "4"));
    dataMap.add(new MapPair("e", "5"));
    dataMap.add(new MapPair("c", "6"));
    assertEquals(6, dataMap.size());
    geSource.setMap(dataMap);
    instrument.addLightSource(geSource);
    ome.addInstrument(instrument);
    // Add an Image/Pixels with a LightSourceSettings reference to the
    // GenericExcitationSource on one of its channels.
    Image image = new Image();
    image.setID("Image:0");
    Pixels pixels = new Pixels();
    pixels.setID("Pixels:0");
    Channel channel = new Channel();
    channel.setID("Channel:0");
    LightSourceSettings settings = new LightSourceSettings();
    settings.setID("LightSource:0");
    channel.setLightSourceSettings(settings);
    pixels.addChannel(channel);
    image.setPixels(pixels);
    ome.addImage(image);
}
Also used : MapPair(ome.xml.model.MapPair) LightSourceSettings(ome.xml.model.LightSourceSettings) GenericExcitationSource(ome.xml.model.GenericExcitationSource) Channel(ome.xml.model.Channel) Instrument(ome.xml.model.Instrument) ArrayList(java.util.ArrayList) Image(ome.xml.model.Image) Pixels(ome.xml.model.Pixels) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

MapPair (ome.xml.model.MapPair)8 ArrayList (java.util.ArrayList)5 DocumentBuilder (javax.xml.parsers.DocumentBuilder)3 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)3 Image (ome.xml.model.Image)3 OME (ome.xml.model.OME)3 OMEModel (ome.xml.model.OMEModel)3 OMEModelImpl (ome.xml.model.OMEModelImpl)3 Pixels (ome.xml.model.Pixels)3 BeforeClass (org.testng.annotations.BeforeClass)3 Test (org.testng.annotations.Test)3 Document (org.w3c.dom.Document)3 Element (org.w3c.dom.Element)3 GenericExcitationSource (ome.xml.model.GenericExcitationSource)2 ImagingEnvironment (ome.xml.model.ImagingEnvironment)2 MapAnnotation (ome.xml.model.MapAnnotation)2 ServiceFactory (loci.common.services.ServiceFactory)1 ImageWriter (loci.formats.ImageWriter)1 IMetadata (loci.formats.meta.IMetadata)1 OMEXMLService (loci.formats.services.OMEXMLService)1