#include #include #include #include "biMap.h" using namespace std; float winWid,winHeight; float rx,ry; float tx,ty; float t1,t2; // target values biMap *BMap; #define RGMAP 1 #define WEAVING 2 int Cond; bool selK1,selK2; float key1,key2; int clickCount; void redraw( void ) { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.00,1.00,0.0); glRectf(00.0,00.0,400.0,400.0); if(Cond == RGMAP) { BMap->drawRG(); glColor3f(1.0,1.0,1.0); // target + color } if(Cond == WEAVING) { BMap->drawSpect(); BMap->drawCircleField(); glColor3f(0.0,0.0,0.0); // target + color } BMap->drawTarget(tx,ty); glutSwapBuffers(); } void motion(int x, int y) // called when a mouse is in motion with a button down { rx = x; ry = winHeight - y; } void mousebutton(int button, int state, int x, int y) { float v; float e1,e2,totalError; int ret; if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { // map into display coordinates rx = M_WID*x/winHeight; ry = M_WID*(winHeight - y)/winHeight; ret = BMap->readKey(rx, ry, v); if(ret == 0){selK1 = true; key1 = v;} if(ret == 1){selK2 = true; key2 = v;} BMap->getMapValues(tx, ty, t1, t2); if(selK1 && selK2) { selK1 = selK2 = false; e1 = fabs(t1-key1); e2 = fabs(t2-key2); // ALL THIS SHOULD GO TO A FILE - NOT TO THE SCREEN cerr << "Target Vals " << t1 << " " << t2 << "\n"; cerr << "Selected " << key1 << " " << key2 << "\n"; cerr << "Error " << e1 << " " << e2 << " "<< sqrt(e1*e1 + e2*e2)<< "\n\n"; // set the new target position for next trial tx = 50 + rand()%300; ty = 50 + rand()%300; } } } void MenuCB(int m) { switch(m) { case 1: Cond = RGMAP; break; case 2: Cond = WEAVING; break; case 3: BMap->mkMaps(); break; } } void keyboard(unsigned char key, int x, int y) // x and y givethe mouse pos { cerr << "Key " << key << " " << int(key) << "\n"; switch(key) { case 't': BMap->mkMaps(); break; case 'w': Cond = WEAVING; break; } } int main(int argc, char *argv[]) { rx = ry = 0.0; t1 = t2 = 0; //Cond = WEAVING; Cond = RGMAP; BMap=new biMap(); BMap->mkMaps(); tx = 50 + rand()%300; ty = 50 + rand()%300; BMap->getMapValues(tx, ty, t1, t2); winWid = 900.0; winHeight = 600.0; glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); glutCreateWindow("Bivariate Map Experiment"); glutPositionWindow(200,100); glutReshapeWindow(winWid,winHeight); glutCreateMenu(MenuCB); glutAttachMenu(GLUT_RIGHT_BUTTON); glutAddMenuEntry("Red Green",1); glutAddMenuEntry("Woven",2); glutAddMenuEntry("New Maps",3); glClearColor(0.0,0.0,0.0,1.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0,M_WID*1.5,0.0,M_WID, -100.0, 100.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glutDisplayFunc(redraw); glutIdleFunc(redraw); glutMotionFunc( motion); glutMouseFunc( mousebutton); glutKeyboardFunc( keyboard ); glutMainLoop(); return 0; }