Changeset 6978


Ignore:
Timestamp:
09/23/10 15:18:08 (9 years ago)
Author:
melissa
Message:

OMETiffReader now populates its' MetadataStore in such as way as to produce valid OME-XML (hopefully). BinData elements are not populated; instead, a MetadataOnly element is inserted under any Pixels that do not have at least one TiffData. See #556.

The only problem with this is that OMETiffReader.getMetadataStore() no longer returns a MetadataStore that can be used with an IFormatWriter (assuming, of course, that an IMetadata was passed to setMetadataStore). The current solution is a new OMETiffWriter API method: 'MetadataStore getMetadataStoreForConversion()'.
This will return a MetadataStore of the same type as 'getMetadataStore()', but that contains the required BinData elements.

Location:
trunk/components/bio-formats/src/loci/formats
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/components/bio-formats/src/loci/formats/in/OMETiffReader.java

    r6969 r6978  
    4747import loci.formats.MetadataTools; 
    4848import loci.formats.MissingLibraryException; 
     49import loci.formats.meta.MetadataStore; 
    4950import loci.formats.ome.OMEXMLMetadata; 
    5051import loci.formats.services.OMEXMLService; 
     
    8081  private int lastPlane; 
    8182  private boolean hasSPW; 
     83 
     84  private OMEXMLService service; 
    8285 
    8386  // -- Constructor -- 
     
    105108    String xml = ifd.getComment(); 
    106109 
     110    if (service == null) setupService(); 
    107111    OMEXMLMetadata meta; 
    108112    try { 
    109       ServiceFactory factory = new ServiceFactory(); 
    110       OMEXMLService service = factory.getInstance(OMEXMLService.class); 
    111113      meta = service.createOMEXMLMetadata(xml); 
    112     } 
    113     catch (DependencyException de) { 
    114       throw new MissingLibraryException(NO_OME_XML_MSG, de); 
    115114    } 
    116115    catch (ServiceException se) { 
     
    145144 
    146145    try { 
    147       ServiceFactory factory = new ServiceFactory(); 
    148       OMEXMLService service = factory.getInstance(OMEXMLService.class); 
     146      if (service == null) setupService(); 
    149147      service.createOMEXMLMetadata(comment.trim()); 
    150148      return true; 
    151149    } 
    152     catch (DependencyException de) { } 
    153150    catch (ServiceException se) { } 
    154151    catch (NullPointerException e) { } 
     152    catch (FormatException e) { } 
    155153    return false; 
    156154  } 
     
    259257    String xml = firstIFD.getComment(); 
    260258 
     259    if (service == null) setupService(); 
    261260    OMEXMLMetadata meta; 
    262     OMEXMLService service; 
    263261    try { 
    264       ServiceFactory factory = new ServiceFactory(); 
    265       service = factory.getInstance(OMEXMLService.class); 
    266262      meta = service.createOMEXMLMetadata(xml); 
    267     } 
    268     catch (DependencyException de) { 
    269       throw new MissingLibraryException(NO_OME_XML_MSG, de); 
    270263    } 
    271264    catch (ServiceException se) { 
     
    642635 
    643636    MetadataTools.populatePixels(metadataStore, this, false, false); 
     637    metadataStore = getMetadataStoreForDisplay(); 
     638  } 
     639 
     640  // -- OMETiffReader API methods -- 
     641 
     642  /** 
     643   * Returns a MetadataStore that is populated in such a way as to 
     644   * produce valid OME-XML.  The returned MetadataStore cannot be used 
     645   * by an IFormatWriter, as it will not contain the required 
     646   * BinData.BigEndian attributes. 
     647   */ 
     648  public MetadataStore getMetadataStoreForDisplay() { 
     649    MetadataStore store = getMetadataStore(); 
     650    if (service.isOMEXMLMetadata(store)) { 
     651      service.removeBinData((OMEXMLMetadata) store); 
     652      for (int i=0; i<getSeriesCount(); i++) { 
     653        if (((OMEXMLMetadata) store).getTiffDataCount(i) == 0) { 
     654          service.addMetadataOnly((OMEXMLMetadata) store, i); 
     655        } 
     656      } 
     657    } 
     658    return store; 
     659  } 
     660 
     661  /** 
     662   * Returns a MetadataStore that is populated in such a way as to be 
     663   * usable by an IFormatWriter.  Any OME-XML generated from this 
     664   * MetadataStore is <em>very unlikely</em> to be valid, as more than 
     665   * likely both BinData and TiffData element will be present. 
     666   */ 
     667  public MetadataStore getMetadataStoreForConversion() { 
     668    MetadataStore store = getMetadataStore(); 
     669    int realSeries = getSeries(); 
     670    for (int i=0; i<getSeriesCount(); i++) { 
     671      setSeries(i); 
     672      store.setPixelsBinDataBigEndian(new Boolean(!isLittleEndian()), i, 0); 
     673    } 
     674    setSeries(realSeries); 
     675    return store; 
    644676  } 
    645677 
     
    650682     if (file.exists()) return file.getAbsolutePath(); 
    651683     return new Location(name).getAbsolutePath(); 
     684  } 
     685 
     686  private void setupService() throws FormatException { 
     687    try { 
     688      ServiceFactory factory = new ServiceFactory(); 
     689      service = factory.getInstance(OMEXMLService.class); 
     690    } 
     691    catch (DependencyException de) { 
     692      throw new MissingLibraryException(NO_OME_XML_MSG, de); 
     693    } 
    652694  } 
    653695 
  • trunk/components/bio-formats/src/loci/formats/out/OMETiffWriter.java

    r6976 r6978  
    9898 
    9999        // remove any BinData elements from the OME-XML 
    100         removeBinData(omeMeta); 
     100        service.removeBinData(omeMeta); 
    101101 
    102102        for (int series=0; series<omeMeta.getImageCount(); series++) { 
     
    261261  } 
    262262 
    263   private void removeBinData(OMEXMLMetadata omeMeta) { 
    264     OME root = (OME) omeMeta.getRoot(); 
    265     List<Image> images = root.copyImageList(); 
    266     for (Image img : images) { 
    267       Pixels pix = img.getPixels(); 
    268       List<BinData> binData = pix.copyBinDataList(); 
    269       for (BinData bin : binData) { 
    270         pix.removeBinData(bin); 
    271       } 
    272     } 
    273     omeMeta.setRoot(root); 
    274   } 
    275  
    276263  private void populateTiffData(OMEXMLMetadata omeMeta, int[] zct, 
    277264    int ifd, int series, int plane) 
  • trunk/components/bio-formats/src/loci/formats/services/OMEXMLService.java

    r6881 r6978  
    184184  public void convertMetadata(MetadataRetrieve src, MetadataStore dest); 
    185185 
     186  /** 
     187   * Remove all of the BinData elements from the given OME-XML metadata object. 
     188   */ 
     189  public void removeBinData(OMEXMLMetadata omexmlMeta); 
     190 
     191  /** 
     192   * Insert a MetadataOnly element under the Image specified by 'index' in the 
     193   * given OME-XML metadata object. 
     194   */ 
     195  public void addMetadataOnly(OMEXMLMetadata omexmlMeta, int image); 
     196 
    186197  // -- Utility methods - casting -- 
    187198 
  • trunk/components/bio-formats/src/loci/formats/services/OMEXMLServiceImpl.java

    r6886 r6978  
    2525 
    2626import java.io.IOException; 
     27import java.util.List; 
    2728 
    2829import javax.xml.parsers.ParserConfigurationException; 
     
    4243import loci.formats.ome.OMEXMLMetadataImpl; 
    4344import ome.xml.OMEXMLFactory; 
     45import ome.xml.model.BinData; 
     46import ome.xml.model.Image; 
     47import ome.xml.model.MetadataOnly; 
    4448import ome.xml.model.OME; 
    4549import ome.xml.model.OMEModel; 
    4650import ome.xml.model.OMEModelImpl; 
    4751import ome.xml.model.OMEModelObject; 
     52import ome.xml.model.Pixels; 
    4853import ome.xml.model.StructuredAnnotations; 
    4954 
     
    402407            "Expecting OMEXMLMetadata instance."); 
    403408      } 
    404       // FIXME: What's below was in the ReflectedUniverse, the method no 
    405       // longer exists or has changed. 
    406       //((OMEXMLMetadata) dest).createRoot(xml); 
     409 
     410      dest.setRoot(ome); 
    407411    } 
    408412    else { 
     
    419423  public void convertMetadata(MetadataRetrieve src, MetadataStore dest) { 
    420424    MetadataConverter.convertMetadata(src, dest); 
     425  } 
     426 
     427  /* @see OMEXMLService#removeBinData(OMEXMLMetadata) */ 
     428  public void removeBinData(OMEXMLMetadata omexmlMeta) { 
     429    OME root = (OME) omexmlMeta.getRoot(); 
     430    List<Image> images = root.copyImageList(); 
     431    for (Image img : images) { 
     432      Pixels pix = img.getPixels(); 
     433      List<BinData> binData = pix.copyBinDataList(); 
     434      for (BinData bin : binData) { 
     435        pix.removeBinData(bin); 
     436      } 
     437    } 
     438    omexmlMeta.setRoot(root); 
     439  } 
     440 
     441  /* @see OMEXMLService#addMetadataOnly(OMEXMLMetadata, int) */ 
     442  public void addMetadataOnly(OMEXMLMetadata omexmlMeta, int image) { 
     443    MetadataOnly meta = new MetadataOnly(); 
     444    OME root = (OME) omexmlMeta.getRoot(); 
     445    Pixels pix = root.getImage(image).getPixels(); 
     446    pix.setMetadataOnly(meta); 
     447    omexmlMeta.setRoot(root); 
    421448  } 
    422449 
  • trunk/components/bio-formats/src/loci/formats/tools/ImageConverter.java

    r6976 r6978  
    4545import loci.formats.ImageWriter; 
    4646import loci.formats.MissingLibraryException; 
     47import loci.formats.ReaderWrapper; 
    4748import loci.formats.in.OMETiffReader; 
    4849import loci.formats.meta.MetadataRetrieve; 
     
    212213 
    213214    MetadataStore store = reader.getMetadataStore(); 
     215    IFormatReader base = reader;  
     216 
     217    if (base instanceof ReaderWrapper) { 
     218      base = ((ReaderWrapper) base).unwrap(); 
     219    } 
     220    if (base instanceof FileStitcher) { 
     221      base = ((FileStitcher) base).getReader(); 
     222    } 
     223    if (base instanceof ImageReader) { 
     224      base = ((ImageReader) base).getReader(); 
     225    } 
     226    if (base instanceof OMETiffReader) { 
     227      store = ((OMETiffReader) base).getMetadataStoreForConversion(); 
     228    } 
     229 
    214230    if (store instanceof MetadataRetrieve) { 
    215231      writer.setMetadataRetrieve((MetadataRetrieve) store); 
Note: See TracChangeset for help on using the changeset viewer.