Commit f2c883d83faa628651a355a3ef9ec102364cebd9
fixed merge conficts
Showing
7 changed files
with
63 additions
and
51 deletions
Show diff stats
stim/envi/bil.h
... | ... | @@ -884,7 +884,7 @@ public: |
884 | 884 | /// using the following indexing: i = p*B + b |
885 | 885 | /// @param matrix is the destination for the pixel data |
886 | 886 | /// @param mask is the mask |
887 | - bool sift(T* matrix, unsigned char* mask){ | |
887 | + bool sift(T* matrix, unsigned char* mask = NULL){ | |
888 | 888 | size_t Lbytes = sizeof(T) * X(); |
889 | 889 | T* line = (T*) malloc( Lbytes ); //allocate space for a line |
890 | 890 | |
... | ... | @@ -897,7 +897,7 @@ public: |
897 | 897 | pl = 0; //initialize the pixel offset for the current line to zero (0) |
898 | 898 | file.read( (char*)line, Lbytes ); //read the current line |
899 | 899 | for(size_t x = 0; x < X(); x++){ |
900 | - if(mask[y * X() + x]){ //if the current pixel is masked | |
900 | + if(mask == NULL || mask[y * X() + x]){ //if the current pixel is masked | |
901 | 901 | size_t i = (p + pl) * Z() + b; //calculate the index in the sifted matrix |
902 | 902 | matrix[i] = line[x]; //store the current value in the line at the correct matrix location |
903 | 903 | pl++; //increment the pixel pointer | ... | ... |
stim/envi/bip.h
... | ... | @@ -817,7 +817,7 @@ public: |
817 | 817 | /// using the following indexing: i = p*B + b |
818 | 818 | /// @param matrix is the destination for the pixel data |
819 | 819 | /// @param mask is the mask |
820 | - bool sift(T* matrix, unsigned char* mask){ | |
820 | + bool sift(T* matrix, unsigned char* mask = NULL){ | |
821 | 821 | size_t Bbytes = sizeof(T) * Z(); |
822 | 822 | size_t XY = X() * Y(); |
823 | 823 | T* band = (T*) malloc( Bbytes ); //allocate space for a line |
... | ... | @@ -826,7 +826,7 @@ public: |
826 | 826 | |
827 | 827 | size_t p = 0; //create counter variables |
828 | 828 | for(size_t xy = 0; xy < XY; xy++){ //for each pixel |
829 | - if(mask[xy]){ //if the current pixel is masked | |
829 | + if(mask == NULL || mask[xy]){ //if the current pixel is masked | |
830 | 830 | file.read( (char*)band, Bbytes ); //read the current line |
831 | 831 | for(size_t b = 0; b < Z(); b++){ //copy each band value to the sifted matrix |
832 | 832 | size_t i = p * Z() + b; //calculate the index in the sifted matrix | ... | ... |
stim/envi/bsq.h
... | ... | @@ -809,7 +809,7 @@ public: |
809 | 809 | /// using the following indexing: i = p*B + b |
810 | 810 | /// @param matrix is the destination for the pixel data |
811 | 811 | /// @param mask is the mask |
812 | - bool sift(T* matrix, unsigned char* mask){ | |
812 | + bool sift(T* matrix, unsigned char* mask = NULL){ | |
813 | 813 | unsigned long long XY = X() * Y(); //Number of XY pixels |
814 | 814 | unsigned long long L = XY * sizeof(T); //size of XY plane (in bytes) |
815 | 815 | ... | ... |
stim/envi/envi.h
... | ... | @@ -61,6 +61,11 @@ class envi{ |
61 | 61 | |
62 | 62 | public: |
63 | 63 | |
64 | + /// Default constructor | |
65 | + envi(){ | |
66 | + file = NULL; //set the file pointer to NULL | |
67 | + } | |
68 | + | |
64 | 69 | envi_header header; |
65 | 70 | |
66 | 71 | void* malloc_spectrum(){ |
... | ... | @@ -665,7 +670,7 @@ public: |
665 | 670 | /// using the following indexing: i = b*P + p |
666 | 671 | /// @param matrix is the destination for the pixel data |
667 | 672 | /// @param p is the mask |
668 | - bool sift(void* matrix, unsigned char* p){ | |
673 | + bool sift(void* matrix, unsigned char* p = NULL){ | |
669 | 674 | |
670 | 675 | if (header.interleave == envi_header::BSQ){ //if the infile is bsq file |
671 | 676 | if (header.data_type == envi_header::float32) |
... | ... | @@ -979,12 +984,13 @@ public: |
979 | 984 | } |
980 | 985 | |
981 | 986 | /// Closes the ENVI file. |
982 | - bool close(){ | |
987 | + void close(){ | |
988 | + if(file == NULL) return; | |
983 | 989 | if(header.interleave == envi_header::BSQ){ |
984 | 990 | if(header.data_type ==envi_header::float32) |
985 | - return ((bsq<float>*)file)->close(); | |
991 | + ((bsq<float>*)file)->close(); | |
986 | 992 | else if(header.data_type == envi_header::float64) |
987 | - return ((bsq<double>*)file)->close(); | |
993 | + ((bsq<double>*)file)->close(); | |
988 | 994 | else{ |
989 | 995 | std::cout<<"ERROR: unidentified data type"<<std::endl; |
990 | 996 | exit(1); |
... | ... | @@ -993,9 +999,9 @@ public: |
993 | 999 | |
994 | 1000 | else if(header.interleave == envi_header::BIL){ |
995 | 1001 | if(header.data_type ==envi_header::float32) |
996 | - return ((bil<float>*)file)->close(); | |
1002 | + ((bil<float>*)file)->close(); | |
997 | 1003 | else if(header.data_type == envi_header::float64) |
998 | - return ((bil<double>*)file)->close(); | |
1004 | + ((bil<double>*)file)->close(); | |
999 | 1005 | else{ |
1000 | 1006 | std::cout<<"ERROR: unidentified data type"<<std::endl; |
1001 | 1007 | exit(1); |
... | ... | @@ -1004,15 +1010,14 @@ public: |
1004 | 1010 | |
1005 | 1011 | else if(header.interleave == envi_header::BIP){ |
1006 | 1012 | if(header.data_type ==envi_header::float32) |
1007 | - return ((bip<float>*)file)->close(); | |
1013 | + ((bip<float>*)file)->close(); | |
1008 | 1014 | else if(header.data_type == envi_header::float64) |
1009 | - return ((bip<double>*)file)->close(); | |
1015 | + ((bip<double>*)file)->close(); | |
1010 | 1016 | else{ |
1011 | 1017 | std::cout<<"ERROR: unidentified data type"<<std::endl; |
1012 | 1018 | exit(1); |
1013 | 1019 | } |
1014 | 1020 | } |
1015 | - return false; | |
1016 | 1021 | } |
1017 | 1022 | |
1018 | 1023 | /// Retrieve a single pixel and stores it in pre-allocated memory. |
... | ... | @@ -1181,6 +1186,7 @@ public: |
1181 | 1186 | else if (header.interleave == envi_header::BIP){ |
1182 | 1187 | if (header.data_type == envi_header::float32){ |
1183 | 1188 | ((bip<float>*)file)->spectrum((float*)temp, n, PROGRESS); |
1189 | + float test = ((float*)temp)[0]; | |
1184 | 1190 | cast<T, float>(ptr, (float*)temp, header.bands); |
1185 | 1191 | } |
1186 | 1192 | else if (header.data_type == envi_header::float64){ | ... | ... |
stim/image/image.h
stim/parser/filename.h
... | ... | @@ -110,7 +110,7 @@ public: |
110 | 110 | } |
111 | 111 | |
112 | 112 | |
113 | - | |
113 | + /// Outputs the file name (including prefix and extension) | |
114 | 114 | std::string get_name(){ |
115 | 115 | if(prefix == "" && ext == "") |
116 | 116 | return ""; |
... | ... | @@ -118,14 +118,18 @@ public: |
118 | 118 | return prefix + "." + ext; |
119 | 119 | } |
120 | 120 | |
121 | + /// Output the file extension only (usually three characters after a '.') | |
121 | 122 | std::string get_extension(){ |
122 | 123 | return ext; |
123 | 124 | } |
124 | 125 | |
126 | + /// Output the file prefix only (name before the extension) | |
125 | 127 | std::string get_prefix(){ |
126 | 128 | return prefix; |
127 | 129 | } |
128 | 130 | |
131 | + /// Output the entire path (not including the filename) | |
132 | + /// ex. "c:\this\is\the\directory\" | |
129 | 133 | std::string dir(){ |
130 | 134 | std::stringstream ss; |
131 | 135 | |
... | ... | @@ -154,17 +158,17 @@ public: |
154 | 158 | ext = ""; //file extension |
155 | 159 | } |
156 | 160 | |
161 | + /// Output the entire string, including the path and filename | |
162 | + /// ex. "c:\this\is\a\directory\file.txt" | |
157 | 163 | std::string str(){ |
158 | - | |
159 | - std::stringstream ss; | |
160 | - | |
161 | - ss<<dir()<<get_name(); | |
162 | - | |
163 | - return ss.str(); | |
164 | + std::stringstream ss; //create a string stream | |
165 | + ss<<dir()<<get_name(); //push the directory and filename to that stream | |
166 | + return ss.str(); //convert the stream to a string and return it | |
164 | 167 | } |
165 | 168 | |
166 | 169 | //***************************************************************************************************************** |
167 | 170 | // output is the directory and the prefix and the extension of the files, which are looking for in that directory. |
171 | + /// David: I have no idea what this is doing. It looks identical to dir() | |
168 | 172 | std::string dir_fname(){ |
169 | 173 | std::stringstream ss; |
170 | 174 | |
... | ... | @@ -190,20 +194,17 @@ public: |
190 | 194 | std::string f_name(std::string file_name){ |
191 | 195 | std::stringstream ss; |
192 | 196 | |
193 | - //if the path is absolute | |
194 | - if(absolute){ | |
195 | - //output the drive letter if in Windows | |
197 | + if(absolute){ //if the path is absolute | |
196 | 198 | #ifdef _WIN32 |
197 | - ss<<drive<<":"; | |
199 | + ss<<drive<<":"; //output the drive letter if in Windows | |
198 | 200 | #endif |
199 | - ss<<STIM_FILENAME_DIV; | |
201 | + ss<<STIM_FILENAME_DIV; //output a path divider | |
200 | 202 | } |
201 | 203 | |
202 | - //output the directory | |
203 | - for(unsigned int d = 0; d < path.size(); d++) | |
204 | - ss<<path[d]<<STIM_FILENAME_DIV; | |
204 | + for(unsigned int d = 0; d < path.size(); d++) //for each directory in the current path | |
205 | + ss<<path[d]<<STIM_FILENAME_DIV; //add that directory, interspersing path dividers | |
205 | 206 | |
206 | - stim::filename fn = file_name; | |
207 | + stim::filename fn = file_name; | |
207 | 208 | std::string fn_prefix = fn.prefix; |
208 | 209 | std::string fn_ext = fn.ext; |
209 | 210 | ss<<fn_prefix + '.' + fn_ext; |
... | ... | @@ -212,38 +213,41 @@ public: |
212 | 213 | |
213 | 214 | } |
214 | 215 | |
216 | + /// Returns a list of files using the current filename as a template. | |
217 | + /// For example: | |
218 | + /// C:\this\is\a\path\file*.txt | |
219 | + /// can be used as a template to find a series of files file001.txt, file002.txt, file003.txt, etc. | |
215 | 220 | std::vector<stim::filename> get_list(){ |
216 | -#ifdef _WIN32 | |
217 | - //get a list of files matching the current template | |
221 | + //this is OS dependent, so we're starting with Windows | |
222 | + //the Unix version requires Boost | |
218 | 223 | |
224 | +#ifdef _WIN32 | |
225 | + stim::filename filepath(dir_fname()); //initialize filepath with the mask | |
219 | 226 | |
220 | - //stim::filename file_path; | |
221 | - stim::filename filepath(dir_fname()); | |
222 | - | |
223 | - HANDLE hFind = INVALID_HANDLE_VALUE; | |
227 | + HANDLE hFind = INVALID_HANDLE_VALUE; //allocate data structures for looping through files | |
224 | 228 | WIN32_FIND_DATAA FindFileData; |
225 | - std::vector<stim::filename> file_list; | |
229 | + std::vector<stim::filename> file_list; //initialize a list to hold all matching filenames | |
226 | 230 | |
227 | - hFind = FindFirstFileA((filepath.str().c_str()), &FindFileData); | |
231 | + hFind = FindFirstFileA((filepath.str().c_str()), &FindFileData); //find the first file that matches the specified file path | |
228 | 232 | |
229 | - if (hFind == INVALID_HANDLE_VALUE) { | |
230 | - printf ("Invalid file handle. Error is %u.\n", GetLastError()); | |
233 | + if (hFind == INVALID_HANDLE_VALUE) { //if there are no matching files | |
234 | + printf ("Invalid file handle. Error is %u.\n", GetLastError()); //print an error | |
231 | 235 | } |
232 | 236 | else { |
233 | - std::string file_name = FindFileData.cFileName; //get the file name | |
234 | - std::string file_path = dir(); | |
235 | - stim::filename current_file(file_path + file_name); | |
236 | - file_list.push_back(current_file); | |
237 | + std::string file_name = FindFileData.cFileName; //save the file name | |
238 | + std::string file_path = dir(); //the file is in the specified directory, so save it | |
239 | + stim::filename current_file(file_path + file_name); //create a stim::filename structure representing this file | |
240 | + file_list.push_back(current_file); //push the new stim::filename to the file list | |
237 | 241 | |
238 | 242 | // List all the other files in the directory. |
239 | - while (FindNextFileA(hFind, &FindFileData) != 0){ | |
240 | - file_name = FindFileData.cFileName; | |
241 | - current_file = (f_name(file_name)); | |
242 | - file_list.push_back(current_file); | |
243 | + while (FindNextFileA(hFind, &FindFileData) != 0){ //iterate until there are no more matching files | |
244 | + file_name = FindFileData.cFileName; //save the next file | |
245 | + current_file = (f_name(file_name)); //append the directory | |
246 | + file_list.push_back(current_file); //push it to the list | |
243 | 247 | } |
244 | - FindClose(hFind); | |
248 | + FindClose(hFind); //close the file data structure | |
245 | 249 | } |
246 | - return file_list; | |
250 | + return file_list; //return the list of files | |
247 | 251 | |
248 | 252 | #elif BOOST_PRECOMPILED |
249 | 253 | ... | ... |
stim/parser/table.h
... | ... | @@ -34,6 +34,8 @@ namespace stim{ |
34 | 34 | template<typename T> |
35 | 35 | T operator<<(T i){ |
36 | 36 | std::stringstream ss; |
37 | + if(std::is_fundamental<T>()) //if the data type is numeric | |
38 | + ss<<std::setprecision(std::numeric_limits<T>::digits10 + 3); //set the precision to account for all digits | |
37 | 39 | ss<<i; |
38 | 40 | TABLE[y].push_back(ss.str()); |
39 | 41 | x++; | ... | ... |