From 5ac53c9e6c160778579743c257a8c6c93fea0131 Mon Sep 17 00:00:00 2001 From: Jiaming Guo Date: Wed, 4 Jan 2017 10:39:37 -0600 Subject: [PATCH] add keyboardfunc --- main.cu | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------- 1 file changed, 67 insertions(+), 39 deletions(-) diff --git a/main.cu b/main.cu index fbe04cd..5a58e81 100644 --- a/main.cu +++ b/main.cu @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -22,6 +22,9 @@ //ANN includes //#include +//chrono includes +//#include + //BOOST includes #include @@ -56,9 +59,12 @@ int mouse_y; bool compareMode = true; // default mode is compare mode bool mappingMode = false; -// random color map +// random color set std::vector colormap; +// special key indicator +int mods; + // create display lists GLuint dlist1; GLuint dlist2; @@ -113,7 +119,6 @@ void glut_render_modelview(){ gluLookAt(eye[0], eye[1], eye[2], focus[0], focus[1], focus[2], up[0], up[1], up[2]); //set up the OpenGL camera } - //draws the network(s) void glut_render(void) { @@ -122,7 +127,7 @@ void glut_render(void) { glut_render_single_projection(); //fill the entire viewport glut_render_modelview(); //set up the modelview matrix with camera details glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen - GT.glCenterline(GT.nmags() - 1); //render the GT network (the only one loaded) + GT.glCenterline0(); //render the GT network (the only one loaded) } if(num_nets == 2){ //if two networks are loaded @@ -144,10 +149,8 @@ void glut_render(void) { } else{ if(num_nets == 1){ //if a single network is loaded - glut_render_single_projection(); //fill the entire viewport - glut_render_modelview(); //set up the modelview matrix with camera details - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen - _GT.glCenterline(_GT.nmags() - 1); //render the GT network (the only one loaded) + std::cout << "You should have at least two networks to do mapping." << std::endl; //exit program because there isn't enough network + exit(1); } if(num_nets == 2){ //if two networks are loaded if(compareMode){ @@ -180,40 +183,41 @@ void glut_render(void) { } } - std::ostringstream ss; - if(mappingMode) // if it is in mapping mode - ss<< "Mapping Mode"; - else - ss<< "Compare Mode"; // default mode is compare mode - - glDisable(GL_TEXTURE_1D); - glMatrixMode(GL_PROJECTION); //Set up the 2d viewport for text printing - glPushMatrix(); - glLoadIdentity(); - int X = glutGet(GLUT_WINDOW_WIDTH); - int Y = glutGet(GLUT_WINDOW_HEIGHT); - glViewport(0, 0, X/2, Y); - gluOrtho2D(0, X, 0, Y); - glColor3f(0.0, 1.0, 0.0); // using green to show mode - - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity(); - - glRasterPos2f(0, 5); //print text in the bottom left corner - glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, (const unsigned char*) (ss.str().c_str())); - - glPopMatrix(); - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - + if(num_nets == 2){ + std::ostringstream ss; + if (mappingMode) // if it is in mapping mode + ss << "Mapping Mode"; + else + ss << "Compare Mode"; // default mode is compare mode + + glDisable(GL_TEXTURE_1D); + glMatrixMode(GL_PROJECTION); //Set up the 2d viewport for mode text printing + glPushMatrix(); + glLoadIdentity(); + int X = glutGet(GLUT_WINDOW_WIDTH); + int Y = glutGet(GLUT_WINDOW_HEIGHT); + glViewport(0, 0, X / 2, Y); // locate to left bottom corner + gluOrtho2D(0, X, 0, Y); // define othogonal aspect + glColor3f(0.0, 1.0, 0.0); // using green to show mode + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + + glRasterPos2f(0, 5); //print text in the bottom left corner + glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, (const unsigned char*)(ss.str().c_str())); + + glPopMatrix(); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + } glutSwapBuffers(); } // defines camera motion based on mouse dragging void glut_motion(int x, int y){ - if(LButtonDown == true && RButtonDown == false){ + if(LButtonDown == true && RButtonDown == false && mods != GLUT_ACTIVE_CTRL){ float theta = orbit_factor * (mouse_x - x); //determine the number of degrees along the x-axis to rotate 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){ mouse_y = y; RButtonDown = false; } + + /// implementation of mouse click mapping feedback + mods = glutGetModifiers(); // get modifier keys + if (mods == GLUT_ACTIVE_CTRL) // if the CTRL key is pressed + if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { + std::cout << "( " << x << ", " << y << " )" << std::endl; // if the CTRL key is pressed and LEFT BUTTON is DOWN, print the window coordinates + + GLint viewport[4]; + GLdouble modelview[16]; + GLdouble projection[16]; + GLdouble winX, winY, winZ; + GLdouble posX, posY, posZ; + + glGetIntegerv(GL_VIEWPORT, viewport); + glGetDoublev(GL_MODELVIEW_MATRIX, modelview); + glGetDoublev(GL_PROJECTION_MATRIX, projection); + + winX = (GLdouble)x; + winY = viewport[3] - (GLdouble)y; + glReadPixels((GLint)winX, (GLint)winY, (GLsizei)1, (GLsizei)1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ); // need frame buffer FBO + gluUnProject(winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ); // not sure why it should add 1 to the winZ + + std::cout << "( " << posX << ", " << posY << ", "<< posZ <<" )" << std::endl; + } } void glut_keyboard(unsigned char key, int x, int y){ @@ -305,7 +333,7 @@ void glut_initialize(){ glutInit(&myargc, myargv); //pass bogus arguments to glutInit() glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); //generate a color buffer, depth buffer, and enable double buffering glutInitWindowPosition(100,100); //set the initial window position - glutInitWindowSize(320,320); //set the initial window size + glutInitWindowSize(320, 320); //set the initial window size glutCreateWindow("NetMets - STIM Lab, UH"); //set the dialog box title @@ -363,8 +391,8 @@ void map(float sigma, int device){ _T.mapping(_GT, _t_gt, device); size_t num = _gt_t.size(); // also create random color for unmapping edge, but won't be used though - colormap.resize(3*num); - for(int i = 0; i < 3*num; i++) + colormap.resize(3 * num); // 3 portions compound RGB + for(int i = 0; i < 3 * num; i++) colormap[i] = rand()/(float)RAND_MAX; //calculate the metrics -- libgit2 0.21.4