Changeset 1750


Ignore:
Timestamp:
11/06/06 13:35:47 (13 years ago)
Author:
curtis
Message:

Finish initial axis guesser implementation;
flesh out isOrderCertain implementation for relevant readers.

Location:
trunk/loci/formats
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/formats/AxisGuesser.java

    r1748 r1750  
    4040  // -- Constants -- 
    4141 
     42  /** Axis type for unclassified axes. */ 
     43  public static final int UNKNOWN_AXIS = 0; 
     44 
    4245  /** Axis type for focal planes. */ 
    4346  public static final int Z_AXIS = 1; 
     
    4851  /** Axis type for channels. */ 
    4952  public static final int C_AXIS = 3; 
    50  
    51   /** Prefix endings indicating time dimension. */ 
    52   protected static final String[] T = {"t", "tl", "tp"}; 
    5353 
    5454  /** Prefix endings indicating space dimension. */ 
     
    5757  }; 
    5858 
     59  /** Prefix endings indicating time dimension. */ 
     60  protected static final String[] T = {"t", "tl", "tp"}; 
     61 
    5962  /** Prefix endings indicating channel dimension. */ 
    6063  protected static final String[] C = {"c", "ch", "w"}; 
    6164 
     65  protected static final BigInteger TWO = new BigInteger("2"); 
     66  protected static final BigInteger THREE = new BigInteger("2"); 
    6267 
    6368  // -- Fields -- 
     
    105110    int[] count = fp.getCount(); 
    106111    axes = new int[count.length]; 
     112    boolean foundZ = false, foundT = false, foundC = false; 
    107113 
    108114    // -- 1) fill in "known" axes based on known patterns and conventions -- 
    109115 
    110     for (int i=0; i<prefixes.length; i++) { 
     116    for (int i=0; i<axes.length; i++) { 
    111117      String p = prefixes[i]; 
    112118 
    113119      // strip trailing digits and divider characters 
    114       p = p.replaceFirst("[\\d -_\\.]+$", ""); 
    115  
    116       // strip off trailing alphanumeric characters 
    117  
    118       // CTR START HERE 
    119       // 
    120       // strip off trailing non-alphabetic characters 
    121       // then pull off only trailing alphabetic characters 
    122       // compare pulled off string to known Z, C and T suffixes 
    123       // if match is found, we *know* a given dimension 
    124       // 
    125       // check for special 2-3 channel case in Bio-Rad files 
     120      char[] c = p.toCharArray(); 
     121      int l = c.length - 1; 
     122      while (l >= 0 && (c[l] >= '0' && c[l] <= '9' || 
     123        c[l] == ' ' || c[l] == '-' || c[l] == '_' || c[l] == '.')) 
     124      { 
     125        l--; 
     126      } 
     127 
     128      // useful prefix segment consists of trailing alphanumeric characters 
     129      int f = l; 
     130      while (f >= 0 && 
     131        (c[f] >= 'A' && c[f] <= 'Z' || c[f] >= 'a' && c[f] <= 'z')) 
     132      { 
     133        f--; 
     134      } 
     135      System.out.println("#" + i + ": old prefix = " + p);//TEMP 
     136      p = p.substring(f + 1, l + 1); 
     137      System.out.println("#" + i + ": new prefix = " + p);//TEMP 
     138 
     139      boolean isZ = false, isT = false, isC = false; 
     140 
     141      // check against known Z prefixes 
     142      for (int j=0; j<Z.length; j++) { 
     143        if (p.equals(Z[j])) { 
     144          axes[i] = Z_AXIS; 
     145          foundZ = true; 
     146          break; 
     147        } 
     148      } 
     149      if (axes[i] != UNKNOWN_AXIS) continue; 
     150 
     151      // check against known T prefixes 
     152      for (int j=0; j<T.length; j++) { 
     153        if (p.equals(T[j])) { 
     154          axes[i] = T_AXIS; 
     155          foundT = true; 
     156          break; 
     157        } 
     158      } 
     159      if (axes[i] != UNKNOWN_AXIS) continue; 
     160 
     161      // check against known C prefixes 
     162      for (int j=0; j<C.length; j++) { 
     163        if (p.equals(C[j])) { 
     164          axes[i] = C_AXIS; 
     165          foundC = true; 
     166          break; 
     167        } 
     168      } 
     169      if (axes[i] != UNKNOWN_AXIS) continue; 
     170 
     171      // check special case: <2-3> (Bio-Rad PIC) 
     172      if (first[i].equals(TWO) && last[i].equals(THREE) && 
     173        step[i].equals(BigInteger.ONE)) 
     174      { 
     175        axes[i] = C_AXIS; 
     176        foundC = true; 
     177        break; 
     178      } 
    126179    } 
    127180 
    128 // known internal axes (ZCT) have isCertain == true 
    129 // known dimensional axes have a known pattern or convention 
    130 // After that, we are left with only unknown slots, which we must guess. 
    131 //  
    132  
    133181    // -- 2) check for special cases where dimension order should be swapped -- 
    134182 
    135 //      * if a Z block was found, but not a T block: 
    136 //          if !isOrderCertain, and sizeZ > 1, and sizeT == 1, swap 'em 
    137 //      * else if a T block was found, but not a Z block: 
    138 //          if !isOrderCertain and sizeT > 1, and sizeZ == 1, swap 'em 
     183    if (!isCertain) { // only switch if dimension order is uncertain 
     184      if (foundZ && !foundT && sizeZ > 1 && sizeT == 1 || 
     185        foundT && !foundZ && sizeT > 1 && sizeZ == 1) 
     186      { 
     187        // swap Z and T dimensions 
     188        int indexZ = newOrder.indexOf('Z'); 
     189        int indexT = newOrder.indexOf('T'); 
     190        char[] c = newOrder.toCharArray(); 
     191        c[indexZ] = 'T'; 
     192        c[indexT] = 'Z'; 
     193        newOrder = new String(c); 
     194        int s = sizeT; 
     195        sizeT = sizeZ; 
     196        sizeZ = s; 
     197      } 
     198    } 
    139199 
    140200    // -- 3) fill in remaining axis types -- 
    141201 
    142 //    Set canBeZ to true iff no Z block is assigned and sizeZ == 1. 
    143 //    Set canBeT to true iff no T block is assigned and sizeT == 1. 
    144 //    Go through the blocks in order from left to right: 
    145 //      * If canBeZ, assign Z and set canBeZ to false. 
    146 //      * If canBeT, assign T and set canBeT to false. 
    147 //      * Otherwise, assign C. 
     202    boolean canBeZ = !foundZ && sizeZ == 1; 
     203    boolean canBeT = !foundT && sizeT == 1; 
     204 
     205    for (int i=0; i<axes.length; i++) { 
     206      if (axes[i] != UNKNOWN_AXIS) continue; 
     207 
     208      if (canBeZ) { 
     209        axes[i] = Z_AXIS; 
     210        canBeZ = false; 
     211      } 
     212      else if (canBeT) { 
     213        axes[i] = T_AXIS; 
     214        canBeT = false; 
     215      } 
     216      else axes[i] = C_AXIS; 
     217    } 
    148218  } 
    149219 
     
    246316 
    247317// INPUTS: file pattern, dimOrder, sizeZ, sizeT, sizeC, isCertain 
    248 //  
     318// 
    249319// 1) Fill in all "known" dimensional axes based on known patterns and 
    250320//    conventions 
     
    252322//      * known dimensional axes have a known pattern or convention 
    253323//    After that, we are left with only unknown slots, which we must guess. 
    254 //  
     324// 
    255325// 2) First, we decide whether we really "believe" the reader. There is a 
    256326//    special case where we may decide that it got Z and T mixed up: 
     
    261331//    At this point, we can (have to) trust the internal ordering, and use it 
    262332//    to decide how to fill in the remaining dimensional blocks. 
    263 //  
     333// 
    264334// 3) Set canBeZ to true iff no Z block is assigned and sizeZ == 1. 
    265335//    Set canBeT to true iff no T block is assigned and sizeT == 1. 
     
    268338//      * If canBeT, assign T and set canBeT to false. 
    269339//      * Otherwise, assign C. 
    270 //  
     340// 
    271341// OUTPUTS: list of axis assignments, new dimOrder 
  • trunk/loci/formats/FormatReader.java

    r1747 r1750  
    9797  protected int[] sizeX, sizeY, sizeZ, sizeC, sizeT, pixelType; 
    9898  protected String[] currentOrder; 
    99   protected boolean orderCertain; 
     99  protected boolean[] orderCertain; 
    100100 
    101101  /** Whether or not we're doing channel stat calculation (no by default). */ 
     
    140140    pixelType = new int[1]; 
    141141    currentOrder = new String[1]; 
    142     orderCertain = true; 
     142    orderCertain = new boolean[] {true}; 
    143143 
    144144    // reinitialize the MetadataStore 
     
    250250  public boolean isOrderCertain(String id) throws FormatException, IOException { 
    251251    if (!id.equals(currentId)) initFile(id); 
    252     return orderCertain; 
     252    return orderCertain[series]; 
    253253  } 
    254254 
     
    609609      boolean little = reader.isLittleEndian(id); 
    610610      String dimOrder = reader.getDimensionOrder(id); 
     611      boolean orderCertain = reader.isOrderCertain(id); 
    611612      int pixelType = reader.getPixelType(id); 
    612613 
     
    632633      System.out.println("\tEndianness = " + 
    633634        (little ? "intel (little)" : "motorola (big)")); 
    634       System.out.println("\tDimension order = " + dimOrder); 
     635      System.out.println("\tDimension order = " + dimOrder + 
     636        (orderCertain ? " (certain)" : " (uncertain)")); 
    635637      System.out.println("\tPixel type = " + getPixelTypeString(pixelType)); 
    636638      if (doMeta) { 
  • trunk/loci/formats/in/BaseTiffReader.java

    r1738 r1750  
    526526 
    527527      currentOrder[0] = "XYCZT"; 
     528      orderCertain[0] = false; 
    528529    } 
    529530    catch (Exception e) { } 
  • trunk/loci/formats/in/BioRadReader.java

    r1673 r1750  
    432432    sizeT[0] = nt; 
    433433    currentOrder[0] = order; 
     434    orderCertain[0] = false; 
    434435 
    435436    store.setPixels( 
  • trunk/loci/formats/in/LIFReader.java

    r1719 r1750  
    2727import java.awt.image.BufferedImage; 
    2828import java.io.*; 
    29 import java.util.Hashtable; 
    30 import java.util.StringTokenizer; 
    31 import java.util.Vector; 
     29import java.util.*; 
    3230import loci.formats.*; 
    3331 
     
    480478    pixelType = new int[numDatasets]; 
    481479    currentOrder = new String[numDatasets]; 
     480    orderCertain = new boolean[numDatasets]; 
     481    Arrays.fill(orderCertain, true); 
    482482 
    483483    for (int i=0; i<numDatasets; i++) { 
  • trunk/loci/formats/in/LeicaReader.java

    r1718 r1750  
    2727import java.awt.image.BufferedImage; 
    2828import java.io.*; 
    29 import java.util.Hashtable; 
    30 import java.util.Vector; 
     29import java.util.*; 
    3130import loci.formats.*; 
    3231 
     
    788787    pixelType = new int[numSeries]; 
    789788    currentOrder = new String[numSeries]; 
     789    orderCertain = new boolean[numSeries]; 
     790    Arrays.fill(orderCertain, true); 
    790791 
    791792    try { 
  • trunk/loci/formats/in/OMEXMLReader.java

    r1681 r1750  
    2727import java.awt.image.BufferedImage; 
    2828import java.io.*; 
    29 import java.util.Hashtable; 
    30 import java.util.Vector; 
     29import java.util.*; 
    3130import java.util.zip.*; 
    3231import loci.formats.*; 
     
    415414    sizeT = numT; 
    416415    currentOrder = order; 
     416    orderCertain = new boolean[currentOrder.length]; 
     417    Arrays.fill(orderCertain, true); 
    417418  } 
    418419 
  • trunk/loci/formats/in/OpenlabReader.java

    r1718 r1750  
    2727import java.awt.image.BufferedImage; 
    2828import java.io.*; 
     29import java.util.Arrays; 
    2930import java.util.Vector; 
    3031import loci.formats.*; 
     
    620621    pixelType = new int[numSeries]; 
    621622    currentOrder = new String[numSeries]; 
     623    orderCertain = new boolean[numSeries]; 
     624    Arrays.fill(orderCertain, true); 
    622625 
    623626    // populate MetadataStore 
Note: See TracChangeset for help on using the changeset viewer.