Commit fe0c75394f642a4e30cea5981c5f9e82206cbe8e
1 parent
b3a38641
added functions to find average segment length, tortuoisity in a network
Showing
1 changed file
with
67 additions
and
0 deletions
Show diff stats
stim/biomodels/network.h
@@ -90,6 +90,7 @@ class network{ | @@ -90,6 +90,7 @@ class network{ | ||
90 | return ss.str(); | 90 | return ss.str(); |
91 | } | 91 | } |
92 | 92 | ||
93 | + | ||
93 | }; | 94 | }; |
94 | 95 | ||
95 | protected: | 96 | protected: |
@@ -109,6 +110,72 @@ public: | @@ -109,6 +110,72 @@ public: | ||
109 | return V.size(); | 110 | return V.size(); |
110 | } | 111 | } |
111 | 112 | ||
113 | + std::vector<vertex> operator*(T s){ | ||
114 | + for (unsigned i=0; i< vertices; i ++ ){ | ||
115 | + V[i] = V[i] * s; | ||
116 | + } | ||
117 | + return V; | ||
118 | + } | ||
119 | + | ||
120 | + std::vector<vertex> operator*(vec<T> s){ | ||
121 | + for (unsigned i=0; i< vertices; i ++ ){ | ||
122 | + for (unsigned dim = 0 ; dim< 3; dim ++){ | ||
123 | + V[i][dim] = V[i][dim] * s[dim]; | ||
124 | + } | ||
125 | + } | ||
126 | + return V; | ||
127 | + } | ||
128 | + | ||
129 | + // Returns an average of fiber/edge lengths in the network | ||
130 | + double Lengths(){ | ||
131 | + stim::vec<T> L;double sumLength = 0; | ||
132 | + for(unsigned e = 0; e < E.size(); e++){ //for each edge in the network | ||
133 | + L.push_back(E[e].length()); //append the edge length | ||
134 | + sumLength = sumLength + E[e].length(); | ||
135 | + } | ||
136 | + double avg = sumLength / E.size(); | ||
137 | + return avg; | ||
138 | + } | ||
139 | + | ||
140 | + | ||
141 | + // Returns an average of tortuosities in the network | ||
142 | + double Tortuosities(){ | ||
143 | + stim::vec<T> t; | ||
144 | + stim::vec<T> id1, id2; // starting and ending vertices of the edge | ||
145 | + //std::vector< stim::vec<T> > vert; // list of visited vertices | ||
146 | + //std::vector<stim::vec<T>>::iterator it; //create an iterator for searching the id2vert array | ||
147 | + //std::vector<unsigned> daughters; // to count number of daughter vessels at branch points | ||
148 | + //stim::vec<T> visitedVert; | ||
149 | + //unsigned visited; | ||
150 | + double distance;double tortuosity;double sumTortuosity = 0; | ||
151 | + for(unsigned e = 0; e < E.size(); e++){ //for each edge in the network | ||
152 | + id1 = E[e][0]; //get the edge starting point | ||
153 | + id2 = E[e][E[e].size() - 1]; //get the edge ending point | ||
154 | + distance = (id1 - id2).len(); //displacement between the starting and ending points | ||
155 | + //it = find(vert.begin(), vert.end(), id1); //look for the first node has a daughter vessel already | ||
156 | + //visitedVert = std::distance(vert.begin(), it); //index where it already exists | ||
157 | + //if(visitedVert == id1){ | ||
158 | + // visited += 1; | ||
159 | + // daughters[e] = visited; | ||
160 | + //} | ||
161 | + //else{ | ||
162 | + // vert.push_back(id1); | ||
163 | + // daughters[e] = 1; | ||
164 | + //} | ||
165 | + if(distance > 0){ | ||
166 | + tortuosity = E[e].length()/ distance ; // tortuoisty = edge length / edge displacement | ||
167 | + } | ||
168 | + else{ | ||
169 | + tortuosity = 0;} | ||
170 | + t.push_back(tortuosity); | ||
171 | + sumTortuosity += tortuosity; | ||
172 | + } | ||
173 | + double avg = sumTortuosity / E.size(); | ||
174 | + //std::cout<<"number of unique branch points"<<daughters.size()<<std::endl; | ||
175 | + return avg; | ||
176 | + } | ||
177 | + | ||
178 | + | ||
112 | stim::cylinder<T> get_cylinder(unsigned f){ | 179 | stim::cylinder<T> get_cylinder(unsigned f){ |
113 | return E[f]; //return the specified edge (casting it to a fiber) | 180 | return E[f]; //return the specified edge (casting it to a fiber) |
114 | } | 181 | } |