Commit b710b044fffde82540a3bdaaa60945237faada70

Authored by Pavel Govyadinov
1 parent 266aa74a

Added more temporary methods for debugging the transformation matrix and changed…

… the positionTemplate function to do the 4-step transformation instead of 3. Added comments
Showing 2 changed files with 71 additions and 46 deletions   Show diff stats
stim/gl/gl_spider.h
... ... @@ -62,7 +62,8 @@ class gl_spider : public virtual gl_texture<T>
62 62 {
63 63 genTemplate(dirVectors, 0);
64 64 int best = getCost();
65   -
  65 + stim::vec<float> next = dirVectors[best];
  66 + // next[0] = next[0]*
66 67  
67 68 }
68 69  
... ... @@ -145,7 +146,6 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
145 146 //Loop over the samples, keeping the original position sample
146 147 //in the center of the resulting texture.
147 148  
148   - int idx;
149 149 for(int i = -dim; i <= dim; i++){
150 150 for(int j = -dim; j <= dim; j++){
151 151 //Create linear index
... ... @@ -419,37 +419,23 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
419 419 stim::vec<float, 4> rot = getRotation(direction);
420 420 glMatrixMode(GL_TEXTURE);
421 421 glLoadIdentity();
422   -
423   - glTranslatef(position[0]/512/S[1],
424   - position[1]/512/S[2],
425   - position[2]/426/S[3]);
426   - glScalef(magnitude[0]/512/S[1],
427   - magnitude[1]/512/S[2],
428   - magnitude[0]/426/S[3]);
429   - glRotatef(rot[0], rot[1], rot[2], rot[3]);
430   -
431   -/*
  422 + glScalef(1.0/512.0/0.6, 1.0/512.0/0.6, 1.0/426.0/2.0);
  423 + glGetDoublev(GL_TEXTURE_MATRIX, currentTransform);
  424 + printTransform();
432 425 glTranslatef(position[0],
433 426 position[1],
434 427 position[2]);
  428 + glGetDoublev(GL_TEXTURE_MATRIX, currentTransform);
  429 + printTransform();
435 430 glScalef(magnitude[0],
436 431 magnitude[1],
437 432 magnitude[0]);
  433 + glGetDoublev(GL_TEXTURE_MATRIX, currentTransform);
  434 + printTransform();
438 435 glRotatef(rot[0], rot[1], rot[2], rot[3]);
439   - glScalef(1/512/0.6, 1/512/0.6, 1/426/2.0); //this does not work
440   -*/
441   -
  436 + glGetDoublev(GL_TEXTURE_MATRIX, currentTransform);
  437 + printTransform();
442 438 glGetDoublev(GL_TEXTURE_MATRIX, currentTransform);
443   - int c = 0;
444   - for(int i = 0; i < 16; i++){
445   - if(c<3){
446   - std::cerr << "[" << currentTransform[i] << "]" << " ";
447   - c++;
448   - } else {
449   - std::cerr << "[" << currentTransform[i] << "]" << "\n";
450   - c = 0;
451   - }
452   - }
453 439 CHECK_OPENGL_ERROR
454 440 glMatrixMode(GL_MODELVIEW);
455 441 }
... ... @@ -637,6 +623,14 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
637 623 magnitude[1] = mag;
638 624 }
639 625  
  626 + void
  627 + setSize(int x, int y, int z)
  628 + {
  629 + R[1] = x;
  630 + R[2] = y;
  631 + R[3] = z;
  632 + }
  633 +
640 634 ///@param dir, the vector to which we are rotating
641 635 ///given a vector to align to, finds the required
642 636 ///axis and angle for glRotatef
... ... @@ -692,7 +686,17 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
692 686 findOptimalDirection();
693 687 }
694 688  
695   -
  689 + void
  690 + printTransform()
  691 + {
  692 + for(int i = 0; i < 4; i++){
  693 + std::cout << "[" << currentTransform[i] << "]" <<
  694 + "[" << currentTransform[i+4] << "]" <<
  695 + "[" << currentTransform[i+8] << "]" <<
  696 + "[" << currentTransform[i+12] << "]" <<
  697 + std::endl;
  698 + }
  699 + }
696 700  
697 701 /* Method for initializing the cuda devices, necessary only
698 702 there are multiple cuda devices */
... ...
stim/gl/gl_texture.h
... ... @@ -31,7 +31,6 @@ template&lt;typename T&gt;
31 31 class gl_texture : public virtual image_stack<T>
32 32 {
33 33 private:
34   -
35 34 ///Method: setTextureType
36 35 /// Sets the internal texture_type, based on the data
37 36 /// size. Either 3D, 2D, 1D textures.
... ... @@ -50,6 +49,10 @@ class gl_texture : public virtual image_stack&lt;T&gt;
50 49 std::string path;
51 50 GLuint texID; //OpenGL object
52 51 GLenum texture_type; //1D, 2D, 3D
  52 + GLint interpType;
  53 + GLint texWrap;
  54 + GLenum type;
  55 + GLenum format;
53 56 using image_stack<T>::R;
54 57 using image_stack<T>::S;
55 58 using image_stack<T>::ptr;
... ... @@ -61,7 +64,7 @@ class gl_texture : public virtual image_stack&lt;T&gt;
61 64 /// Creates an instance of the gl_texture object.
62 65 gl_texture()
63 66 {
64   -
  67 +
65 68 }
66 69  
67 70 ///Method: Path Constructor
... ... @@ -74,8 +77,32 @@ class gl_texture : public virtual image_stack&lt;T&gt;
74 77 image_stack<T>::load_images(path.append("/*.jpg"));
75 78 setTextureType();
76 79 }
  80 + ///Method:getSize
  81 + ///returns the dimentions of
  82 + vec<int>
  83 + getSize()
  84 + {
  85 + stim::vec<int> size(R[1], R[2], R[3]);
  86 + return size;
  87 + }
77 88  
78   -
  89 + ///Method:setTexParam
  90 + ///@param GLint interp --GL_LINEAR, GL_NEAREST...
  91 + ///@param GLint twrap --GL_REPEAR, GL_CLAMP_TO_EDGE...
  92 + ///@param GLenum dataType --GL_UNSIGNED_BYTE, GL_FLOAT16...
  93 + ///@param GLenum dataFormat--GL_LUMINANCE, GL_RGB...
  94 + /// Texture paramenters.
  95 + void
  96 + setTexParam(GLint interp = GL_LINEAR,
  97 + GLint twrap = GL_CLAMP_TO_EDGE,
  98 + GLenum dataType = GL_UNSIGNED_BYTE,
  99 + GLenum dataFormat = GL_LUMINANCE)
  100 + {
  101 + interpType = interp;
  102 + texWrap = twrap;
  103 + type = dataType;
  104 + format = dataFormat;
  105 + }
79 106 ///Method:setDims
80 107 ///@param x size of the voxel in x direction
81 108 ///@param y size of the voxel in y direction
... ... @@ -148,23 +175,23 @@ class gl_texture : public virtual image_stack&lt;T&gt;
148 175 glBindTexture(texture_type, texID);
149 176 glTexParameteri(texture_type,
150 177 GL_TEXTURE_MIN_FILTER,
151   - GL_LINEAR);
  178 + interpType);
152 179 glTexParameteri(texture_type,
153 180 GL_TEXTURE_MAG_FILTER,
154   - GL_LINEAR);
  181 + interpType);
155 182 switch(texture_type)
156 183 {
157 184 case GL_TEXTURE_3D:
158 185 glTexParameteri(texture_type,
159   - GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
  186 + GL_TEXTURE_WRAP_S,texWrap);
160 187 // GL_REPEAT);
161 188 // GL_CLAMP_TO_EDGE);
162 189 glTexParameteri(texture_type,
163   - GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
  190 + GL_TEXTURE_WRAP_T,texWrap);
164 191 // GL_REPEAT);
165 192 // GL_CLAMP_TO_EDGE);
166 193 glTexParameteri(texture_type,
167   - GL_TEXTURE_WRAP_R,GL_CLAMP_TO_EDGE);
  194 + GL_TEXTURE_WRAP_R,texWrap);
168 195 // GL_REPEAT);
169 196 // GL_CLAMP_TO_EDGE);
170 197 glTexImage3D(texture_type,
... ... @@ -175,25 +202,25 @@ class gl_texture : public virtual image_stack&lt;T&gt;
175 202 R[2],
176 203 R[3],
177 204 0,
178   - GL_LUMINANCE,
179   - GL_UNSIGNED_BYTE,
  205 + format,
  206 + type,
180 207 ptr);
181 208 //GL_UNSIGNED_BYTE can be TYPES, convert to GL equivalents
182 209 glPixelStorei(GL_PACK_ALIGNMENT,1);
183 210 break;
184 211 case GL_TEXTURE_2D:
185 212 glTexParameteri(texture_type,
186   - GL_TEXTURE_WRAP_S, GL_REPEAT);
  213 + GL_TEXTURE_WRAP_S, texWrap);
187 214 glTexParameteri(texture_type,
188   - GL_TEXTURE_WRAP_T, GL_REPEAT);
  215 + GL_TEXTURE_WRAP_T, texWrap);
189 216 glTexImage2D(texture_type,
190 217 0,
191 218 1,
192 219 R[1],
193 220 R[2],
194 221 0,
195   - GL_LUMINANCE,
196   - GL_UNSIGNED_BYTE,
  222 + format,
  223 + type,
197 224 ptr);
198 225 break;
199 226 }
... ... @@ -207,12 +234,6 @@ class gl_texture : public virtual image_stack&lt;T&gt;
207 234 return ptr;
208 235 }
209 236  
210   - stim::vec<int>
211   - getSize()
212   - {
213   - stim::vec<int> size(R[1], R[2], R[3]);
214   - return size;
215   - }
216 237  
217 238 };
218 239 }
... ...