Skip to content

Commit f9cbe67

Browse files
committed
Fix cube read loops
1 parent e7fd6f3 commit f9cbe67

File tree

1 file changed

+38
-11
lines changed

1 file changed

+38
-11
lines changed

isis/src/base/objs/Cube/CubeIoHandler.cpp

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,7 @@ namespace Isis {
13431343
// Scale the sampleand line increment, only necessary in read for Q apps
13441344
int lineIncrement = (double)output.LineDimension() / (double)output.LineDimensionScaled();
13451345
int sampleIncrement = (double)output.SampleDimension() / (double)output.SampleDimensionScaled();
1346-
1346+
13471347
for(int z = startZ; z <= endZ; z++) {
13481348
const int &bandIntoChunk = z - chunkStartBand;
13491349
int virtualBand = z;
@@ -1353,18 +1353,34 @@ namespace Isis {
13531353
if(virtualBand != 0 && virtualBand >= bufferBand &&
13541354
virtualBand <= bufferBand + bufferBands - 1) {
13551355

1356-
for(int y = startY; y < endY; y = y + lineIncrement) {
1356+
int bufferLineIndex = -1;
1357+
for(int y = startY; y < endY;) {
13571358
const int &lineIntoChunk = y - chunkStartLine;
1359+
int nextLineBufferIndex = output.Index(startX, y, virtualBand);
13581360

1359-
for(int x = startX; x < endX; x = x + sampleIncrement) {
1361+
int bufferSampleIndex = -1;
1362+
for(int x = startX; x < endX;) {
1363+
int nextSampleBufferIndex = output.Index(x, y, virtualBand);
13601364
const int &sampleIntoChunk = x - chunkStartSample;
1361-
int bufferIndex = output.Index(x, y, virtualBand);
1365+
// Handle sample iteration
1366+
// If we continue to compute the same bufferIndex just iterate by 1
1367+
// If we compute the next index, increment by the
1368+
// floored sample increment and read the DN value
1369+
// at newly computed index
1370+
if (bufferSampleIndex == nextSampleBufferIndex) {
1371+
x++;
1372+
continue;
1373+
}
1374+
else {
1375+
x += sampleIncrement;
1376+
bufferSampleIndex = nextSampleBufferIndex;
1377+
}
13621378

13631379
const int &chunkIndex = sampleIntoChunk +
13641380
(chunkLineSize * lineIntoChunk) +
13651381
(chunkBandSize * bandIntoChunk);
13661382

1367-
double &bufferVal = buffersDoubleBuf[bufferIndex];
1383+
double &bufferVal = buffersDoubleBuf[bufferSampleIndex];
13681384

13691385
if(m_pixelType == Real) {
13701386
float raw = ((float *)chunkBuf)[chunkIndex];
@@ -1389,7 +1405,7 @@ namespace Isis {
13891405
bufferVal = LOW_REPR_SAT8;
13901406
}
13911407

1392-
((float *)buffersRawBuf)[bufferIndex] = raw;
1408+
((float *)buffersRawBuf)[bufferSampleIndex] = raw;
13931409
}
13941410

13951411
else if(m_pixelType == SignedWord) {
@@ -1415,7 +1431,7 @@ namespace Isis {
14151431
bufferVal = LOW_REPR_SAT8;
14161432
}
14171433

1418-
((short *)buffersRawBuf)[bufferIndex] = raw;
1434+
((short *)buffersRawBuf)[bufferSampleIndex] = raw;
14191435
}
14201436

14211437

@@ -1446,7 +1462,7 @@ namespace Isis {
14461462
bufferVal = LOW_REPR_SAT8;
14471463
}
14481464

1449-
((unsigned short *)buffersRawBuf)[bufferIndex] = raw;
1465+
((unsigned short *)buffersRawBuf)[bufferSampleIndex] = raw;
14501466
}
14511467

14521468
else if(m_pixelType == UnsignedInteger) {
@@ -1477,7 +1493,7 @@ namespace Isis {
14771493
bufferVal = LOW_REPR_SAT8;
14781494
}
14791495

1480-
((unsigned int *)buffersRawBuf)[bufferIndex] = raw;
1496+
((unsigned int *)buffersRawBuf)[bufferSampleIndex] = raw;
14811497

14821498

14831499

@@ -1496,10 +1512,21 @@ namespace Isis {
14961512
bufferVal = (double) raw * m_multiplier + m_base;
14971513
}
14981514

1499-
((unsigned char *)buffersRawBuf)[bufferIndex] = raw;
1515+
((unsigned char *)buffersRawBuf)[bufferSampleIndex] = raw;
15001516
}
1517+
}
15011518

1502-
bufferIndex++;
1519+
// Handle line iteration
1520+
// If we continue to compute the same bufferIndex just iterate by 1
1521+
// If we compute a next index, increment by the floored
1522+
// line increment
1523+
if (bufferLineIndex == nextLineBufferIndex) {
1524+
y++;
1525+
continue;
1526+
}
1527+
else {
1528+
y += lineIncrement;
1529+
bufferLineIndex = nextLineBufferIndex;
15031530
}
15041531
}
15051532
}

0 commit comments

Comments
 (0)