Commit 3150c5373298738bb4ac4228991edf538c3e4754

Authored by David Mayerich
1 parent cbce396e

added further progress bar support (sifting, unsifting, cropping)

Showing 3 changed files with 69 additions and 27 deletions   Show diff stats
stim/envi/bil.h
... ... @@ -850,9 +850,9 @@ public:
850 850 std::ofstream target(outfile.c_str(), std::ios::binary);
851 851  
852 852 //for loading pages:
853   - unsigned XZ = X() * Z(); //calculate the number of values in an XZ page on disk
854   - unsigned int B = Z(); //calculate the number of bands
855   - unsigned L = XZ * sizeof(T); //calculate the size of the page (in bytes)
  853 + unsigned long XZ = X() * Z(); //calculate the number of values in an XZ page on disk
  854 + unsigned long B = Z(); //calculate the number of bands
  855 + unsigned long L = XZ * sizeof(T); //calculate the size of the page (in bytes)
856 856  
857 857 //allocate temporary memory for a XZ slice
858 858 T* slice = (T*) malloc(L);
... ... @@ -861,28 +861,32 @@ public:
861 861 T* spec = (T*) malloc(B * sizeof(T));
862 862  
863 863 //for each slice along the y axis
864   - for (unsigned int y = 0; y < Y(); y++) //Select a page by choosing Y coordinate, Y()
  864 + for (unsigned long y = 0; y < Y(); y++) //Select a page by choosing Y coordinate, Y()
865 865 {
866 866 read_plane_y(slice, y); //retrieve an ZX page, store in "slice"
867 867  
868 868 //for each sample along X
869   - for (unsigned x = 0; x < X(); x++) //Select a pixel by choosing X coordinate in the page, X()
  869 + for (unsigned long x = 0; x < X(); x++) //Select a pixel by choosing X coordinate in the page, X()
870 870 {
871 871 //if the mask != 0 at that xy pixel
872 872 if (p[y * X() + x] != 0) //if the mask != 0 at that XY pixel
873 873 {
874 874 //for each band at that pixel
875   - for (unsigned int b = 0; b < B; b++) //Select a voxel by choosing Z coordinate at the pixel
  875 + for (unsigned long b = 0; b < B; b++) //Select a voxel by choosing Z coordinate at the pixel
876 876 {
877 877 spec[b] = slice[b*X() + x]; //Pass the correct spectral value from XZ page into the spectrum to be saved.
878 878 }
879 879 target.write((char*)spec, B * sizeof(T)); //write that spectrum to disk. Size is L2.
880 880 }
  881 +
  882 + thread_data = (double) (y * X() + x) / (Y() * X()) * 100;
881 883 }
882 884 }
883 885 target.close();
884 886 free(slice);
885 887 free(spec);
  888 +
  889 + thread_data = 100;
886 890 return true;
887 891 }
888 892  
... ... @@ -1019,10 +1023,15 @@ public:
1019 1023 {
1020 1024 file.read((char *)(temp + j * sam), sizeof(T) * sam);
1021 1025 file.seekg(jumpb, std::ios::cur); //go to the next band
  1026 +
  1027 + thread_data = (double)(i * Z() + j) / (lin * Z()) * 100;
1022 1028 }
1023 1029 out.write(reinterpret_cast<const char*>(temp), L); //write slice data into target file
1024 1030 }
1025 1031 free(temp);
  1032 +
  1033 + thread_data = 100;
  1034 +
1026 1035 return true;
1027 1036 }
1028 1037  
... ...
stim/envi/bip.h
... ... @@ -858,15 +858,15 @@ public:
858 858 std::ofstream target(outfile.c_str(), std::ios::binary);
859 859  
860 860 //allocate space for a single spectrum
861   - unsigned int B = Z();
  861 + unsigned long B = Z();
862 862 T* spectrum = (T*) malloc(B * sizeof(T));
863 863  
864 864 //calculate the number of pixels in a band
865   - unsigned int XY = X() * Y();
  865 + unsigned long XY = X() * Y();
866 866  
867 867 //for each pixel
868   - unsigned int skip = 0; //number of spectra to skip
869   - for(unsigned int x = 0; x < XY; x++){
  868 + unsigned long skip = 0; //number of spectra to skip
  869 + for(unsigned long x = 0; x < XY; x++){
870 870  
871 871 //if the current pixel isn't masked
872 872 if( mask[x] == 0){
... ... @@ -887,6 +887,8 @@ public:
887 887  
888 888 //write this pixel out
889 889 target.write((char *)spectrum, B * sizeof(T));
  890 +
  891 + thread_data = (double) x / XY * 100;
890 892 }
891 893  
892 894 }
... ... @@ -895,6 +897,8 @@ public:
895 897 target.close();
896 898 free(spectrum);
897 899  
  900 + thread_data = 100;
  901 +
898 902 return true;
899 903 }
900 904  
... ... @@ -907,7 +911,7 @@ public:
907 911 file.seekg(0, std::ios::beg);
908 912  
909 913 //allocate space for a single spectrum
910   - unsigned int B = Z();
  914 + unsigned long B = Z();
911 915 T* spectrum = (T*) malloc(B * sizeof(T));
912 916  
913 917 //allocate space for a spectrum of zeros
... ... @@ -915,11 +919,11 @@ public:
915 919 memset(zeros, 0, B * sizeof(T));
916 920  
917 921 //calculate the number of pixels in a band
918   - unsigned int XY = samples * lines;
  922 + unsigned long XY = samples * lines;
919 923  
920 924 //for each pixel
921   - unsigned int skip = 0; //number of spectra to skip
922   - for(unsigned int x = 0; x < XY; x++){
  925 + unsigned long skip = 0; //number of spectra to skip
  926 + for(unsigned long x = 0; x < XY; x++){
923 927  
924 928 //if the current pixel isn't masked
925 929 if( mask[x] == 0){
... ... @@ -937,12 +941,16 @@ public:
937 941 target.write((char *)spectrum, B * sizeof(T));
938 942 }
939 943  
  944 + thread_data = (double)x / XY * 100;
  945 +
940 946 }
941 947  
942 948 //close the output file
943 949 target.close();
944 950 free(spectrum);
945 951  
  952 + thread_data = 100;
  953 +
946 954 return true;
947 955  
948 956  
... ... @@ -1070,9 +1078,13 @@ public:
1070 1078 {
1071 1079 pixel(temp, sp + j + i * X());
1072 1080 out.write(reinterpret_cast<const char*>(temp), L); //write slice data into target file
  1081 +
  1082 + thread_data = (double)(i * sam + j) / (lin * sam) * 100;
1073 1083 }
1074 1084 }
1075 1085 free(temp);
  1086 +
  1087 + thread_data = 100;
1076 1088 return true;
1077 1089 }
1078 1090  
... ...
stim/envi/bsq.h
... ... @@ -372,15 +372,21 @@ public:
372 372 file.read((char *)(xz_slice + z * X()), sizeof(T) * X()); //read a line
373 373 file.seekg(jump, std::ios::cur); //seek to the next band
374 374  
375   - thread_data = (double)(y * Z() + z) / (Z() * Y()) * 100; //update the progress counter
  375 +
  376 + thread_data = (double)(y * Z() + z) / (Z() * Y()) * 100; //update the progress counter
  377 + std::cout<<y<<","<<z<<" "<<thread_data<<std::endl;
376 378 }
377 379 target.write(reinterpret_cast<const char*>(xz_slice), xz_bytes); //write the generated XZ slice to the target file
378 380 }
  381 +
  382 +
379 383  
380 384 thread_data = 100;
381 385  
382 386 free(xz_slice);
383 387 target.close();
  388 +
  389 + std::cout<<"conversion finished"<<std::endl;
384 390 return true;
385 391 }
386 392  
... ... @@ -777,16 +783,16 @@ public:
777 783 bool sift(std::string outfile, unsigned char* p){
778 784 std::ofstream target(outfile.c_str(), std::ios::binary);
779 785 // open a band (XY plane)
780   - unsigned XY = X() * Y(); //Number of XY pixels
781   - unsigned L = XY * sizeof(T); //size of XY pixels
  786 + unsigned long XY = X() * Y(); //Number of XY pixels
  787 + unsigned long L = XY * sizeof(T); //size of XY pixels
782 788  
783 789 T * temp = (T*)malloc(L); //allocate memory for a band
784 790 T * temp_vox = (T*)malloc(sizeof(T)); //allocate memory for one voxel
785 791  
786   - for (unsigned i = 0; i < Z(); i++) //for each spectral bin
  792 + for (unsigned long i = 0; i < Z(); i++) //for each spectral bin
787 793 {
788 794 band_index(temp, i); //get the specified band (XY sheet by index)
789   - for (unsigned j = 0; j < XY; j++) // for each pixel
  795 + for (unsigned long j = 0; j < XY; j++) // for each pixel
790 796 {
791 797 if (p[j] != 0){ //if the mask is != 0 at that pixel
792 798 temp_vox[0] = temp[j];
... ... @@ -795,10 +801,15 @@ public:
795 801 else{
796 802 continue;
797 803 }
  804 +
  805 + thread_data = (double)(i * XY + j) / (XY * Z()) * 100;
798 806 }
799 807 }
800 808 target.close();
801 809 free(temp);
  810 +
  811 + thread_data = 100;
  812 +
802 813 return true;
803 814 }
804 815  
... ... @@ -817,9 +828,9 @@ public:
817 828 std::cout<<"started sifting"<<std::endl;
818 829  
819 830 //get the number of pixels and bands in the input image
820   - unsigned int P = X(); //Number of pixels
821   - unsigned int B = Z(); //number of bands
822   - unsigned int XY = samples * lines; //total number of pixels in an unsifted image
  831 + unsigned long P = X(); //Number of pixels
  832 + unsigned long B = Z(); //number of bands
  833 + unsigned long XY = samples * lines; //total number of pixels in an unsifted image
823 834  
824 835 // allocate memory for a sifted band
825 836 T * sifted = (T*)malloc(P * sizeof(T)); //allocate memory for a band
... ... @@ -828,28 +839,33 @@ public:
828 839 T* unsifted = (T*) malloc(XY * sizeof(T));
829 840  
830 841 //for each band
831   - for(unsigned int b = 0; b < B; b++){
  842 + for(unsigned long b = 0; b < B; b++){
832 843  
833 844 //set the unsifted index value to zero
834   - unsigned int i = 0;
  845 + unsigned long i = 0;
835 846  
836 847 //retrieve the sifted band (masked pixels only)
837 848 band_index(sifted, b);
838 849  
839 850 //for each pixel in the final image (treat it as a 1D image)
840   - for(unsigned int xi = 0; xi < XY; xi++){
  851 + for(unsigned long xi = 0; xi < XY; xi++){
841 852 if( p[xi] == 0 )
842 853 unsifted[xi] = 0;
843 854 else{
844 855 unsifted[xi] = sifted[i];
845 856 i++;
846 857 }
  858 + //std::cout<<xi<<"/"<<XY<<", "<<b<<"/"<<B<<std::endl;
  859 + thread_data = (double)(b * XY + xi) / (B * XY) * 100;
847 860 }
848   -
  861 + //std::cout<<b*XY<<"/"<<B*XY<<" "<<B<<"-"<<XY<<std::endl;
849 862 //write the band image to disk
850 863 target.write(reinterpret_cast<const char*>(unsifted), sizeof(T) * XY);
851 864 }
852 865  
  866 + //std::cout<<"unsifted"<<std::endl;
  867 + thread_data = 100;
  868 +
853 869 return true;
854 870 }
855 871  
... ... @@ -967,17 +983,22 @@ public:
967 983 unsigned long long jumpl = (X() - sam) * sizeof(T); //jump pointer to the next line
968 984 //get start
969 985 file.seekg((y0 * X() + x0) * sizeof(T), std::ios::beg);
970   - for (unsigned i = 0; i < Z(); i++)
  986 + for (unsigned z = 0; z < Z(); z++)
971 987 {
972 988 for (unsigned j = 0; j < lin; j++)
973 989 {
974 990 file.read((char *)(temp + j * sam), sizeof(T) * sam);
975 991 file.seekg(jumpl, std::ios::cur); //go to the next band
  992 +
  993 + thread_data = (double)(z * lin + j) / (Z() * lin) * 100;
976 994 }
977 995 out.write(reinterpret_cast<const char*>(temp), L); //write slice data into target file
978 996 file.seekg(jumpb, std::ios::cur);
979 997 }
980 998 free(temp);
  999 +
  1000 + thread_data = 100;
  1001 +
981 1002 return true;
982 1003 }
983 1004  
... ...