/************************************************************************** R U N N E R . C ***************************************************************************/ /* Filename : runner.c * purpose : RUNNER.C is the main driver coordinating the show. From this driver CURV stuff, MAT stuff, GRAPHIC stuff, and MATCHING can be called. The four different areas all depend on the files named as such: thisdir/pieceinfo/piece##.xy ***************************************************************************/ #include #include #include #include "statline.h" #include "piece.h" #include "isthdefs.h" struct data piece[25]; int result; char strg[79]; /* for sprintf for printit */ double radt,dx,dy,thta; /* Variables for curvutil.c!! */ float ll; int camera = YES; int image_create = NO; int white_piece = NO; int file_create = NO; int inverse_isthmus = NO; int draw_is_on = NO; int debug = NO; int no_thinning = NO; /* NO means thinning is ON and will be done */ int no_circle = YES; int cpu_time = NO; /* timer for neardear.c */ int scaleit = NO, /* defaults */ smooth_it = NO; int band=0; int deltax, deltay; int image[512][512]; int border_x[512][512]; int border_y[512][512]; int dist_image[512][512]; int temp_image[512][512]; int localx[2500], localy[2500], locallength; int row,col; int top = 2; int bot = 20; char *commsg[19]; WINDOW *stdscr, *cmdwin, *funcwin; int done; /************************************************************************** This is the vision driver program. It first defines the windows that are used in the program. The command window lists all available commands that the user can execute. The function window acts as a sub-menu to the command window. Movement in the windows is done with the arrow keys on the keyboard. The initial positions of the box and cursor are also defined. Actions are performed upon hitting the space bar. The program is terminated when the EXIT option is chosen. ***************************************************************************/ main() { int c; /*** DEFAULTS SET HERE */ currpiece = 9; resl = 5; piecenum = 4; /*** END DEFAULTS */ set_up(); init_comms(); initscr(); crmode(); noecho(); cmdwin = subwin(stdscr,22,12,0,0); clearok(cmdwin,TRUE); wclear(cmdwin); wrefresh(cmdwin); funcwin = subwin(stdscr,22,66,0,13); clearok(funcwin,TRUE); wclear(funcwin); wrefresh(funcwin); row = top; box(cmdwin,VERTCH,HORZCH); wrefresh(cmdwin); display_comm(); done = 0; do { wstandend(cmdwin); box(funcwin,VERTCH,HORZCH); wrefresh(funcwin); explain_comm(); highlite(); getyx(cmdwin,row,col); c = wgetch(funcwin); switch( c ) { case 'e': done = 1; break; case 'm': initialize(); matdriver(); break; case 'c': initialize(); curvdriver(); break; case SPACE: makecalls(row); break; case ESC : if ( wgetch(funcwin) == LBRACKET ) { switch( wgetch(funcwin) ) { case UPC: moveup(); break; case DOWNC: movedown(); break; default : BELL; break; } } break; default : BELL; break; } getyx(cmdwin,row,col); wrefresh(cmdwin); wrefresh(funcwin); } while ( !done ); echo(); nocrmode(); wclear(funcwin); wrefresh(funcwin); wclear(cmdwin); wrefresh(cmdwin); endwin(); echo(); nocrmode(); } /* end main program loop */ /*************************************************************************** This procedure will make the function call to the command option that is chosen. The call is based on the row that the cursor is in when the space bar is pressed. Upon completion of the selected task, control switches back to the command window. ******************************************************************************/ makecalls(row) int row; { char gwbuff[81]; int i, pos_no, x; switch( row ) { case 2 : /* Setup init */ set_up(); break; case 3 : initialize(); matdriver(); break; case 4 : initialize(); curvdriver(); break; case 5 : view(); break; case 6 : freeze(); break; case 7 : load_all_pieces(piecenum); break; case 8 : best_fitter(piecenum); break; case 9 : selt_no_pieces(&piecenum); break; case 10 : white_piece = NO; break; case 11 : white_piece = YES; break; case 12 : inverse_isthmus = (inverse_isthmus == 1) ? 0:1; printstat(0,0,0); /*selt_band(&band); printstat(0,0,0); */ break; case 13 : /*debug = (debug == 1) ? 0:1; */ no_thinning = (no_thinning == 1) ? 0:1; break; case 14 : getdata (&pos_no); for (x=pos_no; x < piece[currpiece].isthnum; x++) { piece[currpiece].dmtisth[x] = piece[currpiece].dmtisth[x+1]; } piece[currpiece].isthnum = piece[currpiece].isthnum -1; break; case 15 : camera = 1; break; case 16 : file_create = 0; break; case 17 : file_create = 1; break; case 18 : /* seltpiece(&currpiece); printstat(0,0,0); */ no_circle = (no_circle == 1) ? 0:1; break; case 19 : boxstuff(); wclear(cmdwin); wrefresh(cmdwin); display_comm(); wrefresh(cmdwin); break; case 20 : done = 1; break; default : break; } /* end case */ } /* end makecalls */ /**************************************************************************** This procedure will display all the commands available to the user in the command window. ****************************************************************************/ display_comm() { int i; wmove(cmdwin,0,1); wstandout(cmdwin); waddstr(cmdwin," COMMANDS "); wstandend(cmdwin); for (i=top;i<=bot;i++) { wmove(cmdwin,i,2); waddstr(cmdwin,commsg[i-top]); } wrefresh(cmdwin); } /*************************************************************************** This procedure will instruct the user how to select a command to be performed. ****************************************************************************/ explain_comm() { wmove(funcwin,3,7); waddstr(funcwin," TEMPLE UNIVERSITY "); wmove(funcwin,5,7); waddstr(funcwin,"MACHINE VISION JIGSAW PUZZLE ASSEMBLY SYSTEM"); wmove(funcwin,7,12); waddstr(funcwin,"-------------------------------------"); wmove(funcwin,9,22); waddstr(funcwin," by"); wmove(funcwin,11,19); waddstr(funcwin," Roger W. Webster"); wmove(funcwin,15,12); waddstr(funcwin,"use ARROW keys to select function"); wmove(funcwin,16,12); waddstr(funcwin,"hit SPACE bar to execute function"); wrefresh(funcwin); } /***************************************************************************** This procedure defines the commands to be displayed in the command window. *****************************************************************************/ init_comms() { commsg[0] = " Set Up "; commsg[1] = "MAT Drivr"; commsg[2] = "Curv Drvr"; commsg[3] = "View "; commsg[4] = "Freeze "; commsg[5] = "Load up P"; commsg[6] = "Best Fit "; commsg[7] = "No Pieces"; commsg[8] = "WhiteBack"; commsg[9] = "BlackBack"; commsg[10] = "Inverse "; commsg[11] = "THINNING "; commsg[12] = "isth edit"; commsg[13] = "Camera Y "; commsg[14] = "File cr N"; commsg[15] = "File cr Y"; commsg[16] = "CIRCLE ON"; commsg[17] = "BOX "; commsg[18] = "Exit "; } /************************************************************************** This procedure will move the highlited cursor up one row in the command window. If the cursor is already at the top of the command list, calling this procedure will cause the cursor to wrap around to the bottom of the command list. **************************************************************************/ moveup() { wmove(cmdwin,row,2); wstandend(cmdwin); waddstr(cmdwin,commsg[row-top]); wrefresh(cmdwin); if ( row == top ) row = bot; else row--; highlite(); } /************************************************************************** This procedure will move the highlited cursor down one row in the command window. If the cursor is already at the bottom of the command list, calling this procedure will cause the cursor to wrap around to the top of the command list. **************************************************************************/ movedown() { wmove(cmdwin,row,2); wstandend(cmdwin); waddstr(cmdwin,commsg[row-top]); wrefresh(cmdwin); if ( row == bot ) row = top; else row++; highlite(); } /**************************************************************************** This procedure will highlite the position of the current cursor. ****************************************************************************/ highlite() { wmove(cmdwin,row,2); wstandout(cmdwin); waddstr(cmdwin,commsg[row-top]); wrefresh(cmdwin); wmove(cmdwin,row,0); } initialize() { init_comms(); initscr(); crmode(); noecho(); cmdwin = subwin(stdscr,22,12,0,0); clearok(cmdwin,TRUE); wclear(cmdwin); wrefresh(cmdwin); funcwin = subwin(stdscr,22,66,0,13); clearok(funcwin,TRUE); wclear(funcwin); wrefresh(funcwin); box(cmdwin,VERTCH,HORZCH); wrefresh(cmdwin); display_comm(); done = 0; } set_up() { VIS$MAP(); VIS$INIT_FB(); VIS$INIT_LUTS(); VIS$VIEW(); initluts(); if (!camera) redscrn(); VIS$SELECT_LUT(0,0); VIS$SELECT_LUT(1,0); VIS$SELECT_LUT(2,0); VIS$SELECT_LUT(3,0); }