apline.c

00001 /* $Id: apline.c,v 1.6 2010/09/13 11:40:13 jim Exp $
00002  *
00003  * This file is part of the VIRCAM Pipeline
00004  * Copyright (C) 2005 Cambridge Astronomy Survey Unit
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 /*
00022  * $Author: jim $
00023  * $Date: 2010/09/13 11:40:13 $
00024  * $Revision: 1.6 $
00025  * $Name: v1-1-0 $
00026  */
00027 
00028 #include <stdio.h>
00029 #include "imcore.h"
00030 #include "util.h"
00031 
00034 /*---------------------------------------------------------------------------*/
00073 /*---------------------------------------------------------------------------*/
00074 
00075 void apline(ap_t *ap, float dat[], float conf[], float smoothed[], 
00076             float smoothedc[], int j, unsigned char *bpm) {
00077     int i,i1,loop,nn;
00078     int is;    /* parent name for image in this slice */
00079     int ip;    /* parent name for image on last line */
00080     int ib;    /* data block name */
00081     float i2compare,icompare;
00082     unsigned char *mflag;
00083 
00084     i2compare = ap->thresh;
00085     icompare = i2compare * ap->multiply;
00086     mflag = ap->mflag;
00087 
00088     for (i = 0; i < ap->lsiz; i++) {
00089         if (smoothedc[i] > icompare && conf[i] != 0) {
00090 
00091             /* Pixel is above threshold, find which parent it belongs to. */
00092 
00093             is = ap->lastline[i];       /* Parent last pixel this line */
00094             ip = ap->lastline[i + 1];   /* Guess belongs to above line */
00095             if (ip == 0) {
00096 
00097                 /* New parent, or, horizontal slice: */
00098 
00099                 if (is == 0) {
00100 
00101                     /* Ah - new parent. */
00102 
00103                     ip = ap->pstack[ap->ipstack++];
00104                     ap->parent[ip].first = ap->bstack[ap->ibstack];
00105                     ap->parent[ip].pnop = 0;
00106                     ap->parent[ip].pnbp = 0;
00107                     ap->parent[ip].growing = 0;
00108                     if (j == 0)
00109 
00110                         /* It touches first line: */
00111 
00112                         ap->parent[ip].touch = 1;
00113                     else
00114                         ap->parent[ip].touch = 0;
00115 
00116                     /* For hunt thru list for terminates: */
00117 
00118                     if (ip > ap->maxip)
00119                         ap->maxip = ip;
00120                 } else {
00121 
00122                     /* Slice with no vertical join: */
00123 
00124                     ip = is;
00125                 }
00126             } else if ((ip > 0 && is > 0) && (ip != is)) {
00127 
00128                 /* merge: Join linked lists: */
00129 
00130                 ap->blink[ap->parent[ip].last] = ap->parent[is].first;
00131 
00132                 /* Copy `last block': */
00133 
00134                 ap->parent[ip].last = ap->parent[is].last;
00135                 ap->parent[ip].pnop += ap->parent[is].pnop;
00136                 ap->parent[ip].pnbp += ap->parent[is].pnbp;
00137 
00138                 /* Fix `lastline' correlator array: */
00139 
00140                 ib = ap->parent[is].first;
00141                 loop = 1;
00142                 while (loop) {
00143                     i1 = ap->plessey[ib].x;
00144                     if (ap->lastline[i1 + 1] == is)
00145                     ap->lastline[i1 + 1] = ip;
00146                     if (ap->parent[is].last == ib)
00147                         loop = 0;
00148                     else
00149                         ib = ap->blink[ib];
00150                 }
00151 
00152                 /* Mark parent inactive: */
00153 
00154                 ap->parent[is].pnop = -1;
00155                 ap->parent[is].pnbp = -1;
00156 
00157                 /* return name to stack: */
00158 
00159                 ap->pstack[--ap->ipstack] = is;
00160             }
00161 
00162             /* Add in pixel to linked list: */
00163 
00164             ib = ap->bstack[ap->ibstack++];
00165 
00166             /* Patch forward link into last data block: */
00167 
00168             if (ap->parent[ip].pnop > 0)
00169                 ap->blink[ap->parent[ip].last] = ib;
00170 
00171             /* Remember last block in chain: */
00172 
00173             ap->parent[ip].last = ib;
00174 
00175             /* Store the data: */
00176 
00177             ap->plessey[ib].x = i;
00178             ap->plessey[ib].y = j;
00179             ap->plessey[ib].z = dat[i];
00180             nn = j*ap->lsiz + i;
00181             if (mflag[nn] != MF_SATURATED)
00182                 ap->plessey[ib].zsm = MIN(ap->saturation,smoothed[i]);
00183             else
00184                 ap->plessey[ib].zsm = ap->saturation;
00185             mflag[nn] = MF_POSSIBLEOBJ;
00186 
00187             /* increment active count: */
00188 
00189             ap->parent[ip].pnop++;
00190             if (bpm != NULL) 
00191                 ap->parent[ip].pnbp += bpm[i];
00192 
00193             /* remember which parent this pixel was for next line: */
00194 
00195             ap->lastline[i + 1] = ip;
00196 
00197         } else {
00198 
00199             /* Pixel was below threshold, mark lastline: */
00200 
00201             ap->lastline[i + 1] = 0;
00202         }
00203     }
00204 
00205     /* Check for images touching left & right edges:
00206        OR the touch flag with 2 for left, 4 for right: */
00207 
00208     if(ap->lastline[1] > 0 )
00209         ap->parent[ap->lastline[1]].touch |= 2;
00210     if(ap->lastline[ap->lsiz] > 0)
00211         ap->parent[ap->lastline[ap->lsiz]].touch |= 4;
00212 }
00213 
00216 /*
00217 
00218 $Log: apline.c,v $
00219 Revision 1.6  2010/09/13 11:40:13  jim
00220 Fixed declaration error
00221 
00222 Revision 1.5  2010/09/09 12:09:57  jim
00223 Added docs
00224 
00225 Revision 1.4  2009/01/23 12:24:33  jim
00226 Fixed bugs in pixel flagging
00227 
00228 Revision 1.3  2008/10/13 08:08:35  jim
00229 Fixed object pixel flagging
00230 
00231 Revision 1.2  2006/06/06 13:04:22  jim
00232 Fixed apline so that it now takes confidence map info correctly
00233 
00234 Revision 1.1  2005/09/13 13:25:27  jim
00235 Initial entry after modifications to make cpl compliant
00236 
00237 
00238 */

Generated on 7 Feb 2011 for VIRCAM Pipeline by  doxygen 1.6.1