Blame view

stim/gl/gl_spider.h 18.9 KB
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
1
2
3
  #ifndef STIM_GL_SPIDER_H
  #define STIM_GL_SPIDER_H
  
a9b45efe   Pavel Govyadinov   changes to spider
4
  #include <GL/glew.h>
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
5
  #include <GL/glut.h>
a9b45efe   Pavel Govyadinov   changes to spider
6
7
8
  #include <cuda.h>
  #include <cuda_gl_interop.h>
  #include <cudaGL.h>
1a456186   Pavel Govyadinov   Added directional...
9
  #include <math.h>
556c4e15   Pavel Govyadinov   Changed the handl...
10
11
12
  #include "stim/gl/gl_texture.h"
  #include "stim/visualization/camera.h"
  #include "stim/gl/error.h"
5eeaf941   Pavel Govyadinov   changer to the ba...
13
  #include "stim/math/mathvec.h"
556c4e15   Pavel Govyadinov   Changed the handl...
14
15
16
17
  #include "stim/math/rect.h"
  #include "stim/math/matrix.h"
  #include "stim/cuda/cost.h"
  #include "stim/cuda/glbind.h"
385d2447   Pavel Govyadinov   Checkpoint: Conve...
18
  #include <vector>
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
19
  
42145f38   Pavel Govyadinov   Fixed the issues ...
20
21
22
  #include <iostream>
  #include <fstream>
  
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
23
24
25
26
27
  
  
  /* Technically since gl_spider inherits from gl_texture, we could
  	call the init with a path to an image stack, and upload
  	the images while creating the spider (calling init) */
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
28
29
30
31
  namespace stim
  {
  
  template<typename T>
8e56a0a7   Pavel Govyadinov   Added the propose...
32
  class gl_spider
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
33
34
  {
  	//doen't use gl_texture really, just needs the GLuint id.
4cefeb6d   Pavel Govyadinov   Changes to the re...
35
  	//doesn't even need the texture iD really.
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
36
  	private:
8e56a0a7   Pavel Govyadinov   Added the propose...
37
38
  		stim::vec<float> p;  	//vector designating the position of the spider.
  		stim::vec<float> d;	//vector designating the orientation of the spider
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
39
  						//always a unit vector.
8e56a0a7   Pavel Govyadinov   Added the propose...
40
  		stim::vec<float> m;	//magnitude of the spider vector.
4cefeb6d   Pavel Govyadinov   Changes to the re...
41
42
  						//mag[0] = length.
  						//mag[1] = width.
8e56a0a7   Pavel Govyadinov   Added the propose...
43
44
45
46
47
48
49
50
  		std::vector<stim::vec<float> > dV;
  		std::vector<stim::vec<float> > pV;
  		std::vector<stim::vec<float> > mV;
  		//currentTransform
  		stim::matrix<float, 4> cT;
  		GLuint texID;
  		stim::vec<float> S;
  		stim::vec<float> R;
a9b45efe   Pavel Govyadinov   changes to spider
51
  		cudaGraphicsResource_t resource;
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
52
  
db3c28c9   Pavel Govyadinov   Implemented glDis...
53
  		GLuint dList;
a9b45efe   Pavel Govyadinov   changes to spider
54
55
  		GLuint fboID;
  		GLuint texbufferID;
2a18be6d   Pavel Govyadinov   New comments and ...
56
  		int numSamples;
8e56a0a7   Pavel Govyadinov   Added the propose...
57
  		float stepsize = 3.0;
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
58
59
60
61
62
63
64
  
  		/// Method for finding the best scale for the spider.
  		/// changes the x, y, z size of the spider to minimize the cost
  		/// function. 
  		void
  		findOptimalDirection()
  		{
8e56a0a7   Pavel Govyadinov   Added the propose...
65
  			setMatrix();
db3c28c9   Pavel Govyadinov   Implemented glDis...
66
  			glCallList(dList);
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
67
  			int best = getCost();
5eeaf941   Pavel Govyadinov   changer to the ba...
68
69
70
71
  			stim::vec<float> next(
   			dV[best][0]*S[0]*R[0],
  			dV[best][1]*S[1]*R[1],
  			dV[best][2]*S[2]*R[2],
d4721000   Pavel Govyadinov   changes with debu...
72
  			0);
8e56a0a7   Pavel Govyadinov   Added the propose...
73
  			next = (cT*next).norm();
80d3850d   Pavel Govyadinov   test
74
  			//next = (cT*next);
8e56a0a7   Pavel Govyadinov   Added the propose...
75
76
77
  			setPosition(	p[0]+next[0]*m[0]/stepsize,
  					p[1]+next[1]*m[0]/stepsize,
  					p[2]+next[2]*m[0]/stepsize);
556c4e15   Pavel Govyadinov   Changed the handl...
78
  			setDirection(next[0], next[1], next[2]);
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
79
80
  		}
  
8e56a0a7   Pavel Govyadinov   Added the propose...
81
82
83
  		/// Method for finding the best d for the spider.
  		/// Not sure if necessary since the next p for the spider
  		/// will be at d * m.
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
84
85
86
  		void
  		findOptimalPosition()
  		{
8e56a0a7   Pavel Govyadinov   Added the propose...
87
  			setMatrix();
db3c28c9   Pavel Govyadinov   Implemented glDis...
88
  			glCallList(dList+1);
385d2447   Pavel Govyadinov   Checkpoint: Conve...
89
  			int best = getCost();
5eeaf941   Pavel Govyadinov   changer to the ba...
90
91
92
93
94
  			stim::vec<float> next(
   			pV[best][0],
  			pV[best][1],
  			pV[best][2],
  			1);
ef64ebad   Pavel Govyadinov   fixed a small mis...
95
  			next = cT*next;	
d4721000   Pavel Govyadinov   changes with debu...
96
97
  			setPosition(
  					next[0]*S[0]*R[0],
8e56a0a7   Pavel Govyadinov   Added the propose...
98
  					next[1]*S[1]*R[1],
d4721000   Pavel Govyadinov   changes with debu...
99
100
  					next[2]*S[2]*R[2]
  				   );
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
101
102
  		}
  	
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
103
104
105
  		/// Method for finding the best scale for the spider.
  		/// changes the x, y, z size of the spider to minimize the cost
  		/// function. */
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
106
107
108
  		void
  		findOptimalScale()
  		{
8e56a0a7   Pavel Govyadinov   Added the propose...
109
  			setMatrix();
db3c28c9   Pavel Govyadinov   Implemented glDis...
110
  			glCallList(dList+2);
385d2447   Pavel Govyadinov   Checkpoint: Conve...
111
  			int best = getCost();
d4721000   Pavel Govyadinov   changes with debu...
112
  			setMagnitude(m[0]*mV[best][0]);
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
113
114
  		}
  
f31bf86d   Pavel Govyadinov   Added skeleton fu...
115
116
117
118
  		void
  		branchDetection()
  		{
  			Bind();
5eeaf941   Pavel Govyadinov   changer to the ba...
119
  			setMatrix();
f31bf86d   Pavel Govyadinov   Added skeleton fu...
120
121
122
123
124
125
  			glCallList(dList+3);
  			
  			int best = getCost();
  			
  		}
  
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
126
127
  
  		
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
128
  		void
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
129
  		Optimize()
385d2447   Pavel Govyadinov   Checkpoint: Conve...
130
  		{
8e56a0a7   Pavel Govyadinov   Added the propose...
131
  			/*find the optimum d and scale */ 
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
132
  		}
385d2447   Pavel Govyadinov   Checkpoint: Conve...
133
  
a9b45efe   Pavel Govyadinov   changes to spider
134
  		
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
135
136
137
138
139
140
141
142
  		
  		
  //--------------------------------------------------------------------------//
  //---------------------TEMPLATE CREATION METHODS----------------------------//
  //--------------------------------------------------------------------------//
  
  		///@param solidAngle, the size of the arc to sample.
  		///Method for populating the vector arrays with sampled vectors.
8e56a0a7   Pavel Govyadinov   Added the propose...
143
  		///uses the default d vector <0,0,1>
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
144
  		void
25580fe7   Pavel Govyadinov   minor bug fix in ...
145
  		genDirectionVectors(float solidAngle = M_PI)
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
146
  		{
5eeaf941   Pavel Govyadinov   changer to the ba...
147
148
  			//ofstream file;
  			//file.open("dvectors.txt");
8e56a0a7   Pavel Govyadinov   Added the propose...
149
  			//Set up the vectors necessary for Rectangle creation.
22e7d0c5   Pavel Govyadinov   Minor changes in ...
150
151
152
153
154
  			vec<float> Y(1.0,0.0,0.0);
  			vec<float> pos(0.0,0.0,0.0);
  			vec<float> mag(1.0, 1.0, 1.0);
  			vec<float> dir(0.0, 0.0, 1.0);
  
8e56a0a7   Pavel Govyadinov   Added the propose...
155
156
  			//Set up the variable necessary for vector creation.
  			vec<float> d_s = d.cart2sph().norm();
5eeaf941   Pavel Govyadinov   changer to the ba...
157
  			vec<float> temp(0,0,0);
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
158
  			int dim = (sqrt(numSamples)-1)/2;
25580fe7   Pavel Govyadinov   minor bug fix in ...
159
160
161
  			float p0  	= -M_PI;
  			float dt  	= solidAngle/(2.0 * ((float)dim + 1.0));
  			float dp  	= p0/(2.0*((float)dim + 1.0));
8e56a0a7   Pavel Govyadinov   Added the propose...
162
163
164
165
  			
  			glNewList(dList, GL_COMPILE);
  			//Loop over the space
  			int idx = 0;
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
166
167
  			for(int i = -dim; i <= dim; i++){
  				for(int j = -dim; j <= dim; j++){
5eeaf941   Pavel Govyadinov   changer to the ba...
168
  					
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
169
  					//Create linear index
8e56a0a7   Pavel Govyadinov   Added the propose...
170
  					idx = (j+dim)+(i+dim)*((dim*2)+1);	
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
171
  					temp[0] = d_s[0]; 			//rotate vector
25580fe7   Pavel Govyadinov   minor bug fix in ...
172
173
  					temp[1] = d_s[1]+dp*(float) i;
  					temp[2] = d_s[2]+dt*(float) j;
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
174
175
  					
  					temp = (temp.sph2cart()).norm();	//back to cart
8e56a0a7   Pavel Govyadinov   Added the propose...
176
177
178
179
180
181
182
183
184
185
186
187
  					dV.push_back(temp);
  				 	if(cos(Y.dot(temp))< 0.087){                                                                             Y[0] = 0.0; Y[1] = 1.0;}
  					else{Y[0] = 1.0; Y[1] = 0.0;}
  
                                         	hor = stim::rect<float>(mag,
  						 pos, temp,
                         				((Y.cross(temp)).cross(temp)).norm());
         				 	ver = stim::rect<float>(mag,
  						 pos, temp,
                         				hor.n());
  					UpdateBuffer(0.0, 0.0+idx*10.0);
  					CHECK_OPENGL_ERROR
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
188
189
  				}
  			}
8e56a0a7   Pavel Govyadinov   Added the propose...
190
  			glEndList();
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
191
  		}
2a18be6d   Pavel Govyadinov   New comments and ...
192
  
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
193
194
195
  		///@param solidAngle, the size of the arc to sample.
  		///Method for populating the buffer with the sampled texture.
  		///uses the default vector <0,0,0>
a9f956be   Pavel Govyadinov   Fixed the cost fu...
196
  		void
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
197
  		genPositionVectors(float delta = 0.2)
a9f956be   Pavel Govyadinov   Fixed the cost fu...
198
  		{
8e56a0a7   Pavel Govyadinov   Added the propose...
199
200
201
202
203
204
205
  			//Set up the vectors necessary for Rectangle creation.
  			vec<float> Y(1.0,0.0,0.0);
  			vec<float> pos(0.0,0.0,0.0);
  			vec<float> mag(1.0, 1.0, 1.0);
  			vec<float> dir(0.0, 0.0, 1.0);
  
  			//Set up the variable necessary for vector creation.
5eeaf941   Pavel Govyadinov   changer to the ba...
206
  			vec<float> temp(0,0,0);
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
207
208
  			int dim = (sqrt(numSamples)-1)/2;
  			stim::rect<float> samplingPlane =
5eeaf941   Pavel Govyadinov   changer to the ba...
209
  				 stim::rect<float>(p, d);
d4721000   Pavel Govyadinov   changes with debu...
210
  			samplingPlane.scale(mag[0]*delta, mag[0]*delta);
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
211
  			float step = 1.0/(dim);
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
212
  
8e56a0a7   Pavel Govyadinov   Added the propose...
213
214
215
216
  			//Loop over the samples, keeping the original p sample
  			//in the center of the resulting texture.
  			int idx;
  			glNewList(dList+1, GL_COMPILE);
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
217
218
219
  			for(int i = -dim; i <= dim; i++){
  				for(int j = -dim; j <= dim; j++){
  					//Create linear index
8e56a0a7   Pavel Govyadinov   Added the propose...
220
  					idx = (j+dim)+(i+dim)*((dim*2)+1);	
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
221
222
223
224
225
  
  					temp = samplingPlane.p(
  							0.5+step*i,
  								 0.5+step*j
  										);
8e56a0a7   Pavel Govyadinov   Added the propose...
226
227
228
229
230
231
232
233
234
235
  					pV.push_back(temp);
                  			hor = stim::rect<float>(mag,
  						 temp, dir,
                        				((Y.cross(d)).cross(d))
  						.norm());
                  			ver = stim::rect<float>(mag,
  						 temp, dir,
                          			hor.n());
  					UpdateBuffer(0.0, 0.0+idx*10.0);
  				CHECK_OPENGL_ERROR
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
236
237
  				}
  			}
8e56a0a7   Pavel Govyadinov   Added the propose...
238
  			glEndList();
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
239
240
241
242
  		}
  
  		///@param solidAngle, the size of the arc to sample.
  		///Method for populating the buffer with the sampled texture.
8e56a0a7   Pavel Govyadinov   Added the propose...
243
  		///uses the default m <1,1,0>
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
244
245
246
247
  		void
  		genMagnitudeVectors(float delta = 0.5)
  		{
  			
8e56a0a7   Pavel Govyadinov   Added the propose...
248
249
250
251
252
253
254
  			//Set up the vectors necessary for Rectangle creation.
  			vec<float> Y(1.0,0.0,0.0);
  			vec<float> pos(0.0,0.0,0.0);
  			vec<float> mag(1.0, 1.0, 1.0);
  			vec<float> dir(0.0, 0.0, 1.0);
  
  			//Set up the variable necessary for vector creation.
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
255
256
257
258
259
  			int dim = (sqrt(numSamples)-1)/2;
  			float min 	= 1.0-delta;
  			float max 	= 1.0+delta;
  			float step	= (max-min)/(numSamples-1);
  			float factor;
5eeaf941   Pavel Govyadinov   changer to the ba...
260
  			vec<float> temp(0.0,0.0,0.0);
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
261
  
8e56a0a7   Pavel Govyadinov   Added the propose...
262
  			glNewList(dList+2, GL_COMPILE);
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
263
264
  			for(int i = 0; i < numSamples; i++){
  				//Create linear index
d4721000   Pavel Govyadinov   changes with debu...
265
  				factor = (min+step*i)*mag[0];
db3c28c9   Pavel Govyadinov   Implemented glDis...
266
  				temp = factor;
8e56a0a7   Pavel Govyadinov   Added the propose...
267
268
269
270
271
272
273
274
275
276
  				mV.push_back(temp);	
  				hor = stim::rect<float>(temp,
  					 pos, dir, 
         	       				((Y.cross(d)).cross(d))
  					.norm());
                 			ver = stim::rect<float>(temp,
  					 pos, dir,
                         			hor.n());
  				UpdateBuffer(0.0, 0.0+i*10.0);
  			CHECK_OPENGL_ERROR
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
277
  			}
8e56a0a7   Pavel Govyadinov   Added the propose...
278
  			glEndList();
a9f956be   Pavel Govyadinov   Fixed the cost fu...
279
  		}
2a18be6d   Pavel Govyadinov   New comments and ...
280
281
  		///@param v_x x-coordinate in buffer-space,
  		///@param v_y y-coordinate in buffer-space.
2a18be6d   Pavel Govyadinov   New comments and ...
282
283
  		///Samples the texturespace and places a sample in the provided coordinates
  		///of bufferspace.
a9f956be   Pavel Govyadinov   Fixed the cost fu...
284
285
286
  		void
  		UpdateBuffer(float v_x, float v_y)
  		{	
a9f956be   Pavel Govyadinov   Fixed the cost fu...
287
288
289
290
291
  			float len = 10.0;
  			stim::vec<float>p1; 
          	        stim::vec<float>p2; 
  	                stim::vec<float>p3; 
                  	stim::vec<float>p4;	
a9f956be   Pavel Govyadinov   Fixed the cost fu...
292
  			p1 = hor.p(1,1);
a9f956be   Pavel Govyadinov   Fixed the cost fu...
293
  			p2 = hor.p(1,0);
a9f956be   Pavel Govyadinov   Fixed the cost fu...
294
  			p3 = hor.p(0,0);
a9f956be   Pavel Govyadinov   Fixed the cost fu...
295
  			p4 = hor.p(0,1);
5e7c7581   Pavel Govyadinov   Debugging build f...
296
  			glBegin(GL_QUADS);
a9f956be   Pavel Govyadinov   Fixed the cost fu...
297
  				glTexCoord3f(
a9f956be   Pavel Govyadinov   Fixed the cost fu...
298
299
300
301
  					p1[0],
  					p1[1],
  					p1[2]
  					);
a9f956be   Pavel Govyadinov   Fixed the cost fu...
302
303
  				glVertex2f(v_x,v_y);
  				glTexCoord3f(
a9f956be   Pavel Govyadinov   Fixed the cost fu...
304
305
306
307
  					p2[0],
  					p2[1],
  					p2[2]
  					);
a9f956be   Pavel Govyadinov   Fixed the cost fu...
308
309
  				glVertex2f(v_x+len, v_y);
  				glTexCoord3f(
a9f956be   Pavel Govyadinov   Fixed the cost fu...
310
311
312
313
  					p3[0],
  					p3[1],
  					p3[2]
  					);
a9f956be   Pavel Govyadinov   Fixed the cost fu...
314
315
  				glVertex2f(v_x+len, v_y+len);
  				glTexCoord3f(
a9f956be   Pavel Govyadinov   Fixed the cost fu...
316
317
318
  					p4[0],
  					p4[1],
  					p4[2]
a9f956be   Pavel Govyadinov   Fixed the cost fu...
319
  					);
a9f956be   Pavel Govyadinov   Fixed the cost fu...
320
321
  				glVertex2f(v_x, v_y+len);
  			 glEnd();
5e7c7581   Pavel Govyadinov   Debugging build f...
322
  
a9f956be   Pavel Govyadinov   Fixed the cost fu...
323
  			 p1 = ver.p(1,1);
a9f956be   Pavel Govyadinov   Fixed the cost fu...
324
  			 p2 = ver.p(1,0);
a9f956be   Pavel Govyadinov   Fixed the cost fu...
325
  			 p3 = ver.p(0,0);
a9f956be   Pavel Govyadinov   Fixed the cost fu...
326
  			 p4 = ver.p(0,1);
5e7c7581   Pavel Govyadinov   Debugging build f...
327
  		 	 glBegin(GL_QUADS);
a9f956be   Pavel Govyadinov   Fixed the cost fu...
328
  				glTexCoord3f(
a9f956be   Pavel Govyadinov   Fixed the cost fu...
329
330
331
332
  					p1[0],
  					p1[1],
  					p1[2]
  					);
a9f956be   Pavel Govyadinov   Fixed the cost fu...
333
334
  				glVertex2f(v_x+len, v_y);
  				glTexCoord3f(
a9f956be   Pavel Govyadinov   Fixed the cost fu...
335
336
337
338
  					p2[0],
  					p2[1],
  					p2[2]
  					);
a9f956be   Pavel Govyadinov   Fixed the cost fu...
339
340
  				glVertex2f(v_x+2*len, v_y);
  				glTexCoord3f(
a9f956be   Pavel Govyadinov   Fixed the cost fu...
341
342
343
344
  					p3[0],
  					p3[1],
  					p3[2]
  					);
a9f956be   Pavel Govyadinov   Fixed the cost fu...
345
346
  				glVertex2f(v_x+2*len, v_y+len);
  				glTexCoord3f(
a9f956be   Pavel Govyadinov   Fixed the cost fu...
347
348
349
350
  					p4[0],
  					p4[1],
  					p4[2]
  					);
a9f956be   Pavel Govyadinov   Fixed the cost fu...
351
  				glVertex2f(v_x+len, v_y+len);
5e7c7581   Pavel Govyadinov   Debugging build f...
352
  			glEnd(); 
a9f956be   Pavel Govyadinov   Fixed the cost fu...
353
  		}
2a18be6d   Pavel Govyadinov   New comments and ...
354
  		
385d2447   Pavel Govyadinov   Checkpoint: Conve...
355
  
385d2447   Pavel Govyadinov   Checkpoint: Conve...
356
  
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
357
358
359
  //--------------------------------------------------------------------------//
  //--------------------------------GL METHODS--------------------------------//
  //--------------------------------------------------------------------------//
385d2447   Pavel Govyadinov   Checkpoint: Conve...
360
  
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
  		///@param width sets the width of the buffer.
  		///@param height sets the height of the buffer.
  		///Function for setting up the 2D buffer that stores the samples.
  		void
  		GenerateFBO(unsigned int width, unsigned int height)
  		{
  			glGenFramebuffers(1, &fboID);
  			glBindFramebuffer(GL_FRAMEBUFFER, fboID);
  			int numChannels = 1;
  			unsigned char* texels = new unsigned char[width * height * numChannels];
  			glGenTextures(1, &texbufferID);
  			glBindTexture(GL_TEXTURE_2D, texbufferID);
  			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  			glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE,
  				 width, height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, texels);   
  			delete[] texels;
  			glBindFramebuffer(GL_FRAMEBUFFER, 0); 
  			glBindTexture(GL_TEXTURE_2D, 0);
a9f956be   Pavel Govyadinov   Fixed the cost fu...
382
  		}
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
383
  
2a18be6d   Pavel Govyadinov   New comments and ...
384
385
  		///Method for controling the buffer and texture binding in order to properly
  		///do the render to texture.
a9f956be   Pavel Govyadinov   Fixed the cost fu...
386
  		void
2a18be6d   Pavel Govyadinov   New comments and ...
387
  		Bind()
a9f956be   Pavel Govyadinov   Fixed the cost fu...
388
  		{
5f81932b   David Mayerich   restored Pavel's ...
389
  			float len = 10.0;
a9f956be   Pavel Govyadinov   Fixed the cost fu...
390
391
392
393
394
395
396
397
398
399
400
  			glBindFramebuffer(GL_FRAMEBUFFER, fboID);//set up GL buffer		
  			glFramebufferTexture2D(
  				GL_FRAMEBUFFER,
  				GL_COLOR_ATTACHMENT0,
  				GL_TEXTURE_2D,
  				texbufferID,
  				0);
  			glBindFramebuffer(GL_FRAMEBUFFER, fboID);
  			GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0};
  			glDrawBuffers(1, DrawBuffers);
  			glBindTexture(GL_TEXTURE_2D, texbufferID);
5e7c7581   Pavel Govyadinov   Debugging build f...
401
  			glClearColor(1,1,1,1);
a9f956be   Pavel Govyadinov   Fixed the cost fu...
402
  			glClear(GL_COLOR_BUFFER_BIT);
a9f956be   Pavel Govyadinov   Fixed the cost fu...
403
404
405
406
407
408
409
410
  			glMatrixMode(GL_PROJECTION);
  			glLoadIdentity();
  			glMatrixMode(GL_MODELVIEW);
  			glLoadIdentity();
  			glViewport(0,0,2.0*len, numSamples*len);
  			gluOrtho2D(0.0,2.0*len,0.0,numSamples*len);
  			glEnable(GL_TEXTURE_3D);
  			glBindTexture(GL_TEXTURE_3D, texID);
957a4248   Pavel Govyadinov   renamed getSample...
411
  
5e7c7581   Pavel Govyadinov   Debugging build f...
412
  			CHECK_OPENGL_ERROR
5f81932b   David Mayerich   restored Pavel's ...
413
414
  		}
  		
2a18be6d   Pavel Govyadinov   New comments and ...
415
  		///Method for Unbinding all of the texture resources
5f81932b   David Mayerich   restored Pavel's ...
416
417
418
419
420
421
422
423
424
  		void
  		Unbind()
  		{
  			//Finalize GL_buffer
  			glBindTexture(GL_TEXTURE_3D, 0);                      
  			glDisable(GL_TEXTURE_3D);
  			glBindFramebuffer(GL_FRAMEBUFFER,0);
  			glBindTexture(GL_TEXTURE_2D, 0);
  		}
385d2447   Pavel Govyadinov   Checkpoint: Conve...
425
  
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
426
427
  		///Method for using the gl manipulation to alighn templates from
  		///Template space (-0.5 0.5) to Texture space (0.0, 1.0),
8e56a0a7   Pavel Govyadinov   Added the propose...
428
429
  		///Based on the p of the spider in real space (arbitrary).
  		void setMatrix()
5f81932b   David Mayerich   restored Pavel's ...
430
  		{
d4721000   Pavel Govyadinov   changes with debu...
431
  			float curTrans[16];
5eeaf941   Pavel Govyadinov   changer to the ba...
432
  			stim::vec<float> rot = getRotation(d);
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
433
434
  			glMatrixMode(GL_TEXTURE);
  			glLoadIdentity();
8e56a0a7   Pavel Govyadinov   Added the propose...
435
  			glScalef(1.0/S[0]/R[0], 1.0/S[1]/R[1], 1.0/S[2]/R[2]);
d4721000   Pavel Govyadinov   changes with debu...
436
437
  
  
8e56a0a7   Pavel Govyadinov   Added the propose...
438
439
440
  			glTranslatef(p[0],
  				     p[1],
  				     p[2]);
a506d41f   Pavel Govyadinov   fixed the methods...
441
  
d4721000   Pavel Govyadinov   changes with debu...
442
  			glRotatef(rot[0], rot[1], rot[2], rot[3]);
a506d41f   Pavel Govyadinov   fixed the methods...
443
  
8e56a0a7   Pavel Govyadinov   Added the propose...
444
  			glScalef(m[0],
d4721000   Pavel Govyadinov   changes with debu...
445
  				 m[0],
8e56a0a7   Pavel Govyadinov   Added the propose...
446
  				 m[0]);
a506d41f   Pavel Govyadinov   fixed the methods...
447
  
ef64ebad   Pavel Govyadinov   fixed a small mis...
448
449
  			glGetFloatv(GL_TEXTURE_MATRIX, curTrans);
  			cT.set(curTrans);
a506d41f   Pavel Govyadinov   fixed the methods...
450
  //			printTransform();
556c4e15   Pavel Govyadinov   Changed the handl...
451
  			
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
452
453
  			CHECK_OPENGL_ERROR
  			glMatrixMode(GL_MODELVIEW);
5f81932b   David Mayerich   restored Pavel's ...
454
  		}
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
455
456
  		
  		
5f81932b   David Mayerich   restored Pavel's ...
457
  
42145f38   Pavel Govyadinov   Fixed the issues ...
458
459
460
461
462
  
  //--------------------------------------------------------------------------//
  //--------------------------------CUDA METHODS------------------------------//
  //--------------------------------------------------------------------------//
  		
2a18be6d   Pavel Govyadinov   New comments and ...
463
464
  		/// Method for registering the texture with Cuda for shared
  		///	access.
42145f38   Pavel Govyadinov   Fixed the issues ...
465
466
467
468
469
470
471
472
473
474
475
476
477
  		void
  		createResource()
  		{
  			HANDLE_ERROR(
  				cudaGraphicsGLRegisterImage(
  					 &resource,
  				 	texbufferID,
  				 	GL_TEXTURE_2D,
  				 	//CU_GRAPHICS_REGISTER_FLAGS_NONE)
  					cudaGraphicsMapFlagsReadOnly)
  			);
  		} 
  		
2a18be6d   Pavel Govyadinov   New comments and ...
478
  		///Method for freeing the texture from Cuda for gl access.
42145f38   Pavel Govyadinov   Fixed the issues ...
479
480
481
482
483
484
485
486
  		void
  		destroyResource()
  		{
  			HANDLE_ERROR(
  				cudaGraphicsUnregisterResource(resource)
  			);		
  		}
  
2a18be6d   Pavel Govyadinov   New comments and ...
487
488
  		///Entry-point into the cuda code for calculating the cost
  		///	of a given samples array (in texture form) 
42145f38   Pavel Govyadinov   Fixed the issues ...
489
490
491
492
  		int
  		getCost()
  		{
  			createResource();
edd4ab2d   Pavel Govyadinov   Cleaned up more a...
493
  			stim::vec<int> cost = 	get_cost(resource, numSamples);
42145f38   Pavel Govyadinov   Fixed the issues ...
494
  			destroyResource();
edd4ab2d   Pavel Govyadinov   Cleaned up more a...
495
496
497
  			if (cost[1] >= 80)
  				exit(0);
  			return cost[0];
a9f956be   Pavel Govyadinov   Fixed the cost fu...
498
499
  		}
  
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
500
  	public:
13c2a7d4   Pavel Govyadinov   some changes to t...
501
502
503
  		stim::rect<float> hor;
  		stim::rect<float> ver;	
  
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
504
505
506
507
508
  //--------------------------------------------------------------------------//
  //-----------------------------CONSTRUCTORS---------------------------------//
  //--------------------------------------------------------------------------//
  
  
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
509
510
511
  		///@param samples, the number of samples this spider is going to use.
  		///best results if samples is can create a perfect root.
  		///Default Constructor
2a18be6d   Pavel Govyadinov   New comments and ...
512
  		gl_spider
8e56a0a7   Pavel Govyadinov   Added the propose...
513
  		(int samples = 1089)
2a18be6d   Pavel Govyadinov   New comments and ...
514
  		{
80d3850d   Pavel Govyadinov   test
515
516
517
518
519
  			p = vec<float>(0.0, 0.0, 0.0);
  			d = vec<float>(0.0, 0.0, 1.0);
  			m = vec<float>(1.0, 1.0);
  			S = vec<float>(1.0, 1.0, 1.0);
  			R = vec<float>(1.0, 1.0, 1.0);
5eeaf941   Pavel Govyadinov   changer to the ba...
520
521
522
  			//setPosition(0.0,0.0,0.0);
  			//setDirection(0.0,0.0,1.0);
  			//setMagnitude(1.0);
2a18be6d   Pavel Govyadinov   New comments and ...
523
  			numSamples = samples;
4cefeb6d   Pavel Govyadinov   Changes to the re...
524
525
  		}
  
385d2447   Pavel Govyadinov   Checkpoint: Conve...
526
  		///temporary constructor for convenience, will be removed in further updates.	
13c2a7d4   Pavel Govyadinov   some changes to t...
527
528
  		gl_spider
  		(float pos_x, float pos_y, float pos_z, float dir_x, float dir_y, float dir_z,
5eeaf941   Pavel Govyadinov   changer to the ba...
529
  			float mag_x, int numSamples = 1089)
13c2a7d4   Pavel Govyadinov   some changes to t...
530
  		{
80d3850d   Pavel Govyadinov   test
531
532
  			p = vec<float>(pos_x, pos_y, pos_z);
  			d = vec<float>(dir_x, dir_y, dir_z);
d4721000   Pavel Govyadinov   changes with debu...
533
  			m = vec<float>(mag_x, mag_x, mag_x);
80d3850d   Pavel Govyadinov   test
534
535
  			S = vec<float>(1.0,1.0,1.0);
  			R = vec<float>(1.0,1.0,1.0);
385d2447   Pavel Govyadinov   Checkpoint: Conve...
536
537
538
  			//setPosition(pos_x, pos_y, pos_z);
  			//setDirection(dir_x, dir_y, dir_z);
  			//setMagnitude(mag_x);
2a18be6d   Pavel Govyadinov   New comments and ...
539
  		
385d2447   Pavel Govyadinov   Checkpoint: Conve...
540
  		}
8e56a0a7   Pavel Govyadinov   Added the propose...
541
542
543
544
545
546
547
548
549
  	
  		~gl_spider
  		(void)
  		{
  			Unbind();
  			glDeleteTextures(1, &texbufferID);
  			glDeleteBuffers(1, &fboID);
  		}
  
385d2447   Pavel Govyadinov   Checkpoint: Conve...
550
  		///@param GLuint id texture that is going to be sampled.
385d2447   Pavel Govyadinov   Checkpoint: Conve...
551
  		///Attached the spider to the texture with the given GLuint ID.
8e56a0a7   Pavel Govyadinov   Added the propose...
552
  		///Samples in the default d acting as the init method.
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
553
  		///Also acts an init.	
a9b45efe   Pavel Govyadinov   changes to spider
554
  		void
2a18be6d   Pavel Govyadinov   New comments and ...
555
  		attachSpider(GLuint id)
a9b45efe   Pavel Govyadinov   changes to spider
556
557
  		{
  			texID = id;
5f81932b   David Mayerich   restored Pavel's ...
558
  			GenerateFBO(20, numSamples*10);
8e56a0a7   Pavel Govyadinov   Added the propose...
559
560
  			setDims(0.6, 0.6, 1.0);
  			setSize(512.0, 512.0, 426.0);
5eeaf941   Pavel Govyadinov   changer to the ba...
561
  			setMatrix();
db3c28c9   Pavel Govyadinov   Implemented glDis...
562
  			dList = glGenLists(3);
db3c28c9   Pavel Govyadinov   Implemented glDis...
563
  			glListBase(dList);
8e56a0a7   Pavel Govyadinov   Added the propose...
564
  			Bind();
d4721000   Pavel Govyadinov   changes with debu...
565
  			genDirectionVectors(M_PI);
8e56a0a7   Pavel Govyadinov   Added the propose...
566
567
  			genPositionVectors();
  			genMagnitudeVectors();
f31bf86d   Pavel Govyadinov   Added skeleton fu...
568
  			DrawCylinder();
8e56a0a7   Pavel Govyadinov   Added the propose...
569
  			Unbind();
a39577bf   Pavel Govyadinov   Changes to the sp...
570
  		}
5f81932b   David Mayerich   restored Pavel's ...
571
  		
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
572
573
574
  //--------------------------------------------------------------------------//
  //-----------------------------ACCESS METHODS-------------------------------//
  //--------------------------------------------------------------------------//
8e56a0a7   Pavel Govyadinov   Added the propose...
575
  		///Returns the p vector.
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
576
  		vec<float>
a39577bf   Pavel Govyadinov   Changes to the sp...
577
  		getPosition()
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
578
  		{
8e56a0a7   Pavel Govyadinov   Added the propose...
579
  			return p;
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
580
581
  		}
  	
8e56a0a7   Pavel Govyadinov   Added the propose...
582
  		///Returns the d vector.
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
583
  		vec<float>
a39577bf   Pavel Govyadinov   Changes to the sp...
584
  		getDirection()
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
585
  		{
8e56a0a7   Pavel Govyadinov   Added the propose...
586
  			return d;
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
587
588
  		}
  
8e56a0a7   Pavel Govyadinov   Added the propose...
589
  		///Returns the m vector.
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
590
  		vec<float>
a39577bf   Pavel Govyadinov   Changes to the sp...
591
  		getMagnitude()
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
592
  		{
8e56a0a7   Pavel Govyadinov   Added the propose...
593
  			return m;
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
594
595
  		}
  	
8e56a0a7   Pavel Govyadinov   Added the propose...
596
597
  		///@param vector pos, the new p.
  		///Sets the p vector to input vector pos.
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
598
599
600
  		void
  		setPosition(vec<float> pos)
  		{
8e56a0a7   Pavel Govyadinov   Added the propose...
601
  			p = pos;
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
602
  		}
385d2447   Pavel Govyadinov   Checkpoint: Conve...
603
604
605
606
  
  		///@param x x-coordinate.
  		///@param y y-coordinate.
  		///@param z z-coordinate.
8e56a0a7   Pavel Govyadinov   Added the propose...
607
  		///Sets the p vector to the input float coordinates x,y,z.
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
608
609
610
  		void
  		setPosition(float x, float y, float z)
  		{
8e56a0a7   Pavel Govyadinov   Added the propose...
611
612
613
  			p[0] = x;
  			p[1] = y;
  			p[2] = z;
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
614
  		}
887a3e49   Pavel Govyadinov   fixed some order ...
615
  		
8e56a0a7   Pavel Govyadinov   Added the propose...
616
617
  		///@param vector dir, the new d.
  		///Sets the d vector to input vector dir.
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
618
619
620
  		void
  		setDirection(vec<float> dir)
  		{
8e56a0a7   Pavel Govyadinov   Added the propose...
621
  			d = dir;
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
622
623
  		}
  		
385d2447   Pavel Govyadinov   Checkpoint: Conve...
624
625
626
  		///@param x x-coordinate.
  		///@param y y-coordinate.
  		///@param z z-coordinate.
8e56a0a7   Pavel Govyadinov   Added the propose...
627
  		///Sets the d vector to the input float coordinates x,y,z.
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
628
629
630
  		void
  		setDirection(float x, float y, float z)
  		{
8e56a0a7   Pavel Govyadinov   Added the propose...
631
632
633
  			d[0] = x;
  			d[1] = y;
  			d[2] = z;
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
634
  		}
385d2447   Pavel Govyadinov   Checkpoint: Conve...
635
  			
8e56a0a7   Pavel Govyadinov   Added the propose...
636
637
  		///@param vector dir, the new d.
  		///Sets the m vector to the input vector mag.	
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
638
639
640
  		void
  		setMagnitude(vec<float> mag)
  		{
8e56a0a7   Pavel Govyadinov   Added the propose...
641
642
  			m[0] = mag[0];
  			m[1] = mag[0];
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
643
644
  		}
  		
385d2447   Pavel Govyadinov   Checkpoint: Conve...
645
  		///@param mag size of the sampled region.
8e56a0a7   Pavel Govyadinov   Added the propose...
646
  		///Sets the m vector to the input mag for both templates.
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
647
  		void
5f81932b   David Mayerich   restored Pavel's ...
648
  		setMagnitude(float mag)
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
649
  		{
8e56a0a7   Pavel Govyadinov   Added the propose...
650
651
  			m[0] = mag;
  			m[1] = mag;
d4721000   Pavel Govyadinov   changes with debu...
652
  			m[2] = mag;
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
653
  		}
5f81932b   David Mayerich   restored Pavel's ...
654
  		
8e56a0a7   Pavel Govyadinov   Added the propose...
655
656
657
658
659
660
661
662
663
  
  		void
  		setDims(float x, float y, float z)
  		{
  			S[0] = x;
  			S[1] = y;
  			S[2] = z;
  		}
  
b710b044   Pavel Govyadinov   Added more tempor...
664
  		void
8e56a0a7   Pavel Govyadinov   Added the propose...
665
  		setSize(float x, float y, float z)
b710b044   Pavel Govyadinov   Added more tempor...
666
  		{
8e56a0a7   Pavel Govyadinov   Added the propose...
667
668
669
  			R[0] = x;
  			R[1] = y;
  			R[2] = z;
b710b044   Pavel Govyadinov   Added more tempor...
670
671
  		}
  		
f304d6de   Pavel Govyadinov   added rotation to...
672
673
674
  		///@param dir, the vector to which we are rotating
  		///given a vector to align to, finds the required
  		///axis and angle for glRotatef
5eeaf941   Pavel Govyadinov   changer to the ba...
675
  		stim::vec<float>
f304d6de   Pavel Govyadinov   added rotation to...
676
677
  		getRotation(stim::vec<float> dir)
  		{
d4721000   Pavel Govyadinov   changes with debu...
678
679
680
681
  			stim::vec<float> out(0.0,0.0,0.0,0.0);
  			stim::vec<float> from(0.0,0.0,1.0);
  			out[0] = acos(dir.dot(from))*180/M_PI;
  			if(out[0] < 1.0){
f304d6de   Pavel Govyadinov   added rotation to...
682
683
684
685
686
  				out[0] = 0.0;
  				out[1] = 0.0;
  				out[2] = 0.0;
  				out[3] = 1.0;
  			} else {
d4721000   Pavel Govyadinov   changes with debu...
687
  				stim::vec<float> temp(0.0, 0.0, 0.0);;
f304d6de   Pavel Govyadinov   added rotation to...
688
689
690
691
692
  				temp = (from.cross(dir)).norm();
  				out[1] = temp[0];
  				out[2] = temp[1];
  				out[3] = temp[2];
  			}
f304d6de   Pavel Govyadinov   added rotation to...
693
694
  			return out;
  		}
f304d6de   Pavel Govyadinov   added rotation to...
695
  		
db3c28c9   Pavel Govyadinov   Implemented glDis...
696
697
  		///Function to get back the framebuffer Object attached to the spider.
  		///For external access.
a9b45efe   Pavel Govyadinov   changes to spider
698
699
700
701
702
  		GLuint
  		getFB()
  		{
  			return fboID;
  		}
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
703
  
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
704
705
706
707
708
709
710
711
712
  //--------------------------------------------------------------------------//
  //-----------------------------TEMPORARY METHODS----------------------------//
  //--------------------------------------------------------------------------//
  
  		///temporary Method necessary for visualization and testing.
  		void
  		Update()
  		{
  			vec<float> Y(1.0,0.0,0.0);
8e56a0a7   Pavel Govyadinov   Added the propose...
713
  			if(cos(Y.dot(d))< 0.087){
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
714
  				Y[0] = 0.0; Y[1] = 1.0;}
8e56a0a7   Pavel Govyadinov   Added the propose...
715
716
717
  			hor = stim::rect<float>(m, p, d.norm(),
  				((Y.cross(d)).cross(d)).norm());
  			ver = stim::rect<float>(m, p, d.norm(),
266aa74a   Pavel Govyadinov   CHECKPOINT: Minor...
718
719
720
721
  				 hor.n());
  		}
  
  
13c2a7d4   Pavel Govyadinov   some changes to t...
722
723
724
  		void
  		Step()
  		{
8e56a0a7   Pavel Govyadinov   Added the propose...
725
  			Bind();
42145f38   Pavel Govyadinov   Fixed the issues ...
726
  			findOptimalDirection();
d4721000   Pavel Govyadinov   changes with debu...
727
728
  			findOptimalPosition();
  			findOptimalScale();
5eeaf941   Pavel Govyadinov   changer to the ba...
729
  //			branchDetection();
8e56a0a7   Pavel Govyadinov   Added the propose...
730
  			Unbind();
13c2a7d4   Pavel Govyadinov   some changes to t...
731
  		}
a9b45efe   Pavel Govyadinov   changes to spider
732
  
556c4e15   Pavel Govyadinov   Changed the handl...
733
734
735
736
  
  		void
  		printTransform()
  		{
8e56a0a7   Pavel Govyadinov   Added the propose...
737
  			std::cout << cT << std::endl;
b710b044   Pavel Govyadinov   Added more tempor...
738
  		}
a9b45efe   Pavel Govyadinov   changes to spider
739
  
42145f38   Pavel Govyadinov   Fixed the issues ...
740
741
742
743
744
  		/* Method for initializing the cuda devices, necessary only
  			there are multiple cuda devices */
  		void
  		initCuda()
  		{	
2a18be6d   Pavel Govyadinov   New comments and ...
745
  			stim::cudaSetDevice();
42145f38   Pavel Govyadinov   Fixed the issues ...
746
747
748
  			//GLint max;
  			//glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max);
  			//std::cout << max << std::endl;
a9b45efe   Pavel Govyadinov   changes to spider
749
  		}
f31bf86d   Pavel Govyadinov   Added skeleton fu...
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
  
  //--------------------------------------------------------------------------//
  //-----------------------------EXPERIMENTAL METHODS-------------------------//
  //--------------------------------------------------------------------------//
  
  		void
  		DrawCylinder()
  		{	 
  			 Bind();
  			 glNewList(dList+3, GL_COMPILE);
  			 float z0 = -0.5; float z1 = 0.5; float r0 = 0.5;
  			 float x,y;
  			 float xold = 0.5; float yold = 0.5;
  			 float step = 360.0/numSamples;
  		 	 int j = 0;
  			 glEnable(GL_TEXTURE_3D);
  			 glBindTexture(GL_TEXTURE_3D, texID);
  			 glBegin(GL_QUAD_STRIP);
  			 	for(float i = step; i <= 360.0; i += step)
  			 	{
  					 x=r0*cos(i*2.0*M_PI/360.0);
  					 y=r0*sin(i*2.0*M_PI/360.0);
  					 glTexCoord3f(x,y,z0); 
22e7d0c5   Pavel Govyadinov   Minor changes in ...
773
  					 glVertex2f(0.0, j*0.1+0.1);
f31bf86d   Pavel Govyadinov   Added skeleton fu...
774
  					 glTexCoord3f(x,y,z1); 
22e7d0c5   Pavel Govyadinov   Minor changes in ...
775
  					 glVertex2f(20.0, j*0.1+0.1);
f31bf86d   Pavel Govyadinov   Added skeleton fu...
776
  					 glTexCoord3f(xold,yold,z1); 
22e7d0c5   Pavel Govyadinov   Minor changes in ...
777
  					 glVertex2f(20.0, j*0.1); 
f31bf86d   Pavel Govyadinov   Added skeleton fu...
778
  					 glTexCoord3f(xold,yold,z0); 
22e7d0c5   Pavel Govyadinov   Minor changes in ...
779
  					 glVertex2f(0.0, j*0.1);
f31bf86d   Pavel Govyadinov   Added skeleton fu...
780
781
782
783
784
785
786
787
  					 xold=x;
  					 yold=y;
  					 j++;
  				}
  		      	 glEnd();  
  			 glEndList();
  			 Unbind();
  		}
4cefeb6d   Pavel Govyadinov   Changes to the re...
788
  };
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
789
790
  }
  #endif