Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion isis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ if(NOT CMAKE_BUILD_TYPE)
endif()

if(APPLE)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0 -fsanitize=address")
else()
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -Og")
endif()
Expand Down
77 changes: 43 additions & 34 deletions isis/src/base/objs/Buffer/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,17 @@ namespace Isis {
if (p_nsampsScaled <= 0) {
p_nsampsScaled = 1;
}
if (int((p_nsamps - 1) * p_scale) == p_nsampsScaled) {
p_nsampsScaled += 1;
}

p_nlinesScaled = int(p_nlines * p_scale);
if (p_nlinesScaled <= 0) {
p_nlinesScaled = 1;
}
if (int((p_nlines - 1) * p_scale) == p_nlinesScaled) {
p_nlinesScaled += 1;
}

p_npixels = (p_nsampsScaled * p_nlinesScaled) * p_nbands;

Expand Down Expand Up @@ -326,14 +333,14 @@ namespace Isis {

// If one rectangle is on left side of other
// if (l1.x > r2.x || l2.x > r1.x)
if (p_line > in.p_line + in.p_nlines ||
in.p_line > p_line + p_nlines)
if (p_line >= in.p_line + in.p_nlines ||
in.p_line >= p_line + p_nlines)
isSubareaOfIn = false;

// If one rectangle is above other
// if (r1.y > l2.y || r2.y > l1.y)
if (p_sample + p_nsamps < in.p_sample ||
in.p_sample + in.p_nsamps < p_sample)
if (p_sample >= in.p_sample + in.p_nsamps ||
in.p_sample >= p_sample + p_nsamps)
isSubareaOfIn = false;

if (isSubareaOfIn) {
Expand All @@ -345,39 +352,41 @@ namespace Isis {

int firstBand = max(in.p_band, p_band);
int lastBand = min(in.p_band + in.p_nbands, p_band + p_nbands);

int lineIncrement = (double)LineDimension() / (double)LineDimensionScaled();
int sampleIncrement = (double)SampleDimension() / (double)SampleDimensionScaled();

for (int b = firstBand; b < lastBand; b++) {
for (int i = topLine; i < bottomLine; i++) {
for (int j = topSamp; j < bottomSamp; j++) {
try {
(*this)[Index(j, i, b)] = in[in.Index(j, i, b)];
int lineIndex = -1;
for (int i = topLine; i < bottomLine;) {
int nextLineIndex = Index(topSamp, i, b);

int sampleIndex = -1;
for (int j = topSamp; j < bottomSamp;) {
int nextSampleIndex = Index(j, i, b);
int inIndex = in.Index(j, i, b);
if (sampleIndex == nextSampleIndex) {
j++;
continue;
}
catch(...) {
(*this)[Index(j, i, b)] = NULL8;
else {
j += sampleIncrement;
sampleIndex = nextSampleIndex;
}
(*this)[sampleIndex] = in[inIndex];
}
if (lineIndex == nextLineIndex) {
i++;
continue;
}
else {
i += lineIncrement;
lineIndex = nextLineIndex;
}
}
}
}

isSubareaOfIn = (p_npixels <= in.size());
isSubareaOfIn &= (p_sample >= in.p_sample);
isSubareaOfIn &= (p_line >= in.p_line);
isSubareaOfIn &= (p_band >= in.p_band);

int endSample = p_sample + p_nsamps - 1;
int otherEndSample = in.p_sample + in.p_nsamps - 1;

int endLine = p_line + p_nlines - 1;
int otherEndLine = in.p_line + in.p_nlines - 1;

int endBand = p_band + p_nbands - 1;
int otherEndBand = in.p_band + in.p_nbands - 1;

isSubareaOfIn &= (endSample <= otherEndSample);
isSubareaOfIn &= (endLine <= otherEndLine);
isSubareaOfIn &= (endBand <= otherEndBand);

return isSubareaOfIn;
}

Expand Down Expand Up @@ -412,8 +421,8 @@ namespace Isis {
* @throws Isis::iException::System - Memory allocation failed
*/
void Buffer::Allocate() {
p_buf = NULL;
p_rawbuf = NULL;
p_buf = nullptr;
p_rawbuf = nullptr;
try {
p_buf = new double [p_npixels];
size_t n = Isis::SizeOf(p_pixelType);
Expand All @@ -424,16 +433,16 @@ namespace Isis {
try {
if(p_buf) {
delete [] p_buf;
p_buf = NULL;
p_buf = nullptr;
}
if(p_rawbuf) {
delete [](char *)p_rawbuf;
p_rawbuf = NULL;
p_rawbuf = nullptr;
}
}
catch(...) {
p_buf = NULL;
p_rawbuf = NULL;
p_buf = nullptr;
p_rawbuf = nullptr;
}
QString message = Message::MemoryAllocationFailed();
throw IException(IException::Unknown, message, _FILEINFO_);
Expand Down
51 changes: 37 additions & 14 deletions isis/src/base/objs/Cube/CubeIoHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,7 @@ namespace Isis {
// Scale the sampleand line increment, only necessary in read for Q apps
int lineIncrement = (double)output.LineDimension() / (double)output.LineDimensionScaled();
int sampleIncrement = (double)output.SampleDimension() / (double)output.SampleDimensionScaled();

for(int z = startZ; z <= endZ; z++) {
const int &bandIntoChunk = z - chunkStartBand;
int virtualBand = z;
Expand All @@ -1353,22 +1353,34 @@ namespace Isis {
if(virtualBand != 0 && virtualBand >= bufferBand &&
virtualBand <= bufferBand + bufferBands - 1) {

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

for(int x = startX; x < endX; x = x + sampleIncrement) {
int bufferSampleIndex = -1;
for(int x = startX; x < endX;) {
int nextSampleBufferIndex = output.Index(x, y, virtualBand);
const int &sampleIntoChunk = x - chunkStartSample;
int bufferIndex = output.Index(x, y, virtualBand);
// Avoid rolling back onto your buffer
if (bufferIndex >= output.size()) {
bufferIndex = output.size() - 1;
// Handle sample iteration
// If we continue to compute the same bufferIndex just iterate by 1
// If we compute the next index, increment by the
// floored sample increment and read the DN value
// at newly computed index
if (bufferSampleIndex == nextSampleBufferIndex) {
x++;
continue;
}
else {
x += sampleIncrement;
bufferSampleIndex = nextSampleBufferIndex;
}

const int &chunkIndex = sampleIntoChunk +
(chunkLineSize * lineIntoChunk) +
(chunkBandSize * bandIntoChunk);

double &bufferVal = buffersDoubleBuf[bufferIndex];
double &bufferVal = buffersDoubleBuf[bufferSampleIndex];

if(m_pixelType == Real) {
float raw = ((float *)chunkBuf)[chunkIndex];
Expand All @@ -1393,7 +1405,7 @@ namespace Isis {
bufferVal = LOW_REPR_SAT8;
}

((float *)buffersRawBuf)[bufferIndex] = raw;
((float *)buffersRawBuf)[bufferSampleIndex] = raw;
}

else if(m_pixelType == SignedWord) {
Expand All @@ -1419,7 +1431,7 @@ namespace Isis {
bufferVal = LOW_REPR_SAT8;
}

((short *)buffersRawBuf)[bufferIndex] = raw;
((short *)buffersRawBuf)[bufferSampleIndex] = raw;
}


Expand Down Expand Up @@ -1450,7 +1462,7 @@ namespace Isis {
bufferVal = LOW_REPR_SAT8;
}

((unsigned short *)buffersRawBuf)[bufferIndex] = raw;
((unsigned short *)buffersRawBuf)[bufferSampleIndex] = raw;
}

else if(m_pixelType == UnsignedInteger) {
Expand Down Expand Up @@ -1481,7 +1493,7 @@ namespace Isis {
bufferVal = LOW_REPR_SAT8;
}

((unsigned int *)buffersRawBuf)[bufferIndex] = raw;
((unsigned int *)buffersRawBuf)[bufferSampleIndex] = raw;



Expand All @@ -1500,10 +1512,21 @@ namespace Isis {
bufferVal = (double) raw * m_multiplier + m_base;
}

((unsigned char *)buffersRawBuf)[bufferIndex] = raw;
((unsigned char *)buffersRawBuf)[bufferSampleIndex] = raw;
}
}

bufferIndex++;
// Handle line iteration
// If we continue to compute the same bufferIndex just iterate by 1
// If we compute a next index, increment by the floored
// line increment
if (bufferLineIndex == nextLineBufferIndex) {
y++;
continue;
}
else {
y += lineIncrement;
bufferLineIndex = nextLineBufferIndex;
}
}
}
Expand Down
44 changes: 36 additions & 8 deletions isis/tests/BufferTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,17 @@ TEST(BufferTest, TestBufferOutOfBound) {
}
}

TEST(BufferTest, TestBufferScale) {
TEST(BufferTest, TestBufferScaleSmallToBig) {
Buffer b(4, 3, 2, Isis::SignedInteger, 0.5);

EXPECT_EQ(b.SampleDimension(), 4);
EXPECT_EQ(b.LineDimension(), 3);
EXPECT_EQ(b.BandDimension(), 2);

EXPECT_EQ(b.SampleDimensionScaled(), 2);
EXPECT_EQ(b.LineDimensionScaled(), 1);
EXPECT_EQ(b.LineDimensionScaled(), 2);

EXPECT_EQ(b.size(), 4);
EXPECT_EQ(b.size(), 8);

for(int i = 0; i < b.size(); i++) {
b[i] = i;
Expand All @@ -146,12 +146,40 @@ TEST(BufferTest, TestBufferScale) {
d.CopyOverlapFrom(b);
std::vector<int> truthBuffer = {0, 0, 1, 1,
0, 0, 1, 1,
0, 0, 1, 1,
// Second band
2, 2, 3, 3,
2, 2, 3, 3,
2, 2, 3, 3};
for (int i = 0; i < truthBuffer.size(); i++) {
// Second band
4, 4, 5, 5,
4, 4, 5, 5,
6, 6, 7, 7};
for (int i = 0; i < d.size(); i++) {
EXPECT_EQ(truthBuffer[i], d[i]);
}
}

TEST(BufferTest, TestBufferScaleBigToSmall) {
Buffer b(4, 3, 2, Isis::SignedInteger, 1);

EXPECT_EQ(b.SampleDimension(), 4);
EXPECT_EQ(b.LineDimension(), 3);
EXPECT_EQ(b.BandDimension(), 2);

EXPECT_EQ(b.SampleDimensionScaled(), 4);
EXPECT_EQ(b.LineDimensionScaled(), 3);

EXPECT_EQ(b.size(), 24);

for(int i = 0; i < b.size(); i++) {
b[i] = i;
}

Buffer d(4, 3, 2, Isis::SignedInteger, 0.5);
d.CopyOverlapFrom(b);
std::vector<int> truthBuffer = {4, 6,
8, 10,
// Second band
16, 18,
20, 22,};
for (int i = 0; i < d.size(); i++) {
EXPECT_EQ(truthBuffer[i], d[i]);
}
}