Commit c08fb790 authored by Ian Humphrey's avatar Ian Humphrey
Browse files

BSQ cubes are now read correctly with virtual bands considered for all sizes....

BSQ cubes are now read correctly with virtual bands considered for all sizes. When processing, chunk sizes for BSQ cubes are now determined more accurately. Fixes #1689.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/trunk@5997 41f8697f-d340-4b68-9986-7bafba869bb8
parent f4879388
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -142,6 +142,10 @@ namespace Isis {
   *   @history 2012-12-31 Steven Lambright - Removed 'get' prefix from accessors. Fixes #1356.
   *   @history 2014-06-20 Ian Humphrey - Added checks to statistics() and histogram() to throw
   *                           an error if the cube is unopened. Fixes #2085.
   *   @history 2014-10-06 Ian Humphrey - Added case to unittest when chunk dimensions are the same
   *                           as the buffer shape to ensure virtual bands accessed correctly.
   *                           Added cases to test creating bsq and large bsq cubes.
   *                           References #1689.
   */
  class Cube {
    public:
+61 −0
Original line number Diff line number Diff line
@@ -211,6 +211,67 @@ Reading completely outside virtual band boundaries ...
Reading partially within virtual band boundaries ... 
Comparing results ... 

Testing one line BSQ cube (where chunk dimensions == buffer shape) ... 
Constructing cube ... 

File   = IsisCube_bsqOneLine.cub
Samps  = 3
Lines  = 1
Bands  = 3
Base   = 0
Mult   = 1
Type   = 7
Atchd  = 1
Format = 0
Open   = 1
R/O    = 0
R/W    = 1
Lbytes = 65536

Testing reading ascending repeating virtual bands (1, 2, 2, 3)... 

Testing reading skipped ascending virtual bands (1, 3, 3)... 

Testing reading outside of cube boundaries with virtual bands (1, 5)... 

Testing reading descending virtual bands (3, 1, 3)... 

Testing creating large BSQ where samples exceed 1GB chunk size limit ... 
Constructing cube ... 

File   = IsisCube_largebsq.cub
Samps  = 268435457
Lines  = 2
Bands  = 1
Base   = 0
Mult   = 1
Type   = 7
Atchd  = 1
Format = 0
Open   = 1
R/O    = 0
R/W    = 1
Lbytes = 65536


Testing creating BSQ cube where size of sample pixels exceeds cube's lineCount ... 
Constructing cube ... 

File   = IsisCube_bsq.cub
Samps  = 15000
Lines  = 18000
Bands  = 1
Base   = 0
Mult   = 1
Type   = 7
Atchd  = 1
Format = 0
Open   = 1
R/O    = 0
R/W    = 1
Lbytes = 65536


Testing errors ... 
**PROGRAMMER ERROR** You already have a cube opened.
**PROGRAMMER ERROR** You already have a cube opened.
+36 −12
Original line number Diff line number Diff line
@@ -52,20 +52,17 @@ namespace Isis {
    : CubeIoHandler(dataFile, virtualBandList, labels, alreadyOnDisk) {
    int numSamplesInChunk = sampleCount();
    int numLinesInChunk = 1;
    QList<int> primeFactors;
    
    // The chunk size must evenly divide into the cube size...
    if(lineCount() < 1024)
      numLinesInChunk = lineCount();
    else {
      int attemptedSize = 1024;
    // we want our chunk sizes to be less than 1GB
    int sizeLimit = 1024 * 1024 * 1024;
    int maxNumLines = (sizeLimit) / (SizeOf(pixelType()) * numSamplesInChunk);
    
      while(numLinesInChunk == 1 && attemptedSize > 1) {
        if(lineCount() % attemptedSize == 0)
          numLinesInChunk = attemptedSize;
        else
          attemptedSize /= 2;
      }
    }
    // we've exceed our sizeLimit; increase our limit so we can process an entire line
    if (maxNumLines == 0) 
      maxNumLines = 1;
    
    numLinesInChunk = findGoodSize(maxNumLines, lineCount());
    
    setChunkSizes(numSamplesInChunk, numLinesInChunk, 1);
  }
@@ -135,6 +132,33 @@ namespace Isis {
  }

  
  /**
   * This method attempts to compute a good chunk line size. Chunk band size is
   * always 1 and chunk sample size is always number of samples in the cube for this format.
   * 
   * @param maxSize The largest allowed size of a chunk dimension
   * @param dimensionSize The cube's size for the chunk size we are trying to calculate
   *     (number of lines)
   * @return The calculated chunk size for the dimension given
   */
  int CubeBsqHandler::findGoodSize(int maxSize, int dimensionSize) const {
    int chunkDimensionSize;
    
    if (dimensionSize <= maxSize) {
      chunkDimensionSize = dimensionSize;
    }
    else {
      // find largest divisor of dimension size so chunks fit into cube uniformly
      int greatestDivisor = maxSize;
      while (dimensionSize % greatestDivisor > 0) {
        greatestDivisor--;
      }
      chunkDimensionSize = greatestDivisor;
    }
    return chunkDimensionSize;
  }


  /**
   * This is a helper method that goes from chunk to file position.
   *
+4 −0
Original line number Diff line number Diff line
@@ -49,6 +49,9 @@ namespace Isis {
   *   @history 2011-07-18 Jai Rideout and Steven Lambright - Added
   *                           unimplemented copy constructor and assignment
   *                           operator.
   *   @history 2014-09-16 Ian Humphrey - Increased size limit for determining chunk sizes.
   *                           Added findGoodSize method to better calculate number of lines in 
   *                           chunks for bsq cubes. References #1689.
   */
  class CubeBsqHandler : public CubeIoHandler {
    public:
@@ -79,6 +82,7 @@ namespace Isis {
       */
      CubeBsqHandler &operator=(const CubeBsqHandler &other);
      
      int findGoodSize(int maxSize, int dimensionSize) const;
      BigInt getChunkStartByte(const RawCubeChunk &chunk) const;
  };
}
+7 −1
Original line number Diff line number Diff line
@@ -271,6 +271,7 @@ namespace Isis {
    int bufferLineCount = bufferToFill.LineDimension();
    int bufferBandCount = bufferToFill.BandDimension();

    // our chunk dimensions are same as buffer shape dimensions
    if (bufferSampleCount == m_samplesInChunk &&
        bufferLineCount == m_linesInChunk &&
        bufferBandCount == m_bandsInChunk) {
@@ -282,11 +283,16 @@ namespace Isis {
      int bufferEndLine = bufferStartLine + bufferLineCount - 1;
      int bufferEndBand = bufferStartBand + bufferBandCount - 1;
    
      // make sure we access the correct band
      int startBand = bufferStartBand - 1;
      if (m_virtualBands)
        startBand = m_virtualBands->at(bufferStartBand - 1);

      int expectedChunkIndex =
          ((bufferStartSample - 1) / getSampleCountInChunk()) +
          ((bufferStartLine - 1) / getLineCountInChunk()) *
            getChunkCountInSampleDimension() +
          ((bufferStartBand - 1) / getBandCountInChunk()) *
          ((startBand - 1) / getBandCountInChunk()) *
            getChunkCountInSampleDimension() *
            getChunkCountInLineDimension();

Loading