Commit 957a42488994eb7bf04c8c447f6ca5777f1c3f6b

Authored by Pavel Govyadinov
1 parent 5e7c7581

renamed getSample to positionTemplate for clarity, fixed the positionTemplate me…

…thod, now works with translation and scaling, added more debugging code to print out information to console. overloaded positionTemplate for easier testing.
Showing 1 changed file with 57 additions and 30 deletions   Show diff stats
stim/gl/gl_spider.h
... ... @@ -54,7 +54,7 @@ class gl_spider : public virtual gl_texture<T>
54 54 Not sure if necessary since the next position for the spider
55 55 will be at direction * magnitude. */
56 56  
57   - getSample(position, direction, magnitude);
  57 + positionTemplate(position, direction, magnitude);
58 58 int best = getCost();
59 59 }
60 60  
... ... @@ -74,7 +74,7 @@ class gl_spider : public virtual gl_texture<T>
74 74 /* Method for finding the best scale for the spider.
75 75 changes the x, y, z size of the spider to minimize the cost
76 76 function. */
77   - getSample(position, direction, magnitude);
  77 + //getSample(position, direction, magnitude);
78 78 genTemplate(dirVectors, 0);
79 79 int bets = getCost();
80 80 //getSample(position, direction, magnitude);
... ... @@ -139,6 +139,10 @@ class gl_spider : public virtual gl_texture<T>
139 139 // p1[1]/S[2],
140 140 // p1[2]/S[3]
141 141 // );
  142 + // ((p1[0]*magnitude[1])+position[0])/512/0.6,
  143 + // ((p1[1]*magnitude[1])+position[1])/512/0.6,
  144 + // ((p1[2]*magnitude[1])+position[2])/426/2.0
  145 +
142 146 p1[0],
143 147 p1[1],
144 148 p1[2]
... ... @@ -149,6 +153,9 @@ class gl_spider : public virtual gl_texture<T>
149 153 // p2[0]/S[1],
150 154 // p2[1]/S[2],
151 155 // p2[2]/S[3]
  156 + // ((p2[0]*magnitude[1])+position[0])/512/0.6,
  157 + // ((p2[1]*magnitude[1])+position[1])/512/0.6,
  158 + // ((p2[2]*magnitude[1])+position[2])/426/2.0
152 159 p2[0],
153 160 p2[1],
154 161 p2[2]
... ... @@ -159,6 +166,9 @@ class gl_spider : public virtual gl_texture<T>
159 166 // p2[0]/S[1],
160 167 // p2[1]/S[2],
161 168 // p2[2]/S[3]
  169 + // ((p3[0]*magnitude[1])+position[0])/512/0.6,
  170 + // ((p3[1]*magnitude[1])+position[1])/512/0.6,
  171 + // ((p3[2]*magnitude[1])+position[2])/426/2.0
162 172 p3[0],
163 173 p3[1],
164 174 p3[2]
... ... @@ -172,6 +182,9 @@ class gl_spider : public virtual gl_texture<T>
172 182 p4[0],
173 183 p4[1],
174 184 p4[2]
  185 + // ((p4[0]*magnitude[1])+position[0])/512/0.6,
  186 + // ((p4[1]*magnitude[1])+position[1])/512/0.6,
  187 + // ((p4[2]*magnitude[1])+position[2])/426/2.0
175 188 );
176 189 //glVertex2f(0.0, 2.0);
177 190 glVertex2f(v_x, v_y+len);
... ... @@ -247,7 +260,8 @@ class gl_spider : public virtual gl_texture<T>
247 260 vec<float> mag(1.0, 1.0, 1.0);
248 261 switch(type) {
249 262 case 0: //Direction
250   - Bind();
  263 + Bind();
  264 + positionTemplate();
251 265 for(int i = 0; i < in.size(); i++)
252 266 {
253 267 if(cos(Y.dot(in[i]))< 0.087){ Y[0] = 0.0; Y[1] = 1.0;}
... ... @@ -262,6 +276,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
262 276 // std::cout<< (x+i*10.0) << std::endl;
263 277 UpdateBuffer(x, x+i*10.0);
264 278 }
  279 + //getSample();
265 280 Unbind();
266 281 break;
267 282 case 1: //Position
... ... @@ -326,9 +341,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
326 341 glBindTexture(GL_TEXTURE_2D, texbufferID);
327 342 glClearColor(1,1,1,1);
328 343 glClear(GL_COLOR_BUFFER_BIT);
329   - glMatrixMode(GL_TEXTURE);
330   - glLoadIdentity();
331   - getSample(position, direction, magnitude);
  344 + //glMatrixMode(GL_TEXTURE);
332 345 glMatrixMode(GL_PROJECTION);
333 346 glLoadIdentity();
334 347 glMatrixMode(GL_MODELVIEW);
... ... @@ -337,6 +350,13 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
337 350 gluOrtho2D(0.0,2.0*len,0.0,numSamples*len);
338 351 glEnable(GL_TEXTURE_3D);
339 352 glBindTexture(GL_TEXTURE_3D, texID);
  353 +
  354 +
  355 + //glScalef(1/512/S[1], 1/512/S[2], 1/426/S[3]);
  356 + //glLoadIdentity();
  357 + //glViewport(0,0,2.0*len, numSamples*len);
  358 + //gluOrtho2D(0.0,2.0*len,0.0,numSamples*len);
  359 +
340 360 CHECK_OPENGL_ERROR
341 361 }
342 362  
... ... @@ -485,8 +505,8 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
485 505 setPosition(0.0,0.0,0.0);
486 506 setDirection(0.0,0.0,1.0);
487 507 setMagnitude(1.0);
488   - numSamples = 1089;
489   - //numSamples = 9;
  508 + //numSamples = 1089;
  509 + numSamples = 9;
490 510 std::cout << "I did this" <<std::endl;
491 511 }
492 512 gl_spider
... ... @@ -522,7 +542,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
522 542 genPositionVectors();
523 543 genMagnitudeVectors();
524 544 gl_texture<T>::setDims(0.6, 0.6, 2.0);
525   - getSample(position, direction, magnitude);
  545 + //getSample(position, direction, magnitude);
526 546 genTemplate(dirVectors, 0);
527 547 std::cout << S[1] << ":" << S[2] << ":" << S[3] << std::endl;
528 548 //gl_texture<T>::setDims(1.0, 1.0,1.0);
... ... @@ -582,31 +602,33 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
582 602 position[2] = z;
583 603 }
584 604  
585   - void getSample(vec<float> pos, vec<float> dir, vec<float> mag)
  605 + void positionTemplate(vec<float> pos, vec<float> dir, vec<float> mag)
586 606 {
587 607 //Bind();
588   - stim::vec<float>p1;
589   - stim::vec<float>p2;
590   - stim::vec<float>p3;
591   - stim::vec<float>p4;
592   - p1 = hor.p(1,1);
593   - p2 = hor.p(1,0);
594   - p3 = hor.p(0,0);
595   - p4 = hor.p(0,1);
  608 +
  609 + //stim::vec<float>p1;
  610 + //stim::vec<float>p2;
  611 + //stim::vec<float>p3;
  612 + //stim::vec<float>p4;
  613 + //p1 = hor.p(1,1);
  614 + //p2 = hor.p(1,0);
  615 + //p3 = hor.p(0,0);
  616 + //p4 = hor.p(0,1);
596 617 glMatrixMode(GL_TEXTURE);
597 618 glLoadIdentity();
598   - //glScalef(0.005,0.005, 0.005);
599   - glScalef(mag[0], mag[1], mag[0]);
600   - //glRotatef(30, 0.0, 0.0, 1.0);
601   - //glRotatef(roty, 0.0, 1.0, 0.0);
602   - //glRotatef(rotx, 1.0, 0.0 ,0.0);
603   - glTranslatef(pos[0], pos[1], pos[2]);
604   - glScalef(1/512/S[1], 1/512/S[2], 1/426/S[3]);
  619 + //glTranslatef(pos[0], pos[1], pos[2]);
  620 + //glScalef(mag[0], mag[1], mag[0]);
  621 +
  622 + //glScalef(1/512/S[1], 1/512/S[2], 1/426/S[3]);
  623 + //glMatrixMode(GL_TEXTURE);
  624 + //glLoadIdentity();
  625 + glTranslatef(position[0]/512/S[1], position[1]/512/S[2], position[2]/426/S[3]);
  626 + glScalef(magnitude[0]/512/S[1], magnitude[1]/512/S[2], magnitude[0]/426/S[3]);
605 627 std::cout << "DEBUG: gl_spider::605" << std::endl;
606 628 std::cout << "pos: " << position << std::endl;
607 629 std::cout << "dir: " << direction << std::endl;
608 630 std::cout << "mag: " << magnitude << std::endl;
609   - std::cout << "Before Transformation" << std::endl;
  631 + /*std::cout << "Before Transformation" << std::endl;
610 632 std::cout << p1 << ":" << p2 << ":" << p3 << ":" << p4 << std::endl;
611 633 std::cout << "After Transformation" << std::endl;
612 634 std::cout << "[" << (p1[0]+pos[0])/512/S[1] << ", "
... ... @@ -620,12 +642,17 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
620 642 << (p3[2]+pos[2])/426/S[3] << "]" << ":"
621 643 << "[" << (p4[0]+pos[0])/512/S[1] << ", "
622 644 << (p4[1]+pos[1])/512/S[2] << ", "
623   - << (p4[2]+pos[2])/426/S[3] << "]" << std::endl;
624   -
625   - //glMatrixMode(GL_MODELVIEW);
  645 + << (p4[2]+pos[2])/426/S[3] << "]" << std::endl;*/
  646 + //GLdouble mat[16];
  647 + //glGetDoublev(GL_TEXTURE, mat);
  648 + glMatrixMode(GL_MODELVIEW);
626 649 //Unbind();
627 650 }
628   -
  651 +
  652 + void positionTemplate()
  653 + {
  654 + positionTemplate(position, direction, magnitude);
  655 + }
629 656 ///@param vector dir, the new direction.
630 657 ///Sets the direction vector to input vector dir.
631 658 void
... ...