18 |
|
|
19 |
|
#include "random.h" |
20 |
|
|
21 |
+ |
#ifndef WFLUSH |
22 |
+ |
#ifdef SPEED |
23 |
+ |
#define WFLUSH (5*SPEED) |
24 |
+ |
#else |
25 |
+ |
#define WFLUSH 100 /* flush after this many rays */ |
26 |
+ |
#endif |
27 |
+ |
#endif |
28 |
|
|
29 |
+ |
#ifdef SMLFLT |
30 |
+ |
#define sscanvec(s,v) (sscanf(s,"%f %f %f",v,v+1,v+2)==3) |
31 |
+ |
#else |
32 |
+ |
#define sscanvec(s,v) (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3) |
33 |
+ |
#endif |
34 |
+ |
|
35 |
+ |
|
36 |
|
getrect(s, r) /* get a box */ |
37 |
|
char *s; |
38 |
|
register RECT *r; |
41 |
|
|
42 |
|
if (*s && !strncmp(s, "all", strlen(s))) { |
43 |
|
r->l = r->d = 0; |
44 |
< |
r->r = ourview.hresolu; |
45 |
< |
r->u = ourview.vresolu; |
44 |
> |
r->r = hresolu; |
45 |
> |
r->u = vresolu; |
46 |
|
return(0); |
47 |
|
} |
48 |
|
if (sscanf(s, "%d %d %d %d", &x0, &y0, &x1, &y1) != 4) { |
71 |
|
} |
72 |
|
if (r->l < 0) r->l = 0; |
73 |
|
if (r->d < 0) r->d = 0; |
74 |
< |
if (r->r > ourview.hresolu) r->r = ourview.hresolu; |
75 |
< |
if (r->u > ourview.vresolu) r->u = ourview.vresolu; |
74 |
> |
if (r->r > hresolu) r->r = hresolu; |
75 |
> |
if (r->u > vresolu) r->u = vresolu; |
76 |
|
if (r->l > r->r) r->l = r->r; |
77 |
|
if (r->d > r->u) r->d = r->u; |
78 |
|
return(0); |
97 |
|
error(COMMAND, "illegal magnification"); |
98 |
|
return(-1); |
99 |
|
} |
100 |
< |
if (sscanf(s, "%*lf %lf %lf %lf", &vec[0], &vec[1], &vec[2]) != 3) { |
100 |
> |
if (!sscanvec(sskip(s), vec)) { |
101 |
|
if (dev->getcur == NULL) |
102 |
|
return(-1); |
103 |
|
(*dev->comout)("Pick view center\n"); |
104 |
|
if ((*dev->getcur)(&x, &y) == ABORT) |
105 |
|
return(-1); |
106 |
< |
rayview(thisray.rorg, thisray.rdir, &ourview, x+.5, y+.5); |
106 |
> |
if (viewray(thisray.rorg, thisray.rdir, &ourview, |
107 |
> |
(x+.5)/hresolu, (y+.5)/vresolu) < 0) { |
108 |
> |
error(COMMAND, "not on image"); |
109 |
> |
return(-1); |
110 |
> |
} |
111 |
|
if (!direc || ourview.type == VT_PAR) { |
112 |
|
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
113 |
|
if (!localhit(&thisray, &thescene)) { |
147 |
|
register PNODE *p; |
148 |
|
int xmin, ymin, xmax, ymax; |
149 |
|
{ |
150 |
+ |
extern long nrays; |
151 |
+ |
static long lastflush = 0; |
152 |
|
static RAY thisray; |
153 |
|
double h, v; |
134 |
– |
register int i; |
154 |
|
|
155 |
|
if (xmax - xmin <= 0 || ymax - ymin <= 0) { /* empty */ |
156 |
|
p->x = xmin; |
159 |
|
return; |
160 |
|
} |
161 |
|
/* jitter ray direction */ |
162 |
< |
p->x = h = xmin + (xmax-xmin)*frandom(); |
163 |
< |
p->y = v = ymin + (ymax-ymin)*frandom(); |
162 |
> |
h = xmin + (xmax-xmin)*frandom(); |
163 |
> |
v = ymin + (ymax-ymin)*frandom(); |
164 |
|
|
165 |
< |
rayview(thisray.rorg, thisray.rdir, &ourview, h, v); |
165 |
> |
if (viewray(thisray.rorg, thisray.rdir, &ourview, |
166 |
> |
h/hresolu, v/vresolu) < 0) { |
167 |
> |
setcolor(thisray.rcol, 0.0, 0.0, 0.0); |
168 |
> |
} else { |
169 |
> |
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
170 |
> |
samplendx++; |
171 |
> |
rayvalue(&thisray); |
172 |
> |
} |
173 |
|
|
174 |
< |
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
175 |
< |
|
150 |
< |
rayvalue(&thisray); |
151 |
< |
|
174 |
> |
p->x = h; |
175 |
> |
p->y = v; |
176 |
|
copycolor(p->v, thisray.rcol); |
153 |
– |
|
177 |
|
scalecolor(p->v, exposure); |
178 |
|
|
179 |
|
(*dev->paintr)(greyscale?greyof(p->v):p->v, xmin, ymin, xmax, ymax); |
180 |
+ |
|
181 |
+ |
if (dev->flush != NULL && nrays - lastflush >= WFLUSH) { |
182 |
+ |
lastflush = nrays; |
183 |
+ |
(*dev->flush)(); |
184 |
+ |
} |
185 |
|
} |
186 |
|
|
187 |
|
|
189 |
|
{ |
190 |
|
/* free old image */ |
191 |
|
freepkids(&ptrunk); |
192 |
< |
/* set up frame */ |
193 |
< |
if (ourview.hresolu > dev->xsiz || ourview.vresolu > dev->ysiz) |
194 |
< |
newview(&ourview); /* beware recursive loop! */ |
192 |
> |
/* save reserve memory */ |
193 |
> |
fillreserves(); |
194 |
> |
/* compute resolution */ |
195 |
> |
hresolu = dev->xsiz; |
196 |
> |
vresolu = dev->ysiz; |
197 |
> |
normaspect(viewaspect(&ourview), &dev->pixaspect, &hresolu, &vresolu); |
198 |
|
pframe.l = pframe.d = 0; |
199 |
< |
pframe.r = ourview.hresolu; pframe.u = ourview.vresolu; |
199 |
> |
pframe.r = hresolu; pframe.u = vresolu; |
200 |
|
pdepth = 0; |
201 |
|
/* clear device */ |
202 |
< |
(*dev->clear)(ourview.hresolu, ourview.vresolu); |
202 |
> |
(*dev->clear)(hresolu, vresolu); |
203 |
|
/* get first value */ |
204 |
< |
paint(&ptrunk, 0, 0, ourview.hresolu, ourview.vresolu); |
204 |
> |
paint(&ptrunk, 0, 0, hresolu, vresolu); |
205 |
|
} |
206 |
|
|
207 |
|
|
208 |
|
redraw() /* redraw the image */ |
209 |
|
{ |
210 |
< |
(*dev->clear)(ourview.hresolu, ourview.vresolu); |
210 |
> |
(*dev->clear)(hresolu, vresolu); |
211 |
|
(*dev->comout)("redrawing...\n"); |
212 |
< |
repaint(0, 0, ourview.hresolu, ourview.vresolu); |
212 |
> |
repaint(0, 0, hresolu, vresolu); |
213 |
|
(*dev->comout)("\n"); |
214 |
|
} |
215 |
|
|
222 |
|
reg.l = xmin; reg.r = xmax; |
223 |
|
reg.d = ymin; reg.u = ymax; |
224 |
|
|
225 |
< |
paintrect(&ptrunk, 0, 0, ourview.hresolu, ourview.vresolu, ®); |
225 |
> |
paintrect(&ptrunk, 0, 0, hresolu, vresolu, ®); |
226 |
|
} |
227 |
|
|
228 |
|
|
370 |
|
{ |
371 |
|
char *err; |
372 |
|
|
342 |
– |
if (vp->hresolu > dev->xsiz || vp->vresolu > dev->ysiz) /* shrink */ |
343 |
– |
if (vp->vresolu * dev->xsiz < vp->hresolu * dev->ysiz) { |
344 |
– |
vp->vresolu = dev->xsiz * vp->vresolu / vp->hresolu; |
345 |
– |
vp->hresolu = dev->xsiz; |
346 |
– |
} else { |
347 |
– |
vp->hresolu = dev->ysiz * vp->hresolu / vp->vresolu; |
348 |
– |
vp->vresolu = dev->ysiz; |
349 |
– |
} |
373 |
|
if ((err = setview(vp)) != NULL) { |
374 |
|
sprintf(errmsg, "view not set - %s", err); |
375 |
|
error(COMMAND, errmsg); |
376 |
< |
} else if (bcmp(vp, &ourview, sizeof(VIEW))) { |
377 |
< |
bcopy(&ourview, &oldview, sizeof(VIEW)); |
378 |
< |
bcopy(vp, &ourview, sizeof(VIEW)); |
379 |
< |
newimage(); /* newimage() calls with vp=&ourview! */ |
376 |
> |
} else if (bcmp((char *)vp, (char *)&ourview, sizeof(VIEW))) { |
377 |
> |
copystruct(&oldview, &ourview); |
378 |
> |
copystruct(&ourview, vp); |
379 |
> |
newimage(); |
380 |
|
} |
381 |
|
} |
382 |
|
|
385 |
|
double angle, elev, mag; |
386 |
|
FVECT vc; |
387 |
|
{ |
365 |
– |
extern double sqrt(), dist2(); |
388 |
|
double d; |
389 |
|
FVECT v1; |
390 |
|
VIEW nv; |
391 |
|
register int i; |
392 |
|
|
393 |
|
VCOPY(nv.vup, ourview.vup); |
394 |
< |
nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu; |
394 |
> |
nv.hoff = ourview.hoff; nv.voff = ourview.voff; |
395 |
|
spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.)); |
396 |
|
if (elev != 0.0) { |
397 |
|
fcross(v1, ourview.vup, nv.vdir); |
415 |
|
} |
416 |
|
|
417 |
|
|
418 |
< |
spinvector(vres, vorig, vnorm, theta) /* rotate vector around normal */ |
419 |
< |
FVECT vres, vorig, vnorm; |
420 |
< |
double theta; |
418 |
> |
zoomview(vp, zf) /* zoom in our out */ |
419 |
> |
register VIEW *vp; |
420 |
> |
double zf; |
421 |
|
{ |
422 |
< |
extern double sin(), cos(); |
423 |
< |
double sint, cost, dotp; |
424 |
< |
FVECT vperp; |
425 |
< |
register int i; |
426 |
< |
|
405 |
< |
if (theta == 0.0) { |
406 |
< |
VCOPY(vres, vorig); |
422 |
> |
switch (vp->type) { |
423 |
> |
case VT_PAR: /* parallel view */ |
424 |
> |
case VT_ANG: /* angular fisheye */ |
425 |
> |
vp->horiz /= zf; |
426 |
> |
vp->vert /= zf; |
427 |
|
return; |
428 |
+ |
case VT_PER: /* perspective view */ |
429 |
+ |
vp->horiz = atan(tan(vp->horiz*(PI/180./2.))/zf) / |
430 |
+ |
(PI/180./2.); |
431 |
+ |
vp->vert = atan(tan(vp->vert*(PI/180./2.))/zf) / |
432 |
+ |
(PI/180./2.); |
433 |
+ |
return; |
434 |
+ |
case VT_HEM: /* hemispherical fisheye */ |
435 |
+ |
vp->horiz = sin(vp->horiz*(PI/180./2.))/zf; |
436 |
+ |
if (vp->horiz >= 1.0-FTINY) |
437 |
+ |
vp->horiz = 180.; |
438 |
+ |
else |
439 |
+ |
vp->horiz = asin(vp->horiz) / (PI/180./2.); |
440 |
+ |
vp->vert = sin(vp->vert*(PI/180./2.))/zf; |
441 |
+ |
if (vp->vert >= 1.0-FTINY) |
442 |
+ |
vp->vert = 180.; |
443 |
+ |
else |
444 |
+ |
vp->vert = asin(vp->vert) / (PI/180./2.); |
445 |
+ |
return; |
446 |
|
} |
409 |
– |
sint = sin(theta); |
410 |
– |
cost = cos(theta); |
411 |
– |
dotp = DOT(vorig, vnorm); |
412 |
– |
fcross(vperp, vnorm, vorig); |
413 |
– |
for (i = 0; i < 3; i++) |
414 |
– |
vres[i] = vnorm[i]*dotp*(1.-cost) + |
415 |
– |
vorig[i]*cost + vperp[i]*sint; |
447 |
|
} |