ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/raytrace.c
Revision: 2.37
Committed: Tue Mar 11 17:08:55 2003 UTC (21 years, 1 month ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.36: +1 -0 lines
Log Message:
First working version of new "mesh" primitive, obj2mesh converter

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 greg 2.36 static const char RCSid[] = "$Id$";
3 greg 1.1 #endif
4     /*
5     * raytrace.c - routines for tracing and shading rays.
6     *
7 greg 2.34 * External symbols declared in ray.h
8     */
9    
10 greg 2.35 #include "copyright.h"
11 greg 1.1
12     #include "ray.h"
13    
14     #include "otypes.h"
15    
16 greg 1.15 #include "otspecial.h"
17    
18 greg 2.3 #define MAXCSET ((MAXSET+1)*2-1) /* maximum check set size */
19    
20 greg 2.6 unsigned long raynum = 0; /* next unique ray number */
21     unsigned long nrays = 0; /* number of calls to localhit */
22 greg 1.1
23 greg 1.23 static FLOAT Lambfa[5] = {PI, PI, PI, 0.0, 0.0};
24 greg 1.15 OBJREC Lamb = {
25     OVOID, MAT_PLASTIC, "Lambertian",
26 greg 2.2 {0, 5, NULL, Lambfa}, NULL,
27 greg 1.15 }; /* a Lambertian surface */
28    
29 greg 2.17 OBJREC Aftplane; /* aft clipping plane object */
30 greg 2.16
31 greg 2.34 static int raymove(), checkhit();
32     static void checkset();
33 greg 2.5
34 gwlarson 2.33 #ifndef MAXLOOP
35     #define MAXLOOP 0 /* modifier loop detection */
36     #endif
37 greg 1.1
38     #define RAYHIT (-1) /* return value for intercepted ray */
39    
40    
41 greg 2.34 int
42 greg 1.1 rayorigin(r, ro, rt, rw) /* start new ray from old one */
43     register RAY *r, *ro;
44     int rt;
45     double rw;
46     {
47 gwlarson 2.31 double re;
48    
49 greg 1.1 if ((r->parent = ro) == NULL) { /* primary ray */
50     r->rlvl = 0;
51     r->rweight = rw;
52     r->crtype = r->rtype = rt;
53     r->rsrc = -1;
54     r->clipset = NULL;
55 greg 1.21 r->revf = raytrace;
56 greg 2.23 copycolor(r->cext, cextinction);
57 greg 2.26 copycolor(r->albedo, salbedo);
58 greg 2.23 r->gecc = seccg;
59     r->slights = NULL;
60 greg 1.1 } else { /* spawned ray */
61     r->rlvl = ro->rlvl;
62     if (rt & RAYREFL) {
63     r->rlvl++;
64     r->rsrc = -1;
65     r->clipset = ro->clipset;
66 greg 2.22 r->rmax = 0.0;
67 greg 1.1 } else {
68     r->rsrc = ro->rsrc;
69     r->clipset = ro->newcset;
70 greg 2.22 r->rmax = ro->rmax <= FTINY ? 0.0 : ro->rmax - ro->rot;
71 greg 1.1 }
72 greg 1.21 r->revf = ro->revf;
73 greg 2.23 copycolor(r->cext, ro->cext);
74 greg 2.26 copycolor(r->albedo, ro->albedo);
75 greg 2.23 r->gecc = ro->gecc;
76     r->slights = ro->slights;
77 greg 1.1 r->crtype = ro->crtype | (r->rtype = rt);
78     VCOPY(r->rorg, ro->rop);
79 gwlarson 2.31 r->rweight = ro->rweight * rw;
80     /* estimate absorption */
81     re = colval(ro->cext,RED) < colval(ro->cext,GRN) ?
82     colval(ro->cext,RED) : colval(ro->cext,GRN);
83     if (colval(ro->cext,BLU) < re) re = colval(ro->cext,BLU);
84     if (re > 0.)
85     r->rweight *= exp(-re*ro->rot);
86 greg 1.1 }
87 greg 1.22 rayclear(r);
88     return(r->rlvl <= maxdepth && r->rweight >= minweight ? 0 : -1);
89     }
90    
91    
92 greg 2.34 void
93 greg 1.22 rayclear(r) /* clear a ray for (re)evaluation */
94     register RAY *r;
95     {
96 greg 1.20 r->rno = raynum++;
97 greg 1.1 r->newcset = r->clipset;
98 greg 2.36 r->hitf = rayhit;
99 greg 2.28 r->robj = OVOID;
100 greg 2.17 r->ro = NULL;
101 greg 2.34 r->rox = NULL;
102 gregl 2.29 r->rt = r->rot = FHUGE;
103 greg 1.1 r->pert[0] = r->pert[1] = r->pert[2] = 0.0;
104 greg 2.37 r->uv[0] = r->uv[1] = 0.0;
105 greg 1.1 setcolor(r->pcol, 1.0, 1.0, 1.0);
106     setcolor(r->rcol, 0.0, 0.0, 0.0);
107     }
108    
109    
110 greg 2.34 void
111 greg 1.21 raytrace(r) /* trace a ray and compute its value */
112 greg 1.8 RAY *r;
113 greg 1.1 {
114 greg 1.15 if (localhit(r, &thescene))
115 greg 2.24 raycont(r); /* hit local surface, evaluate */
116 greg 2.16 else if (r->ro == &Aftplane) {
117 greg 2.23 r->ro = NULL; /* hit aft clipping plane */
118 greg 2.16 r->rot = FHUGE;
119     } else if (sourcehit(r))
120 greg 2.24 rayshade(r, r->ro->omod); /* distant source */
121 greg 1.1
122 greg 2.23 rayparticipate(r); /* for participating medium */
123    
124 greg 1.1 if (trace != NULL)
125     (*trace)(r); /* trace execution */
126     }
127    
128    
129 greg 2.34 void
130 greg 1.8 raycont(r) /* check for clipped object and continue */
131     register RAY *r;
132     {
133 greg 2.7 if ((r->clipset != NULL && inset(r->clipset, r->ro->omod)) ||
134 greg 2.24 !rayshade(r, r->ro->omod))
135 greg 1.8 raytrans(r);
136     }
137    
138    
139 greg 2.34 void
140 greg 1.1 raytrans(r) /* transmit ray as is */
141 greg 1.8 register RAY *r;
142 greg 1.1 {
143     RAY tr;
144    
145     if (rayorigin(&tr, r, TRANS, 1.0) == 0) {
146     VCOPY(tr.rdir, r->rdir);
147     rayvalue(&tr);
148     copycolor(r->rcol, tr.rcol);
149 greg 1.10 r->rt = r->rot + tr.rt;
150 greg 1.1 }
151     }
152    
153    
154 greg 2.34 int
155 greg 1.1 rayshade(r, mod) /* shade ray r with material mod */
156     register RAY *r;
157     int mod;
158     {
159 greg 2.9 int gotmat;
160 greg 1.1 register OBJREC *m;
161 gwlarson 2.33 #if MAXLOOP
162     static int depth = 0;
163 greg 1.1 /* check for infinite loop */
164     if (depth++ >= MAXLOOP)
165 greg 1.4 objerror(r->ro, USER, "possible modifier loop");
166 gwlarson 2.33 #endif
167 greg 1.19 r->rt = r->rot; /* set effective ray length */
168 greg 2.9 for (gotmat = 0; !gotmat && mod != OVOID; mod = m->omod) {
169 greg 1.1 m = objptr(mod);
170 greg 1.4 /****** unnecessary test since modifier() is always called
171 greg 1.1 if (!ismodifier(m->otype)) {
172     sprintf(errmsg, "illegal modifier \"%s\"", m->oname);
173     error(USER, errmsg);
174     }
175 greg 1.4 ******/
176 greg 1.16 /* hack for irradiance calculation */
177     if (do_irrad && !(r->crtype & ~(PRIMARY|TRANS))) {
178     if (irr_ignore(m->otype)) {
179 gwlarson 2.33 #if MAXLOOP
180 greg 1.16 depth--;
181 gwlarson 2.33 #endif
182 greg 1.16 raytrans(r);
183 greg 2.15 return(1);
184 greg 1.16 }
185 greg 1.18 if (!islight(m->otype))
186 greg 1.16 m = &Lamb;
187     }
188 greg 2.9 /* materials call raytexture */
189     gotmat = (*ofun[m->otype].funp)(m, r);
190 greg 1.1 }
191 gwlarson 2.33 #if MAXLOOP
192 greg 2.9 depth--;
193 gwlarson 2.33 #endif
194 greg 2.9 return(gotmat);
195 greg 2.23 }
196    
197    
198 greg 2.34 void
199 greg 2.23 rayparticipate(r) /* compute ray medium participation */
200     register RAY *r;
201     {
202     COLOR ce, ca;
203     double re, ge, be;
204    
205     if (intens(r->cext) <= 1./FHUGE)
206     return; /* no medium */
207 greg 2.27 re = r->rot*colval(r->cext,RED);
208     ge = r->rot*colval(r->cext,GRN);
209     be = r->rot*colval(r->cext,BLU);
210 greg 2.26 if (r->crtype & SHADOW) { /* no scattering for sources */
211     re *= 1. - colval(r->albedo,RED);
212     ge *= 1. - colval(r->albedo,GRN);
213     be *= 1. - colval(r->albedo,BLU);
214     }
215     setcolor(ce, re<=0. ? 1. : re>92. ? 0. : exp(-re),
216     ge<=0. ? 1. : ge>92. ? 0. : exp(-ge),
217     be<=0. ? 1. : be>92. ? 0. : exp(-be));
218 greg 2.23 multcolor(r->rcol, ce); /* path absorption */
219 greg 2.26 if (r->crtype & SHADOW || intens(r->albedo) <= FTINY)
220 greg 2.23 return; /* no scattering */
221 greg 2.26 setcolor(ca,
222     colval(r->albedo,RED)*colval(ambval,RED)*(1.-colval(ce,RED)),
223     colval(r->albedo,GRN)*colval(ambval,GRN)*(1.-colval(ce,GRN)),
224     colval(r->albedo,BLU)*colval(ambval,BLU)*(1.-colval(ce,BLU)));
225 greg 2.23 addcolor(r->rcol, ca); /* ambient in scattering */
226     srcscatter(r); /* source in scattering */
227 greg 1.1 }
228    
229    
230     raytexture(r, mod) /* get material modifiers */
231     RAY *r;
232     int mod;
233     {
234 gwlarson 2.33 register OBJREC *m;
235     #if MAXLOOP
236 greg 1.1 static int depth = 0;
237     /* check for infinite loop */
238     if (depth++ >= MAXLOOP)
239     objerror(r->ro, USER, "modifier loop");
240 gwlarson 2.33 #endif
241 greg 1.1 /* execute textures and patterns */
242     for ( ; mod != OVOID; mod = m->omod) {
243     m = objptr(mod);
244 greg 2.9 /****** unnecessary test since modifier() is always called
245     if (!ismodifier(m->otype)) {
246 greg 1.1 sprintf(errmsg, "illegal modifier \"%s\"", m->oname);
247     error(USER, errmsg);
248     }
249 greg 2.9 ******/
250 greg 2.20 if ((*ofun[m->otype].funp)(m, r)) {
251     sprintf(errmsg, "conflicting material \"%s\"",
252     m->oname);
253     objerror(r->ro, USER, errmsg);
254     }
255 greg 1.1 }
256 gwlarson 2.33 #if MAXLOOP
257 greg 1.1 depth--; /* end here */
258 gwlarson 2.33 #endif
259 greg 1.1 }
260    
261    
262 greg 2.34 int
263 greg 1.1 raymixture(r, fore, back, coef) /* mix modifiers */
264     register RAY *r;
265     OBJECT fore, back;
266     double coef;
267     {
268 greg 2.9 RAY fr, br;
269     int foremat, backmat;
270 greg 1.1 register int i;
271 greg 2.24 /* bound coefficient */
272 greg 1.1 if (coef > 1.0)
273     coef = 1.0;
274     else if (coef < 0.0)
275     coef = 0.0;
276 greg 2.13 /* compute foreground and background */
277 greg 2.24 foremat = backmat = 0;
278 greg 2.9 /* foreground */
279     copystruct(&fr, r);
280 greg 2.24 if (coef > FTINY)
281 greg 2.9 foremat = rayshade(&fr, fore);
282     /* background */
283     copystruct(&br, r);
284 greg 2.24 if (coef < 1.0-FTINY)
285 greg 2.9 backmat = rayshade(&br, back);
286 greg 2.24 /* check for transparency */
287     if (backmat ^ foremat)
288 gwlarson 2.33 if (backmat && coef > FTINY)
289 greg 2.24 raytrans(&fr);
290 gwlarson 2.33 else if (foremat && coef < 1.0-FTINY)
291 greg 2.24 raytrans(&br);
292 greg 2.12 /* mix perturbations */
293 greg 1.1 for (i = 0; i < 3; i++)
294 greg 2.12 r->pert[i] = coef*fr.pert[i] + (1.0-coef)*br.pert[i];
295     /* mix pattern colors */
296 greg 2.9 scalecolor(fr.pcol, coef);
297     scalecolor(br.pcol, 1.0-coef);
298 greg 2.12 copycolor(r->pcol, fr.pcol);
299     addcolor(r->pcol, br.pcol);
300 greg 2.24 /* return value tells if material */
301     if (!foremat & !backmat)
302     return(0);
303 greg 2.12 /* mix returned ray values */
304 greg 2.24 scalecolor(fr.rcol, coef);
305     scalecolor(br.rcol, 1.0-coef);
306     copycolor(r->rcol, fr.rcol);
307     addcolor(r->rcol, br.rcol);
308     r->rt = bright(fr.rcol) > bright(br.rcol) ? fr.rt : br.rt;
309     return(1);
310 greg 1.1 }
311    
312    
313     double
314 greg 2.21 raydist(r, flags) /* compute (cumulative) ray distance */
315     register RAY *r;
316     register int flags;
317     {
318     double sum = 0.0;
319    
320     while (r != NULL && r->crtype&flags) {
321     sum += r->rot;
322     r = r->parent;
323     }
324     return(sum);
325     }
326    
327    
328     double
329 greg 1.1 raynormal(norm, r) /* compute perturbed normal for ray */
330     FVECT norm;
331     register RAY *r;
332     {
333     double newdot;
334     register int i;
335    
336     /* The perturbation is added to the surface normal to obtain
337     * the new normal. If the new normal would affect the surface
338     * orientation wrt. the ray, a correction is made. The method is
339     * still fraught with problems since reflected rays and similar
340     * directions calculated from the surface normal may spawn rays behind
341     * the surface. The only solution is to curb textures at high
342 greg 1.9 * incidence (namely, keep DOT(rdir,pert) < Rdot).
343 greg 1.1 */
344    
345     for (i = 0; i < 3; i++)
346     norm[i] = r->ron[i] + r->pert[i];
347    
348     if (normalize(norm) == 0.0) {
349     objerror(r->ro, WARNING, "illegal normal perturbation");
350     VCOPY(norm, r->ron);
351     return(r->rod);
352     }
353     newdot = -DOT(norm, r->rdir);
354     if ((newdot > 0.0) != (r->rod > 0.0)) { /* fix orientation */
355     for (i = 0; i < 3; i++)
356     norm[i] += 2.0*newdot*r->rdir[i];
357     newdot = -newdot;
358     }
359     return(newdot);
360 greg 1.12 }
361    
362    
363 greg 2.34 void
364 greg 1.12 newrayxf(r) /* get new tranformation matrix for ray */
365     RAY *r;
366     {
367     static struct xfn {
368     struct xfn *next;
369     FULLXF xf;
370     } xfseed = { &xfseed }, *xflast = &xfseed;
371     register struct xfn *xp;
372     register RAY *rp;
373    
374     /*
375     * Search for transform in circular list that
376     * has no associated ray in the tree.
377     */
378     xp = xflast;
379     for (rp = r->parent; rp != NULL; rp = rp->parent)
380     if (rp->rox == &xp->xf) { /* xp in use */
381     xp = xp->next; /* move to next */
382     if (xp == xflast) { /* need new one */
383 greg 2.34 xp = (struct xfn *)malloc(sizeof(struct xfn));
384 greg 1.12 if (xp == NULL)
385     error(SYSTEM,
386     "out of memory in newrayxf");
387     /* insert in list */
388     xp->next = xflast->next;
389     xflast->next = xp;
390     break; /* we're done */
391     }
392     rp = r; /* start check over */
393     }
394     /* got it */
395     r->rox = &xp->xf;
396     xflast = xp;
397 greg 1.1 }
398    
399    
400 greg 2.34 void
401 greg 1.1 flipsurface(r) /* reverse surface orientation */
402     register RAY *r;
403     {
404     r->rod = -r->rod;
405     r->ron[0] = -r->ron[0];
406     r->ron[1] = -r->ron[1];
407     r->ron[2] = -r->ron[2];
408     r->pert[0] = -r->pert[0];
409     r->pert[1] = -r->pert[1];
410     r->pert[2] = -r->pert[2];
411     }
412    
413    
414 greg 2.36 void
415     rayhit(oset, r) /* standard ray hit test */
416     OBJECT *oset;
417     RAY *r;
418     {
419     OBJREC *o;
420     int i;
421    
422     for (i = oset[0]; i > 0; i--) {
423     o = objptr(oset[i]);
424     if ((*ofun[o->otype].funp)(o, r))
425     r->robj = oset[i];
426     }
427     }
428    
429    
430 greg 2.34 int
431 greg 1.1 localhit(r, scene) /* check for hit in the octree */
432     register RAY *r;
433     register CUBE *scene;
434     {
435 greg 2.3 OBJECT cxset[MAXCSET+1]; /* set of checked objects */
436 greg 1.1 FVECT curpos; /* current cube position */
437 greg 1.11 int sflags; /* sign flags */
438 greg 1.1 double t, dt;
439     register int i;
440    
441 greg 1.21 nrays++; /* increment trace counter */
442 greg 1.11 sflags = 0;
443 greg 1.1 for (i = 0; i < 3; i++) {
444     curpos[i] = r->rorg[i];
445 greg 2.8 if (r->rdir[i] > 1e-7)
446 greg 1.11 sflags |= 1 << i;
447 greg 2.8 else if (r->rdir[i] < -1e-7)
448 greg 1.11 sflags |= 0x10 << i;
449 greg 1.1 }
450 greg 1.17 if (sflags == 0)
451     error(CONSISTENCY, "zero ray direction in localhit");
452 greg 2.17 /* start off assuming nothing hit */
453     if (r->rmax > FTINY) { /* except aft plane if one */
454     r->ro = &Aftplane;
455     r->rot = r->rmax;
456     for (i = 0; i < 3; i++)
457     r->rop[i] = r->rorg[i] + r->rot*r->rdir[i];
458     }
459     /* find global cube entrance point */
460 greg 1.1 t = 0.0;
461     if (!incube(scene, curpos)) {
462     /* find distance to entry */
463     for (i = 0; i < 3; i++) {
464     /* plane in our direction */
465 greg 1.11 if (sflags & 1<<i)
466 greg 1.1 dt = scene->cuorg[i];
467 greg 1.11 else if (sflags & 0x10<<i)
468 greg 1.1 dt = scene->cuorg[i] + scene->cusize;
469     else
470     continue;
471     /* distance to the plane */
472     dt = (dt - r->rorg[i])/r->rdir[i];
473     if (dt > t)
474     t = dt; /* farthest face is the one */
475     }
476     t += FTINY; /* fudge to get inside cube */
477 greg 2.17 if (t >= r->rot) /* clipped already */
478     return(0);
479 greg 1.1 /* advance position */
480     for (i = 0; i < 3; i++)
481     curpos[i] += r->rdir[i]*t;
482    
483     if (!incube(scene, curpos)) /* non-intersecting ray */
484     return(0);
485     }
486 greg 2.3 cxset[0] = 0;
487 greg 2.19 raymove(curpos, cxset, sflags, r, scene);
488     return(r->ro != NULL & r->ro != &Aftplane);
489 greg 1.1 }
490    
491    
492     static int
493 greg 2.3 raymove(pos, cxs, dirf, r, cu) /* check for hit as we move */
494     FVECT pos; /* current position, modified herein */
495     OBJECT *cxs; /* checked objects, modified by checkhit */
496 greg 1.11 int dirf; /* direction indicators to speed tests */
497 greg 1.1 register RAY *r;
498     register CUBE *cu;
499     {
500     int ax;
501     double dt, t;
502    
503     if (istree(cu->cutree)) { /* recurse on subcubes */
504     CUBE cukid;
505 greg 1.11 register int br, sgn;
506 greg 1.1
507     cukid.cusize = cu->cusize * 0.5; /* find subcube */
508     VCOPY(cukid.cuorg, cu->cuorg);
509     br = 0;
510     if (pos[0] >= cukid.cuorg[0]+cukid.cusize) {
511     cukid.cuorg[0] += cukid.cusize;
512     br |= 1;
513     }
514     if (pos[1] >= cukid.cuorg[1]+cukid.cusize) {
515     cukid.cuorg[1] += cukid.cusize;
516     br |= 2;
517     }
518     if (pos[2] >= cukid.cuorg[2]+cukid.cusize) {
519     cukid.cuorg[2] += cukid.cusize;
520     br |= 4;
521     }
522     for ( ; ; ) {
523     cukid.cutree = octkid(cu->cutree, br);
524 greg 2.3 if ((ax = raymove(pos,cxs,dirf,r,&cukid)) == RAYHIT)
525 greg 1.1 return(RAYHIT);
526     sgn = 1 << ax;
527 greg 1.11 if (sgn & dirf) /* positive axis? */
528 greg 1.1 if (sgn & br)
529     return(ax); /* overflow */
530     else {
531     cukid.cuorg[ax] += cukid.cusize;
532     br |= sgn;
533     }
534 greg 1.11 else
535     if (sgn & br) {
536     cukid.cuorg[ax] -= cukid.cusize;
537     br &= ~sgn;
538     } else
539     return(ax); /* underflow */
540 greg 1.1 }
541     /*NOTREACHED*/
542     }
543 greg 2.18 if (isfull(cu->cutree)) {
544     if (checkhit(r, cu, cxs))
545     return(RAYHIT);
546     } else if (r->ro == &Aftplane && incube(cu, r->rop))
547 greg 1.1 return(RAYHIT);
548     /* advance to next cube */
549 greg 1.11 if (dirf&0x11) {
550     dt = dirf&1 ? cu->cuorg[0] + cu->cusize : cu->cuorg[0];
551 greg 1.1 t = (dt - pos[0])/r->rdir[0];
552     ax = 0;
553     } else
554     t = FHUGE;
555 greg 1.11 if (dirf&0x22) {
556     dt = dirf&2 ? cu->cuorg[1] + cu->cusize : cu->cuorg[1];
557 greg 1.1 dt = (dt - pos[1])/r->rdir[1];
558     if (dt < t) {
559     t = dt;
560     ax = 1;
561     }
562     }
563 greg 1.11 if (dirf&0x44) {
564     dt = dirf&4 ? cu->cuorg[2] + cu->cusize : cu->cuorg[2];
565 greg 1.1 dt = (dt - pos[2])/r->rdir[2];
566     if (dt < t) {
567     t = dt;
568     ax = 2;
569     }
570     }
571     pos[0] += r->rdir[0]*t;
572     pos[1] += r->rdir[1]*t;
573     pos[2] += r->rdir[2]*t;
574     return(ax);
575     }
576    
577    
578 greg 2.34 static int
579 greg 2.3 checkhit(r, cu, cxs) /* check for hit in full cube */
580 greg 1.1 register RAY *r;
581     CUBE *cu;
582 greg 2.3 OBJECT *cxs;
583 greg 1.1 {
584     OBJECT oset[MAXSET+1];
585    
586     objset(oset, cu->cutree);
587 greg 2.36 checkset(oset, cxs); /* avoid double-checking */
588    
589     (*r->hitf)(oset, r); /* test for hit in set */
590    
591     if (r->robj == OVOID)
592 greg 1.1 return(0); /* no scores yet */
593    
594     return(incube(cu, r->rop)); /* hit OK if in current cube */
595 greg 2.2 }
596    
597    
598 greg 2.34 static void
599 greg 2.2 checkset(os, cs) /* modify checked set and set to check */
600 greg 2.3 register OBJECT *os; /* os' = os - cs */
601     register OBJECT *cs; /* cs' = cs + os */
602 greg 2.2 {
603     OBJECT cset[MAXCSET+MAXSET+1];
604 greg 2.3 register int i, j;
605     int k;
606 greg 2.2 /* copy os in place, cset <- cs */
607     cset[0] = 0;
608     k = 0;
609     for (i = j = 1; i <= os[0]; i++) {
610     while (j <= cs[0] && cs[j] < os[i])
611     cset[++cset[0]] = cs[j++];
612     if (j > cs[0] || os[i] != cs[j]) { /* object to check */
613     os[++k] = os[i];
614     cset[++cset[0]] = os[i];
615     }
616     }
617 greg 2.3 if (!(os[0] = k)) /* new "to check" set size */
618     return; /* special case */
619 greg 2.2 while (j <= cs[0]) /* get the rest of cs */
620     cset[++cset[0]] = cs[j++];
621 greg 2.3 if (cset[0] > MAXCSET) /* truncate "checked" set if nec. */
622 greg 2.2 cset[0] = MAXCSET;
623 greg 2.3 /* setcopy(cs, cset); */ /* copy cset back to cs */
624     os = cset;
625     for (i = os[0]; i-- >= 0; )
626     *cs++ = *os++;
627 greg 1.1 }