Commit 278c622bd2312ee44317af56022d64c5619147f9

Authored by David Mayerich
1 parent 58e55e6b

finished Windows and Linux HSIproc compiler tests after Sam and Davar's work

stim/envi/bil.h
... ... @@ -1309,6 +1309,66 @@ public:
1309 1309  
1310 1310 }
1311 1311  
  1312 + bool multiply(std::string outname, double v, unsigned char* mask = NULL, bool PROGRESS = false){
  1313 + unsigned long long B = Z(); //calculate the number of bands
  1314 + unsigned long long ZX = Z() * X();
  1315 + unsigned long long XY = X() * Y(); //calculate the number of pixels in a band
  1316 + unsigned long long S = XY * sizeof(T); //calculate the number of bytes in a band
  1317 + unsigned long long L = ZX * sizeof(T);
  1318 +
  1319 + std::ofstream target(outname.c_str(), std::ios::binary); //open the target binary file
  1320 +
  1321 + T * c; //pointer to the current ZX slice
  1322 + c = (T*)malloc( L ); //allocate space for the slice
  1323 +
  1324 + for(unsigned long long j = 0; j < Y(); j++){ //for each line
  1325 + read_plane_y(c, j); //load the line into memory
  1326 + for(unsigned long long i = 0; i < B; i++){ //for each band
  1327 + for(unsigned long long m = 0; m < X(); m++){ //for each sample
  1328 + if( mask == NULL && mask[m + j * X()] ) //if the pixel is masked
  1329 + c[m + i * X()] *= (T)v;
  1330 + }
  1331 + }
  1332 + target.write(reinterpret_cast<const char*>(c), L); //write normalized data into destination
  1333 +
  1334 + if(PROGRESS) progress = (double)(j+1) / Y() * 100; //update the progress
  1335 + }
  1336 +
  1337 + free(c); //free the slice memory
  1338 + target.close(); //close the output file
  1339 + return true;
  1340 + }
  1341 +
  1342 + bool add(std::string outname, double v, unsigned char* mask = NULL, bool PROGRESS = false){
  1343 + unsigned long long B = Z(); //calculate the number of bands
  1344 + unsigned long long ZX = Z() * X();
  1345 + unsigned long long XY = X() * Y(); //calculate the number of pixels in a band
  1346 + unsigned long long S = XY * sizeof(T); //calculate the number of bytes in a band
  1347 + unsigned long long L = ZX * sizeof(T);
  1348 +
  1349 + std::ofstream target(outname.c_str(), std::ios::binary); //open the target binary file
  1350 +
  1351 + T * c; //pointer to the current ZX slice
  1352 + c = (T*)malloc( L ); //allocate space for the slice
  1353 +
  1354 + for(unsigned long long j = 0; j < Y(); j++){ //for each line
  1355 + read_plane_y(c, j); //load the line into memory
  1356 + for(unsigned long long i = 0; i < B; i++){ //for each band
  1357 + for(unsigned long long m = 0; m < X(); m++){ //for each sample
  1358 + if( mask == NULL && mask[m + j * X()] ) //if the pixel is masked
  1359 + c[m + i * X()] += (T)v;
  1360 + }
  1361 + }
  1362 + target.write(reinterpret_cast<const char*>(c), L); //write normalized data into destination
  1363 +
  1364 + if(PROGRESS) progress = (double)(j+1) / Y() * 100; //update the progress
  1365 + }
  1366 +
  1367 + free(c); //free the slice memory
  1368 + target.close(); //close the output file
  1369 + return true;
  1370 + }
  1371 +
1312 1372 /// Close the file.
1313 1373 bool close(){
1314 1374 file.close();
... ...
stim/envi/bip.h
... ... @@ -1630,6 +1630,52 @@ public:
1630 1630 }
1631 1631 }
1632 1632  
  1633 + bool multiply(std::string outname, double v, unsigned char* mask = NULL, bool PROGRESS = false){
  1634 + std::ofstream target(outname.c_str(), std::ios::binary); //open the target binary file
  1635 + std::string headername = outname + ".hdr"; //the header file name
  1636 +
  1637 + unsigned long long N = X() * Y(); //calculate the total number of pixels to be processed
  1638 + unsigned long long B = Z(); //get the number of bands
  1639 + T* s = (T*)malloc(sizeof(T) * B); //allocate memory to store a pixel
  1640 + for(unsigned long long n = 0; n < N; n++){ //for each pixel in the image
  1641 + if(mask == NULL || mask[n]){ //if the pixel is masked
  1642 + for(size_t b = 0; b < B; b++) //for each band in the spectrum
  1643 + s[b] *= (T)v; //multiply
  1644 + }
  1645 +
  1646 + if(PROGRESS) progress = (double)(n+1) / N * 100; //set the current progress
  1647 +
  1648 + target.write((char*)s, sizeof(T) * B); //write the corrected data into destination
  1649 + } //end for each pixel
  1650 +
  1651 + free(s); //free the spectrum
  1652 + target.close(); //close the output file
  1653 + return true;
  1654 + }
  1655 +
  1656 + bool add(std::string outname, double v, unsigned char* mask = NULL, bool PROGRESS = false){
  1657 + std::ofstream target(outname.c_str(), std::ios::binary); //open the target binary file
  1658 + std::string headername = outname + ".hdr"; //the header file name
  1659 +
  1660 + unsigned long long N = X() * Y(); //calculate the total number of pixels to be processed
  1661 + unsigned long long B = Z(); //get the number of bands
  1662 + T* s = (T*)malloc(sizeof(T) * B); //allocate memory to store a pixel
  1663 + for(unsigned long long n = 0; n < N; n++){ //for each pixel in the image
  1664 + if(mask == NULL || mask[n]){ //if the pixel is masked
  1665 + for(size_t b = 0; b < B; b++) //for each band in the spectrum
  1666 + s[b] += (T)v; //multiply
  1667 + }
  1668 +
  1669 + if(PROGRESS) progress = (double)(n+1) / N * 100; //set the current progress
  1670 +
  1671 + target.write((char*)s, sizeof(T) * B); //write the corrected data into destination
  1672 + } //end for each pixel
  1673 +
  1674 + free(s); //free the spectrum
  1675 + target.close(); //close the output file
  1676 + return true;
  1677 + }
  1678 +
1633 1679  
1634 1680  
1635 1681 /// Close the file.
... ...
stim/envi/bsq.h
... ... @@ -1238,6 +1238,60 @@ public:
1238 1238 if(PROGRESS) progress = (double)(b+1) / (double)B * 100;
1239 1239 }
1240 1240  
  1241 + } //end deriv
  1242 +
  1243 + bool multiply(std::string outname, double v, unsigned char* mask = NULL, bool PROGRESS = false){
  1244 + unsigned long long B = Z(); //calculate the number of bands
  1245 + unsigned long long XY = X() * Y(); //calculate the number of pixels in a band
  1246 + unsigned long long S = XY * sizeof(T); //calculate the number of bytes in a band
  1247 +
  1248 + std::ofstream target(outname.c_str(), std::ios::binary); //open the target binary file
  1249 + std::string headername = outname + ".hdr"; //the header file name
  1250 +
  1251 + T * c; //pointer to the current image
  1252 + c = (T*)malloc( S ); //allocate memory for the band image
  1253 +
  1254 + for(unsigned long long j = 0; j < B; j++){ //for each band
  1255 + band_index(c, j); //load the current band
  1256 + for(unsigned long long i = 0; i < XY; i++){ //for each pixel
  1257 + if(mask == NULL || mask[i]) //if the pixel is masked
  1258 + c[i] *= (T)v; //perform the multiplication
  1259 + }
  1260 + target.write(reinterpret_cast<const char*>(c), S); //write normalized data into destination
  1261 +
  1262 + if(PROGRESS) progress = (double)(j+1) / B * 100; //update the progress
  1263 + }
  1264 +
  1265 + free(c); //free the band
  1266 + target.close(); //close the output file
  1267 + return true;
  1268 + }
  1269 +
  1270 + bool add(std::string outname, double v, unsigned char* mask = NULL, bool PROGRESS = false){
  1271 + unsigned long long B = Z(); //calculate the number of bands
  1272 + unsigned long long XY = X() * Y(); //calculate the number of pixels in a band
  1273 + unsigned long long S = XY * sizeof(T); //calculate the number of bytes in a band
  1274 +
  1275 + std::ofstream target(outname.c_str(), std::ios::binary); //open the target binary file
  1276 + std::string headername = outname + ".hdr"; //the header file name
  1277 +
  1278 + T * c; //pointer to the current image
  1279 + c = (T*)malloc( S ); //allocate memory for the band image
  1280 +
  1281 + for(unsigned long long j = 0; j < B; j++){ //for each band
  1282 + band_index(c, j); //load the current band
  1283 + for(unsigned long long i = 0; i < XY; i++){ //for each pixel
  1284 + if(mask == NULL || mask[i]) //if the pixel is masked
  1285 + c[i] += (T)v; //perform the multiplication
  1286 + }
  1287 + target.write(reinterpret_cast<const char*>(c), S); //write normalized data into destination
  1288 +
  1289 + if(PROGRESS) progress = (double)(j+1) / B * 100; //update the progress
  1290 + }
  1291 +
  1292 + free(c); //free the band
  1293 + target.close(); //close the output file
  1294 + return true;
1241 1295 }
1242 1296  
1243 1297  
... ...
stim/envi/envi.h
... ... @@ -1695,7 +1695,81 @@ public:
1695 1695 }
1696 1696 exit(1);
1697 1697 }
1698   -};
  1698 +
  1699 + void multiply(std::string outfile, double v, unsigned char* mask = NULL, bool PROGRESS = false){
  1700 + header.save(outfile + ".hdr");
  1701 + if (header.interleave == envi_header::BSQ){
  1702 + if (header.data_type == envi_header::float32)
  1703 + ((bsq<float>*)file)->multiply(outfile, v, mask, PROGRESS);
  1704 + else if (header.data_type == envi_header::float64)
  1705 + ((bsq<double>*)file)->multiply(outfile, v, mask, PROGRESS);
  1706 + else{
  1707 + std::cout << "ERROR: unidentified data type" << std::endl;
  1708 + exit(1);
  1709 + }
  1710 + }
  1711 +
  1712 + else if (header.interleave == envi_header::BIL){
  1713 + if (header.data_type == envi_header::float32)
  1714 + ((bil<float>*)file)->multiply(outfile, v, mask, PROGRESS);
  1715 + else if (header.data_type == envi_header::float64)
  1716 + ((bil<double>*)file)->multiply(outfile, v, mask, PROGRESS);
  1717 + else{
  1718 + std::cout << "ERROR: unidentified data type" << std::endl;
  1719 + exit(1);
  1720 + }
  1721 + }
  1722 +
  1723 + else if (header.interleave == envi_header::BIP){
  1724 + if (header.data_type == envi_header::float32)
  1725 + ((bip<float>*)file)->multiply(outfile, v, mask, PROGRESS);
  1726 + else if (header.data_type == envi_header::float64)
  1727 + ((bip<double>*)file)->multiply(outfile, v, mask, PROGRESS);
  1728 + else{
  1729 + std::cout << "ERROR: unidentified data type" << std::endl;
  1730 + exit(1);
  1731 + }
  1732 + }
  1733 + exit(1);
  1734 + }
  1735 +
  1736 + void add(std::string outfile, double v, unsigned char* mask = NULL, bool PROGRESS = false){
  1737 + header.save(outfile + ".hdr");
  1738 + if (header.interleave == envi_header::BSQ){
  1739 + if (header.data_type == envi_header::float32)
  1740 + ((bsq<float>*)file)->add(outfile, v, mask, PROGRESS);
  1741 + else if (header.data_type == envi_header::float64)
  1742 + ((bsq<double>*)file)->add(outfile, v, mask, PROGRESS);
  1743 + else{
  1744 + std::cout << "ERROR: unidentified data type" << std::endl;
  1745 + exit(1);
  1746 + }
  1747 + }
  1748 +
  1749 + else if (header.interleave == envi_header::BIL){
  1750 + if (header.data_type == envi_header::float32)
  1751 + ((bil<float>*)file)->add(outfile, v, mask, PROGRESS);
  1752 + else if (header.data_type == envi_header::float64)
  1753 + ((bil<double>*)file)->add(outfile, v, mask, PROGRESS);
  1754 + else{
  1755 + std::cout << "ERROR: unidentified data type" << std::endl;
  1756 + exit(1);
  1757 + }
  1758 + }
  1759 +
  1760 + else if (header.interleave == envi_header::BIP){
  1761 + if (header.data_type == envi_header::float32)
  1762 + ((bip<float>*)file)->add(outfile, v, mask, PROGRESS);
  1763 + else if (header.data_type == envi_header::float64)
  1764 + ((bip<double>*)file)->add(outfile, v, mask, PROGRESS);
  1765 + else{
  1766 + std::cout << "ERROR: unidentified data type" << std::endl;
  1767 + exit(1);
  1768 + }
  1769 + }
  1770 + exit(1);
  1771 + }
  1772 +}; //end ENVI
1699 1773  
1700 1774 } //end namespace rts
1701 1775  
... ...