Commit c6ad70041620feffb162ac232501904e2f6d023a

Authored by David Mayerich
2 parents 9bef85ea 49061f1d

Merge branch 'master' of git.stim.ee.uh.edu:codebase/stimlib

stim/biomodels/centerline.h
... ... @@ -31,6 +31,7 @@ protected:
31 31 vec3<T> ab = a.norm() + b.norm();
32 32 return ab.norm();
33 33 }
  34 +
34 35 //initializes the integrated length vector to make parameterization easier, starting with index idx (all previous indices are assumed to be correct)
35 36 void update_L(size_t start = 0) {
36 37 L.resize(size()); //allocate space for the L array
... ... @@ -107,7 +108,12 @@ public:
107 108 centerline(size_t n) : std::vector< stim::vec3<T> >(n){
108 109 init();
109 110 }
110   -
  111 + centerline(std::vector<stim::vec3<T> > pos) :
  112 + std::vector<stim::vec3<T> > (pos)
  113 + {
  114 + init();
  115 + }
  116 +
111 117 //overload the push_back function to update the length vector
112 118 void push_back(stim::vec3<T> p) {
113 119 std::vector< stim::vec3<T> >::push_back(p);
... ... @@ -135,6 +141,7 @@ public:
135 141 return L.back();
136 142 }
137 143  
  144 +
138 145 /// stitch two centerlines
139 146 ///@param c1, c2: two centerlines
140 147 ///@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>() {
... ... @@ -78,6 +79,10 @@ class network{
78 79  
79 80 }
80 81 */
  82 + edge(std::vector<stim::vec3<T> p, std::vector<T> s)
  83 + : cylinder<T>(p,s)
  84 + {
  85 + }
81 86 ///@param p is an array of positions in space
82 87 edge(stim::centerline<T> p) : cylinder<T>(p){}
83 88  
... ... @@ -127,7 +132,7 @@ class network{
127 132 // for(int j = 0; j < nmags(); j++) //future code for multiple mags
128 133 // {
129 134 out.write(reinterpret_cast<const char*>(&e.R[i]), sizeof(T)); ///write the radius
130   - std::cout << point.str() << " " << e.R[i] << std::endl;
  135 + //std::cout << point.str() << " " << e.R[i] << std::endl;
131 136 // }
132 137 }
133 138 return out; //return stream
... ... @@ -140,22 +145,25 @@ class network{
140 145 in.read(reinterpret_cast<char*>(&v0), sizeof(unsigned int)); //read the staring point.
141 146 in.read(reinterpret_cast<char*>(&v1), sizeof(unsigned int)); //read the ending point
142 147 in.read(reinterpret_cast<char*>(&sz), sizeof(unsigned int)); //read the number of points in the edge
143   - stim::centerline<T> temp = stim::centerline<T>(sz); //allocate the new edge
144   - e = edge(temp);
145   - e.v[0] = v0; e.v[1] = v1;
  148 +// stim::centerline<T> temp = stim::centerline<T>(sz); //allocate the new edge
  149 +// e = edge(temp);
  150 + std::vector<stim::vec3<T> > p(sz);
  151 + std::vector<T> r(sz);
146 152 for(int i = 0; i < sz; i++) //set the points and radii to the newly read values
147 153 {
148 154 stim::vec3<T> point;
149 155 in.read(reinterpret_cast<char*>(&point[0]), 3*sizeof(T));
150   - e[i] = point;
  156 + p[i] = point;
151 157 T mag;
152 158 // for(int j = 0; j < nmags(); j++) ///future code for mags
153 159 // {
154 160 in.read(reinterpret_cast<char*>(&mag), sizeof(T));
155   - e.set_r(0, mag);
156   - std::cout << point.str() << " " << mag << std::endl;
  161 + r[i] = mag;
  162 + //std::cout << point.str() << " " << mag << std::endl;
157 163 // }
158 164 }
  165 + e = edge(p,r);
  166 + e.v[0] = v0; e.v[1] = v1;
159 167 return in;
160 168 }
161 169 };
... ... @@ -193,21 +201,23 @@ class network{
193 201  
194 202 return ss.str();
195 203 }
196   - ///operator for writing the edge into the stream;
  204 + ///operator for writing the vector into the stream;
197 205 friend std::ofstream& operator<<(std::ofstream& out, const vertex& v)
198 206 {
199 207 unsigned int s0, s1;
200 208 s0 = v.e[0].size();
201 209 s1 = v.e[1].size();
202 210 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"
  211 + out.write(reinterpret_cast<const char*>(&s0), sizeof(unsigned int)); ///write the number of "outgoing edges"
  212 + out.write(reinterpret_cast<const char*>(&s1), sizeof(unsigned int)); ///write the number of "incoming edges"
  213 + if (s0 != 0)
  214 + out.write(reinterpret_cast<const char*>(&v.e[0][0]), sizeof(unsigned int)*v.e[0].size()); ///write the "outgoing edges"
  215 + if (s1 != 0)
  216 + out.write(reinterpret_cast<const char*>(&v.e[1][0]), sizeof(unsigned int)*v.e[1].size()); ///write the "incoming edges"
207 217 return out;
208 218 }
209 219  
210   - ///operator for reading the edge out of the stream;
  220 + ///operator for reading the vector out of the stream;
211 221 friend std::ifstream& operator>>(std::ifstream& in, vertex& v)
212 222 {
213 223 in.read(reinterpret_cast<char*>(&v[0]), 3*sizeof(T)); ///read the physical position
... ... @@ -218,8 +228,10 @@ class network{
218 228 std::vector<unsigned int> two(s[1]);
219 229 v.e[0] = one;
220 230 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"
  231 + if (one.size() != 0)
  232 + in.read(reinterpret_cast<char*>(&v.e[0][0]), s[0] * sizeof(unsigned int)); ///read the arrays of "outgoing edges"
  233 + if (two.size() != 0)
  234 + in.read(reinterpret_cast<char*>(&v.e[1][0]), s[1] * sizeof(unsigned int)); ///read the arrays of "incoming edges"
223 235 return in;
224 236 }
225 237  
... ... @@ -501,10 +513,24 @@ public:
501 513 it = find(id2vert.begin(), id2vert.end(), i[0]); //look for the first node
502 514 if(it == id2vert.end()){ //if i[0] hasn't already been used
503 515 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
  516 + bool flag = false;
  517 + unsigned j = 0;
  518 + for (; j < V.size(); j++) { // check whether current vertex is already exist
  519 + if (new_vertex == V[j]) {
  520 + flag = true;
  521 + break;
  522 + }
  523 + }
  524 + if (!flag) { // unique one
  525 + new_vertex.e[0].push_back(E.size()); //add the current edge as outgoing
  526 + new_edge.v[0] = V.size(); //add the new edge to the edge
  527 + V.push_back(new_vertex); //add the new vertex to the vertex list
  528 + id2vert.push_back(i[0]); //add the ID to the ID->vertex conversion list
  529 + }
  530 + else {
  531 + V[j].e[0].push_back(E.size());
  532 + new_edge.v[0] = j;
  533 + }
508 534 }
509 535 else{ //if the vertex already exists
510 536 it_idx = std::distance(id2vert.begin(), it);
... ... @@ -515,10 +541,24 @@ public:
515 541 it = find(id2vert.begin(), id2vert.end(), i[1]); //look for the second ID
516 542 if(it == id2vert.end()){ //if i[1] hasn't already been used
517 543 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
  544 + bool flag = false;
  545 + unsigned j = 0;
  546 + for (; j < V.size(); j++) { // check whether current vertex is already exist
  547 + if (new_vertex == V[j]) {
  548 + flag = true;
  549 + break;
  550 + }
  551 + }
  552 + if (!flag) {
  553 + new_vertex.e[1].push_back(E.size()); //add the current edge as incoming
  554 + new_edge.v[1] = V.size(); //add the new vertex to the edge
  555 + V.push_back(new_vertex); //add the new vertex to the vertex list
  556 + id2vert.push_back(i[1]); //add the ID to the ID->vertex conversion list
  557 + }
  558 + else {
  559 + V[j].e[1].push_back(E.size());
  560 + new_edge.v[1] = j;
  561 + }
522 562 }
523 563 else{ //if the vertex already exists
524 564 it_idx = std::distance(id2vert.begin(), it);
... ... @@ -529,6 +569,27 @@ public:
529 569 E.push_back(new_edge); //push the edge to the list
530 570  
531 571 }
  572 +
  573 + // copy the radii information from OBJ
  574 + /*if (O.numVT()) {
  575 + unsigned k = 0;
  576 + for (unsigned i = 0; i < E.size(); i++) {
  577 + for (unsigned j = 0; j < E[i].size(); j++) {
  578 + E[i].cylinder<T>::set_r(j, O.getVT(k)[0] / 2);
  579 + k++;
  580 + }
  581 + }
  582 + }*/
  583 + // OBJ class assumes that in L the two values are equal
  584 + if (O.numVT()) {
  585 + std::vector< unsigned > id; //create an array to store the centerline point IDs
  586 + for (unsigned i = 0; i < O.numL(); i++) {
  587 + id.clear();
  588 + O.getLinei(i + 1, id); //get the list of point IDs for the line
  589 + for (unsigned j = 0; j < id.size(); j++)
  590 + E[i].cylinder<T>::set_r(j, O.getVT(id[j] - 1)[0] / 2);
  591 + }
  592 + }
532 593 }
533 594  
534 595 ///loads a .nwt file. Reads the header and loads the data into the network according to the header.
... ... @@ -554,7 +615,7 @@ public:
554 615 edge e;
555 616 file >> e;
556 617 E.push_back(e);
557   - std::cout << i << " " << E[i].str() << std::endl;
  618 + //std::cout << i << " " << E[i].str() << std::endl; // not necessary?
558 619 }
559 620 file.close();
560 621 }
... ... @@ -573,7 +634,7 @@ public:
573 634 }
574 635 for(int i = 0; i < E.size(); i++) ///loop through the Edges and write each one.
575 636 {
576   - std::cout << i << " " << E[i].str() << std::endl;
  637 + //std::cout << i << " " << E[i].str() << std::endl; // not necesarry?
577 638 file << E[i];
578 639 }
579 640 file.close();
... ...
stim/parser/table.h
1 1 #ifndef STIM_CSV_H
2 2 #define STIM_CSV_H
3 3  
  4 +#include <type_traits>
4 5 #include <vector>
5 6 #include <sstream>
6 7 #include <fstream>
... ... @@ -105,4 +106,4 @@ namespace stim{
105 106 };
106 107  
107 108  
108   -#endif
109 109 \ No newline at end of file
  110 +#endif
... ...
stim/visualization/cylinder.h
... ... @@ -18,13 +18,12 @@ protected:
18 18 std::vector< T > R; //stores a list of magnitudes for each point in the centerline (assuming mags[0] is the radius)
19 19  
20 20 using stim::centerline<T>::findIdx;
21   -
22   - //calculates the U values for each point to initialize the frenet frame
23   - // this function assumes that the centerline has already been set
  21 +
24 22 void init() {
25   - U.resize(size()); //allocate space for the frenet frame vectors
  23 + U.resize(size()); //allocate space for the frenet frame vectors
  24 +// if (R.size() != 0)
26 25 R.resize(size());
27   -
  26 +
28 27 stim::circle<T> c; //create a circle
29 28 stim::vec3<T> d0, d1;
30 29 for (size_t i = 0; i < size() - 1; i++) { //for each line segment in the centerline
... ... @@ -33,6 +32,9 @@ protected:
33 32 }
34 33 U[size() - 1] = c.U; //for the last point, duplicate the final frenet frame vector
35 34 }
  35 +
  36 + //calculates the U values for each point to initialize the frenet frame
  37 + // this function assumes that the centerline has already been set
36 38  
37 39 public:
38 40  
... ... @@ -46,6 +48,19 @@ public:
46 48 cylinder(centerline<T>c) : centerline<T>(c) {
47 49 init();
48 50 }
  51 +
  52 + cylinder(std::vector<stim::vec3<T> > p, std::vector<T> s)
  53 + : centerline<T>(p)
  54 + {
  55 + R = s;
  56 + init();
  57 + {
  58 +
  59 + cylinder(stim::centerline<T> p, std::vector<T> s)
  60 + {
  61 + d = s;
  62 + init();
  63 + {
49 64  
50 65 //cylinder(centerline<T>c, T r) : centerline(c) {
51 66 // init();
... ... @@ -94,6 +109,7 @@ public:
94 109 return R[i];
95 110 }
96 111  
  112 +
97 113 ///adds a magnitude to each point in the cylinder
98 114 /*void add_mag(V val = 0) {
99 115 if (M.size() == 0) M.resize(size()); //if the magnitude vector isn't initialized, resize it to match the centerline
... ...