VIRCAM Pipeline  1.3.3
apline.c
1 /* $Id: apline.c,v 1.6 2010-09-13 11:40:13 jim Exp $
2  *
3  * This file is part of the VIRCAM Pipeline
4  * Copyright (C) 2005 Cambridge Astronomy Survey Unit
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 /*
22  * $Author: jim $
23  * $Date: 2010-09-13 11:40:13 $
24  * $Revision: 1.6 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 #include <stdio.h>
29 #include "imcore.h"
30 #include "util.h"
31 
34 /*---------------------------------------------------------------------------*/
73 /*---------------------------------------------------------------------------*/
74 
75 void apline(ap_t *ap, float dat[], float conf[], float smoothed[],
76  float smoothedc[], int j, unsigned char *bpm) {
77  int i,i1,loop,nn;
78  int is; /* parent name for image in this slice */
79  int ip; /* parent name for image on last line */
80  int ib; /* data block name */
81  float i2compare,icompare;
82  unsigned char *mflag;
83 
84  i2compare = ap->thresh;
85  icompare = i2compare * ap->multiply;
86  mflag = ap->mflag;
87 
88  for (i = 0; i < ap->lsiz; i++) {
89  if (smoothedc[i] > icompare && conf[i] != 0) {
90 
91  /* Pixel is above threshold, find which parent it belongs to. */
92 
93  is = ap->lastline[i]; /* Parent last pixel this line */
94  ip = ap->lastline[i + 1]; /* Guess belongs to above line */
95  if (ip == 0) {
96 
97  /* New parent, or, horizontal slice: */
98 
99  if (is == 0) {
100 
101  /* Ah - new parent. */
102 
103  ip = ap->pstack[ap->ipstack++];
104  ap->parent[ip].first = ap->bstack[ap->ibstack];
105  ap->parent[ip].pnop = 0;
106  ap->parent[ip].pnbp = 0;
107  ap->parent[ip].growing = 0;
108  if (j == 0)
109 
110  /* It touches first line: */
111 
112  ap->parent[ip].touch = 1;
113  else
114  ap->parent[ip].touch = 0;
115 
116  /* For hunt thru list for terminates: */
117 
118  if (ip > ap->maxip)
119  ap->maxip = ip;
120  } else {
121 
122  /* Slice with no vertical join: */
123 
124  ip = is;
125  }
126  } else if ((ip > 0 && is > 0) && (ip != is)) {
127 
128  /* merge: Join linked lists: */
129 
130  ap->blink[ap->parent[ip].last] = ap->parent[is].first;
131 
132  /* Copy `last block': */
133 
134  ap->parent[ip].last = ap->parent[is].last;
135  ap->parent[ip].pnop += ap->parent[is].pnop;
136  ap->parent[ip].pnbp += ap->parent[is].pnbp;
137 
138  /* Fix `lastline' correlator array: */
139 
140  ib = ap->parent[is].first;
141  loop = 1;
142  while (loop) {
143  i1 = ap->plessey[ib].x;
144  if (ap->lastline[i1 + 1] == is)
145  ap->lastline[i1 + 1] = ip;
146  if (ap->parent[is].last == ib)
147  loop = 0;
148  else
149  ib = ap->blink[ib];
150  }
151 
152  /* Mark parent inactive: */
153 
154  ap->parent[is].pnop = -1;
155  ap->parent[is].pnbp = -1;
156 
157  /* return name to stack: */
158 
159  ap->pstack[--ap->ipstack] = is;
160  }
161 
162  /* Add in pixel to linked list: */
163 
164  ib = ap->bstack[ap->ibstack++];
165 
166  /* Patch forward link into last data block: */
167 
168  if (ap->parent[ip].pnop > 0)
169  ap->blink[ap->parent[ip].last] = ib;
170 
171  /* Remember last block in chain: */
172 
173  ap->parent[ip].last = ib;
174 
175  /* Store the data: */
176 
177  ap->plessey[ib].x = i;
178  ap->plessey[ib].y = j;
179  ap->plessey[ib].z = dat[i];
180  nn = j*ap->lsiz + i;
181  if (mflag[nn] != MF_SATURATED)
182  ap->plessey[ib].zsm = MIN(ap->saturation,smoothed[i]);
183  else
184  ap->plessey[ib].zsm = ap->saturation;
185  mflag[nn] = MF_POSSIBLEOBJ;
186 
187  /* increment active count: */
188 
189  ap->parent[ip].pnop++;
190  if (bpm != NULL)
191  ap->parent[ip].pnbp += bpm[i];
192 
193  /* remember which parent this pixel was for next line: */
194 
195  ap->lastline[i + 1] = ip;
196 
197  } else {
198 
199  /* Pixel was below threshold, mark lastline: */
200 
201  ap->lastline[i + 1] = 0;
202  }
203  }
204 
205  /* Check for images touching left & right edges:
206  OR the touch flag with 2 for left, 4 for right: */
207 
208  if(ap->lastline[1] > 0 )
209  ap->parent[ap->lastline[1]].touch |= 2;
210  if(ap->lastline[ap->lsiz] > 0)
211  ap->parent[ap->lastline[ap->lsiz]].touch |= 4;
212 }
213 
216 /*
217 
218 $Log: not supported by cvs2svn $
219 Revision 1.5 2010/09/09 12:09:57 jim
220 Added docs
221 
222 Revision 1.4 2009/01/23 12:24:33 jim
223 Fixed bugs in pixel flagging
224 
225 Revision 1.3 2008/10/13 08:08:35 jim
226 Fixed object pixel flagging
227 
228 Revision 1.2 2006/06/06 13:04:22 jim
229 Fixed apline so that it now takes confidence map info correctly
230 
231 Revision 1.1 2005/09/13 13:25:27 jim
232 Initial entry after modifications to make cpl compliant
233 
234 
235 */