From 278c622bd2312ee44317af56022d64c5619147f9 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 25 Aug 2016 12:40:45 -0500 Subject: [PATCH] finished Windows and Linux HSIproc compiler tests after Sam and Davar's work --- stim/envi/bil.h | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ stim/envi/bip.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ stim/envi/bsq.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ stim/envi/envi.h | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 235 insertions(+), 1 deletion(-) diff --git a/stim/envi/bil.h b/stim/envi/bil.h index 591c44c..7bc1eaf 100644 --- a/stim/envi/bil.h +++ b/stim/envi/bil.h @@ -1309,6 +1309,66 @@ public: } + bool multiply(std::string outname, double v, unsigned char* mask = NULL, bool PROGRESS = false){ + unsigned long long B = Z(); //calculate the number of bands + unsigned long long ZX = Z() * X(); + unsigned long long XY = X() * Y(); //calculate the number of pixels in a band + unsigned long long S = XY * sizeof(T); //calculate the number of bytes in a band + unsigned long long L = ZX * sizeof(T); + + std::ofstream target(outname.c_str(), std::ios::binary); //open the target binary file + + T * c; //pointer to the current ZX slice + c = (T*)malloc( L ); //allocate space for the slice + + for(unsigned long long j = 0; j < Y(); j++){ //for each line + read_plane_y(c, j); //load the line into memory + for(unsigned long long i = 0; i < B; i++){ //for each band + for(unsigned long long m = 0; m < X(); m++){ //for each sample + if( mask == NULL && mask[m + j * X()] ) //if the pixel is masked + c[m + i * X()] *= (T)v; + } + } + target.write(reinterpret_cast(c), L); //write normalized data into destination + + if(PROGRESS) progress = (double)(j+1) / Y() * 100; //update the progress + } + + free(c); //free the slice memory + target.close(); //close the output file + return true; + } + + bool add(std::string outname, double v, unsigned char* mask = NULL, bool PROGRESS = false){ + unsigned long long B = Z(); //calculate the number of bands + unsigned long long ZX = Z() * X(); + unsigned long long XY = X() * Y(); //calculate the number of pixels in a band + unsigned long long S = XY * sizeof(T); //calculate the number of bytes in a band + unsigned long long L = ZX * sizeof(T); + + std::ofstream target(outname.c_str(), std::ios::binary); //open the target binary file + + T * c; //pointer to the current ZX slice + c = (T*)malloc( L ); //allocate space for the slice + + for(unsigned long long j = 0; j < Y(); j++){ //for each line + read_plane_y(c, j); //load the line into memory + for(unsigned long long i = 0; i < B; i++){ //for each band + for(unsigned long long m = 0; m < X(); m++){ //for each sample + if( mask == NULL && mask[m + j * X()] ) //if the pixel is masked + c[m + i * X()] += (T)v; + } + } + target.write(reinterpret_cast(c), L); //write normalized data into destination + + if(PROGRESS) progress = (double)(j+1) / Y() * 100; //update the progress + } + + free(c); //free the slice memory + target.close(); //close the output file + return true; + } + /// Close the file. bool close(){ file.close(); diff --git a/stim/envi/bip.h b/stim/envi/bip.h index c76f316..9de7311 100644 --- a/stim/envi/bip.h +++ b/stim/envi/bip.h @@ -1630,6 +1630,52 @@ public: } } + bool multiply(std::string outname, double v, unsigned char* mask = NULL, bool PROGRESS = false){ + std::ofstream target(outname.c_str(), std::ios::binary); //open the target binary file + std::string headername = outname + ".hdr"; //the header file name + + unsigned long long N = X() * Y(); //calculate the total number of pixels to be processed + unsigned long long B = Z(); //get the number of bands + T* s = (T*)malloc(sizeof(T) * B); //allocate memory to store a pixel + for(unsigned long long n = 0; n < N; n++){ //for each pixel in the image + if(mask == NULL || mask[n]){ //if the pixel is masked + for(size_t b = 0; b < B; b++) //for each band in the spectrum + s[b] *= (T)v; //multiply + } + + if(PROGRESS) progress = (double)(n+1) / N * 100; //set the current progress + + target.write((char*)s, sizeof(T) * B); //write the corrected data into destination + } //end for each pixel + + free(s); //free the spectrum + target.close(); //close the output file + return true; + } + + bool add(std::string outname, double v, unsigned char* mask = NULL, bool PROGRESS = false){ + std::ofstream target(outname.c_str(), std::ios::binary); //open the target binary file + std::string headername = outname + ".hdr"; //the header file name + + unsigned long long N = X() * Y(); //calculate the total number of pixels to be processed + unsigned long long B = Z(); //get the number of bands + T* s = (T*)malloc(sizeof(T) * B); //allocate memory to store a pixel + for(unsigned long long n = 0; n < N; n++){ //for each pixel in the image + if(mask == NULL || mask[n]){ //if the pixel is masked + for(size_t b = 0; b < B; b++) //for each band in the spectrum + s[b] += (T)v; //multiply + } + + if(PROGRESS) progress = (double)(n+1) / N * 100; //set the current progress + + target.write((char*)s, sizeof(T) * B); //write the corrected data into destination + } //end for each pixel + + free(s); //free the spectrum + target.close(); //close the output file + return true; + } + /// Close the file. diff --git a/stim/envi/bsq.h b/stim/envi/bsq.h index 5eb5190..4ea407a 100644 --- a/stim/envi/bsq.h +++ b/stim/envi/bsq.h @@ -1238,6 +1238,60 @@ public: if(PROGRESS) progress = (double)(b+1) / (double)B * 100; } + } //end deriv + + bool multiply(std::string outname, double v, unsigned char* mask = NULL, bool PROGRESS = false){ + unsigned long long B = Z(); //calculate the number of bands + unsigned long long XY = X() * Y(); //calculate the number of pixels in a band + unsigned long long S = XY * sizeof(T); //calculate the number of bytes in a band + + std::ofstream target(outname.c_str(), std::ios::binary); //open the target binary file + std::string headername = outname + ".hdr"; //the header file name + + T * c; //pointer to the current image + c = (T*)malloc( S ); //allocate memory for the band image + + for(unsigned long long j = 0; j < B; j++){ //for each band + band_index(c, j); //load the current band + for(unsigned long long i = 0; i < XY; i++){ //for each pixel + if(mask == NULL || mask[i]) //if the pixel is masked + c[i] *= (T)v; //perform the multiplication + } + target.write(reinterpret_cast(c), S); //write normalized data into destination + + if(PROGRESS) progress = (double)(j+1) / B * 100; //update the progress + } + + free(c); //free the band + target.close(); //close the output file + return true; + } + + bool add(std::string outname, double v, unsigned char* mask = NULL, bool PROGRESS = false){ + unsigned long long B = Z(); //calculate the number of bands + unsigned long long XY = X() * Y(); //calculate the number of pixels in a band + unsigned long long S = XY * sizeof(T); //calculate the number of bytes in a band + + std::ofstream target(outname.c_str(), std::ios::binary); //open the target binary file + std::string headername = outname + ".hdr"; //the header file name + + T * c; //pointer to the current image + c = (T*)malloc( S ); //allocate memory for the band image + + for(unsigned long long j = 0; j < B; j++){ //for each band + band_index(c, j); //load the current band + for(unsigned long long i = 0; i < XY; i++){ //for each pixel + if(mask == NULL || mask[i]) //if the pixel is masked + c[i] += (T)v; //perform the multiplication + } + target.write(reinterpret_cast(c), S); //write normalized data into destination + + if(PROGRESS) progress = (double)(j+1) / B * 100; //update the progress + } + + free(c); //free the band + target.close(); //close the output file + return true; } diff --git a/stim/envi/envi.h b/stim/envi/envi.h index 9c8506a..f859fd2 100644 --- a/stim/envi/envi.h +++ b/stim/envi/envi.h @@ -1695,7 +1695,81 @@ public: } exit(1); } -}; + + void multiply(std::string outfile, double v, unsigned char* mask = NULL, bool PROGRESS = false){ + header.save(outfile + ".hdr"); + if (header.interleave == envi_header::BSQ){ + if (header.data_type == envi_header::float32) + ((bsq*)file)->multiply(outfile, v, mask, PROGRESS); + else if (header.data_type == envi_header::float64) + ((bsq*)file)->multiply(outfile, v, mask, PROGRESS); + else{ + std::cout << "ERROR: unidentified data type" << std::endl; + exit(1); + } + } + + else if (header.interleave == envi_header::BIL){ + if (header.data_type == envi_header::float32) + ((bil*)file)->multiply(outfile, v, mask, PROGRESS); + else if (header.data_type == envi_header::float64) + ((bil*)file)->multiply(outfile, v, mask, PROGRESS); + else{ + std::cout << "ERROR: unidentified data type" << std::endl; + exit(1); + } + } + + else if (header.interleave == envi_header::BIP){ + if (header.data_type == envi_header::float32) + ((bip*)file)->multiply(outfile, v, mask, PROGRESS); + else if (header.data_type == envi_header::float64) + ((bip*)file)->multiply(outfile, v, mask, PROGRESS); + else{ + std::cout << "ERROR: unidentified data type" << std::endl; + exit(1); + } + } + exit(1); + } + + void add(std::string outfile, double v, unsigned char* mask = NULL, bool PROGRESS = false){ + header.save(outfile + ".hdr"); + if (header.interleave == envi_header::BSQ){ + if (header.data_type == envi_header::float32) + ((bsq*)file)->add(outfile, v, mask, PROGRESS); + else if (header.data_type == envi_header::float64) + ((bsq*)file)->add(outfile, v, mask, PROGRESS); + else{ + std::cout << "ERROR: unidentified data type" << std::endl; + exit(1); + } + } + + else if (header.interleave == envi_header::BIL){ + if (header.data_type == envi_header::float32) + ((bil*)file)->add(outfile, v, mask, PROGRESS); + else if (header.data_type == envi_header::float64) + ((bil*)file)->add(outfile, v, mask, PROGRESS); + else{ + std::cout << "ERROR: unidentified data type" << std::endl; + exit(1); + } + } + + else if (header.interleave == envi_header::BIP){ + if (header.data_type == envi_header::float32) + ((bip*)file)->add(outfile, v, mask, PROGRESS); + else if (header.data_type == envi_header::float64) + ((bip*)file)->add(outfile, v, mask, PROGRESS); + else{ + std::cout << "ERROR: unidentified data type" << std::endl; + exit(1); + } + } + exit(1); + } +}; //end ENVI } //end namespace rts -- libgit2 0.21.4