Commit 19ec4731eaea24ff9dac28540bf413a40ce04528
1 parent
8b30eb84
add light
Showing
1 changed file
with
88 additions
and
63 deletions
Show diff stats
main.cu
@@ -67,17 +67,13 @@ std::vector<float> colormap; | @@ -67,17 +67,13 @@ 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 |
80 | -int transparancy_fac = 0; | 76 | +int adjoint_fac = 0; |
81 | 77 | ||
82 | //sets an OpenGL viewport taking up the entire window | 78 | //sets an OpenGL viewport taking up the entire window |
83 | void glut_render_single_projection(){ | 79 | void glut_render_single_projection(){ |
@@ -146,23 +142,31 @@ void glut_render(void) { | @@ -146,23 +142,31 @@ void glut_render(void) { | ||
146 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen | 142 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen |
147 | 143 | ||
148 | glEnable(GL_TEXTURE_1D); //enable texture mapping | 144 | glEnable(GL_TEXTURE_1D); //enable texture mapping |
149 | - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); //texture map will be used as the network color | 145 | + if(adjoint_fac == 1) |
146 | + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); //texture map will be used as the network color | ||
147 | + else if (adjoint_fac == 0) | ||
148 | + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); | ||
150 | glBindTexture(GL_TEXTURE_1D, cmap_tex); //bind the Brewer texture map | 149 | glBindTexture(GL_TEXTURE_1D, cmap_tex); //bind the Brewer texture map |
151 | 150 | ||
152 | GT.glCylinder(sigma, radius); //render the GT network | 151 | GT.glCylinder(sigma, radius); //render the GT network |
153 | - if (transparancy_fac == 1) { | 152 | + if (adjoint_fac == 1) { |
153 | + glDisable(GL_TEXTURE_1D); | ||
154 | glEnable(GL_BLEND); //enable color blend | 154 | glEnable(GL_BLEND); //enable color blend |
155 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //set blend function | 155 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //set blend function |
156 | glDisable(GL_DEPTH_TEST); //should disable depth | 156 | glDisable(GL_DEPTH_TEST); //should disable depth |
157 | - glColor4f(1.0f, 1.0f, 1.0f, 0.2f); | ||
158 | - T.glCylinder(sigma, radius); | 157 | + glColor4f(0.0f, 0.3f, 0.0f, 0.2f); |
158 | + T.glAdjointCylinder(sigma, radius); | ||
159 | glDisable(GL_BLEND); | 159 | glDisable(GL_BLEND); |
160 | glEnable(GL_DEPTH_TEST); | 160 | glEnable(GL_DEPTH_TEST); |
161 | + glEnable(GL_TEXTURE_1D); | ||
162 | + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); | ||
161 | } | 163 | } |
162 | 164 | ||
163 | glut_render_right_projection(); //set up a projection for the right half of the window | 165 | glut_render_right_projection(); //set up a projection for the right half of the window |
164 | glut_render_modelview(); //set up the modelview matrix using camera details | 166 | glut_render_modelview(); //set up the modelview matrix using camera details |
167 | + | ||
165 | T.glCylinder(sigma, radius); //render the T network | 168 | T.glCylinder(sigma, radius); //render the T network |
169 | + | ||
166 | sigma = radius; // set sigma equal to radius | 170 | sigma = radius; // set sigma equal to radius |
167 | } | 171 | } |
168 | } | 172 | } |
@@ -181,23 +185,31 @@ void glut_render(void) { | @@ -181,23 +185,31 @@ void glut_render(void) { | ||
181 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen | 185 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen |
182 | 186 | ||
183 | glEnable(GL_TEXTURE_1D); //enable texture mapping | 187 | glEnable(GL_TEXTURE_1D); //enable texture mapping |
184 | - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); //texture map will be used as the network color | 188 | + if (adjoint_fac == 1) |
189 | + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); //texture map will be used as the network color | ||
190 | + else if (adjoint_fac == 0) | ||
191 | + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);//map light to texture | ||
185 | glBindTexture(GL_TEXTURE_1D, cmap_tex); //bind the Brewer texture map | 192 | glBindTexture(GL_TEXTURE_1D, cmap_tex); //bind the Brewer texture map |
186 | 193 | ||
187 | _GT.glCylinder(sigma, radius); //render the GT network | 194 | _GT.glCylinder(sigma, radius); //render the GT network |
188 | - if (transparancy_fac == 1) { | 195 | + if (adjoint_fac == 1) { |
196 | + glDisable(GL_TEXTURE_1D); //temporarily disable texture | ||
189 | glEnable(GL_BLEND); //enable color blend | 197 | glEnable(GL_BLEND); //enable color blend |
190 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //set blend function | 198 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //set blend function |
191 | glDisable(GL_DEPTH_TEST); //should disable depth | 199 | glDisable(GL_DEPTH_TEST); //should disable depth |
192 | - glColor4f(1.0f, 1.0f, 1.0f, 0.2f); | ||
193 | - _T.glCylinder(sigma, radius); | 200 | + glColor4f(0.0f, 0.3f, 0.0f, 0.2f); |
201 | + _T.glAdjointCylinder(sigma, radius); | ||
194 | glDisable(GL_BLEND); | 202 | glDisable(GL_BLEND); |
195 | glEnable(GL_DEPTH_TEST); | 203 | glEnable(GL_DEPTH_TEST); |
204 | + glEnable(GL_TEXTURE_1D); //re-enable texture | ||
205 | + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); | ||
196 | } | 206 | } |
197 | 207 | ||
198 | glut_render_right_projection(); //set up a projection for the right half of the window | 208 | glut_render_right_projection(); //set up a projection for the right half of the window |
199 | glut_render_modelview(); //set up the modelview matrix using camera details | 209 | glut_render_modelview(); //set up the modelview matrix using camera details |
210 | + | ||
200 | _T.glCylinder(sigma, radius); //render the T network | 211 | _T.glCylinder(sigma, radius); //render the T network |
212 | + | ||
201 | sigma = radius; //set sigma equal to radius | 213 | sigma = radius; //set sigma equal to radius |
202 | } | 214 | } |
203 | else { | 215 | else { |
@@ -206,54 +218,45 @@ void glut_render(void) { | @@ -206,54 +218,45 @@ void glut_render(void) { | ||
206 | glut_render_modelview(); //set up the modelview matrix using camera details | 218 | glut_render_modelview(); //set up the modelview matrix using camera details |
207 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen | 219 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen |
208 | 220 | ||
209 | - _GT.glRandColorCylinder1(dlist1, _gt_t, colormap, sigma, radius); | ||
210 | - if (transparancy_fac == 1) { | ||
211 | - glEnable(GL_BLEND); //enable color blend | ||
212 | - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //set blend function | ||
213 | - glDisable(GL_DEPTH_TEST); //should disable depth | ||
214 | - glColor4f(1.0f, 1.0f, 1.0f, 0.2f); | ||
215 | - _T.glRandColorCylinder2(dlist2, _t_gt, colormap, sigma, radius); | ||
216 | - glDisable(GL_BLEND); | ||
217 | - glEnable(GL_DEPTH_TEST); | ||
218 | - } | 221 | + _GT.glRandColorCylinder(0, _gt_t, colormap, sigma, radius); |
219 | 222 | ||
220 | glut_render_right_projection(); //set up a projection for the right half of the window | 223 | glut_render_right_projection(); //set up a projection for the right half of the window |
221 | glut_render_modelview(); //set up the modelview matrix using camera details | 224 | glut_render_modelview(); //set up the modelview matrix using camera details |
222 | 225 | ||
223 | - _T.glRandColorCylinder2(dlist2, _t_gt, colormap, sigma, radius); | 226 | + _T.glRandColorCylinder(1, _t_gt, colormap, sigma, radius); |
227 | + | ||
224 | sigma = radius; //set sigma equal to radius | 228 | sigma = radius; //set sigma equal to radius |
225 | } | 229 | } |
226 | } | 230 | } |
227 | } | 231 | } |
228 | - | ||
229 | - if (num_nets == 2) { // works only with two networks | ||
230 | - std::ostringstream ss; | ||
231 | - if (mappingMode) // if it is in mapping mode | ||
232 | - ss << "Mapping Mode"; | ||
233 | - else | ||
234 | - ss << "Compare Mode"; // default mode is compare mode | ||
235 | - | ||
236 | - glDisable(GL_TEXTURE_1D); | ||
237 | - glMatrixMode(GL_PROJECTION); // set up the 2d viewport for mode text printing | ||
238 | - glPushMatrix(); | ||
239 | - glLoadIdentity(); | ||
240 | - int X = glutGet(GLUT_WINDOW_WIDTH); // get the current window width | ||
241 | - int Y = glutGet(GLUT_WINDOW_HEIGHT); // get the current window height | ||
242 | - glViewport(0, 0, X / 2, Y); // locate to left bottom corner | ||
243 | - gluOrtho2D(0, X, 0, Y); // define othogonal aspect | ||
244 | - glColor3f(0.0, 1.0, 0.0); // using green to show mode | ||
245 | - | ||
246 | - glMatrixMode(GL_MODELVIEW); | ||
247 | - glPushMatrix(); | ||
248 | - glLoadIdentity(); | ||
249 | - | ||
250 | - glRasterPos2f(0, 5); //print text in the left bottom corner | ||
251 | - glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, (const unsigned char*)(ss.str().c_str())); | ||
252 | - | ||
253 | - glPopMatrix(); | ||
254 | - glMatrixMode(GL_PROJECTION); | ||
255 | - glPopMatrix(); | ||
256 | - } | 232 | + glDisable(GL_TEXTURE_1D); //disable texture |
233 | + | ||
234 | + //if (num_nets == 2) { // works only with two networks | ||
235 | + // std::ostringstream ss; | ||
236 | + // if (mappingMode) // if it is in mapping mode | ||
237 | + // ss << "Mapping Mode"; | ||
238 | + // else | ||
239 | + // ss << "Compare Mode"; // default mode is compare mode | ||
240 | + // glMatrixMode(GL_PROJECTION); // set up the 2d viewport for mode text printing | ||
241 | + // glPushMatrix(); | ||
242 | + // glLoadIdentity(); | ||
243 | + // int X = glutGet(GLUT_WINDOW_WIDTH); // get the current window width | ||
244 | + // int Y = glutGet(GLUT_WINDOW_HEIGHT); // get the current window height | ||
245 | + // glViewport(0, 0, X / 2, Y); // locate to left bottom corner | ||
246 | + // gluOrtho2D(0, X, 0, Y); // define othogonal aspect | ||
247 | + // glColor3f(0.0, 1.0, 0.0); // using green to show mode | ||
248 | + | ||
249 | + // glMatrixMode(GL_MODELVIEW); | ||
250 | + // glPushMatrix(); | ||
251 | + // glLoadIdentity(); | ||
252 | + | ||
253 | + // glRasterPos2f(0, 5); //print text in the left bottom corner | ||
254 | + // glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, (const unsigned char*)(ss.str().c_str())); | ||
255 | + | ||
256 | + // glPopMatrix(); | ||
257 | + // glMatrixMode(GL_PROJECTION); | ||
258 | + // glPopMatrix(); | ||
259 | + //} | ||
257 | glutSwapBuffers(); | 260 | glutSwapBuffers(); |
258 | } | 261 | } |
259 | 262 | ||
@@ -358,12 +361,12 @@ void glut_keyboard(unsigned char key, int x, int y){ | @@ -358,12 +361,12 @@ void glut_keyboard(unsigned char key, int x, int y){ | ||
358 | switch (key) { | 361 | switch (key) { |
359 | 362 | ||
360 | // change render mode | 363 | // change render mode |
361 | - case 'm': // if keyboard 'm' is pressed, then change render mode | ||
362 | - if (compareMode && !mappingMode && ind) { // if current mode is comparing mode | 364 | + case 'm': // if keyboard 'm' is pressed, then change render mode |
365 | + if (compareMode && !mappingMode && ind && !adjoint_fac) { // if current mode is comparing mode | ||
363 | compareMode = false; | 366 | compareMode = false; |
364 | mappingMode = true; | 367 | mappingMode = true; |
365 | } | 368 | } |
366 | - else if (!compareMode && mappingMode && ind) { // if current mode is mapping mode | 369 | + else if (!compareMode && mappingMode && ind && !adjoint_fac) { // if current mode is mapping mode |
367 | compareMode = true; | 370 | compareMode = true; |
368 | mappingMode = false; | 371 | mappingMode = false; |
369 | } | 372 | } |
@@ -389,13 +392,13 @@ void glut_keyboard(unsigned char key, int x, int y){ | @@ -389,13 +392,13 @@ void glut_keyboard(unsigned char key, int x, int y){ | ||
389 | if (radius < 0.001f) | 392 | if (radius < 0.001f) |
390 | radius = 0.2; | 393 | radius = 0.2; |
391 | break; | 394 | break; |
392 | - | ||
393 | - // render a transparant T very close to GT | ||
394 | - case 32: // if keyboard 'SPACE' is pressed, then change the transparancy_fac | ||
395 | - if (compareMode && !mappingMode && !transparancy_fac) | ||
396 | - transparancy_fac = 1; | ||
397 | - else | ||
398 | - transparancy_fac = 0; | 395 | + |
396 | + // render a transparant T very close to GT in compare mode | ||
397 | + case 32: // if keyboard 'SPACE' is pressed, then change the adjoint_fac | ||
398 | + if (!adjoint_fac && compareMode) | ||
399 | + adjoint_fac = 1; | ||
400 | + else if(adjoint_fac && compareMode) | ||
401 | + adjoint_fac = 0; | ||
399 | break; | 402 | break; |
400 | 403 | ||
401 | // close window and exit application | 404 | // close window and exit application |
@@ -468,6 +471,28 @@ void glut_initialize(){ | @@ -468,6 +471,28 @@ void glut_initialize(){ | ||
468 | //place the camera along the z-axis at a distance determined by the network size along x and y | 471 | //place the camera along the z-axis at a distance determined by the network size along x and y |
469 | cam.setPosition(c + stim::vec<float>(0, 0, camera_factor * std::max(bb.size()[0], bb.size()[1]))); | 472 | cam.setPosition(c + stim::vec<float>(0, 0, camera_factor * std::max(bb.size()[0], bb.size()[1]))); |
470 | cam.LookAt(c[0], c[1], c[2]); //look at the center of the network | 473 | cam.LookAt(c[0], c[1], c[2]); //look at the center of the network |
474 | + | ||
475 | + // light | ||
476 | + stim::vec3<float> eye = cam.getPosition(); //get the camera position point | ||
477 | + stim::vec3<float> focus = cam.getLookAt(); //get the camera focal point | ||
478 | + | ||
479 | + GLfloat ambient[] = { 0.2, 0.2, 0.2, 1.0 }; | ||
480 | + GLfloat diffuse1[] = { 1.0, 1.0, 1.0, 1.0 }; | ||
481 | + GLfloat diffuse2[] = { 0.2, 0.2, 0.2, 1.0 }; | ||
482 | + GLfloat position1[] = { 3*focus[0], 3*focus[1], -3*eye[2], 1.0 }; // upper right light source | ||
483 | + GLfloat position2[] = { -2*focus[0], -2*focus[1], -3*eye[2], 0.0 }; // lower left light source | ||
484 | + glClearColor(0.0, 0.0, 0.0, 1.0); | ||
485 | + glShadeModel(GL_SMOOTH); | ||
486 | + | ||
487 | + glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); | ||
488 | + glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse1); | ||
489 | + glLightfv(GL_LIGHT0, GL_POSITION, position1); | ||
490 | + glLightfv(GL_LIGHT1, GL_AMBIENT, ambient); | ||
491 | + glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse2); | ||
492 | + glLightfv(GL_LIGHT1, GL_POSITION, position2); | ||
493 | + | ||
494 | + glEnable(GL_LIGHTING); | ||
495 | + glEnable(GL_LIGHT0); | ||
471 | } | 496 | } |
472 | 497 | ||
473 | #ifdef __CUDACC__ | 498 | #ifdef __CUDACC__ |