Commit 0d0ef1a95d99ca400df0ccbad7c68b0f373e806e
1 parent
32ba91f2
Adapted classes to work with the new stim::cylinder class.
Showing
5 changed files
with
66 additions
and
28 deletions
Show diff stats
stim/biomodels/centerline.h
... | ... | @@ -57,10 +57,14 @@ protected: |
57 | 57 | ///finds the index of the point closest to the length l on the lower bound. |
58 | 58 | ///binary search. |
59 | 59 | size_t findIdx(T l) { |
60 | - size_t i = L.size() / 2; | |
60 | + for (size_t i = 1; i < L.size(); i++) { //for each point in the centerline | |
61 | + if (L[i] > l) return i - 1; //if we have passed the desired length value, return i-1 | |
62 | + } | |
63 | + return L.size() - 1; | |
64 | + /*size_t i = L.size() / 2; | |
61 | 65 | size_t max = L.size() - 1; |
62 | 66 | size_t min = 0; |
63 | - while (i > 0 && i < L.size() - 1){ | |
67 | + while (i < L.size() - 1){ | |
64 | 68 | if (l < L[i]) { |
65 | 69 | max = i; |
66 | 70 | i = min + (max - min) / 2; |
... | ... | @@ -73,7 +77,7 @@ protected: |
73 | 77 | i = min + (max - min) / 2; |
74 | 78 | } |
75 | 79 | } |
76 | - return i; | |
80 | + return i;*/ | |
77 | 81 | } |
78 | 82 | |
79 | 83 | ///Returns a position vector at the given length into the fiber (based on the pvalue). |
... | ... | @@ -118,6 +122,10 @@ public: |
118 | 122 | return p(l, idx); |
119 | 123 | } |
120 | 124 | |
125 | + ///Update centerline internal parameters (currently the L vector) | |
126 | + void update() { | |
127 | + init(); | |
128 | + } | |
121 | 129 | ///Return the length of the entire centerline |
122 | 130 | T length() { |
123 | 131 | return L.back(); | ... | ... |
stim/biomodels/network.h
... | ... | @@ -338,6 +338,7 @@ public: |
338 | 338 | stim::centerline<T> c3(c.size()); |
339 | 339 | for(size_t j = 0; j < c.size(); j++) |
340 | 340 | c3[j] = c[j]; |
341 | + c3.update(); | |
341 | 342 | |
342 | 343 | // edge new_edge = c3; ///This is dangerous. |
343 | 344 | edge new_edge(c3); |
... | ... | @@ -512,8 +513,8 @@ public: |
512 | 513 | kdt.create(c, n_data, MaxTreeLevels); // build a KD tree |
513 | 514 | |
514 | 515 | for(unsigned e = 0; e < R.E.size(); e++){ //for each edge in A |
515 | - R.E[e].add_mag(0); //add a new magnitude for the metric | |
516 | - size_t errormag_id = R.E[e].nmags() - 1; //get the id for the new magnitude | |
516 | + //R.E[e].add_mag(0); //add a new magnitude for the metric | |
517 | + //size_t errormag_id = R.E[e].nmags() - 1; //get the id for the new magnitude | |
517 | 518 | |
518 | 519 | size_t n = R.E[e].size(); // the number of points in current edge |
519 | 520 | T* queryPt = new T[3 * n]; |
... | ... | @@ -540,7 +541,7 @@ public: |
540 | 541 | cudaMemcpy(m1, d_m1, n * sizeof(T), cudaMemcpyDeviceToHost); |
541 | 542 | |
542 | 543 | for(unsigned p = 0; p < n; p++){ |
543 | - R.E[e].set_mag(errormag_id, p, m1[p]); | |
544 | + R.E[e].set_r(p, m1[p]); | |
544 | 545 | } |
545 | 546 | |
546 | 547 | //d_set_mag<<<blocks, threads>>>(R.E[e].M, errormag_id, n, m1); |
... | ... | @@ -608,8 +609,8 @@ public: |
608 | 609 | relation.resize(A.E.size()); |
609 | 610 | |
610 | 611 | for(unsigned e = 0; e < A.E.size(); e++){ //for each edge in A |
611 | - A.E[e].add_mag(0); //add a new magnitude for the metric | |
612 | - size_t errormag_id = A.E[e].nmags() - 1; | |
612 | + //A.E[e].add_mag(0); //add a new magnitude for the metric | |
613 | + //size_t errormag_id = A.E[e].nmags() - 1; | |
613 | 614 | |
614 | 615 | size_t n = A.E[e].size(); // the number of edges in A |
615 | 616 | |
... | ... | @@ -643,7 +644,7 @@ public: |
643 | 644 | cudaMemcpy(m1, d_m1, n * sizeof(T), cudaMemcpyDeviceToHost); |
644 | 645 | |
645 | 646 | for(unsigned p = 0; p < n; p++){ |
646 | - A.E[e].set_mag(errormag_id, p, m1[p]); // set the error(radius) value to every point in current edge | |
647 | + A.E[e].set_r(p, m1[p]); // set the error(radius) value to every point in current edge | |
647 | 648 | } |
648 | 649 | |
649 | 650 | relation[e].resize(n); // resize every edge relation size |
... | ... | @@ -723,10 +724,10 @@ public: |
723 | 724 | if(p == E[e].size() - 2) // if there is no splitting index, set the id to the last point index of current edge |
724 | 725 | id = p + 1; |
725 | 726 | } |
726 | - unsigned errormag_id = E[e].nmags() - 1; | |
727 | + //unsigned errormag_id = E[e].nmags() - 1; | |
727 | 728 | T G = 0; // test to see whether it has its nearest neighbor |
728 | 729 | for(unsigned i = 0; i < E[e].size(); i++) |
729 | - G += E[e].m(i, errormag_id); // won't split special edges | |
730 | + G += E[e].r(i); // won't split special edges | |
730 | 731 | if(G / E[e].size() > metric_fac) // should based on the color map |
731 | 732 | id = E[e].size() - 1; // set split idx to outgoing direction vertex |
732 | 733 | |
... | ... | @@ -795,12 +796,12 @@ public: |
795 | 796 | kdt.create(c, n_data, MaxTreeLevels); // build a KD tree |
796 | 797 | |
797 | 798 | for(unsigned e = 0; e < n; e++){ //for each edge in A |
798 | - size_t errormag_id = A.E[e].nmags() - 1; //get the id for the new magnitude | |
799 | + //size_t errormag_id = A.E[e].nmags() - 1; //get the id for the new magnitude | |
799 | 800 | |
800 | 801 | //pre-judge to get rid of impossibly mapping edges |
801 | 802 | T M = 0; |
802 | 803 | for(unsigned p = 0; p < A.E[e].size(); p++) |
803 | - M += A.E[e].m(p, errormag_id); | |
804 | + M += A.E[e].r(p); | |
804 | 805 | M = M / A.E[e].size(); |
805 | 806 | if(M > metric_fac) |
806 | 807 | C[e] = (unsigned)-1; //set the nearest edge of impossibly mapping edges to maximum of unsigned |
... | ... | @@ -862,9 +863,9 @@ public: |
862 | 863 | } |
863 | 864 | |
864 | 865 | /// Returns the number of magnitude values stored in each edge. This should be uniform across the network. |
865 | - unsigned nmags(){ | |
866 | - return E[0].nmags(); | |
867 | - } | |
866 | + //unsigned nmags(){ | |
867 | + // return E[0].nmags(); | |
868 | + //} | |
868 | 869 | // split a string in text by the character sep |
869 | 870 | stim::vec<T> split(std::string &text, char sep) |
870 | 871 | { | ... | ... |
stim/visualization/camera.h
1 | 1 | #include <stim/math/vector.h> |
2 | 2 | #include <stim/math/quaternion.h> |
3 | -#include <stim/math/matrix.h> | |
3 | +#include <stim/math/matrix_sq.h> | |
4 | 4 | |
5 | 5 | #include <ostream> |
6 | 6 | |
... | ... | @@ -92,7 +92,7 @@ public: |
92 | 92 | quaternion<float> final = qz*qy*qx; |
93 | 93 | |
94 | 94 | //get the rotation matrix |
95 | - matrix<float, 3> rot_matrix = final.toMatrix3(); | |
95 | + matrix_sq<float, 3> rot_matrix = final.toMatrix3(); | |
96 | 96 | |
97 | 97 | //apply the rotation |
98 | 98 | d = rot_matrix*d; | ... | ... |
stim/visualization/cylinder.h
... | ... | @@ -21,6 +21,7 @@ protected: |
21 | 21 | // this function assumes that the centerline has already been set |
22 | 22 | void init() { |
23 | 23 | U.resize(size()); //allocate space for the frenet frame vectors |
24 | + R.resize(size()); | |
24 | 25 | |
25 | 26 | stim::circle<T> c; //create a circle |
26 | 27 | stim::vec3<T> d0, d1; |
... | ... | @@ -44,13 +45,13 @@ public: |
44 | 45 | |
45 | 46 | cylinder(centerline& c, T r) : centerline(c) { |
46 | 47 | init(); |
47 | - add_mag(r); | |
48 | + //add_mag(r); | |
48 | 49 | } |
49 | 50 | |
50 | 51 | //initialize a cylinder with a list of points and magnitude values |
51 | 52 | cylinder(centerline& c, std::vector<T> r) : centerline(c){ |
52 | 53 | init(); |
53 | - add_mag(r); | |
54 | + //add_mag(r); | |
54 | 55 | } |
55 | 56 | |
56 | 57 | ///Returns magnitude i at the given length into the fiber (based on the pvalue). |
... | ... | @@ -73,15 +74,15 @@ public: |
73 | 74 | |
74 | 75 | T l = pvalue*L[L.size() - 1]; |
75 | 76 | int idx = findIdx(l); |
76 | - return r(l, idx, i); | |
77 | + return r(l, idx); | |
77 | 78 | } |
78 | 79 | |
79 | 80 | /// Returns the magnitude at the given index |
80 | 81 | /// @param i is the index of the desired point |
81 | 82 | /// @param r is the index of the magnitude value |
82 | - T r(unsigned i) { | |
83 | - return R[i]; | |
84 | - } | |
83 | + //T r(unsigned i) { | |
84 | + // return R[i]; | |
85 | + //} | |
85 | 86 | |
86 | 87 | ///adds a magnitude to each point in the cylinder |
87 | 88 | /*void add_mag(V val = 0) { |
... | ... | @@ -210,9 +211,37 @@ public: |
210 | 211 | c.R[i] = r(t); //retrieve the interpolated magnitude from the current cylinder and store it in the new one |
211 | 212 | //} |
212 | 213 | } |
214 | + return c; | |
215 | + } | |
213 | 216 | |
217 | + std::vector< stim::cylinder<T> > split(unsigned int idx) { | |
218 | + | |
219 | + unsigned N = size(); | |
220 | + std::vector< stim::centerline<T> > LL; | |
221 | + LL.resize(2); | |
222 | + LL = (*this).centerline<T>::split(idx); | |
223 | + std::vector< stim::cylinder<T> > C(LL.size()); | |
224 | + unsigned i = 0; | |
225 | + C[0] = LL[0]; | |
226 | + //C[0].R.resize(idx); | |
227 | + for (; i < idx; i++) { | |
228 | + //for(unsigned d = 0; d < 3; d++) | |
229 | + //C[0][i][d] = LL[0].c[i][d]; | |
230 | + C[0].R[i] = R[i]; | |
231 | + //C[0].R[i].resize(1); | |
232 | + } | |
233 | + if (C.size() == 2) { | |
234 | + C[1] = LL[1]; | |
235 | + //C[1].M.resize(N - idx); | |
236 | + for (; i < N; i++) { | |
237 | + //for(unsigned d = 0; d < 3; d++) | |
238 | + //C[1][i - idx][d] = LL[1].c[i - idx][d]; | |
239 | + C[1].R[i - idx] = R[i]; | |
240 | + //C[1].M[i - idx].resize(1); | |
241 | + } | |
242 | + } | |
214 | 243 | |
215 | - return c; | |
244 | + return C; | |
216 | 245 | } |
217 | 246 | |
218 | 247 | ... | ... |
stim/visualization/gl_network.h
... | ... | @@ -63,17 +63,17 @@ public: |
63 | 63 | } |
64 | 64 | |
65 | 65 | /// @param m specifies the magnitude value used as the vertex weight (radius, error, etc.) |
66 | - void glCenterline(unsigned m = 0){ | |
66 | + void glCenterline(){ | |
67 | 67 | |
68 | 68 | if(!glIsList(dlist)){ //if dlist isn't a display list, create it |
69 | 69 | dlist = glGenLists(3); //generate a display list |
70 | 70 | glNewList(dlist, GL_COMPILE); //start a new display list |
71 | 71 | for(unsigned e = 0; e < E.size(); e++){ //for each edge in the network |
72 | - unsigned errormag_id = E[e].nmags() - 1; | |
72 | + //unsigned errormag_id = E[e].nmags() - 1; | |
73 | 73 | glBegin(GL_LINE_STRIP); |
74 | 74 | for(unsigned p = 0; p < E[e].size(); p++){ //for each point on that edge |
75 | 75 | glVertex3f(E[e][p][0], E[e][p][1], E[e][p][2]); //set the vertex position based on the current point |
76 | - glTexCoord1f(E[e].m(p, errormag_id)); //set the texture coordinate based on the specified magnitude index | |
76 | + glTexCoord1f(E[e].r(p)); //set the texture coordinate based on the specified magnitude index | |
77 | 77 | } |
78 | 78 | glEnd(); |
79 | 79 | } | ... | ... |