From 1a55a328300dc8bae2d0576f3a8b8bb16e16c84c Mon Sep 17 00:00:00 2001 From: David Mayerich Date: Wed, 3 Jun 2015 18:09:19 -0500 Subject: [PATCH] Added comments for apply_mask for Brad --- stim/envi/bil.h | 13 +++++++------ stim/envi/bip.h | 28 ++++++++++++++-------------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/stim/envi/bil.h b/stim/envi/bil.h index a770292..8142a8b 100644 --- a/stim/envi/bil.h +++ b/stim/envi/bil.h @@ -814,15 +814,16 @@ public: std::ofstream target(outfile.c_str(), std::ios::binary); - unsigned XZ = R[0] * R[2]; //calculate number of a band - unsigned L = XZ * sizeof(T); + //I THINK THIS IS WRONG + unsigned XZ = R[0] * R[2]; //calculate the number of values in a page on disk + unsigned L = XZ * sizeof(T); //calculate the size of the page (in bytes) - T * temp = (T*)malloc(L); + T * temp = (T*)malloc(L); //allocate memory for a temporary page - for (unsigned i = 0; i < R[1]; i++) + for (unsigned i = 0; i < R[1]; i++) //for each value in R[1] (BIP should be X) { - getY(temp, i); - for ( unsigned j = 0; j < R[2]; j++) + getY(temp, i); //retrieve an ZX slice, stored in temp + for ( unsigned j = 0; j < R[2]; j++) //for each R[2] (BIP should be Y) { for (unsigned k = 0; k < R[0]; k++) { diff --git a/stim/envi/bip.h b/stim/envi/bip.h index 565f086..c2788ff 100644 --- a/stim/envi/bip.h +++ b/stim/envi/bip.h @@ -905,29 +905,29 @@ public: std::ofstream target(outfile.c_str(), std::ios::binary); - unsigned ZX = R[2] * R[0]; //calculate number of a band - unsigned L = ZX * sizeof(T); + unsigned ZX = R[2] * R[0]; //calculate the number of values in a page (XZ in BIP) + unsigned L = ZX * sizeof(T); //calculate the number of bytes in a page - T * temp = (T*)malloc(L); + T * temp = (T*)malloc(L); //allocate space for that page - for (unsigned i = 0; i < R[1]; i++) + for (unsigned i = 0; i < R[1]; i++) //for each page (Y in BIP) { - getY(temp, i); - for ( unsigned j = 0; j < R[0]; j++) + getY(temp, i); //load that page (it's pointed to by temp) + for ( unsigned j = 0; j < R[0]; j++) //for each X value { - for (unsigned k = 0; k < R[2]; k++) + for (unsigned k = 0; k < R[2]; k++) //for each B value (band) { - if(p[i * R[0] + k] == 0) - temp[j * R[2] + k] = 0; - else + if(p[i * R[0] + k] == 0) //if the mask value is zero + temp[j * R[2] + k] = 0; //set the pixel value to zero + else //otherwise just continue continue; } } - target.write(reinterpret_cast(temp), L); //write a band data into target file + target.write(reinterpret_cast(temp), L); //write the edited band data into target file } - target.close(); - free(temp); - return true; + target.close(); //close the target file + free(temp); //free allocated memory + return true; //return true } /// Calculate the mean band value (average along B) at each pixel location. -- libgit2 0.21.4