Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
manobjlist.c
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*
* Part of: SExtractor
*
* Author: E.BERTIN (IAP)
*
* Contents: functions for the management of object lists.
*
* Last modify: 26/11/2003
*
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <string.h>
#include "define.h"
#include "globals.h"
#include "plist.h"
/********************************* belong ************************************/
/*
say if an object is "included" in another.
*/
int belong(int corenb, objliststruct *coreobjlist,
int shellnb, objliststruct *shellobjlist)
{
objstruct *cobj = &(coreobjlist->obj[corenb]),
*sobj = &(shellobjlist->obj[shellnb]);
pliststruct *cpl = coreobjlist->plist, *spl = shellobjlist->plist, *pixt;
int xc=PLIST(cpl+cobj->firstpix,x), yc=PLIST(cpl+cobj->firstpix,y);
for (pixt = spl+sobj->firstpix; pixt>=spl; pixt = spl+PLIST(pixt,nextpix))
if ((PLIST(pixt,x) == xc) && (PLIST(pixt,y) == yc))
return 1;
return 0;
}
/********************************* addobj ************************************/
/*
Add an object to an objlist.
*/
int addobj(int objnb, objliststruct *objl1, objliststruct *objl2)
{
objstruct *objl2obj;
pliststruct *plist1 = objl1->plist, *plist2 = objl2->plist;
int fp, i, j, npx, objnb2;
j = (fp = objl2->npix)*plistsize;
objnb2 = objl2->nobj;
/* Update the object list */
if (objl2->nobj)
{
if (!(objl2obj = (objstruct *)realloc(objl2->obj,
(++objl2->nobj) * sizeof(objstruct))))
goto exit_addobj;
}
else
if (!(objl2obj = (objstruct *)malloc((++objl2->nobj)*sizeof(objstruct))))
goto exit_addobj;
/* Update the pixel list */
npx = objl1->obj[objnb].fdnpix;
if (fp)
{
if (!(plist2 = (pliststruct *)realloc(plist2,
(objl2->npix+=npx) * plistsize)))
goto exit_addobj;
}
else
if (!(plist2=(pliststruct *)malloc((objl2->npix=npx)*plistsize)))
goto exit_addobj;
objl2->obj = objl2obj;
objl2->plist = plist2;
plist2 += j;
for(i=objl1->obj[objnb].firstpix; i!=-1; i=PLIST(plist1+i,nextpix))
{
memcpy(plist2, plist1+i, (size_t)plistsize);
PLIST(plist2,nextpix) = (j+=plistsize);
plist2 += plistsize;
}
PLIST(plist2-=plistsize, nextpix) = -1;
objl2->obj[objnb2] = objl1->obj[objnb];
objl2->obj[objnb2].firstpix = fp*plistsize;
objl2->obj[objnb2].lastpix = j-plistsize;
return objnb2;
exit_addobj:
objl2->nobj--;
objl2->npix = fp;
return RETURN_FATAL_ERROR;
}