Commit d4721000325e5bca5cb21ea8f7ed9d43b58203b5

Authored by Pavel Govyadinov
1 parent a81d396e

changes with debugging comments

Showing 2 changed files with 80 additions and 29 deletions   Show diff stats
stim/gl/gl_spider.h
... ... @@ -64,6 +64,7 @@ class gl_spider
64 64 findOptimalDirection()
65 65 {
66 66 //genTemplate(dV, 0);
  67 + cout << "|||||||||||DIRECTION||||||||: " << endl;
67 68 cout << "Direction Before: " << d << endl;
68 69 setMatrix();
69 70 glCallList(dList);
... ... @@ -72,14 +73,17 @@ class gl_spider
72 73 dV[best][0]*S[0]*R[0],
73 74 dV[best][1]*S[1]*R[1],
74 75 dV[best][2]*S[2]*R[2],
75   - 1);
  76 + 0);
  77 + cout << "Best Vector: " << next << endl;
76 78 next = (cT*next).norm();
  79 + cout << "Best Vector after Mat Mult: " << next << endl;
77 80 //next = (cT*next);
78 81 setPosition( p[0]+next[0]*m[0]/stepsize,
79 82 p[1]+next[1]*m[0]/stepsize,
80 83 p[2]+next[2]*m[0]/stepsize);
81 84 setDirection(next[0], next[1], next[2]);
82 85 cout << "Direction After: " << d << endl;
  86 + cout << "Direction After: " << d << endl;
83 87 }
84 88  
85 89 /// Method for finding the best d for the spider.
... ... @@ -88,6 +92,7 @@ class gl_spider
88 92 void
89 93 findOptimalPosition()
90 94 {
  95 + cout << "|||||||||||POSITION||||||||: " << endl;
91 96 setMatrix();
92 97 glCallList(dList+1);
93 98 int best = getCost();
... ... @@ -96,11 +101,18 @@ class gl_spider
96 101 pV[best][1],
97 102 pV[best][2],
98 103 1);
  104 + cout << "Best Vector: " << next << endl;
99 105 next = cT*next;
100   - setPosition( next[0]*S[0]*R[0],
  106 + cout << "Best Vector after mat mult: " << next << endl;
  107 + cout << "Best Vector after conversion:" << "[" << next[0]*S[0]*R[0]
  108 + << ", " << next[1]*S[1]*R[1] << ", " << next[2]*S[2]*R[2] << "]" << endl;
  109 + setPosition(
  110 + next[0]*S[0]*R[0],
101 111 next[1]*S[1]*R[1],
102   - next[2]*S[2]*R[2]);
  112 + next[2]*S[2]*R[2]
  113 + );
103 114 std::cout << "Optimal p:"<< p << std::endl;
  115 + cout << "Final Position: " << p << endl;
104 116 }
105 117  
106 118 /// Method for finding the best scale for the spider.
... ... @@ -112,14 +124,15 @@ class gl_spider
112 124 setMatrix();
113 125 glCallList(dList+2);
114 126 int best = getCost();
115   - stim::vec<float> next(
116   - mV[best][0]*S[0]*R[0],
117   - mV[best][1]*S[1]*R[1],
118   - mV[best][2]*S[2]*R[2],
119   - 1);
120   - next = cT*next;
121   - std::cout << "Optimal Scale:"<< next << std::endl;
122   - setMagnitude(next[0]);
  127 + //stim::vec<float> next(
  128 + //mV[best][0]*S[0]*R[0],
  129 + //mV[best][1]*S[1]*R[1],
  130 + //mV[best][2]*S[2]*R[2],
  131 + //1);
  132 + //next = cT*next;
  133 + std::cout << "Optimal Scale:"<< m[0]*mV[best][0] << std::endl;
  134 + //setMagnitude(next[0]);
  135 + setMagnitude(m[0]*mV[best][0]);
123 136 }
124 137  
125 138 void
... ... @@ -220,7 +233,8 @@ class gl_spider
220 233 int dim = (sqrt(numSamples)-1)/2;
221 234 stim::rect<float> samplingPlane =
222 235 stim::rect<float>(p, d);
223   - samplingPlane.scale(m[0]*delta, m[0]*delta);
  236 + cout << "Final Position: " << p << endl;
  237 + samplingPlane.scale(mag[0]*delta, mag[0]*delta);
224 238 float step = 1.0/(dim);
225 239  
226 240 //Loop over the samples, keeping the original p sample
... ... @@ -276,7 +290,7 @@ class gl_spider
276 290 glNewList(dList+2, GL_COMPILE);
277 291 for(int i = 0; i < numSamples; i++){
278 292 //Create linear index
279   - factor = (min+step*i)*m[0];
  293 + factor = (min+step*i)*mag[0];
280 294 temp = factor;
281 295 mV.push_back(temp);
282 296 hor = stim::rect<float>(temp,
... ... @@ -442,20 +456,34 @@ class gl_spider
442 456 ///Based on the p of the spider in real space (arbitrary).
443 457 void setMatrix()
444 458 {
  459 + float curTrans[16];
445 460 stim::vec<float> rot = getRotation(d);
446 461 glMatrixMode(GL_TEXTURE);
447 462 glLoadIdentity();
448   -
449   - glRotatef(rot[0], rot[1], rot[2], rot[3]);
450 463 glScalef(1.0/S[0]/R[0], 1.0/S[1]/R[1], 1.0/S[2]/R[2]);
  464 + //std::cout << "Scale by 1/S/R" << std::endl;
  465 + //glGetFloatv(GL_TEXTURE_MATRIX, curTrans);
  466 + //cT.set(curTrans);
  467 + //printTransform();
  468 +
  469 +
451 470 glTranslatef(p[0],
452 471 p[1],
453 472 p[2]);
  473 + // std::cout << "Translate" << std::endl;
  474 + // glGetFloatv(GL_TEXTURE_MATRIX, curTrans);
  475 + // cT.set(curTrans);
  476 + // printTransform();
  477 +
  478 + // std::cout << "Rotation" << std::endl;
  479 + // glGetFloatv(GL_TEXTURE_MATRIX, curTrans);
  480 + // cT.set(curTrans);
  481 + // printTransform();
  482 + glRotatef(rot[0], rot[1], rot[2], rot[3]);
454 483 glScalef(m[0],
455   - m[1],
  484 + m[0],
456 485 m[0]);
457   -
458   - float curTrans[16];
  486 + std::cout << "ScaleTemp" << std::endl;
459 487 glGetFloatv(GL_TEXTURE_MATRIX, curTrans);
460 488 cT.set(curTrans);
461 489 printTransform();
... ... @@ -540,7 +568,7 @@ class gl_spider
540 568 {
541 569 p = vec<float>(pos_x, pos_y, pos_z);
542 570 d = vec<float>(dir_x, dir_y, dir_z);
543   - m = vec<float>(mag_x, mag_x);
  571 + m = vec<float>(mag_x, mag_x, mag_x);
544 572 S = vec<float>(1.0,1.0,1.0);
545 573 R = vec<float>(1.0,1.0,1.0);
546 574 //setPosition(pos_x, pos_y, pos_z);
... ... @@ -573,7 +601,7 @@ class gl_spider
573 601 dList = glGenLists(3);
574 602 glListBase(dList);
575 603 Bind();
576   - genDirectionVectors(5*M_PI/4);
  604 + genDirectionVectors(M_PI);
577 605 genPositionVectors();
578 606 genMagnitudeVectors();
579 607 DrawCylinder();
... ... @@ -660,6 +688,7 @@ class gl_spider
660 688 {
661 689 m[0] = mag;
662 690 m[1] = mag;
  691 + m[2] = mag;
663 692 }
664 693  
665 694  
... ... @@ -685,21 +714,31 @@ class gl_spider
685 714 stim::vec<float>
686 715 getRotation(stim::vec<float> dir)
687 716 {
688   - stim::vec<float> out(0,0,0,0);;
689   - stim::vec<float> from(0,0,1);
690   - out[0] = acos(from.dot(dir))*M_PI/180;
691   - if(out[0] < 0.0001){
  717 + stim::vec<float> out(0.0,0.0,0.0,0.0);
  718 + stim::vec<float> from(0.0,0.0,1.0);
  719 + out[0] = acos(dir.dot(from))*180/M_PI;
  720 + if(out[0] < 1.0){
692 721 out[0] = 0.0;
693 722 out[1] = 0.0;
694 723 out[2] = 0.0;
695 724 out[3] = 1.0;
696 725 } else {
697   - stim::vec<float> temp;
  726 + stim::vec<float> temp(0.0, 0.0, 0.0);;
698 727 temp = (from.cross(dir)).norm();
699 728 out[1] = temp[0];
700 729 out[2] = temp[1];
701 730 out[3] = temp[2];
702 731 }
  732 + std::cout << "Theta = " << out[0] << std::endl;
  733 +/* stim::vec<float> rot = from.cross(dir);
  734 + float theta = asin(rot.len());
  735 + if(theta == 0){
  736 + rot = rot.norm();
  737 + }
  738 + out[0] = theta;
  739 + out[1] = rot[0];
  740 + out[2] = rot[1];
  741 + out[3] = rot[2]; */
703 742 return out;
704 743 }
705 744  
... ... @@ -734,8 +773,8 @@ class gl_spider
734 773 {
735 774 Bind();
736 775 findOptimalDirection();
737   - //findOptimalPosition();
738   - //findOptimalScale();
  776 + findOptimalPosition();
  777 + findOptimalScale();
739 778 // branchDetection();
740 779 Unbind();
741 780 }
... ...
stim/math/mathvec.h
... ... @@ -19,6 +19,7 @@ struct vec : public std::vector&lt;T&gt;
19 19 using std::vector<T>::at;
20 20 using std::vector<T>::resize;
21 21 using std::vector<T>::push_back;
  22 +
22 23 vec(){
23 24  
24 25 }
... ... @@ -170,8 +171,6 @@ struct vec : public std::vector&lt;T&gt;
170 171 /// Computes the cross product of a 3-dimensional vector
171 172 vec<T> cross(const vec<T> rhs) const
172 173 {
173   - if(size() != 3)
174   - std::cout<<"Error in stim::mathvec::cross() - the vector must have 3 components"<<std::endl;
175 174  
176 175 vec<T> result(3);
177 176  
... ... @@ -237,6 +236,19 @@ struct vec : public std::vector&lt;T&gt;
237 236  
238 237 return result;
239 238 }
  239 + /// Arithmetic subtraction to a scalar
  240 +
  241 + /// @param rhs is the right-hand-side operator for the addition
  242 + vec<T> operator-(T rhs) const
  243 + {
  244 + unsigned int N = size();
  245 +
  246 + vec<T> result(N);
  247 + for(int i=0; i<N; i++)
  248 + result[i] = at(i) - rhs;
  249 +
  250 + return result;
  251 + }
240 252  
241 253 /// Arithmetic scalar multiplication operator
242 254  
... ...