Exemplo n.º 1
0
  /*
   * Makes sure calculation of IJ1 channels is correctly invertible
   */
  @Test
  public void testRasterization() {
    final long[][] dimsList = {{1, 1, 1}, {1, 2, 3}, {2, 3, 4}, {5, 4, 3}, {4, 2, 7}};
    final AxisType[] axes = {Axes.CHANNEL, SCIFIOAxes.SPECTRA, SCIFIOAxes.FREQUENCY};
    for (long[] dims : dimsList) {
      // setup
      long numChannels = 1;
      for (long dim : dims) numChannels *= dim;

      // test from long index back to long index
      for (long channel = 0; channel < numChannels; channel++) {
        long[] channelPositions = new long[dims.length];
        LegacyUtils.fillChannelIndices(dims, axes, channel, channelPositions);
        long ij1Pos = LegacyUtils.calcIJ1ChannelPos(dims, axes, channelPositions);
        assertEquals(channel, ij1Pos);
      }

      // test from long[] index back to long[] index
      long[] channelPositions1 = new long[dims.length];
      long[] channelPositions2 = new long[dims.length];
      Extents extents = new Extents(dims);
      Position pos = extents.createPosition();
      while (pos.hasNext()) {
        pos.fwd();
        pos.localize(channelPositions1);
        long ij1Channel = LegacyUtils.calcIJ1ChannelPos(dims, axes, channelPositions1);
        LegacyUtils.fillChannelIndices(dims, axes, ij1Channel, channelPositions2);
        for (int i = 0; i < channelPositions1.length; i++)
          assertEquals(channelPositions1[i], channelPositions2[i]);
      }
    }
  }