ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhd_odraw.c
Revision: 3.4
Committed: Mon Dec 21 14:05:43 1998 UTC (25 years, 4 months ago) by gwlarson
Content type: text/plain
Branch: MAIN
Changes since 3.3: +16 -31 lines
Log Message:
made odUpdate() simpler and faster

File Contents

# User Rev Content
1 gwlarson 3.1 /* Copyright (c) 1998 Silicon Graphics, Inc. */
2    
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ SGI";
5     #endif
6    
7     /*
8     * Routines for drawing samples using depth buffer checks.
9     */
10    
11     #include "standard.h"
12    
13     #include <sys/types.h>
14     #include <GL/glx.h>
15     #include <GL/glu.h>
16    
17     #include "random.h"
18     #include "rhd_odraw.h"
19    
20     #ifndef DEPTHEPS
21     #define DEPTHEPS 0.02 /* depth epsilon */
22     #endif
23     #ifndef SAMPSPERBLOCK
24     #define SAMPSPERBLOCK 1024 /* target samples per image block */
25     #endif
26     #ifndef SFREEFRAC
27     #define SFREEFRAC 0.2 /* fraction to free at a time */
28     #endif
29     #ifndef MAXFAN
30     #define MAXFAN 32 /* maximum arms in a triangle fan */
31     #endif
32     #ifndef MINFAN
33     #define MINFAN 4 /* minimum arms in a triangle fan */
34     #endif
35     #ifndef FANSIZE
36     #define FANSIZE 3.5 /* fan sizing factor */
37     #endif
38    
39     #define NEWMAP 01 /* need to recompute mapping */
40     #define NEWRGB 02 /* need to remap RGB values */
41 gwlarson 3.2 #define NEWHIST 04 /* clear histogram as well */
42 gwlarson 3.1
43     struct ODview *odView; /* our view list */
44     int odNViews; /* number of views in our list */
45    
46     struct ODsamp odS; /* sample values */
47    
48     static int needmapping; /* what needs doing with tone map */
49    
50    
51     #define SAMP32 (32*(2*sizeof(short)+sizeof(union ODfunion)+sizeof(TMbright)+\
52     6*sizeof(BYTE))+sizeof(int4))
53    
54     int
55     odInit(n) /* initialize drawing routines */
56     int n;
57     {
58     int nbytes, i, j, k, nextsamp, count, blockdiv;
59     int res[2];
60    
61 gwlarson 3.3 if (odNViews > 0) { /* deallocate view structures */
62     for (i = odNViews; i--; ) {
63 gwlarson 3.1 free((char *)odView[i].bmap);
64 gwlarson 3.3 free((char *)odView[i].pmap);
65 gwlarson 3.1 if (odView[i].emap != NULL)
66     free((char *)odView[i].emap);
67     }
68     free((char *)odView);
69     odView = NULL;
70     odNViews = 0;
71     }
72     if (n && n != odS.nsamp) {
73     /* round space up to nearest power of 2 */
74     nbytes = (n+31)/32 * SAMP32;
75     for (i = 1024; nbytes > i-8; i <<= 1)
76     ;
77     n = (i-8)/SAMP32 * 32;
78 gwlarson 3.2 needmapping = NEWHIST;
79 gwlarson 3.1 }
80     if (n != odS.nsamp) { /* (re)allocate sample array */
81     if (odS.nsamp)
82     free(odS.base);
83     odS.nsamp = 0;
84     if (!n)
85     return(0);
86     nbytes = (n+31)/32 * SAMP32;
87     odS.base = (char *)malloc(nbytes);
88     if (odS.base == NULL)
89     return(0);
90     /* assign larger alignment types earlier */
91     odS.f = (union ODfunion *)odS.base;
92     odS.redraw = (int4 *)(odS.f + n);
93     odS.ip = (short (*)[2])(odS.redraw + n/32);
94     odS.brt = (TMbright *)(odS.ip + n);
95     odS.chr = (BYTE (*)[3])(odS.brt + n);
96     odS.rgb = (BYTE (*)[3])(odS.chr + n);
97     odS.nsamp = n;
98     }
99     if (!n)
100     return(0);
101     /* allocate view information */
102     count = 0; /* count pixels */
103     for (i = 0; dev_auxview(i, res) != NULL; i++)
104     count += res[0]*res[1];
105     odView = (struct ODview *)malloc(i*sizeof(struct ODview));
106     if (odView == NULL)
107     return(0);
108     odNViews = i;
109     blockdiv = sqrt(count/(n/SAMPSPERBLOCK)) + 0.5;
110     if (blockdiv < 8) blockdiv = 8;
111     nextsamp = 0; count /= blockdiv*blockdiv; /* # blocks */
112     while (i--) { /* initialize each view */
113     dev_auxview(i, res);
114     odView[i].hhi = res[0];
115     odView[i].hlow = (res[0] + blockdiv/2) / blockdiv;
116     if (odView[i].hlow < 1) odView[i].hlow = 1;
117     odView[i].vhi = res[1];
118     odView[i].vlow = (res[1] + blockdiv/2) / blockdiv;
119     if (odView[i].vlow < 1) odView[i].vlow = 1;
120 gwlarson 3.3 odView[i].emap = NULL;
121     odView[i].dmap = NULL;
122     odView[i].pmap = (int4 *)calloc(FL4NELS(res[0]*res[1]),
123     sizeof(int4));
124     if (odView[i].pmap == NULL)
125     return(0);
126 gwlarson 3.1 j = odView[i].hlow*odView[i].vlow;
127     odView[i].bmap = (struct ODblock *)malloc(
128     j * sizeof(struct ODblock));
129     if (odView[i].bmap == NULL)
130     return(0);
131     DCHECK(count<=0 | nextsamp>=n,
132     CONSISTENCY, "counter botch in odInit");
133     if (!i) count = j;
134 gwlarson 3.2 while (j--) { /* initialize blocks & free lists */
135     odView[i].bmap[j].pthresh = FHUGE;
136 gwlarson 3.1 odView[i].bmap[j].first = k = nextsamp;
137     nextsamp += odView[i].bmap[j].nsamp =
138     (n - nextsamp)/count--;
139     odView[i].bmap[j].free = k;
140     while (++k < nextsamp)
141     odS.nextfree(k-1) = k;
142     odS.nextfree(k-1) = ENDFREE;
143     odView[i].bmap[j].nused = 0;
144     }
145     }
146     CLR4ALL(odS.redraw, odS.nsamp); /* clear redraw flags */
147 gwlarson 3.2 for (i = odS.nsamp; i--; ) { /* clear values */
148 gwlarson 3.1 odS.ip[i][0] = odS.ip[i][1] = -1;
149 gwlarson 3.2 odS.brt[i] = TM_NOBRT;
150     }
151     needmapping |= NEWMAP; /* compute new map on update */
152 gwlarson 3.1 return(odS.nsamp); /* return number of samples */
153     }
154    
155     #undef SAMP32
156    
157    
158     int
159     sampcmp(s0, s1) /* sample order, descending proximity */
160     int *s0, *s1;
161     {
162     register double diff = odS.closeness(*s1) - odS.closeness(*s0);
163    
164     return (diff > FTINY ? 1 : diff < -FTINY ? -1 : 0);
165     }
166    
167    
168     int
169 gwlarson 3.2 odAllocBlockSamp(vn, hh, vh, prox) /* allocate sample from block */
170     int vn, hh, vh;
171     double prox;
172 gwlarson 3.1 {
173     int si[SAMPSPERBLOCK+SAMPSPERBLOCK/4];
174 gwlarson 3.2 int hl, vl;
175 gwlarson 3.1 VIEW *vw;
176     FVECT ro, rd;
177     int res[2];
178     register struct ODblock *bp;
179 gwlarson 3.2 register int i, j;
180     /* get block */
181     hl = hh*odView[vn].hlow/odView[vn].hhi;
182     vl = vh*odView[vn].vlow/odView[vn].vhi;
183 gwlarson 3.1 bp = odView[vn].bmap + vl*odView[vn].hlow + hl;
184 gwlarson 3.2 if (prox > bp->pthresh)
185     return(-1); /* worse than free list occupants */
186     /* check for duplicate pixel */
187 gwlarson 3.3 if (CHK4(odView[vn].pmap, vh*odView[vn].hhi + hh))
188     i = bp->first + bp->nsamp;
189     else
190     i = -1;
191     while (i-- > bp->first)
192 gwlarson 3.2 if (hh == odS.ip[i][0] && vh == odS.ip[i][1]) { /* found it! */
193     /* search free list for it */
194     if (i == bp->free)
195     break; /* special case */
196     if (bp->free != ENDFREE)
197     for (j = bp->free; odS.nextfree(j) != ENDFREE;
198     j = odS.nextfree(j))
199     if (odS.nextfree(j) == i) {
200     odS.nextfree(j) =
201     odS.nextfree(i);
202     bp->nused++;
203     goto gotit;
204     }
205     if (prox >= 0.999*odS.closeness(i))
206     return(-1); /* previous sample is fine */
207     goto gotit;
208     }
209 gwlarson 3.3 DCHECK(i>=-1, WARNING, "pixel in presence map not found in block");
210 gwlarson 3.2 if (bp->free != ENDFREE) { /* allocate from free list */
211 gwlarson 3.1 i = bp->free;
212 gwlarson 3.3 if (odS.ip[i][0] >= 0 & odS.ip[i][1] >= 0)
213     CLR4(odView[vn].pmap, odS.ip[i][1]*odView[vn].hhi +
214     odS.ip[i][0]);
215 gwlarson 3.1 bp->free = odS.nextfree(i);
216     bp->nused++;
217 gwlarson 3.2 goto gotit;
218 gwlarson 3.1 }
219     DCHECK(bp->nsamp<=0, CONSISTENCY,
220     "no available samples in odAllocBlockSamp");
221     DCHECK(bp->nsamp > sizeof(si)/sizeof(si[0]), CONSISTENCY,
222     "too many samples in odAllocBlockSamp");
223     /* free some samples */
224     if ((vw = dev_auxview(vn, res)) == NULL)
225     error(CONSISTENCY, "bad view number in odAllocBlockSamp");
226     for (i = bp->nsamp; i--; ) /* figure out which are worse */
227     si[i] = bp->first + i;
228     qsort((char *)si, bp->nsamp, sizeof(int), sampcmp);
229 gwlarson 3.2 i = bp->nsamp*SFREEFRAC + .5; /* put them into free list */
230     if (i >= bp->nsamp) i = bp->nsamp-1; /* paranoia */
231     bp->pthresh = odS.closeness(si[i]); /* new proximity threshold */
232 gwlarson 3.1 while (--i > 0) {
233     odS.nextfree(si[i]) = bp->free;
234     bp->free = si[i];
235     bp->nused--;
236     }
237 gwlarson 3.2 i = si[0]; /* use worst sample */
238 gwlarson 3.3 CLR4(odView[vn].pmap, odS.ip[i][1]*odView[vn].hhi + odS.ip[i][0]);
239 gwlarson 3.2 gotit:
240     odS.ip[i][0] = hh;
241     odS.ip[i][1] = vh;
242     odS.closeness(i) = prox;
243 gwlarson 3.3 SET4(odView[vn].pmap, vh*odView[vn].hhi + hh);
244 gwlarson 3.2 return(i);
245 gwlarson 3.1 }
246    
247    
248     odSample(c, d, p) /* add a sample value */
249     COLR c;
250     FVECT d, p;
251     {
252     FVECT disp;
253 gwlarson 3.2 double d0, d1, h, v, prox;
254 gwlarson 3.1 register VIEW *vw;
255 gwlarson 3.2 int hh, vh;
256 gwlarson 3.1 int res[2];
257     register int i, id;
258    
259     DCHECK(odS.nsamp<=0, CONSISTENCY, "no samples allocated in odSample");
260     /* add value to each view */
261     for (i = 0; (vw = dev_auxview(i, res)) != NULL; i++) {
262     DCHECK(i>=odNViews, CONSISTENCY, "too many views in odSample");
263     CHECK(vw->type!=VT_PER, INTERNAL,
264     "cannot handle non-perspective views");
265     if (p != NULL) { /* compute view position */
266     VSUB(disp, p, vw->vp);
267     d0 = DOT(disp, vw->vdir);
268     if (d0 <= vw->vfore+FTINY)
269     continue; /* too close */
270     } else {
271     VCOPY(disp, d);
272     d0 = DOT(disp, vw->vdir);
273     if (d0 <= FTINY) /* behind view */
274     continue;
275     }
276     h = DOT(disp,vw->hvec)/(d0*vw->hn2) + 0.5 - vw->hoff;
277     if (h < 0. || h >= 1.)
278     continue; /* left or right */
279     v = DOT(disp,vw->vvec)/(d0*vw->vn2) + 0.5 - vw->voff;
280     if (v < 0. || v >= 1.)
281     continue; /* above or below */
282     hh = h * res[0];
283     vh = v * res[1];
284     if (odView[i].dmap != NULL) { /* check depth */
285     d1 = odView[i].dmap[vh*res[0] + hh];
286     if (d1 < 0.99*FHUGE && (d0 > (1.+DEPTHEPS)*d1 ||
287     (1.+DEPTHEPS)*d0 < d1))
288     continue; /* occlusion error */
289     }
290     if (p != NULL) { /* compute closeness (sin^2) */
291     d1 = DOT(disp, d);
292 gwlarson 3.2 prox = 1. - d1*d1/DOT(disp,disp);
293 gwlarson 3.1 } else
294 gwlarson 3.2 prox = 0.;
295     /* allocate sample */
296     id = odAllocBlockSamp(i, hh, vh, prox);
297     if (id < 0)
298     continue; /* not good enough */
299 gwlarson 3.1 /* convert color */
300     tmCvColrs(&odS.brt[id], odS.chr[id], c, 1);
301     if (imm_mode | needmapping) /* if immediate mode */
302     needmapping |= NEWRGB; /* map it later */
303     else /* else map it now */
304     tmMapPixels(odS.rgb[id], &odS.brt[id], odS.chr[id], 1);
305     SET4(odS.redraw, id); /* mark for redraw */
306     }
307     }
308    
309    
310 gwlarson 3.2 odRemap(newhist) /* recompute tone mapping */
311     int newhist;
312 gwlarson 3.1 {
313     needmapping |= NEWMAP|NEWRGB;
314 gwlarson 3.2 if (newhist)
315     needmapping |= NEWHIST;
316 gwlarson 3.1 }
317    
318    
319     odRedraw(vn, hmin, vmin, hmax, vmax) /* redraw view region */
320     int vn, hmin, vmin, hmax, vmax;
321     {
322     int i, j;
323     register struct ODblock *bp;
324     register int k;
325    
326     if (vn<0 | vn>=odNViews)
327     return;
328     /* check view limits */
329     if (hmin < 0) hmin = 0;
330     if (hmax >= odView[vn].hhi) hmax = odView[vn].hhi-1;
331     if (vmin < 0) vmin = 0;
332     if (vmax >= odView[vn].vhi) vmax = odView[vn].vhi-1;
333     if (hmax <= hmin | vmax <= vmin)
334     return;
335     /* convert to low resolution */
336     hmin = hmin * odView[vn].hlow / odView[vn].hhi;
337     hmax = hmax * odView[vn].hlow / odView[vn].hhi;
338     vmin = vmin * odView[vn].vlow / odView[vn].vhi;
339     vmax = vmax * odView[vn].vlow / odView[vn].vhi;
340     /* mark block samples for redraw, inclusive */
341     for (i = hmin; i <= hmax; i++)
342     for (j = vmin; j <= vmax; j++) {
343     bp = odView[vn].bmap + j*odView[vn].hlow + i;
344     for (k = bp->nsamp; k--; )
345     if (odS.ip[bp->first+k][0] >= 0)
346     SET4(odS.redraw, bp->first+k);
347     }
348     }
349    
350    
351     odDepthMap(vn, dm) /* assign depth map for view */
352     int vn;
353     GLfloat *dm;
354     {
355     double d0, d1;
356     int i, j, hmin, hmax, vmin, vmax;
357     register int k, l;
358    
359     if (dm == NULL) { /* free edge map */
360 gwlarson 3.2 if (vn<0 | vn>=odNViews)
361     return; /* too late -- they're gone! */
362 gwlarson 3.1 if (odView[vn].emap != NULL)
363     free((char *)odView[vn].emap);
364     odView[vn].emap = NULL;
365     odView[vn].dmap = NULL;
366     return;
367     }
368 gwlarson 3.2 DCHECK(vn<0 | vn>=odNViews, CONSISTENCY,
369     "bad view number in odDepthMap");
370 gwlarson 3.1 odView[vn].dmap = dm; /* initialize edge map */
371     if (odView[vn].emap == NULL) {
372     odView[vn].emap = (int4 *)malloc(
373     FL4NELS(odView[vn].hlow*odView[vn].vlow)*sizeof(int4));
374     if (odView[vn].emap == NULL)
375     error(SYSTEM, "out of memory in odDepthMap");
376     }
377     CLR4ALL(odView[vn].emap, odView[vn].hlow*odView[vn].vlow);
378     /* compute edge map */
379     vmin = odView[vn].vhi; /* enter loopsville */
380     for (j = odView[vn].vlow; j--; ) {
381     vmax = vmin;
382     vmin = j*odView[vn].vhi/odView[vn].vlow;
383     hmin = odView[vn].hhi;
384     for (i = odView[vn].hlow; i--; ) {
385     hmax = hmin;
386     hmin = i*odView[vn].hhi/odView[vn].hlow;
387     for (l = vmin; l < vmax; l++) { /* vertical edges */
388     d1 = dm[l*odView[vn].hhi+hmin];
389     for (k = hmin+1; k < hmax; k++) {
390     d0 = d1;
391     d1 = dm[l*odView[vn].hhi+k];
392     if (d0 > (1.+DEPTHEPS)*d1 ||
393     (1.+DEPTHEPS)*d0 < d1) {
394     SET4(odView[vn].emap,
395     j*odView[vn].hlow + i);
396     break;
397     }
398     }
399     if (k < hmax)
400     break;
401     }
402     if (l < vmax)
403     continue;
404     for (k = hmin; k < hmax; k++) { /* horizontal edges */
405     d1 = dm[vmin*odView[vn].hhi+k];
406     for (l = vmin+1; l < vmax; l++) {
407     d0 = d1;
408     d1 = dm[l*odView[vn].hhi+k];
409     if (d0 > (1.+DEPTHEPS)*d1 ||
410     (1.+DEPTHEPS)*d0 < d1) {
411     SET4(odView[vn].emap,
412     j*odView[vn].hlow + i);
413     break;
414     }
415     }
416     if (l < vmax)
417     break;
418     }
419     }
420     }
421     }
422    
423    
424     odUpdate(vn) /* update this view */
425     int vn;
426     {
427 gwlarson 3.4 register int i, j;
428 gwlarson 3.1
429     DCHECK(vn<0 | vn>=odNViews, CONSISTENCY,
430     "bad view number in odUpdate");
431     /* need to do some tone mapping? */
432     if (needmapping & NEWRGB) {
433     if (needmapping & NEWMAP) {
434 gwlarson 3.2 if (needmapping & NEWHIST)
435     tmClearHisto();
436 gwlarson 3.1 if (tmAddHisto(odS.brt,odS.nsamp,1) != TM_E_OK)
437     return;
438     if (tmComputeMapping(0.,0.,0.) != TM_E_OK)
439     return;
440 gwlarson 3.4 for (i = odS.nsamp; i--; ) /* redraw all */
441     if (odS.ip[i][0] >= 0)
442     SET4(odS.redraw, i);
443 gwlarson 3.1 }
444     if (tmMapPixels(odS.rgb,odS.brt,odS.chr,odS.nsamp) != TM_E_OK)
445     return;
446     needmapping = 0; /* reset flag */
447     }
448 gwlarson 3.4 /* draw samples flagged for redraw */
449     for (j = FL4NELS(odS.nsamp); j--; )
450     for (i = 0; odS.redraw[j]; i++) /* skips faster */
451     if (odS.redraw[j] & 1L<<i) {
452     odDrawSamp(vn, (j<<5)+i);
453     odS.redraw[j] &= ~(1L<<i);
454     }
455 gwlarson 3.1 }
456    
457    
458     #if 0
459     static
460     clip_end(p, o, vp) /* clip line segment to view */
461     GLshort p[3];
462     short o[2];
463     register struct ODview *vp;
464     {
465     if (p[0] < 0) {
466     p[1] = -o[0]*(p[1]-o[1])/(p[0]-o[0]) + o[1];
467     p[2] = -o[0]*p[2]/(p[0]-o[0]);
468     p[0] = 0;
469     } else if (p[0] >= vp->hhi) {
470     p[1] = (vp->hhi-1-o[0])*(p[1]-o[1])/(p[0]-o[0]) + o[1];
471     p[2] = (vp->hhi-1-o[0])*p[2]/(p[0]-o[0]);
472     p[0] = vp->hhi-1;
473     }
474     if (p[1] < 0) {
475     p[0] = -o[1]*(p[0]-o[0])/(p[1]-o[1]) + o[0];
476     p[2] = -o[1]*p[2]/(p[1]-o[1]);
477     p[1] = 0;
478     } else if (p[1] >= vp->vhi) {
479     p[0] = (vp->vhi-1-o[1])*(p[0]-o[0])/(p[1]-o[1]) + o[0];
480     p[2] = (vp->vhi-1-o[1])*p[2]/(p[1]-o[1]);
481     p[1] = vp->vhi-1;
482     }
483     }
484     #endif
485    
486    
487     static int
488     make_arms(ar, cp, vp, sz) /* make arms for triangle fan */
489     GLshort ar[MAXFAN][3];
490     short cp[2];
491     register struct ODview *vp;
492     double sz;
493     {
494     int na, dv;
495     double hrad, vrad, phi0, phi;
496     register int i;
497    
498     DCHECK(sz > 1, CONSISTENCY, "super-unary size in make_arms");
499     na = MAXFAN*sz*sz + 0.5; /* keep area constant */
500     if (na < MINFAN) na = MINFAN;
501     hrad = FANSIZE*sz*vp->hhi/vp->hlow;
502     vrad = FANSIZE*sz*vp->vhi/vp->vlow;
503     if (hrad*vrad < 2.25)
504     hrad = vrad = 1.5;
505     phi0 = (2.*PI) * frandom();
506     dv = OMAXDEPTH*sz + 0.5;
507     for (i = 0; i < na; i++) {
508     phi = phi0 + (2.*PI)*i/na;
509     ar[i][0] = cp[0] + tcos(phi)*hrad + 0.5;
510     ar[i][1] = cp[1] + tsin(phi)*vrad + 0.5;
511     ar[i][2] = dv;
512     /* clip_end(ar[i], cp, vp); */
513     }
514     return(na);
515     }
516    
517    
518     static int
519     depthchange(vp, x0, y0, x1, y1) /* check depth discontinuity */
520     register struct ODview *vp;
521     int x0, y0, x1, y1;
522     {
523     register double d0, d1;
524    
525     DCHECK(x0<0 | x0>=vp->hhi | y0<0 | y0>=vp->vhi,
526     CONSISTENCY, "coordinates off view in depthchange");
527    
528     if (x1<0 | x1>=vp->hhi | y1<0 | y1>=vp->vhi)
529     return(1);
530    
531     d0 = vp->dmap[y0*vp->hhi + x0];
532     d1 = vp->dmap[y1*vp->hhi + x1];
533    
534     return((1.+DEPTHEPS)*d0 < d1 || d0 > (1.+DEPTHEPS)*d1);
535     }
536    
537    
538     static
539     clip_edge(p, o, vp) /* clip line segment to depth edge */
540     GLshort p[3];
541     short o[2];
542     register struct ODview *vp;
543     {
544     int x, y, xstep, ystep, rise, rise2, run, run2, n;
545    
546     DCHECK(vp->dmap==NULL, CONSISTENCY,
547     "clip_edge called with no depth map");
548     x = o[0]; y = o[1];
549     run = p[0] - x;
550     xstep = run > 0 ? 1 : -1;
551     run *= xstep;
552     rise = p[1] - y;
553     ystep = rise > 0 ? 1 : -1;
554     rise *= ystep;
555     rise2 = run2 = 0;
556     if (rise > run) rise2 = 1;
557     else run2 = 1;
558     n = rise + run;
559     while (n--) /* run out arm, checking depth */
560     if (run2 > rise2) {
561     if (depthchange(vp, x, y, x+xstep, y))
562     break;
563     x += xstep;
564     rise2 += rise;
565     } else {
566     if (depthchange(vp, x, y, x, y+ystep))
567     break;
568     y += ystep;
569     run2 += run;
570     }
571     if (n < 0) /* found something? */
572     return;
573     if (run > rise)
574     p[2] = (x - o[0])*p[2]/(p[0] - o[0]);
575     else
576     p[2] = (y - o[1])*p[2]/(p[1] - o[1]);
577     p[0] = x;
578     p[1] = y;
579     }
580    
581    
582     static int
583     getblock(vp, h, v) /* get block index */
584     register struct ODview *vp;
585     register int h, v;
586     {
587     if (h<0 | h>=vp->hhi | v<0 | v>=vp->vhi)
588     return(-1);
589     return(h*vp->hlow/vp->hhi + v*vp->vlow/vp->vhi*vp->hlow);
590     }
591    
592    
593 gwlarson 3.4 odDrawSamp(vn, id) /* draw view sample */
594     int vn;
595 gwlarson 3.1 register int id;
596     {
597     GLshort arm[MAXFAN][3];
598     int narms, blockindex, bi1;
599     register struct ODview *vp;
600     double size;
601     int home_edges;
602     register int i;
603    
604     vp = odView + vn;
605 gwlarson 3.4 blockindex = getblock(vp, odS.ip[id][0], odS.ip[id][1]);
606     DCHECK(blockindex<0, CONSISTENCY, "bad sample handed to odDrawSamp");
607 gwlarson 3.1 DCHECK(vp->bmap[blockindex].nused <= 0,
608 gwlarson 3.4 CONSISTENCY, "bad in-use count in odDrawSamp");
609 gwlarson 3.1 /* create triangle fan */
610     size = 1./sqrt((double)vp->bmap[blockindex].nused);
611     narms = make_arms(arm, odS.ip[id], vp, size);
612     if (vp->emap != NULL) { /* check for edge collisions */
613     home_edges = CHK4(vp->emap, blockindex);
614     for (i = 0; i < narms; i++)
615     /* the following test is flawed, because we could
616     * be passing through a block on a diagonal run */
617     if (home_edges ||
618     ( (bi1 = getblock(vp, arm[i][0], arm[i][1]))
619     != blockindex &&
620     (bi1 < 0 || CHK4(vp->emap, bi1)) ))
621     clip_edge(arm[i], odS.ip[id], vp);
622     }
623     /* draw triangle fan */
624     glColor3ub(odS.rgb[id][0], odS.rgb[id][1], odS.rgb[id][2]);
625     glBegin(GL_TRIANGLE_FAN);
626     glVertex3s((GLshort)odS.ip[id][0], (GLshort)odS.ip[id][1], (GLshort)0);
627     for (i = 0; i < narms; i++)
628     glVertex3sv(arm[i]);
629     glVertex3sv(arm[0]); /* connect last to first */
630     glEnd();
631     }