Commit 14b500f9c8e06a32af40f9093d94be370d3837b4

Authored by Pavel Govyadinov
1 parent 79a9bf3f

minor bug fixes

stim/gl/gl_spider.h
... ... @@ -245,6 +245,7 @@ class gl_spider
245 245 ///uses the default m <1,1,0>
246 246 void
247 247 genMagnitudeVectors(float delta = 0.70)
  248 +// genMagnitudeVectors(float delta = 0.50)
248 249 {
249 250  
250 251 //Set up the vectors necessary for Rectangle creation.
... ... @@ -725,12 +726,12 @@ class gl_spider
725 726 int
726 727 Step()
727 728 {
728   - // Bind();
  729 + Bind();
729 730 findOptimalDirection();
730 731 findOptimalPosition();
731 732 findOptimalScale();
732 733 // branchDetection();
733   - // Unbind();
  734 + Unbind();
734 735 return current_cost;
735 736 }
736 737  
... ...
stim/visualization/glObj.h
1 1 #ifndef STIM_GLOBJ_H
2 2 #define STIM_GLOBJ_H
3 3  
4   -#include <stim/visualization/obj.h>
5 4 #include <GL/glew.h>
6 5 #include <GL/glut.h>
7 6 #include <stim/math/vector.h>
  7 +#include <stim/visualization/obj.h>
8 8  
9 9  
10 10 namespace stim
... ... @@ -13,23 +13,25 @@ namespace stim
13 13 * Assist with the visualization the segmented vessels.
14 14 * Uses
15 15 */
16   -
17   -class objGl : public virtual stim::obj<T>
  16 +template <typename T>
  17 +class glObj : public virtual stim::obj<T>
18 18 {
19 19 private:
20 20 using stim::obj<T>::L;
21 21 using stim::obj<T>::P;
22 22 using stim::obj<T>::F;
23   - using vec<T>::size;
24   - using vec<T>::at;
  23 +// using stim::obj<T>::numL();
  24 +// using std::vector<T>::size;
  25 +// using std::vector<T>::at;
25 26 GLuint dList;
26 27  
27 28  
28 29 void
29   - init
  30 + init()
30 31 {
31   - dList = glGenList(1);
  32 + dList = glGenLists(1);
32 33 glListBase(dList);
  34 +
33 35 glMatrixMode(GL_PROJECTION);
34 36 glLoadIdentity;
35 37 glMatrixMode(GL_MODELVIEW);
... ... @@ -40,15 +42,17 @@ private:
40 42 void
41 43 Create()
42 44 {
43   - int len = (int) numL();
  45 + int len = (int) stim::obj<T>::numL();
44 46 std::vector< stim::vec<float> > line;
45 47 glNewList(dList, GL_COMPILE);
46   - glColor3f(0.5, 1.0, 0.5);
  48 + // glColor3f(0.0, 1.0, 0.0);
  49 + glLineWidth(2.5);
47 50 for(int i = 0; i < len; i++){
48   - line = getL_V(i);
49   - glBegin(GL_LINES);
  51 + line = stim::obj<T>::getL_V(i);
  52 + glColor3ub(rand()%255, rand()%255, rand()%255);
  53 + glBegin(GL_LINE_STRIP);
50 54 for(int j = 0; j < line.size(); j++){
51   - glVectex3f(
  55 + glVertex3f(
52 56 line[j][0],
53 57 line[j][1],
54 58 line[j][2]
... ... @@ -57,16 +61,33 @@ private:
57 61 glEnd();
58 62 }
59 63 glEndList();
  64 + CHECK_OPENGL_ERROR
60 65 }
61 66  
62 67 public:
63   - objGl(std::string filename)
  68 + glObj()
64 69 {
65   - stim::obj::load(filename);
66   - glPopMatrix(); //Safety Operation to avoid changing the current matrix.
  70 +
  71 + }
  72 +
  73 + void
  74 + createFromSelf()
  75 + {
  76 + // glPopMatrix();
67 77 init();
68 78 Create();
69   - glPushMatrix();
  79 + // glPushMatrix();
  80 + }
  81 +
  82 + void
  83 + createFromFile(std::string filename)
  84 + {
  85 + stim::obj<T>::load(filename);
  86 + glPushMatrix(); //Safety Operation to avoid changing the current matrix.
  87 + init();
  88 + Create();
  89 + glPopMatrix();
  90 + CHECK_OPENGL_ERROR
70 91 }
71 92  
72 93  
... ... @@ -74,7 +95,44 @@ public:
74 95 Render()
75 96 {
76 97 glCallList(dList);
  98 + CHECK_OPENGL_ERROR
77 99 }
78 100  
  101 + void
  102 + RenderLine(int i)
  103 + {
  104 + std::vector < stim::vec<T> > line;
  105 + int len = (int) stim::obj<T>::numL();
  106 + line = stim::obj<T>::getL_V(i);
  107 + glColor3f(0.5, 1.0, 0.5);
  108 + glLineWidth(3.0);
  109 + glBegin(GL_LINE_STRIP);
  110 + for(int j = 0; j < line.size(); j++){
  111 + glVertex3f(
  112 + line[j][0],
  113 + line[j][1],
  114 + line[j][2]
  115 + );
  116 + }
  117 + glEnd();
  118 + }
  119 +
  120 + void
  121 + RenderLine(std::vector< stim::vec<T> > l)
  122 + {
  123 + glColor3f(0.5, 1.0, 0.5);
  124 + glLineWidth(3.0);
  125 + glBegin(GL_LINE_STRIP);
  126 + for(int j = 0; j < l.size(); j++){
  127 + glVertex3f(
  128 + l[j][0],
  129 + l[j][1],
  130 + l[j][2]
  131 + );
  132 + }
  133 + glEnd();
  134 + }
  135 +
  136 +};
79 137 }
80   -}
  138 +#endif
... ...
stim/visualization/obj.h
... ... @@ -324,26 +324,27 @@ public:
324 324  
325 325 /// This function terminates drawing of a primitive object, such as a line, face, or point set
326 326 void End(){
327   -
328 327 //copy the current object to the appropriate list
329   - switch(current_type){
  328 + if(current_geo.size() != 0)
  329 + {
  330 + switch(current_type){
330 331  
331   - case OBJ_NONE:
332   - std::cout<<"STIM::OBJ error, objEnd() called before objBegin()."<<std::endl;
333   - break;
  332 + case OBJ_NONE:
  333 + std::cout<<"STIM::OBJ error, objEnd() called before objBegin()."<<std::endl;
  334 + break;
334 335  
335   - case OBJ_POINTS:
336   - P.push_back(current_geo);
337   - break;
  336 + case OBJ_POINTS:
  337 + P.push_back(current_geo);
  338 + break;
338 339  
339   - case OBJ_LINE:
340   - L.push_back(current_geo);
341   - break;
  340 + case OBJ_LINE:
  341 + L.push_back(current_geo);
  342 + break;
342 343  
343   - case OBJ_FACE:
344   - F.push_back(current_geo);
  344 + case OBJ_FACE:
  345 + F.push_back(current_geo);
  346 + }
345 347 }
346   -
347 348 //clear everything
348 349 current_type = OBJ_NONE;
349 350 current_geo.clear();
... ... @@ -352,6 +353,12 @@ public:
352 353 geo_flag_vt = false;
353 354 geo_flag_vn = false;
354 355 }
  356 +//temporary convenience method
  357 + void rev(){
  358 + if(current_geo.size() != 0)
  359 + // current_geo.reverse(current_geo.begin(), current_geo.end());
  360 + std::reverse(current_geo.begin(), current_geo.end());
  361 + }
355 362  
356 363 //output the OBJ structure as a string
357 364 std::string str(){
... ... @@ -556,7 +563,6 @@ public:
556 563  
557 564 //get the number of points in the specified line
558 565 unsigned int nP = L[i].size();
559   -
560 566 //create a vector of points
561 567 std::vector< stim::vec<T> > l;
562 568  
... ... @@ -602,6 +608,7 @@ public:
602 608 return l;
603 609 }
604 610  
  611 +
605 612 /// Returns a vector containing the list of texture coordinates associated with each point of a line.
606 613  
607 614 /// @param i is the index of the desired line
... ...