/************************************************************************** T H I N . C *****************************************************************************/ /***************************************************************************** FILENAME : thin.c PURPOSE : (thinning algorithm) *****************************************************************************/ #include #include #include #include "isthdefs.h" #include "piece.h" #include "statline.h" extern int temp_image[512][512]; extern int file_create; /* flag */ extern int inverse_isthmus; /* flag */ int otherthin_vals[512]; int thin_vals[512]; int p[10]; char thin_strg[79]; int thin_x[2500], thin_y[2500], thin_length; /***************************************************************************** DO_THINNING *****************************************************************************/ do_thining (deltax, deltay, minx, miny, maxx, maxy) int deltax, deltay, minx, miny, maxx, maxy; { int looky; colors(20); classic_thin (deltax, deltay, minx, miny, maxx, maxy); printit ("end classic thin"); if (inverse_isthmus) { piece[currpiece].inv_isthnum = 0; VIS$STRING( "Inverse Isthmus", 's', minx+30, miny-25, 14, 255,255,255); } else { printit ("Postive Isthmus\n"); /*VIS$STRING( "Positive Isthmus", 's', minx+30, miny-25, 14, 255,255,255); */ piece[currpiece].isthnum = 0; piece[currpiece].inv_skelx[0] = 0; looky = ((maxy - miny) * 0.5) + miny; /* here */ #ifdef ROGER printf ("before draw line\n"); printf ("currpiece: %d minx: %d looky: %d maxx: %d, maxy: %d \n", currpiece, minx, looky, maxx, maxy); VIS$DRAWLINE (512, looky, 640, looky, 255); printf ("before sleep starting border follow\n"); sleep(1); #endif VIS$BORDER_FOLLOW(&thin_length,thin_x,thin_y,254,253,minx,looky,maxx,maxy,5); printf ("length from border follow %d \n", thin_length); if (thin_length > MAXBORDER) { printf ("DISASTER IS HERE ---> PATHCNT > MAXBORDER %d\n", thin_length); printf ("DISASTER IS HERE ---> PATHCNT > MAXBORDER %d\n", thin_length); } load_piece_ds(&thin_length,thin_x,thin_y,currpiece); } printit ("start make-graph"); make_graph (deltax, deltay, minx, miny, maxx, maxy); printit ("end make-graph"); if (file_create) { printit ("start writing a piece"); write_new_piece(currpiece); printit ("end writing a piece"); } /* endif file_create */ } /* end do_thinning */ /***************************************************************************** CLASSIC_THIN *****************************************************************************/ classic_thin(deltax, deltay, minx, miny, maxx, maxy) int deltax, deltay, minx, miny, maxx, maxy; { int i; int x,y,j, z; y=0; for (j=miny; j<=maxy; j++) { VIS$READ_HORIZONTAL_LINE (minx, j, deltax, temp_image[y]); y++; } for (i=0;i<=deltax;i++) { thin_vals[i] = 0; otherthin_vals[i] = 0; } y= 1; do { sprintf (thin_strg, "%d times thinning", y); printit (thin_strg); step_one(minx, miny, maxx, maxy, deltax, deltay); step_two(minx, miny, maxx, maxy, deltax, deltay); y++; } while (y < 3); printit ("rid diags"); rid_diagonals (minx, miny, maxx, maxy, deltax, deltay); } /***************************************************************************** STEP_ONE *****************************************************************************/ step_one(minx, miny, maxx, maxy, deltax, deltay) int minx, miny, maxx, maxy, deltax, deltay; { int i,j; int n,z, y, done = 1; for (j=1;j= 2 && n <= 6) && (p[4] == 0 || p[6] == 0 || (p[2] == 0 && p[8] == 0) ) && (trans_01(p) == 1) ) { thin_vals[i] = 0; done = 0; } else thin_vals[i] = 1; } } /* end if !=0*/ else thin_vals[i] = 0; } /* end for i*/ swap_thin_vals(j, deltax); } /* end for j */ return (done); } /* end thin */ /***************************************************************************** STEP_TWO *****************************************************************************/ step_two(minx, miny, maxx, maxy, deltax, deltay) int minx, miny, maxx, maxy; int deltax, deltay; { int i,j; int n,z, y, done = 1; for (j=1;j= 2 && n <= 6) && (p[2] == 0 || p[8] == 0 || (p[4] == 0 && p[6] == 0) ) && (trans_01(p) == 1) ) { thin_vals[i] = 0; done = 0; } else thin_vals[i] = 1; } } /* end if !=0*/ else thin_vals[i] = 0; } /* end for i*/ swap_thin_vals(j, deltax); } /* end for j */ return (done); } /* end thin */ /***************************************************************************** TRANS_01 *****************************************************************************/ trans_01(p) int p[10]; { int i,n = 0; for (i=2;i<=9;i++) if (i == 9) { if (p[9] == 0 && p[2] == 1) n++; } else if (p[i] == 0 && p[i+1] == 1) n++; return(n); }/* end trans */ /***************************************************************************** RID_DIAGONALS *****************************************************************************/ rid_diagonals (minx, miny, maxx, maxy, deltax, deltay) int minx, miny, maxx, maxy, deltax, deltay; { int i,j,y; for (j=1; j < deltay ; j++) for (i=5; i