1 |
– |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ SGI"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Quadtree-specific set operations with unsorted sets. |
6 |
|
*/ |
7 |
|
|
8 |
+ |
#include <string.h> |
9 |
+ |
|
10 |
|
#include "standard.h" |
11 |
|
#include "sm_flag.h" |
12 |
+ |
#include "object.h" |
13 |
|
#include "sm_qtree.h" |
14 |
|
|
15 |
|
|
23 |
|
OBJECT **qtsettab= NULL; /* quadtree leaf node table */ |
24 |
|
QUADTREE qtnumsets=0; /* number of used set indices */ |
25 |
|
static int qtfreesets = EMPTY; /* free set index list */ |
26 |
< |
int4 *qtsetflag = NULL; |
26 |
> |
int32 *qtsetflag = NULL; |
27 |
|
static int qtallocsets =0; |
28 |
|
|
29 |
|
qtclearsetflags() |
32 |
|
if(!qtsetflag) |
33 |
|
return; |
34 |
|
|
35 |
< |
bzero((char *)qtsetflag,FLAG_BYTES(qtallocsets)); |
35 |
> |
memset((char *)qtsetflag, '\0', FLAG_BYTES(qtallocsets)); |
36 |
|
} |
37 |
|
|
38 |
|
|
48 |
|
osi = qtfreesets; |
49 |
|
qtfreesets = (int)qtsettab[osi]; |
50 |
|
} else if ((osi = qtnumsets++) % QTSETIBLK == 0) { |
51 |
< |
qtsettab = (OBJECT **)realloc((char *)qtsettab, |
51 |
> |
qtsettab = (OBJECT **)realloc((void *)qtsettab, |
52 |
|
(unsigned)(osi+QTSETIBLK)*sizeof(OBJECT *)); |
53 |
|
if (qtsettab == NULL) |
54 |
|
goto memerr; |
55 |
< |
qtsetflag = (int4 *)realloc((char *)qtsetflag, |
55 |
> |
qtsetflag = (int32 *)realloc((void *)qtsetflag, |
56 |
|
FLAG_BYTES(osi+ QTSETIBLK)); |
57 |
|
if (qtsetflag == NULL) |
58 |
|
goto memerr; |
59 |
|
if(qtallocsets) |
60 |
< |
bzero((char *)((char *)(qtsetflag)+FLAG_BYTES(qtallocsets)), |
60 |
> |
memset((char *)((char *)(qtsetflag)+FLAG_BYTES(qtallocsets)), '\0', |
61 |
|
FLAG_BYTES(osi+QTSETIBLK)-FLAG_BYTES(qtallocsets)); |
62 |
|
else |
63 |
< |
bzero((char *)(qtsetflag),FLAG_BYTES(osi +QTSETIBLK)); |
63 |
> |
memset((char *)(qtsetflag), '\0', FLAG_BYTES(osi +QTSETIBLK)); |
64 |
|
|
65 |
|
qtallocsets = osi + QTSETIBLK; |
66 |
|
} |
74 |
|
} |
75 |
|
|
76 |
|
|
77 |
+ |
deletuelem(os, obj) /* delete obj from unsorted os, no questions */ |
78 |
+ |
register OBJECT *os; |
79 |
+ |
OBJECT obj; |
80 |
+ |
{ |
81 |
+ |
register int i,j; |
82 |
+ |
OBJECT *optr; |
83 |
+ |
/* Take 2nd to last and put in position of obj: move last down: |
84 |
+ |
want to preserve last added |
85 |
+ |
*/ |
86 |
+ |
i = (*os)--; |
87 |
+ |
#ifdef DEBUG |
88 |
+ |
if( i <= 0) |
89 |
+ |
error(CONSISTENCY,"deleteuelem():empty set\n"); |
90 |
+ |
#endif |
91 |
+ |
if(i < 3) |
92 |
+ |
{ |
93 |
+ |
if((i == 2) && (*(++os) == obj)) |
94 |
+ |
*os = *(os+1); |
95 |
+ |
return; |
96 |
+ |
} |
97 |
+ |
optr = os + i; |
98 |
+ |
os++; |
99 |
+ |
while (i-- > 1 && *os != obj) |
100 |
+ |
os++; |
101 |
+ |
#ifdef DEBUG |
102 |
+ |
if( *os != obj) |
103 |
+ |
error(CONSISTENCY,"deleteuelem():id not found\n"); |
104 |
+ |
#endif |
105 |
+ |
*os = *(optr-1); |
106 |
+ |
*(optr-1) = *optr; |
107 |
+ |
} |
108 |
|
|
109 |
|
QUADTREE |
110 |
+ |
qtdeletuelem(qt, id) /* delete element from unsorted leaf node */ |
111 |
+ |
QUADTREE qt; |
112 |
+ |
OBJECT id; |
113 |
+ |
{ |
114 |
+ |
register QUADTREE lf; |
115 |
+ |
#ifdef DEBUG |
116 |
+ |
if(id < 0) |
117 |
+ |
eputs("qtdeletuelem():Invalid triangle id\n"); |
118 |
+ |
if (!QT_IS_LEAF(qt) || (lf = QT_SET_INDEX(qt)) >= qtnumsets) |
119 |
+ |
error(CONSISTENCY, "empty/bad node in qtdelelem"); |
120 |
+ |
#else |
121 |
+ |
lf = QT_SET_INDEX(qt); |
122 |
+ |
#endif |
123 |
+ |
if (qtsettab[lf][0] <= 1) { /* blow leaf away */ |
124 |
+ |
free((void *)qtsettab[lf]); |
125 |
+ |
qtsettab[lf] = (OBJECT *)qtfreesets; |
126 |
+ |
qtfreesets = lf; |
127 |
+ |
return(EMPTY); |
128 |
+ |
} |
129 |
+ |
deletuelem(qtsettab[lf], id); |
130 |
+ |
if (QTONTHRESH(qtsettab[lf][0])) |
131 |
+ |
qtsettab[lf] = (OBJECT *)realloc((void *)qtsettab[lf], |
132 |
+ |
QTNODESIZ(qtsettab[lf][0])*sizeof(OBJECT)); |
133 |
+ |
return(qt); |
134 |
+ |
} |
135 |
+ |
|
136 |
+ |
QUADTREE |
137 |
|
qtdelelem(qt, id) /* delete element from leaf node */ |
138 |
|
QUADTREE qt; |
139 |
|
OBJECT id; |
156 |
|
return(qt); |
157 |
|
} |
158 |
|
if (qtsettab[lf][0] <= 1) { /* blow leaf away */ |
159 |
< |
free((char *)qtsettab[lf]); |
159 |
> |
free((void *)qtsettab[lf]); |
160 |
|
qtsettab[lf] = (OBJECT *)qtfreesets; |
161 |
|
qtfreesets = lf; |
162 |
|
return(EMPTY); |
163 |
|
} |
164 |
|
deletelem(qtsettab[lf], id); |
165 |
|
if (QTONTHRESH(qtsettab[lf][0])) |
166 |
< |
qtsettab[lf] = (OBJECT *)realloc((char *)qtsettab[lf], |
166 |
> |
qtsettab[lf] = (OBJECT *)realloc((void *)qtsettab[lf], |
167 |
|
QTNODESIZ(qtsettab[lf][0])*sizeof(OBJECT)); |
168 |
|
return(qt); |
169 |
|
} |
200 |
|
return(qt); |
201 |
|
} |
202 |
|
if (QTONTHRESH(qtsettab[lf][0])) { |
203 |
< |
qtsettab[lf] = (OBJECT *)realloc((char *)qtsettab[lf], |
203 |
> |
qtsettab[lf] = (OBJECT *)realloc((void *)qtsettab[lf], |
204 |
|
QTNODESIZ(qtsettab[lf][0]+1)*sizeof(OBJECT)); |
205 |
|
if (qtsettab[lf] == NULL) |
206 |
|
error(SYSTEM, "out of memory in qtaddelem"); |
232 |
|
osize = os[0]; |
233 |
|
if((i=compress_set(os)) < osize) |
234 |
|
{ |
235 |
< |
qtsettab[lf] = (OBJECT *)realloc((char *)qtsettab[lf], |
235 |
> |
qtsettab[lf] = (OBJECT *)realloc((void *)qtsettab[lf], |
236 |
|
QTNODESIZ(i+1)*sizeof(OBJECT)); |
237 |
|
if (qtsettab[lf] == NULL) |
238 |
|
error(SYSTEM, "out of memory in qtaddelem"); |
251 |
|
|
252 |
|
#ifdef DEBUG |
253 |
|
if(id < 0) |
254 |
< |
eputs("qtaddelem():Invalid triangle id\n"); |
254 |
> |
eputs("qtadduelem():Invalid sample id\n"); |
255 |
|
#endif |
256 |
|
if (QT_IS_EMPTY(qt)) { /* create new leaf */ |
257 |
|
newset[0] = 1; newset[1] = id; |
264 |
|
lf = QT_SET_INDEX(qt); |
265 |
|
#endif |
266 |
|
if (QTONTHRESH(qtsettab[lf][0])) { |
267 |
< |
qtsettab[lf] = (OBJECT *)realloc((char *)qtsettab[lf], |
267 |
> |
qtsettab[lf] = (OBJECT *)realloc((void *)qtsettab[lf], |
268 |
|
QTNODESIZ(qtsettab[lf][0]+1)*sizeof(OBJECT)); |
269 |
|
if (qtsettab[lf] == NULL) |
270 |
|
error(SYSTEM, "out of memory in qtaddelem"); |
314 |
|
osi = QT_SET_INDEX(qt); |
315 |
|
if (osi >= qtnumsets) |
316 |
|
return; |
317 |
< |
free((char *)qtsettab[osi]); |
317 |
> |
free((void *)qtsettab[osi]); |
318 |
|
qtsettab[osi] = (OBJECT *)qtfreesets; |
319 |
|
qtfreesets = osi; |
320 |
|
} |
331 |
|
} |
332 |
|
for (i = qtnumsets; i--; ) |
333 |
|
if (qtsettab[i] != NULL) |
334 |
< |
free((char *)qtsettab[i]); |
335 |
< |
free((char *)qtsettab); |
334 |
> |
free((void *)qtsettab[i]); |
335 |
> |
free((void *)qtsettab); |
336 |
|
qtsettab = NULL; |
337 |
|
if(qtsetflag) |
338 |
|
{ |
339 |
< |
free((char *)qtsetflag); |
339 |
> |
free((void *)qtsetflag); |
340 |
|
qtsetflag=0; |
341 |
|
} |
342 |
|
qtnumsets = 0; |