/* * dcsplit.c Simon Towers 10-03-87 * * dcsplit [-p] [-o] * composite detection and splitting * */ #include #include #include #include #include #define FIP 0 /*#define FIP 1 /* FIP digitisation assumed */ main(argc, argv) int argc; char **argv; { struct chromosome *objlist[100], *readobj(); int i, maxobjs=0, oflag=0, pflag=0; while (argc>1 && argv[1][0]=='-') { switch (argv[1][1]) { case 'o': oflag++; break; case 'p': pflag++; break; default: fprintf(stderr, "unrecognised switch -%c\n", argv[1][1]); break; } argc--; argv++; } /* read objects comprising an entire cell */ while ((objlist[maxobjs] = readobj(stdin)) != NULL) maxobjs++; /* For non-manually-derived objects, loop making measurements */ /* e.g. as basis of statistical classifier */ for (i=0 ; iplist->otype == COMPOSITE) comp_split(objlist[i], objlist, &maxobjs, i+1); if (objlist[i]->plist->otype == OVERLAP) over_split(objlist[i], objlist, &maxobjs, i+1); } /* Loop, evaluating and printing results. This could * include a measure of similarity between manually * and automatically derived objects */ eval_and_print(objlist, maxobjs, oflag, pflag); } manually_derived(obj) struct chromosome *obj; { if (obj->plist->history[0]) return(1); return(0); } make_measurements(obj) struct chromosome *obj; { } comp_classify(obj) struct chromosome *obj; { struct object *spobj, *dcvertical(); struct polygondomain *boundary; struct histogramdomain *hist, *hist_diff, *bound_curv(); spobj = dcvertical(obj, FIP); hist = bound_curv(spobj, &boundary, &hist_diff); bound_comp(obj, spobj, boundary, hist, hist_diff); freeobj(spobj); free(boundary); free(hist); free(hist_diff); } eval_and_print(objlist, maxobjs, oflag, pflag) struct chromosome *objlist[]; int maxobjs, oflag, pflag; { struct chromosome *obj; int *history, sums[4], i, a; for (i=0 ; i<4 ; i++) sums[i] = 0; if (pflag) for (i=0 ; iplist->number); history = obj->plist->history; printf("otype=%d pnum=%d history=%d %d %d %d %d %d %d %d\n", obj->plist->otype, obj->plist->pnumber, history[0], history[1], history[2], history[3], history[4], history[5], history[6], history[7]); printf("Cotype=%d\n\n", obj->plist->Cotype); } /* sums[0] = !manually_derived objects * sums[1] = identified as composite, but not true * sums[2] = not identified, but true * sums[3] = identified and true */ if (oflag) { for (i=0 ; iplist->otype == COMPOSITE) a++; if (true_composite(objlist[i])) a += 2; if (a > 0) sums[a]++; } printf(" %d %d %d %d\n", sums[0], sums[1], sums[2], sums[3]); } for (i=0 ; iplist->history; if (obj->plist->Cotype == COMPOSITE || (obj->plist->Cotype == UNKNOWN && (history[1] == 1 || history[1] == 2))) return(1); return(0); } /* simon.c * * split a composite * ------------- * ji Liang Mar 1, 1987 */ comp_split(obj, objlist, num, parent) struct chromosome *obj; struct object **objlist; int *num, parent; { struct object *sobj[2], *splitcomps(); struct object *polytoobj(), *tobj; struct object *splithole(), *temp_obj, *newgrey(); struct object *ibound(); struct intervaldomain *newidomain(); struct boundlist *blist; struct polygondomain *boundary(), *plgd; struct polygondomain *tlgd, *pathtest(); struct chromplist *plist, *makechromplist(); struct ivertex tp[4], *wtx; int i, n; /* * if there is a hole split it at first */ temp_obj = newgrey(obj); temp_obj->idom = newidomain(obj->idom); temp_obj->plist = NULL; blist = (struct boundlist *) ibound(temp_obj, 1)->idom; if(blist->down != 0){ temp_obj = splithole(temp_obj, blist); plgd = boundary(temp_obj, 0); } else plgd = blist->poly; /* * find the split curve and cut points * change the curve into an object * then split the composite along this curve * finally restore the grey level */ if((tlgd = pathtest(temp_obj, plgd, tp)) == NULL){ fprintf(stderr,"The object is not composite \n"); return(0); } else { tobj = polytoobj(tlgd); sobj[0] = splitcomps(temp_obj, tobj); if(sobj[0]->assoc == 0) fprintf(stderr,"\n can not pass the second obj\n\n"); sobj[1] = sobj[0]->assoc; n = *num; for(i = 0; i < 2; i++){ sobj[i]->plist = (struct propertylist *) makechromplist(); plist = (struct chromplist *) sobj[i]->plist; plist->pnumber = parent; plist->history[2] = 1; restoregrey(sobj[i], temp_obj); objlist[n++] = sobj[i]; plist->number = n; } *num = n; return(1); } }