Blame view

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