Commit b745544ec121473fcd351a5a890d4d2ff1ffeb49
Merge branch 'JACK' into 'master'
Jack See merge request !10
Showing
1 changed file
with
144 additions
and
28 deletions
Show diff stats
main.cu
@@ -67,16 +67,18 @@ std::vector<float> colormap; | @@ -67,16 +67,18 @@ std::vector<float> colormap; | ||
67 | // special key indicator | 67 | // special key indicator |
68 | int mods; | 68 | int mods; |
69 | 69 | ||
70 | -// create display lists | ||
71 | -GLuint dlist1; | ||
72 | -GLuint dlist2; | ||
73 | - | ||
74 | //OpenGL objects | 70 | //OpenGL objects |
75 | GLuint cmap_tex = 0; //texture name for the color map | 71 | GLuint cmap_tex = 0; //texture name for the color map |
76 | 72 | ||
77 | float delta; | 73 | float delta; |
78 | float sigma = 3; //default sigma | 74 | float sigma = 3; //default sigma |
79 | float radius = 3; //equals to radius | 75 | float radius = 3; //equals to radius |
76 | +int adjoint_fac = 0; | ||
77 | +int light_fac = 0; | ||
78 | + | ||
79 | +//light position | ||
80 | +stim::vec3<float> l1(0.0, 0.0, 0.0); | ||
81 | +stim::vec3<float> l2(0.0, 0.0, 0.0); | ||
80 | 82 | ||
81 | //sets an OpenGL viewport taking up the entire window | 83 | //sets an OpenGL viewport taking up the entire window |
82 | void glut_render_single_projection(){ | 84 | void glut_render_single_projection(){ |
@@ -128,6 +130,50 @@ void glut_render_modelview(){ | @@ -128,6 +130,50 @@ void glut_render_modelview(){ | ||
128 | //draws the network(s) | 130 | //draws the network(s) |
129 | void glut_render(void) { | 131 | void glut_render(void) { |
130 | 132 | ||
133 | + // light | ||
134 | + stim::vec3<float> eye = cam.getPosition(); //get the camera position (eye point) | ||
135 | + if (l1[0] + l1[1] + l1[2] + l2[0] + l2[1] + l2[2] == 0) { | ||
136 | + stim::vec3<float> s = bb.size(); | ||
137 | + | ||
138 | + l1[0] = eye[0] + s[0] / 2; | ||
139 | + l1[1] = eye[1] + s[1] / 2; | ||
140 | + l1[2] = eye[2] + s[2] / 2; | ||
141 | + l2[0] = eye[0] - s[0] / 2; | ||
142 | + l2[1] = eye[1] - s[1] / 2; | ||
143 | + l2[2] = eye[2] - s[2] / 2; | ||
144 | + } | ||
145 | + | ||
146 | + GLfloat global_ambient[] = { 0.3, 0.3, 0.3, 1.0 }; | ||
147 | + GLfloat ambient[] = { 0.0, 0.0, 0.0, 1.0 }; | ||
148 | + GLfloat diffuse1[] = { 0.6, 0.6, 0.6, 1.0 }; | ||
149 | + GLfloat diffuse2[] = { 0.4, 0.4, 0.4, 1.0 }; | ||
150 | + GLfloat specular[] = { 0.6, 0.6, 0.6, 1.0 }; | ||
151 | + GLfloat position1[] = { l1[0], l1[1], 50, 0.0 }; // upper right light source | ||
152 | + GLfloat position2[] = { l2[0], l2[1], 0, 0.0 }; // lower left light source | ||
153 | + GLfloat position[] = { eye[0], eye[1], 50, 1.0 }; | ||
154 | + | ||
155 | + glClearColor(0.0, 0.0, 0.0, 1.0); | ||
156 | + glShadeModel(GL_SMOOTH); | ||
157 | + | ||
158 | + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient); | ||
159 | + | ||
160 | + glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); | ||
161 | + glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse1); | ||
162 | + glLightfv(GL_LIGHT0, GL_SPECULAR, specular); | ||
163 | + glLightfv(GL_LIGHT0, GL_POSITION, position1); | ||
164 | + | ||
165 | + glLightfv(GL_LIGHT1, GL_AMBIENT, ambient); | ||
166 | + glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse2); | ||
167 | + glLightfv(GL_LIGHT1, GL_SPECULAR, specular); | ||
168 | + glLightfv(GL_LIGHT1, GL_POSITION, position2); | ||
169 | + | ||
170 | + glLightfv(GL_LIGHT2, GL_AMBIENT, ambient); | ||
171 | + glLightfv(GL_LIGHT2, GL_DIFFUSE, diffuse1); | ||
172 | + glLightfv(GL_LIGHT2, GL_SPECULAR, specular); | ||
173 | + glLightfv(GL_LIGHT2, GL_POSITION, position); | ||
174 | + | ||
175 | + glEnable(GL_COLOR_MATERIAL); | ||
176 | + | ||
131 | //no mapping, just comparing | 177 | //no mapping, just comparing |
132 | if (ind == 0) { | 178 | if (ind == 0) { |
133 | if (num_nets == 1) { //if a single network is loaded | 179 | if (num_nets == 1) { //if a single network is loaded |
@@ -136,23 +182,41 @@ void glut_render(void) { | @@ -136,23 +182,41 @@ void glut_render(void) { | ||
136 | glut_render_modelview(); //set up the modelview matrix with camera details | 182 | glut_render_modelview(); //set up the modelview matrix with camera details |
137 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen | 183 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen |
138 | GT.glCenterline0(); //render the GT network (the only one loaded) | 184 | GT.glCenterline0(); //render the GT network (the only one loaded) |
185 | + glDisable(GL_DEPTH_TEST); | ||
139 | } | 186 | } |
140 | 187 | ||
141 | if (num_nets == 2) { //if two networks are loaded | 188 | if (num_nets == 2) { //if two networks are loaded |
189 | + glEnable(GL_TEXTURE_1D); //enable texture mapping | ||
190 | + if (light_fac == 0) | ||
191 | + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); //texture map will be used as the network color | ||
192 | + else | ||
193 | + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); | ||
194 | + glBindTexture(GL_TEXTURE_1D, cmap_tex); //bind the Brewer texture map | ||
195 | + | ||
142 | glEnable(GL_DEPTH_TEST); //enable depth | 196 | glEnable(GL_DEPTH_TEST); //enable depth |
143 | glut_render_left_projection(); //set up a projection for the left half of the window | 197 | glut_render_left_projection(); //set up a projection for the left half of the window |
144 | glut_render_modelview(); //set up the modelview matrix using camera details | 198 | glut_render_modelview(); //set up the modelview matrix using camera details |
145 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen | 199 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen |
146 | 200 | ||
147 | - glEnable(GL_TEXTURE_1D); //enable texture mapping | ||
148 | - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); //texture map will be used as the network color | ||
149 | - glBindTexture(GL_TEXTURE_1D, cmap_tex); //bind the Brewer texture map | ||
150 | - | ||
151 | GT.glCylinder(sigma, radius); //render the GT network | 201 | GT.glCylinder(sigma, radius); //render the GT network |
202 | + if (adjoint_fac == 1) { | ||
203 | + glDisable(GL_TEXTURE_1D); //disable texture in order to render in other color | ||
204 | + glEnable(GL_BLEND); //enable color blend | ||
205 | + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //set blend function | ||
206 | + glDisable(GL_DEPTH_TEST); //should disable depth to render transparancy | ||
207 | + glColor4f(0.0f, 0.3f, 0.0f, 0.2f); | ||
208 | + T.glAdjointCylinder(sigma, radius); | ||
209 | + glDisable(GL_BLEND); | ||
210 | + glEnable(GL_DEPTH_TEST); | ||
211 | + glEnable(GL_TEXTURE_1D); | ||
212 | + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); | ||
213 | + } | ||
152 | 214 | ||
153 | glut_render_right_projection(); //set up a projection for the right half of the window | 215 | glut_render_right_projection(); //set up a projection for the right half of the window |
154 | glut_render_modelview(); //set up the modelview matrix using camera details | 216 | glut_render_modelview(); //set up the modelview matrix using camera details |
217 | + | ||
155 | T.glCylinder(sigma, radius); //render the T network | 218 | T.glCylinder(sigma, radius); //render the T network |
219 | + | ||
156 | sigma = radius; // set sigma equal to radius | 220 | sigma = radius; // set sigma equal to radius |
157 | } | 221 | } |
158 | } | 222 | } |
@@ -165,20 +229,37 @@ void glut_render(void) { | @@ -165,20 +229,37 @@ void glut_render(void) { | ||
165 | } | 229 | } |
166 | if (num_nets == 2) { //if two networks are loaded | 230 | if (num_nets == 2) { //if two networks are loaded |
167 | if (compareMode) { | 231 | if (compareMode) { |
232 | + glEnable(GL_TEXTURE_1D); //enable texture mapping | ||
233 | + if (light_fac == 0) | ||
234 | + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); //texture map will be used as the network color | ||
235 | + else | ||
236 | + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);//map light to texture | ||
237 | + glBindTexture(GL_TEXTURE_1D, cmap_tex); //bind the Brewer texture map | ||
238 | + | ||
168 | glEnable(GL_DEPTH_TEST); //enable depth | 239 | glEnable(GL_DEPTH_TEST); //enable depth |
169 | glut_render_left_projection(); //set up a projection for the left half of the window | 240 | glut_render_left_projection(); //set up a projection for the left half of the window |
170 | glut_render_modelview(); //set up the modelview matrix using camera details | 241 | glut_render_modelview(); //set up the modelview matrix using camera details |
171 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen | 242 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen |
172 | 243 | ||
173 | - glEnable(GL_TEXTURE_1D); //enable texture mapping | ||
174 | - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); //texture map will be used as the network color | ||
175 | - glBindTexture(GL_TEXTURE_1D, cmap_tex); //bind the Brewer texture map | ||
176 | - | ||
177 | _GT.glCylinder(sigma, radius); //render the GT network | 244 | _GT.glCylinder(sigma, radius); //render the GT network |
245 | + if (adjoint_fac == 1) { | ||
246 | + glDisable(GL_TEXTURE_1D); //temporarily disable texture | ||
247 | + glEnable(GL_BLEND); //enable color blend | ||
248 | + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //set blend function | ||
249 | + glDisable(GL_DEPTH_TEST); //should disable depth | ||
250 | + glColor4f(0.0f, 0.3f, 0.0f, 0.2f); | ||
251 | + _T.glAdjointCylinder(sigma, radius); | ||
252 | + glDisable(GL_BLEND); | ||
253 | + glEnable(GL_DEPTH_TEST); | ||
254 | + glEnable(GL_TEXTURE_1D); //re-enable texture | ||
255 | + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); | ||
256 | + } | ||
178 | 257 | ||
179 | glut_render_right_projection(); //set up a projection for the right half of the window | 258 | glut_render_right_projection(); //set up a projection for the right half of the window |
180 | glut_render_modelview(); //set up the modelview matrix using camera details | 259 | glut_render_modelview(); //set up the modelview matrix using camera details |
260 | + | ||
181 | _T.glCylinder(sigma, radius); //render the T network | 261 | _T.glCylinder(sigma, radius); //render the T network |
262 | + | ||
182 | sigma = radius; //set sigma equal to radius | 263 | sigma = radius; //set sigma equal to radius |
183 | } | 264 | } |
184 | else { | 265 | else { |
@@ -186,18 +267,20 @@ void glut_render(void) { | @@ -186,18 +267,20 @@ void glut_render(void) { | ||
186 | glut_render_left_projection(); //set up a projection for the left half of the window | 267 | glut_render_left_projection(); //set up a projection for the left half of the window |
187 | glut_render_modelview(); //set up the modelview matrix using camera details | 268 | glut_render_modelview(); //set up the modelview matrix using camera details |
188 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen | 269 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen |
189 | - | ||
190 | - //_GT.glRandColorCenterlineGT(dlist1, _gt_t, colormap); | ||
191 | - _GT.glRandColorCylinder1(dlist1, _gt_t, colormap, sigma, radius); | 270 | + |
271 | + _GT.glRandColorCylinder(0, _gt_t, colormap, sigma, radius); | ||
192 | 272 | ||
193 | glut_render_right_projection(); //set up a projection for the right half of the window | 273 | glut_render_right_projection(); //set up a projection for the right half of the window |
194 | glut_render_modelview(); //set up the modelview matrix using camera details | 274 | glut_render_modelview(); //set up the modelview matrix using camera details |
195 | - //_T.glRandColorCenterlineT(dlist2, _t_gt, colormap); | ||
196 | - _T.glRandColorCylinder2(dlist2, _t_gt, colormap, sigma, radius); | 275 | + |
276 | + _T.glRandColorCylinder(1, _t_gt, colormap, sigma, radius); | ||
277 | + | ||
197 | sigma = radius; //set sigma equal to radius | 278 | sigma = radius; //set sigma equal to radius |
198 | } | 279 | } |
199 | } | 280 | } |
200 | } | 281 | } |
282 | + glDisable(GL_DEPTH_TEST); | ||
283 | + glDisable(GL_TEXTURE_1D); | ||
201 | 284 | ||
202 | if (num_nets == 2) { // works only with two networks | 285 | if (num_nets == 2) { // works only with two networks |
203 | std::ostringstream ss; | 286 | std::ostringstream ss; |
@@ -206,27 +289,34 @@ void glut_render(void) { | @@ -206,27 +289,34 @@ void glut_render(void) { | ||
206 | else | 289 | else |
207 | ss << "Compare Mode"; // default mode is compare mode | 290 | ss << "Compare Mode"; // default mode is compare mode |
208 | 291 | ||
209 | - glDisable(GL_TEXTURE_1D); | ||
210 | - glMatrixMode(GL_PROJECTION); // set up the 2d viewport for mode text printing | 292 | + if (light_fac == 1) |
293 | + glDisable(GL_LIGHTING); | ||
294 | + glMatrixMode(GL_PROJECTION); // set up the 2d viewport for mode text printing | ||
211 | glPushMatrix(); | 295 | glPushMatrix(); |
212 | glLoadIdentity(); | 296 | glLoadIdentity(); |
213 | - int X = glutGet(GLUT_WINDOW_WIDTH); // get the current window width | ||
214 | - int Y = glutGet(GLUT_WINDOW_HEIGHT); // get the current window height | ||
215 | - glViewport(0, 0, X / 2, Y); // locate to left bottom corner | ||
216 | - gluOrtho2D(0, X, 0, Y); // define othogonal aspect | ||
217 | - glColor3f(0.0, 1.0, 0.0); // using green to show mode | 297 | + int X = glutGet(GLUT_WINDOW_WIDTH); // get the current window width |
298 | + int Y = glutGet(GLUT_WINDOW_HEIGHT); // get the current window height | ||
299 | + glViewport(0, 0, X / 2, Y); // locate to left bottom corner | ||
300 | + gluOrtho2D(0, X, 0, Y); // define othogonal aspect | ||
301 | + glColor3f(0.8, 0.0, 0.0); // using red to show mode | ||
218 | 302 | ||
219 | glMatrixMode(GL_MODELVIEW); | 303 | glMatrixMode(GL_MODELVIEW); |
220 | glPushMatrix(); | 304 | glPushMatrix(); |
221 | glLoadIdentity(); | 305 | glLoadIdentity(); |
222 | 306 | ||
223 | - glRasterPos2f(0, 5); //print text in the left bottom corner | 307 | + glRasterPos2f(0, 5); //print text in the left bottom corner |
224 | glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, (const unsigned char*)(ss.str().c_str())); | 308 | glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, (const unsigned char*)(ss.str().c_str())); |
225 | 309 | ||
226 | glPopMatrix(); | 310 | glPopMatrix(); |
227 | glMatrixMode(GL_PROJECTION); | 311 | glMatrixMode(GL_PROJECTION); |
228 | glPopMatrix(); | 312 | glPopMatrix(); |
313 | + glColor3f(1.0, 1.0, 1.0); //clear red color | ||
314 | + if (light_fac == 1) | ||
315 | + glEnable(GL_LIGHTING); | ||
229 | } | 316 | } |
317 | + | ||
318 | + glDisable(GL_COLOR_MATERIAL); | ||
319 | + | ||
230 | glutSwapBuffers(); | 320 | glutSwapBuffers(); |
231 | } | 321 | } |
232 | 322 | ||
@@ -331,12 +421,12 @@ void glut_keyboard(unsigned char key, int x, int y){ | @@ -331,12 +421,12 @@ void glut_keyboard(unsigned char key, int x, int y){ | ||
331 | switch (key) { | 421 | switch (key) { |
332 | 422 | ||
333 | // change render mode | 423 | // change render mode |
334 | - case 'm': // if keyboard 'm' is pressed, then change render mode | ||
335 | - if (compareMode && !mappingMode && ind) { // if current mode is comparing mode | 424 | + case 'm': // if keyboard 'm' is pressed, then change render mode |
425 | + if (compareMode && !mappingMode && ind && !adjoint_fac) { // if current mode is comparing mode | ||
336 | compareMode = false; | 426 | compareMode = false; |
337 | mappingMode = true; | 427 | mappingMode = true; |
338 | } | 428 | } |
339 | - else if (!compareMode && mappingMode && ind) { // if current mode is mapping mode | 429 | + else if (!compareMode && mappingMode && ind && !adjoint_fac) { // if current mode is mapping mode |
340 | compareMode = true; | 430 | compareMode = true; |
341 | mappingMode = false; | 431 | mappingMode = false; |
342 | } | 432 | } |
@@ -363,6 +453,32 @@ void glut_keyboard(unsigned char key, int x, int y){ | @@ -363,6 +453,32 @@ void glut_keyboard(unsigned char key, int x, int y){ | ||
363 | radius = 0.2; | 453 | radius = 0.2; |
364 | break; | 454 | break; |
365 | 455 | ||
456 | + // turn on/off the light | ||
457 | + case 'l': // if keyboard 'l' is pressed, then change the light | ||
458 | + if (!light_fac && !adjoint_fac) { | ||
459 | + light_fac = 1; | ||
460 | + glEnable(GL_LIGHTING); | ||
461 | + glEnable(GL_LIGHT0); | ||
462 | + glEnable(GL_LIGHT1); | ||
463 | + glEnable(GL_LIGHT2); | ||
464 | + } | ||
465 | + else if (light_fac && !adjoint_fac) { | ||
466 | + light_fac = 0; | ||
467 | + glDisable(GL_LIGHTING); | ||
468 | + glDisable(GL_LIGHT0); | ||
469 | + glDisable(GL_LIGHT1); | ||
470 | + glDisable(GL_LIGHT2); | ||
471 | + } | ||
472 | + break; | ||
473 | + | ||
474 | + // render a transparant T very close to GT in compare mode | ||
475 | + case 32: // if keyboard 'SPACE' is pressed, then change the adjoint_fac | ||
476 | + if (!adjoint_fac && compareMode && !light_fac) | ||
477 | + adjoint_fac = 1; | ||
478 | + else if(adjoint_fac && compareMode && !light_fac) | ||
479 | + adjoint_fac = 0; | ||
480 | + break; | ||
481 | + | ||
366 | // close window and exit application | 482 | // close window and exit application |
367 | case 27: // if keyboard 'ESC' is pressed, then exit | 483 | case 27: // if keyboard 'ESC' is pressed, then exit |
368 | exit(0); | 484 | exit(0); |