Commit ad9345728682e41b55856cb4f4572bba8738096a
Merge branch 'master' of git.stim.ee.uh.edu:codebase/stimlib
Showing
9 changed files
with
685 additions
and
748 deletions
Show diff stats
stim/biomodels/fiber.h renamed to stim/biomodels/centerline.h
1 | -#ifndef STIM_FIBER_H | ||
2 | -#define STIM_FIBER_H | 1 | +#ifndef STIM_CENTERLINE_H |
2 | +#define STIM_CENTERLINE_H | ||
3 | 3 | ||
4 | #include <vector> | 4 | #include <vector> |
5 | -#include <ANN/ANN.h> | 5 | +#include <stim/math/vec3.h> |
6 | +//#include <ANN/ANN.h> | ||
6 | 7 | ||
7 | namespace stim{ | 8 | namespace stim{ |
8 | 9 | ||
@@ -11,22 +12,19 @@ namespace stim{ | @@ -11,22 +12,19 @@ namespace stim{ | ||
11 | * class to describe an interconnected (often biological) network. | 12 | * class to describe an interconnected (often biological) network. |
12 | */ | 13 | */ |
13 | template<typename T> | 14 | template<typename T> |
14 | -class fiber{ | 15 | +class centerline{ |
15 | 16 | ||
16 | protected: | 17 | protected: |
17 | unsigned int N; //number of points in the fiber | 18 | unsigned int N; //number of points in the fiber |
18 | double **c; //centerline (array of double pointers) | 19 | double **c; //centerline (array of double pointers) |
19 | - | ||
20 | - T* r; // array of fiber radii | ||
21 | - ANNkd_tree* kdt; //kd-tree stores all points in the fiber for fast searching | 20 | +// ANNkd_tree* kdt; //kd-tree stores all points in the fiber for fast searching |
22 | 21 | ||
23 | /// Initialize an empty fiber | 22 | /// Initialize an empty fiber |
24 | void init() | 23 | void init() |
25 | { | 24 | { |
26 | - kdt = NULL; | ||
27 | - c=NULL; | ||
28 | - r=NULL; | ||
29 | N=0; | 25 | N=0; |
26 | + c=NULL; | ||
27 | +// kdt = NULL; | ||
30 | } | 28 | } |
31 | 29 | ||
32 | /// Initialize a fiber with N centerline points (all located at [0, 0, 0] with radius 0) | 30 | /// Initialize a fiber with N centerline points (all located at [0, 0, 0] with radius 0) |
@@ -34,19 +32,17 @@ protected: | @@ -34,19 +32,17 @@ protected: | ||
34 | { | 32 | { |
35 | 33 | ||
36 | N = n; //set the number of points | 34 | N = n; //set the number of points |
37 | - kdt = NULL; | 35 | +// kdt = NULL; |
38 | c = (double**) malloc(sizeof(double*) * N); //allocate the array pointer | 36 | c = (double**) malloc(sizeof(double*) * N); //allocate the array pointer |
39 | 37 | ||
40 | for(unsigned int i = 0; i < N; i++) //allocate space for each point | 38 | for(unsigned int i = 0; i < N; i++) //allocate space for each point |
41 | c[i] = (double*) malloc(sizeof(double) * 3); | 39 | c[i] = (double*) malloc(sizeof(double) * 3); |
42 | - | ||
43 | - r = (T*) malloc(sizeof(T) * N); //allocate space for the radii | ||
44 | } | 40 | } |
45 | 41 | ||
46 | /// Copies an existing fiber to the current fiber | 42 | /// Copies an existing fiber to the current fiber |
47 | 43 | ||
48 | /// @param cpy stores the new copy of the fiber | 44 | /// @param cpy stores the new copy of the fiber |
49 | - void copy( const stim::fiber<T>& cpy ){ | 45 | + void copy( const stim::centerline<T>& cpy, bool kd = 0){ |
50 | 46 | ||
51 | ///allocate space for the new fiber | 47 | ///allocate space for the new fiber |
52 | init(cpy.N); | 48 | init(cpy.N); |
@@ -55,20 +51,18 @@ protected: | @@ -55,20 +51,18 @@ protected: | ||
55 | for(unsigned int i = 0; i < N; i++){ | 51 | for(unsigned int i = 0; i < N; i++){ |
56 | for(unsigned int d = 0; d < 3; d++) //for each dimension | 52 | for(unsigned int d = 0; d < 3; d++) //for each dimension |
57 | c[i][d] = cpy.c[i][d]; //copy the coordinate | 53 | c[i][d] = cpy.c[i][d]; //copy the coordinate |
58 | - | ||
59 | - r[i] = cpy.r[i]; //copy the radius | ||
60 | } | 54 | } |
61 | - | ||
62 | - gen_kdtree(); //generate the kd tree for the new fiber | 55 | +// if(kd) |
56 | +// gen_kdtree(); //generate the kd tree for the new fiber | ||
63 | } | 57 | } |
64 | 58 | ||
65 | /// generate a KD tree for points on fiber | 59 | /// generate a KD tree for points on fiber |
66 | - void gen_kdtree() | ||
67 | - { | ||
68 | - int n_data = N; //create an array of data points | ||
69 | - ANNpointArray pts = (ANNpointArray)c; //cast the centerline list to an ANNpointArray | ||
70 | - kdt = new ANNkd_tree(pts, n_data, 3); //build a KD tree | ||
71 | - } | 60 | +// void gen_kdtree() |
61 | +// { | ||
62 | +// int n_data = N; //create an array of data points | ||
63 | +// ANNpointArray pts = (ANNpointArray)c; //cast the centerline list to an ANNpointArray | ||
64 | +// kdt = new ANNkd_tree(pts, n_data, 3); //build a KD tree | ||
65 | +// } | ||
72 | 66 | ||
73 | /// find distance between two points | 67 | /// find distance between two points |
74 | double dist(double* p0, double* p1){ | 68 | double dist(double* p0, double* p1){ |
@@ -79,7 +73,6 @@ protected: | @@ -79,7 +73,6 @@ protected: | ||
79 | { | 73 | { |
80 | v = p1[d] - p0[d]; | 74 | v = p1[d] - p0[d]; |
81 | sum +=v * v; | 75 | sum +=v * v; |
82 | - | ||
83 | } | 76 | } |
84 | return sqrt(sum); | 77 | return sqrt(sum); |
85 | } | 78 | } |
@@ -87,21 +80,18 @@ protected: | @@ -87,21 +80,18 @@ protected: | ||
87 | /// This function retreives the index for the fiber point closest to q | 80 | /// This function retreives the index for the fiber point closest to q |
88 | 81 | ||
89 | /// @param q is a reference point used to find the closest point on the fiber center line | 82 | /// @param q is a reference point used to find the closest point on the fiber center line |
90 | - unsigned int ann( stim::vec<double> q ){ | ||
91 | - | ||
92 | - ANNidxArray idx = new ANNidx[1]; //variable used to hold the nearest point | ||
93 | - ANNdistArray sq_dist = new ANNdist[1]; //variable used to hold the squared distance to the nearest point | ||
94 | - | ||
95 | - kdt->annkSearch(q.data(), 1, idx, sq_dist); //search the KD tree for the nearest neighbor | ||
96 | - | ||
97 | - return *idx; | ||
98 | - } | 83 | +// unsigned int ann( stim::vec<double> q ){ |
84 | +// ANNidxArray idx = new ANNidx[1]; //variable used to hold the nearest point | ||
85 | +// ANNdistArray sq_dist = new ANNdist[1]; //variable used to hold the squared distance to the nearest point | ||
86 | +// kdt->annkSearch(q.data(), 1, idx, sq_dist); //search the KD tree for the nearest neighbor | ||
87 | +// return *idx; | ||
88 | +// } | ||
99 | 89 | ||
100 | /// Returns a stim::vec representing the point at index i | 90 | /// Returns a stim::vec representing the point at index i |
101 | 91 | ||
102 | /// @param i is an index of the desired centerline point | 92 | /// @param i is an index of the desired centerline point |
103 | stim::vec<T> get_vec(unsigned i){ | 93 | stim::vec<T> get_vec(unsigned i){ |
104 | - stim::vec<T> r; | 94 | + stim::vec3<T> r; |
105 | r.resize(3); | 95 | r.resize(3); |
106 | r[0] = c[i][0]; | 96 | r[0] = c[i][0]; |
107 | r[1] = c[i][1]; | 97 | r[1] = c[i][1]; |
@@ -113,25 +103,23 @@ protected: | @@ -113,25 +103,23 @@ protected: | ||
113 | 103 | ||
114 | public: | 104 | public: |
115 | 105 | ||
116 | - fiber(){ | 106 | + centerline(){ |
117 | init(); | 107 | init(); |
118 | } | 108 | } |
119 | 109 | ||
120 | /// Copy constructor | 110 | /// Copy constructor |
121 | - fiber(const stim::fiber<T> &obj){ | ||
122 | - | 111 | + centerline(const stim::centerline<T> &obj){ |
123 | copy(obj); | 112 | copy(obj); |
124 | - | ||
125 | } | 113 | } |
126 | 114 | ||
127 | //temp constructor for graph visualization | 115 | //temp constructor for graph visualization |
128 | - fiber(int n) | 116 | + centerline(int n) |
129 | { | 117 | { |
130 | init(n); | 118 | init(n); |
131 | } | 119 | } |
132 | 120 | ||
133 | /// Constructor takes a list of stim::vec points, the radius at each point is set to zero | 121 | /// Constructor takes a list of stim::vec points, the radius at each point is set to zero |
134 | - fiber(std::vector< stim::vec<T> > p){ | 122 | + centerline(std::vector< stim::vec<T> > p, bool kd = 0){ |
135 | init(p.size()); //initialize the fiber | 123 | init(p.size()); //initialize the fiber |
136 | 124 | ||
137 | //for each point, set the centerline position and radius | 125 | //for each point, set the centerline position and radius |
@@ -142,200 +130,77 @@ public: | @@ -142,200 +130,77 @@ public: | ||
142 | c[i][d] = (double) p[i][d]; | 130 | c[i][d] = (double) p[i][d]; |
143 | 131 | ||
144 | //set the radius | 132 | //set the radius |
145 | - r[i] = 0; | ||
146 | } | 133 | } |
147 | - | ||
148 | //generate a kd tree | 134 | //generate a kd tree |
149 | - gen_kdtree(); | 135 | +// if(kd) |
136 | +// gen_kdtree(); | ||
150 | } | 137 | } |
151 | 138 | ||
152 | - /// constructor takes a list of points and radii | ||
153 | - fiber(std::vector< stim::vec< T > > pos, std::vector< T > radii){ | 139 | + /// constructor takes a list of points |
140 | + centerline(std::vector< stim::vec3< T > > pos, bool kd = 0){ | ||
154 | init(pos.size()); //initialize the fiber | 141 | init(pos.size()); //initialize the fiber |
155 | 142 | ||
156 | //for each point, set the centerline position and radius | 143 | //for each point, set the centerline position and radius |
157 | for(unsigned int i = 0; i < N; i++){ | 144 | for(unsigned int i = 0; i < N; i++){ |
158 | - | ||
159 | //set the centerline position | 145 | //set the centerline position |
160 | for(unsigned int d = 0; d < 3; d++) | 146 | for(unsigned int d = 0; d < 3; d++) |
161 | c[i][d] = (double) pos[i][d]; | 147 | c[i][d] = (double) pos[i][d]; |
162 | - | ||
163 | //set the radius | 148 | //set the radius |
164 | - r[i] = radii[i]; | ||
165 | } | 149 | } |
166 | 150 | ||
167 | //generate a kd tree | 151 | //generate a kd tree |
168 | - gen_kdtree(); | ||
169 | - } | ||
170 | - | ||
171 | - /// constructor takes an array of points and radii | ||
172 | - // this function is used when the radii are represented as a stim::vec, | ||
173 | - // since this may be easier when importing OBJs | ||
174 | - fiber(std::vector< stim::vec<T> > pos, std::vector< stim::vec<T> > radii){ | ||
175 | - | ||
176 | - init(pos.size()); | ||
177 | - | ||
178 | - //for each point, set the position and radius | ||
179 | - for(unsigned int i = 0; i < N; i++){ | ||
180 | - //at(i) = (double*)malloc(sizeof(double) * 3); | ||
181 | - for(unsigned int d = 0; d < 3; d++) | ||
182 | - c[i][d] = (double) pos[i][d]; | ||
183 | - | ||
184 | - r[i] = radii[i][(unsigned int)0]; | ||
185 | - } | ||
186 | - | ||
187 | - gen_kdtree(); | 152 | + //if(kd) |
153 | + // gen_kdtree(); | ||
188 | } | 154 | } |
189 | 155 | ||
190 | /// Assignment operation | 156 | /// Assignment operation |
191 | - fiber& operator=(const fiber &rhs){ | ||
192 | - | 157 | + centerline& operator=(const centerline &rhs){ |
193 | if(this == &rhs) return *this; //test for and handle self-assignment | 158 | if(this == &rhs) return *this; //test for and handle self-assignment |
194 | - | ||
195 | copy(rhs); | 159 | copy(rhs); |
160 | + return *this; | ||
196 | } | 161 | } |
197 | 162 | ||
198 | - /// Calculate the length of the fiber and return it. | ||
199 | - double length(){ | ||
200 | - | ||
201 | - double* p0; | ||
202 | - double *p1; | ||
203 | - double l = 0; //initialize the length to zero | ||
204 | - | ||
205 | - //for each point | ||
206 | - //typename std::list< point<T> >::iterator i; //create a point iterator | ||
207 | - for(unsigned int i = 0; i < N; i++){ //for each point in the fiber | ||
208 | - | ||
209 | - if(i == 0) //if this is the first point, just store it | ||
210 | - p1 = c[0]; | ||
211 | - else{ //if this is any other point | ||
212 | - p0 = p1; //shift p1->p0 | ||
213 | - p1 = c[i]; //set p1 to the new point | ||
214 | - l += dist(p0, p1); //add the length of p1 - p0 to the running sum | ||
215 | - } | ||
216 | - } | ||
217 | - | ||
218 | - return l; //return the length | ||
219 | - } | ||
220 | - | ||
221 | - /// Calculates the length and average radius of the fiber | ||
222 | - | ||
223 | - /// @param length is filled with the fiber length | ||
224 | - T radius(T& length){ | ||
225 | - | ||
226 | - double* p0; //temporary variables to store point positions | ||
227 | - double* p1; | ||
228 | - T r0, r1; //temporary variables to store radii at points | ||
229 | - double l; | ||
230 | - T r_mean; //temporary variable to store the length and average radius of a fiber segment | ||
231 | - double length_sum = 0; //initialize the length to zero | ||
232 | - T radius_sum = 0; //initialize the radius sum to zero | ||
233 | - | ||
234 | - //for each point | ||
235 | - //typename std::list< point<T> >::iterator i; //create a point iterator | ||
236 | - for(unsigned int i = 0; i < N; i++){ //for each point in the fiber | ||
237 | - | ||
238 | - if(i == 0){ //if this is the first point, just store it | ||
239 | - p1 = c[0]; | ||
240 | - r1 = r[0]; | ||
241 | - } | ||
242 | - else{ //if this is any other point | ||
243 | - p0 = p1; //shift p1->p0 and r1->r0 | ||
244 | - r0 = r1; | ||
245 | - p1 = c[i]; //set p1 to the new point | ||
246 | - r1 = r[i]; | ||
247 | - | ||
248 | - l = dist(p0, p1); //calculate the length of the p0-p1 segment | ||
249 | - r_mean = (r0 + r1) / 2; //calculate the average radius of the segment | ||
250 | - | ||
251 | - radius_sum += r_mean * (T) l; //add the radius scaled by the length to a running sum | ||
252 | - length_sum += l; //add the length of p1 - p0 to the running sum | ||
253 | - } | ||
254 | - } | ||
255 | - | ||
256 | - length = length_sum; //store the total length | ||
257 | - | ||
258 | - //if the total length is zero, store a radius of zero | ||
259 | - if(length == 0) | ||
260 | - return 0; | ||
261 | - else | ||
262 | - return (T)(radius_sum / length); //return the average radius of the fiber | ||
263 | - } | ||
264 | - T average_radius() | ||
265 | - { | ||
266 | - T r_sum = 0.; | ||
267 | - for(unsigned int i = 0; i < N; i++) | ||
268 | - { | ||
269 | - r_sum = r_sum + r[i]; | ||
270 | - } | ||
271 | - return r_sum/((T) N); | ||
272 | - } | ||
273 | - | ||
274 | - /// Calculates the average radius of the fiber | ||
275 | - T radius(){ | ||
276 | - T length; | ||
277 | - return radius(length); | ||
278 | - } | ||
279 | - | ||
280 | - /// Returns the radius at index idx. | ||
281 | - T radius(int idx){ | ||
282 | - return r[idx]; | ||
283 | - } | ||
284 | 163 | ||
285 | /// Return the point on the fiber closest to q | 164 | /// Return the point on the fiber closest to q |
286 | /// @param q is the query point used to locate the nearest point on the fiber centerline | 165 | /// @param q is the query point used to locate the nearest point on the fiber centerline |
287 | - stim::vec<T> nearest(stim::vec<T> q){ | ||
288 | - | ||
289 | - stim::vec<double> temp( (double) q[0], (double) q[1], (double) q[2]); | ||
290 | - | ||
291 | - unsigned int idx = ann(temp); //determine the index of the nearest neighbor | ||
292 | - | ||
293 | - return stim::vec<T>((T) c[idx][0], (T) c[idx][1], (T) c[idx][2]); //return the nearest centerline point | ||
294 | - } | 166 | +// stim::vec<T> nearest(stim::vec<T> q){ |
167 | +// | ||
168 | +// stim::vec<double> temp( (double) q[0], (double) q[1], (double) q[2]); | ||
169 | +// | ||
170 | +// unsigned int idx = ann(temp); //determine the index of the nearest neighbor | ||
171 | +// | ||
172 | +// return stim::vec<T>((T) c[idx][0], (T) c[idx][1], (T) c[idx][2]); //return the nearest centerline point | ||
173 | +// } | ||
295 | 174 | ||
296 | /// Return the point index on the fiber closest to q | 175 | /// Return the point index on the fiber closest to q |
297 | /// @param q is the query point used to locate the nearest point on the fiber centerline | 176 | /// @param q is the query point used to locate the nearest point on the fiber centerline |
298 | - unsigned int nearest_idx(stim::vec<T> q){ | ||
299 | - | ||
300 | - stim::vec<double> temp((double) q[0], (double) q[1], (double) q[2]); | ||
301 | - | ||
302 | - unsigned int idx = ann(temp); //determine the index of the nearest neighbor | ||
303 | - | ||
304 | - return idx; //return the nearest centerline point index | ||
305 | - } | 177 | +// unsigned int nearest_idx(stim::vec<T> q){ |
178 | +// | ||
179 | +// stim::vec<double> temp((double) q[0], (double) q[1], (double) q[2]); | ||
180 | +// | ||
181 | +// unsigned int idx = ann(temp); //determine the index of the nearest neighbor | ||
182 | +// | ||
183 | +// return idx; //return the nearest centerline point index | ||
184 | +// } | ||
306 | 185 | ||
307 | /// Returns the fiber centerline as an array of stim::vec points | 186 | /// Returns the fiber centerline as an array of stim::vec points |
308 | - std::vector< stim::vec<T> > centerline(){ | 187 | + std::vector< stim::vec<T> > get_centerline(){ |
309 | 188 | ||
310 | //create an array of stim vectors | 189 | //create an array of stim vectors |
311 | - std::vector< stim::vec<T> > pts(N); | 190 | + std::vector< stim::vec3<T> > pts(N); |
312 | 191 | ||
313 | //cast each point to a stim::vec, keeping only the position information | 192 | //cast each point to a stim::vec, keeping only the position information |
314 | for(unsigned int i = 0; i < N; i++) | 193 | for(unsigned int i = 0; i < N; i++) |
315 | - pts[i] = stim::vec<T>((T) c[i][0], (T) c[i][1], (T) c[i][2]); | ||
316 | - | ||
317 | - //return the centerline array | ||
318 | - return pts; | ||
319 | - } | ||
320 | - | ||
321 | - /// Returns the fiber centerline magnitudes as an array of stim::vec points | ||
322 | - std::vector< stim::vec<T> > centerlinemag(){ | ||
323 | - | ||
324 | - //create an array of stim vectors | ||
325 | - std::vector< stim::vec<T> > pts(N); | ||
326 | - | ||
327 | - //cast each point to a stim::vec, keeping only the position information | ||
328 | - for(unsigned int i = 0; i < N; i++) | ||
329 | - pts[i] = stim::vec<T>(r[i], r[i]);; | 194 | + pts[i] = stim::vec3<T>((T) c[i][0], (T) c[i][1], (T) c[i][2]); |
330 | 195 | ||
331 | //return the centerline array | 196 | //return the centerline array |
332 | return pts; | 197 | return pts; |
333 | } | 198 | } |
334 | 199 | ||
335 | /// Split the fiber at the specified index. If the index is an end point, only one fiber is returned | 200 | /// Split the fiber at the specified index. If the index is an end point, only one fiber is returned |
336 | - std::vector< stim::fiber<T> > split(unsigned int idx){ | 201 | + std::vector< stim::centerline<T> > split(unsigned int idx){ |
337 | 202 | ||
338 | - std::vector< stim::fiber<T> > fl; //create an array to store up to two fibers | 203 | + std::vector< stim::centerline<T> > fl; //create an array to store up to two fibers |
339 | 204 | ||
340 | //if the index is an end point, only the existing fiber is returned | 205 | //if the index is an end point, only the existing fiber is returned |
341 | if(idx == 0 || idx == N-1){ | 206 | if(idx == 0 || idx == N-1){ |
@@ -361,14 +226,13 @@ public: | @@ -361,14 +226,13 @@ public: | ||
361 | for(i = 0; i < N1; i++){ //for each centerline point | 226 | for(i = 0; i < N1; i++){ //for each centerline point |
362 | for(d = 0; d < 3; d++) | 227 | for(d = 0; d < 3; d++) |
363 | fl[0].c[i][d] = c[i][d]; //copy each coordinate | 228 | fl[0].c[i][d] = c[i][d]; //copy each coordinate |
364 | - fl[0].r[i] = r[i]; //copy the corresponding radius | ||
365 | } | 229 | } |
366 | 230 | ||
367 | //second half | 231 | //second half |
368 | for(i = 0; i < N2; i++){ | 232 | for(i = 0; i < N2; i++){ |
369 | for(d = 0; d < 3; d++) | 233 | for(d = 0; d < 3; d++) |
370 | fl[1].c[i][d] = c[idx + i][d]; | 234 | fl[1].c[i][d] = c[idx + i][d]; |
371 | - fl[1].r[i] = r[idx + i]; | 235 | + |
372 | } | 236 | } |
373 | } | 237 | } |
374 | 238 | ||
@@ -379,7 +243,7 @@ public: | @@ -379,7 +243,7 @@ public: | ||
379 | /// Calculates the set of fibers resulting from a connection between the current fiber and a fiber f | 243 | /// Calculates the set of fibers resulting from a connection between the current fiber and a fiber f |
380 | 244 | ||
381 | /// @param f is the fiber that will be connected to the current fiber | 245 | /// @param f is the fiber that will be connected to the current fiber |
382 | - std::vector< stim::fiber<T> > connect( stim::fiber<T> &f, double dist){ | 246 | +/* std::vector< stim::centerline<T> > connect( stim::centerline<T> &f, double dist){ |
383 | 247 | ||
384 | double min_dist; | 248 | double min_dist; |
385 | unsigned int idx0, idx1; | 249 | unsigned int idx0, idx1; |
@@ -393,7 +257,7 @@ public: | @@ -393,7 +257,7 @@ public: | ||
393 | 257 | ||
394 | 258 | ||
395 | } | 259 | } |
396 | - | 260 | +*/ |
397 | /// Outputs the fiber as a string | 261 | /// Outputs the fiber as a string |
398 | std::string str(){ | 262 | std::string str(){ |
399 | std::stringstream ss; | 263 | std::stringstream ss; |
@@ -405,7 +269,6 @@ public: | @@ -405,7 +269,6 @@ public: | ||
405 | for(unsigned int d = 0; d < 3; d++){ | 269 | for(unsigned int d = 0; d < 3; d++){ |
406 | ss<<c[i][d]<<" "; | 270 | ss<<c[i][d]<<" "; |
407 | } | 271 | } |
408 | - ss<<"] r = "<<r[i]<<std::endl; | ||
409 | } | 272 | } |
410 | 273 | ||
411 | return ss.str(); | 274 | return ss.str(); |
@@ -428,7 +291,7 @@ public: | @@ -428,7 +291,7 @@ public: | ||
428 | return get_vec(N-1); | 291 | return get_vec(N-1); |
429 | } | 292 | } |
430 | ////resample a fiber in the network | 293 | ////resample a fiber in the network |
431 | - stim::fiber<T> resample(T spacing) | 294 | + stim::centerline<T> resample(T spacing) |
432 | { | 295 | { |
433 | std::cout<<"fiber::resample()"<<std::endl; | 296 | std::cout<<"fiber::resample()"<<std::endl; |
434 | 297 | ||
@@ -468,7 +331,7 @@ public: | @@ -468,7 +331,7 @@ public: | ||
468 | newPointList.push_back(fiberPositions[f+1]); | 331 | newPointList.push_back(fiberPositions[f+1]); |
469 | } | 332 | } |
470 | newPointList.push_back(fiberPositions[N-1]); //add the last point on the fiber to the new fiber list | 333 | newPointList.push_back(fiberPositions[N-1]); //add the last point on the fiber to the new fiber list |
471 | - fiber newFiber(newPointList); | 334 | + centerline newFiber(newPointList); |
472 | return newFiber; | 335 | return newFiber; |
473 | } | 336 | } |
474 | 337 |
stim/cuda/testKernel.cuh
@@ -8,7 +8,7 @@ | @@ -8,7 +8,7 @@ | ||
8 | #include <stim/cuda/cudatools/devices.h> | 8 | #include <stim/cuda/cudatools/devices.h> |
9 | #include <stim/cuda/cudatools/threads.h> | 9 | #include <stim/cuda/cudatools/threads.h> |
10 | #include <stim/cuda/cuda_texture.cuh> | 10 | #include <stim/cuda/cuda_texture.cuh> |
11 | - stim::cuda::cuda_texture tx; //texture object. | 11 | + |
12 | float* print; | 12 | float* print; |
13 | 13 | ||
14 | ///Initialization function, allocates the memory and passes the necessary | 14 | ///Initialization function, allocates the memory and passes the necessary |
@@ -26,16 +26,16 @@ | @@ -26,16 +26,16 @@ | ||
26 | cudaFree(print); ///temporary | 26 | cudaFree(print); ///temporary |
27 | } | 27 | } |
28 | 28 | ||
29 | - __device__ | ||
30 | - float templ(int x) | ||
31 | - { | ||
32 | - if(x < 32/6 || x > 32*5/6 || (x > 32*2/6 && x < 32*4/6)){ | ||
33 | - return 1.0; | ||
34 | - }else{ | ||
35 | - return 0.0; | ||
36 | - } | ||
37 | - | ||
38 | - } | 29 | + __device__ |
30 | + float templ(int x, int max_x) | ||
31 | + { | ||
32 | + if(x < max_x/6 || x > max_x*5/6 || (x > max_x*2/6 && x < max_x*4/6)) | ||
33 | + { | ||
34 | + return 1.0; | ||
35 | + }else{ | ||
36 | + return 0.0; | ||
37 | + } | ||
38 | + } | ||
39 | 39 | ||
40 | ///Find the difference of the given set of samples and the template | 40 | ///Find the difference of the given set of samples and the template |
41 | ///using cuda acceleration. | 41 | ///using cuda acceleration. |
@@ -44,33 +44,24 @@ | @@ -44,33 +44,24 @@ | ||
44 | ///@param float* result --a pointer to the memory that stores the result. | 44 | ///@param float* result --a pointer to the memory that stores the result. |
45 | __global__ | 45 | __global__ |
46 | //void get_diff (float *result) | 46 | //void get_diff (float *result) |
47 | - void get_diff (cudaTextureObject_t texIn, float *print) | 47 | + void get_diff (cudaTextureObject_t texIn, float *print, int dx) |
48 | { | 48 | { |
49 | int x = threadIdx.x + blockIdx.x * blockDim.x; | 49 | int x = threadIdx.x + blockIdx.x * blockDim.x; |
50 | int y = threadIdx.y + blockIdx.y * blockDim.y; | 50 | int y = threadIdx.y + blockIdx.y * blockDim.y; |
51 | -// int idx = y*64+x; | ||
52 | - int idx = y*32+x; | 51 | + int idx = y*dx+x; |
53 | // int idx = y*16+x; | 52 | // int idx = y*16+x; |
54 | 53 | ||
55 | float valIn = tex2D<unsigned char>(texIn, x, y); | 54 | float valIn = tex2D<unsigned char>(texIn, x, y); |
56 | - float templa = templ(x); | ||
57 | - print[idx] = valIn; ///temporary | 55 | + float templa = templ(x, 32)*255.0; |
56 | + print[idx] = abs(valIn-templa); ///temporary | ||
58 | //print[idx] = abs(templa); ///temporary | 57 | //print[idx] = abs(templa); ///temporary |
59 | 58 | ||
60 | } | 59 | } |
61 | 60 | ||
62 | - | ||
63 | - ///External access-point to the cuda function | ||
64 | - ///@param GLuint texbufferID --GLtexture (most be contained in a framebuffer object) | ||
65 | - /// that holds the data that will be handed to cuda. | ||
66 | - ///@param GLenum texType --either GL_TEXTURE_1D, GL_TEXTURE_2D or GL_TEXTURE_3D | ||
67 | - /// may work with other gl texture types, but untested. | ||
68 | - ///@param DIM_Y, the number of samples in the template. | ||
69 | - void test(GLint texbufferID, GLenum texType, int x, int y) | 61 | + void test(cudaTextureObject_t tObj, int x, int y, std::string nam) |
70 | { | 62 | { |
71 | 63 | ||
72 | //Bind the Texture in GL and allow access to cuda. | 64 | //Bind the Texture in GL and allow access to cuda. |
73 | - tx.MapCudaTexture(texbufferID, texType); | ||
74 | 65 | ||
75 | //initialize the return arrays. | 66 | //initialize the return arrays. |
76 | 67 | ||
@@ -85,44 +76,13 @@ | @@ -85,44 +76,13 @@ | ||
85 | 76 | ||
86 | 77 | ||
87 | // get_diff <<< blocks, threads >>> (tx.getTexture(), print); | 78 | // get_diff <<< blocks, threads >>> (tx.getTexture(), print); |
88 | - get_diff <<< numBlocks, threadsPerBlock >>> (tx.getTexture(), print); | ||
89 | - | ||
90 | - cudaDeviceSynchronize(); | ||
91 | - stringstream name; //for debugging | ||
92 | - name << "FromTex.bmp"; | ||
93 | - stim::gpu2image<float>(print, name.str(),x,y,0,255); | ||
94 | - | ||
95 | - tx.UnmapCudaTexture(); | ||
96 | - cleanUP(); | ||
97 | - } | ||
98 | - | ||
99 | - void test(GLint texbufferID, GLenum texType, int x, int y, std::string nam) | ||
100 | - { | ||
101 | - | ||
102 | - //Bind the Texture in GL and allow access to cuda. | ||
103 | - tx.MapCudaTexture(texbufferID, texType); | ||
104 | - | ||
105 | - //initialize the return arrays. | ||
106 | - | ||
107 | - initArray(x,y); | ||
108 | - dim3 numBlocks(1, y); | ||
109 | - dim3 threadsPerBlock(x, 1); | ||
110 | - int max_threads = stim::maxThreadsPerBlock(); | ||
111 | - //dim3 threads(max_threads, 1); | ||
112 | - //dim3 blocks(x / threads.x + 1, y); | ||
113 | - //dim3 numBlocks(2, 2); | ||
114 | - //dim3 threadsPerBlock(8, 108); | ||
115 | - | ||
116 | - | ||
117 | -// get_diff <<< blocks, threads >>> (tx.getTexture(), print); | ||
118 | - get_diff <<< numBlocks, threadsPerBlock >>> (tx.getTexture(), print); | 79 | + get_diff <<< numBlocks, threadsPerBlock >>> (tObj, print, x); |
119 | 80 | ||
120 | cudaDeviceSynchronize(); | 81 | cudaDeviceSynchronize(); |
121 | stringstream name; //for debugging | 82 | stringstream name; //for debugging |
122 | name << nam.c_str(); | 83 | name << nam.c_str(); |
123 | - //stim::gpu2image<float>(print, name.str(),x,y,0,255); | 84 | + stim::gpu2image<float>(print, name.str(),x,y,0,255); |
124 | 85 | ||
125 | - tx.UnmapCudaTexture(); | ||
126 | cleanUP(); | 86 | cleanUP(); |
127 | } | 87 | } |
128 | 88 |
stim/gl/gl_spider.h
@@ -23,14 +23,11 @@ | @@ -23,14 +23,11 @@ | ||
23 | #include <stim/cuda/ivote.cuh> | 23 | #include <stim/cuda/ivote.cuh> |
24 | #include <stim/visualization/glObj.h> | 24 | #include <stim/visualization/glObj.h> |
25 | #include <vector> | 25 | #include <vector> |
26 | +#include <stack> | ||
26 | #include <stim/cuda/branch_detection.cuh> | 27 | #include <stim/cuda/branch_detection.cuh> |
27 | -#include "../../../volume-spider/fiber.h" | ||
28 | #include "../../../volume-spider/glnetwork.h" | 28 | #include "../../../volume-spider/glnetwork.h" |
29 | #include <stim/visualization/cylinder.h> | 29 | #include <stim/visualization/cylinder.h> |
30 | #include <stim/cuda/testKernel.cuh> | 30 | #include <stim/cuda/testKernel.cuh> |
31 | - | ||
32 | -//#include <stim/cuda/testKernel.cuh> | ||
33 | - | ||
34 | #include <iostream> | 31 | #include <iostream> |
35 | #include <fstream> | 32 | #include <fstream> |
36 | #ifdef TIMING | 33 | #ifdef TIMING |
@@ -39,7 +36,6 @@ | @@ -39,7 +36,6 @@ | ||
39 | #endif | 36 | #endif |
40 | 37 | ||
41 | #ifdef TESTING | 38 | #ifdef TESTING |
42 | - #include <iostream> | ||
43 | #include <cstdio> | 39 | #include <cstdio> |
44 | #include <ctime> | 40 | #include <ctime> |
45 | #endif | 41 | #endif |
@@ -49,7 +45,7 @@ namespace stim | @@ -49,7 +45,7 @@ namespace stim | ||
49 | { | 45 | { |
50 | 46 | ||
51 | template<typename T> | 47 | template<typename T> |
52 | -class gl_spider : public virtual gl_texture<T> | 48 | +class gl_spider // : public virtual gl_texture<T> |
53 | { | 49 | { |
54 | //doen't use gl_texture really, just needs the GLuint id. | 50 | //doen't use gl_texture really, just needs the GLuint id. |
55 | //doesn't even need the texture iD really. | 51 | //doesn't even need the texture iD really. |
@@ -65,72 +61,87 @@ class gl_spider : public virtual gl_texture<T> | @@ -65,72 +61,87 @@ class gl_spider : public virtual gl_texture<T> | ||
65 | double hit_time;// = 0; | 61 | double hit_time;// = 0; |
66 | #endif | 62 | #endif |
67 | 63 | ||
68 | - // | ||
69 | stim::vec3<float> p; //vector designating the position of the spider. | 64 | stim::vec3<float> p; //vector designating the position of the spider. |
70 | - stim::vec3<float> d; //vector designating the orientation of the spider | ||
71 | - //always a unit vector. | ||
72 | - stim::vec<float> m; //magnitude of the spider vector. | ||
73 | - //mag[0] = length. | ||
74 | - //mag[1] = width. | 65 | + stim::vec3<float> d; //normalized direction of travel |
66 | + float m; //size of the spider in tissue space. | ||
67 | + | ||
75 | std::vector<stim::vec3<float> > dV; //A list of all the direction vectors. | 68 | std::vector<stim::vec3<float> > dV; //A list of all the direction vectors. |
76 | - std::vector<stim::vec3<float> > pV; //A list of all the position vectors. | ||
77 | - std::vector<stim::vec3<float> > mV; //A list of all the size vectors. | 69 | + std::vector<stim::vec3<float> > pV; //A list of all test positions (relative to p) |
70 | + std::vector<float> mV; //A list of all the size vectors. | ||
78 | 71 | ||
79 | - stim::matrix<float, 4> cT; //current Transformation matrix | ||
80 | - //From tissue space to texture space. | ||
81 | - GLuint texID; | ||
82 | - stim::vec<float> S; //Size of a voxel in the volume. | ||
83 | - stim::vec<float> R; //Dimensions of the volume. | 72 | + stim::matrix<float, 4> cT; //current Transformation matrix (tissue)->(texture) |
73 | + GLuint texID; //OpenGL ID for the texture to be traced | ||
74 | + stim::vec3<float> S; //Size of a voxel in the volume. | ||
75 | + stim::vec3<float> R; //Dimensions of the volume. | ||
84 | 76 | ||
85 | 77 | ||
86 | //GL and Cuda variables | 78 | //GL and Cuda variables |
87 | - GLuint dList; //displaylist ID | ||
88 | - GLuint fboID; //framebuffer ID | ||
89 | - GLuint texbufferID; //texbuffer ID, only necessary for | ||
90 | - //cuda aspect of the calculation. | ||
91 | - GLuint pfboID; //buffer object for position tracking. | ||
92 | - GLuint ptexbufferID; //texture object for position tracking. | ||
93 | - | ||
94 | - GLuint mfboID; //buffer object for magnitude adjustment. | ||
95 | - GLuint mtexbufferID; //texture object for magnitude adjustment. | ||
96 | - GLuint bfboID; //buffer object for position adjustment. | ||
97 | - GLuint btexbufferID; //buffer object for position adjustment. | 79 | + GLuint dList; //ID of the starting display lists (series of 4) |
80 | + //dList + 0 = direction template rectangles | ||
81 | + //dList + 1 = position template rectangles | ||
82 | + //dList + 2 = size template rectangles | ||
83 | + //dList + 3 = branch detection cylinder around the fiber | ||
84 | + | ||
85 | + GLuint fboID; //framebuffer ID for direction templates | ||
86 | + GLuint texbufferID; //texture ID for direction templates | ||
87 | + GLuint direction_buffID; //framebuffer ID, position templates | ||
88 | + GLuint direction_texID; //texture ID, position templates | ||
89 | + | ||
90 | + GLuint position_buffID; //framebuffer ID, position templates | ||
91 | + GLuint position_texID; //texture ID, position templates | ||
92 | + | ||
93 | + GLuint radius_buffID; //framebuffer ID, radius templates | ||
94 | + GLuint radius_texID; //texture ID, radius templates | ||
95 | + | ||
96 | + GLuint cylinder_buffID; //framebuffer ID, cylinder (surrounding fiber) | ||
97 | + GLuint cylinder_texID; //texture ID, cylinder | ||
98 | 98 | ||
99 | int numSamples; //The number of templates in the buffer. | 99 | int numSamples; //The number of templates in the buffer. |
100 | int numSamplesPos; | 100 | int numSamplesPos; |
101 | int numSamplesMag; | 101 | int numSamplesMag; |
102 | 102 | ||
103 | - float stepsize;// = 5.0; //Step size. | ||
104 | -// float stepsize = 3.0; //Step size. | ||
105 | - int current_cost; //variable to store the cost of the current step. | ||
106 | - | 103 | + float length; //this will be a function of the radius |
104 | + float stepsize; //this will be a function of the length | ||
105 | + | ||
106 | + int current_cost; //variable to store the cost of the current step | ||
107 | 107 | ||
108 | //Tracing variables. | 108 | //Tracing variables. |
109 | - std::stack< stim::vec3<float> > seeds; //seed positions. | ||
110 | - std::stack< stim::vec3<float> > seedsvecs; //seed directions. | ||
111 | - std::stack< float > seedsmags; //seed magnitudes. | 109 | + std::stack< stim::vec3<float> > seeds; //seed positions |
110 | + std::stack< stim::vec3<float> > seedsvecs; //seed directions | ||
111 | + std::stack< float > seedsmags; //seed magnitudes | ||
112 | + | ||
113 | + std::vector< stim::vec3<float> > cL; //centerline up to the current point | ||
114 | + std::vector< stim::vec3<float> > cD; //directions up to the current point (debugging) | ||
115 | + std::vector< float > cM; //radius up to the current point | ||
112 | 116 | ||
113 | - std::vector< stim::vec3<float> > cL; //Positions of line currently being traced. | ||
114 | - std::vector< stim::vec3<float> > cD; //Direction of line currently being traced. | ||
115 | - std::vector< stim::vec<float> > cM; //Magnitude of line currently being traced. | 117 | + stim::glnetwork<float> nt; //network object holding the currently traced centerlines |
118 | + stim::glObj<float> sk; //OBJ file storing the network (identical to above) | ||
116 | 119 | ||
117 | - stim::glnetwork<float> nt; //object for storing the network. | 120 | + //consider replacing with two seed points facing opposite directions |
121 | + stim::vec<float> rev; //reverse vector | ||
118 | 122 | ||
119 | - stim::vec<float> rev; //reverse vector; | ||
120 | - stim::camera camSel; | ||
121 | - stim::vec3<float> ps; | ||
122 | - stim::vec3<float> ups; | ||
123 | - stim::vec3<float> ds; | 123 | + //selection mode - detecting fiber intersections |
124 | + stim::camera camSel; //camera for selection mode (detecting collisions) | ||
125 | + stim::vec3<float> ps; //position for the selection camera | ||
126 | + stim::vec3<float> ups; //up direction for the selection camera | ||
127 | + stim::vec3<float> ds; //direction for the selection camera | ||
124 | 128 | ||
125 | - //static const float t_length = 16.0; | ||
126 | - float t_length; | 129 | + float n_pixels; //length of the template (in pixels) |
127 | 130 | ||
128 | //cuda texture variables that keep track of the binding. | 131 | //cuda texture variables that keep track of the binding. |
129 | - stim::cuda::cuda_texture t_dir; | ||
130 | - stim::cuda::cuda_texture t_pos; | ||
131 | - stim::cuda::cuda_texture t_mag; | 132 | + stim::cuda::cuda_texture t_dir; //cuda_texture object used as an interface between OpenGL and cuda for direction vectors. |
133 | + stim::cuda::cuda_texture t_pos; //cuda_texture object used as an interface between OpenGL and cuda for position vectors. | ||
134 | + stim::cuda::cuda_texture t_mag; //cuda_texture object used as an interface between OpenGL and cuda for size vectors. | ||
132 | 135 | ||
133 | 136 | ||
137 | + #ifdef DEBUG | ||
138 | + stringstream name; | ||
139 | + int iter; | ||
140 | + int iter_pos; | ||
141 | + int iter_dir; | ||
142 | + int iter_siz; | ||
143 | + #endif | ||
144 | + | ||
134 | //--------------------------------------------------------------------------// | 145 | //--------------------------------------------------------------------------// |
135 | //-------------------------------PRIVATE METHODS----------------------------// | 146 | //-------------------------------PRIVATE METHODS----------------------------// |
136 | //--------------------------------------------------------------------------// | 147 | //--------------------------------------------------------------------------// |
@@ -142,31 +153,32 @@ class gl_spider : public virtual gl_texture<T> | @@ -142,31 +153,32 @@ class gl_spider : public virtual gl_texture<T> | ||
142 | findOptimalDirection() | 153 | findOptimalDirection() |
143 | { | 154 | { |
144 | #ifdef TIMING | 155 | #ifdef TIMING |
145 | - gpuStartTimer(); | 156 | + gpuStartTimer(); //Timer for profiling |
146 | #endif | 157 | #endif |
147 | setMatrix(); //create the transformation matrix. | 158 | setMatrix(); //create the transformation matrix. |
148 | glCallList(dList); //move the templates to p, d, m. | 159 | glCallList(dList); //move the templates to p, d, m. |
149 | - glFinish(); | ||
150 | -// glFlush(); | 160 | + glFinish(); //flush the pipeline |
151 | #ifdef TIMING | 161 | #ifdef TIMING |
152 | - direction_time += gpuStopTimer(); | ||
153 | - #endif | ||
154 | - #ifdef TESTING | ||
155 | -// test(texbufferID, GL_TEXTURE_2D,2*t_length,numSamples*t_length, "Final_Cost_Direction.bmp"); | 162 | + direction_time += gpuStopTimer(); //profiling |
156 | #endif | 163 | #endif |
157 | 164 | ||
158 | int best = getCost(t_dir.getTexture(), t_dir.getAuxArray() ,numSamples); //find min cost. | 165 | int best = getCost(t_dir.getTexture(), t_dir.getAuxArray() ,numSamples); //find min cost. |
159 | - stim::vec<float> next( //find next vector. | 166 | + #ifdef DEBUG |
167 | + name.str(""); | ||
168 | + name << "Final_Cost_Direction_fiber_"<< iter << "_" << iter_dir << ".bmp"; | ||
169 | + test(t_dir.getTexture(), n_pixels*2.0, numSamples*n_pixels, name.str()); | ||
170 | + iter_dir++; | ||
171 | + #endif | ||
172 | + stim::vec<float> next( ///calculate the next vector. | ||
160 | dV[best][0]*S[0]*R[0], | 173 | dV[best][0]*S[0]*R[0], |
161 | dV[best][1]*S[1]*R[1], | 174 | dV[best][1]*S[1]*R[1], |
162 | dV[best][2]*S[2]*R[2], | 175 | dV[best][2]*S[2]*R[2], |
163 | 0); | 176 | 0); |
164 | - next = (cT*next).norm(); //find next vector. | ||
165 | - setPosition( p[0]+next[0]*m[0]/stepsize, | ||
166 | - p[1]+next[1]*m[0]/stepsize, | ||
167 | - p[2]+next[2]*m[0]/stepsize); | ||
168 | - setDirection(next[0], next[1], next[2]); | ||
169 | - //move forward and change direction. | 177 | + next = (cT*next).norm(); ///transform the next vector into Tissue space. |
178 | + setPosition( p[0]+next[0]*m/stepsize, | ||
179 | + p[1]+next[1]*m/stepsize, | ||
180 | + p[2]+next[2]*m/stepsize); | ||
181 | + setDirection(next[0], next[1], next[2]); //move forward and change direction. | ||
170 | } | 182 | } |
171 | 183 | ||
172 | /// Method for finding the best d (direction) for the spider. | 184 | /// Method for finding the best d (direction) for the spider. |
@@ -176,27 +188,29 @@ class gl_spider : public virtual gl_texture<T> | @@ -176,27 +188,29 @@ class gl_spider : public virtual gl_texture<T> | ||
176 | findOptimalPosition() | 188 | findOptimalPosition() |
177 | { | 189 | { |
178 | #ifdef TIMING | 190 | #ifdef TIMING |
179 | - gpuStartTimer(); | 191 | + gpuStartTimer(); //timer for profiling |
180 | #endif | 192 | #endif |
181 | setMatrix(); //create the transformation matrix. | 193 | setMatrix(); //create the transformation matrix. |
182 | glCallList(dList+1); //move the templates to p, d, m. | 194 | glCallList(dList+1); //move the templates to p, d, m. |
183 | - glFinish(); | 195 | + glFinish(); //flush the pipeline |
184 | // glFlush(); | 196 | // glFlush(); |
185 | #ifdef TIMING | 197 | #ifdef TIMING |
186 | - position_time += gpuStopTimer(); | 198 | + position_time += gpuStopTimer(); ///timer for profiling |
187 | #endif | 199 | #endif |
188 | 200 | ||
189 | - #ifdef TESTING | ||
190 | -// test(ptexbufferID, GL_TEXTURE_2D,2*t_length, numSamplesPos*t_length, "Final_Cost_Position.bmp"); | ||
191 | - #endif | ||
192 | int best = getCost(t_pos.getTexture(), t_pos.getAuxArray(), numSamplesPos); //find min cost. | 201 | int best = getCost(t_pos.getTexture(), t_pos.getAuxArray(), numSamplesPos); //find min cost. |
193 | -// std::cerr << best << std::endl; | 202 | + #ifdef DEBUG |
203 | + name.str(""); | ||
204 | + name << "Final_Cost_Position_" << iter << "_" << iter_pos << ".bmp"; | ||
205 | + test(t_pos.getTexture(), n_pixels*2.0, numSamplesPos*n_pixels, name.str()); | ||
206 | + iter_pos++; | ||
207 | + #endif | ||
194 | stim::vec<float> next( //find next position. | 208 | stim::vec<float> next( //find next position. |
195 | pV[best][0], | 209 | pV[best][0], |
196 | pV[best][1], | 210 | pV[best][1], |
197 | pV[best][2], | 211 | pV[best][2], |
198 | 1); | 212 | 1); |
199 | - next = cT*next; //find next position. | 213 | + next = cT*next; //transform the next position vector into tissue space. |
200 | setPosition( | 214 | setPosition( |
201 | next[0]*S[0]*R[0], | 215 | next[0]*S[0]*R[0], |
202 | next[1]*S[1]*R[1], | 216 | next[1]*S[1]*R[1], |
@@ -206,7 +220,7 @@ class gl_spider : public virtual gl_texture<T> | @@ -206,7 +220,7 @@ class gl_spider : public virtual gl_texture<T> | ||
206 | 220 | ||
207 | /// Method for finding the best scale for the spider. | 221 | /// Method for finding the best scale for the spider. |
208 | /// changes the x, y, z size of the spider to minimize the cost | 222 | /// changes the x, y, z size of the spider to minimize the cost |
209 | - /// function. */ | 223 | + /// function. |
210 | void | 224 | void |
211 | findOptimalScale() | 225 | findOptimalScale() |
212 | { | 226 | { |
@@ -215,64 +229,21 @@ class gl_spider : public virtual gl_texture<T> | @@ -215,64 +229,21 @@ class gl_spider : public virtual gl_texture<T> | ||
215 | #endif | 229 | #endif |
216 | setMatrix(); //create the transformation. | 230 | setMatrix(); //create the transformation. |
217 | glCallList(dList+2); //move the templates to p, d, m. | 231 | glCallList(dList+2); //move the templates to p, d, m. |
218 | - glFinish(); | ||
219 | -// glFlush(); | 232 | + glFinish(); //flush the drawing pipeline. |
220 | #ifdef TIMING | 233 | #ifdef TIMING |
221 | size_time += gpuStopTimer(); | 234 | size_time += gpuStopTimer(); |
222 | #endif | 235 | #endif |
223 | - #ifdef TESTING | ||
224 | -// test(mtexbufferID, GL_TEXTURE_2D, 2*t_length, numSamplesMag*t_length, "Final_Cost_Position.bmp"); | ||
225 | - #endif | ||
226 | int best = getCost(t_mag.getTexture(), t_mag.getAuxArray(), numSamplesMag); //get best cost. | 236 | int best = getCost(t_mag.getTexture(), t_mag.getAuxArray(), numSamplesMag); //get best cost. |
227 | - setMagnitude(m[0]*mV[best][0]); //adjust the magnitude. | 237 | + #ifdef DEBUG |
238 | + name.str(""); | ||
239 | + name << "Final_Cost_Size_" << iter << "_" << iter_siz << ".bmp"; | ||
240 | + test(t_mag.getTexture(), n_pixels*2.0, numSamplesMag*n_pixels, name.str()); | ||
241 | + iter_siz++; | ||
242 | + #endif | ||
243 | + setMagnitude(m*mV[best]); //adjust the magnitude. | ||
228 | } | 244 | } |
229 | 245 | ||
230 | 246 | ||
231 | - ///subject to change. | ||
232 | - ///finds branches. | ||
233 | - ///depreciated | ||
234 | - void | ||
235 | - branchDetection() | ||
236 | - { | ||
237 | - setMatrix(); | ||
238 | - glCallList(dList+3); | ||
239 | - std::vector< stim::vec<float> > result = find_branch( | ||
240 | - btexbufferID, GL_TEXTURE_2D, 16, 216); | ||
241 | - stim::vec3<float> size(S[0]*R[0], S[1]*R[1], S[2]*R[2]); | ||
242 | - if(!result.empty()) | ||
243 | - { | ||
244 | - for(int i = 1; i < result.size(); i++) | ||
245 | - { | ||
246 | - stim::vec<float> cylp( | ||
247 | - 0.5 * cos(2*M_PI*(result[i][1])), | ||
248 | - 0.5 * sin(2*M_PI*(result[i][1])), | ||
249 | - result[i][0]-0.5, | ||
250 | - 1.0); | ||
251 | - cylp = cT*cylp; | ||
252 | - | ||
253 | - stim::vec3<float> vec( | ||
254 | - cylp[0]*S[0]*R[0], | ||
255 | - cylp[1]*S[1]*R[1], | ||
256 | - cylp[2]*S[2]*R[2]); | ||
257 | - stim::vec3<float> seeddir(-p[0] + cylp[0]*S[0]*R[0], | ||
258 | - -p[1] + cylp[1]*S[1]*R[1], | ||
259 | - -p[2] + cylp[2]*S[2]*R[2]); | ||
260 | - seeddir = seeddir.norm(); | ||
261 | - float seedm = m[0]; | ||
262 | -// Uncomment for global run | ||
263 | - if( | ||
264 | - !(vec[0] > size[0] || vec[1] > size[1] | ||
265 | - || vec[2] > size[2] || vec[0] < 0 | ||
266 | - || vec[1] < 0 || vec[2] < 0)) | ||
267 | - { | ||
268 | - setSeed(vec); | ||
269 | - setSeedVec(seeddir); | ||
270 | - setSeedMag(seedm); | ||
271 | - } | ||
272 | - } | ||
273 | - } | ||
274 | - | ||
275 | - } | ||
276 | 247 | ||
277 | 248 | ||
278 | ///finds all the branches in the a given fiber. | 249 | ///finds all the branches in the a given fiber. |
@@ -281,78 +252,78 @@ class gl_spider : public virtual gl_texture<T> | @@ -281,78 +252,78 @@ class gl_spider : public virtual gl_texture<T> | ||
281 | branchDetection2(int n = 8, int l_template = 8, int l_square = 8) | 252 | branchDetection2(int n = 8, int l_template = 8, int l_square = 8) |
282 | { | 253 | { |
283 | #ifdef TIMING | 254 | #ifdef TIMING |
284 | - gpuStartTimer(); | 255 | + gpuStartTimer(); ///timer for performance analysis |
285 | #endif | 256 | #endif |
286 | 257 | ||
287 | - if(cL.size() < 4){} | 258 | + if(cL.size() < 4){} ///if the size of the fiber is less then 4 we do nothing. |
288 | else{ | 259 | else{ |
289 | - setMatrix(1); | ||
290 | - DrawLongCylinder(n, l_template, l_square); | 260 | + setMatrix(1); ///finds the current transformation matrix |
261 | + DrawLongCylinder(n, l_template, l_square); ///Draw the cylinder. | ||
291 | stim::cylinder<float> cyl(cL, cM); | 262 | stim::cylinder<float> cyl(cL, cM); |
292 | - std::vector< stim::vec<float> > result = find_branch(btexbufferID, GL_TEXTURE_2D, n*l_square, (cL.size()-1)*l_template); | ||
293 | - stim::vec3<float> size(S[0]*R[0], S[1]*R[1], S[2]*R[2]); | ||
294 | - float pval; | ||
295 | - if(!result.empty()) | 263 | + std::vector< stim::vec<float> > result = find_branch(cylinder_texID, GL_TEXTURE_2D, n*l_square, (cL.size()-1)*l_template); ///find all the centers in cuda |
264 | + stim::vec3<float> size(S[0]*R[0], S[1]*R[1], S[2]*R[2]); ///the borders of the texture. | ||
265 | + float pval; //pvalue associated with the points on the cylinder. | ||
266 | + if(!result.empty()) ///if we have any points | ||
296 | { | 267 | { |
297 | - for(int i = 0; i < result.size(); i++) | 268 | + for(int i = 0; i < result.size(); i++) ///for each point |
298 | { | 269 | { |
299 | int id = result[i][2]; | 270 | int id = result[i][2]; |
300 | - if(fmod(result[i][2], id) != 0 && id != 0) | 271 | + if(fmod(result[i][2], id) != 0 && id != 0) ///if the remainer is odd |
301 | { | 272 | { |
302 | 273 | ||
303 | pval = ((cyl.getl(id+1)-cyl.getl(id))* | 274 | pval = ((cyl.getl(id+1)-cyl.getl(id))* |
304 | - (fmod(result[i][2], id))+cyl.getl(id))/cyl.getl(cL.size()-1); | 275 | + (fmod(result[i][2], id))+cyl.getl(id))/cyl.getl(cL.size()-1); ///calculate pvalue |
305 | } | 276 | } |
306 | - else if(id == 0) | 277 | + else if(id == 0) ///if the point is on the edge |
307 | { | 278 | { |
308 | - pval = (cyl.getl(id+1)*result[i][2])/cyl.getl(cL.size()-1); | 279 | + pval = (cyl.getl(id+1)*result[i][2])/cyl.getl(cL.size()-1); |
309 | } | 280 | } |
310 | else | 281 | else |
311 | { | 282 | { |
312 | - pval = (cyl.getl(id)/cyl.getl(cL.size()-1)); | 283 | + pval = (cyl.getl(id)/cyl.getl(cL.size()-1)); ///if the point is somewhere on the surface of the cylinder other than the edge |
313 | } | 284 | } |
314 | - stim::vec3<float> v = cyl.surf(pval, result[i][0]); | ||
315 | - stim::vec3<float> di = cyl.p(pval); | ||
316 | - float rad = cyl.r(pval); | 285 | + stim::vec3<float> v = cyl.surf(pval, result[i][0]); ///find the coordinates of the point at pval on the surface in tissue space. |
286 | + stim::vec3<float> di = cyl.p(pval); ///find the coord of v in tissue space projected on the centerline. | ||
287 | + float rad = cyl.r(pval)/2; ///find the radius at the pvalue's location | ||
317 | if( | 288 | if( |
318 | !(v[0] > size[0] || v[1] > size[1] | 289 | !(v[0] > size[0] || v[1] > size[1] |
319 | || v[2] > size[2] || v[0] < 0 | 290 | || v[2] > size[2] || v[0] < 0 |
320 | - || v[1] < 0 || v[2] < 0)) | 291 | + || v[1] < 0 || v[2] < 0)) ///if the v point is INSIDE the volume |
321 | { | 292 | { |
322 | - setSeed(v); | ||
323 | - setSeedVec((v-di).norm()); | ||
324 | - setSeedMag(rad); | 293 | + setSeed(v); ///add a seedpoint's position. |
294 | + setSeedVec((v-di).norm()); ///add a seedpoints direction | ||
295 | + setSeedMag(rad); ///add the starting radius. | ||
325 | } | 296 | } |
326 | } | 297 | } |
327 | } | 298 | } |
328 | } | 299 | } |
329 | #ifdef TIMING | 300 | #ifdef TIMING |
330 | - branch_time += gpuStopTimer(); | 301 | + branch_time += gpuStopTimer(); ///timer for performance. |
331 | #endif | 302 | #endif |
332 | } | 303 | } |
333 | 304 | ||
334 | 305 | ||
335 | float uniformRandom() | 306 | float uniformRandom() |
336 | { | 307 | { |
337 | - return ( (float)(rand()))/( (float)(RAND_MAX)); | 308 | + return ( (float)(rand()))/( (float)(RAND_MAX)); ///generates a random number between 0 and 1 using the uniform distribution. |
338 | } | 309 | } |
339 | 310 | ||
340 | float normalRandom() | 311 | float normalRandom() |
341 | { | 312 | { |
342 | float u1 = uniformRandom(); | 313 | float u1 = uniformRandom(); |
343 | float u2 = uniformRandom(); | 314 | float u2 = uniformRandom(); |
344 | - return cos(2.0*atan(1.0)*u2)*sqrt(-1.0*log(u1)); | 315 | + return cos(2.0*atan(1.0)*u2)*sqrt(-1.0*log(u1)); ///generate a random number using the normal distribution between 0 and 1. |
345 | } | 316 | } |
346 | 317 | ||
347 | stim::vec3<float> uniformRandVector() | 318 | stim::vec3<float> uniformRandVector() |
348 | { | 319 | { |
349 | - stim::vec3<float> r(uniformRandom(), uniformRandom(), 1.0); | 320 | + stim::vec3<float> r(uniformRandom(), uniformRandom(), 1.0); ///generate a random vector using the uniform distribution between 0 and 1. |
350 | return r; | 321 | return r; |
351 | } | 322 | } |
352 | 323 | ||
353 | stim::vec3<float> normalRandVector() | 324 | stim::vec3<float> normalRandVector() |
354 | { | 325 | { |
355 | - stim::vec3<float> r(normalRandom(), normalRandom(), 1.0); | 326 | + stim::vec3<float> r(normalRandom(), normalRandom(), 1.0); ///generate a random vector using the normal distribution between 0 and 1. |
356 | return r; | 327 | return r; |
357 | } | 328 | } |
358 | 329 | ||
@@ -370,49 +341,57 @@ class gl_spider : public virtual gl_texture<T> | @@ -370,49 +341,57 @@ class gl_spider : public virtual gl_texture<T> | ||
370 | ///Stored in a display list. | 341 | ///Stored in a display list. |
371 | ///uses the default d vector <0,0,1> | 342 | ///uses the default d vector <0,0,1> |
372 | void | 343 | void |
373 | - genDirectionVectors(float solidAngle = M_PI/2) | 344 | + genDirectionVectors(float solidAngle = stim::PI/2) |
374 | { | 345 | { |
375 | 346 | ||
376 | //Set up the vectors necessary for Rectangle creation. | 347 | //Set up the vectors necessary for Rectangle creation. |
377 | stim::vec3<float> Y(1.0,0.0,0.0); //orthogonal vec. | 348 | stim::vec3<float> Y(1.0,0.0,0.0); //orthogonal vec. |
378 | - stim::vec3<float> pos(0.0,0.0,0.0); | ||
379 | - stim::vec3<float> mag(1.0, 1.0, 1.0); | ||
380 | - stim::vec3<float> dir(0.0, 0.0, 1.0); | 349 | + stim::vec3<float> pos(0.0,0.0,0.0); //center point of a rectangle |
350 | + float mag = 1.0; //size of the generated rectangle. | ||
351 | + stim::vec3<float> dir(0.0, 0.0, 1.0); //normal of the rectangle | ||
381 | 352 | ||
382 | - float PHI[2], Z[2], range; | ||
383 | - PHI[0] = solidAngle/2; | 353 | + float PHI[2], Z[2], range; |
354 | + PHI[0] = solidAngle/2; ///Project the solid angle into spherical coordinates | ||
384 | PHI[1] = asin(0); | 355 | PHI[1] = asin(0); |
385 | 356 | ||
386 | - Z[0] = cos(PHI[0]); | 357 | + Z[0] = cos(PHI[0]); ///Project the z into spherical coordinates |
387 | Z[1] = cos(PHI[1]); | 358 | Z[1] = cos(PHI[1]); |
388 | 359 | ||
389 | - range = Z[0] - Z[1]; | 360 | + range = Z[0] - Z[1]; ///The range the possible values can be. |
390 | 361 | ||
391 | float z, theta, phi; | 362 | float z, theta, phi; |
392 | - glNewList(dList, GL_COMPILE); | ||
393 | - for(int i = 0; i < numSamples; i++) | 363 | + glNewList(dList, GL_COMPILE); ///create a display list of all the direction templates. |
364 | + for(int i = 0; i < numSamples; i++) ///for each sample | ||
394 | { | 365 | { |
395 | - z = uniformRandom()*range + Z[1]; | ||
396 | - theta = uniformRandom()*2*M_PI; | ||
397 | - phi = acos(z); | ||
398 | - stim::vec3<float> sph(1, theta, phi); | ||
399 | - stim::vec3<float> cart = sph.sph2cart(); | ||
400 | - dV.push_back(cart); | ||
401 | - if(cos(Y.dot(cart)) < 0.087) | 366 | + z = uniformRandom()*range + Z[1]; ///generate a z coordinate |
367 | + theta = uniformRandom()*stim::TAU; ///generate a theta coordinate | ||
368 | + phi = acos(z); ///generate a phi from the z. | ||
369 | + stim::vec3<float> sph(1, theta, phi); ///combine into a vector in spherical coordinates. | ||
370 | + stim::vec3<float> cart = sph.sph2cart();///convert to cartesian. | ||
371 | + dV.push_back(cart); ///save the generated vector for further use. | ||
372 | + #ifdef DEBUG | ||
373 | +// std::cout << cart << std::endl; | ||
374 | + #endif | ||
375 | + if(cos(Y.dot(cart)) < 0.087) ///make sure that the Y is not parallel to the new vector. | ||
402 | { | 376 | { |
403 | Y[0] = 0.0; Y[1] = 1.0; | 377 | Y[0] = 0.0; Y[1] = 1.0; |
404 | }else{ | 378 | }else{ |
405 | Y[0] = 1.0; Y[1] = 0.0; | 379 | Y[0] = 1.0; Y[1] = 0.0; |
406 | } | 380 | } |
407 | - hor = stim::rect<float>(mag, | 381 | + |
382 | + hor = stim::rect<float>(mag, ///generate a rectangle with the new vectro as a normal. | ||
408 | pos, cart, | 383 | pos, cart, |
409 | ((Y.cross(cart)).cross(cart)).norm()); | 384 | ((Y.cross(cart)).cross(cart)).norm()); |
410 | - ver = stim::rect<float>(mag, | 385 | + |
386 | + #ifdef DEBUG | ||
387 | + // std::cout << hor.n() << std::endl; | ||
388 | + #endif | ||
389 | + ver = stim::rect<float>(mag, ///generate another rectangle that's perpendicular the first but parallel to the cart vector. | ||
411 | pos, cart, | 390 | pos, cart, |
412 | hor.n()); | 391 | hor.n()); |
413 | - UpdateBuffer(0.0, 0.0+i*t_length); | 392 | + UpdateBuffer(0.0, 0.0+i*n_pixels); ///Put the necessary points into the diplaylist. |
414 | } | 393 | } |
415 | - glEndList(); | 394 | + glEndList(); ///finilize the display list. |
416 | } | 395 | } |
417 | 396 | ||
418 | ///@param float delta, How much the rectangles vary in position. | 397 | ///@param float delta, How much the rectangles vary in position. |
@@ -426,28 +405,45 @@ class gl_spider : public virtual gl_texture<T> | @@ -426,28 +405,45 @@ class gl_spider : public virtual gl_texture<T> | ||
426 | { | 405 | { |
427 | //Set up the vectors necessary for Rectangle creation. | 406 | //Set up the vectors necessary for Rectangle creation. |
428 | stim::vec3<float> Y(1.0,0.0,0.0); //orthogonal vec. | 407 | stim::vec3<float> Y(1.0,0.0,0.0); //orthogonal vec. |
429 | - stim::vec3<float> pos(0.0,0.0,0.0); | ||
430 | - stim::vec3<float> mag(1.0, 1.0, 1.0); | ||
431 | - stim::vec3<float> dir(0.0, 0.0, 1.0); | 408 | + stim::vec3<float> pos(0.0,0.0,0.0); //center point of a rectangle |
409 | + float mag = 1.0; ///size of each rectangle | ||
410 | + stim::vec3<float> dir(0.0, 0.0, 1.0); ///normal of the rectangle plane. | ||
432 | 411 | ||
433 | //Set up the variable necessary for vector creation. | 412 | //Set up the variable necessary for vector creation. |
434 | - glNewList(dList+1, GL_COMPILE); | ||
435 | - for(int i = 0; i < numSamplesPos; i++) | 413 | + glNewList(dList+1, GL_COMPILE); ///generate a new display list. |
414 | + pV.push_back(pos); | ||
415 | + hor = stim::rect<float>(mag, ///generate a rec tangle with the new vector as a normal. | ||
416 | + pos, dir, | ||
417 | + ((Y.cross(d)).cross(d)) | ||
418 | + .norm()); | ||
419 | + ver = stim::rect<float>(mag, ///generate anoth er rectangle that's perpendicular the first but parallel to the cart vector. | ||
420 | + pos, dir, | ||
421 | + hor.n()); | ||
422 | + ///The first vector is always in the center. | ||
423 | + UpdateBuffer(0.0, 0.0+0*n_pixels); | ||
424 | + for(int i = 1; i < numSamplesPos; i++) ///for the number of position samples | ||
436 | { | 425 | { |
437 | - stim::vec3<float> temp = uniformRandVector(); | ||
438 | - temp = temp*delta*2.0 - delta/2.0; | 426 | + stim::vec3<float> temp = uniformRandVector(); ///generate a random point on a plane. |
427 | + temp[0] = temp[0]*delta; | ||
428 | + temp[1] = temp[1]*2*stim::PI; | ||
429 | + | ||
439 | temp[2] = 0.0; | 430 | temp[2] = 0.0; |
440 | - pV.push_back(temp); | ||
441 | - hor = stim::rect<float>(mag, | 431 | + temp = temp.cyl2cart(); |
432 | + pV.push_back(temp); ///save the point for further use. | ||
433 | + hor = stim::rect<float>(mag, ///generate a rectangle with the new vector as a normal. | ||
442 | temp, dir, | 434 | temp, dir, |
443 | ((Y.cross(d)).cross(d)) | 435 | ((Y.cross(d)).cross(d)) |
444 | .norm()); | 436 | .norm()); |
445 | - ver = stim::rect<float>(mag, | 437 | + ver = stim::rect<float>(mag, ///generate another rectangle that's perpendicular the first but parallel to the cart vector. |
446 | temp, dir, | 438 | temp, dir, |
447 | hor.n()); | 439 | hor.n()); |
448 | - UpdateBuffer(0.0, 0.0+i*t_length); | 440 | + UpdateBuffer(0.0, 0.0+i*n_pixels); ///sample the necessary points and put them into a display list. |
449 | } | 441 | } |
450 | - glEndList(); | 442 | + glEndList(); ///finilize the display list. |
443 | + #ifdef DEBUG | ||
444 | + for(int i = 0; i < numSamplesPos; i++) | ||
445 | + std::cout << pV[i] << std::endl; | ||
446 | + #endif | ||
451 | } | 447 | } |
452 | 448 | ||
453 | ///@param float delta, How much the rectangles are allowed to expand. | 449 | ///@param float delta, How much the rectangles are allowed to expand. |
@@ -462,35 +458,31 @@ class gl_spider : public virtual gl_texture<T> | @@ -462,35 +458,31 @@ class gl_spider : public virtual gl_texture<T> | ||
462 | 458 | ||
463 | //Set up the vectors necessary for Rectangle creation. | 459 | //Set up the vectors necessary for Rectangle creation. |
464 | stim::vec3<float> Y(1.0, 0.0, 0.0); //orthogonal vec. | 460 | stim::vec3<float> Y(1.0, 0.0, 0.0); //orthogonal vec. |
465 | - stim::vec3<float> pos(0.0, 0.0, 0.0); | ||
466 | - stim::vec3<float> mag(1.0, 1.0, 1.0); | ||
467 | - stim::vec3<float> dir(0.0, 0.0, 1.0); | 461 | + stim::vec3<float> pos(0.0, 0.0, 0.0); //center of the future rect. |
462 | + float mag = 1.0; ///size of the rectangle | ||
463 | + stim::vec3<float> dir(0.0, 0.0, 1.0); ///normal of the rectangle plane. | ||
468 | 464 | ||
469 | //Set up the variable necessary for vector creation. | 465 | //Set up the variable necessary for vector creation. |
470 | - int dim = (sqrt(numSamplesMag)-1)/2; | ||
471 | - float min = 1.0-delta; | ||
472 | - float max = 1.0+delta; | ||
473 | - float step = (max-min)/(numSamplesMag-1); | 466 | + float min = 1.0-delta; ///smallest size |
467 | + float max = 1.0+delta; ///largers size. | ||
468 | + float step = (max-min)/(numSamplesMag-1); ///the size variation from one rect to the next. | ||
474 | float factor; | 469 | float factor; |
475 | - stim::vec3<float> temp(0.0,0.0,0.0); | ||
476 | - | ||
477 | glNewList(dList+2, GL_COMPILE); | 470 | glNewList(dList+2, GL_COMPILE); |
478 | - for(int i = 0; i < numSamplesMag; i++){ | 471 | + for(int i = 0; i < numSamplesMag; i++){ ///for the number of position samples |
479 | //Create linear index | 472 | //Create linear index |
480 | - factor = (min+step*i)*mag[0]; | ||
481 | - temp = factor; | ||
482 | - mV.push_back(temp); | ||
483 | - hor = stim::rect<float>(temp, | 473 | + factor = (min+step*i)*mag; ///scaling factor |
474 | + mV.push_back(factor); ///save the size factor for further use. | ||
475 | + hor = stim::rect<float>(factor, ///generate a rectangle with the new vector as a normal. | ||
484 | pos, dir, | 476 | pos, dir, |
485 | ((Y.cross(d)).cross(d)) | 477 | ((Y.cross(d)).cross(d)) |
486 | .norm()); | 478 | .norm()); |
487 | - ver = stim::rect<float>(temp, | 479 | + ver = stim::rect<float>(factor, ///generate another rectangle that's perpendicular the first but parallel to the cart vector. |
488 | pos, dir, | 480 | pos, dir, |
489 | hor.n()); | 481 | hor.n()); |
490 | - UpdateBuffer(0.0, 0.0+i*t_length); | 482 | + UpdateBuffer(0.0, 0.0+i*n_pixels); ///sample the necessary points and put them into a display list. |
491 | CHECK_OPENGL_ERROR | 483 | CHECK_OPENGL_ERROR |
492 | } | 484 | } |
493 | - glEndList(); | 485 | + glEndList(); ///finilize the displaylist. |
494 | } | 486 | } |
495 | 487 | ||
496 | ///@param float v_x x-coordinate in buffer-space, | 488 | ///@param float v_x x-coordinate in buffer-space, |
@@ -500,15 +492,15 @@ class gl_spider : public virtual gl_texture<T> | @@ -500,15 +492,15 @@ class gl_spider : public virtual gl_texture<T> | ||
500 | void | 492 | void |
501 | UpdateBuffer(float v_x, float v_y) | 493 | UpdateBuffer(float v_x, float v_y) |
502 | { | 494 | { |
503 | - stim::vec3<float>p1; | ||
504 | - stim::vec3<float>p2; | ||
505 | - stim::vec3<float>p3; | ||
506 | - stim::vec3<float>p4; | ||
507 | - p1 = hor.p(1,1); | ||
508 | - p2 = hor.p(1,0); | ||
509 | - p3 = hor.p(0,0); | ||
510 | - p4 = hor.p(0,1); | ||
511 | - glBegin(GL_QUADS); | 495 | + stim::vec3<float>p1; ///first point. |
496 | + stim::vec3<float>p2; ///second point. | ||
497 | + stim::vec3<float>p3; ///third point. | ||
498 | + stim::vec3<float>p4; ///fourth point. | ||
499 | + p1 = hor.p(1,1); ///generate the top right point from the horizontal template. | ||
500 | + p2 = hor.p(1,0); ///generate the bottom right point from the horizonatal template. | ||
501 | + p3 = hor.p(0,0); ///generate the bottom left point from the horizontal template. | ||
502 | + p4 = hor.p(0,1); ///generate the top left point from the horizonatal template. | ||
503 | + glBegin(GL_QUADS); ///generate the Quad from the 4 points. | ||
512 | glTexCoord3f( | 504 | glTexCoord3f( |
513 | p1[0], | 505 | p1[0], |
514 | p1[1], | 506 | p1[1], |
@@ -520,51 +512,51 @@ class gl_spider : public virtual gl_texture<T> | @@ -520,51 +512,51 @@ class gl_spider : public virtual gl_texture<T> | ||
520 | p2[1], | 512 | p2[1], |
521 | p2[2] | 513 | p2[2] |
522 | ); | 514 | ); |
523 | - glVertex2f(v_x+t_length, v_y); | 515 | + glVertex2f(v_x+n_pixels, v_y); |
524 | glTexCoord3f( | 516 | glTexCoord3f( |
525 | p3[0], | 517 | p3[0], |
526 | p3[1], | 518 | p3[1], |
527 | p3[2] | 519 | p3[2] |
528 | ); | 520 | ); |
529 | - glVertex2f(v_x+t_length, v_y+t_length); | 521 | + glVertex2f(v_x+n_pixels, v_y+n_pixels); |
530 | glTexCoord3f( | 522 | glTexCoord3f( |
531 | p4[0], | 523 | p4[0], |
532 | p4[1], | 524 | p4[1], |
533 | p4[2] | 525 | p4[2] |
534 | ); | 526 | ); |
535 | - glVertex2f(v_x, v_y+t_length); | ||
536 | - glEnd(); | ||
537 | - | ||
538 | - p1 = ver.p(1,1); | ||
539 | - p2 = ver.p(1,0); | ||
540 | - p3 = ver.p(0,0); | ||
541 | - p4 = ver.p(0,1); | ||
542 | - glBegin(GL_QUADS); | 527 | + glVertex2f(v_x, v_y+n_pixels); |
528 | + glEnd(); ///finish the quad. | ||
529 | + | ||
530 | + p1 = ver.p(1,1); ///generate the top right point from the vertical template. | ||
531 | + p2 = ver.p(1,0); ///generate the bottom right point from the vertical template. | ||
532 | + p3 = ver.p(0,0); ///generate the bottom left point from the vertical template. | ||
533 | + p4 = ver.p(0,1); ///generate the top left point from the vertical template. | ||
534 | + glBegin(GL_QUADS); ///generate the Quad from the 4 points. | ||
543 | glTexCoord3f( | 535 | glTexCoord3f( |
544 | p1[0], | 536 | p1[0], |
545 | p1[1], | 537 | p1[1], |
546 | p1[2] | 538 | p1[2] |
547 | ); | 539 | ); |
548 | - glVertex2f(v_x+t_length, v_y); | 540 | + glVertex2f(v_x+n_pixels, v_y); |
549 | glTexCoord3f( | 541 | glTexCoord3f( |
550 | p2[0], | 542 | p2[0], |
551 | p2[1], | 543 | p2[1], |
552 | p2[2] | 544 | p2[2] |
553 | ); | 545 | ); |
554 | - glVertex2f(v_x+2.0*t_length, v_y); | 546 | + glVertex2f(v_x+2.0*n_pixels, v_y); |
555 | glTexCoord3f( | 547 | glTexCoord3f( |
556 | p3[0], | 548 | p3[0], |
557 | p3[1], | 549 | p3[1], |
558 | p3[2] | 550 | p3[2] |
559 | ); | 551 | ); |
560 | - glVertex2f(v_x+2.0*t_length, v_y+t_length); | 552 | + glVertex2f(v_x+2.0*n_pixels, v_y+n_pixels); |
561 | glTexCoord3f( | 553 | glTexCoord3f( |
562 | p4[0], | 554 | p4[0], |
563 | p4[1], | 555 | p4[1], |
564 | p4[2] | 556 | p4[2] |
565 | ); | 557 | ); |
566 | - glVertex2f(v_x+t_length, v_y+t_length); | ||
567 | - glEnd(); | 558 | + glVertex2f(v_x+n_pixels, v_y+n_pixels); |
559 | + glEnd(); ///finish the quad. | ||
568 | } | 560 | } |
569 | 561 | ||
570 | 562 | ||
@@ -582,50 +574,24 @@ class gl_spider : public virtual gl_texture<T> | @@ -582,50 +574,24 @@ class gl_spider : public virtual gl_texture<T> | ||
582 | void | 574 | void |
583 | GenerateFBO(unsigned int width, unsigned int height, GLuint &textureID, GLuint &framebufferID) | 575 | GenerateFBO(unsigned int width, unsigned int height, GLuint &textureID, GLuint &framebufferID) |
584 | { | 576 | { |
585 | - glDeleteFramebuffers(1, &framebufferID); | ||
586 | - glGenFramebuffers(1, &framebufferID); | ||
587 | - glBindFramebuffer(GL_FRAMEBUFFER, framebufferID); | 577 | + glDeleteFramebuffers(1, &framebufferID); ///clear the framebuffer. |
578 | + glGenFramebuffers(1, &framebufferID); ///generate a clean buffer. | ||
579 | + glBindFramebuffer(GL_FRAMEBUFFER, framebufferID); ///bind the new buffer. | ||
588 | // int numChannels = 1; | 580 | // int numChannels = 1; |
589 | // unsigned char* texels = new unsigned char[width * height * numChannels]; | 581 | // unsigned char* texels = new unsigned char[width * height * numChannels]; |
590 | - glGenTextures(1, &textureID); | 582 | + glGenTextures(1, &textureID); ///generate a texture that will attach to the buffer. |
591 | glBindTexture(GL_TEXTURE_2D, textureID); | 583 | glBindTexture(GL_TEXTURE_2D, textureID); |
592 | 584 | ||
593 | //Textures repeat and use linear interpolation, luminance format. | 585 | //Textures repeat and use linear interpolation, luminance format. |
594 | - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); | ||
595 | - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); | ||
596 | - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 586 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); ///Set up the texture to repeat at edges. |
587 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); | ||
588 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); ///Set up the texture to use Linear interpolation | ||
597 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 589 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
598 | - glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, | 590 | + glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, ///Create the texture with no data. |
599 | width, height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, NULL); | 591 | width, height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, NULL); |
600 | // delete[] texels; | 592 | // delete[] texels; |
601 | - glBindFramebuffer(GL_FRAMEBUFFER, 0); | ||
602 | - glBindTexture(GL_TEXTURE_2D, 0); | ||
603 | - } | ||
604 | - | ||
605 | - ///@param uint width sets the width of the buffer. | ||
606 | - ///@param uint height sets the height of the buffer. | ||
607 | - ///Function for setting up the 2D buffer that stores the samples. | ||
608 | - void | ||
609 | - GenerateFBO(unsigned int width, unsigned int height) | ||
610 | - { | ||
611 | - glGenFramebuffers(1, &fboID); | ||
612 | - glBindFramebuffer(GL_FRAMEBUFFER, fboID); | ||
613 | -// int numChannels = 1; | ||
614 | -// unsigned char* texels = new unsigned char[width * height * numChannels]; | ||
615 | - glGenTextures(1, &texbufferID); | ||
616 | - glBindTexture(GL_TEXTURE_2D, texbufferID); | ||
617 | - | ||
618 | - //Textures repeat and use linear interpolation, luminance format. | ||
619 | - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); | ||
620 | - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); | ||
621 | - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | ||
622 | - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | ||
623 | - glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, | ||
624 | - width, height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, NULL); | ||
625 | -// delete[] texels; | ||
626 | - glBindFramebuffer(GL_FRAMEBUFFER, 0); | ||
627 | - glBindTexture(GL_TEXTURE_2D, 0); | ||
628 | - CHECK_OPENGL_ERROR | 593 | + glBindFramebuffer(GL_FRAMEBUFFER, 0); ///Bind the frontbuffer |
594 | + glBindTexture(GL_TEXTURE_2D, 0); ///Unbind the texture. | ||
629 | } | 595 | } |
630 | 596 | ||
631 | 597 | ||
@@ -657,13 +623,12 @@ class gl_spider : public virtual gl_texture<T> | @@ -657,13 +623,12 @@ class gl_spider : public virtual gl_texture<T> | ||
657 | //rotate to the current direction of the spider. | 623 | //rotate to the current direction of the spider. |
658 | glRotatef(rot[0], rot[1], rot[2], rot[3]); | 624 | glRotatef(rot[0], rot[1], rot[2], rot[3]); |
659 | //scale to the magnitude of the spider. | 625 | //scale to the magnitude of the spider. |
660 | - glScalef(m[0], | ||
661 | - m[0], | ||
662 | - m[0]); | 626 | + glScalef(m, |
627 | + m, | ||
628 | + m); | ||
663 | //get and store the current transformation matrix for later use. | 629 | //get and store the current transformation matrix for later use. |
664 | glGetFloatv(GL_TEXTURE_MATRIX, curTrans); | 630 | glGetFloatv(GL_TEXTURE_MATRIX, curTrans); |
665 | cT.set(curTrans); | 631 | cT.set(curTrans); |
666 | - // printTransform(); | ||
667 | 632 | ||
668 | CHECK_OPENGL_ERROR | 633 | CHECK_OPENGL_ERROR |
669 | //revert back to default gl mode. | 634 | //revert back to default gl mode. |
@@ -683,31 +648,31 @@ class gl_spider : public virtual gl_texture<T> | @@ -683,31 +648,31 @@ class gl_spider : public virtual gl_texture<T> | ||
683 | void | 648 | void |
684 | Bind() | 649 | Bind() |
685 | { | 650 | { |
686 | - glBindFramebuffer(GL_FRAMEBUFFER, fboID);//set up GL buffer | 651 | + glBindFramebuffer(GL_FRAMEBUFFER, direction_buffID);//set up GL buffer |
687 | glFramebufferTexture2D( | 652 | glFramebufferTexture2D( |
688 | GL_FRAMEBUFFER, | 653 | GL_FRAMEBUFFER, |
689 | GL_COLOR_ATTACHMENT0, | 654 | GL_COLOR_ATTACHMENT0, |
690 | GL_TEXTURE_2D, | 655 | GL_TEXTURE_2D, |
691 | - texbufferID, | 656 | + direction_texID, |
692 | 0); | 657 | 0); |
693 | - glBindFramebuffer(GL_FRAMEBUFFER, fboID); | 658 | + glBindFramebuffer(GL_FRAMEBUFFER, direction_buffID); |
694 | GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0}; | 659 | GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0}; |
695 | glDrawBuffers(1, DrawBuffers); | 660 | glDrawBuffers(1, DrawBuffers); |
696 | - glBindTexture(GL_TEXTURE_2D, texbufferID); | 661 | + glBindTexture(GL_TEXTURE_2D, direction_texID); |
697 | glClearColor(1,1,1,1); | 662 | glClearColor(1,1,1,1); |
698 | glClear(GL_COLOR_BUFFER_BIT); | 663 | glClear(GL_COLOR_BUFFER_BIT); |
699 | glMatrixMode(GL_PROJECTION); | 664 | glMatrixMode(GL_PROJECTION); |
700 | glLoadIdentity(); | 665 | glLoadIdentity(); |
701 | glMatrixMode(GL_MODELVIEW); | 666 | glMatrixMode(GL_MODELVIEW); |
702 | glLoadIdentity(); | 667 | glLoadIdentity(); |
703 | - glViewport(0,0,2.0*t_length, numSamples*t_length); | ||
704 | - gluOrtho2D(0.0,2.0*t_length,0.0,numSamples*t_length); | 668 | + glViewport(0,0,2.0*n_pixels, numSamples*n_pixels); |
669 | + gluOrtho2D(0.0,2.0*n_pixels,0.0,numSamples*n_pixels); | ||
705 | glEnable(GL_TEXTURE_3D); | 670 | glEnable(GL_TEXTURE_3D); |
706 | glBindTexture(GL_TEXTURE_3D, texID); | 671 | glBindTexture(GL_TEXTURE_3D, texID); |
707 | 672 | ||
708 | CHECK_OPENGL_ERROR | 673 | CHECK_OPENGL_ERROR |
709 | } | 674 | } |
710 | - | 675 | + |
711 | ///Method for controling the buffer and texture binding. | 676 | ///Method for controling the buffer and texture binding. |
712 | ///Clears the buffer upon binding. | 677 | ///Clears the buffer upon binding. |
713 | ///@param GLuint &textureID, texture to be bound. | 678 | ///@param GLuint &textureID, texture to be bound. |
@@ -717,25 +682,25 @@ class gl_spider : public virtual gl_texture<T> | @@ -717,25 +682,25 @@ class gl_spider : public virtual gl_texture<T> | ||
717 | Bind(GLuint &textureID, GLuint &framebufferID, int nSamples, float len = 8.0) | 682 | Bind(GLuint &textureID, GLuint &framebufferID, int nSamples, float len = 8.0) |
718 | { | 683 | { |
719 | 684 | ||
720 | - glBindFramebuffer(GL_FRAMEBUFFER, framebufferID);//set up GL buffer | ||
721 | - glFramebufferTexture2D( | 685 | + glBindFramebuffer(GL_FRAMEBUFFER, framebufferID); ///Bind the framebuffer. |
686 | + glFramebufferTexture2D( ///associate it with the texture | ||
722 | GL_FRAMEBUFFER, | 687 | GL_FRAMEBUFFER, |
723 | GL_COLOR_ATTACHMENT0, | 688 | GL_COLOR_ATTACHMENT0, |
724 | GL_TEXTURE_2D, | 689 | GL_TEXTURE_2D, |
725 | textureID, | 690 | textureID, |
726 | 0); | 691 | 0); |
727 | - glBindFramebuffer(GL_FRAMEBUFFER, framebufferID); | ||
728 | - GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0}; | ||
729 | - glDrawBuffers(1, DrawBuffers); | ||
730 | - glBindTexture(GL_TEXTURE_2D, textureID); | ||
731 | - glMatrixMode(GL_PROJECTION); | 692 | + glBindFramebuffer(GL_FRAMEBUFFER, framebufferID); ///Bind the framebuffer. |
693 | + GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0}; ///generate the drawbuffer. | ||
694 | + glDrawBuffers(1, DrawBuffers); ///set the drawbuffer. | ||
695 | + glBindTexture(GL_TEXTURE_2D, textureID); ///Bind the texture passed. | ||
696 | + glMatrixMode(GL_PROJECTION); ///clear out the draw matrices | ||
732 | glLoadIdentity(); | 697 | glLoadIdentity(); |
733 | glMatrixMode(GL_MODELVIEW); | 698 | glMatrixMode(GL_MODELVIEW); |
734 | glLoadIdentity(); | 699 | glLoadIdentity(); |
735 | - glViewport(0,0,2.0*len, nSamples*len); | ||
736 | - gluOrtho2D(0.0,2.0*len,0.0,nSamples*len); | ||
737 | - glEnable(GL_TEXTURE_3D); | ||
738 | - glBindTexture(GL_TEXTURE_3D, texID); | 700 | + glViewport(0,0,2.0*len, nSamples*len); ///set up viewport |
701 | + gluOrtho2D(0.0,2.0*len,0.0,nSamples*len); ///Set up ortho | ||
702 | + glEnable(GL_TEXTURE_3D); | ||
703 | + glBindTexture(GL_TEXTURE_3D, texID); ///bind the main texture (return to original state). | ||
739 | 704 | ||
740 | CHECK_OPENGL_ERROR | 705 | CHECK_OPENGL_ERROR |
741 | } | 706 | } |
@@ -745,34 +710,16 @@ class gl_spider : public virtual gl_texture<T> | @@ -745,34 +710,16 @@ class gl_spider : public virtual gl_texture<T> | ||
745 | Unbind() | 710 | Unbind() |
746 | { | 711 | { |
747 | //Finalize GL_buffer | 712 | //Finalize GL_buffer |
748 | - glBindTexture(GL_TEXTURE_3D, 0); | 713 | + glBindTexture(GL_TEXTURE_3D, 0); ///Bind the front buffer. |
749 | CHECK_OPENGL_ERROR | 714 | CHECK_OPENGL_ERROR |
750 | - glBindTexture(GL_TEXTURE_2D, 0); | 715 | + glBindTexture(GL_TEXTURE_2D, 0); ///Bind the default GL texture. |
751 | CHECK_OPENGL_ERROR | 716 | CHECK_OPENGL_ERROR |
752 | - glBindFramebuffer(GL_FRAMEBUFFER, 0); | 717 | + glBindFramebuffer(GL_FRAMEBUFFER, 0); ///Bind the defautl framebuffer. |
753 | CHECK_OPENGL_ERROR | 718 | CHECK_OPENGL_ERROR |
754 | - glDisable(GL_TEXTURE_3D); | 719 | + glDisable(GL_TEXTURE_3D); ///Turn off texturing. |
755 | CHECK_OPENGL_ERROR | 720 | CHECK_OPENGL_ERROR |
756 | } | 721 | } |
757 | 722 | ||
758 | - ///Makes the spider take a step. | ||
759 | - ///starting with the current p, d, m, find the next optimal p, d, m. | ||
760 | - ///Performs the branch detection on each step. | ||
761 | - int | ||
762 | - StepP() | ||
763 | - { | ||
764 | - Bind(); | ||
765 | - CHECK_OPENGL_ERROR | ||
766 | - findOptimalDirection(); | ||
767 | - findOptimalPosition(); | ||
768 | - findOptimalScale(); | ||
769 | - Unbind(); | ||
770 | - Bind(btexbufferID, bfboID, 27); | ||
771 | - branchDetection(); | ||
772 | - Unbind(); | ||
773 | - return current_cost; | ||
774 | - } | ||
775 | - | ||
776 | 723 | ||
777 | 724 | ||
778 | 725 | ||
@@ -785,42 +732,17 @@ class gl_spider : public virtual gl_texture<T> | @@ -785,42 +732,17 @@ class gl_spider : public virtual gl_texture<T> | ||
785 | ///finds the minimum cost and sets the current_cost to that value. | 732 | ///finds the minimum cost and sets the current_cost to that value. |
786 | /// and returns the index of the template with the minimal cost. | 733 | /// and returns the index of the template with the minimal cost. |
787 | int | 734 | int |
788 | - getCost() | ||
789 | - { | ||
790 | - stim::vec<int> cost = | ||
791 | -// stim::cuda::get_cost(texbufferID, GL_TEXTURE_2D, numSamples); | ||
792 | - cudaDeviceSynchronize(); | ||
793 | - current_cost = cost[1]; | ||
794 | - return cost[0]; | ||
795 | - } | ||
796 | - | ||
797 | -// int | ||
798 | -// getCost(GLuint tID, int n) | ||
799 | -// { | ||
800 | -// #ifdef TIMING | ||
801 | -// gpuStartTimer(); | ||
802 | -// #endif | ||
803 | -// stim::vec<int> cost = | ||
804 | -// stim::cuda::get_cost(tID, GL_TEXTURE_2D, n, 2*t_length, t_length); | ||
805 | -// #ifdef TIMING | ||
806 | -// cost_time += gpuStopTimer(); | ||
807 | -// #endif | ||
808 | -// current_cost = cost[1]; | ||
809 | -// return cost[0]; | ||
810 | -// } | ||
811 | - | ||
812 | - int | ||
813 | getCost(cudaTextureObject_t tObj, float* result, int n) | 735 | getCost(cudaTextureObject_t tObj, float* result, int n) |
814 | { | 736 | { |
815 | #ifdef TIMING | 737 | #ifdef TIMING |
816 | gpuStartTimer(); | 738 | gpuStartTimer(); |
817 | #endif | 739 | #endif |
818 | stim::vec<int> cost = | 740 | stim::vec<int> cost = |
819 | - stim::cuda::get_cost(tObj, result, n, 2*t_length, t_length); | 741 | + stim::cuda::get_cost(tObj, result, n, 2*n_pixels, n_pixels); ///call the cuda function with the appropriate texture buffer. |
820 | #ifdef TIMING | 742 | #ifdef TIMING |
821 | cost_time += gpuStopTimer(); | 743 | cost_time += gpuStopTimer(); |
822 | #endif | 744 | #endif |
823 | - current_cost = cost[1]; | 745 | + current_cost = cost[1]; ///current cost. |
824 | return cost[0]; | 746 | return cost[0]; |
825 | } | 747 | } |
826 | 748 | ||
@@ -854,17 +776,20 @@ class gl_spider : public virtual gl_texture<T> | @@ -854,17 +776,20 @@ class gl_spider : public virtual gl_texture<T> | ||
854 | gl_spider | 776 | gl_spider |
855 | (int samples = 1089, int samplespos = 441,int samplesmag = 144) | 777 | (int samples = 1089, int samplespos = 441,int samplesmag = 144) |
856 | { | 778 | { |
857 | -// std::cout << "I ran this constructor" << std::endl; | ||
858 | p = stim::vec3<float>(0.0, 0.0, 0.0); | 779 | p = stim::vec3<float>(0.0, 0.0, 0.0); |
859 | d = stim::vec3<float>(0.0, 0.0, 1.0); | 780 | d = stim::vec3<float>(0.0, 0.0, 1.0); |
860 | - m = stim::vec<float>(1.0, 1.0); | 781 | + m = 1.0; |
861 | S = stim::vec3<float>(1.0, 1.0, 1.0); | 782 | S = stim::vec3<float>(1.0, 1.0, 1.0); |
862 | R = stim::vec3<float>(1.0, 1.0, 1.0); | 783 | R = stim::vec3<float>(1.0, 1.0, 1.0); |
863 | -// std::cout << samples << std::endl; | ||
864 | numSamples = samples; | 784 | numSamples = samples; |
865 | -// std::cout << numSamples << std::endl; | ||
866 | numSamplesPos = samplespos; | 785 | numSamplesPos = samplespos; |
867 | numSamplesMag = samplesmag; | 786 | numSamplesMag = samplesmag; |
787 | + #ifdef DEBUG | ||
788 | + iter = 0; | ||
789 | + iter_pos = 0; | ||
790 | + iter_dir = 0; | ||
791 | + iter_siz = 0; | ||
792 | + #endif | ||
868 | } | 793 | } |
869 | 794 | ||
870 | ///Position constructor: floats. | 795 | ///Position constructor: floats. |
@@ -882,12 +807,18 @@ class gl_spider : public virtual gl_texture<T> | @@ -882,12 +807,18 @@ class gl_spider : public virtual gl_texture<T> | ||
882 | { | 807 | { |
883 | p = stim::vec3<float>(pos_x, pos_y, pos_z); | 808 | p = stim::vec3<float>(pos_x, pos_y, pos_z); |
884 | d = stim::vec3<float>(dir_x, dir_y, dir_z); | 809 | d = stim::vec3<float>(dir_x, dir_y, dir_z); |
885 | - m = stim::vec<float>(mag_x, mag_x, mag_x); | 810 | + m = mag_x; |
886 | S = stim::vec3<float>(1.0,1.0,1.0); | 811 | S = stim::vec3<float>(1.0,1.0,1.0); |
887 | R = stim::vec3<float>(1.0,1.0,1.0); | 812 | R = stim::vec3<float>(1.0,1.0,1.0); |
888 | numSamples = numsamples; | 813 | numSamples = numsamples; |
889 | numSamplesPos = numsamplespos; | 814 | numSamplesPos = numsamplespos; |
890 | numSamplesMag = numsamplesmag; | 815 | numSamplesMag = numsamplesmag; |
816 | + #ifdef DEBUG | ||
817 | + iter = 0; | ||
818 | + iter_pos = 0; | ||
819 | + iter_dir = 0; | ||
820 | + iter_siz = 0; | ||
821 | + #endif | ||
891 | } | 822 | } |
892 | 823 | ||
893 | ///Position constructor: vecs of floats. | 824 | ///Position constructor: vecs of floats. |
@@ -900,12 +831,18 @@ class gl_spider : public virtual gl_texture<T> | @@ -900,12 +831,18 @@ class gl_spider : public virtual gl_texture<T> | ||
900 | { | 831 | { |
901 | p = pos; | 832 | p = pos; |
902 | d = dir; | 833 | d = dir; |
903 | - m = vec<float>(mag, mag, mag); | 834 | + m = mag; |
904 | S = vec3<float>(1.0,1.0,1.0); | 835 | S = vec3<float>(1.0,1.0,1.0); |
905 | R = vec3<float>(1.0,1.0,1.0); | 836 | R = vec3<float>(1.0,1.0,1.0); |
906 | numSamples = samples; | 837 | numSamples = samples; |
907 | numSamplesPos = samplesPos; | 838 | numSamplesPos = samplesPos; |
908 | numSamplesMag = samplesMag; | 839 | numSamplesMag = samplesMag; |
840 | + #ifdef DEBUG | ||
841 | + iter = 0; | ||
842 | + iter_pos = 0; | ||
843 | + iter_dir = 0; | ||
844 | + iter_siz = 0; | ||
845 | + #endif | ||
909 | } | 846 | } |
910 | 847 | ||
911 | ///destructor | 848 | ///destructor |
@@ -913,14 +850,14 @@ class gl_spider : public virtual gl_texture<T> | @@ -913,14 +850,14 @@ class gl_spider : public virtual gl_texture<T> | ||
913 | (void) | 850 | (void) |
914 | { | 851 | { |
915 | Unbind(); | 852 | Unbind(); |
916 | - glDeleteTextures(1, &texbufferID); | ||
917 | - glDeleteBuffers(1, &fboID); | ||
918 | - glDeleteTextures(1, &ptexbufferID); | ||
919 | - glDeleteBuffers(1, &pfboID); | ||
920 | - glDeleteTextures(1, &mtexbufferID); | ||
921 | - glDeleteBuffers(1, &mfboID); | ||
922 | - glDeleteTextures(1, &btexbufferID); | ||
923 | - glDeleteBuffers(1, &bfboID); | 853 | + glDeleteTextures(1, &direction_texID); |
854 | + glDeleteBuffers(1, &direction_buffID); | ||
855 | + glDeleteTextures(1, &position_texID); | ||
856 | + glDeleteBuffers(1, &position_buffID); | ||
857 | + glDeleteTextures(1, &radius_texID); | ||
858 | + glDeleteBuffers(1, &radius_buffID); | ||
859 | + glDeleteTextures(1, &cylinder_texID); | ||
860 | + glDeleteBuffers(1, &cylinder_buffID); | ||
924 | } | 861 | } |
925 | 862 | ||
926 | ///@param GLuint id, texture that is going to be sampled. | 863 | ///@param GLuint id, texture that is going to be sampled. |
@@ -939,45 +876,45 @@ class gl_spider : public virtual gl_texture<T> | @@ -939,45 +876,45 @@ class gl_spider : public virtual gl_texture<T> | ||
939 | network_time = 0; | 876 | network_time = 0; |
940 | hit_time = 0; | 877 | hit_time = 0; |
941 | #endif | 878 | #endif |
942 | - stepsize = 2.5; | ||
943 | - t_length = 16.0; | 879 | +#ifdef DEBUG |
880 | + iter = 0; | ||
881 | + iter_pos = 0; | ||
882 | + iter_dir = 0; | ||
883 | + iter_siz = 0; | ||
884 | +#endif | ||
885 | + stepsize = 10.0; | ||
886 | + n_pixels = 16.0; | ||
944 | 887 | ||
945 | srand(100); | 888 | srand(100); |
946 | texID = id; | 889 | texID = id; |
947 | - //GenerateFBO(16, numSamples*8); | ||
948 | - GenerateFBO(t_length*2, numSamples*t_length, texbufferID, fboID); | ||
949 | - std::cout << numSamples << std::endl; | 890 | + GenerateFBO(n_pixels*2, numSamples*n_pixels, direction_texID, direction_buffID); |
950 | CHECK_OPENGL_ERROR | 891 | CHECK_OPENGL_ERROR |
951 | - GenerateFBO(t_length*2, numSamplesPos*t_length, ptexbufferID, pfboID); | ||
952 | - std::cout << numSamplesPos << std::endl; | 892 | + GenerateFBO(n_pixels*2, numSamplesPos*n_pixels, position_texID, position_buffID); |
953 | CHECK_OPENGL_ERROR | 893 | CHECK_OPENGL_ERROR |
954 | - GenerateFBO(t_length*2, numSamplesMag*t_length, mtexbufferID, mfboID); | ||
955 | - std::cout << numSamplesMag << std::endl; | 894 | + GenerateFBO(n_pixels*2, numSamplesMag*n_pixels, radius_texID, radius_buffID); |
956 | CHECK_OPENGL_ERROR | 895 | CHECK_OPENGL_ERROR |
957 | - GenerateFBO(16, 216, btexbufferID, bfboID); | 896 | + GenerateFBO(16, 216, cylinder_texID, cylinder_buffID); |
958 | CHECK_OPENGL_ERROR | 897 | CHECK_OPENGL_ERROR |
959 | - t_dir.MapCudaTexture(texbufferID, GL_TEXTURE_2D); | 898 | + t_dir.MapCudaTexture(direction_texID, GL_TEXTURE_2D); |
960 | t_dir.Alloc(numSamples); | 899 | t_dir.Alloc(numSamples); |
961 | - t_pos.MapCudaTexture(ptexbufferID, GL_TEXTURE_2D); | 900 | + t_pos.MapCudaTexture(position_texID, GL_TEXTURE_2D); |
962 | t_pos.Alloc(numSamplesPos); | 901 | t_pos.Alloc(numSamplesPos); |
963 | - t_mag.MapCudaTexture(mtexbufferID, GL_TEXTURE_2D); | 902 | + t_mag.MapCudaTexture(radius_texID, GL_TEXTURE_2D); |
964 | t_mag.Alloc(numSamplesMag); | 903 | t_mag.Alloc(numSamplesMag); |
965 | -// setDims(0.6, 0.6, 1.0); | ||
966 | -// setSize(1024.0, 1024.0, 1024.0); | ||
967 | setMatrix(); | 904 | setMatrix(); |
968 | dList = glGenLists(3); | 905 | dList = glGenLists(3); |
969 | glListBase(dList); | 906 | glListBase(dList); |
970 | - Bind(texbufferID, fboID, numSamples, t_length); | ||
971 | - genDirectionVectors(5*M_PI/4); | 907 | + Bind(direction_texID, direction_buffID, numSamples, n_pixels); |
908 | + genDirectionVectors(5*stim::PI/4); | ||
972 | Unbind(); | 909 | Unbind(); |
973 | - Bind(ptexbufferID, pfboID, numSamplesPos, t_length); | ||
974 | - genPositionVectors(); | 910 | + Bind(position_texID, position_buffID, numSamplesPos, n_pixels); |
911 | + genPositionVectors(0.2); | ||
975 | Unbind(); | 912 | Unbind(); |
976 | - Bind(mtexbufferID, mfboID, numSamplesMag, t_length); | 913 | + Bind(radius_texID, radius_buffID, numSamplesMag, n_pixels); |
977 | genMagnitudeVectors(); | 914 | genMagnitudeVectors(); |
978 | Unbind(); | 915 | Unbind(); |
979 | - Bind(btexbufferID, bfboID, 27); | ||
980 | - DrawCylinder(); | 916 | + Bind(cylinder_texID, cylinder_buffID, 27); |
917 | +// DrawCylinder(); | ||
981 | Unbind(); | 918 | Unbind(); |
982 | } | 919 | } |
983 | 920 | ||
@@ -999,7 +936,7 @@ class gl_spider : public virtual gl_texture<T> | @@ -999,7 +936,7 @@ class gl_spider : public virtual gl_texture<T> | ||
999 | } | 936 | } |
1000 | 937 | ||
1001 | ///Returns the m vector. | 938 | ///Returns the m vector. |
1002 | - stim::vec<float> | 939 | + float |
1003 | getMagnitude() | 940 | getMagnitude() |
1004 | { | 941 | { |
1005 | return m; | 942 | return m; |
@@ -1045,22 +982,13 @@ class gl_spider : public virtual gl_texture<T> | @@ -1045,22 +982,13 @@ class gl_spider : public virtual gl_texture<T> | ||
1045 | d[2] = z; | 982 | d[2] = z; |
1046 | } | 983 | } |
1047 | 984 | ||
1048 | - ///@param stim::vec<float> dir, the new d. | ||
1049 | - ///Sets the m vector to the input vector mag. | ||
1050 | - void | ||
1051 | - setMagnitude(stim::vec<float> mag) | ||
1052 | - { | ||
1053 | - m[0] = mag[0]; | ||
1054 | - m[1] = mag[0]; | ||
1055 | - } | ||
1056 | 985 | ||
1057 | ///@param float mag, size of the sampled region. | 986 | ///@param float mag, size of the sampled region. |
1058 | ///Sets the m vector to the input mag for both templates. | 987 | ///Sets the m vector to the input mag for both templates. |
1059 | void | 988 | void |
1060 | setMagnitude(float mag) | 989 | setMagnitude(float mag) |
1061 | { | 990 | { |
1062 | - m[0] = mag; | ||
1063 | - m[1] = mag; | 991 | + m = mag; |
1064 | } | 992 | } |
1065 | 993 | ||
1066 | ///@param float x, voxel size in the x direction. | 994 | ///@param float x, voxel size in the x direction. |
@@ -1111,17 +1039,27 @@ class gl_spider : public virtual gl_texture<T> | @@ -1111,17 +1039,27 @@ class gl_spider : public virtual gl_texture<T> | ||
1111 | getRotation(stim::vec3<float> dir) | 1039 | getRotation(stim::vec3<float> dir) |
1112 | { | 1040 | { |
1113 | stim::vec<float> out(0.0,0.0,0.0,0.0); | 1041 | stim::vec<float> out(0.0,0.0,0.0,0.0); |
1114 | - stim::vec<float> from(0.0,0.0,1.0); | ||
1115 | - out[0] = acos(dir.dot(from))*180/M_PI; | ||
1116 | - if(out[0] < 1.0){ | 1042 | + stim::vec3<float> from(0.0,0.0,1.0); |
1043 | + out[0] = acos(dir.dot(from))*180/stim::PI; | ||
1044 | + #ifdef DEBUG | ||
1045 | + std::cout << "out is " << out << std::endl; | ||
1046 | + std::cout << "when rotating from " << from << " to " << dir << std::endl; | ||
1047 | + #endif | ||
1048 | + if(out[0] < 0.01){ | ||
1117 | out[0] = 0.0; | 1049 | out[0] = 0.0; |
1118 | out[1] = 0.0; | 1050 | out[1] = 0.0; |
1119 | out[2] = 0.0; | 1051 | out[2] = 0.0; |
1120 | out[3] = 1.0; | 1052 | out[3] = 1.0; |
1053 | + } | ||
1054 | + else if(out[0] < -180.0+0.01) | ||
1055 | + { | ||
1056 | + out[0] = 180.0; | ||
1057 | + out[1] = 1.0; | ||
1058 | + out[2] = 0.0; | ||
1059 | + out[3] = 0.0; | ||
1121 | } else { | 1060 | } else { |
1122 | - stim::vec<float> temp(0.0, 0.0, 0.0);; | ||
1123 | - stim::vec<float> dir1(dir[0], dir[1], dir[2]); | ||
1124 | - temp = (from.cross(dir1)).norm(); | 1061 | + stim::vec3<float> temp(0.0, 0.0, 0.0);; |
1062 | + temp = (from.cross(dir)).norm(); | ||
1125 | out[1] = temp[0]; | 1063 | out[1] = temp[0]; |
1126 | out[2] = temp[1]; | 1064 | out[2] = temp[1]; |
1127 | out[3] = temp[2]; | 1065 | out[3] = temp[2]; |
@@ -1152,7 +1090,6 @@ class gl_spider : public virtual gl_texture<T> | @@ -1152,7 +1090,6 @@ class gl_spider : public virtual gl_texture<T> | ||
1152 | void | 1090 | void |
1153 | setSeedMag(float mag) | 1091 | setSeedMag(float mag) |
1154 | { | 1092 | { |
1155 | -// std::cout << "sMag: " << mag << std::endl; | ||
1156 | seedsmags.push(mag); | 1093 | seedsmags.push(mag); |
1157 | } | 1094 | } |
1158 | 1095 | ||
@@ -1165,7 +1102,6 @@ class gl_spider : public virtual gl_texture<T> | @@ -1165,7 +1102,6 @@ class gl_spider : public virtual gl_texture<T> | ||
1165 | void | 1102 | void |
1166 | setSeed(float x, float y, float z) | 1103 | setSeed(float x, float y, float z) |
1167 | { | 1104 | { |
1168 | -// std::cout << "sPos: " << x << " " << y << " " << z << std::endl; | ||
1169 | seeds.push(stim::vec<float>(x, y, z)); | 1105 | seeds.push(stim::vec<float>(x, y, z)); |
1170 | } | 1106 | } |
1171 | 1107 | ||
@@ -1176,7 +1112,6 @@ class gl_spider : public virtual gl_texture<T> | @@ -1176,7 +1112,6 @@ class gl_spider : public virtual gl_texture<T> | ||
1176 | void | 1112 | void |
1177 | setSeedVec(float x, float y, float z) | 1113 | setSeedVec(float x, float y, float z) |
1178 | { | 1114 | { |
1179 | -// std::cout << "sDir: " << x << " " << y << " " << z << std::endl; | ||
1180 | seedsvecs.push(stim::vec<float>(x, y, z)); | 1115 | seedsvecs.push(stim::vec<float>(x, y, z)); |
1181 | } | 1116 | } |
1182 | 1117 | ||
@@ -1297,7 +1232,7 @@ class gl_spider : public virtual gl_texture<T> | @@ -1297,7 +1232,7 @@ class gl_spider : public virtual gl_texture<T> | ||
1297 | void | 1232 | void |
1298 | saveNetwork(std::string name) | 1233 | saveNetwork(std::string name) |
1299 | { | 1234 | { |
1300 | - stim::glObj<float> sk; | 1235 | +/* stim::glObj<float> sk; |
1301 | for(int i = 0; i < nt.sizeE(); i++) | 1236 | for(int i = 0; i < nt.sizeE(); i++) |
1302 | { | 1237 | { |
1303 | std::vector<stim::vec< float > > cm = nt.getEdgeCenterLineMag(i); | 1238 | std::vector<stim::vec< float > > cm = nt.getEdgeCenterLineMag(i); |
@@ -1310,7 +1245,7 @@ class gl_spider : public virtual gl_texture<T> | @@ -1310,7 +1245,7 @@ class gl_spider : public virtual gl_texture<T> | ||
1310 | } | 1245 | } |
1311 | sk.End(); | 1246 | sk.End(); |
1312 | } | 1247 | } |
1313 | - sk.save(name); | 1248 | +*/ sk.save(name); |
1314 | } | 1249 | } |
1315 | 1250 | ||
1316 | ///Depreciated, but might be reused later() | 1251 | ///Depreciated, but might be reused later() |
@@ -1318,7 +1253,7 @@ class gl_spider : public virtual gl_texture<T> | @@ -1318,7 +1253,7 @@ class gl_spider : public virtual gl_texture<T> | ||
1318 | stim::glObj<float> | 1253 | stim::glObj<float> |
1319 | getNetwork() | 1254 | getNetwork() |
1320 | { | 1255 | { |
1321 | - | 1256 | + return sk; |
1322 | } | 1257 | } |
1323 | 1258 | ||
1324 | ///returns a COPY of the entire stim::glnetwork object. | 1259 | ///returns a COPY of the entire stim::glnetwork object. |
@@ -1333,7 +1268,7 @@ class gl_spider : public virtual gl_texture<T> | @@ -1333,7 +1268,7 @@ class gl_spider : public virtual gl_texture<T> | ||
1333 | GLuint | 1268 | GLuint |
1334 | getFB() | 1269 | getFB() |
1335 | { | 1270 | { |
1336 | - return bfboID; | 1271 | + return cylinder_buffID; |
1337 | } | 1272 | } |
1338 | 1273 | ||
1339 | //--------------------------------------------------------------------------// | 1274 | //--------------------------------------------------------------------------// |
@@ -1357,14 +1292,17 @@ class gl_spider : public virtual gl_texture<T> | @@ -1357,14 +1292,17 @@ class gl_spider : public virtual gl_texture<T> | ||
1357 | int | 1292 | int |
1358 | Step() | 1293 | Step() |
1359 | { | 1294 | { |
1360 | - Bind(texbufferID, fboID, numSamples, t_length); | 1295 | + #ifdef DEBUG |
1296 | + std::cerr << "Took a step" << std::endl; | ||
1297 | + #endif | ||
1298 | + Bind(direction_texID, direction_buffID, numSamples, n_pixels); | ||
1361 | CHECK_OPENGL_ERROR | 1299 | CHECK_OPENGL_ERROR |
1362 | findOptimalDirection(); | 1300 | findOptimalDirection(); |
1363 | Unbind(); | 1301 | Unbind(); |
1364 | - Bind(ptexbufferID, pfboID, numSamplesPos, t_length); | 1302 | + Bind(position_texID, position_buffID, numSamplesPos, n_pixels); |
1365 | findOptimalPosition(); | 1303 | findOptimalPosition(); |
1366 | Unbind(); | 1304 | Unbind(); |
1367 | - Bind(mtexbufferID, mfboID, numSamplesMag, t_length); | 1305 | + Bind(radius_texID, radius_buffID, numSamplesMag, n_pixels); |
1368 | findOptimalScale(); | 1306 | findOptimalScale(); |
1369 | Unbind(); | 1307 | Unbind(); |
1370 | CHECK_OPENGL_ERROR | 1308 | CHECK_OPENGL_ERROR |
@@ -1385,16 +1323,16 @@ class gl_spider : public virtual gl_texture<T> | @@ -1385,16 +1323,16 @@ class gl_spider : public virtual gl_texture<T> | ||
1385 | //--------------------------------------------------------------------------// | 1323 | //--------------------------------------------------------------------------// |
1386 | 1324 | ||
1387 | void | 1325 | void |
1388 | - MonteCarloDirectionVectors(int nSamples, float solidAngle = 2*M_PI) | 1326 | + MonteCarloDirectionVectors(int nSamples, float solidAngle = stim::TAU) |
1389 | { | 1327 | { |
1390 | - float PHI[2], Z[2], range; | ||
1391 | - PHI[0] = asin(solidAngle/2); | ||
1392 | - PHI[1] = asin(0); | 1328 | +// float PHI[2];//, Z[2];//, range; |
1329 | +// PHI[0] = asin(solidAngle/2); | ||
1330 | +// PHI[1] = asin(0); | ||
1393 | 1331 | ||
1394 | - Z[0] = cos(PHI[0]); | ||
1395 | - Z[1] = cos(PHI[1]); | 1332 | +// Z[0] = cos(PHI[0]); |
1333 | +// Z[1] = cos(PHI[1]); | ||
1396 | 1334 | ||
1397 | - range = Z[0] - Z[1]; | 1335 | +// range = Z[0] - Z[1]; |
1398 | 1336 | ||
1399 | std::vector<stim::vec3<float> > vecsUni; | 1337 | std::vector<stim::vec3<float> > vecsUni; |
1400 | for(int i = 0; i < numSamplesPos; i++) | 1338 | for(int i = 0; i < numSamplesPos; i++) |
@@ -1428,8 +1366,8 @@ class gl_spider : public virtual gl_texture<T> | @@ -1428,8 +1366,8 @@ class gl_spider : public virtual gl_texture<T> | ||
1428 | int j = 0; | 1366 | int j = 0; |
1429 | for(float i = step; i <= 360.0; i += step) | 1367 | for(float i = step; i <= 360.0; i += step) |
1430 | { | 1368 | { |
1431 | - x=r0*cos(i*2.0*M_PI/360.0); | ||
1432 | - y=r0*sin(i*2.0*M_PI/360.0); | 1369 | + x=r0*cos(i*stim::TAU/360.0); |
1370 | + y=r0*sin(i*stim::TAU/360.0); | ||
1433 | glTexCoord3f(x,y,z0); | 1371 | glTexCoord3f(x,y,z0); |
1434 | glVertex2f(0.0, j*6.4+6.4); | 1372 | glVertex2f(0.0, j*6.4+6.4); |
1435 | // glVertex2f(0.0, j*27.0+27.0); | 1373 | // glVertex2f(0.0, j*27.0+27.0); |
@@ -1451,12 +1389,13 @@ class gl_spider : public virtual gl_texture<T> | @@ -1451,12 +1389,13 @@ class gl_spider : public virtual gl_texture<T> | ||
1451 | } | 1389 | } |
1452 | 1390 | ||
1453 | ///need to return the cylinder. | 1391 | ///need to return the cylinder. |
1392 | +///SOMETHING MIGHT BE GOING ON HERE IN GENERATE BUFFER. | ||
1454 | void | 1393 | void |
1455 | DrawLongCylinder(int n = 8, int l_template = 8,int l_square = 8) | 1394 | DrawLongCylinder(int n = 8, int l_template = 8,int l_square = 8) |
1456 | { | 1395 | { |
1457 | int cylLen = cL.size()-1; | 1396 | int cylLen = cL.size()-1; |
1458 | - GenerateFBO(n*l_square, cylLen*l_template, btexbufferID, bfboID); | ||
1459 | - Bind(btexbufferID, bfboID, cylLen, l_template*l_square/2.0); | 1397 | + GenerateFBO(n*l_square, cylLen*l_template, cylinder_texID, cylinder_buffID); |
1398 | + Bind(cylinder_texID, cylinder_buffID, cylLen, l_template*l_square/2.0); | ||
1460 | stim::cylinder<float> cyl(cL, cM); | 1399 | stim::cylinder<float> cyl(cL, cM); |
1461 | std::vector<std::vector<stim::vec3<float> > > p = cyl.getPoints(n); | 1400 | std::vector<std::vector<stim::vec3<float> > > p = cyl.getPoints(n); |
1462 | for(int i = 0; i < p.size()-1; i++) ///number of circles | 1401 | for(int i = 0; i < p.size()-1; i++) ///number of circles |
@@ -1502,14 +1441,28 @@ class gl_spider : public virtual gl_texture<T> | @@ -1502,14 +1441,28 @@ class gl_spider : public virtual gl_texture<T> | ||
1502 | seeds.pop(); | 1441 | seeds.pop(); |
1503 | seedsvecs.pop(); | 1442 | seedsvecs.pop(); |
1504 | seedsmags.pop(); | 1443 | seedsmags.pop(); |
1505 | -// std::cout << "The current seed Vector is " << curSeedVec << std::endl; | ||
1506 | setPosition(curSeed); | 1444 | setPosition(curSeed); |
1507 | setDirection(curSeedVec); | 1445 | setDirection(curSeedVec); |
1508 | setMagnitude(curSeedMag); | 1446 | setMagnitude(curSeedMag); |
1447 | + | ||
1448 | + #ifdef DEBUG | ||
1449 | + std::cout << "The new seed " << curSeed << curSeedVec << curSeedMag << std::endl; | ||
1450 | + #endif | ||
1451 | + | ||
1452 | +// Bind(direction_texID, direction_buffID, numSamples, n_pixels); | ||
1453 | +// CHECK_OPENGL_ERROR | ||
1454 | +// findOptimalDirection(); | ||
1455 | +// Unbind(); | ||
1456 | +//THIS IS EXPERIMENTAL | ||
1457 | + Bind(radius_texID, radius_buffID, numSamplesMag, n_pixels); | ||
1458 | + findOptimalScale(); | ||
1459 | + Unbind(); | ||
1460 | +//THIS IS EXPERIMENTAL | ||
1461 | + | ||
1509 | // cL.push_back(curSeed); | 1462 | // cL.push_back(curSeed); |
1510 | // cM.push_back(curSeedMag); | 1463 | // cM.push_back(curSeedMag); |
1511 | // cD.push_back(curSeedMag); | 1464 | // cD.push_back(curSeedMag); |
1512 | - pair<stim::fiber<float>, int> a = traceLine(p, m, min_cost); | 1465 | + traceLine(p, m, min_cost); |
1513 | } | 1466 | } |
1514 | } | 1467 | } |
1515 | 1468 | ||
@@ -1556,17 +1509,17 @@ class gl_spider : public virtual gl_texture<T> | @@ -1556,17 +1509,17 @@ class gl_spider : public virtual gl_texture<T> | ||
1556 | ds[0], ds[1], ds[2], | 1509 | ds[0], ds[1], ds[2], |
1557 | ups[0], ups[1], ups[2]); | 1510 | ups[0], ups[1], ups[2]); |
1558 | 1511 | ||
1559 | -// sk.Render(); | ||
1560 | - nt.Render(); | 1512 | + sk.Render(); |
1513 | +// nt.Render(); | ||
1561 | 1514 | ||
1562 | CHECK_OPENGL_ERROR | 1515 | CHECK_OPENGL_ERROR |
1563 | 1516 | ||
1564 | 1517 | ||
1565 | -// glLoadName((int) sk.numL()); | ||
1566 | - glLoadName(nt.sizeE()); | 1518 | + glLoadName((int) sk.numL()); |
1519 | +// glLoadName(nt.sizeE()); | ||
1567 | 1520 | ||
1568 | -// sk.RenderLine(cL); | ||
1569 | - nt.RenderLine(cL); | 1521 | + sk.RenderLine(cL); |
1522 | +// nt.RenderLine(cL); | ||
1570 | 1523 | ||
1571 | // glPopName(); | 1524 | // glPopName(); |
1572 | glFlush(); | 1525 | glFlush(); |
@@ -1615,8 +1568,9 @@ class gl_spider : public virtual gl_texture<T> | @@ -1615,8 +1568,9 @@ class gl_spider : public virtual gl_texture<T> | ||
1615 | { | 1568 | { |
1616 | cL.clear(); | 1569 | cL.clear(); |
1617 | cM.clear(); | 1570 | cM.clear(); |
1618 | - } | 1571 | + } |
1619 | 1572 | ||
1573 | +/* | ||
1620 | void | 1574 | void |
1621 | addToNetwork(pair<stim::fiber<float>, int> in, stim::vec3<float> spos, | 1575 | addToNetwork(pair<stim::fiber<float>, int> in, stim::vec3<float> spos, |
1622 | stim::vec<float> smag, stim::vec3<float> sdir) | 1576 | stim::vec<float> smag, stim::vec3<float> sdir) |
@@ -1664,13 +1618,26 @@ class gl_spider : public virtual gl_texture<T> | @@ -1664,13 +1618,26 @@ class gl_spider : public virtual gl_texture<T> | ||
1664 | network_time += nt * 1000.0; | 1618 | network_time += nt * 1000.0; |
1665 | #endif | 1619 | #endif |
1666 | } | 1620 | } |
1621 | +*/ | ||
1622 | + void | ||
1623 | + addToNetwork(std::vector<stim::vec3<float> > L, std::vector<float > M) | ||
1624 | + { | ||
1625 | + if(L.size() > 3) | ||
1626 | + { | ||
1627 | + sk.Begin(stim::OBJ_LINE); | ||
1628 | + for(int i = 0; i < L.size(); i++) | ||
1629 | + { | ||
1630 | + sk.TexCoord(M[i]); | ||
1631 | + sk.Vertex(L[i][0], L[i][1], L[i][2]); | ||
1632 | + } | ||
1633 | + sk.End(); | ||
1667 | 1634 | ||
1668 | -// void | ||
1669 | -// addToNetwork(pair<stim::fiber<float>, int> in, stim::vec3<float> spos, | ||
1670 | -// stim::vec<float> smag, stim::vec3<float> sdir) | ||
1671 | -// { | ||
1672 | -// | ||
1673 | -// } | 1635 | + nt.addEdge(L,M); |
1636 | + #ifdef DEBUG | ||
1637 | + iter++; | ||
1638 | + #endif | ||
1639 | + } | ||
1640 | + } | ||
1674 | 1641 | ||
1675 | 1642 | ||
1676 | void | 1643 | void |
@@ -1678,23 +1645,22 @@ class gl_spider : public virtual gl_texture<T> | @@ -1678,23 +1645,22 @@ class gl_spider : public virtual gl_texture<T> | ||
1678 | { | 1645 | { |
1679 | std::cout << nt.sizeE() << " edges " << std::endl; | 1646 | std::cout << nt.sizeE() << " edges " << std::endl; |
1680 | std::cout << nt.sizeV() << " nodes " << std::endl; | 1647 | std::cout << nt.sizeV() << " nodes " << std::endl; |
1681 | - | ||
1682 | } | 1648 | } |
1683 | 1649 | ||
1684 | - std::pair<stim::fiber<float>, int > | ||
1685 | - traceLine(stim::vec3<float> pos, stim::vec<float> mag, int min_cost) | 1650 | + void |
1651 | + traceLine(stim::vec3<float> pos, float mag, int min_cost) | ||
1686 | { | 1652 | { |
1687 | //starting (seed) position and magnitude. | 1653 | //starting (seed) position and magnitude. |
1688 | stim::vec3<float> spos = getPosition(); | 1654 | stim::vec3<float> spos = getPosition(); |
1689 | - stim::vec<float> smag = getMagnitude(); | 1655 | + float smag = getMagnitude(); |
1690 | stim::vec3<float> sdir = getDirection(); | 1656 | stim::vec3<float> sdir = getDirection(); |
1691 | 1657 | ||
1692 | - Bind(); | 1658 | +// Bind(); |
1693 | // sk.Begin(stim::OBJ_LINE); | 1659 | // sk.Begin(stim::OBJ_LINE); |
1694 | 1660 | ||
1695 | 1661 | ||
1696 | -// sk.createFromSelf(GL_SELECT); | ||
1697 | - nt.createFromSelf(GL_SELECT); | 1662 | + sk.createFromSelf(GL_SELECT); |
1663 | +// nt.createFromSelf(GL_SELECT); | ||
1698 | 1664 | ||
1699 | cL.push_back(pos); | 1665 | cL.push_back(pos); |
1700 | cM.push_back(mag); | 1666 | cM.push_back(mag); |
@@ -1710,12 +1676,11 @@ class gl_spider : public virtual gl_texture<T> | @@ -1710,12 +1676,11 @@ class gl_spider : public virtual gl_texture<T> | ||
1710 | int cost = Step(); | 1676 | int cost = Step(); |
1711 | if (cost > min_cost){ | 1677 | if (cost > min_cost){ |
1712 | running = false; | 1678 | running = false; |
1713 | -// sk.End(); | ||
1714 | branchDetection2(); | 1679 | branchDetection2(); |
1715 | - pair<stim::fiber<float>, int> a(stim::fiber<float> (cL, cM), -1); | ||
1716 | - addToNetwork(a, spos, smag, sdir); | ||
1717 | -// std::cout << "the cost of " << cost << " > " << min_cost << std::endl; | ||
1718 | - return a; | 1680 | + addToNetwork(cL, cM); |
1681 | + #ifdef DEBUG | ||
1682 | + std::cerr << "the cost of " << cost << " > " << min_cost << std::endl; | ||
1683 | + #endif | ||
1719 | break; | 1684 | break; |
1720 | } else { | 1685 | } else { |
1721 | //Have we found the edge of the map? | 1686 | //Have we found the edge of the map? |
@@ -1726,10 +1691,10 @@ class gl_spider : public virtual gl_texture<T> | @@ -1726,10 +1691,10 @@ class gl_spider : public virtual gl_texture<T> | ||
1726 | { | 1691 | { |
1727 | running = false; | 1692 | running = false; |
1728 | branchDetection2(); | 1693 | branchDetection2(); |
1729 | - pair<stim::fiber<float>, int> a(stim::fiber<float> (cL, cM), -1); | ||
1730 | - addToNetwork(a, spos, smag, sdir); | ||
1731 | -// std::cout << "I hit and edge" << std::endl; | ||
1732 | - return a; | 1694 | + addToNetwork(cL, cM); |
1695 | + #ifdef DEBUG | ||
1696 | + std::cerr << "I hit and edge" << std::endl; | ||
1697 | + #endif | ||
1733 | break; | 1698 | break; |
1734 | } | 1699 | } |
1735 | //If this is the first step in the trace, | 1700 | //If this is the first step in the trace, |
@@ -1741,39 +1706,40 @@ class gl_spider : public virtual gl_texture<T> | @@ -1741,39 +1706,40 @@ class gl_spider : public virtual gl_texture<T> | ||
1741 | } | 1706 | } |
1742 | //Has the template size gotten unreasonable? | 1707 | //Has the template size gotten unreasonable? |
1743 | mag = getMagnitude(); | 1708 | mag = getMagnitude(); |
1744 | - if(mag[0] > 75 || mag[0] < 1){ | 1709 | + if(mag > 75 || mag < 1){ |
1745 | running = false; | 1710 | running = false; |
1746 | branchDetection2(); | 1711 | branchDetection2(); |
1747 | - pair<stim::fiber<float>, int> a(stim::fiber<float> (cL, cM), -1); | ||
1748 | - addToNetwork(a, spos, smag, sdir); | ||
1749 | -// std::cout << "The templates are too big" << std::endl; | ||
1750 | - return a; | 1712 | + addToNetwork(cL, cM); |
1713 | + #ifdef DEBUG | ||
1714 | + std::cerr << "The templates are too big" << std::endl; | ||
1715 | + #endif | ||
1751 | break; | 1716 | break; |
1752 | } | 1717 | } |
1753 | else | 1718 | else |
1754 | { | 1719 | { |
1755 | - h = selectObject(p, getDirection(), m[0]); | 1720 | + h = selectObject(p, getDirection(), m); |
1756 | //Have we hit something previously traced? | 1721 | //Have we hit something previously traced? |
1757 | if(h != -1){ | 1722 | if(h != -1){ |
1758 | -// std::cout << "I hit the fiber " << h << std::endl; | 1723 | + #ifdef DEBUG |
1724 | + std::cerr << "I hit the fiber " << h << std::endl; | ||
1725 | + #endif | ||
1759 | running = false; | 1726 | running = false; |
1760 | branchDetection2(); | 1727 | branchDetection2(); |
1761 | - pair<stim::fiber<float>, int> a(stim::fiber<float> (cL, cM), h); | ||
1762 | - addToNetwork(a, spos, smag, sdir); | ||
1763 | - return a; | 1728 | + addToNetwork(cL, cM); |
1764 | break; | 1729 | break; |
1765 | } | 1730 | } |
1766 | else { | 1731 | else { |
1767 | cL.push_back(stim::vec3<float>(p[0], p[1],p[2])); | 1732 | cL.push_back(stim::vec3<float>(p[0], p[1],p[2])); |
1768 | - cM.push_back(stim::vec<float>(m[0], m[0])); | ||
1769 | -// Bind(btexbufferID, bfboID, 27); | ||
1770 | - Unbind(); | 1733 | + cM.push_back(m); |
1734 | +// Unbind(); | ||
1771 | CHECK_OPENGL_ERROR | 1735 | CHECK_OPENGL_ERROR |
1772 | - | ||
1773 | } | 1736 | } |
1774 | } | 1737 | } |
1775 | } | 1738 | } |
1776 | } | 1739 | } |
1740 | + #ifdef DEBUG | ||
1741 | + std::cout << "I broke out!" << std::endl; | ||
1742 | + #endif | ||
1777 | } | 1743 | } |
1778 | }; | 1744 | }; |
1779 | } | 1745 | } |
stim/gl/gl_texture.h
@@ -64,7 +64,7 @@ class gl_texture : public virtual image_stack<T, F> | @@ -64,7 +64,7 @@ class gl_texture : public virtual image_stack<T, F> | ||
64 | case 4: | 64 | case 4: |
65 | return GL_RGBA; | 65 | return GL_RGBA; |
66 | default: | 66 | default: |
67 | - std::cout<<"Error in stim::gl_texture - unable to guess texture format based on number of channels ("<<R[4]<<")"<<std::endl; | 67 | + std::cout<<"Error in stim::gl_texture - unable to guess texture format based on number of channels" << std::endl; |
68 | exit(1); | 68 | exit(1); |
69 | } | 69 | } |
70 | } | 70 | } |
@@ -236,7 +236,7 @@ class gl_texture : public virtual image_stack<T, F> | @@ -236,7 +236,7 @@ class gl_texture : public virtual image_stack<T, F> | ||
236 | if(texID == 0) generate_texture(); //generate the texture if it doesn't already exist | 236 | if(texID == 0) generate_texture(); //generate the texture if it doesn't already exist |
237 | else{ | 237 | else{ |
238 | std::cout<<"Texture has already been attached to a context."<<std::endl; | 238 | std::cout<<"Texture has already been attached to a context."<<std::endl; |
239 | - exit(1); | 239 | + //exit(1); Why do we need to quit if it's attached. print the message and continue. |
240 | } | 240 | } |
241 | } | 241 | } |
242 | 242 |
stim/math/circle.h
@@ -48,9 +48,9 @@ public: | @@ -48,9 +48,9 @@ public: | ||
48 | CUDA_CALLABLE | 48 | CUDA_CALLABLE |
49 | circle(T size, T z_pos = (T)0) : plane<T>() | 49 | circle(T size, T z_pos = (T)0) : plane<T>() |
50 | { | 50 | { |
51 | - init(); | ||
52 | center(stim::vec3<T>(0,0,z_pos)); | 51 | center(stim::vec3<T>(0,0,z_pos)); |
53 | scale(size); | 52 | scale(size); |
53 | + init(); | ||
54 | } | 54 | } |
55 | 55 | ||
56 | ///create a rectangle from a center point, normal | 56 | ///create a rectangle from a center point, normal |
@@ -88,6 +88,7 @@ public: | @@ -88,6 +88,7 @@ public: | ||
88 | { | 88 | { |
89 | init(); | 89 | init(); |
90 | setU(u); | 90 | setU(u); |
91 | +// U = u; | ||
91 | center(c); | 92 | center(c); |
92 | normal(n); | 93 | normal(n); |
93 | scale(s); | 94 | scale(s); |
@@ -174,6 +175,13 @@ public: | @@ -174,6 +175,13 @@ public: | ||
174 | return p(x,y); | 175 | return p(x,y); |
175 | } | 176 | } |
176 | 177 | ||
178 | + std::string str() const | ||
179 | + { | ||
180 | + std::stringstream ss; | ||
181 | + ss << "(P=" << P.str() << ", N=" << N.str() << ", U=" << U.str() << ", Y=" << Y.str(); | ||
182 | + return ss.str(); | ||
183 | + } | ||
184 | + | ||
177 | }; | 185 | }; |
178 | } | 186 | } |
179 | #endif | 187 | #endif |
stim/math/vec3.h
@@ -80,6 +80,15 @@ public: | @@ -80,6 +80,15 @@ public: | ||
80 | return sph; | 80 | return sph; |
81 | } | 81 | } |
82 | 82 | ||
83 | + CUDA_CALLABLE vec3<T> cart2cyl() const{ | ||
84 | + vec3<T> cyl; | ||
85 | + cyl.ptr[0] = sqrt(pow(ptr[0],2) + pow(ptr[1],2)); | ||
86 | + cyl.ptr[1] = atan(ptr[1]/ptr[0]); | ||
87 | + cyl.ptr[2] = ptr[2]; | ||
88 | + | ||
89 | + return cyl; | ||
90 | + } | ||
91 | + | ||
83 | /// Convert the vector from cartesian to spherical coordinates (r, theta, phi -> x, y, z where theta = [0, 2*pi]) | 92 | /// Convert the vector from cartesian to spherical coordinates (r, theta, phi -> x, y, z where theta = [0, 2*pi]) |
84 | CUDA_CALLABLE vec3<T> sph2cart() const{ | 93 | CUDA_CALLABLE vec3<T> sph2cart() const{ |
85 | vec3<T> cart; | 94 | vec3<T> cart; |
@@ -90,6 +99,16 @@ public: | @@ -90,6 +99,16 @@ public: | ||
90 | return cart; | 99 | return cart; |
91 | } | 100 | } |
92 | 101 | ||
102 | + /// Convert the vector from cylindrical to cart coordinates (r, theta, z -> x, y, z where theta = [0, 2*pi]) | ||
103 | + CUDA_CALLABLE vec3<T> cyl2cart() const{ | ||
104 | + vec3<T> cart; | ||
105 | + cart.ptr[0] = ptr[0] * std::cos(ptr[1]); | ||
106 | + cart.ptr[1] = ptr[0] * std::sin(ptr[1]); | ||
107 | + cart.ptr[2] = ptr[2]; | ||
108 | + | ||
109 | + return cart; | ||
110 | + } | ||
111 | + | ||
93 | /// Computes the normalized vector (where each coordinate is divided by the L2 norm) | 112 | /// Computes the normalized vector (where each coordinate is divided by the L2 norm) |
94 | CUDA_CALLABLE vec3<T> norm() const{ | 113 | CUDA_CALLABLE vec3<T> norm() const{ |
95 | vec3<T> result; | 114 | vec3<T> result; |
stim/visualization/cylinder.h
@@ -2,19 +2,27 @@ | @@ -2,19 +2,27 @@ | ||
2 | #define STIM_CYLINDER_H | 2 | #define STIM_CYLINDER_H |
3 | #include <iostream> | 3 | #include <iostream> |
4 | #include <stim/math/circle.h> | 4 | #include <stim/math/circle.h> |
5 | -#include <stim/math/vec3.h> | 5 | +#include <stim/biomodels/centerline.h> |
6 | 6 | ||
7 | 7 | ||
8 | namespace stim | 8 | namespace stim |
9 | { | 9 | { |
10 | template<typename T> | 10 | template<typename T> |
11 | class cylinder | 11 | class cylinder |
12 | + : public centerline<T> | ||
12 | { | 13 | { |
13 | private: | 14 | private: |
14 | stim::circle<T> s; //an arbitrary circle | 15 | stim::circle<T> s; //an arbitrary circle |
15 | - std::vector<stim::circle<T> > e; | 16 | + std::vector<stim::circle<T> > e; //an array of circles that store the centerline |
17 | + | ||
18 | + std::vector<stim::vec3<T> > norms; | ||
19 | + std::vector<stim::vec<T> > Us; | ||
16 | std::vector<stim::vec<T> > mags; | 20 | std::vector<stim::vec<T> > mags; |
17 | std::vector< T > L; //length of the cylinder at each position. | 21 | std::vector< T > L; //length of the cylinder at each position. |
22 | + | ||
23 | + | ||
24 | + using stim::centerline<T>::c; | ||
25 | + using stim::centerline<T>::N; | ||
18 | 26 | ||
19 | ///default init | 27 | ///default init |
20 | void | 28 | void |
@@ -23,6 +31,20 @@ class cylinder | @@ -23,6 +31,20 @@ class cylinder | ||
23 | 31 | ||
24 | } | 32 | } |
25 | 33 | ||
34 | + ///Calculate the physical length of the fiber at each point in the fiber. | ||
35 | + void | ||
36 | + calculateL() | ||
37 | + { | ||
38 | +/* L.resize(inP.size()); | ||
39 | + T temp = (T)0; | ||
40 | + L[0] = 0; | ||
41 | + for(size_t i = 1; i < L.size(); i++) | ||
42 | + { | ||
43 | + temp += (inP[i-1] - inP[i]).len(); | ||
44 | + L[i] = temp; | ||
45 | + } | ||
46 | +*/ } | ||
47 | + | ||
26 | ///inits the cylinder from a list of points (std::vector of stim::vec3 --inP) and radii (inM) | 48 | ///inits the cylinder from a list of points (std::vector of stim::vec3 --inP) and radii (inM) |
27 | void | 49 | void |
28 | init(std::vector<stim::vec3<T> > inP, std::vector<stim::vec<T> > inM) | 50 | init(std::vector<stim::vec3<T> > inP, std::vector<stim::vec<T> > inM) |
@@ -31,6 +53,10 @@ class cylinder | @@ -31,6 +53,10 @@ class cylinder | ||
31 | stim::vec3<float> v1; | 53 | stim::vec3<float> v1; |
32 | stim::vec3<float> v2; | 54 | stim::vec3<float> v2; |
33 | e.resize(inP.size()); | 55 | e.resize(inP.size()); |
56 | + | ||
57 | + norms.resize(inP.size()); | ||
58 | + Us.resize(inP.size()); | ||
59 | + | ||
34 | if(inP.size() < 2) | 60 | if(inP.size() < 2) |
35 | return; | 61 | return; |
36 | 62 | ||
@@ -46,7 +72,9 @@ class cylinder | @@ -46,7 +72,9 @@ class cylinder | ||
46 | 72 | ||
47 | stim::vec3<T> dr = (inP[1] - inP[0]).norm(); | 73 | stim::vec3<T> dr = (inP[1] - inP[0]).norm(); |
48 | s = stim::circle<T>(inP[0], inM[0][0], dr, stim::vec3<T>(1,0,0)); | 74 | s = stim::circle<T>(inP[0], inM[0][0], dr, stim::vec3<T>(1,0,0)); |
75 | + norms[0] = s.N; | ||
49 | e[0] = s; | 76 | e[0] = s; |
77 | + Us[0] = e[0].U; | ||
50 | for(size_t i = 1; i < inP.size()-1; i++) | 78 | for(size_t i = 1; i < inP.size()-1; i++) |
51 | { | 79 | { |
52 | s.center(inP[i]); | 80 | s.center(inP[i]); |
@@ -54,16 +82,24 @@ class cylinder | @@ -54,16 +82,24 @@ class cylinder | ||
54 | v2 = (inP[i+1] - inP[i]).norm(); | 82 | v2 = (inP[i+1] - inP[i]).norm(); |
55 | dr = (v1+v2).norm(); | 83 | dr = (v1+v2).norm(); |
56 | s.normal(dr); | 84 | s.normal(dr); |
85 | + | ||
86 | + norms[i] = s.N; | ||
87 | + | ||
57 | s.scale(inM[i][0]/inM[i-1][0]); | 88 | s.scale(inM[i][0]/inM[i-1][0]); |
58 | e[i] = s; | 89 | e[i] = s; |
90 | + Us[i] = e[i].U; | ||
59 | } | 91 | } |
60 | 92 | ||
61 | int j = inP.size()-1; | 93 | int j = inP.size()-1; |
62 | s.center(inP[j]); | 94 | s.center(inP[j]); |
63 | dr = (inP[j] - inP[j-1]).norm(); | 95 | dr = (inP[j] - inP[j-1]).norm(); |
64 | s.normal(dr); | 96 | s.normal(dr); |
97 | + | ||
98 | + norms[j] = s.N; | ||
99 | + | ||
65 | s.scale(inM[j][0]/inM[j-1][0]); | 100 | s.scale(inM[j][0]/inM[j-1][0]); |
66 | e[j] = s; | 101 | e[j] = s; |
102 | + Us[j] = e[j].U; | ||
67 | } | 103 | } |
68 | 104 | ||
69 | ///returns the direction vector at point idx. | 105 | ///returns the direction vector at point idx. |
@@ -72,18 +108,42 @@ class cylinder | @@ -72,18 +108,42 @@ class cylinder | ||
72 | { | 108 | { |
73 | if(idx == 0) | 109 | if(idx == 0) |
74 | { | 110 | { |
75 | - return (e[idx+1].P - e[idx].P).norm(); | 111 | + stim::vec3<T> temp( |
112 | + c[idx+1][0]-c[idx][0], | ||
113 | + c[idx+1][1]-c[idx][1], | ||
114 | + c[idx+1][2]-c[idx][2] | ||
115 | + ); | ||
116 | +// return (e[idx+1].P - e[idx].P).norm(); | ||
117 | + return (temp.norm()); | ||
76 | } | 118 | } |
77 | - else if(idx == e.size()-1) | 119 | + else if(idx == N-1) |
78 | { | 120 | { |
79 | - return (e[idx].P - e[idx-1].P).norm(); | 121 | + stim::vec3<T> temp( |
122 | + c[idx][0]-c[idx+1][0], | ||
123 | + c[idx][1]-c[idx+1][1], | ||
124 | + c[idx][2]-c[idx+1][2] | ||
125 | + ); | ||
126 | + // return (e[idx].P - e[idx-1].P).norm(); | ||
127 | + return (temp.norm()); | ||
80 | } | 128 | } |
81 | else | 129 | else |
82 | { | 130 | { |
83 | // return (e[idx+1].P - e[idx].P).norm(); | 131 | // return (e[idx+1].P - e[idx].P).norm(); |
84 | - stim::vec3<float> v1 = (e[idx].P-e[idx-1].P).norm(); | ||
85 | - stim::vec3<float> v2 = (e[idx+1].P-e[idx].P).norm(); | ||
86 | - return (v1+v2).norm(); | 132 | +// stim::vec3<float> v1 = (e[idx].P-e[idx-1].P).norm(); |
133 | + stim::vec3<T> v1( | ||
134 | + c[idx][0]-c[idx-1][0], | ||
135 | + c[idx][1]-c[idx-1][1], | ||
136 | + c[idx][2]-c[idx-1][2] | ||
137 | + ); | ||
138 | + | ||
139 | +// stim::vec3<float> v2 = (e[idx+1].P-e[idx].P).norm(); | ||
140 | + stim::vec3<T> v2( | ||
141 | + c[idx+1][0]-c[idx][0], | ||
142 | + c[idx+1][1]-c[idx][1], | ||
143 | + c[idx+1][2]-c[idx][2] | ||
144 | + ); | ||
145 | + | ||
146 | + return (v1.norm()+v2.norm()).norm(); | ||
87 | } | 147 | } |
88 | // return e[idx].N; | 148 | // return e[idx].N; |
89 | 149 | ||
@@ -92,14 +152,17 @@ class cylinder | @@ -92,14 +152,17 @@ class cylinder | ||
92 | stim::vec3<T> | 152 | stim::vec3<T> |
93 | d(T l, int idx) | 153 | d(T l, int idx) |
94 | { | 154 | { |
95 | - if(idx == 0 || idx == e.size()-1) | 155 | + if(idx == 0 || idx == N-1) |
96 | { | 156 | { |
97 | - return e[idx].N; | 157 | + return norms[idx]; |
158 | +// return e[idx].N; | ||
98 | } | 159 | } |
99 | else | 160 | else |
100 | { | 161 | { |
162 | + | ||
101 | T rat = (l-L[idx])/(L[idx+1]-L[idx]); | 163 | T rat = (l-L[idx])/(L[idx+1]-L[idx]); |
102 | - return( e[idx].N + (e[idx+1].N - e[idx].N)*rat); | 164 | + return( norms[idx] + (norms[idx+1] - norms[idx])*rat); |
165 | +// return( e[idx].N + (e[idx+1].N - e[idx].N)*rat); | ||
103 | } | 166 | } |
104 | } | 167 | } |
105 | 168 | ||
@@ -137,6 +200,7 @@ class cylinder | @@ -137,6 +200,7 @@ class cylinder | ||
137 | public: | 200 | public: |
138 | ///default constructor | 201 | ///default constructor |
139 | cylinder() | 202 | cylinder() |
203 | + // : centerline<T>() | ||
140 | { | 204 | { |
141 | 205 | ||
142 | } | 206 | } |
@@ -144,15 +208,33 @@ class cylinder | @@ -144,15 +208,33 @@ class cylinder | ||
144 | ///constructor to create a cylinder from a set of points, radii, and the number of sides for the cylinder. | 208 | ///constructor to create a cylinder from a set of points, radii, and the number of sides for the cylinder. |
145 | ///@param inP: Vector of stim vec3 composing the points of the centerline. | 209 | ///@param inP: Vector of stim vec3 composing the points of the centerline. |
146 | ///@param inM: Vector of stim vecs composing the radii of the centerline. | 210 | ///@param inM: Vector of stim vecs composing the radii of the centerline. |
147 | - cylinder(std::vector<stim::vec3<T> > inP, std::vector<stim::vec<T> > inM){ | 211 | + cylinder(std::vector<stim::vec3<T> > inP, std::vector<stim::vec<T> > inM) |
212 | + : centerline<T>(inP) | ||
213 | + { | ||
148 | init(inP, inM); | 214 | init(inP, inM); |
149 | } | 215 | } |
150 | 216 | ||
217 | + ///constructor to create a cylinder from a set of points, radii, and the number of sides for the cylinder. | ||
218 | + ///@param inP: Vector of stim vec3 composing the points of the centerline. | ||
219 | + ///@param inM: Vector of stim vecs composing the radii of the centerline. | ||
220 | + cylinder(std::vector<stim::vec3<T> > inP, std::vector< T > inM) | ||
221 | + : centerline<T>(inP) | ||
222 | + { | ||
223 | + std::vector<stim::vec<T> > temp; | ||
224 | + stim::vec<T> zero(0.0,0.0); | ||
225 | + temp.resize(inM.size(), zero); | ||
226 | + for(int i = 0; i < inM.size(); i++) | ||
227 | + temp[i][0] = inM[i]; | ||
228 | + init(inP, temp); | ||
229 | + } | ||
230 | + | ||
151 | 231 | ||
152 | ///Constructor defines a cylinder with centerline inP and magnitudes of zero | 232 | ///Constructor defines a cylinder with centerline inP and magnitudes of zero |
153 | ///@param inP: Vector of stim vec3 composing the points of the centerline | 233 | ///@param inP: Vector of stim vec3 composing the points of the centerline |
154 | - cylinder(std::vector< stim::vec3<T> > inP){ | ||
155 | - std::vector< stim::vec<T> > inM; //create an array of arbitrary magnitudes | 234 | + cylinder(std::vector< stim::vec3<T> > inP) |
235 | + : centerline<T>(inP) | ||
236 | + { | ||
237 | + std::vector< T > inM; //create an array of arbitrary magnitudes | ||
156 | 238 | ||
157 | stim::vec<T> zero; | 239 | stim::vec<T> zero; |
158 | zero.push_back(0); | 240 | zero.push_back(0); |
@@ -164,7 +246,7 @@ class cylinder | @@ -164,7 +246,7 @@ class cylinder | ||
164 | ///Returns the number of points on the cylinder centerline | 246 | ///Returns the number of points on the cylinder centerline |
165 | 247 | ||
166 | unsigned int size(){ | 248 | unsigned int size(){ |
167 | - return e.size(); | 249 | + return N; |
168 | } | 250 | } |
169 | 251 | ||
170 | 252 | ||
@@ -180,9 +262,23 @@ class cylinder | @@ -180,9 +262,23 @@ class cylinder | ||
180 | } | 262 | } |
181 | T l = pvalue*L[L.size()-1]; | 263 | T l = pvalue*L[L.size()-1]; |
182 | int idx = findIdx(l); | 264 | int idx = findIdx(l); |
183 | - T rat = (l-L[idx])/(L[idx+1]-L[idx]); | ||
184 | - return( e[idx].P + (e[idx+1].P-e[idx].P)*rat); | ||
185 | - } | 265 | + return (p(l,idx)); |
266 | +/* T rat = (l-L[idx])/(L[idx+1]-L[idx]); | ||
267 | + stim::vec3<T> v1( | ||
268 | + c[idx][0], | ||
269 | + c[idx][1], | ||
270 | + c[idx][2] | ||
271 | + ); | ||
272 | + | ||
273 | + stim::vec3<T> v2( | ||
274 | + c[idx+1][0], | ||
275 | + c[idx+1][1], | ||
276 | + c[idx+1][2] | ||
277 | + ); | ||
278 | + | ||
279 | +// return( e[idx].P + (e[idx+1].P-e[idx].P)*rat); | ||
280 | + return( v1 + (v2 - v1)*rat); | ||
281 | +*/ } | ||
186 | 282 | ||
187 | ///Returns a position vector at the given length into the fiber (based on the pvalue). | 283 | ///Returns a position vector at the given length into the fiber (based on the pvalue). |
188 | ///Interpolates the radius along the line. | 284 | ///Interpolates the radius along the line. |
@@ -192,7 +288,19 @@ class cylinder | @@ -192,7 +288,19 @@ class cylinder | ||
192 | p(T l, int idx) | 288 | p(T l, int idx) |
193 | { | 289 | { |
194 | T rat = (l-L[idx])/(L[idx+1]-L[idx]); | 290 | T rat = (l-L[idx])/(L[idx+1]-L[idx]); |
195 | - return( e[idx].P + (e[idx+1].P-e[idx].P)*rat); | 291 | + stim::vec3<T> v1( |
292 | + c[idx][0], | ||
293 | + c[idx][1], | ||
294 | + c[idx][2] | ||
295 | + ); | ||
296 | + | ||
297 | + stim::vec3<T> v2( | ||
298 | + c[idx+1][0], | ||
299 | + c[idx+1][1], | ||
300 | + c[idx+1][2] | ||
301 | + ); | ||
302 | +// return( e[idx].P + (e[idx+1].P-e[idx].P)*rat); | ||
303 | + return( v1 + (v2-v1)*rat); | ||
196 | // return( | 304 | // return( |
197 | // return (pos[idx] + (pos[idx+1]-pos[idx])*((l-L[idx])/(L[idx+1]- L[idx]))); | 305 | // return (pos[idx] + (pos[idx+1]-pos[idx])*((l-L[idx])/(L[idx+1]- L[idx]))); |
198 | } | 306 | } |
@@ -209,8 +317,11 @@ class cylinder | @@ -209,8 +317,11 @@ class cylinder | ||
209 | } | 317 | } |
210 | T l = pvalue*L[L.size()-1]; | 318 | T l = pvalue*L[L.size()-1]; |
211 | int idx = findIdx(l); | 319 | int idx = findIdx(l); |
212 | - return (e[idx].U.len() + (e[idx+1].U.len() - e[idx].U.len())*((l-L[idx])/(L[idx+1]- L[idx]))); | ||
213 | - } | 320 | + return (r(l,idx)); |
321 | +/* T rat = (l-L[idx])/(L[idx+1]-L[idx]); | ||
322 | +// return (mags[idx][0] + (mags[idx+1][0]-mags[idx][0])*rat); | ||
323 | + return (e[idx].U.len() + (e[idx+1].U.len() - e[idx].U.len())*rat); | ||
324 | +*/ } | ||
214 | 325 | ||
215 | ///Returns a radius at the given length into the fiber (based on the pvalue). | 326 | ///Returns a radius at the given length into the fiber (based on the pvalue). |
216 | ///Interpolates the position along the line. | 327 | ///Interpolates the position along the line. |
@@ -220,7 +331,23 @@ class cylinder | @@ -220,7 +331,23 @@ class cylinder | ||
220 | r(T l, int idx) | 331 | r(T l, int idx) |
221 | { | 332 | { |
222 | T rat = (l-L[idx])/(L[idx+1]-L[idx]); | 333 | T rat = (l-L[idx])/(L[idx+1]-L[idx]); |
223 | - return( e[idx].U.len() + (e[idx+1].U.len() - e[idx].U.len())*rat); | 334 | + T v1 = (e[idx].U.len() + (e[idx+1].U.len() - e[idx].U.len())*rat); |
335 | + T v3 = (Us[idx].len() + (Us[idx+1].len() - Us[idx].len())*rat); | ||
336 | + T v2 = (mags[idx][0] + (mags[idx+1][0]-mags[idx][0])*rat); | ||
337 | +// std::cout << (float)v1 = (float) v2 << std::endl; | ||
338 | + if(abs(v3 - v1) >= 10e-6) | ||
339 | + { | ||
340 | + std::cout << "-------------------------" << std::endl; | ||
341 | + std::cout << e[idx].str() << std::endl << std::endl; | ||
342 | + std::cout << Us[idx].str() << std::endl; | ||
343 | + std::cout << (float)v1 - (float) v2 << std::endl; | ||
344 | + std::cout << "failed" << std::endl; | ||
345 | + } | ||
346 | +// std::cout << e[idx].U.len() << " " << mags[idx][0] << std::endl; | ||
347 | +// std::cout << v2 << std::endl; | ||
348 | + return(v2); | ||
349 | +// return (mags[idx][0] + (mags[idx+1][0]-mags[idx][0])*rat); | ||
350 | + // ( | ||
224 | } | 351 | } |
225 | 352 | ||
226 | /// Returns the magnitude at the given index | 353 | /// Returns the magnitude at the given index |
@@ -233,7 +360,7 @@ class cylinder | @@ -233,7 +360,7 @@ class cylinder | ||
233 | /// Adds a new magnitude value to all points | 360 | /// Adds a new magnitude value to all points |
234 | /// @param m is the starting value for the new magnitude | 361 | /// @param m is the starting value for the new magnitude |
235 | void add_mag(T m = 0){ | 362 | void add_mag(T m = 0){ |
236 | - for(unsigned int p = 0; p < e.size(); p++) | 363 | + for(unsigned int p = 0; p < N; p++) |
237 | mags[p].push_back(m); | 364 | mags[p].push_back(m); |
238 | } | 365 | } |
239 | 366 | ||
@@ -279,8 +406,8 @@ class cylinder | @@ -279,8 +406,8 @@ class cylinder | ||
279 | getPoints(int sides) | 406 | getPoints(int sides) |
280 | { | 407 | { |
281 | std::vector<std::vector <vec3<T> > > points; | 408 | std::vector<std::vector <vec3<T> > > points; |
282 | - points.resize(e.size()); | ||
283 | - for(int i = 0; i < e.size(); i++) | 409 | + points.resize(N); |
410 | + for(int i = 0; i < N; i++) | ||
284 | { | 411 | { |
285 | points[i] = e[i].getPoints(sides); | 412 | points[i] = e[i].getPoints(sides); |
286 | } | 413 | } |
@@ -319,7 +446,7 @@ class cylinder | @@ -319,7 +446,7 @@ class cylinder | ||
319 | T len = L[0]; //allocate space for the segment length | 446 | T len = L[0]; //allocate space for the segment length |
320 | 447 | ||
321 | //for every consecutive point in the cylinder | 448 | //for every consecutive point in the cylinder |
322 | - for(unsigned p = 1; p < e.size(); p++){ | 449 | + for(unsigned p = 1; p < N; p++){ |
323 | 450 | ||
324 | //p1 = pos[p]; //get the position and magnitude for the next point | 451 | //p1 = pos[p]; //get the position and magnitude for the next point |
325 | m1 = mags[p][m]; | 452 | m1 = mags[p][m]; |
stim/visualization/glObj.h
@@ -5,6 +5,7 @@ | @@ -5,6 +5,7 @@ | ||
5 | #include <GL/glut.h> | 5 | #include <GL/glut.h> |
6 | #include <stim/math/vector.h> | 6 | #include <stim/math/vector.h> |
7 | #include <stim/visualization/obj.h> | 7 | #include <stim/visualization/obj.h> |
8 | +#include <stim/gl/error.h> | ||
8 | 9 | ||
9 | 10 | ||
10 | namespace stim | 11 | namespace stim |
@@ -35,9 +36,9 @@ private: | @@ -35,9 +36,9 @@ private: | ||
35 | glListBase(dList); | 36 | glListBase(dList); |
36 | 37 | ||
37 | glMatrixMode(GL_PROJECTION); | 38 | glMatrixMode(GL_PROJECTION); |
38 | - glLoadIdentity; | 39 | + glLoadIdentity(); |
39 | glMatrixMode(GL_MODELVIEW); | 40 | glMatrixMode(GL_MODELVIEW); |
40 | - glLoadIdentity; | 41 | + glLoadIdentity(); |
41 | 42 | ||
42 | } | 43 | } |
43 | 44 | ||
@@ -129,7 +130,7 @@ public: | @@ -129,7 +130,7 @@ public: | ||
129 | } | 130 | } |
130 | 131 | ||
131 | void | 132 | void |
132 | - RenderLine(std::vector< stim::vec<T> > l) | 133 | + RenderLine(std::vector< stim::vec3<T> > l) |
133 | { | 134 | { |
134 | glColor3f(0.5, 1.0, 0.5); | 135 | glColor3f(0.5, 1.0, 0.5); |
135 | glLineWidth(3.0); | 136 | glLineWidth(3.0); |
stim/visualization/obj.h
@@ -322,13 +322,6 @@ protected: | @@ -322,13 +322,6 @@ protected: | ||
322 | return OBJ_INVALID; | 322 | return OBJ_INVALID; |
323 | } | 323 | } |
324 | 324 | ||
325 | - //private method returns the vertex indices for a line | ||
326 | - std::vector<unsigned> get_l_v(unsigned l){ | ||
327 | - | ||
328 | - | ||
329 | - | ||
330 | - } | ||
331 | - | ||
332 | public: | 325 | public: |
333 | /// Constructor loads a Wavefront OBJ file | 326 | /// Constructor loads a Wavefront OBJ file |
334 | obj(std::string filename){ | 327 | obj(std::string filename){ |