struct object *straighten(obj, poly) struct object *obj, *poly; { struct object *strobj, *makemain(), *threshold(); struct intervaldomain *idom,*makedomain(); struct valuetable *vtbl,*makevaluetb(); struct polygondomain *p, *ply, *makepolydmn(); struct iwspace iwsp; struct gwspace gwsp; int strwidth,halfwidth,sline,mlines,i,*g; float x,y,sintheta,costheta; p = (struct polygondomain *) poly->idom; if (poly->type != 10 || p->type != 2) { fprintf(stderr,"not a type 2 polygon\n"); exit(91); } mlines = p->nvertices; /* * approximate mean width of object * this is used as half-width of straightened object */ halfwidth = area(obj)/mlines; if (halfwidth > 10) halfwidth = 10; strwidth = 1 + 2*halfwidth; /* * make a rectangular object with an empty grey table */ idom = makedomain(2,1,mlines,1,strwidth); vtbl = makevaluetb(1,1,mlines,0,NULL); strobj = makemain(1,idom,vtbl,NULL,obj); vtbl->original = strobj; /* have to make grey-table one bigger than might be thought necessary as somewhere there is a loss of sync !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ g = (int *) calloc(mlines*strwidth+1,sizeof(int)); for (i=1; i<=mlines; i++) { makevalueline(vtbl,i,1,strwidth,g); g += strwidth; } /* * start transformation */ initgreyscan(strobj,&iwsp,&gwsp); for (sline=1; sline<=mlines; sline++) { /* * get next column, line (x,y) in unit-spaced steps * along smoothed mid-points polygon, and local orientation. * sline is line number in straightened object */ setnextpoint(p,&x,&y,&sintheta,&costheta,sline); /* * rotate and fill rotated interval centred at x,y. */ nextgreyinterval(&iwsp); g = gwsp.grintptr; rotate(obj,x,y,sintheta,costheta,halfwidth,g); } /* * threshold to remove unset points */ strobj = threshold(strobj,1); return(strobj); }