Commit 5ac53c9e6c160778579743c257a8c6c93fea0131
1 parent
9627c6e6
add keyboardfunc
Showing
1 changed file
with
67 additions
and
39 deletions
Show diff stats
main.cu
1 | -#include <stdlib.h> | |
1 | +#include <stdlib.h> | |
2 | 2 | #include <string> |
3 | 3 | #include <fstream> |
4 | 4 | #include <algorithm> |
... | ... | @@ -22,6 +22,9 @@ |
22 | 22 | //ANN includes |
23 | 23 | //#include <ANN/ANN.h> |
24 | 24 | |
25 | +//chrono includes | |
26 | +//#include <chrono> | |
27 | + | |
25 | 28 | //BOOST includes |
26 | 29 | #include <boost/tuple/tuple.hpp> |
27 | 30 | |
... | ... | @@ -56,9 +59,12 @@ int mouse_y; |
56 | 59 | bool compareMode = true; // default mode is compare mode |
57 | 60 | bool mappingMode = false; |
58 | 61 | |
59 | -// random color map | |
62 | +// random color set | |
60 | 63 | std::vector<float> colormap; |
61 | 64 | |
65 | +// special key indicator | |
66 | +int mods; | |
67 | + | |
62 | 68 | // create display lists |
63 | 69 | GLuint dlist1; |
64 | 70 | GLuint dlist2; |
... | ... | @@ -113,7 +119,6 @@ void glut_render_modelview(){ |
113 | 119 | gluLookAt(eye[0], eye[1], eye[2], focus[0], focus[1], focus[2], up[0], up[1], up[2]); //set up the OpenGL camera |
114 | 120 | } |
115 | 121 | |
116 | - | |
117 | 122 | //draws the network(s) |
118 | 123 | void glut_render(void) { |
119 | 124 | |
... | ... | @@ -122,7 +127,7 @@ void glut_render(void) { |
122 | 127 | glut_render_single_projection(); //fill the entire viewport |
123 | 128 | glut_render_modelview(); //set up the modelview matrix with camera details |
124 | 129 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen |
125 | - GT.glCenterline(GT.nmags() - 1); //render the GT network (the only one loaded) | |
130 | + GT.glCenterline0(); //render the GT network (the only one loaded) | |
126 | 131 | } |
127 | 132 | |
128 | 133 | if(num_nets == 2){ //if two networks are loaded |
... | ... | @@ -144,10 +149,8 @@ void glut_render(void) { |
144 | 149 | } |
145 | 150 | else{ |
146 | 151 | if(num_nets == 1){ //if a single network is loaded |
147 | - glut_render_single_projection(); //fill the entire viewport | |
148 | - glut_render_modelview(); //set up the modelview matrix with camera details | |
149 | - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen | |
150 | - _GT.glCenterline(_GT.nmags() - 1); //render the GT network (the only one loaded) | |
152 | + std::cout << "You should have at least two networks to do mapping." << std::endl; //exit program because there isn't enough network | |
153 | + exit(1); | |
151 | 154 | } |
152 | 155 | if(num_nets == 2){ //if two networks are loaded |
153 | 156 | if(compareMode){ |
... | ... | @@ -180,40 +183,41 @@ void glut_render(void) { |
180 | 183 | } |
181 | 184 | } |
182 | 185 | |
183 | - std::ostringstream ss; | |
184 | - if(mappingMode) // if it is in mapping mode | |
185 | - ss<< "Mapping Mode"; | |
186 | - else | |
187 | - ss<< "Compare Mode"; // default mode is compare mode | |
188 | - | |
189 | - glDisable(GL_TEXTURE_1D); | |
190 | - glMatrixMode(GL_PROJECTION); //Set up the 2d viewport for text printing | |
191 | - glPushMatrix(); | |
192 | - glLoadIdentity(); | |
193 | - int X = glutGet(GLUT_WINDOW_WIDTH); | |
194 | - int Y = glutGet(GLUT_WINDOW_HEIGHT); | |
195 | - glViewport(0, 0, X/2, Y); | |
196 | - gluOrtho2D(0, X, 0, Y); | |
197 | - glColor3f(0.0, 1.0, 0.0); // using green to show mode | |
198 | - | |
199 | - glMatrixMode(GL_MODELVIEW); | |
200 | - glPushMatrix(); | |
201 | - glLoadIdentity(); | |
202 | - | |
203 | - glRasterPos2f(0, 5); //print text in the bottom left corner | |
204 | - glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, (const unsigned char*) (ss.str().c_str())); | |
205 | - | |
206 | - glPopMatrix(); | |
207 | - glMatrixMode(GL_PROJECTION); | |
208 | - glPopMatrix(); | |
209 | - | |
186 | + if(num_nets == 2){ | |
187 | + std::ostringstream ss; | |
188 | + if (mappingMode) // if it is in mapping mode | |
189 | + ss << "Mapping Mode"; | |
190 | + else | |
191 | + ss << "Compare Mode"; // default mode is compare mode | |
192 | + | |
193 | + glDisable(GL_TEXTURE_1D); | |
194 | + glMatrixMode(GL_PROJECTION); //Set up the 2d viewport for mode text printing | |
195 | + glPushMatrix(); | |
196 | + glLoadIdentity(); | |
197 | + int X = glutGet(GLUT_WINDOW_WIDTH); | |
198 | + int Y = glutGet(GLUT_WINDOW_HEIGHT); | |
199 | + glViewport(0, 0, X / 2, Y); // locate to left bottom corner | |
200 | + gluOrtho2D(0, X, 0, Y); // define othogonal aspect | |
201 | + glColor3f(0.0, 1.0, 0.0); // using green to show mode | |
202 | + | |
203 | + glMatrixMode(GL_MODELVIEW); | |
204 | + glPushMatrix(); | |
205 | + glLoadIdentity(); | |
206 | + | |
207 | + glRasterPos2f(0, 5); //print text in the bottom left corner | |
208 | + glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, (const unsigned char*)(ss.str().c_str())); | |
209 | + | |
210 | + glPopMatrix(); | |
211 | + glMatrixMode(GL_PROJECTION); | |
212 | + glPopMatrix(); | |
213 | + } | |
210 | 214 | glutSwapBuffers(); |
211 | 215 | } |
212 | 216 | |
213 | 217 | // defines camera motion based on mouse dragging |
214 | 218 | void glut_motion(int x, int y){ |
215 | 219 | |
216 | - if(LButtonDown == true && RButtonDown == false){ | |
220 | + if(LButtonDown == true && RButtonDown == false && mods != GLUT_ACTIVE_CTRL){ | |
217 | 221 | |
218 | 222 | float theta = orbit_factor * (mouse_x - x); //determine the number of degrees along the x-axis to rotate |
219 | 223 | float phi = orbit_factor * (y - mouse_y); //number of degrees along the y-axis to rotate |
... | ... | @@ -250,6 +254,30 @@ void glut_mouse(int button, int state, int x, int y){ |
250 | 254 | mouse_y = y; |
251 | 255 | RButtonDown = false; |
252 | 256 | } |
257 | + | |
258 | + /// implementation of mouse click mapping feedback | |
259 | + mods = glutGetModifiers(); // get modifier keys | |
260 | + if (mods == GLUT_ACTIVE_CTRL) // if the CTRL key is pressed | |
261 | + if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { | |
262 | + std::cout << "( " << x << ", " << y << " )" << std::endl; // if the CTRL key is pressed and LEFT BUTTON is DOWN, print the window coordinates | |
263 | + | |
264 | + GLint viewport[4]; | |
265 | + GLdouble modelview[16]; | |
266 | + GLdouble projection[16]; | |
267 | + GLdouble winX, winY, winZ; | |
268 | + GLdouble posX, posY, posZ; | |
269 | + | |
270 | + glGetIntegerv(GL_VIEWPORT, viewport); | |
271 | + glGetDoublev(GL_MODELVIEW_MATRIX, modelview); | |
272 | + glGetDoublev(GL_PROJECTION_MATRIX, projection); | |
273 | + | |
274 | + winX = (GLdouble)x; | |
275 | + winY = viewport[3] - (GLdouble)y; | |
276 | + glReadPixels((GLint)winX, (GLint)winY, (GLsizei)1, (GLsizei)1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ); // need frame buffer FBO | |
277 | + gluUnProject(winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ); // not sure why it should add 1 to the winZ | |
278 | + | |
279 | + std::cout << "( " << posX << ", " << posY << ", "<< posZ <<" )" << std::endl; | |
280 | + } | |
253 | 281 | } |
254 | 282 | |
255 | 283 | void glut_keyboard(unsigned char key, int x, int y){ |
... | ... | @@ -305,7 +333,7 @@ void glut_initialize(){ |
305 | 333 | glutInit(&myargc, myargv); //pass bogus arguments to glutInit() |
306 | 334 | glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); //generate a color buffer, depth buffer, and enable double buffering |
307 | 335 | glutInitWindowPosition(100,100); //set the initial window position |
308 | - glutInitWindowSize(320,320); //set the initial window size | |
336 | + glutInitWindowSize(320, 320); //set the initial window size | |
309 | 337 | glutCreateWindow("NetMets - STIM Lab, UH"); //set the dialog box title |
310 | 338 | |
311 | 339 | |
... | ... | @@ -363,8 +391,8 @@ void map(float sigma, int device){ |
363 | 391 | _T.mapping(_GT, _t_gt, device); |
364 | 392 | |
365 | 393 | size_t num = _gt_t.size(); // also create random color for unmapping edge, but won't be used though |
366 | - colormap.resize(3*num); | |
367 | - for(int i = 0; i < 3*num; i++) | |
394 | + colormap.resize(3 * num); // 3 portions compound RGB | |
395 | + for(int i = 0; i < 3 * num; i++) | |
368 | 396 | colormap[i] = rand()/(float)RAND_MAX; |
369 | 397 | |
370 | 398 | //calculate the metrics | ... | ... |