VIRCAM Pipeline  2.3.12
terminate.c
1 /* $Id: terminate.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: 2015/08/12 11:16:55 $
24  * $Revision: 1.3 $
25  * $Name: $
26  */
27 
28 #include <stdio.h>
29 #include "imcore.h"
30 #include "util.h"
31 
34 /*---------------------------------------------------------------------------*/
62 /*---------------------------------------------------------------------------*/
63 
64 extern void imcore_restack(ap_t *ap, int ip) {
65  int i,ib,nn,np;
66  unsigned char *mflag;
67 
68  /* Reset the mflag */
69 
70  np = ap->parent[ip].pnop;
71  ib = ap->parent[ip].first;
72  mflag = ap->mflag;
73  for (i = 0; i < np; i++) {
74  nn = ap->plessey[ib].y*ap->lsiz + ap->plessey[ib].x;
75  mflag[nn] = MF_POSSIBLEOBJ;
76  ib = ap->blink[ib];
77  }
78 
79  /* Stash all blocks back in a burst: */
80 
81  ib = ap->parent[ip].first;
82  for(i = ap->ibstack - ap->parent[ip].pnop; i < ap->ibstack-1; i++) {
83  ap->bstack[i] = ib;
84  ib = ap->blink[ib];
85  }
86 
87  /* and the last one: */
88 
89  ap->bstack[ap->ibstack-1] = ib;
90  ap->ibstack -= ap->parent[ip].pnop;
91 
92  /* Put parent name back on stack: */
93 
94  ap->pstack[--ap->ipstack] = ip;
95 
96  /* Mark that parent inactive: */
97 
98  ap->parent[ip].pnop = -1;
99  ap->parent[ip].pnbp = -1;
100 }
101 
102 /*---------------------------------------------------------------------------*/
128 /*---------------------------------------------------------------------------*/
129 
130 extern void imcore_terminate(ap_t *ap, int cattype, float gain, int *nobjects,
131  cpl_table *tab) {
132  int ip,status;
133 
134  /* Search through all possible parents! */
135 
136  for (ip = 1; ip <= ap->maxip; ip++) {
137  if(ap->parent[ip].pnop != -1) {
138  if(ap->parent[ip].pnop == ap->parent[ip].growing) {
139 
140  /* That's a termination: */
141 
142  if((ap->parent[ip].pnop >= ap->ipnop &&
143  ap->parent[ip].touch == 0) &&
144  (ap->parent[ip].pnbp < (ap->parent[ip].pnop)/2)) {
145  imcore_extract_data(ap,ip);
146 
147  /* Call the processing routine */
148 
149  status = imcore_process_results(ap,cattype,gain,nobjects,
150  tab);
151  if (status != CASU_OK) {
152  imcore_restack(ap,ip);
153  continue;
154  }
155  }
156  imcore_restack(ap,ip);
157  } else {
158 
159  /* This parent still active: */
160 
161  ap->parent[ip].growing = ap->parent[ip].pnop;
162  }
163  }
164  }
165 }
166 
167 /*---------------------------------------------------------------------------*/
192 /*---------------------------------------------------------------------------*/
193 
194 extern void imcore_apfu(ap_t *ap) {
195  int ip, big, ipbig;
196 
197  /* Search through all possible parents and just junk the biggest
198  one to free space: */
199 
200  big = 0;
201  ipbig = 0;
202  for (ip = 1; ip <= ap->maxip; ip++) {
203  if(ap->parent[ip].pnop != -1) {
204  if(ap->parent[ip].pnop > big) {
205  big = ap->parent[ip].pnop;
206  ipbig = ip;
207  }
208  }
209  }
210  if(big > 0) {
211  imcore_restack(ap, ipbig);
212 
213  /* clearout lastline references to this parent: */
214 
215  for (ip = 0; ip <= ap->lsiz; ip++)
216  if(ap->lastline[ip] == ipbig) ap->lastline[ip] = 0;
217  }
218 }
219 
220 /*---------------------------------------------------------------------------*/
248 /*---------------------------------------------------------------------------*/
249 
250 extern void imcore_extract_data(ap_t *ap, int ip) {
251  int ib,i,np,nn;
252  unsigned char *mflag;
253 
254  /* Check the size of the workspace and see if it's big enough. If it
255  isn't then increase the size until it is */
256 
257  np = ap->parent[ip].pnop;
258  if (ap->npl < np) {
259  ap->plarray = cpl_realloc(ap->plarray,np*sizeof(plstruct));
260  ap->npl = np;
261  }
262 
263  /* Pull the info out now */
264 
265  ib = ap->parent[ip].first;
266  ap->npl_pix = np;
267  mflag = ap->mflag;
268  for (i = 0; i < np; i++) {
269  ap->plarray[i].x = ap->plessey[ib].x + 1;
270  ap->plarray[i].y = ap->plessey[ib].y + 1;
271  ap->plarray[i].z = ap->plessey[ib].z;
272  ap->plarray[i].zsm = ap->plessey[ib].zsm;
273  nn = ap->plessey[ib].y*ap->lsiz + ap->plessey[ib].x;
274  mflag[nn] = MF_OBJPIX;
275  ib = ap->blink[ib];
276  }
277 }
278 
281 /*
282 
283 $Log: terminate.c,v $
284 Revision 1.3 2015/08/12 11:16:55 jim
285 Modified procedure names to protect namespace
286 
287 Revision 1.2 2015/08/07 13:06:54 jim
288 Fixed copyright to ESO
289 
290 Revision 1.1.1.1 2015/06/12 10:44:32 jim
291 Initial import
292 
293 Revision 1.3 2015/01/09 11:42:36 jim
294 Fixed routines to remove globals
295 
296 Revision 1.2 2014/04/09 09:09:51 jim
297 Detabbed
298 
299 Revision 1.1.1.1 2013/08/27 12:07:48 jim
300 Imported
301 
302 
303 */
void imcore_apfu(ap_t *ap)
Get rid of the largest contributor in an ap structure.
Definition: terminate.c:194
void imcore_terminate(ap_t *ap, int cattype, float gain, int *nobjects, cpl_table *tab)
Check for objects that have terminated.
Definition: terminate.c:130
void imcore_extract_data(ap_t *ap, int ip)
Put data into the Plessey array for an object.
Definition: terminate.c:250
void imcore_restack(ap_t *ap, int ip)
Free information for an object from the ap structure.
Definition: terminate.c:64
int imcore_process_results(ap_t *ap, int cattype, float gain, int *nobjects, cpl_table *tab)
Process results.
Definition: create_table.c:176