00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <stdio.h>
00029 #include "imcore.h"
00030 #include "util.h"
00031
00034
00062
00063
00064 extern void restack(ap_t *ap, int ip) {
00065 int i,ib,nn,np;
00066 unsigned char *mflag;
00067
00068
00069
00070 np = ap->parent[ip].pnop;
00071 ib = ap->parent[ip].first;
00072 mflag = ap->mflag;
00073 for (i = 0; i < np; i++) {
00074 nn = ap->plessey[ib].y*ap->lsiz + ap->plessey[ib].x;
00075 mflag[nn] = MF_POSSIBLEOBJ;
00076 ib = ap->blink[ib];
00077 }
00078
00079
00080
00081 ib = ap->parent[ip].first;
00082 for(i = ap->ibstack - ap->parent[ip].pnop; i < ap->ibstack-1; i++) {
00083 ap->bstack[i] = ib;
00084 ib = ap->blink[ib];
00085 }
00086
00087
00088
00089 ap->bstack[ap->ibstack-1] = ib;
00090 ap->ibstack -= ap->parent[ip].pnop;
00091
00092
00093
00094 ap->pstack[--ap->ipstack] = ip;
00095
00096
00097
00098 ap->parent[ip].pnop = -1;
00099 ap->parent[ip].pnbp = -1;
00100 }
00101
00102
00128
00129
00130 extern void terminate(ap_t *ap) {
00131 int ip,status;
00132
00133
00134
00135 for (ip = 1; ip <= ap->maxip; ip++) {
00136 if(ap->parent[ip].pnop != -1) {
00137 if(ap->parent[ip].pnop == ap->parent[ip].growing) {
00138
00139
00140
00141 if((ap->parent[ip].pnop >= ap->ipnop &&
00142 ap->parent[ip].touch == 0) &&
00143 (ap->parent[ip].pnbp < (ap->parent[ip].pnop)/2)) {
00144 extract_data(ap,ip);
00145
00146
00147
00148 status = process_results(ap);
00149 if (status != VIR_OK) {
00150 restack(ap,ip);
00151 continue;
00152 }
00153 }
00154 restack(ap,ip);
00155 } else {
00156
00157
00158
00159 ap->parent[ip].growing = ap->parent[ip].pnop;
00160 }
00161 }
00162 }
00163 }
00164
00165
00190
00191
00192 extern void apfu(ap_t *ap) {
00193 int ip, big, ipbig;
00194
00195
00196
00197
00198 big = 0;
00199 ipbig = 0;
00200 for (ip = 1; ip <= ap->maxip; ip++) {
00201 if(ap->parent[ip].pnop != -1) {
00202 if(ap->parent[ip].pnop > big) {
00203 big = ap->parent[ip].pnop;
00204 ipbig = ip;
00205 }
00206 }
00207 }
00208 if(big > 0) {
00209 restack(ap, ipbig);
00210
00211
00212
00213 for (ip = 0; ip <= ap->lsiz; ip++)
00214 if(ap->lastline[ip] == ipbig) ap->lastline[ip] = 0;
00215 }
00216 }
00217
00218
00246
00247
00248 extern void extract_data(ap_t *ap, int ip) {
00249 int ib,i,np,nn;
00250 unsigned char *mflag;
00251
00252
00253
00254
00255 np = ap->parent[ip].pnop;
00256 if (ap->npl < np) {
00257 ap->plarray = cpl_realloc(ap->plarray,np*sizeof(plstruct));
00258 ap->npl = np;
00259 }
00260
00261
00262
00263 ib = ap->parent[ip].first;
00264 ap->npl_pix = np;
00265 mflag = ap->mflag;
00266 for (i = 0; i < np; i++) {
00267 ap->plarray[i].x = ap->plessey[ib].x + 1;
00268 ap->plarray[i].y = ap->plessey[ib].y + 1;
00269 ap->plarray[i].z = ap->plessey[ib].z;
00270 ap->plarray[i].zsm = ap->plessey[ib].zsm;
00271 nn = ap->plessey[ib].y*ap->lsiz + ap->plessey[ib].x;
00272 mflag[nn] = MF_OBJPIX;
00273 ib = ap->blink[ib];
00274 }
00275 }
00276
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295