ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhd_qtree2c.c
Revision: 3.2
Committed: Sat Feb 22 02:07:24 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Changes since 3.1: +1 -4 lines
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

File Contents

# User Rev Content
1 gregl 3.1 #ifndef lint
2 greg 3.2 static const char RCSid[] = "$Id$";
3 gregl 3.1 #endif
4     /*
5     * Quadtree display support routines for cone output.
6     */
7    
8     #include "standard.h"
9     #include "rhd_qtree.h"
10    
11    
12     static
13     redraw(tp, x0, y0, x1, y1, l) /* mark portion of a tree for redraw */
14     register RTREE *tp;
15     int x0, y0, x1, y1;
16     int l[2][2];
17     {
18     int quads = CH_ANY;
19     int mx, my;
20     register int i;
21     /* compute midpoint */
22     mx = (x0 + x1) >> 1;
23     my = (y0 + y1) >> 1;
24     /* see what to do */
25     if (l[0][0] > mx)
26     quads &= ~(CHF(UL)|CHF(DL));
27     else if (l[0][1] < mx)
28     quads &= ~(CHF(UR)|CHF(DR));
29     if (l[1][0] > my)
30     quads &= ~(CHF(DR)|CHF(DL));
31     else if (l[1][1] < my)
32     quads &= ~(CHF(UR)|CHF(UL));
33     tp->flgs |= quads; /* mark quadrants for update */
34     /* climb the branches */
35     for (i = 0; i < 4; i++)
36     if (tp->flgs & BRF(i) && quads & CHF(i))
37     redraw(tp->k[i].b, i&01 ? mx : x0, i&02 ? my : y0,
38     i&01 ? x1 : mx, i&02 ? y1 : my, l);
39     }
40    
41    
42     static
43     cpaint(rgb, p, x0, y0, x1, y1) /* paint a cone within a rectangle */
44     BYTE rgb[3];
45     register float *p;
46     int x0, y0, x1, y1;
47     {
48     static FVECT ip, wp;
49     double rad;
50     /* compute base radius */
51     rad = (double)(y1 - y0 + x1 - x0)/(odev.hres + odev.vres);
52     /* approximate apex pos? */
53     if (p == NULL || y1-y0 <= qtMinNodesiz || x1-x0 <= qtMinNodesiz) {
54     ip[0] = (double)(x0 + x1)/(odev.hres<<1);
55     ip[1] = (double)(y0 + y1)/(odev.vres<<1);
56     if (p != NULL) {
57     wp[0] = p[0] - odev.v.vp[0];
58     wp[1] = p[1] - odev.v.vp[1];
59     wp[2] = p[2] - odev.v.vp[2];
60     if (odev.v.type == VT_PER)
61     ip[2] = DOT(wp,odev.v.vdir);
62     else
63     ip[2] = VLEN(wp);
64     } else
65     ip[2] = FHUGE;
66     } else if (odev.v.type == VT_PER) { /* special case (faster) */
67     wp[0] = p[0] - odev.v.vp[0];
68     wp[1] = p[1] - odev.v.vp[1];
69     wp[2] = p[2] - odev.v.vp[2];
70     ip[2] = DOT(wp,odev.v.vdir);
71     ip[0] = DOT(wp,odev.v.hvec)/(ip[2]*odev.v.hn2) +
72     0.5 - odev.v.hoff;
73     ip[1] = DOT(wp,odev.v.vvec)/(ip[2]*odev.v.vn2) +
74     0.5 - odev.v.voff;
75     } else { /* general case */
76     VCOPY(wp, p);
77     viewloc(ip, &odev.v, wp);
78     }
79     dev_cone(rgb, ip, rad);
80     }
81    
82    
83     static
84     update(ca, tp, x0, y0, x1, y1) /* update tree display as needed */
85     BYTE ca[3]; /* returned average color */
86     register RTREE *tp;
87     int x0, y0, x1, y1;
88     {
89     int csm[3], nc;
90     register BYTE *cp;
91     BYTE rgb[3];
92     int gaps = 0;
93     int mx, my;
94     register int i;
95     /* compute midpoint */
96     mx = (x0 + x1) >> 1;
97     my = (y0 + y1) >> 1;
98     /* draw leaves */
99     csm[0] = csm[1] = csm[2] = nc = 0;
100     for (i = 0; i < 4; i++) {
101     if (tp->flgs & LFF(i)) {
102     cp = qtL.rgb[tp->k[i].li];
103     csm[0] += cp[0]; csm[1] += cp[1]; csm[2] += cp[2];
104     nc++;
105     if (tp->flgs & CHF(i))
106     cpaint(cp, qtL.wp[tp->k[i].li],
107     i&01 ? mx : x0, i&02 ? my : y0,
108     i&01 ? x1 : mx, i&02 ? y1 : my);
109     } else if ((tp->flgs & CHBRF(i)) == CHF(i))
110     gaps |= 1<<i; /* empty stem */
111     }
112     /* do branches */
113     for (i = 0; i < 4; i++)
114     if ((tp->flgs & CHBRF(i)) == CHBRF(i)) {
115     update(rgb, tp->k[i].b, i&01 ? mx : x0, i&02 ? my : y0,
116     i&01 ? x1 : mx, i&02 ? y1 : my);
117     csm[0] += rgb[0]; csm[1] += rgb[1]; csm[2] += rgb[2];
118     nc++;
119     }
120     if (nc > 1) {
121     ca[0] = csm[0]/nc; ca[1] = csm[1]/nc; ca[2] = csm[2]/nc;
122     } else {
123     ca[0] = csm[0]; ca[1] = csm[1]; ca[2] = csm[2];
124     }
125     /* fill in gaps with average */
126     for (i = 0; gaps && i < 4; gaps >>= 1, i++)
127     if (gaps & 01)
128     cpaint(ca, (float *)NULL,
129     i&01 ? mx : x0, i&02 ? my : y0,
130     i&01 ? x1 : mx, i&02 ? y1 : my);
131     tp->flgs &= ~CH_ANY; /* all done */
132     }
133    
134    
135     qtRedraw(x0, y0, x1, y1) /* redraw part or all of our screen */
136     int x0, y0, x1, y1;
137     {
138     int lim[2][2];
139    
140     if (is_stump(&qtrunk))
141     return;
142     if (!qtMapLeaves((lim[0][0]=x0) <= 0 & (lim[1][0]=y0) <= 0 &
143     (lim[0][1]=x1) >= odev.hres-1 & (lim[1][1]=y1) >= odev.vres-1))
144     return;
145     redraw(&qtrunk, 0, 0, odev.hres, odev.vres, lim);
146     }
147    
148    
149     qtUpdate() /* update our tree display */
150     {
151     BYTE ca[3];
152    
153     if (is_stump(&qtrunk))
154     return;
155     if (!qtMapLeaves(0))
156     return;
157     update(ca, &qtrunk, 0, 0, odev.hres, odev.vres);
158     }