VIRCAM Pipeline 2.3.15
apline.c
1/* $Id: apline.c,v 1.3 2015/08/12 11:16:55 jim Exp $
2 *
3 * This file is part of the CASU Pipeline utilities
4 * Copyright (C) 2015 European Southern Observatory
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:
24 * $Revision: 1.3 $
25 * $Name: $
26 */
27
28#include <stdio.h>
29#include "imcore.h"
30#include "util.h"
31
34/*---------------------------------------------------------------------------*/
73/*---------------------------------------------------------------------------*/
74
75void imcore_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: apline.c,v $
219Revision 1.3 2015/08/12 11:16:55 jim
220Modified procedure names to protect namespace
221
222Revision 1.2 2015/08/07 13:06:54 jim
223Fixed copyright to ESO
224
225Revision 1.1.1.1 2015/06/12 10:44:32 jim
226Initial import
227
228Revision 1.2 2014/04/09 09:09:51 jim
229Detabbed
230
231Revision 1.1.1.1 2013/08/27 12:07:48 jim
232Imported
233
234
235
236*/
void imcore_apline(ap_t *ap, float dat[], float conf[], float smoothed[], float smoothedc[], int j, unsigned char *bpm)
Detect objects on a line of data.
Definition: apline.c:75