Commit 6a46c8ff09229928c105e8fc22ab8b2a8b074833
1 parent
ba51ae6a
fixed bugs in applying masks to files
Showing
4 changed files
with
14 additions
and
12 deletions
Show diff stats
stim/envi/bil.h
@@ -818,7 +818,7 @@ public: | @@ -818,7 +818,7 @@ public: | ||
818 | 818 | ||
819 | /// @param outfile is the name of the masked output file | 819 | /// @param outfile is the name of the masked output file |
820 | /// @param p is a pointer to memory of size X * Y, where p(i) = 0 for pixels that will be set to zero. | 820 | /// @param p is a pointer to memory of size X * Y, where p(i) = 0 for pixels that will be set to zero. |
821 | - bool apply_mask(std::string outfile, unsigned char* p){ | 821 | + bool apply_mask(std::string outfile, unsigned char* p, bool PROGRESS = false){ |
822 | 822 | ||
823 | std::ofstream target(outfile.c_str(), std::ios::binary); | 823 | std::ofstream target(outfile.c_str(), std::ios::binary); |
824 | 824 | ||
@@ -842,6 +842,7 @@ public: | @@ -842,6 +842,7 @@ public: | ||
842 | } | 842 | } |
843 | } | 843 | } |
844 | target.write(reinterpret_cast<const char*>(temp), L); //write a band data into target file | 844 | target.write(reinterpret_cast<const char*>(temp), L); //write a band data into target file |
845 | + if(PROGRESS) progress = (double)(i+1) / (double)Y() * 100; | ||
845 | } | 846 | } |
846 | target.close(); | 847 | target.close(); |
847 | free(temp); | 848 | free(temp); |
stim/envi/bip.h
@@ -745,7 +745,7 @@ public: | @@ -745,7 +745,7 @@ public: | ||
745 | 745 | ||
746 | /// @param outfile is the name of the masked output file | 746 | /// @param outfile is the name of the masked output file |
747 | /// @param p is a pointer to memory of size X * Y, where p(i) = 0 for pixels that will be set to zero. | 747 | /// @param p is a pointer to memory of size X * Y, where p(i) = 0 for pixels that will be set to zero. |
748 | - bool apply_mask(std::string outfile, unsigned char* p){ | 748 | + bool apply_mask(std::string outfile, unsigned char* p, bool PROGRESS = false){ |
749 | 749 | ||
750 | std::ofstream target(outfile.c_str(), std::ios::binary); | 750 | std::ofstream target(outfile.c_str(), std::ios::binary); |
751 | 751 | ||
@@ -768,6 +768,7 @@ public: | @@ -768,6 +768,7 @@ public: | ||
768 | } | 768 | } |
769 | } | 769 | } |
770 | target.write(reinterpret_cast<const char*>(temp), L); //write the edited band data into target file | 770 | target.write(reinterpret_cast<const char*>(temp), L); //write the edited band data into target file |
771 | + if(PROGRESS) progress = (double)(i+1) / (double)Y() * 100; | ||
771 | } | 772 | } |
772 | target.close(); //close the target file | 773 | target.close(); //close the target file |
773 | free(temp); //free allocated memory | 774 | free(temp); //free allocated memory |
stim/envi/bsq.h
@@ -734,7 +734,7 @@ public: | @@ -734,7 +734,7 @@ public: | ||
734 | 734 | ||
735 | /// @param outfile is the name of the masked output file | 735 | /// @param outfile is the name of the masked output file |
736 | /// @param p is a pointer to memory of size X * Y, where p(i) = 0 for pixels that will be set to zero. | 736 | /// @param p is a pointer to memory of size X * Y, where p(i) = 0 for pixels that will be set to zero. |
737 | - bool apply_mask(std::string outfile, unsigned char* p){ | 737 | + bool apply_mask(std::string outfile, unsigned char* p, bool PROGRESS = false){ |
738 | 738 | ||
739 | std::ofstream target(outfile.c_str(), std::ios::binary); | 739 | std::ofstream target(outfile.c_str(), std::ios::binary); |
740 | 740 | ||
@@ -756,6 +756,7 @@ public: | @@ -756,6 +756,7 @@ public: | ||
756 | } | 756 | } |
757 | } | 757 | } |
758 | target.write(reinterpret_cast<const char*>(temp), L); //write the XY slice at that band to disk | 758 | target.write(reinterpret_cast<const char*>(temp), L); //write the XY slice at that band to disk |
759 | + if(PROGRESS) progress = (double)(i + 1) / (double)Z() * 100; | ||
759 | } | 760 | } |
760 | target.close(); | 761 | target.close(); |
761 | free(temp); | 762 | free(temp); |
stim/envi/envi.h
@@ -541,32 +541,31 @@ public: | @@ -541,32 +541,31 @@ public: | ||
541 | 541 | ||
542 | /// @param outfile is the name of the resulting masked output file | 542 | /// @param outfile is the name of the resulting masked output file |
543 | /// @param p is memory of size X*Y containing the mask (0 = false, all other values are true) | 543 | /// @param p is memory of size X*Y containing the mask (0 = false, all other values are true) |
544 | - bool apply_mask(std::string outfile, unsigned char* p) | 544 | + void apply_mask(std::string outfile, unsigned char* p, bool PROGRESS = false) |
545 | { | 545 | { |
546 | - header.save(outfile + ".hdr"); | ||
547 | if (header.interleave == envi_header::BSQ){ //if the infile is bsq file | 546 | if (header.interleave == envi_header::BSQ){ //if the infile is bsq file |
548 | if (header.data_type == envi_header::float32) | 547 | if (header.data_type == envi_header::float32) |
549 | - return ((bsq<float>*)file)->apply_mask(outfile, p); | 548 | + ((bsq<float>*)file)->apply_mask(outfile, p, PROGRESS); |
550 | else if (header.data_type == envi_header::float64) | 549 | else if (header.data_type == envi_header::float64) |
551 | - return ((bsq<double>*)file)->apply_mask(outfile, p); | 550 | + ((bsq<double>*)file)->apply_mask(outfile, p, PROGRESS); |
552 | else | 551 | else |
553 | std::cout << "ERROR: unidentified data type" << std::endl; | 552 | std::cout << "ERROR: unidentified data type" << std::endl; |
554 | } | 553 | } |
555 | 554 | ||
556 | else if (header.interleave == envi_header::BIL){ //if the infile is bil file | 555 | else if (header.interleave == envi_header::BIL){ //if the infile is bil file |
557 | if (header.data_type == envi_header::float32) | 556 | if (header.data_type == envi_header::float32) |
558 | - return ((bil<float>*)file)->apply_mask(outfile, p); | 557 | + ((bil<float>*)file)->apply_mask(outfile, p, PROGRESS); |
559 | else if (header.data_type == envi_header::float64) | 558 | else if (header.data_type == envi_header::float64) |
560 | - return ((bil<double>*)file)->apply_mask(outfile, p); | 559 | + ((bil<double>*)file)->apply_mask(outfile, p, PROGRESS); |
561 | else | 560 | else |
562 | std::cout << "ERROR: unidentified data type" << std::endl; | 561 | std::cout << "ERROR: unidentified data type" << std::endl; |
563 | } | 562 | } |
564 | 563 | ||
565 | else if (header.interleave == envi_header::BIP){ //if the infile is bip file | 564 | else if (header.interleave == envi_header::BIP){ //if the infile is bip file |
566 | if (header.data_type == envi_header::float32) | 565 | if (header.data_type == envi_header::float32) |
567 | - return ((bip<float>*)file)->apply_mask(outfile, p); | 566 | + ((bip<float>*)file)->apply_mask(outfile, p, PROGRESS); |
568 | else if (header.data_type == envi_header::float64) | 567 | else if (header.data_type == envi_header::float64) |
569 | - return ((bip<double>*)file)->apply_mask(outfile, p); | 568 | + ((bip<double>*)file)->apply_mask(outfile, p, PROGRESS); |
570 | else | 569 | else |
571 | std::cout << "ERROR: unidentified data type" << std::endl; | 570 | std::cout << "ERROR: unidentified data type" << std::endl; |
572 | } | 571 | } |
@@ -575,7 +574,7 @@ public: | @@ -575,7 +574,7 @@ public: | ||
575 | std::cout << "ERROR: unidentified file type" << std::endl; | 574 | std::cout << "ERROR: unidentified file type" << std::endl; |
576 | exit(1); | 575 | exit(1); |
577 | } | 576 | } |
578 | - return false; | 577 | + header.save(outfile + ".hdr"); |
579 | } | 578 | } |
580 | 579 | ||
581 | /// Copies all spectra corresponding to nonzero values of a mask into a pre-allocated matrix of size (P x B) | 580 | /// Copies all spectra corresponding to nonzero values of a mask into a pre-allocated matrix of size (P x B) |