Commit 945ee13c87d2f84bc8e48abb12dce75629e46c3a
1 parent
91d8912e
the get_list function by using the windows.h, these changes are in the image_stack.h and filename.h
Showing
5 changed files
with
114 additions
and
32 deletions
Show diff stats
stim/cuda/arraymath/array_cart2polar.cuh
stim/grids/grid.h
... | ... | @@ -5,7 +5,7 @@ |
5 | 5 | #include <string> |
6 | 6 | #include <sstream> |
7 | 7 | #include <fstream> |
8 | -#include <cstdarg> | |
8 | +#include <cstdarg> | |
9 | 9 | |
10 | 10 | #include <stim/math/vector.h> |
11 | 11 | |
... | ... | @@ -51,7 +51,9 @@ protected: |
51 | 51 | public: |
52 | 52 | |
53 | 53 | ///Default constructor doesn't do anything |
54 | - grid(){} | |
54 | + grid(){ | |
55 | + ptr = NULL; //set the pointer to NULL so that we know nothing is allocated | |
56 | + } | |
55 | 57 | |
56 | 58 | ///Constructor used to specify the grid size as a vector |
57 | 59 | |
... | ... | @@ -110,6 +112,9 @@ public: |
110 | 112 | |
111 | 113 | R = S; //set the sample resolution |
112 | 114 | |
115 | + //allocate space for the data | |
116 | + init(); | |
117 | + | |
113 | 118 | std::fstream file; |
114 | 119 | |
115 | 120 | //open the file as binary for writing |
... | ... | @@ -118,6 +123,7 @@ public: |
118 | 123 | //seek past the header |
119 | 124 | file.seekg(header, std::ios::beg); |
120 | 125 | |
126 | + | |
121 | 127 | //read the data |
122 | 128 | file.read((char *)ptr, samples() * sizeof(T)); |
123 | 129 | } |
... | ... | @@ -173,7 +179,9 @@ public: |
173 | 179 | for(unsigned int d = 0; d<D; d++){ |
174 | 180 | if(d!=0) result<<", "; |
175 | 181 | result<<R[d]; |
182 | + | |
176 | 183 | } |
184 | + | |
177 | 185 | result<<"]"<<std::endl; |
178 | 186 | |
179 | 187 | //calculate the number of values to output | ... | ... |
stim/grids/image_stack.h
... | ... | @@ -21,6 +21,7 @@ protected: |
21 | 21 | using stim::grid<T, 4>::R; |
22 | 22 | using stim::grid<T, 4>::ptr; |
23 | 23 | using stim::grid<T, 4>::samples; |
24 | + using stim::grid<T, 4>::read; | |
24 | 25 | |
25 | 26 | public: |
26 | 27 | |
... | ... | @@ -62,11 +63,13 @@ public: |
62 | 63 | //load and copy each image into the grid |
63 | 64 | for(unsigned int i = 0; i<R[3]; i++){ |
64 | 65 | |
66 | + std::cout<<"File to Load: "<<file_list[i].str()<<std::endl; | |
65 | 67 | //load the image |
66 | 68 | stim::image<T> I(file_list[i].str()); |
67 | 69 | |
68 | 70 | //retrieve the interlaced data from the image - store it in the grid |
69 | 71 | I.data_interleaved(&ptr[ i * R[0] * R[1] * R[2] ]); |
72 | + | |
70 | 73 | } |
71 | 74 | } |
72 | 75 | |
... | ... | @@ -117,6 +120,19 @@ public: |
117 | 120 | save_image(file_list[i], i); |
118 | 121 | } |
119 | 122 | |
123 | + /// Returns the pixel at the specified point | |
124 | + T get(unsigned int x, unsigned int y, unsigned int z, unsigned int c = 0){ | |
125 | + return ptr[z * R[0] * R[1] * R[2] + y * R[0] * R[1] + x * R[0] + c]; | |
126 | + } | |
127 | + | |
128 | + void read(std::string file, unsigned int X, unsigned int Y, unsigned int Z, unsigned int C = 1, unsigned int header = 0){ | |
129 | + read(file, stim::vec<unsigned long>(C, X, Y, Z), header); | |
130 | + } | |
131 | + | |
132 | + T* data(){ | |
133 | + return ptr; | |
134 | + } | |
135 | + | |
120 | 136 | }; |
121 | 137 | |
122 | 138 | ... | ... |
stim/image/image.h
... | ... | @@ -135,6 +135,7 @@ public: |
135 | 135 | } |
136 | 136 | |
137 | 137 | T* data(){ |
138 | + | |
138 | 139 | return img.data(); |
139 | 140 | } |
140 | 141 | |
... | ... | @@ -260,6 +261,22 @@ public: |
260 | 261 | |
261 | 262 | return result; |
262 | 263 | } |
264 | + | |
265 | + // leila's code for non_interleaving data in 3D | |
266 | + //create an data set from an interleaved buffer | |
267 | + void set_interleaved3(T* buffer, unsigned int width, unsigned int height, unsigned int depth, unsigned int channels = 3){ | |
268 | + | |
269 | + T* non_interleaved3 = (T*)malloc(width * height * depth * 3 * sizeof(T)); | |
270 | + unsigned int p = width * height * depth; | |
271 | + | |
272 | + for(unsigned int i = 0; i < p; i++){ | |
273 | + for(unsigned int c = 0; c < channels; c++){ | |
274 | + non_interleaved3[i + c * p] = buffer[i * channels + c]; | |
275 | + } | |
276 | + } | |
277 | + | |
278 | + img = cimg_library::CImg<T>(non_interleaved3, width, height, depth, channels); | |
279 | + } | |
263 | 280 | |
264 | 281 | }; |
265 | 282 | ... | ... |
stim/parser/filename.h
... | ... | @@ -19,10 +19,6 @@ |
19 | 19 | #include <algorithm> |
20 | 20 | |
21 | 21 | #include "../parser/parser.h" |
22 | -#ifdef BOOST_PRECOMPILED | |
23 | -#include <boost/filesystem.hpp> | |
24 | -#endif | |
25 | - | |
26 | 22 | namespace stim{ |
27 | 23 | |
28 | 24 | //filename class designed to work with both Windows and Unix |
... | ... | @@ -155,47 +151,93 @@ public: |
155 | 151 | |
156 | 152 | return ss.str(); |
157 | 153 | } |
158 | -#ifdef BOOST_PRECOMPILED | |
159 | 154 | |
160 | - //get a list of files matching the current template | |
161 | - std::vector<stim::filename> get_list(){ | |
155 | + //***************************************************************************************************************** | |
156 | + // output is the directory and the prefix and the extension of the files, which are looking for in that directory. | |
157 | + std::string dir_fname(){ | |
158 | + std::stringstream ss; | |
162 | 159 | |
163 | - boost::filesystem::path p(dir()); //create a path from the current filename | |
160 | + //if the path is absolute | |
161 | + if(absolute){ | |
162 | + //output the drive letter if in Windows | |
163 | + #ifdef _WIN32 | |
164 | + ss<<drive<<":"; | |
165 | + #endif | |
166 | + ss<<STIM_FILENAME_DIV; | |
167 | + } | |
164 | 168 | |
165 | - std::vector<stim::filename> file_list; | |
169 | + | |
170 | + for(unsigned int d = 0; d < path.size(); d++) | |
171 | + ss<<path[d]<<STIM_FILENAME_DIV; | |
172 | + ss<<get_name(); | |
166 | 173 | |
167 | - if(boost::filesystem::exists(p)){ | |
168 | - if(boost::filesystem::is_directory(p)){ | |
174 | + return ss.str(); | |
169 | 175 | |
170 | - typedef std::vector<boost::filesystem::path> vec; // store paths, | |
171 | - vec v; // so we can sort them later | |
176 | + } | |
177 | + | |
178 | + // output is the directory and the name of the file which are found in that given directory | |
179 | + std::string f_name(std::string file_name){ | |
180 | + std::stringstream ss; | |
172 | 181 | |
173 | - std::copy(boost::filesystem::directory_iterator(p), boost::filesystem::directory_iterator(), back_inserter(v)); | |
182 | + //if the path is absolute | |
183 | + if(absolute){ | |
184 | + //output the drive letter if in Windows | |
185 | + #ifdef _WIN32 | |
186 | + ss<<drive<<":"; | |
187 | + #endif | |
188 | + ss<<STIM_FILENAME_DIV; | |
189 | + } | |
174 | 190 | |
175 | - std::sort(v.begin(), v.end()); // sort, since directory iteration | |
176 | - // is not ordered on some file systems | |
191 | + //output the directory | |
192 | + for(unsigned int d = 0; d < path.size(); d++) | |
193 | + ss<<path[d]<<STIM_FILENAME_DIV; | |
177 | 194 | |
178 | - //compare file names to the current template (look for wild cards) | |
179 | - for (vec::const_iterator it(v.begin()), it_end(v.end()); it != it_end; ++it) | |
180 | - { | |
195 | + stim::filename fn = file_name; | |
196 | + std::string fn_prefix = fn.prefix; | |
197 | + std::string fn_ext = fn.ext; | |
198 | + ss<<fn_prefix + '.' + fn_ext; | |
181 | 199 | |
182 | - //if the filename is a wild card *or* it matches the read file name | |
183 | - if( prefix == "*" || prefix == (*it).filename().stem().string()){ | |
200 | + return ss.str(); | |
184 | 201 | |
185 | - //if the extension is a wild card *or* it matches the read file extension | |
186 | - if( ext == "*" || "." + ext == (*it).filename().extension().string()){ | |
202 | + } | |
187 | 203 | |
188 | - file_list.push_back((*it).string()); //include it in the final list | |
189 | - } | |
190 | - } | |
204 | + | |
205 | +#ifdef _WIN32 | |
206 | +#include <windows.h> | |
207 | + //get a list of files matching the current template | |
208 | + std::vector<stim::filename> get_list(){ | |
191 | 209 | |
192 | - } | |
210 | + //stim::filename file_path; | |
211 | + stim::filename filepath(dir_fname()); | |
212 | + HANDLE hFind = INVALID_HANDLE_VALUE; | |
213 | + WIN32_FIND_DATAA FindFileData; | |
214 | + std::vector<stim::filename> file_list; | |
215 | + | |
216 | + hFind = FindFirstFileA((filepath.str().c_str()), &FindFileData); | |
217 | + | |
218 | + if (hFind == INVALID_HANDLE_VALUE) { | |
219 | + printf ("Invalid file handle. Error is %u.\n", GetLastError()); | |
220 | + } | |
221 | + else { | |
222 | + std::string file_name = FindFileData.cFileName; | |
223 | + stim::filename current_file(f_name(file_name)); | |
224 | + file_list.push_back(current_file); | |
225 | + | |
226 | + // List all the other files in the directory. | |
227 | + while (FindNextFileA(hFind, &FindFileData) != 0){ | |
228 | + file_name = FindFileData.cFileName; | |
229 | + current_file = (f_name(file_name)); | |
230 | + file_list.push_back(current_file); | |
193 | 231 | } |
194 | - } | |
195 | - | |
232 | + FindClose(hFind); | |
233 | + | |
196 | 234 | return file_list; |
197 | 235 | } |
236 | + | |
237 | + } | |
198 | 238 | #endif |
239 | + //************************************************************************************************** | |
240 | + | |
199 | 241 | //gets the current working directory |
200 | 242 | static stim::filename cwd(){ |
201 | 243 | ... | ... |