Changeset 4860


Ignore:
Timestamp:
02/27/09 17:15:51 (11 years ago)
Author:
curtis
Message:

Begin refactoring of DeltaVisionReader.initFile to be more modular.

File:
1 edited

Legend:

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

    r4771 r4860  
    135135      new FilterMetadata(getMetadataStore(), isMetadataFiltered()); 
    136136 
     137    // --- read in the image header data --- 
     138 
     139    status("Reading header"); 
     140 
    137141    in = new RandomAccessStream(id); 
    138142 
    139     status("Reading header"); 
    140  
    141     // read in the image header data 
    142143    in.seek(96); 
    143144    in.order(true); 
    144     core[0].littleEndian = in.readShort() == LITTLE_ENDIAN; 
    145  
    146     in.order(isLittleEndian()); 
     145 
     146    boolean little = in.readShort() == LITTLE_ENDIAN; 
     147    in.order(little); 
    147148    in.seek(0); 
    148149 
    149     core[0].sizeX = in.readInt(); 
    150     core[0].sizeY = in.readInt(); 
    151     core[0].imageCount = in.readInt(); 
     150    int sizeX = in.readInt(); 
     151    int sizeY = in.readInt(); 
     152    int imageCount = in.readInt(); 
    152153    int filePixelType = in.readInt(); 
    153154 
    154     addMeta("ImageWidth", getSizeX()); 
    155     addMeta("ImageHeight", getSizeY()); 
    156     addMeta("NumberOfImages", getImageCount()); 
    157     String pixel; 
    158  
    159     switch (filePixelType) { 
    160       case 0: 
    161         pixel = "8 bit unsigned integer"; 
    162         core[0].pixelType = FormatTools.UINT8; 
    163         break; 
    164       case 1: 
    165         pixel = "16 bit signed integer"; 
    166         core[0].pixelType = FormatTools.INT16; 
    167         break; 
    168       case 2: 
    169         pixel = "32 bit floating point"; 
    170         core[0].pixelType = FormatTools.FLOAT; 
    171         break; 
    172       case 3: 
    173         pixel = "16 bit complex"; 
    174         core[0].pixelType = FormatTools.INT16; 
    175         break; 
    176       case 4: 
    177         pixel = "64 bit complex"; 
    178         core[0].pixelType = FormatTools.FLOAT; 
    179         break; 
    180       case 6: 
    181         pixel = "16 bit unsigned integer"; 
    182         core[0].pixelType = FormatTools.UINT16; 
    183         break; 
    184       default: 
    185         pixel = "unknown"; 
    186         core[0].pixelType = FormatTools.UINT8; 
    187     } 
    188  
    189     addMeta("PixelType", pixel); 
    190     addMeta("Sub-image starting point (X)", in.readInt()); 
    191     addMeta("Sub-image starting point (Y)", in.readInt()); 
    192     addMeta("Sub-image starting point (Z)", in.readInt()); 
    193     addMeta("Pixel sampling size (X)", in.readInt()); 
    194     addMeta("Pixel sampling size (Y)", in.readInt()); 
    195     addMeta("Pixel sampling size (Z)", in.readInt()); 
     155    int subImageStartX = in.readInt(); 
     156    int subImageStartY = in.readInt(); 
     157    int subImageStartZ = in.readInt(); 
     158    int pixelSamplingX = in.readInt(); 
     159    int pixelSamplingY = in.readInt(); 
     160    int pixelSamplingZ = in.readInt(); 
    196161 
    197162    float pixX = in.readFloat(); 
    198163    float pixY = in.readFloat(); 
    199164    float pixZ = in.readFloat(); 
    200  
    201     addMeta("X element length (in um)", pixX); 
    202     addMeta("Y element length (in um)", pixY); 
    203     addMeta("Z element length (in um)", pixZ); 
    204     addMeta("X axis angle", in.readFloat()); 
    205     addMeta("Y axis angle", in.readFloat()); 
    206     addMeta("Z axis angle", in.readFloat()); 
    207     addMeta("Column axis sequence", in.readInt()); 
    208     addMeta("Row axis sequence", in.readInt()); 
    209     addMeta("Section axis sequence", in.readInt()); 
     165    float xAxisAngle = in.readFloat(); 
     166    float yAxisAngle = in.readFloat(); 
     167    float zAxisAngle = in.readFloat(); 
     168    int xAxisSeq = in.readInt(); 
     169    int yAxisSeq = in.readInt(); 
     170    int zAxisSeq = in.readInt(); 
    210171 
    211172    in.seek(160); 
     
    215176      type < IMAGE_TYPES.length ? IMAGE_TYPES[type] : "unknown"; 
    216177 
    217     addMeta("Image Type", imageType); 
    218178    int lensID = in.readShort(); 
    219     addMeta("Lens ID Number", lensID); 
    220179 
    221180    in.seek(180); 
    222     core[0].sizeT = in.readShort(); 
    223     addMeta("Number of timepoints", getSizeT()); 
     181 
     182    int sizeT = in.readShort(); 
     183    int realSizeT = sizeT == 0 ? 1 : sizeT; 
    224184 
    225185    int sequence = in.readShort(); 
     
    241201        imageSequence = "ZTW"; 
    242202    } 
     203 
     204    float xTiltAngle = in.readFloat(); 
     205    float yTiltAngle = in.readFloat(); 
     206    float zTiltAngle = in.readFloat(); 
     207 
     208    int sizeC = in.readShort(); 
     209    int realSizeC = sizeC == 0 ? 1 : sizeC; 
     210    int sizeZ = imageCount / (realSizeC * realSizeT); 
     211 
     212    short[] waves = new short[5]; 
     213    for (int i=0; i<waves.length; i++) { 
     214      waves[i] = in.readShort(); 
     215    } 
     216 
     217    float xOrigin = in.readFloat(); 
     218    float yOrigin = in.readFloat(); 
     219    float zOrigin = in.readFloat(); 
     220 
     221    in.skipBytes(4); 
     222 
     223    String[] title = new String[10]; 
     224    for (int i=0; i<title.length; i++) { 
     225      // Make sure that "null" characters are stripped out 
     226      title[i] = in.readString(80).replaceAll("\0", ""); 
     227    } 
     228 
     229    long fp = in.getFilePointer(); 
     230 
     231    in.seek(76); 
     232 
     233    float[] minWave = new float[5]; 
     234    float[] maxWave = new float[5]; 
     235 
     236    minWave[0] = in.readFloat(); 
     237    maxWave[0] = in.readFloat(); 
     238 
     239    float meanWave0 = in.readFloat(); 
     240    int spaceGroupNumber = in.readInt(); 
     241 
     242    extSize = in.readInt(); 
     243 
     244    in.seek(128); 
     245    numIntsPerSection = in.readShort(); 
     246    numFloatsPerSection = in.readShort(); 
     247 
     248    short numSubResSets = in.readShort(); 
     249    short zAxisReductionQuotient = in.readShort(); 
     250 
     251    for (int i=1; i<=3; i++) { 
     252      minWave[i] = in.readFloat(); 
     253      maxWave[i] = in.readFloat(); 
     254    } 
     255 
     256    in.seek(172); 
     257 
     258    minWave[4] = in.readFloat(); 
     259    maxWave[4] = in.readFloat(); 
     260 
     261    // --- populate core metadata --- 
     262 
     263    status("Populating core metadata"); 
     264 
     265    core[0].littleEndian = little; 
     266    core[0].sizeX = sizeX; 
     267    core[0].sizeY = sizeY; 
     268    core[0].imageCount = imageCount; 
     269 
     270    String pixel; 
     271    switch (filePixelType) { 
     272      case 0: 
     273        pixel = "8 bit unsigned integer"; 
     274        core[0].pixelType = FormatTools.UINT8; 
     275        break; 
     276      case 1: 
     277        pixel = "16 bit signed integer"; 
     278        core[0].pixelType = FormatTools.INT16; 
     279        break; 
     280      case 2: 
     281        pixel = "32 bit floating point"; 
     282        core[0].pixelType = FormatTools.FLOAT; 
     283        break; 
     284      case 3: 
     285        pixel = "16 bit complex"; 
     286        core[0].pixelType = FormatTools.INT16; 
     287        break; 
     288      case 4: 
     289        pixel = "64 bit complex"; 
     290        core[0].pixelType = FormatTools.FLOAT; 
     291        break; 
     292      case 6: 
     293        pixel = "16 bit unsigned integer"; 
     294        core[0].pixelType = FormatTools.UINT16; 
     295        break; 
     296      default: 
     297        pixel = "unknown"; 
     298        core[0].pixelType = FormatTools.UINT8; 
     299    } 
     300 
     301    core[0].sizeT = realSizeT; 
     302 
    243303    core[0].dimensionOrder = "XY" + imageSequence.replaceAll("W", "C"); 
    244     addMeta("Image sequence", imageSequence); 
    245  
    246     addMeta("X axis tilt angle", in.readFloat()); 
    247     addMeta("Y axis tilt angle", in.readFloat()); 
    248     addMeta("Z axis tilt angle", in.readFloat()); 
    249  
    250     core[0].sizeC = in.readShort(); 
    251     addMeta("Number of wavelengths", getSizeC()); 
    252     if (getSizeC() == 0) core[0].sizeC = 1; 
    253     if (getSizeT() == 0) core[0].sizeT = 1; 
    254     core[0].sizeZ = getImageCount() / (getSizeC() * getSizeT()); 
    255     addMeta("Number of focal planes", getSizeZ()); 
     304 
     305    core[0].sizeC = realSizeC; 
     306    core[0].sizeZ = sizeZ; 
    256307 
    257308    core[0].rgb = false; 
     
    261312    core[0].falseColor = false; 
    262313 
     314    // --- populate original metadata --- 
     315 
     316    status("Populating original metadata"); 
     317 
     318    addMeta("ImageWidth", sizeX); 
     319    addMeta("ImageHeight", sizeY); 
     320    addMeta("NumberOfImages", imageCount); 
     321 
     322    addMeta("PixelType", pixel); 
     323    addMeta("Sub-image starting point (X)", subImageStartX); 
     324    addMeta("Sub-image starting point (Y)", subImageStartY); 
     325    addMeta("Sub-image starting point (Z)", subImageStartZ); 
     326    addMeta("Pixel sampling size (X)", pixelSamplingX); 
     327    addMeta("Pixel sampling size (Y)", pixelSamplingY); 
     328    addMeta("Pixel sampling size (Z)", pixelSamplingZ); 
     329 
     330    addMeta("X element length (in um)", pixX); 
     331    addMeta("Y element length (in um)", pixY); 
     332    addMeta("Z element length (in um)", pixZ); 
     333    addMeta("X axis angle", xAxisAngle); 
     334    addMeta("Y axis angle", yAxisAngle); 
     335    addMeta("Z axis angle", zAxisAngle); 
     336    addMeta("Column axis sequence", xAxisSeq); 
     337    addMeta("Row axis sequence", yAxisSeq); 
     338    addMeta("Section axis sequence", zAxisSeq); 
     339 
     340    addMeta("Image Type", imageType); 
     341    addMeta("Lens ID Number", lensID); 
     342 
     343    addMeta("Number of timepoints", sizeT); 
     344 
     345    addMeta("Image sequence", imageSequence); 
     346 
     347    addMeta("X axis tilt angle", xTiltAngle); 
     348    addMeta("Y axis tilt angle", yTiltAngle); 
     349    addMeta("Z axis tilt angle", zTiltAngle); 
     350 
     351    addMeta("Number of wavelengths", sizeC); 
     352    addMeta("Number of focal planes", sizeZ); 
     353 
     354    for (int i=0; i<waves.length; i++) { 
     355      addMeta("Wavelength " + (i + 1) + " (in nm)", waves[i]); 
     356    } 
     357 
     358    addMeta("X origin (in um)", xOrigin); 
     359    addMeta("Y origin (in um)", yOrigin); 
     360    addMeta("Z origin (in um)", zOrigin); 
     361 
     362    for (int i=0; i<title.length; i++) addMeta("Title " + (i + 1), title[i]); 
     363 
     364    for (int i=0; i<minWave.length; i++) { 
     365      addMeta("Wavelength " + (i + 1) + " min. intensity", minWave[i]); 
     366      addMeta("Wavelength " + (i + 1) + " max. intensity", maxWave[i]); 
     367    } 
     368 
     369    addMeta("Wavelength 1 mean intensity", meanWave0); 
     370    addMeta("Space group number", spaceGroupNumber); 
     371 
     372    addMeta("Number of Sub-resolution sets", numSubResSets); 
     373    addMeta("Z axis reduction quotient", zAxisReductionQuotient); 
     374 
     375    // --- populate OME metadata --- 
     376 
     377    status("Populating OME metadata"); 
     378 
    263379    MetadataTools.populatePixels(store, this, true); 
    264  
    265     short[] waves = new short[5]; 
    266     for (int i=0; i<waves.length; i++) { 
    267       waves[i] = in.readShort(); 
    268       addMeta("Wavelength " + (i + 1) + " (in nm)", waves[i]); 
    269     } 
    270  
    271     addMeta("X origin (in um)", in.readFloat()); 
    272     addMeta("Y origin (in um)", in.readFloat()); 
    273     addMeta("Z origin (in um)", in.readFloat()); 
    274380 
    275381    MetadataTools.setDefaultCreationDate(store, id, 0); 
     
    279385    store.setImageInstrumentRef("Instrument:0", 0); 
    280386 
    281     String objectiveID = "Objective:" + String.valueOf(lensID); 
     387    String objectiveID = "Objective:" + lensID; 
    282388    store.setObjectiveID(objectiveID, 0, 0); 
    283389    store.setObjectiveSettingsObjective(objectiveID, 0); 
     
    285391    store.setObjectiveImmersion("Unknown", 0, 0); 
    286392 
    287     in.skipBytes(4); 
    288  
    289     String title = null; 
    290     for (int i=1; i<=10; i++) { 
    291       // Make sure that "null" characters are stripped out 
    292       title = in.readString(80).replaceAll("\0", ""); 
    293       addMeta("Title " + i, title); 
    294     } 
    295  
    296     long fp = in.getFilePointer(); 
    297  
    298     in.seek(76); 
    299     readWavelength(0, store); 
    300     addMeta("Wavelength 1 mean intensity", in.readFloat()); 
    301     addMeta("Space group number", in.readInt()); 
    302  
    303     extSize = in.readInt(); 
    304  
    305     in.seek(128); 
    306     numIntsPerSection = in.readShort(); 
    307     numFloatsPerSection = in.readShort(); 
    308  
    309     addMeta("Number of Sub-resolution sets", in.readShort()); 
    310     addMeta("Z axis reduction quotient", in.readShort()); 
    311     readWavelength(1, store); 
    312     readWavelength(2, store); 
    313     readWavelength(3, store); 
    314  
    315     in.seek(172); 
    316     readWavelength(4, store); 
    317  
    318     // ----- The Extended Header data handler begins here ------ 
    319  
    320     status("Reading extended header"); 
    321  
    322     in.seek(fp); 
    323  
    324     setOffsetInfo(sequence, getSizeZ(), getSizeC(), getSizeT()); 
    325     extHdrFields = new DVExtHdrFields[getSizeZ()][getSizeC()][getSizeT()]; 
     393    if (store instanceof IMinMaxStore) { 
     394      IMinMaxStore minMaxStore = (IMinMaxStore) store; 
     395      for (int i=0; i<minWave.length; i++) { 
     396        minMaxStore.setChannelGlobalMinMax(0, minWave[i], maxWave[i], i); 
     397      } 
     398    } 
    326399 
    327400    store.setDimensionsPhysicalSizeX(new Float(pixX), 0, 0); 
     
    330403 
    331404    store.setImageName("", 0); 
    332     if (title == null) title = ""; 
    333     title = title.length() == 0 ? null : title; 
    334     store.setImageDescription(title, 0); 
    335  
    336     ndFilters = new Float[getSizeC()]; 
     405 
     406    String desc = title[0]; 
     407    if (desc != null && desc.length() == 0) desc = null; 
     408    store.setImageDescription(desc, 0); 
     409 
     410    // ----- The Extended Header data handler begins here ------ 
     411 
     412    status("Reading extended header"); 
     413 
     414    in.seek(fp); 
     415 
     416    setOffsetInfo(sequence, sizeZ, realSizeC, realSizeT); 
     417    extHdrFields = new DVExtHdrFields[sizeZ][realSizeC][getSizeT()]; 
     418 
     419    ndFilters = new Float[realSizeC]; 
    337420 
    338421    // if matching log file exists, extract key/value pairs from it 
     
    370453    } 
    371454 
    372     for (int w=0; w<getSizeC(); w++) { 
     455    for (int w=0; w<realSizeC; w++) { 
    373456      store.setLogicalChannelEmWave(new Integer(waves[w]), 0, w); 
    374457      store.setLogicalChannelExWave( 
     
    379462      store.setLogicalChannelNdFilter(ndFilters[w], 0, w); 
    380463    } 
    381  
    382     status("Populating metadata"); 
    383464  } 
    384465 
Note: See TracChangeset for help on using the changeset viewer.