apline.c

00001 /*
00002 
00003 $Id: apline.c,v 1.2 2006/06/06 13:04:22 jim Exp $
00004 
00005 */
00006 
00007 #include <stdio.h>
00008 #include "imcore.h"
00009 #include "util.h"
00010 
00011 void apline(ap_t *ap, float dat[], int conf[], float smoothed[], 
00012             float smoothedc[], int j,  unsigned char *bpm) {
00013     int i,i1,loop,nn;
00014     int is;    /* parent name for image in this slice */
00015     int ip;    /* parent name for image on last line */
00016     int ib;    /* data block name */
00017     float i2compare,icompare;
00018     unsigned char *mflag;
00019 
00020     i2compare = ap->thresh;
00021     icompare = i2compare * ap->multiply;
00022     mflag = ap->mflag;
00023 
00024     for (i = 0; i < ap->lsiz; i++) {
00025         if (smoothedc[i] > icompare && conf[i] != 0) {
00026 
00027             /* Pixel is above threshold, find which parent it belongs to. */
00028 
00029             is = ap->lastline[i];       /* Parent last pixel this line */
00030             ip = ap->lastline[i + 1];   /* Guess belongs to above line */
00031             if (ip == 0) {
00032 
00033                 /* New parent, or, horizontal slice: */
00034 
00035                 if (is == 0) {
00036 
00037                     /* Ah - new parent. */
00038 
00039                     ip = ap->pstack[ap->ipstack++];
00040                     ap->parent[ip].first = ap->bstack[ap->ibstack];
00041                     ap->parent[ip].pnop = 0;
00042                     ap->parent[ip].pnbp = 0;
00043                     ap->parent[ip].growing = 0;
00044                     if (j == 0)
00045 
00046                         /* It touches first line: */
00047 
00048                         ap->parent[ip].touch = 1;
00049                     else
00050                         ap->parent[ip].touch = 0;
00051 
00052                     /* For hunt thru list for terminates: */
00053 
00054                     if (ip > ap->maxip)
00055                         ap->maxip = ip;
00056                 } else {
00057 
00058                     /* Slice with no vertical join: */
00059 
00060                     ip = is;
00061                 }
00062             } else if ((ip > 0 && is > 0) && (ip != is)) {
00063 
00064                 /* merge: Join linked lists: */
00065 
00066                 ap->blink[ap->parent[ip].last] = ap->parent[is].first;
00067 
00068                 /* Copy `last block': */
00069 
00070                 ap->parent[ip].last = ap->parent[is].last;
00071                 ap->parent[ip].pnop += ap->parent[is].pnop;
00072                 ap->parent[ip].pnbp += ap->parent[is].pnbp;
00073 
00074                 /* Fix `lastline' correlator array: */
00075 
00076                 ib = ap->parent[is].first;
00077                 loop = 1;
00078                 while (loop) {
00079                     i1 = ap->plessey[ib].x;
00080                     if (ap->lastline[i1 + 1] == is)
00081                     ap->lastline[i1 + 1] = ip;
00082                     if (ap->parent[is].last == ib)
00083                         loop = 0;
00084                     else
00085                         ib = ap->blink[ib];
00086                 }
00087 
00088                 /* Mark parent inactive: */
00089 
00090                 ap->parent[is].pnop = -1;
00091                 ap->parent[is].pnbp = -1;
00092 
00093                 /* return name to stack: */
00094 
00095                 ap->pstack[--ap->ipstack] = is;
00096             }
00097 
00098             /* Add in pixel to linked list: */
00099 
00100             ib = ap->bstack[ap->ibstack++];
00101 
00102             /* Patch forward link into last data block: */
00103 
00104             if (ap->parent[ip].pnop > 0)
00105                 ap->blink[ap->parent[ip].last] = ib;
00106 
00107             /* Remember last block in chain: */
00108 
00109             ap->parent[ip].last = ib;
00110 
00111             /* Store the data: */
00112 
00113             ap->plessey[ib].x = i;
00114             ap->plessey[ib].y = j;
00115             ap->plessey[ib].z = dat[i];
00116             nn = j*ap->lsiz + i;
00117             if (mflag[nn] != MF_SATURATED)
00118                 ap->plessey[ib].zsm = MIN(ap->saturation,smoothed[i]);
00119             else
00120                 ap->plessey[ib].zsm = ap->saturation;
00121             mflag[nn] = MF_POBJPIX;
00122 
00123             /* increment active count: */
00124 
00125             ap->parent[ip].pnop++;
00126             if (bpm != NULL) 
00127                 ap->parent[ip].pnbp += bpm[i];
00128 
00129             /* remember which parent this pixel was for next line: */
00130 
00131             ap->lastline[i + 1] = ip;
00132 
00133         } else {
00134 
00135             /* Pixel was below threshold, mark lastline: */
00136 
00137             ap->lastline[i + 1] = 0;
00138         }
00139     }
00140 
00141     /* Check for images touching left & right edges:
00142        OR the touch flag with 2 for left, 4 for right: */
00143 
00144     if(ap->lastline[1] > 0 )
00145         ap->parent[ap->lastline[1]].touch |= 2;
00146     if(ap->lastline[ap->lsiz] > 0)
00147         ap->parent[ap->lastline[ap->lsiz]].touch |= 4;
00148 }
00149 
00150 /*
00151 
00152 $Log: apline.c,v $
00153 Revision 1.2  2006/06/06 13:04:22  jim
00154 Fixed apline so that it now takes confidence map info correctly
00155 
00156 Revision 1.1  2005/09/13 13:25:27  jim
00157 Initial entry after modifications to make cpl compliant
00158 
00159 
00160 */

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