Compare View
Commits (2)
Showing
3 changed files
Show diff stats
stim/biomodels/centerline.h
... | ... | @@ -31,20 +31,6 @@ protected: |
31 | 31 | vec3<T> ab = a.norm() + b.norm(); |
32 | 32 | return ab.norm(); |
33 | 33 | } |
34 | - //initializes the integrated length vector to make parameterization easier, starting with index idx (all previous indices are assumed to be correct) | |
35 | - void update_L(size_t start = 0) { | |
36 | - L.resize(size()); //allocate space for the L array | |
37 | - if (start == 0) { | |
38 | - L[0] = 0; //initialize the length value for the first point to zero (0) | |
39 | - start++; | |
40 | - } | |
41 | - | |
42 | - stim::vec3<T> d; | |
43 | - for (size_t i = start; i < size(); i++) { //for each line segment in the centerline | |
44 | - d = at(i) - at(i - 1); | |
45 | - L[i] = L[i - 1] + d.len(); //calculate the running length total | |
46 | - } | |
47 | - } | |
48 | 34 | |
49 | 35 | void init() { |
50 | 36 | if (size() == 0) return; //return if there aren't any points |
... | ... | @@ -135,6 +121,21 @@ public: |
135 | 121 | return L.back(); |
136 | 122 | } |
137 | 123 | |
124 | + //initializes the integrated length vector to make parameterization easier, starting with index idx (all previous indices are assumed to be correct) | |
125 | + void update_L(size_t start = 0) { | |
126 | + L.resize(size()); //allocate space for the L array | |
127 | + if (start == 0) { | |
128 | + L[0] = 0; //initialize the length value for the first point to zero (0) | |
129 | + start++; | |
130 | + } | |
131 | + | |
132 | + stim::vec3<T> d; | |
133 | + for (size_t i = start; i < size(); i++) { //for each line segment in the centerline | |
134 | + d = at(i) - at(i - 1); | |
135 | + L[i] = L[i - 1] + d.len(); //calculate the running length total | |
136 | + } | |
137 | + } | |
138 | + | |
138 | 139 | /// stitch two centerlines |
139 | 140 | ///@param c1, c2: two centerlines |
140 | 141 | ///@param sigma: sample rate | ... | ... |
stim/biomodels/network.h
... | ... | @@ -63,6 +63,7 @@ class network{ |
63 | 63 | class edge : public cylinder<T> |
64 | 64 | { |
65 | 65 | public: |
66 | + | |
66 | 67 | unsigned int v[2]; //unique id's designating the starting and ending |
67 | 68 | // default constructor |
68 | 69 | edge() : cylinder<T>() { |
... | ... | @@ -127,7 +128,7 @@ class network{ |
127 | 128 | // for(int j = 0; j < nmags(); j++) //future code for multiple mags |
128 | 129 | // { |
129 | 130 | out.write(reinterpret_cast<const char*>(&e.R[i]), sizeof(T)); ///write the radius |
130 | - std::cout << point.str() << " " << e.R[i] << std::endl; | |
131 | + //std::cout << point.str() << " " << e.R[i] << std::endl; | |
131 | 132 | // } |
132 | 133 | } |
133 | 134 | return out; //return stream |
... | ... | @@ -141,7 +142,7 @@ class network{ |
141 | 142 | in.read(reinterpret_cast<char*>(&v1), sizeof(unsigned int)); //read the ending point |
142 | 143 | in.read(reinterpret_cast<char*>(&sz), sizeof(unsigned int)); //read the number of points in the edge |
143 | 144 | stim::centerline<T> temp = stim::centerline<T>(sz); //allocate the new edge |
144 | - e = edge(temp); | |
145 | + e = edge(temp); | |
145 | 146 | e.v[0] = v0; e.v[1] = v1; |
146 | 147 | for(int i = 0; i < sz; i++) //set the points and radii to the newly read values |
147 | 148 | { |
... | ... | @@ -152,10 +153,12 @@ class network{ |
152 | 153 | // for(int j = 0; j < nmags(); j++) ///future code for mags |
153 | 154 | // { |
154 | 155 | in.read(reinterpret_cast<char*>(&mag), sizeof(T)); |
155 | - e.set_r(0, mag); | |
156 | - std::cout << point.str() << " " << mag << std::endl; | |
156 | + e.set_r(i, mag); | |
157 | + //std::cout << point.str() << " " << mag << std::endl; | |
157 | 158 | // } |
158 | 159 | } |
160 | + e.init(); | |
161 | + e.update(); | |
159 | 162 | return in; |
160 | 163 | } |
161 | 164 | }; |
... | ... | @@ -193,21 +196,23 @@ class network{ |
193 | 196 | |
194 | 197 | return ss.str(); |
195 | 198 | } |
196 | - ///operator for writing the edge into the stream; | |
199 | + ///operator for writing the vector into the stream; | |
197 | 200 | friend std::ofstream& operator<<(std::ofstream& out, const vertex& v) |
198 | 201 | { |
199 | 202 | unsigned int s0, s1; |
200 | 203 | s0 = v.e[0].size(); |
201 | 204 | s1 = v.e[1].size(); |
202 | 205 | out.write(reinterpret_cast<const char*>(&v.ptr[0]), 3*sizeof(T)); ///write physical vertex location |
203 | - out.write(reinterpret_cast<const char*>(&s0), sizeof(unsigned int)); ///write the number of "incoming edges" | |
204 | - out.write(reinterpret_cast<const char*>(&s1), sizeof(unsigned int)); ///write the number of "outgoing edges" | |
205 | - out.write(reinterpret_cast<const char*>(&v.e[0][0]), sizeof(unsigned int)*v.e[0].size()); ///write the "incoming edges" | |
206 | - out.write(reinterpret_cast<const char*>(&v.e[1][0]), sizeof(unsigned int)*v.e[1].size()); ///write the "outgoing edges" | |
206 | + out.write(reinterpret_cast<const char*>(&s0), sizeof(unsigned int)); ///write the number of "outgoing edges" | |
207 | + out.write(reinterpret_cast<const char*>(&s1), sizeof(unsigned int)); ///write the number of "incoming edges" | |
208 | + if (s0 != 0) | |
209 | + out.write(reinterpret_cast<const char*>(&v.e[0][0]), sizeof(unsigned int)*v.e[0].size()); ///write the "outgoing edges" | |
210 | + if (s1 != 0) | |
211 | + out.write(reinterpret_cast<const char*>(&v.e[1][0]), sizeof(unsigned int)*v.e[1].size()); ///write the "incoming edges" | |
207 | 212 | return out; |
208 | 213 | } |
209 | 214 | |
210 | - ///operator for reading the edge out of the stream; | |
215 | + ///operator for reading the vector out of the stream; | |
211 | 216 | friend std::ifstream& operator>>(std::ifstream& in, vertex& v) |
212 | 217 | { |
213 | 218 | in.read(reinterpret_cast<char*>(&v[0]), 3*sizeof(T)); ///read the physical position |
... | ... | @@ -218,8 +223,10 @@ class network{ |
218 | 223 | std::vector<unsigned int> two(s[1]); |
219 | 224 | v.e[0] = one; |
220 | 225 | v.e[1] = two; |
221 | - in.read(reinterpret_cast<char*>(&v.e[0][0]),s[0]*sizeof(unsigned int)); ///read the arrays of "incoming edges" | |
222 | - in.read(reinterpret_cast<char*>(&v.e[1][0]),s[1]*sizeof(unsigned int)); ///read the arrays of "outgoing edges" | |
226 | + if (one.size() != 0) | |
227 | + in.read(reinterpret_cast<char*>(&v.e[0][0]), s[0] * sizeof(unsigned int)); ///read the arrays of "outgoing edges" | |
228 | + if (two.size() != 0) | |
229 | + in.read(reinterpret_cast<char*>(&v.e[1][0]), s[1] * sizeof(unsigned int)); ///read the arrays of "incoming edges" | |
223 | 230 | return in; |
224 | 231 | } |
225 | 232 | |
... | ... | @@ -501,10 +508,24 @@ public: |
501 | 508 | it = find(id2vert.begin(), id2vert.end(), i[0]); //look for the first node |
502 | 509 | if(it == id2vert.end()){ //if i[0] hasn't already been used |
503 | 510 | vertex new_vertex = new_edge[0]; //create a new vertex, assign it a position |
504 | - new_vertex.e[0].push_back(E.size()); //add the current edge as outgoing | |
505 | - new_edge.v[0] = V.size(); //add the new edge to the edge | |
506 | - V.push_back(new_vertex); //add the new vertex to the vertex list | |
507 | - id2vert.push_back(i[0]); //add the ID to the ID->vertex conversion list | |
511 | + bool flag = false; | |
512 | + unsigned j = 0; | |
513 | + for (; j < V.size(); j++) { // check whether current vertex is already exist | |
514 | + if (new_vertex == V[j]) { | |
515 | + flag = true; | |
516 | + break; | |
517 | + } | |
518 | + } | |
519 | + if (!flag) { // unique one | |
520 | + new_vertex.e[0].push_back(E.size()); //add the current edge as outgoing | |
521 | + new_edge.v[0] = V.size(); //add the new edge to the edge | |
522 | + V.push_back(new_vertex); //add the new vertex to the vertex list | |
523 | + id2vert.push_back(i[0]); //add the ID to the ID->vertex conversion list | |
524 | + } | |
525 | + else { | |
526 | + V[j].e[0].push_back(E.size()); | |
527 | + new_edge.v[0] = j; | |
528 | + } | |
508 | 529 | } |
509 | 530 | else{ //if the vertex already exists |
510 | 531 | it_idx = std::distance(id2vert.begin(), it); |
... | ... | @@ -515,10 +536,24 @@ public: |
515 | 536 | it = find(id2vert.begin(), id2vert.end(), i[1]); //look for the second ID |
516 | 537 | if(it == id2vert.end()){ //if i[1] hasn't already been used |
517 | 538 | vertex new_vertex = new_edge[I-1]; //create a new vertex, assign it a position |
518 | - new_vertex.e[1].push_back(E.size()); //add the current edge as incoming | |
519 | - new_edge.v[1] = V.size(); //add the new vertex to the edge | |
520 | - V.push_back(new_vertex); //add the new vertex to the vertex list | |
521 | - id2vert.push_back(i[1]); //add the ID to the ID->vertex conversion list | |
539 | + bool flag = false; | |
540 | + unsigned j = 0; | |
541 | + for (; j < V.size(); j++) { // check whether current vertex is already exist | |
542 | + if (new_vertex == V[j]) { | |
543 | + flag = true; | |
544 | + break; | |
545 | + } | |
546 | + } | |
547 | + if (!flag) { | |
548 | + new_vertex.e[1].push_back(E.size()); //add the current edge as incoming | |
549 | + new_edge.v[1] = V.size(); //add the new vertex to the edge | |
550 | + V.push_back(new_vertex); //add the new vertex to the vertex list | |
551 | + id2vert.push_back(i[1]); //add the ID to the ID->vertex conversion list | |
552 | + } | |
553 | + else { | |
554 | + V[j].e[1].push_back(E.size()); | |
555 | + new_edge.v[1] = j; | |
556 | + } | |
522 | 557 | } |
523 | 558 | else{ //if the vertex already exists |
524 | 559 | it_idx = std::distance(id2vert.begin(), it); |
... | ... | @@ -529,6 +564,27 @@ public: |
529 | 564 | E.push_back(new_edge); //push the edge to the list |
530 | 565 | |
531 | 566 | } |
567 | + | |
568 | + // copy the radii information from OBJ | |
569 | + /*if (O.numVT()) { | |
570 | + unsigned k = 0; | |
571 | + for (unsigned i = 0; i < E.size(); i++) { | |
572 | + for (unsigned j = 0; j < E[i].size(); j++) { | |
573 | + E[i].cylinder<T>::set_r(j, O.getVT(k)[0] / 2); | |
574 | + k++; | |
575 | + } | |
576 | + } | |
577 | + }*/ | |
578 | + // OBJ class assumes that in L the two values are equal | |
579 | + if (O.numVT()) { | |
580 | + std::vector< unsigned > id; //create an array to store the centerline point IDs | |
581 | + for (unsigned i = 0; i < O.numL(); i++) { | |
582 | + id.clear(); | |
583 | + O.getLinei(i + 1, id); //get the list of point IDs for the line | |
584 | + for (unsigned j = 0; j < id.size(); j++) | |
585 | + E[i].cylinder<T>::set_r(j, O.getVT(id[j] - 1)[0] / 2); | |
586 | + } | |
587 | + } | |
532 | 588 | } |
533 | 589 | |
534 | 590 | ///loads a .nwt file. Reads the header and loads the data into the network according to the header. |
... | ... | @@ -554,7 +610,7 @@ public: |
554 | 610 | edge e; |
555 | 611 | file >> e; |
556 | 612 | E.push_back(e); |
557 | - std::cout << i << " " << E[i].str() << std::endl; | |
613 | + //std::cout << i << " " << E[i].str() << std::endl; // not necessary? | |
558 | 614 | } |
559 | 615 | file.close(); |
560 | 616 | } |
... | ... | @@ -573,7 +629,7 @@ public: |
573 | 629 | } |
574 | 630 | for(int i = 0; i < E.size(); i++) ///loop through the Edges and write each one. |
575 | 631 | { |
576 | - std::cout << i << " " << E[i].str() << std::endl; | |
632 | + //std::cout << i << " " << E[i].str() << std::endl; // not necesarry? | |
577 | 633 | file << E[i]; |
578 | 634 | } |
579 | 635 | file.close(); | ... | ... |
stim/visualization/cylinder.h
... | ... | @@ -21,18 +21,6 @@ protected: |
21 | 21 | |
22 | 22 | //calculates the U values for each point to initialize the frenet frame |
23 | 23 | // this function assumes that the centerline has already been set |
24 | - void init() { | |
25 | - U.resize(size()); //allocate space for the frenet frame vectors | |
26 | - R.resize(size()); | |
27 | - | |
28 | - stim::circle<T> c; //create a circle | |
29 | - stim::vec3<T> d0, d1; | |
30 | - for (size_t i = 0; i < size() - 1; i++) { //for each line segment in the centerline | |
31 | - c.rotate(d(i)); //rotate the circle to match that normal | |
32 | - U[i] = c.U; //save the U vector from the circle | |
33 | - } | |
34 | - U[size() - 1] = c.U; //for the last point, duplicate the final frenet frame vector | |
35 | - } | |
36 | 24 | |
37 | 25 | public: |
38 | 26 | |
... | ... | @@ -94,6 +82,20 @@ public: |
94 | 82 | return R[i]; |
95 | 83 | } |
96 | 84 | |
85 | + void init() { | |
86 | + U.resize(size()); //allocate space for the frenet frame vectors | |
87 | +// if (R.size() != 0) | |
88 | + R.resize(size()); | |
89 | + | |
90 | + stim::circle<T> c; //create a circle | |
91 | + stim::vec3<T> d0, d1; | |
92 | + for (size_t i = 0; i < size() - 1; i++) { //for each line segment in the centerline | |
93 | + c.rotate(d(i)); //rotate the circle to match that normal | |
94 | + U[i] = c.U; //save the U vector from the circle | |
95 | + } | |
96 | + U[size() - 1] = c.U; //for the last point, duplicate the final frenet frame vector | |
97 | + } | |
98 | + | |
97 | 99 | ///adds a magnitude to each point in the cylinder |
98 | 100 | /*void add_mag(V val = 0) { |
99 | 101 | if (M.size() == 0) M.resize(size()); //if the magnitude vector isn't initialized, resize it to match the centerline | ... | ... |