ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/sm_sets.c
(Generate patch)

Comparing ray/src/hd/sm_sets.c (file contents):
Revision 3.1 by gwlarson, Wed Aug 19 17:45:23 1998 UTC vs.
Revision 3.2 by gwlarson, Fri Sep 11 11:52:27 1998 UTC

# Line 11 | Line 11 | static char SCCSid[] = "$SunId$ SGI";
11   #include "standard.h"
12  
13   #include "sm_qtree.h"
14 #include "object.h"
14  
15 < #define QTSETIBLK       1024            /* set index allocation block size */
15 >
16 > #define QTSETIBLK       2048            /* set index allocation block size */
17   #define QTELEMBLK       8               /* set element allocation block */
18  
19   #define QTNODESIZ(ne)   ((ne) + QTELEMBLK - ((ne) % QTELEMBLK))
20  
21 < static OBJECT   **qtsettab;             /* quadtree leaf node table */
22 < static QUADTREE  qtnumsets;             /* number of used set indices */
21 > OBJECT  **qtsettab= NULL;                       /* quadtree leaf node table */
22 > QUADTREE  qtnumsets;                    /* number of used set indices */
23   static int  qtfreesets = EMPTY;         /* free set index list */
24  
25  
# Line 59 | Line 59 | OBJECT  id;
59          register QUADTREE  lf;
60          int  oalc, nalc;
61  
62 <        if (QT_IS_EMPTY(qt))
63 <                return(EMPTY);
64 <        if (!QT_IS_LEAF(qt))
65 <                goto noderr;
62 > #ifdef DEBUG
63 >        if(id < 0)
64 >                eputs("qtdelelem():Invalid triangle id\n");
65 >        if (!QT_IS_LEAF(qt) || (lf = QT_SET_INDEX(qt)) >= qtnumsets)
66 >                error(CONSISTENCY, "empty/bad node in qtdelelem");
67 >        if (!inset(qtsettab[lf], id))
68 >                error(CONSISTENCY, "id not in leaf in qtdelelem");
69 > #else
70          lf = QT_SET_INDEX(qt);
71 <        if (lf >= qtnumsets)
68 <                goto noderr;
71 > #endif
72          if (qtsettab[lf][0] <= 1) {             /* blow leaf away */
73                  free((char *)qtsettab[lf]);
74                  qtsettab[lf] = (OBJECT *)qtfreesets;
# Line 79 | Line 82 | OBJECT  id;
82                  qtsettab[lf] = (OBJECT *)realloc((char *)qtsettab[lf],
83                                  nalc*sizeof(OBJECT));
84          return(qt);
82 noderr:
83        error(CONSISTENCY, "bad node in qtdelelem");
85   }
86  
87  
# Line 93 | Line 94 | OBJECT  id;
94          register QUADTREE  lf;
95          int  oalc, nalc;
96  
97 + #ifdef DEBUG
98 +        if(id < 0)
99 +                eputs("qtaddelem():Invalid triangle id\n");
100 + #endif
101          if (QT_IS_EMPTY(qt)) {          /* create new leaf */
102                  newset[0] = 1; newset[1] = id;
103                  return(qtnewleaf(newset));
104          }                               /* else add element */
105 <        if (!QT_IS_LEAF(qt))
106 <                goto noderr;
105 > #ifdef DEBUG
106 >        if (!QT_IS_LEAF(qt) || (lf = QT_SET_INDEX(qt)) >= qtnumsets)
107 >                error(CONSISTENCY, "bad node in qtaddelem");
108 >        if (inset(qtsettab[lf], id))
109 >                error(CONSISTENCY, "id already in leaf in qtaddelem");
110 > #else
111          lf = QT_SET_INDEX(qt);
112 <        if (lf >= qtnumsets)
104 <                goto noderr;
112 > #endif
113          oalc = QTNODESIZ(qtsettab[lf][0]);
114          nalc = QTNODESIZ(qtsettab[lf][0] + 1);
115          if (nalc != oalc) {
# Line 112 | Line 120 | OBJECT  id;
120          }
121          insertelem(qtsettab[lf], id);
122          return(qt);
115 noderr:
116        error(CONSISTENCY, "bad node in qtaddelem");
123   }
124  
125  
126 < qtgetset(oset, qt)              /* get object set for leaf node */
127 < register OBJECT  *oset;
126 > #ifdef DEBUG
127 > OBJECT *
128 > qtqueryset(qt)                  /* return object set for leaf node */
129   QUADTREE  qt;
130   {
131 <        QUADTREE  lf;
125 <        register OBJECT  *os;
126 <        register int  i;
131 >        register QUADTREE  lf;
132  
133 <        if (!QT_IS_LEAF(qt))
134 <                goto noderr;
135 <        lf = QT_SET_INDEX(qt);
131 <        if (lf >= qtnumsets)
132 <                goto noderr;
133 <        for (i = *(os = qtsettab[lf]); i-- >= 0; )
134 <                *oset++ = *os++;
135 <        return;
136 < noderr:
137 <        error(CONSISTENCY, "bad node in qtgetset");
133 >        if (!QT_IS_LEAF(qt) || (lf = QT_SET_INDEX(qt)) >= qtnumsets)
134 >                error(CONSISTENCY, "bad node in qtqueryset");
135 >        return(qtsettab[lf]);
136   }
137 + #endif
138  
139  
140   qtfreeleaf(qt)                  /* free set and leaf node */
# Line 147 | Line 146 | QUADTREE  qt;
146                  return;
147          osi = QT_SET_INDEX(qt);
148          if (osi >= qtnumsets)
149 <                error(CONSISTENCY, "bad node in qtfreeleaf");
149 >                return;
150          free((char *)qtsettab[osi]);
151          qtsettab[osi] = (OBJECT *)qtfreesets;
152          qtfreesets = osi;
153   }
154  
155  
156 +
157 + qtfreeleaves()                  /* free ALL sets and leaf nodes */
158 + {
159 +        register int    i;
160 +
161 +        while ((i = qtfreesets) != EMPTY) {
162 +                qtfreesets = (int)qtsettab[i];
163 +                qtsettab[i] = NULL;
164 +        }
165 +        for (i = qtnumsets; i--; )
166 +                if (qtsettab[i] != NULL)
167 +                        free((char *)qtsettab[i]);
168 +        free((char *)qtsettab);
169 +        qtsettab = NULL;
170 +        qtnumsets = 0;
171 + }
172 +
173 +
174   check_set(os, cs)                /* modify checked set and set to check */
175   register OBJECT  *os;                   /* os' = os - cs */
176   register OBJECT  *cs;                   /* cs' = cs + os */
177   {
178 <    OBJECT  cset[MAXCSET+MAXSET+1];
178 >    OBJECT  cset[QT_MAXCSET+QT_MAXSET+1];
179      register int  i, j;
180      int  k;
181                                          /* copy os in place, cset <- cs */
# Line 176 | Line 193 | register OBJECT  *cs;                   /* cs' = cs +
193         return;                 /* special case */
194      while (j <= cs[0])              /* get the rest of cs */
195         cset[++cset[0]] = cs[j++];
196 <    if (cset[0] > MAXCSET)          /* truncate "checked" set if nec. */
197 <       cset[0] = MAXCSET;
196 >    if (cset[0] > QT_MAXCSET)          /* truncate "checked" set if nec. */
197 >       cset[0] = QT_MAXCSET;
198      /* setcopy(cs, cset); */        /* copy cset back to cs */
199      os = cset;
200      for (i = os[0]; i-- >= 0; )
201         *cs++ = *os++;
202   }
203 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines