Commit b50c840e50d9cb72e96f07010f3d5ab49e52c0cf

Authored by David Mayerich
1 parent a9ed210f

eliminated ANN from centerline

stim/biomodels/centerline.h
... ... @@ -3,7 +3,7 @@
3 3  
4 4 #include <vector>
5 5 #include <stim/math/vec3.h>
6   -#include <ANN/ANN.h>
  6 +//#include <ANN/ANN.h>
7 7  
8 8 namespace stim{
9 9  
... ... @@ -17,14 +17,14 @@ class centerline{
17 17 protected:
18 18 unsigned int N; //number of points in the fiber
19 19 double **c; //centerline (array of double pointers)
20   - ANNkd_tree* kdt; //kd-tree stores all points in the fiber for fast searching
  20 +// ANNkd_tree* kdt; //kd-tree stores all points in the fiber for fast searching
21 21  
22 22 /// Initialize an empty fiber
23 23 void init()
24 24 {
25 25 N=0;
26 26 c=NULL;
27   - kdt = NULL;
  27 +// kdt = NULL;
28 28 }
29 29  
30 30 /// Initialize a fiber with N centerline points (all located at [0, 0, 0] with radius 0)
... ... @@ -32,7 +32,7 @@ protected:
32 32 {
33 33  
34 34 N = n; //set the number of points
35   - kdt = NULL;
  35 +// kdt = NULL;
36 36 c = (double**) malloc(sizeof(double*) * N); //allocate the array pointer
37 37  
38 38 for(unsigned int i = 0; i < N; i++) //allocate space for each point
... ... @@ -52,17 +52,17 @@ protected:
52 52 for(unsigned int d = 0; d < 3; d++) //for each dimension
53 53 c[i][d] = cpy.c[i][d]; //copy the coordinate
54 54 }
55   - if(kd)
56   - gen_kdtree(); //generate the kd tree for the new fiber
  55 +// if(kd)
  56 +// gen_kdtree(); //generate the kd tree for the new fiber
57 57 }
58 58  
59 59 /// generate a KD tree for points on fiber
60   - void gen_kdtree()
61   - {
62   - int n_data = N; //create an array of data points
63   - ANNpointArray pts = (ANNpointArray)c; //cast the centerline list to an ANNpointArray
64   - kdt = new ANNkd_tree(pts, n_data, 3); //build a KD tree
65   - }
  60 +// void gen_kdtree()
  61 +// {
  62 +// int n_data = N; //create an array of data points
  63 +// ANNpointArray pts = (ANNpointArray)c; //cast the centerline list to an ANNpointArray
  64 +// kdt = new ANNkd_tree(pts, n_data, 3); //build a KD tree
  65 +// }
66 66  
67 67 /// find distance between two points
68 68 double dist(double* p0, double* p1){
... ... @@ -80,12 +80,12 @@ protected:
80 80 /// This function retreives the index for the fiber point closest to q
81 81  
82 82 /// @param q is a reference point used to find the closest point on the fiber center line
83   - unsigned int ann( stim::vec<double> q ){
84   - ANNidxArray idx = new ANNidx[1]; //variable used to hold the nearest point
85   - ANNdistArray sq_dist = new ANNdist[1]; //variable used to hold the squared distance to the nearest point
86   - kdt->annkSearch(q.data(), 1, idx, sq_dist); //search the KD tree for the nearest neighbor
87   - return *idx;
88   - }
  83 +// unsigned int ann( stim::vec<double> q ){
  84 +// ANNidxArray idx = new ANNidx[1]; //variable used to hold the nearest point
  85 +// ANNdistArray sq_dist = new ANNdist[1]; //variable used to hold the squared distance to the nearest point
  86 +// kdt->annkSearch(q.data(), 1, idx, sq_dist); //search the KD tree for the nearest neighbor
  87 +// return *idx;
  88 +// }
89 89  
90 90 /// Returns a stim::vec representing the point at index i
91 91  
... ... @@ -132,8 +132,8 @@ public:
132 132 //set the radius
133 133 }
134 134 //generate a kd tree
135   - if(kd)
136   - gen_kdtree();
  135 +// if(kd)
  136 +// gen_kdtree();
137 137 }
138 138  
139 139 /// constructor takes a list of points
... ... @@ -149,8 +149,8 @@ public:
149 149 }
150 150  
151 151 //generate a kd tree
152   - if(kd)
153   - gen_kdtree();
  152 + //if(kd)
  153 + // gen_kdtree();
154 154 }
155 155  
156 156 /// Assignment operation
... ...
stim/gl/gl_spider.h
... ... @@ -23,6 +23,7 @@
23 23 #include <stim/cuda/ivote.cuh>
24 24 #include <stim/visualization/glObj.h>
25 25 #include <vector>
  26 +#include <stack>
26 27 #include <stim/cuda/branch_detection.cuh>
27 28 #include "../../../volume-spider/glnetwork.h"
28 29 #include <stim/visualization/cylinder.h>
... ... @@ -187,10 +188,8 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
187 188 #endif
188 189  
189 190 #ifdef TESTING
190   -// test(ptexbufferID, GL_TEXTURE_2D,2*t_length, numSamplesPos*t_length, "Final_Cost_Position.bmp");
191 191 #endif
192 192 int best = getCost(t_pos.getTexture(), t_pos.getAuxArray(), numSamplesPos); //find min cost.
193   -// std::cerr << best << std::endl;
194 193 stim::vec<float> next( //find next position.
195 194 pV[best][0],
196 195 pV[best][1],
... ... @@ -206,7 +205,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
206 205  
207 206 /// Method for finding the best scale for the spider.
208 207 /// changes the x, y, z size of the spider to minimize the cost
209   - /// function. */
  208 + /// function.
210 209 void
211 210 findOptimalScale()
212 211 {
... ... @@ -216,12 +215,10 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
216 215 setMatrix(); //create the transformation.
217 216 glCallList(dList+2); //move the templates to p, d, m.
218 217 glFinish();
219   -// glFlush();
220 218 #ifdef TIMING
221 219 size_time += gpuStopTimer();
222 220 #endif
223 221 #ifdef TESTING
224   -// test(mtexbufferID, GL_TEXTURE_2D, 2*t_length, numSamplesMag*t_length, "Final_Cost_Position.bmp");
225 222 #endif
226 223 int best = getCost(t_mag.getTexture(), t_mag.getAuxArray(), numSamplesMag); //get best cost.
227 224 setMagnitude(m[0]*mV[best][0]); //adjust the magnitude.
... ... @@ -270,7 +267,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
270 267 stim::vec3<float> di = cyl.p(pval);
271 268 float rad = cyl.r(pval);
272 269  
273   - std::cout << v << " " << di << " " << rad << std::endl;
  270 + std::cout << v.str() << " " << di.str() << " " << rad << std::endl;
274 271 if(
275 272 !(v[0] > size[0] || v[1] > size[1]
276 273 || v[2] > size[2] || v[0] < 0
... ... @@ -350,7 +347,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
350 347 for(int i = 0; i < numSamples; i++)
351 348 {
352 349 z = uniformRandom()*range + Z[1];
353   - theta = uniformRandom()*2*M_PI;
  350 + theta = uniformRandom()*stim::TAU;
354 351 phi = acos(z);
355 352 stim::vec3<float> sph(1, theta, phi);
356 353 stim::vec3<float> cart = sph.sph2cart();
... ... @@ -620,7 +617,6 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
620 617 //get and store the current transformation matrix for later use.
621 618 glGetFloatv(GL_TEXTURE_MATRIX, curTrans);
622 619 cT.set(curTrans);
623   - // printTransform();
624 620  
625 621 CHECK_OPENGL_ERROR
626 622 //revert back to default gl mode.
... ... @@ -751,21 +747,6 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
751 747 return cost[0];
752 748 }
753 749  
754   -// int
755   -// getCost(GLuint tID, int n)
756   -// {
757   -// #ifdef TIMING
758   -// gpuStartTimer();
759   -// #endif
760   -// stim::vec<int> cost =
761   -// stim::cuda::get_cost(tID, GL_TEXTURE_2D, n, 2*t_length, t_length);
762   -// #ifdef TIMING
763   -// cost_time += gpuStopTimer();
764   -// #endif
765   -// current_cost = cost[1];
766   -// return cost[0];
767   -// }
768   -
769 750 int
770 751 getCost(cudaTextureObject_t tObj, float* result, int n)
771 752 {
... ... @@ -817,9 +798,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
817 798 m = stim::vec<float>(1.0, 1.0);
818 799 S = stim::vec3<float>(1.0, 1.0, 1.0);
819 800 R = stim::vec3<float>(1.0, 1.0, 1.0);
820   -// std::cout << samples << std::endl;
821 801 numSamples = samples;
822   -// std::cout << numSamples << std::endl;
823 802 numSamplesPos = samplespos;
824 803 numSamplesMag = samplesmag;
825 804 }
... ... @@ -901,7 +880,6 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
901 880  
902 881 srand(100);
903 882 texID = id;
904   - //GenerateFBO(16, numSamples*8);
905 883 GenerateFBO(t_length*2, numSamples*t_length, texbufferID, fboID);
906 884 std::cout << numSamples << std::endl;
907 885 CHECK_OPENGL_ERROR
... ... @@ -919,13 +897,11 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
919 897 t_pos.Alloc(numSamplesPos);
920 898 t_mag.MapCudaTexture(mtexbufferID, GL_TEXTURE_2D);
921 899 t_mag.Alloc(numSamplesMag);
922   -// setDims(0.6, 0.6, 1.0);
923   -// setSize(1024.0, 1024.0, 1024.0);
924 900 setMatrix();
925 901 dList = glGenLists(3);
926 902 glListBase(dList);
927 903 Bind(texbufferID, fboID, numSamples, t_length);
928   - genDirectionVectors(5*M_PI/4);
  904 + genDirectionVectors(5*stim::PI/4);
929 905 Unbind();
930 906 Bind(ptexbufferID, pfboID, numSamplesPos, t_length);
931 907 genPositionVectors();
... ... @@ -1069,7 +1045,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
1069 1045 {
1070 1046 stim::vec<float> out(0.0,0.0,0.0,0.0);
1071 1047 stim::vec<float> from(0.0,0.0,1.0);
1072   - out[0] = acos(dir.dot(from))*180/M_PI;
  1048 + out[0] = acos(dir.dot(from))*180/stim::PI;
1073 1049 if(out[0] < 1.0){
1074 1050 out[0] = 0.0;
1075 1051 out[1] = 0.0;
... ... @@ -1385,8 +1361,8 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
1385 1361 int j = 0;
1386 1362 for(float i = step; i <= 360.0; i += step)
1387 1363 {
1388   - x=r0*cos(i*2.0*M_PI/360.0);
1389   - y=r0*sin(i*2.0*M_PI/360.0);
  1364 + x=r0*cos(i*stim::TAU/360.0);
  1365 + y=r0*sin(i*stim::TAU/360.0);
1390 1366 glTexCoord3f(x,y,z0);
1391 1367 glVertex2f(0.0, j*6.4+6.4);
1392 1368 // glVertex2f(0.0, j*27.0+27.0);
... ...
stim/visualization/cylinder.h
... ... @@ -325,13 +325,13 @@ class cylinder
325 325 {
326 326 std::cout << "-------------------------" << std::endl;
327 327 std::cout << e[idx].str() << std::endl << std::endl;
328   - std::cout << Us[idx] << std::endl;
  328 + std::cout << Us[idx].str() << std::endl;
329 329 std::cout << (float)v1 - (float) v2 << std::endl;
330 330 std::cout << "failed" << std::endl;
331 331 }
332 332 // std::cout << e[idx].U.len() << " " << mags[idx][0] << std::endl;
333 333 // std::cout << v2 << std::endl;
334   - return(v1);
  334 + return(v2);
335 335 // return (mags[idx][0] + (mags[idx+1][0]-mags[idx][0])*rat);
336 336 // (
337 337 }
... ...
stim/visualization/glObj.h
... ... @@ -5,6 +5,7 @@
5 5 #include <GL/glut.h>
6 6 #include <stim/math/vector.h>
7 7 #include <stim/visualization/obj.h>
  8 +#include <stim/gl/error.h>
8 9  
9 10  
10 11 namespace stim
... ...