Commit eb554b481084fad3ec082244497228b47872e9bb

Authored by David Mayerich
1 parent e21d1051

bug fixes for NetMets

stim/biomodels/centerline.h
... ... @@ -190,7 +190,7 @@ public:
190 190 stim::vec3<T> p; //- intermediate point to be added
191 191 stim::vec3<T> p1; // p1 - starting point of an segment on the fiber,
192 192 stim::vec3<T> p2; // p2 - ending point,
193   - double sum=0; //distance summation
  193 + //double sum=0; //distance summation
194 194  
195 195 size_t N = size();
196 196  
... ...
stim/biomodels/network.h
... ... @@ -33,16 +33,15 @@ class network{
33 33 public:
34 34 unsigned v[2]; //unique id's designating the starting and ending
35 35 // default constructor
36   - edge() : cylinder<T>()
37   - {
  36 + edge() : cylinder<T>() {
38 37 v[1] = (unsigned)(-1); v[0] = (unsigned)(-1);
39 38 }
40 39 /// Constructor - creates an edge from a list of points by calling the stim::fiber constructor
41 40  
42 41 ///@param p is an array of positions in space
43   - edge(std::vector< stim::vec3<T> > p) : cylinder<T>(p){}
  42 + edge(centerline p) : cylinder<T>(p){}
44 43  
45   - /// Copy constructor creates an edge from a fiber
  44 + /// Copy constructor creates an edge from a cylinder
46 45 edge(stim::cylinder<T> f) : cylinder<T>(f) {}
47 46  
48 47 /// Resamples an edge by calling the fiber resampling function
... ... @@ -291,7 +290,7 @@ public:
291 290 std::vector< stim::vec<T> > c; //allocate an array of points for the vessel centerline
292 291 O.getLine(l, c); //get the fiber centerline
293 292  
294   - std::vector< stim::vec3<T> > c3(c.size());
  293 + stim::centerline<T> c3(c.size());
295 294 for(size_t j = 0; j < c.size(); j++)
296 295 c3[j] = c[j];
297 296  
... ... @@ -431,7 +430,7 @@ public:
431 430  
432 431 /// @param A is the network to compare to - the field is generated for A
433 432 /// @param sigma is the user-defined tolerance value - smaller values provide a stricter comparison
434   - stim::network<T> compare(stim::network<T> A, float sigma, int device){
  433 + stim::network<T> compare(stim::network<T> A, float sigma, int device = -1){
435 434  
436 435 stim::network<T> R; //generate a network storing the result of the comparison
437 436 R = (*this); //initialize the result with the current network
... ... @@ -471,6 +470,7 @@ public:
471 470 T* queryPt = new T[3];
472 471 for(unsigned e = 0; e < R.E.size(); e++){ //for each edge in A
473 472 R.E[e].add_mag(0); //add a new magnitude for the metric
  473 + size_t errormag_id = R.E[e].nmags() - 1; //get the id for the new magnitude
474 474  
475 475 for(unsigned p = 0; p < R.E[e].size(); p++){ //for each point in the edge
476 476  
... ... @@ -479,7 +479,7 @@ public:
479 479 kdt.search(queryPt, 1, nnIdx, dists); //find the distance between A and the current network
480 480  
481 481 m1 = 1.0f - gaussianFunction((T)dists[0], sigma); //calculate the metric value based on the distance
482   - R.E[e].set_mag(m1, p, 1); //set the error for the second point in the segment
  482 + R.E[e].set_mag(errormag_id, p, m1); //set the error for the second point in the segment
483 483  
484 484 }
485 485 }
... ...
stim/visualization/cylinder.h
... ... @@ -11,19 +11,10 @@ namespace stim
11 11 template<typename T>
12 12 class cylinder : public centerline<T> {
13 13 protected:
14   - //stim::circle<T> s; //an arbitrary circle
15   - //std::vector<stim::circle<T> > e; //an array of circles that store the centerline
16 14  
17   - //std::vector<stim::vec3<T> > norms;
18 15 std::vector< stim::vec3<T> > U; //stores the array of U vectors defining the Frenet frame
19 16 std::vector< std::vector<T> > M; //stores a list of magnitudes for each point in the centerline (assuming mags[0] is the radius)
20   - //std::vector< T > L; //length of the cylinder at each position (pre-integration)
21 17  
22   -
23   - //using stim::centerline<T>::c;
24   - //using stim::centerline<T>::N;
25   - using stim::centerline<T>::size;
26   - using stim::centerline<T>::at;
27 18 using stim::centerline<T>::findIdx;
28 19  
29 20 //calculates the U values for each point to initialize the frenet frame
... ... @@ -40,33 +31,18 @@ protected:
40 31 U[size() - 1] = c.U; //for the last point, duplicate the final frenet frame vector
41 32 }
42 33  
43   - ///adds a magnitude to each point in the cylinder
44   - void add_mag(T val = 0) {
45   - if (M.size() == 0) M.resize(size()); //if the magnitude vector isn't initialized, resize it to match the centerline
46   - for (size_t i = 0; i < size(); i++) //for each point
47   - M[i].push_back(val); //add this value to the magnitude vector at each point
48   - }
49   -
50   - //adds a magnitude based on a list of magnitudes for each point
51   - void add_mag(std::vector<T> val) {
52   - if (M.size() == 0) M.resize(size()); //if the magnitude vector isn't initialized, resize it to match the centerline
53   - for (size_t i = 0; i < size(); i++) //for each point
54   - M[i].push_back(val[i]); //add this value to the magnitude vector at each point
55   - }
56   -
57 34 public:
58   - std::string str() {
59   - std::stringstream ss;
60   - size_t N = std::vector< stim::vec3<T> >::size();
61   - ss << "---------[" << N << "]---------" << std::endl;
62   - for (size_t i = 0; i < N; i++)
63   - ss << std::vector< stim::vec3<T> >::at(i) << " r = "<< M[i][0]<<" u = "<<U[i]<<std::endl;
64   - ss << "--------------------" << std::endl;
65 35  
66   - return ss.str();
  36 + using stim::centerline<T>::size;
  37 + using stim::centerline<T>::at;
  38 +
  39 + cylinder() : centerline(){}
  40 +
  41 + cylinder(centerline& c) : centerline(c) {
  42 + init();
67 43 }
68 44  
69   - cylinder(centerline& c, T r = 0) : centerline(c) {
  45 + cylinder(centerline& c, T r) : centerline(c) {
70 46 init();
71 47 add_mag(r);
72 48 }
... ... @@ -81,7 +57,7 @@ public:
81 57 ///Interpolates the position along the line.
82 58 ///@param l: the location of the in the cylinder.
83 59 ///@param idx: integer location of the point closest to l but prior to it.
84   - T m(T l, int idx, size_t i = 0) {
  60 + T m(T l, int idx, size_t i) {
85 61 T a = (l - L[idx]) / (L[idx + 1] - L[idx]);
86 62 T v2 = (M[idx][i] + (M[idx + 1][i] - M[idx][i])*a);
87 63  
... ... @@ -100,6 +76,37 @@ public:
100 76 return m(l, idx, i);
101 77 }
102 78  
  79 + /// Returns the magnitude at the given index
  80 + /// @param i is the index of the desired point
  81 + /// @param m is the index of the magnitude value
  82 + T m(unsigned i, unsigned m) {
  83 + return M[i][m];
  84 + }
  85 +
  86 + ///adds a magnitude to each point in the cylinder
  87 + void add_mag(T val = 0) {
  88 + if (M.size() == 0) M.resize(size()); //if the magnitude vector isn't initialized, resize it to match the centerline
  89 + for (size_t i = 0; i < size(); i++) //for each point
  90 + M[i].push_back(val); //add this value to the magnitude vector at each point
  91 + }
  92 +
  93 + //adds a magnitude based on a list of magnitudes for each point
  94 + void add_mag(std::vector<T> val) {
  95 + if (M.size() == 0) M.resize(size()); //if the magnitude vector isn't initialized, resize it to match the centerline
  96 + for (size_t i = 0; i < size(); i++) //for each point
  97 + M[i].push_back(val[i]); //add this value to the magnitude vector at each point
  98 + }
  99 +
  100 + //sets the value of magnitude m at point i
  101 + void set_mag(size_t m, size_t i, T v) {
  102 + M[i][m] = v;
  103 + }
  104 +
  105 + size_t nmags() {
  106 + if (M.size() == 0) return 0;
  107 + else return M[0].size();
  108 + }
  109 +
103 110 ///Returns a circle representing the cylinder cross section at point i
104 111 stim::circle<T> circ(size_t i, size_t m = 0) {
105 112 return stim::circle<T>(at(i), M[i][m], d(i), U[i]);
... ... @@ -153,6 +160,61 @@ public:
153 160 return out;
154 161 }
155 162  
  163 + std::string str() {
  164 + std::stringstream ss;
  165 + size_t N = std::vector< stim::vec3<T> >::size();
  166 + ss << "---------[" << N << "]---------" << std::endl;
  167 + for (size_t i = 0; i < N; i++)
  168 + ss << std::vector< stim::vec3<T> >::at(i) << " r = " << M[i][0] << " u = " << U[i] << std::endl;
  169 + ss << "--------------------" << std::endl;
  170 +
  171 + return ss.str();
  172 + }
  173 +
  174 + /// Integrates a magnitude value along the cylinder.
  175 + /// @param m is the magnitude value to be integrated (this is usually the radius)
  176 + T integrate(size_t m = 0) {
  177 +
  178 + T sum = 0; //initialize the integral to zero
  179 + T m0, m1; //allocate space for both magnitudes in a single segment
  180 + m0 = M[0][m]; //initialize the first point and magnitude to the first point in the cylinder
  181 + T len = L[0]; //allocate space for the segment length
  182 +
  183 +
  184 + for (unsigned p = 1; p < size(); p++) { //for every consecutive point in the cylinder
  185 + m1 = M[p][m];
  186 + if (p > 1) len = (L[p - 1] - L[p - 2]); //calculate the segment length using the L array
  187 + sum += (m0 + m1) / (T)2.0 * len; //add the average magnitude, weighted by the segment length
  188 + m0 = m1; //move to the next segment by shifting points
  189 + }
  190 + return sum; //return the integral
  191 + }
  192 +
  193 + /// Resamples the cylinder to provide a maximum distance of "spacing" between centerline points. All current
  194 + /// centerline points are guaranteed to exist in the new cylinder
  195 + /// @param spacing is the maximum spacing allowed between sample points
  196 + cylinder<T> resample(T spacing) {
  197 + cylinder<T> c = stim::centerline<T>::resample(spacing); //resample the centerline and use it to create a new cylinder
  198 +
  199 + size_t nm = nmags(); //get the number of magnitude values in the current cylinder
  200 + if (nm > 0) { //if there are magnitude values
  201 + std::vector<T> magvec(nm, 0); //create a magnitude vector for a single point
  202 + c.M.resize(c.size(), magvec); //allocate space for a magnitude vector at each point of the new cylinder
  203 + }
  204 +
  205 + T l, t;
  206 + for (size_t i = 0; i < c.size(); i++) { //for each point in the new cylinder
  207 + l = c.L[i]; //get the length along the new cylinder
  208 + t = l / length(); //calculate the parameter value along the new cylinder
  209 + for (size_t mag = 0; mag < nm; mag++) { //for each magnitude value
  210 + c.M[i][mag] = m(t, mag); //retrieve the interpolated magnitude from the current cylinder and store it in the new one
  211 + }
  212 + }
  213 +
  214 +
  215 + return c;
  216 + }
  217 +
156 218  
157 219 /*
158 220 ///inits the cylinder from a list of points (std::vector of stim::vec3 --inP) and magnitudes (inM)
... ...
stim/visualization/gl_network.h
... ... @@ -55,7 +55,7 @@ public:
55 55 glBegin(GL_LINE_STRIP);
56 56 for(unsigned p = 0; p < E[e].size(); p++){ //for each point on that edge
57 57 glVertex3f(E[e][p][0], E[e][p][1], E[e][p][2]); //set the vertex position based on the current point
58   - glTexCoord1f(E[e].ri(p, m)); //set the texture coordinate based on the specified magnitude index
  58 + glTexCoord1f(E[e].m(p, m)); //set the texture coordinate based on the specified magnitude index
59 59 }
60 60 glEnd();
61 61 }
... ...