Changeset 3818


Ignore:
Timestamp:
03/13/08 20:20:04 (12 years ago)
Author:
melissa
Message:
  • Removed duplicate logic from OMEWriter and added support for writing multiple series.
  • Tweaked omeul to take advantage of multi-series support. 'omeul <file>' now uploads every series in the file, while 'omeul -series <num> <file>' uploads only the selected series.
Location:
trunk/loci
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/formats/ome/OMEWriter.java

    r3816 r3818  
    2525package loci.formats.ome; 
    2626 
     27import java.awt.Image; 
    2728import java.io.*; 
    2829import loci.formats.*; 
     
    8889  private int planesWritten = 0; 
    8990 
    90   private MetadataRetrieve metadata; 
    91  
    9291  // -- Constructor -- 
    9392 
     
    116115  // -- IFormatWriter API methods -- 
    117116 
    118   /* @see loci.formats.IFormatWriter#setMetadata(MetadataRetrieve) */ 
    119   public void setMetadata(MetadataRetrieve meta) { 
    120     metadata = meta; 
    121   } 
    122  
    123117  /* @see loci.formats.IFormatWriter#saveImage(Image, boolean) */ 
    124   public void saveImage(java.awt.Image image, boolean last) 
     118  public void saveImage(Image image, boolean last) 
     119    throws FormatException, IOException 
     120  { 
     121    saveImage(image, 0, last, last); 
     122  } 
     123 
     124  /* @see loci.formats.IFormatWriter#saveImage(Image, int, boolean, boolean) */ 
     125  public void saveImage(Image image, int series, boolean lastInSeries, 
     126    boolean last) 
    125127    throws FormatException, IOException 
    126128  { 
    127129    byte[][] b = ImageTools.getPixelBytes(ImageTools.makeBuffered(image), 
    128       !metadata.getPixelsBigEndian(0, 0).booleanValue()); 
     130      !metadataRetrieve.getPixelsBigEndian(series, 0).booleanValue()); 
    129131    for (int i=0; i<b.length; i++) { 
    130       saveBytes(b[i], last && (i == b.length - 1)); 
    131     } 
    132   } 
    133  
    134   /* @see loci.formats.IFormatWriter#saveBytes(String, byte[], boolean) */ 
    135   public void saveBytes(byte[] bytes, boolean last) 
     132      saveBytes(b[i], series, lastInSeries && (i == b.length - 1), 
     133        last && (i == b.length - 1)); 
     134    } 
     135  } 
     136 
     137  /* @see loci.formats.IFormatWriter#saveBytes(byte[], int, boolean, boolean) */ 
     138  public void saveBytes(byte[] bytes, int series, boolean lastInSeries, 
     139    boolean last) 
    136140    throws FormatException, IOException 
    137141  { 
     
    171175        r.exec("repository = pf.findRepository(zero)"); 
    172176        r.exec("repository.setImageServerURL(omeis)"); 
    173  
    174         r.exec("im.startImport(exp)"); 
    175177      } 
    176178      catch (ReflectException e) { 
     
    178180      } 
    179181 
    180       if (metadata == null) { 
     182      if (metadataRetrieve == null) { 
    181183        throw new FormatException("Metadata store not specified."); 
    182184      } 
    183185    } 
    184186 
    185     int x = metadata.getPixelsSizeX(0, 0).intValue(); 
    186     int y = metadata.getPixelsSizeY(0, 0).intValue(); 
    187     int z = metadata.getPixelsSizeZ(0, 0).intValue(); 
    188     int c = metadata.getPixelsSizeC(0, 0).intValue(); 
    189     int t = metadata.getPixelsSizeT(0, 0).intValue(); 
    190     String order = metadata.getPixelsDimensionOrder(0, 0); 
    191     String pixelTypeString = metadata.getPixelsPixelType(0, 0); 
     187    try { 
     188      r.exec("im.startImport(exp)"); 
     189    } 
     190    catch (ReflectException e) { 
     191      if (debug) LogTools.trace(e); 
     192    } 
     193 
     194    int x = metadataRetrieve.getPixelsSizeX(series, 0).intValue(); 
     195    int y = metadataRetrieve.getPixelsSizeY(series, 0).intValue(); 
     196    int z = metadataRetrieve.getPixelsSizeZ(series, 0).intValue(); 
     197    int c = metadataRetrieve.getPixelsSizeC(series, 0).intValue(); 
     198    int t = metadataRetrieve.getPixelsSizeT(series, 0).intValue(); 
     199    String order = metadataRetrieve.getPixelsDimensionOrder(series, 0); 
     200    String pixelTypeString = metadataRetrieve.getPixelsPixelType(series, 0); 
    192201    int pixelType = FormatTools.pixelTypeFromString(pixelTypeString); 
    193202    int bpp = FormatTools.getBytesPerPixel(pixelType); 
    194     boolean bigEndian = metadata.getPixelsBigEndian(0, 0).booleanValue(); 
     203    boolean bigEndian = 
     204      metadataRetrieve.getPixelsBigEndian(series, 0).booleanValue(); 
    195205 
    196206    try { 
     
    239249    } 
    240250 
    241     if (last) { 
     251    if (lastInSeries) { 
    242252      try { 
    243253        r.exec("pixelsId = is.finishPixels(pixelsId)"); 
     
    246256        r.setVar("NOW", "now"); 
    247257 
    248         String creationDate = metadata.getImageCreationDate(0); 
     258        String creationDate = metadataRetrieve.getImageCreationDate(series); 
    249259        if (creationDate == null) { 
    250260          creationDate = 
     
    254264        r.setVar("creationDate", creationDate); 
    255265 
    256         if (metadata.getImageName(0) != null) { 
    257           r.setVar("imageName", metadata.getImageName(0)); 
     266        if (metadataRetrieve.getImageName(series) != null) { 
     267          r.setVar("imageName", metadataRetrieve.getImageName(series)); 
    258268        } 
    259269        else r.setVar("imageName", "new image " + credentials.imageID); 
    260         r.setVar("imageDescription", metadata.getImageDescription(0)); 
     270        r.setVar("imageDescription", 
     271          metadataRetrieve.getImageDescription(series)); 
    261272 
    262273        r.setVar("IMAGE_CLASS", "org.openmicroscopy.ds.dto.Image"); 
     
    320331        r.exec("img.setDefaultPixels(pixels)"); 
    321332        r.exec("df.update(img)"); 
    322  
    323         close(); 
    324333      } 
    325334      catch (ReflectException e) { 
    326335        throw new FormatException(e); 
    327336      } 
    328     } 
     337 
     338      planesWritten = 0; 
     339      credentials.imageID = -1; 
     340    } 
     341 
     342    if (last) close(); 
    329343  } 
    330344 
     
    342356    credentials = null; 
    343357    planesWritten = 0; 
    344     metadata = null; 
     358    if (currentId != null) metadataRetrieve = null; 
     359    currentId = null; 
    345360  } 
    346361 
     
    404419    String server = null, user = null, pass = null; 
    405420    String id = null; 
     421    int series = -1; 
    406422 
    407423    // parse command-line arguments 
     
    416432          else if (param.equalsIgnoreCase("-u")) user = args[++i]; 
    417433          else if (param.equalsIgnoreCase("-p")) pass = args[++i]; 
     434          else if (param.equalsIgnoreCase("-series")) { 
     435            series = Integer.parseInt(args[++i]); 
     436          } 
    418437          else if (param.equalsIgnoreCase("-h") || param.equalsIgnoreCase("-?")) 
    419438          { 
     
    450469    if (doUsage) { 
    451470      LogTools.println("Usage: omeul [-s server.address] " + 
    452         "[-u username] [-p password] filename"); 
     471        "[-u username] [-p password] [-series series.number] filename"); 
    453472      LogTools.println(); 
    454473      System.exit(1); 
     
    487506    }); 
    488507 
    489     uploader.setId(server + "?user=" + user + "&password=" + pass); 
    490  
    491508    FileStitcher reader = new FileStitcher(); 
    492509    reader.setMetadataStore(MetadataTools.createOMEXMLMetadata()); 
    493510    reader.setId(id); 
    494     uploader.setMetadata((MetadataRetrieve) reader.getMetadataStore()); 
    495     for (int i=0; i<reader.getImageCount(); i++) { 
    496       uploader.saveImage(reader.openImage(i), i == reader.getImageCount() - 1); 
     511 
     512    uploader.setMetadataRetrieve((MetadataRetrieve) reader.getMetadataStore()); 
     513    uploader.setId(server + "?user=" + user + "&password=" + pass); 
     514 
     515    int start = series == -1 ? 0 : series; 
     516    int end = series == -1 ? reader.getSeriesCount() : series + 1; 
     517 
     518    for (int s=start; s<end; s++) { 
     519      reader.setSeries(s); 
     520      for (int i=0; i<reader.getImageCount(); i++) { 
     521        boolean last = i == reader.getImageCount() - 1; 
     522        uploader.saveImage(reader.openImage(i), s, last, 
     523          last && s == end - 1); 
     524      } 
    497525    } 
    498526    reader.close(); 
  • trunk/loci/plugins/LociUploader.java

    r3817 r3818  
    108108      OMEWriter ul = new OMEWriter(); 
    109109      String id = server + "?user=" + user + "&password=" + pass; 
    110       ul.setId(id); 
    111110 
    112111      ImagePlus imp = WindowManager.getCurrentImage(); 
     
    152151      } 
    153152      MetadataRetrieve retrieve = (MetadataRetrieve) store; 
    154       ul.setMetadata(retrieve); 
     153      ul.setMetadataRetrieve(retrieve); 
     154      ul.setId(id); 
    155155 
    156156      boolean little = !retrieve.getPixelsBigEndian(0, 0).booleanValue(); 
  • trunk/loci/visbio/ome/ImageUploader.java

    r3524 r3818  
    6767      store.setRoot(data.getOMENode()); 
    6868      MetadataRetrieve retrieve = (MetadataRetrieve) store; 
    69       writer.setMetadata(retrieve); 
     69      writer.setMetadataRetrieve(retrieve); 
    7070 
    7171      String id = server + "?user=" + username + "&password=" + password; 
Note: See TracChangeset for help on using the changeset viewer.