void process_input(Matrix3x3 &M){ char command[1024]; bool done; float theta, s, cx, cy; float sx, sy, shx, shy, px, py; int dx, dy; /* build identity matrix */ M.identity(); for(done = false; !done;) { /* prompt and accept input, converting text to lower case */ cout << "> "; cin >> command; lowercase(command); /* parse the input command, and read parameters as needed */ if(strcmp(command, "d") == 0) { done = true; imageData = Manipulation::warper(imageData, M); } else if(strcmp(command, "n") == 0) {// twirl if(cin >> s >> cx >> cy) imageData = Manipulation::twirl(imageData, s, cx, cy); else cout << "invalid twirl parameter\n"; done = true; } else if(strlen(command) != 1) {
/* Routine to build a projective transform from input text, display, or write transformed image to a file */ void process_input(Matrix3x3 &M) { char command[1024]; bool done; float theta; float inputX; float inputY; float inputZ; /* build identity matrix */ M.identity(); for(done = false; !done;) { /* prompt and accept input, converting text to lower case */ printf("> "); scanf("%s", command); lowercase(command); /* parse the input command, and read parameters as needed */ if(strcmp(command, "d") == 0) { done = true; } else if(strlen(command) != 1) { printf("invalid command, enter r, s, t, h, d\n"); } else { switch(command[0]) { case 'r': /* Rotation, accept angle in degrees */ if(scanf("%f", &theta) == 1) Rotate(M, theta); else fprintf(stderr, "invalid rotation angle\n"); break; case 's': /* Scale, accept scale factors */ if(scanf("%f %f", &inputX, &inputY)) Scale(M, inputX, inputY); else fprintf(stderr,"invalid scaling input\n"); break; case 't': /* Translation, accept translations */ if(scanf("%f %f", &inputX, &inputY)) Translate(M, inputX, inputY); else fprintf(stderr,"invalid scaling input\n"); break; case 'h': /* Shear, accept shear factors */ if(scanf("%f %f", &inputX, &inputY)) Shear(M, inputX, inputY); else fprintf(stderr,"invalid scaling input\n"); break; //twirl mode on case 'n': if(scanf("%f %f %f", &inputX, &inputY, &inputZ)) { manager.turnTwrilModeOn(inputX, inputY, inputZ); } else { fprintf(stderr, "invalid scaling input\n"); } break; case 'p': if(scanf("%f %f", &inputX, &inputY)) Perspective(M, inputX, inputY); else fprintf(stderr,"invalid scaling input\n"); break; case 'd': /* Done, that's all for now */ done = true; break; default: printf("invalid command, enter r, s, t, h, d\n"); } } } }