Commit 90933f7f810c5dab73eca0b14a705c076d248769

Authored by David Mayerich
2 parents 8550e94f cce7daf9

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

stim/biomodels/network.h
... ... @@ -2,6 +2,7 @@
2 2 #define STIM_NETWORK_H
3 3  
4 4 #include <stim/math/vector.h>
  5 +#include <stim/visualization/obj.h>
5 6 #include <list>
6 7 #include <ANN/ANN.h>
7 8  
... ...
stim/cuda/cost.h
... ... @@ -5,8 +5,9 @@
5 5 #include <stdio.h>
6 6 #include <stim/visualization/colormap.h>
7 7 #include <sstream>
8   -#include <stim/math/mathvec.h>
9   -
  8 +#include <stim/math/vector.h>
  9 +#include <stim/cuda/devices.h>
  10 +#include <stim/cuda/threads.h>
10 11  
11 12 ///Cost function that works with the gl-spider class to find index of the item with min-cost.
12 13 typedef unsigned char uchar;
... ... @@ -38,6 +39,7 @@ float get_sum(float *diff)
38 39 ret = cublasSetVector(20*10, sizeof(*diff), diff, 1, v_dif, 1);
39 40 float out;
40 41 ret = cublasSasum(handle, 20*10, v_dif, 1, &out);
  42 +// cublasDestroy(ret);
41 43 cublasDestroy(handle);
42 44 return out;
43 45 }
... ... @@ -90,7 +92,7 @@ void initArray(cudaGraphicsResource_t src, int DIM_Y)
90 92 cudaGraphicsMapResources(1, &src)
91 93 );
92 94 HANDLE_ERROR(
93   - cudaGraphicsSubResourceGetMappedArray(&srcArray, src,0,0)
  95 + cudaGraphicsSubResourceGetMappedArray(&srcArray, src, 0, 0)
94 96 );
95 97 HANDLE_ERROR(
96 98 cudaBindTextureToArray(texIn, srcArray)
... ... @@ -109,9 +111,6 @@ void initArray(cudaGraphicsResource_t src, int DIM_Y)
109 111 void cleanUP(cudaGraphicsResource_t src)
110 112 {
111 113 HANDLE_ERROR(
112   - cudaUnbindTexture(texIn)
113   - );
114   - HANDLE_ERROR(
115 114 cudaFree(result)
116 115 );
117 116 HANDLE_ERROR(
... ... @@ -120,7 +119,13 @@ void cleanUP(cudaGraphicsResource_t src)
120 119 HANDLE_ERROR(
121 120 cudaFree(v_dif)
122 121 );
  122 + HANDLE_ERROR(
  123 + cudaUnbindTexture(texIn)
  124 + );
123 125 }
  126 +
  127 +
  128 +
124 129 ///External access-point to the cuda function
125 130 ///@param src, cudaGraphicsResource that handles the shared OpenGL/Cuda Texture
126 131 ///@param DIM_Y, the number of samples in the template.
... ... @@ -128,17 +133,33 @@ void cleanUP(cudaGraphicsResource_t src)
128 133 extern "C"
129 134 stim::vec<int> get_cost(cudaGraphicsResource_t src, int DIM_Y)
130 135 {
  136 +// int minGridSize;
  137 +// int blockSize;
  138 +
  139 +// cudaOccupancyMaxPotentialBlockSize(&minGridSize, &blockSize, get_diff, 0, 20*DIM_Y*10);
  140 +// std::cout << blockSize << std::endl;
  141 +// std::cout << minGridSize << std::endl;
  142 +// stringstream name; //for debugging
  143 +// name << "Test.bmp";
  144 +// dim3 block(4,4);
  145 +// dim3 grid(20/4, DIM_Y*10/4);
  146 +// int gridSize = (DIM_Y*10*20 + 1024 - 1)/1024;
  147 +// dim3 grid(26, 26);
  148 +// dim3 grid = GenGrid1D(DIM_Y*10*20);
  149 +// stim::gpu2image<float>(result, name.str(), 20,DIM_Y*10,0,1);
  150 +// name.clear();
  151 +// name << "sample_" << inter << "_" << idx << ".bmp";
  152 +// stim::gpu2image<float>(v_dif, name.str(), 20,10,0,1);
  153 +
131 154 float output[DIM_Y];
132 155 stim::vec<int> ret(0, 0);
133 156 float mini = 10000000000000000.0;
134 157 int idx;
135   - stringstream name; //for debugging
136   - name << "Test.bmp";
137 158 initArray(src, DIM_Y*10);
138   - dim3 grid(20, DIM_Y*10);
139   - dim3 block(1, 1);
  159 + dim3 grid(20/2, DIM_Y*10/2);
  160 + dim3 block(2, 2);
  161 +
140 162 get_diff <<< grid, block >>> (result);
141   - stim::gpu2image<float>(result, name.str(), 20,DIM_Y*10,0,1);
142 163 for (int i = 0; i < DIM_Y; i++){
143 164 output[i] = get_sum(result+(20*10*i));
144 165 if(output[i] <= mini){
... ... @@ -147,10 +168,7 @@ stim::vec&lt;int&gt; get_cost(cudaGraphicsResource_t src, int DIM_Y)
147 168 }
148 169 }
149 170  
150   -// name.clear();
151   -// name << "sample_" << inter << "_" << idx << ".bmp";
152 171 output[idx] = get_sum(result+(20*10*idx));
153   -// stim::gpu2image<float>(v_dif, name.str(), 20,10,0,1);
154 172 cleanUP(src);
155 173 ret[0] = idx; ret[1] = (int) output[idx];
156 174 return ret;
... ...
stim/gl/gl_spider.h
... ... @@ -10,11 +10,12 @@
10 10 #include "stim/gl/gl_texture.h"
11 11 #include "stim/visualization/camera.h"
12 12 #include "stim/gl/error.h"
13   -#include "stim/math/mathvec.h"
  13 +#include "stim/math/vector.h"
14 14 #include "stim/math/rect.h"
15 15 #include "stim/math/matrix.h"
16 16 #include "stim/cuda/cost.h"
17 17 #include "stim/cuda/glbind.h"
  18 +#include <stim/visualization/obj.h>
18 19 #include <vector>
19 20  
20 21 #include <iostream>
... ... @@ -55,6 +56,7 @@ class gl_spider
55 56 GLuint texbufferID;
56 57 int numSamples;
57 58 float stepsize = 3.0;
  59 + int current_cost;
58 60  
59 61 /// Method for finding the best scale for the spider.
60 62 /// changes the x, y, z size of the spider to minimize the cost
... ... @@ -119,7 +121,7 @@ class gl_spider
119 121 setMatrix();
120 122 glCallList(dList+3);
121 123  
122   - int best = getCost();
  124 +// int best = getCost();
123 125  
124 126 }
125 127  
... ... @@ -142,7 +144,7 @@ class gl_spider
142 144 ///Method for populating the vector arrays with sampled vectors.
143 145 ///uses the default d vector <0,0,1>
144 146 void
145   - genDirectionVectors(float solidAngle = M_PI)
  147 + genDirectionVectors(float solidAngle = 5*M_PI/4)
146 148 {
147 149 //ofstream file;
148 150 //file.open("dvectors.txt");
... ... @@ -492,8 +494,9 @@ class gl_spider
492 494 createResource();
493 495 stim::vec<int> cost = get_cost(resource, numSamples);
494 496 destroyResource();
495   - if (cost[1] >= 80)
496   - exit(0);
  497 +// if (cost[1] >= 80)
  498 +// exit(0);
  499 + current_cost = cost[1];
497 500 return cost[0];
498 501 }
499 502  
... ... @@ -562,7 +565,7 @@ class gl_spider
562 565 dList = glGenLists(3);
563 566 glListBase(dList);
564 567 Bind();
565   - genDirectionVectors(M_PI);
  568 + genDirectionVectors(5*M_PI/4);
566 569 genPositionVectors();
567 570 genMagnitudeVectors();
568 571 DrawCylinder();
... ... @@ -649,7 +652,7 @@ class gl_spider
649 652 {
650 653 m[0] = mag;
651 654 m[1] = mag;
652   - m[2] = mag;
  655 + // m[2] = mag;
653 656 }
654 657  
655 658  
... ... @@ -719,15 +722,16 @@ class gl_spider
719 722 }
720 723  
721 724  
722   - void
  725 + int
723 726 Step()
724 727 {
725 728 Bind();
726 729 findOptimalDirection();
727 730 findOptimalPosition();
728 731 findOptimalScale();
729   -// branchDetection();
  732 + // branchDetection();
730 733 Unbind();
  734 + return current_cost;
731 735 }
732 736  
733 737  
... ...
stim/grids/grid.h
... ... @@ -7,7 +7,7 @@
7 7 #include <fstream>
8 8 #include <cstdarg>
9 9  
10   -#include "../math/mathvec.h"
  10 +#include <stim/math/vector.h>
11 11  
12 12 namespace stim{
13 13  
... ...
stim/math/matrix.h
... ... @@ -4,7 +4,7 @@
4 4 //#include "rts/vector.h"
5 5 #include <string.h>
6 6 #include <iostream>
7   -#include "mathvec.h"
  7 +#include <stim/math/vector.h>
8 8 #include "../cuda/callable.h"
9 9  
10 10 namespace stim{
... ...
stim/math/plane.h
... ... @@ -2,7 +2,7 @@
2 2 #define RTS_PLANE_H
3 3  
4 4 #include <iostream>
5   -#include "../math/vector.h"
  5 +#include <stim/math/vector.h>
6 6 #include "rts/cuda/callable.h"
7 7  
8 8  
... ...
stim/math/quad.h
... ... @@ -2,10 +2,10 @@
2 2 #define RTS_QUAD_H
3 3  
4 4 //enable CUDA_CALLABLE macro
5   -#include "../cuda/callable.h"
6   -#include "../math/vector.h"
7   -#include "../math/triangle.h"
8   -#include "../math/quaternion.h"
  5 +#include <stim/cuda/callable.h>
  6 +#include <stim/math/vector.h>
  7 +#include <stim/math/triangle.h>
  8 +#include <stim/math/quaternion.h>
9 9 #include <iostream>
10 10 #include <iomanip>
11 11 #include <algorithm>
... ...
stim/math/rect.h
... ... @@ -2,10 +2,10 @@
2 2 #define RTS_RECT_H
3 3  
4 4 //enable CUDA_CALLABLE macro
5   -#include "../cuda/callable.h"
6   -#include "../math/mathvec.h"
7   -#include "../math/triangle.h"
8   -#include "../math/quaternion.h"
  5 +#include <stim/cuda/callable.h>
  6 +#include <stim/math/vector.h>
  7 +#include <stim/math/triangle.h>
  8 +#include <stim/math/quaternion.h>
9 9 #include <iostream>
10 10 #include <iomanip>
11 11 #include <algorithm>
... ...
stim/math/spharmonics.h
1 1 #ifndef STIM_SPH_HARMONICS
2 2 #define STIM_SPH_HARMONICS
3 3  
4   -#include <stim/math/mathvec.h>
  4 +#include <stim/math/vector.h>
5 5 #include <boost/math/special_functions/spherical_harmonic.hpp>
6 6 #include <vector>
7 7  
... ...
stim/math/triangle.h
... ... @@ -2,8 +2,8 @@
2 2 #define RTS_TRIANGLE_H
3 3  
4 4 //enable CUDA_CALLABLE macro
5   -#include "../cuda/callable.h"
6   -#include "../math/mathvec.h"
  5 +#include <stim/cuda/callable.h>
  6 +#include <stim/math/vector.h>
7 7 #include <iostream>
8 8  
9 9 namespace stim{
... ...
stim/visualization/camera.h
1   -#include "../math/mathvec.h"
2   -#include "../math/quaternion.h"
3   -#include "../math/matrix.h"
  1 +#include <stim/math/vector.h>
  2 +#include <stim/math/quaternion.h>
  3 +#include <stim/math/matrix.h>
4 4  
5 5 #include <ostream>
6 6  
... ...
stim/visualization/glObj.h 0 → 100644
  1 +#ifndef STIM_GLOBJ_H
  2 +#define STIM_GLOBJ_H
  3 +
  4 +#include <stim/visualization/obj.h>
  5 +#include <GL/glew.h>
  6 +#include <GL/glut.h>
  7 +#include <stim/math/vector.h>
  8 +
  9 +
  10 +namespace stim
  11 +{
  12 +/** This class uses the loading functionality of the obj class in order to
  13 + * Assist with the visualization the segmented vessels.
  14 + * Uses
  15 +*/
  16 +
  17 +class objGl : public virtual stim::obj<T>
  18 +{
  19 +private:
  20 + using stim::obj<T>::L;
  21 + using stim::obj<T>::P;
  22 + using stim::obj<T>::F;
  23 + using vec<T>::size;
  24 + using vec<T>::at;
  25 + GLuint dList;
  26 +
  27 +
  28 + void
  29 + init
  30 + {
  31 + dList = glGenList(1);
  32 + glListBase(dList);
  33 + glMatrixMode(GL_PROJECTION);
  34 + glLoadIdentity;
  35 + glMatrixMode(GL_MODELVIEW);
  36 + glLoadIdentity;
  37 +
  38 + }
  39 +
  40 + void
  41 + Create()
  42 + {
  43 + int len = (int) numL();
  44 + std::vector< stim::vec<float> > line;
  45 + glNewList(dList, GL_COMPILE);
  46 + glColor3f(0.5, 1.0, 0.5);
  47 + for(int i = 0; i < len; i++){
  48 + line = getL_V(i);
  49 + glBegin(GL_LINES);
  50 + for(int j = 0; j < line.size(); j++){
  51 + glVectex3f(
  52 + line[j][0],
  53 + line[j][1],
  54 + line[j][2]
  55 + );
  56 + }
  57 + glEnd();
  58 + }
  59 + glEndList();
  60 + }
  61 +
  62 +public:
  63 + objGl(std::string filename)
  64 + {
  65 + stim::obj::load(filename);
  66 + glPopMatrix(); //Safety Operation to avoid changing the current matrix.
  67 + init();
  68 + Create();
  69 + glPushMatrix();
  70 + }
  71 +
  72 +
  73 + void
  74 + Render()
  75 + {
  76 + glCallList(dList);
  77 + }
  78 +
  79 +}
  80 +}
... ...