Commit c78b2ff4da257c3f0e5724491c6fbbbf5104c6b0
1 parent
b66bbf3f
add some function in order to get grid work
Showing
1 changed file
with
14 additions
and
3 deletions
Show diff stats
stim/grids/image_stack.h
@@ -147,6 +147,7 @@ public: | @@ -147,6 +147,7 @@ public: | ||
147 | R[3] = depth; | 147 | R[3] = depth; |
148 | 148 | ||
149 | ptr = (T*)malloc(sizeof(T) * samples()); | 149 | ptr = (T*)malloc(sizeof(T) * samples()); |
150 | + memset(ptr, 0, sizeof(T) * samples()); | ||
150 | } | 151 | } |
151 | 152 | ||
152 | ///Saves the entire stack to a set of images | 153 | ///Saves the entire stack to a set of images |
@@ -170,12 +171,22 @@ public: | @@ -170,12 +171,22 @@ public: | ||
170 | /// Returns the world-space position at an index point (i, j, k) | 171 | /// Returns the world-space position at an index point (i, j, k) |
171 | vec3<F> p(size_t i, size_t j, size_t k){ | 172 | vec3<F> p(size_t i, size_t j, size_t k){ |
172 | vec3<F> result; | 173 | vec3<F> result; |
173 | - result[0] = (F)i * S[0]; | ||
174 | - result[1] = (F)j * S[1]; | ||
175 | - result[2] = (F)j * S[2]; | 174 | + result[0] = (F)i * S[1]; |
175 | + result[1] = (F)j * S[2]; | ||
176 | + result[2] = (F)k * S[3]; | ||
176 | return result; | 177 | return result; |
177 | } | 178 | } |
178 | 179 | ||
180 | + // set the pixel at the specified point | ||
181 | + void set(size_t i, size_t j, size_t k, T value, size_t c = 0){ | ||
182 | + ptr[k * R[0] * R[1] * R[2] + j * R[0] * R[1] + i * R[0] + c] = value; | ||
183 | + } | ||
184 | + void set(T* Ptr, size_t k) { | ||
185 | + | ||
186 | + for (unsigned i = 0; i < R[0] * R[1] * R[2]; i++) | ||
187 | + ptr[i + k * R[0] * R[1] * R[2]] = Ptr[i]; | ||
188 | + } | ||
189 | + | ||
179 | void read(std::string file, unsigned int X, unsigned int Y, unsigned int Z, unsigned int C = 1, unsigned int header = 0){ | 190 | void read(std::string file, unsigned int X, unsigned int Y, unsigned int Z, unsigned int C = 1, unsigned int header = 0){ |
180 | read(file, stim::vec<unsigned long>(C, X, Y, Z), header); | 191 | read(file, stim::vec<unsigned long>(C, X, Y, Z), header); |
181 | } | 192 | } |