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,7 +884,7 @@ public: | ||
884 | /// using the following indexing: i = p*B + b | 884 | /// using the following indexing: i = p*B + b |
885 | /// @param matrix is the destination for the pixel data | 885 | /// @param matrix is the destination for the pixel data |
886 | /// @param mask is the mask | 886 | /// @param mask is the mask |
887 | - bool sift(T* matrix, unsigned char* mask){ | 887 | + bool sift(T* matrix, unsigned char* mask = NULL){ |
888 | size_t Lbytes = sizeof(T) * X(); | 888 | size_t Lbytes = sizeof(T) * X(); |
889 | T* line = (T*) malloc( Lbytes ); //allocate space for a line | 889 | T* line = (T*) malloc( Lbytes ); //allocate space for a line |
890 | 890 | ||
@@ -897,7 +897,7 @@ public: | @@ -897,7 +897,7 @@ public: | ||
897 | pl = 0; //initialize the pixel offset for the current line to zero (0) | 897 | pl = 0; //initialize the pixel offset for the current line to zero (0) |
898 | file.read( (char*)line, Lbytes ); //read the current line | 898 | file.read( (char*)line, Lbytes ); //read the current line |
899 | for(size_t x = 0; x < X(); x++){ | 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 | size_t i = (p + pl) * Z() + b; //calculate the index in the sifted matrix | 901 | size_t i = (p + pl) * Z() + b; //calculate the index in the sifted matrix |
902 | matrix[i] = line[x]; //store the current value in the line at the correct matrix location | 902 | matrix[i] = line[x]; //store the current value in the line at the correct matrix location |
903 | pl++; //increment the pixel pointer | 903 | pl++; //increment the pixel pointer |
stim/envi/bip.h
@@ -817,7 +817,7 @@ public: | @@ -817,7 +817,7 @@ public: | ||
817 | /// using the following indexing: i = p*B + b | 817 | /// using the following indexing: i = p*B + b |
818 | /// @param matrix is the destination for the pixel data | 818 | /// @param matrix is the destination for the pixel data |
819 | /// @param mask is the mask | 819 | /// @param mask is the mask |
820 | - bool sift(T* matrix, unsigned char* mask){ | 820 | + bool sift(T* matrix, unsigned char* mask = NULL){ |
821 | size_t Bbytes = sizeof(T) * Z(); | 821 | size_t Bbytes = sizeof(T) * Z(); |
822 | size_t XY = X() * Y(); | 822 | size_t XY = X() * Y(); |
823 | T* band = (T*) malloc( Bbytes ); //allocate space for a line | 823 | T* band = (T*) malloc( Bbytes ); //allocate space for a line |
@@ -826,7 +826,7 @@ public: | @@ -826,7 +826,7 @@ public: | ||
826 | 826 | ||
827 | size_t p = 0; //create counter variables | 827 | size_t p = 0; //create counter variables |
828 | for(size_t xy = 0; xy < XY; xy++){ //for each pixel | 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 | file.read( (char*)band, Bbytes ); //read the current line | 830 | file.read( (char*)band, Bbytes ); //read the current line |
831 | for(size_t b = 0; b < Z(); b++){ //copy each band value to the sifted matrix | 831 | for(size_t b = 0; b < Z(); b++){ //copy each band value to the sifted matrix |
832 | size_t i = p * Z() + b; //calculate the index in the sifted matrix | 832 | size_t i = p * Z() + b; //calculate the index in the sifted matrix |
stim/envi/bsq.h
@@ -809,7 +809,7 @@ public: | @@ -809,7 +809,7 @@ public: | ||
809 | /// using the following indexing: i = p*B + b | 809 | /// using the following indexing: i = p*B + b |
810 | /// @param matrix is the destination for the pixel data | 810 | /// @param matrix is the destination for the pixel data |
811 | /// @param mask is the mask | 811 | /// @param mask is the mask |
812 | - bool sift(T* matrix, unsigned char* mask){ | 812 | + bool sift(T* matrix, unsigned char* mask = NULL){ |
813 | unsigned long long XY = X() * Y(); //Number of XY pixels | 813 | unsigned long long XY = X() * Y(); //Number of XY pixels |
814 | unsigned long long L = XY * sizeof(T); //size of XY plane (in bytes) | 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,6 +61,11 @@ class envi{ | ||
61 | 61 | ||
62 | public: | 62 | public: |
63 | 63 | ||
64 | + /// Default constructor | ||
65 | + envi(){ | ||
66 | + file = NULL; //set the file pointer to NULL | ||
67 | + } | ||
68 | + | ||
64 | envi_header header; | 69 | envi_header header; |
65 | 70 | ||
66 | void* malloc_spectrum(){ | 71 | void* malloc_spectrum(){ |
@@ -665,7 +670,7 @@ public: | @@ -665,7 +670,7 @@ public: | ||
665 | /// using the following indexing: i = b*P + p | 670 | /// using the following indexing: i = b*P + p |
666 | /// @param matrix is the destination for the pixel data | 671 | /// @param matrix is the destination for the pixel data |
667 | /// @param p is the mask | 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 | if (header.interleave == envi_header::BSQ){ //if the infile is bsq file | 675 | if (header.interleave == envi_header::BSQ){ //if the infile is bsq file |
671 | if (header.data_type == envi_header::float32) | 676 | if (header.data_type == envi_header::float32) |
@@ -979,12 +984,13 @@ public: | @@ -979,12 +984,13 @@ public: | ||
979 | } | 984 | } |
980 | 985 | ||
981 | /// Closes the ENVI file. | 986 | /// Closes the ENVI file. |
982 | - bool close(){ | 987 | + void close(){ |
988 | + if(file == NULL) return; | ||
983 | if(header.interleave == envi_header::BSQ){ | 989 | if(header.interleave == envi_header::BSQ){ |
984 | if(header.data_type ==envi_header::float32) | 990 | if(header.data_type ==envi_header::float32) |
985 | - return ((bsq<float>*)file)->close(); | 991 | + ((bsq<float>*)file)->close(); |
986 | else if(header.data_type == envi_header::float64) | 992 | else if(header.data_type == envi_header::float64) |
987 | - return ((bsq<double>*)file)->close(); | 993 | + ((bsq<double>*)file)->close(); |
988 | else{ | 994 | else{ |
989 | std::cout<<"ERROR: unidentified data type"<<std::endl; | 995 | std::cout<<"ERROR: unidentified data type"<<std::endl; |
990 | exit(1); | 996 | exit(1); |
@@ -993,9 +999,9 @@ public: | @@ -993,9 +999,9 @@ public: | ||
993 | 999 | ||
994 | else if(header.interleave == envi_header::BIL){ | 1000 | else if(header.interleave == envi_header::BIL){ |
995 | if(header.data_type ==envi_header::float32) | 1001 | if(header.data_type ==envi_header::float32) |
996 | - return ((bil<float>*)file)->close(); | 1002 | + ((bil<float>*)file)->close(); |
997 | else if(header.data_type == envi_header::float64) | 1003 | else if(header.data_type == envi_header::float64) |
998 | - return ((bil<double>*)file)->close(); | 1004 | + ((bil<double>*)file)->close(); |
999 | else{ | 1005 | else{ |
1000 | std::cout<<"ERROR: unidentified data type"<<std::endl; | 1006 | std::cout<<"ERROR: unidentified data type"<<std::endl; |
1001 | exit(1); | 1007 | exit(1); |
@@ -1004,15 +1010,14 @@ public: | @@ -1004,15 +1010,14 @@ public: | ||
1004 | 1010 | ||
1005 | else if(header.interleave == envi_header::BIP){ | 1011 | else if(header.interleave == envi_header::BIP){ |
1006 | if(header.data_type ==envi_header::float32) | 1012 | if(header.data_type ==envi_header::float32) |
1007 | - return ((bip<float>*)file)->close(); | 1013 | + ((bip<float>*)file)->close(); |
1008 | else if(header.data_type == envi_header::float64) | 1014 | else if(header.data_type == envi_header::float64) |
1009 | - return ((bip<double>*)file)->close(); | 1015 | + ((bip<double>*)file)->close(); |
1010 | else{ | 1016 | else{ |
1011 | std::cout<<"ERROR: unidentified data type"<<std::endl; | 1017 | std::cout<<"ERROR: unidentified data type"<<std::endl; |
1012 | exit(1); | 1018 | exit(1); |
1013 | } | 1019 | } |
1014 | } | 1020 | } |
1015 | - return false; | ||
1016 | } | 1021 | } |
1017 | 1022 | ||
1018 | /// Retrieve a single pixel and stores it in pre-allocated memory. | 1023 | /// Retrieve a single pixel and stores it in pre-allocated memory. |
@@ -1181,6 +1186,7 @@ public: | @@ -1181,6 +1186,7 @@ public: | ||
1181 | else if (header.interleave == envi_header::BIP){ | 1186 | else if (header.interleave == envi_header::BIP){ |
1182 | if (header.data_type == envi_header::float32){ | 1187 | if (header.data_type == envi_header::float32){ |
1183 | ((bip<float>*)file)->spectrum((float*)temp, n, PROGRESS); | 1188 | ((bip<float>*)file)->spectrum((float*)temp, n, PROGRESS); |
1189 | + float test = ((float*)temp)[0]; | ||
1184 | cast<T, float>(ptr, (float*)temp, header.bands); | 1190 | cast<T, float>(ptr, (float*)temp, header.bands); |
1185 | } | 1191 | } |
1186 | else if (header.data_type == envi_header::float64){ | 1192 | else if (header.data_type == envi_header::float64){ |
stim/image/image.h
@@ -225,7 +225,7 @@ public: | @@ -225,7 +225,7 @@ public: | ||
225 | 225 | ||
226 | for(size_t x = 0; x < X(); x++){ | 226 | for(size_t x = 0; x < X(); x++){ |
227 | for(size_t y = 0; y < Y(); y++){ | 227 | for(size_t y = 0; y < Y(); y++){ |
228 | - r.img[r.idx(x, y, c)] = img[idx(x, y, c)]; | 228 | + r.img[r.idx(x, y, 0)] = img[idx(x, y, c)]; |
229 | } | 229 | } |
230 | } | 230 | } |
231 | 231 |
stim/parser/filename.h
@@ -110,7 +110,7 @@ public: | @@ -110,7 +110,7 @@ public: | ||
110 | } | 110 | } |
111 | 111 | ||
112 | 112 | ||
113 | - | 113 | + /// Outputs the file name (including prefix and extension) |
114 | std::string get_name(){ | 114 | std::string get_name(){ |
115 | if(prefix == "" && ext == "") | 115 | if(prefix == "" && ext == "") |
116 | return ""; | 116 | return ""; |
@@ -118,14 +118,18 @@ public: | @@ -118,14 +118,18 @@ public: | ||
118 | return prefix + "." + ext; | 118 | return prefix + "." + ext; |
119 | } | 119 | } |
120 | 120 | ||
121 | + /// Output the file extension only (usually three characters after a '.') | ||
121 | std::string get_extension(){ | 122 | std::string get_extension(){ |
122 | return ext; | 123 | return ext; |
123 | } | 124 | } |
124 | 125 | ||
126 | + /// Output the file prefix only (name before the extension) | ||
125 | std::string get_prefix(){ | 127 | std::string get_prefix(){ |
126 | return prefix; | 128 | return prefix; |
127 | } | 129 | } |
128 | 130 | ||
131 | + /// Output the entire path (not including the filename) | ||
132 | + /// ex. "c:\this\is\the\directory\" | ||
129 | std::string dir(){ | 133 | std::string dir(){ |
130 | std::stringstream ss; | 134 | std::stringstream ss; |
131 | 135 | ||
@@ -154,17 +158,17 @@ public: | @@ -154,17 +158,17 @@ public: | ||
154 | ext = ""; //file extension | 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 | std::string str(){ | 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 | // output is the directory and the prefix and the extension of the files, which are looking for in that directory. | 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 | std::string dir_fname(){ | 172 | std::string dir_fname(){ |
169 | std::stringstream ss; | 173 | std::stringstream ss; |
170 | 174 | ||
@@ -190,20 +194,17 @@ public: | @@ -190,20 +194,17 @@ public: | ||
190 | std::string f_name(std::string file_name){ | 194 | std::string f_name(std::string file_name){ |
191 | std::stringstream ss; | 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 | #ifdef _WIN32 | 198 | #ifdef _WIN32 |
197 | - ss<<drive<<":"; | 199 | + ss<<drive<<":"; //output the drive letter if in Windows |
198 | #endif | 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 | std::string fn_prefix = fn.prefix; | 208 | std::string fn_prefix = fn.prefix; |
208 | std::string fn_ext = fn.ext; | 209 | std::string fn_ext = fn.ext; |
209 | ss<<fn_prefix + '.' + fn_ext; | 210 | ss<<fn_prefix + '.' + fn_ext; |
@@ -212,38 +213,41 @@ public: | @@ -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 | std::vector<stim::filename> get_list(){ | 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 | WIN32_FIND_DATAA FindFileData; | 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 | else { | 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 | // List all the other files in the directory. | 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 | #elif BOOST_PRECOMPILED | 252 | #elif BOOST_PRECOMPILED |
249 | 253 |
stim/parser/table.h
@@ -34,6 +34,8 @@ namespace stim{ | @@ -34,6 +34,8 @@ namespace stim{ | ||
34 | template<typename T> | 34 | template<typename T> |
35 | T operator<<(T i){ | 35 | T operator<<(T i){ |
36 | std::stringstream ss; | 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 | ss<<i; | 39 | ss<<i; |
38 | TABLE[y].push_back(ss.str()); | 40 | TABLE[y].push_back(ss.str()); |
39 | x++; | 41 | x++; |