Changeset 7284


Ignore:
Timestamp:
12/01/10 07:57:18 (10 years ago)
Author:
callan
Message:

Fixed minMaxDone population. Much more thorough test case that includes IMinMaxStore testing. (See  omero:#3599)

Location:
trunk/components/bio-formats
Files:
2 edited

Legend:

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

    r7283 r7284  
    342342      } 
    343343    } 
    344     minMaxDone[series]++; 
     344    minMaxDone[series] = Math.max(minMaxDone[series], ndx + 1); 
    345345 
    346346    if (minMaxDone[getSeries()] == getImageCount() && minMaxStore != null) { 
  • trunk/components/bio-formats/test/loci/formats/utests/MinMaxCalculatorTest.java

    r7283 r7284  
    2424package loci.formats.utests; 
    2525 
    26 import static org.testng.AssertJUnit.assertEquals; 
    27 import static org.testng.AssertJUnit.assertNotNull; 
     26import static org.testng.AssertJUnit.*; 
    2827 
    2928import java.io.IOException; 
     29import java.util.ArrayList; 
    3030import java.util.Arrays; 
     31import java.util.List; 
    3132 
    3233import loci.common.Location; 
     
    3536import loci.formats.MinMaxCalculator; 
    3637import loci.formats.in.FakeReader; 
     38import loci.formats.meta.IMinMaxStore; 
    3739 
    3840import org.testng.annotations.AfterMethod; 
     
    6062  private MinMaxCalculator minMaxCalculator; 
    6163 
     64  private TestMinMaxStore minMaxStore; 
     65 
    6266  private static int fullPlaneCallIndex; 
    6367 
     
    7680    reader = new MinMaxCalculatorTestReader(); 
    7781    reader.setId(TEST_FILE); 
     82    minMaxStore = new TestMinMaxStore(); 
    7883    minMaxCalculator = new MinMaxCalculator(reader); 
     84    minMaxCalculator.setMinMaxStore(minMaxStore); 
    7985    sizeX = reader.getSizeX(); 
    8086    sizeY = reader.getSizeY(); 
    8187    bpp = FormatTools.getBytesPerPixel(reader.getPixelType()); 
    8288    planeSize = sizeY * sizeY * bpp; 
    83  
    8489  } 
    8590 
     
    8893    minMaxCalculator.close(); 
    8994    reader.close(); 
     95  } 
     96 
     97  private void assertMinMax(double minimum, double maximum) throws Exception { 
     98    Double[] min = minMaxCalculator.getPlaneMinimum(0); 
     99    Double[] max = minMaxCalculator.getPlaneMaximum(0); 
     100    Double globalMin = minMaxCalculator.getChannelGlobalMinimum(0); 
     101    Double globalMax = minMaxCalculator.getChannelGlobalMaximum(0); 
     102    Double knownGlobalMin = minMaxCalculator.getChannelKnownMinimum(0); 
     103    Double knownGlobalMax = minMaxCalculator.getChannelKnownMaximum(0); 
     104    assertTrue(minMaxCalculator.isMinMaxPopulated()); 
     105    assertNotNull(min); 
     106    assertNotNull(max); 
     107    assertNotNull(globalMin); 
     108    assertNotNull(globalMax); 
     109    assertNotNull(knownGlobalMin); 
     110    assertNotNull(knownGlobalMax); 
     111    assertEquals(1, min.length); 
     112    assertEquals(1, max.length); 
     113    assertEquals(minimum, min[0]); 
     114    assertEquals(maximum, max[0]); 
     115    assertEquals(minimum, globalMin); 
     116    assertEquals(maximum, globalMax); 
     117    assertEquals(minimum, knownGlobalMin); 
     118    assertEquals(maximum, knownGlobalMax); 
     119    List<List<double[]>> seriesGlobalMinimaMaxima =  
     120      minMaxStore.seriesGlobalMinimaMaxima; 
     121    assertEquals(1, seriesGlobalMinimaMaxima.size()); 
     122    List<double[]> channelGlobalMinimaMaxima =  
     123      seriesGlobalMinimaMaxima.get(0); 
     124    assertEquals(1, channelGlobalMinimaMaxima.size()); 
     125    double[] channelGlobalMinMax = channelGlobalMinimaMaxima.get(0); 
     126    channelGlobalMinMax[0] = minimum; 
     127    channelGlobalMinMax[1] = maximum; 
    90128  } 
    91129 
     
    106144  public void testValidMinMax() throws Exception { 
    107145    minMaxCalculator.openBytes(0); 
    108     Double[] min = minMaxCalculator.getPlaneMinimum(0); 
    109     Double[] max = minMaxCalculator.getPlaneMaximum(0); 
    110     assertNotNull(min); 
    111     assertNotNull(max); 
    112     assertEquals(1, min.length); 
    113     assertEquals(1, max.length); 
    114     assertEquals(-2.0, min[0]); 
    115     assertEquals(101.0, max[0]); 
    116   } 
    117    
     146    assertMinMax(-2.0, 101.0); 
     147  } 
     148 
    118149  @Test 
    119150  public void testValidMinMaxDoesntRecalculateOnFullPlane() throws Exception { 
    120151    minMaxCalculator.openBytes(0); 
    121152    minMaxCalculator.openBytes(0); 
    122     Double[] min = minMaxCalculator.getPlaneMinimum(0); 
    123     Double[] max = minMaxCalculator.getPlaneMaximum(0); 
    124     assertNotNull(min); 
    125     assertNotNull(max); 
    126     assertEquals(1, min.length); 
    127     assertEquals(1, max.length); 
    128     assertEquals(-2.0, min[0]); 
    129     assertEquals(101.0, max[0]); 
     153    assertMinMax(-2.0, 101.0); 
    130154  } 
    131155 
     
    135159    int halfway = sizeY / 2; 
    136160    minMaxCalculator.openBytes(0, buf, 0, 0, sizeX, halfway); 
    137     Double[] min = minMaxCalculator.getPlaneMinimum(0); 
    138     Double[] max = minMaxCalculator.getPlaneMaximum(0); 
    139     assertNotNull(min); 
    140     assertNotNull(max); 
    141     assertEquals(1, min.length); 
    142     assertEquals(1, max.length); 
    143     assertEquals(-1.0, min[0]); 
    144     assertEquals(1.0, max[0]); 
     161    assertMinMax(-1.0, 1.0); 
    145162  } 
    146163 
     
    150167    int halfway = sizeY / 2; 
    151168    minMaxCalculator.openBytes(0, buf, 0, halfway, sizeX, halfway); 
    152     Double[] min = minMaxCalculator.getPlaneMinimum(0); 
    153     Double[] max = minMaxCalculator.getPlaneMaximum(0); 
    154     assertNotNull(min); 
    155     assertNotNull(max); 
    156     assertEquals(1, min.length); 
    157     assertEquals(1, max.length); 
    158     assertEquals(-2.0, min[0]); 
    159     assertEquals(2.0, max[0]); 
     169    assertMinMax(-2.0, 2.0); 
    160170  } 
    161171 
     
    166176    minMaxCalculator.openBytes(0, buf, 0, 0, sizeX, halfway); 
    167177    minMaxCalculator.openBytes(0, buf, 0, halfway, sizeX, halfway); 
    168     Double[] min = minMaxCalculator.getPlaneMinimum(0); 
    169     Double[] max = minMaxCalculator.getPlaneMaximum(0); 
    170     assertNotNull(min); 
    171     assertNotNull(max); 
    172     assertEquals(1, min.length); 
    173     assertEquals(1, max.length); 
    174     assertEquals(-2.0, min[0]); 
    175     assertEquals(2.0, max[0]); 
     178    assertMinMax(-2.0, 2.0); 
    176179  } 
    177180 
     
    182185    minMaxCalculator.openBytes(0, buf, 0, halfway, sizeX, halfway); 
    183186    minMaxCalculator.openBytes(0, buf, 0, 0, sizeX, halfway); 
    184     Double[] min = minMaxCalculator.getPlaneMinimum(0); 
    185     Double[] max = minMaxCalculator.getPlaneMaximum(0); 
    186     assertNotNull(min); 
    187     assertNotNull(max); 
    188     assertEquals(1, min.length); 
    189     assertEquals(1, max.length); 
    190     assertEquals(-2.0, min[0]); 
    191     assertEquals(2.0, max[0]); 
     187    assertMinMax(-2.0, 2.0); 
     188  } 
     189 
     190  /** 
     191   * A testing implementation of {@link loci.formats.meta.IMinMaxStore} that 
     192   * we'll use to ensure that the various methods are called with the correct 
     193   * parameters. 
     194   *  
     195   * @author Chris Allan <callan at blackcat dot ca> 
     196   * 
     197   */ 
     198  class TestMinMaxStore implements IMinMaxStore { 
     199 
     200    public List<List<double[]>> seriesGlobalMinimaMaxima =  
     201      new ArrayList<List<double[]>>(); 
     202 
     203    /** 
     204     * @see loci.formats.meta.IMinMaxStore#setChannelGlobalMinMax(int, double, double, int) 
     205     */ 
     206    public void setChannelGlobalMinMax(int channel, double minimum, 
     207                                       double maximum, int series) { 
     208      if (seriesGlobalMinimaMaxima.size() == series) { 
     209        seriesGlobalMinimaMaxima.add(new ArrayList<double[]>()); 
     210      } 
     211      List<double[]> channelGlobalMinimaMaxima =  
     212        seriesGlobalMinimaMaxima.get(series); 
     213      if (channelGlobalMinimaMaxima.size() == channel) { 
     214        channelGlobalMinimaMaxima.add(new double[2]); 
     215      } 
     216      double[] channelGlobalMinMax = channelGlobalMinimaMaxima.get(channel); 
     217      channelGlobalMinMax[0] = minimum; 
     218      channelGlobalMinMax[1] = maximum; 
     219    } 
    192220  } 
    193221 
Note: See TracChangeset for help on using the changeset viewer.