terminate.c

00001 /*
00002 
00003 $Id: terminate.c,v 1.2 2007/03/01 12:38:26 jim Exp $
00004 
00005 */
00006 
00007 #include <stdio.h>
00008 #include "imcore.h"
00009 #include "util.h"
00010 
00011 extern void restack(ap_t *ap, int ip) {
00012     int i,ib;
00013 
00014     ib = ap->parent[ip].first;
00015     for(i = ap->ibstack - ap->parent[ip].pnop; i < ap->ibstack-1;  i++) {
00016 
00017         /* Stash all blocks back in a burst: */
00018     
00019         ap->bstack[i] = ib;
00020         ib = ap->blink[ib];
00021     }
00022 
00023     /* and the last one: */
00024 
00025     ap->bstack[ap->ibstack-1] = ib;
00026     ap->ibstack -= ap->parent[ip].pnop;
00027 
00028     /* Put parent name back on stack: */
00029 
00030     ap->pstack[--ap->ipstack] = ip;
00031 
00032     /* Mark that parent inactive: */
00033 
00034     ap->parent[ip].pnop = -1;
00035     ap->parent[ip].pnbp = -1;
00036 }
00037 
00038 extern void terminate(ap_t *ap) {
00039     int ip,status;
00040 
00041     /* Search through all possible parents!  */
00042 
00043     for (ip = 1; ip <= ap->maxip; ip++) {
00044         if(ap->parent[ip].pnop != -1) {
00045             if(ap->parent[ip].pnop == ap->parent[ip].growing) {
00046 
00047                 /* That's a termination: */
00048 
00049                 if((ap->parent[ip].pnop >= ap->ipnop &&
00050                     ap->parent[ip].touch == 0) &&
00051                     (ap->parent[ip].pnbp < (ap->parent[ip].pnop)/2)) {
00052                     extract_data(ap,ip);
00053                     
00054                     /* Call the processing routine */
00055 
00056                     status = process_results(ap);
00057                     if (status != VIR_OK) {
00058                         restack(ap,ip);
00059                         continue;
00060                     }
00061                 }
00062                 restack(ap,ip);
00063             } else {
00064 
00065                 /* This parent still active: */
00066 
00067                 ap->parent[ip].growing = ap->parent[ip].pnop;
00068             }
00069         }
00070     }
00071 }
00072 
00073 extern void apfu(ap_t *ap) {
00074     int ip, big, ipbig;
00075 
00076     /* Search through all possible parents and just junk the biggest
00077        one to free space:  */
00078 
00079     big = 0;
00080     ipbig = 0;
00081     for (ip = 1; ip <= ap->maxip; ip++) {
00082         if(ap->parent[ip].pnop != -1) {
00083             if(ap->parent[ip].pnop > big) {
00084                 big = ap->parent[ip].pnop;
00085                 ipbig = ip;
00086             }
00087         }
00088     }
00089     if(big > 0) {
00090         restack(ap, ipbig);
00091 
00092         /* clearout lastline references to this parent: */
00093 
00094         for (ip = 0; ip <= ap->lsiz; ip++)
00095             if(ap->lastline[ip] == ipbig) ap->lastline[ip] = 0;
00096     }
00097 }
00098 
00099 extern void extract_data(ap_t *ap, int ip) {
00100     int ib,i,np,nn;
00101     unsigned char *mflag;
00102 
00103     /* Check the size of the workspace and see if it's big enough. If it
00104        isn't then increase the size until it is */
00105 
00106     np = ap->parent[ip].pnop;
00107     if (ap->npl < np) {
00108         ap->plarray = cpl_realloc(ap->plarray,np*sizeof(plstruct));
00109         ap->npl = np;
00110     }
00111 
00112     /* Pull the info out now */
00113 
00114     ib = ap->parent[ip].first;
00115     ap->npl_pix = np;
00116     mflag = ap->mflag;
00117     for (i = 0; i < np; i++) {
00118         ap->plarray[i].x = ap->plessey[ib].x + 1;
00119         ap->plarray[i].y = ap->plessey[ib].y + 1;
00120         ap->plarray[i].z = ap->plessey[ib].z;
00121         ap->plarray[i].zsm = ap->plessey[ib].zsm;
00122         nn = ap->plessey[ib].y*ap->lsiz + ap->plessey[ib].x;
00123         mflag[nn] = MF_OBJPIX;
00124         ib = ap->blink[ib];
00125     }
00126 }
00127 
00128 /*
00129 
00130 $Log: terminate.c,v $
00131 Revision 1.2  2007/03/01 12:38:26  jim
00132 Small modifications after a bit of code checking
00133 
00134 Revision 1.1  2005/09/13 13:25:31  jim
00135 Initial entry after modifications to make cpl compliant
00136 
00137 
00138 */

Generated on Sat Apr 6 04:03:07 2013 for VIRCAM Pipeline by  doxygen 1.5.1