Changeset 2564


Ignore:
Timestamp:
04/06/07 12:27:56 (13 years ago)
Author:
melissa
Message:

Moved dimension swapping logic to ReaderWrapper subclass (DimensionSwapper).

Location:
trunk/loci
Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/apps/stitcher/MovieStitcher.java

    r2547 r2564  
    4343 
    4444  private FileStitcher reader = new FileStitcher(true); 
     45  private DimensionSwapper swap = new DimensionSwapper(reader);  
    4546  private ImageWriter writer = new ImageWriter(); 
    4647  private JFileChooser rc, wc; 
     
    6263 
    6364    // file choosers 
    64     rc = GUITools.buildFileChooser(reader); 
     65    rc = GUITools.buildFileChooser(swap); 
    6566    wc = GUITools.buildFileChooser(writer); 
    6667 
     
    282283      
    283284      try { 
    284         if (reader.getSeriesCount(pattern) > 1 && series == null) { 
     285        if (swap.getSeriesCount(pattern) > 1 && series == null) { 
    285286          JLabel seriesLabel = new JLabel("Series: "); 
    286287          series = new JSpinner(new SpinnerNumberModel(1, 1,  
    287             reader.getSeriesCount(pattern), 1));  
     288            swap.getSeriesCount(pattern), 1));  
    288289          series.addChangeListener(this); 
    289290          seriesRow.add(seriesLabel); 
     
    293294        else if (series != null) { 
    294295          ((SpinnerNumberModel) series.getModel()).setMaximum( 
    295             new Integer(reader.getSeriesCount(pattern))); 
     296            new Integer(swap.getSeriesCount(pattern))); 
    296297          pack(); 
    297298        } 
    298         else if (reader.getSeriesCount(pattern) == 1 && series != null) { 
     299        else if (swap.getSeriesCount(pattern) == 1 && series != null) { 
    299300          seriesRow.remove(series); 
    300301          series = null; 
     
    370371    if (e.getSource() == series) { 
    371372      try { 
    372         reader.setSeries(reader.getCurrentFile(),  
     373        swap.setSeries(swap.getCurrentFile(),  
    373374          ((Integer) series.getValue()).intValue() - 1); 
    374375        updateLabels(input.getText()); 
     
    420421  
    421422      if (series != null) { 
    422         reader.setSeries(in, ((Integer) series.getValue()).intValue() - 1); 
     423        swap.setSeries(in, ((Integer) series.getValue()).intValue() - 1); 
    423424      } 
    424425 
     
    429430      catch (NullPointerException npe) { } 
    430431 
    431       boolean isQT = reader.getFormat().equals("QuickTime"); 
     432      boolean isQT = swap.getFormat().equals("QuickTime"); 
    432433      boolean useQTJ = isQT && qtJava.isSelected(); 
    433434      //((QTReader) reader.getReader(QTReader.class)).setLegacy(useQTJ); 
     
    435436      // swap dimensions based on user input 
    436437 
    437       String order = reader.getDimensionOrder(in); 
     438      String order = swap.getDimensionOrder(in); 
    438439       
    439440      if (zLabel.getText().indexOf("Time") != -1) { 
     
    458459      } 
    459460 
    460       reader.swapDimensions(in, order); 
     461      swap.swapDimensions(in, order); 
    461462 
    462463      OMEXMLMetadataStore store = new OMEXMLMetadataStore(); 
    463464      store.createRoot(); 
    464       reader.close(); 
    465       reader.setMetadataStore(store); 
     465      swap.close(); 
     466      swap.setMetadataStore(store); 
    466467 
    467468      // determine internal and external dimensions for each axis 
    468469 
    469       int internalZ = includeZ.isSelected() ? reader.getSizeZ(in) : 1; 
    470       int internalT = includeT.isSelected() ? reader.getSizeT(in) : 1; 
    471       int internalC = includeC.isSelected() ? reader.getEffectiveSizeC(in) : 1; 
    472  
    473       int externalZ = includeZ.isSelected() ? 1 : reader.getSizeZ(in); 
    474       int externalT = includeT.isSelected() ? 1 : reader.getSizeT(in); 
    475       int externalC = includeC.isSelected() ? 1 : reader.getEffectiveSizeC(in); 
     470      int internalZ = includeZ.isSelected() ? swap.getSizeZ(in) : 1; 
     471      int internalT = includeT.isSelected() ? swap.getSizeT(in) : 1; 
     472      int internalC = includeC.isSelected() ? swap.getEffectiveSizeC(in) : 1; 
     473 
     474      int externalZ = includeZ.isSelected() ? 1 : swap.getSizeZ(in); 
     475      int externalT = includeT.isSelected() ? 1 : swap.getSizeT(in); 
     476      int externalC = includeC.isSelected() ? 1 : swap.getEffectiveSizeC(in); 
    476477 
    477478      int numFiles = externalZ * externalT * externalC; 
     
    481482      int cDigits = ("" + externalC).length(); 
    482483 
    483       progress.setMaximum(2 * reader.getImageCount(in)); 
     484      progress.setMaximum(2 * swap.getImageCount(in)); 
    484485 
    485486      int star = out.lastIndexOf("."); 
     
    490491      // determine appropriate pixel type 
    491492 
    492       int type = reader.getPixelType(in); 
     493      int type = swap.getPixelType(in); 
    493494      if (force && !writer.isSupportedType(out, type)) { 
    494495        int[] types = writer.getPixelTypes(out); 
     
    568569                  progress.setValue(2 * (plane + 1)); 
    569570                  plane++; 
    570                   int ndx = reader.getIndex(in, zPos, cPos, tPos); 
    571  
    572                   BufferedImage img = reader.openImage(in, ndx); 
     571                  int ndx = swap.getIndex(in, zPos, cPos, tPos); 
     572 
     573                  BufferedImage img = swap.openImage(in, ndx); 
    573574                  if (force &&  
    574                     !writer.isSupportedType(out, reader.getPixelType(in)))  
     575                    !writer.isSupportedType(out, swap.getPixelType(in)))  
    575576                  { 
    576577                    int pixelType = 0; 
     
    612613               
    613614              OMENode root = (OMENode)  
    614                 ((OMEXMLMetadataStore) reader.getMetadataStore(in)).getRoot(); 
     615                ((OMEXMLMetadataStore) swap.getMetadataStore(in)).getRoot(); 
    615616                 
    616617              // add TiffData element here  
     
    630631      } 
    631632 
    632       progress.setValue(2 * reader.getImageCount(in)); 
     633      progress.setValue(2 * swap.getImageCount(in)); 
    633634      progress.setString("Finishing"); 
    634635      if (writer != null) writer.close(); 
     
    636637      long end = System.currentTimeMillis(); 
    637638      double time = (end - start) / 1000.0; 
    638       long avg = (end - start) / (reader.getImageCount(in)); 
     639      long avg = (end - start) / (swap.getImageCount(in)); 
    639640      progress.setString(time + " s elapsed (" + avg + " ms/plane)"); 
    640641      progress.setValue(0); 
    641       if (reader != null) reader.close(); 
     642      if (swap != null) swap.close(); 
    642643    } 
    643644    catch (Exception exc) { 
     
    680681      String z = zLabel.getText(); 
    681682      z = z.substring(0, z.indexOf("<")); 
    682       z += "<1-" + reader.getSizeZ(pattern) + ">"; 
     683      z += "<1-" + swap.getSizeZ(pattern) + ">"; 
    683684      zLabel.setText(z); 
    684685 
    685686      String t = tLabel.getText(); 
    686687      t = t.substring(0, t.indexOf("<")); 
    687       t += "<1-" + reader.getSizeT(pattern) + ">"; 
     688      t += "<1-" + swap.getSizeT(pattern) + ">"; 
    688689      tLabel.setText(t); 
    689690 
    690691      String c = cLabel.getText(); 
    691692      c = c.substring(0, c.indexOf("<")); 
    692       c += "<1-" + reader.getEffectiveSizeC(pattern) + ">"; 
     693      c += "<1-" + swap.getEffectiveSizeC(pattern) + ">"; 
    693694      cLabel.setText(c); 
    694695       
  • trunk/loci/formats/FileStitcher.java

    r2563 r2564  
    531531  public String getCurrentFile() { return currentId; } 
    532532 
    533   /* @see IFormatReader#swapDimensions(String, String) */ 
    534   public void swapDimensions(String id, String dimOrder) 
    535     throws FormatException, IOException 
    536   { 
    537     if (!id.equals(currentId)) initFile(id); 
    538     order[getSeries(id)] = dimOrder; 
    539     String f0 = files[0]; 
    540     reader.swapDimensions(f0, dimOrder); 
    541     sizeZ[getSeries(id)] = reader.getSizeZ(f0); 
    542     sizeC[getSeries(id)] = reader.getSizeC(f0); 
    543     sizeT[getSeries(id)] = reader.getSizeT(f0); 
    544     computeAxisLengths(); 
    545   } 
    546  
    547533  /* @see IFormatReader#getIndex(String, int, int, int) */ 
    548534  public int getIndex(String id, int z, int c, int t) 
     
    571557    if (!id.equals(currentId)) initFile(id); 
    572558    return reader.getMetadata(files[0]); 
     559  } 
     560 
     561  /* @see IFormatReader#getCoreMetadata(String) */ 
     562  public CoreMetadata getCoreMetadata(String id) 
     563    throws FormatException, IOException 
     564  { 
     565    if (!id.equals(currentId)) initFile(id); 
     566    return reader.getCoreMetadata(files[0]); 
    573567  } 
    574568 
     
    781775      setSeries(currentId, i); 
    782776      order[i] = ag[i].getAdjustedOrder(); 
    783       swapDimensions(currentId, order[i]); 
    784777    } 
    785778    setSeries(currentId, oldSeries); 
     
    880873    // configure the reader, in case we haven't done this one yet 
    881874    readers[fno].setSeries(files[fno], reader.getSeries(files[0])); 
    882     readers[fno].swapDimensions(files[fno], order[sno]); 
    883875 
    884876    return new int[] {fno, ino}; 
  • trunk/loci/formats/FormatReader.java

    r2563 r2564  
    9999    metadata = new Hashtable(); 
    100100 
     101    /* debug */ System.out.println("reinitializing core metadata"); 
    101102    core = new CoreMetadata(1); 
    102103    Arrays.fill(core.orderCertain, true); 
     
    394395  } 
    395396 
    396   /* @see IFormatReader#swapDimensions(String, String) */ 
    397   public void swapDimensions(String id, String order) 
    398     throws FormatException, IOException 
    399   { 
    400     if (!id.equals(currentId)) initFile(id); 
    401     if (order == null) return; 
    402     if (order.equals(core.currentOrder[series])) return; 
    403  
    404     int[] dims = new int[5]; 
    405  
    406     int xndx = core.currentOrder[series].indexOf("X"); 
    407     int yndx = core.currentOrder[series].indexOf("Y"); 
    408     int zndx = core.currentOrder[series].indexOf("Z"); 
    409     int cndx = core.currentOrder[series].indexOf("C"); 
    410     int tndx = core.currentOrder[series].indexOf("T"); 
    411  
    412     dims[xndx] = core.sizeX[series]; 
    413     dims[yndx] = core.sizeY[series]; 
    414     dims[zndx] = core.sizeZ[series]; 
    415     dims[cndx] = core.sizeC[series]; 
    416     dims[tndx] = core.sizeT[series]; 
    417  
    418     core.sizeX[series] = dims[order.indexOf("X")]; 
    419     core.sizeY[series] = dims[order.indexOf("Y")]; 
    420     core.sizeZ[series] = dims[order.indexOf("Z")]; 
    421     core.sizeC[series] = dims[order.indexOf("C")]; 
    422     core.sizeT[series] = dims[order.indexOf("T")]; 
    423     core.currentOrder[series] = order; 
    424  
    425     MetadataStore store = getMetadataStore(id); 
    426     store.setPixels(new Integer(core.sizeX[series]),  
    427       new Integer(core.sizeY[series]), new Integer(core.sizeZ[series]),  
    428       new Integer(core.sizeC[series]), new Integer(core.sizeT[series]),  
    429       null, null, order, new Integer(series), null); 
    430   } 
    431  
    432397  /* @see IFormatReader#getIndex(String, int, int, int) */ 
    433398  public int getIndex(String id, int z, int c, int t) 
     
    456421    if (!id.equals(currentId)) initFile(id); 
    457422    return metadata; 
     423  } 
     424 
     425  /* @see IFormatReader#getCoreMetadata(String) */ 
     426  public CoreMetadata getCoreMetadata(String id)  
     427    throws FormatException, IOException 
     428  { 
     429    if (!id.equals(currentId)) initFile(id); 
     430    return core; 
    458431  } 
    459432 
  • trunk/loci/formats/FormatTools.java

    r2563 r2564  
    121121    boolean separate = false; 
    122122    boolean omexml = false; 
    123     boolean ignoreColors = false; 
    124123    boolean normalize = false; 
    125124    boolean fastBlit = false; 
     
    138137          else if (args[i].equals("-stitch")) stitch = true; 
    139138          else if (args[i].equals("-separate")) separate = true; 
    140           else if (args[i].equals("-nocolors")) ignoreColors = true; 
    141139          else if (args[i].equals("-omexml")) omexml = true; 
    142140          else if (args[i].equals("-normalize")) normalize = true; 
     
    180178        "To test read a file in " + format + " format, run:", 
    181179        "  java " + className + " [-nopix] [-nometa] [-thumbs] [-minmax]", 
    182         "    [-merge] [-stitch] [-separate] [-nocolors] [-omexml] [-normalize]", 
     180        "    [-merge] [-stitch] [-separate] [-omexml] [-normalize]", 
    183181        "    [-fast] [-debug] [-range start end] [-series num] [-map id] file", 
    184182        "", 
     
    191189        "   -stitch: stitch files with similar names", 
    192190        " -separate: split RGB image into separate channels", 
    193         " -nocolors: ignore color lookup tables, if present", 
    194191        "   -omexml: populate OME-XML metadata", 
    195192        "-normalize: normalize floating point images*", 
  • trunk/loci/formats/IFormatReader.java

    r2563 r2564  
    203203 
    204204  /** 
    205    * Swaps the dimensions according to the given dimension order.  If the given 
    206    * order is identical to the file's native order, then nothing happens. 
    207    * Note that this method will throw an exception if X and Y do not appear in 
    208    * positions 0 and 1 (although X and Y can be reversed). 
    209    */ 
    210   void swapDimensions(String id, String order) 
    211     throws FormatException, IOException; 
    212  
    213   /** 
    214205   * Gets the rasterized index corresponding 
    215206   * to the given Z, C and T coordinates. 
     
    242233   */ 
    243234  Hashtable getMetadata(String id) throws FormatException, IOException; 
     235 
     236  /** Obtains the core metadata values for the given file. */ 
     237  CoreMetadata getCoreMetadata(String id) throws FormatException, IOException; 
    244238 
    245239  /** 
  • trunk/loci/formats/ImageReader.java

    r2563 r2564  
    347347  } 
    348348 
    349   /* @see IFormatReader#swapDimensions(String, String) */ 
    350   public void swapDimensions(String id, String order) 
    351     throws FormatException, IOException 
    352   { 
    353     getReader(id).swapDimensions(id, order); 
    354   } 
    355  
    356349  /* @see IFormatReader#getIndex(String, int, int, int) */ 
    357350  public int getIndex(String id, int z, int c, int t) 
     
    378371  public Hashtable getMetadata(String id) throws FormatException, IOException { 
    379372    return getReader(id).getMetadata(id); 
     373  } 
     374 
     375  /* @see IFormatReader#getCoreMetadata(String) */ 
     376  public CoreMetadata getCoreMetadata(String id) 
     377    throws FormatException, IOException 
     378  { 
     379    return getReader(id).getCoreMetadata(id); 
    380380  } 
    381381 
  • trunk/loci/formats/ReaderWrapper.java

    r2563 r2564  
    210210  public String getCurrentFile() { return reader.getCurrentFile(); } 
    211211 
    212   public void swapDimensions(String id, String order) 
    213     throws FormatException, IOException 
    214   { 
    215     reader.swapDimensions(id, order); 
    216   } 
    217  
    218212  public int getIndex(String id, int z, int c, int t) 
    219213    throws FormatException, IOException 
     
    238232  } 
    239233 
     234  public CoreMetadata getCoreMetadata(String id) 
     235    throws FormatException, IOException 
     236  { 
     237    return reader.getCoreMetadata(id); 
     238  } 
     239 
    240240  public void setMetadataFiltered(boolean filter) { 
    241241    reader.setMetadataFiltered(filter); 
  • trunk/loci/formats/in/LeicaReader.java

    r2563 r2564  
    7171  /** Number of significant bits per pixel. */ 
    7272  private int[][] validBits; 
     73 
     74  private int[] channelIndices; 
    7375 
    7476  /** Name of current LEI file */ 
     
    9991001    } 
    10001002 
    1001     core = new CoreMetadata(numSeries); 
     1003    //core = new CoreMetadata(numSeries); 
    10021004    Arrays.fill(core.orderCertain, true); 
    10031005 
  • trunk/loci/formats/in/QTReader.java

    r2557 r2564  
    290290  } 
    291291 
    292   /* @see loci.formats.IFormatReader#swapDimensions(String, String) */ 
    293   public void swapDimensions(String id, String order) 
    294     throws FormatException, IOException 
    295   { 
    296     super.swapDimensions(id, order); 
    297     if (useLegacy) legacy.swapDimensions(id, order); 
    298   } 
    299  
    300292  /* @see loci.formats.IFormatReader#openBytes(String, int) */  
    301293  public byte[] openBytes(String id, int no) 
  • trunk/loci/formats/in/ZeissZVIReader.java

    r2557 r2564  
    204204    super.setMetadataStore(store); 
    205205    if (noPOI || needLegacy) legacy.setMetadataStore(store); 
    206   } 
    207  
    208   /* @see loci.formats.IFormatReader#swapDimensions(String, String) */ 
    209   public void swapDimensions(String id, String order) 
    210     throws FormatException, IOException 
    211   { 
    212     if (noPOI || needLegacy) legacy.swapDimensions(id, order); 
    213     else super.swapDimensions(id, order); 
    214206  } 
    215207 
  • trunk/loci/plugins/browser/LociDataBrowser.java

    r2463 r2564  
    5454 
    5555  /** The file format reader used by the plugin. */ 
    56   protected IFormatReader reader; 
     56  protected DimensionSwapper reader; 
    5757 
    5858  /** The file stitcher used by the reader.*/ 
     
    9999  public LociDataBrowser() { 
    100100    fStitch = new FileStitcher(); 
    101     reader = new ChannelSeparator(fStitch); 
     101    reader = new DimensionSwapper(new ChannelSeparator(fStitch)); 
    102102// TODO: macros 
    103103//    macro = new MacroManager(); 
     
    114114  public LociDataBrowser(boolean merged) { 
    115115    fStitch = new FileStitcher(); 
    116     if (merged) reader = new ChannelMerger(fStitch); 
    117     else reader = new ChannelSeparator(fStitch); 
     116    if (merged) reader = new DimensionSwapper(new ChannelMerger(fStitch)); 
     117    else reader = new DimensionSwapper(new ChannelSeparator(fStitch)); 
    118118  } 
    119119 
     
    126126  public LociDataBrowser(IFormatReader r, FileStitcher fs, String name) { 
    127127    virtual = true; 
    128     reader = r; 
     128    reader = new DimensionSwapper(r); 
    129129    fStitch = fs; 
    130130    id = name; 
     
    260260   
    261261  public void toggleMerge() {     
    262     if (reader instanceof ChannelMerger) { 
     262    if (reader.getReader() instanceof ChannelMerger) { 
    263263      IFormatReader parent = ((ReaderWrapper) reader).getReader(); 
    264       reader = new ChannelSeparator(parent); 
     264      reader = new DimensionSwapper(new ChannelSeparator(parent)); 
    265265      run(""); 
    266266    } 
    267     else if (reader instanceof ChannelSeparator) { 
     267    else if (reader.getReader() instanceof ChannelSeparator) { 
    268268      IFormatReader parent = ((ReaderWrapper) reader).getReader(); 
    269       reader = new ChannelMerger(parent); 
     269      reader = new DimensionSwapper(new ChannelMerger(parent)); 
    270270      run(""); 
    271271    } 
     
    277277   
    278278  public boolean isMerged() { 
    279     return reader instanceof ChannelMerger; 
     279    return reader.getReader() instanceof ChannelMerger; 
    280280  } 
    281281 
Note: See TracChangeset for help on using the changeset viewer.