CR2RE Pipeline Reference Manual 1.6.8
hdrl_cat_terminate.c
1/*
2 * This file is part of the HDRL
3 * Copyright (C) 2017 European Southern Observatory
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#include "hdrl_cat_terminate.h"
21
22#include "hdrl_cat_table.h"
23
24
25/*---------------------------------------------------------------------------*/
33/*----------------------------------------------------------------------------*/
34
37/* ---------------------------------------------------------------------------*/
52/* ---------------------------------------------------------------------------*/
53void hdrl_terminate(ap_t *ap, double gain, cpl_size *nobjects,
54 cpl_table *tab, hdrl_casu_result *res)
55{
56
57 /* Search through all possible parents! */
58 for (cpl_size ip = 1; ip <= ap->maxip; ip++) {
59
60 if (ap->parent[ip].pnop != -1) {
61
62 if (ap->parent[ip].pnop == ap->parent[ip].growing) {
63
64 /* That's a termination: */
65 if (( ap->parent[ip].pnop >= ap->ipnop &&
66 ap->parent[ip].touch == 0) &&
67 (ap->parent[ip].pnbp < (ap->parent[ip].pnop)/2) ){
68
69 /* Call the processing routine */
70 hdrl_extract_data(ap, ip);
71 hdrl_process_results(ap, gain, nobjects, tab, res);
72 }
73
74 hdrl_restack(ap,ip);
75
76 } else {
77
78 /* This parent still active: */
79 ap->parent[ip].growing = ap->parent[ip].pnop;
80 }
81 }
82 }
83}
84
85/* ---------------------------------------------------------------------------*/
96/* ---------------------------------------------------------------------------*/
97void hdrl_restack(ap_t *ap, cpl_size ip)
98{
99 /* Reset the mflag */
100 unsigned char *mflag = ap->mflag;
101
102 cpl_size np = ap->parent[ip].pnop;
103 cpl_size ib = ap->parent[ip].first;
104
105 for (cpl_size i = 0; i < np; i++) {
106 cpl_size nn = ap->plessey[ib].y*ap->lsiz + ap->plessey[ib].x;
107 mflag[nn] = MF_POSSIBLEOBJ;
108 ib = ap->blink[ib];
109 }
110
111 /* Stash all blocks back in a burst */
112 ib = ap->parent[ip].first;
113 for (cpl_size i = ap->ibstack - ap->parent[ip].pnop; i < ap->ibstack-1; i++) {
114 ap->bstack[i] = ib;
115 ib = ap->blink[ib];
116 }
117
118 /* and the last one */
119 ap->bstack[ap->ibstack-1] = ib;
120 ap->ibstack -= ap->parent[ip].pnop;
121
122 /* Put parent name back on stack */
123 ap->pstack[--ap->ipstack] = ip;
124
125 /* Mark that parent inactive */
126 ap->parent[ip].pnop = -1;
127 ap->parent[ip].pnbp = -1;
128}
129
130/* ---------------------------------------------------------------------------*/
140/* ---------------------------------------------------------------------------*/
141void hdrl_apfu(ap_t *ap)
142{
143 /* Search through all possible parents and just junk the biggest one to free space: */
144 cpl_size big = 0;
145 cpl_size ipbig = 0;
146
147 for (cpl_size ip = 1; ip <= ap->maxip; ip++) {
148
149 if (ap->parent[ip].pnop != -1) {
150
151 if (ap->parent[ip].pnop > big) {
152 big = ap->parent[ip].pnop;
153 ipbig = ip;
154 }
155 }
156 }
157
158 if (big > 0) {
159
160 hdrl_restack(ap, ipbig);
161
162 /* clearout lastline references to this parent: */
163 for (cpl_size ip = 0; ip <= ap->lsiz; ip++) {
164
165 if (ap->lastline[ip] == ipbig) ap->lastline[ip] = 0;
166 }
167 }
168}
169
170/* ---------------------------------------------------------------------------*/
182/* ---------------------------------------------------------------------------*/
183void hdrl_extract_data(ap_t *ap, cpl_size ip)
184{
185 /* Check the size of the workspace and see if it's big enough. If it
186 isn't then increase the size until it is */
187
188 unsigned char *mflag = ap->mflag;
189
190 cpl_size np = ap->parent[ip].pnop;
191 if (ap->npl < np) {
192 ap->plarray = cpl_realloc(ap->plarray, np * sizeof(*ap->plarray));
193 ap->npl = np;
194 }
195
196 /* Pull the info out now */
197 cpl_size ib = ap->parent[ip].first;
198 ap->npl_pix = np;
199 for (cpl_size i = 0; i < np; i++) {
200
201 ap->plarray[i].x = ap->plessey[ib].x + 1;
202 ap->plarray[i].y = ap->plessey[ib].y + 1;
203
204 ap->plarray[i].z = ap->plessey[ib].z;
205 ap->plarray[i].zsm = ap->plessey[ib].zsm;
206
207 cpl_size nn = ap->plessey[ib].y*ap->lsiz + ap->plessey[ib].x;
208
209 mflag[nn] = MF_OBJPIX;
210
211 ib = ap->blink[ib];
212 }
213}
214
cpl_error_code hdrl_process_results(ap_t *ap, double gain, cpl_size *nobjects, cpl_table *tab, hdrl_casu_result *res)
Process the results for each object and store them in the table.
void hdrl_restack(ap_t *ap, cpl_size ip)
Free information for an object from the ap structure.
void hdrl_apfu(ap_t *ap)
Get rid of the largest contributor in an ap structure.
void hdrl_terminate(ap_t *ap, double gain, cpl_size *nobjects, cpl_table *tab, hdrl_casu_result *res)
Check for objects that have terminated.
void hdrl_extract_data(ap_t *ap, cpl_size ip)
Put data into the Plessey array for an object.