18 |
|
|
19 |
|
#include "random.h" |
20 |
|
|
21 |
+ |
#ifndef WFLUSH |
22 |
+ |
#define WFLUSH 30 /* flush after this many rays */ |
23 |
+ |
#endif |
24 |
|
|
25 |
+ |
#ifdef SMLFLT |
26 |
+ |
#define sscanvec(s,v) (sscanf(s,"%f %f %f",v,v+1,v+2)==3) |
27 |
+ |
#else |
28 |
+ |
#define sscanvec(s,v) (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3) |
29 |
+ |
#endif |
30 |
+ |
|
31 |
+ |
|
32 |
|
getrect(s, r) /* get a box */ |
33 |
|
char *s; |
34 |
|
register RECT *r; |
93 |
|
error(COMMAND, "illegal magnification"); |
94 |
|
return(-1); |
95 |
|
} |
96 |
< |
if (sscanf(s, "%*lf %lf %lf %lf", &vec[0], &vec[1], &vec[2]) != 3) { |
96 |
> |
if (!sscanvec(sskip(s), vec)) { |
97 |
|
if (dev->getcur == NULL) |
98 |
|
return(-1); |
99 |
|
(*dev->comout)("Pick view center\n"); |
100 |
|
if ((*dev->getcur)(&x, &y) == ABORT) |
101 |
|
return(-1); |
102 |
< |
viewray(thisray.rorg, thisray.rdir, &ourview, |
103 |
< |
(x+.5)/hresolu, (y+.5)/vresolu); |
102 |
> |
if (viewray(thisray.rorg, thisray.rdir, &ourview, |
103 |
> |
(x+.5)/hresolu, (y+.5)/vresolu) < 0) { |
104 |
> |
error(COMMAND, "not on image"); |
105 |
> |
return(-1); |
106 |
> |
} |
107 |
|
if (!direc || ourview.type == VT_PAR) { |
108 |
|
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
109 |
|
if (!localhit(&thisray, &thescene)) { |
143 |
|
register PNODE *p; |
144 |
|
int xmin, ymin, xmax, ymax; |
145 |
|
{ |
146 |
+ |
extern long nrays; |
147 |
+ |
static long lastflush = 0; |
148 |
|
static RAY thisray; |
149 |
|
double h, v; |
135 |
– |
register int i; |
150 |
|
|
151 |
|
if (xmax - xmin <= 0 || ymax - ymin <= 0) { /* empty */ |
152 |
|
p->x = xmin; |
155 |
|
return; |
156 |
|
} |
157 |
|
/* jitter ray direction */ |
158 |
< |
p->x = h = xmin + (xmax-xmin)*frandom(); |
159 |
< |
h /= hresolu; |
146 |
< |
p->y = v = ymin + (ymax-ymin)*frandom(); |
147 |
< |
v /= vresolu; |
158 |
> |
h = xmin + (xmax-xmin)*frandom(); |
159 |
> |
v = ymin + (ymax-ymin)*frandom(); |
160 |
|
|
161 |
< |
viewray(thisray.rorg, thisray.rdir, &ourview, h, v); |
161 |
> |
if (viewray(thisray.rorg, thisray.rdir, &ourview, |
162 |
> |
h/hresolu, v/vresolu) < 0) { |
163 |
> |
setcolor(thisray.rcol, 0.0, 0.0, 0.0); |
164 |
> |
} else { |
165 |
> |
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
166 |
> |
samplendx++; |
167 |
> |
rayvalue(&thisray); |
168 |
> |
} |
169 |
|
|
170 |
< |
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
171 |
< |
|
153 |
< |
rayvalue(&thisray); |
154 |
< |
|
170 |
> |
p->x = h; |
171 |
> |
p->y = v; |
172 |
|
copycolor(p->v, thisray.rcol); |
156 |
– |
|
173 |
|
scalecolor(p->v, exposure); |
174 |
|
|
175 |
|
(*dev->paintr)(greyscale?greyof(p->v):p->v, xmin, ymin, xmax, ymax); |
176 |
+ |
|
177 |
+ |
if (dev->flush != NULL && nrays - lastflush >= WFLUSH) { |
178 |
+ |
lastflush = nrays; |
179 |
+ |
(*dev->flush)(); |
180 |
+ |
} |
181 |
|
} |
182 |
|
|
183 |
|
|
185 |
|
{ |
186 |
|
/* free old image */ |
187 |
|
freepkids(&ptrunk); |
188 |
+ |
/* save reserve memory */ |
189 |
+ |
fillreserves(); |
190 |
|
/* compute resolution */ |
191 |
|
hresolu = dev->xsiz; |
192 |
|
vresolu = dev->ysiz; |
193 |
< |
normaspect(&ourview, &dev->pixaspect, &hresolu, &vresolu); |
193 |
> |
normaspect(viewaspect(&ourview), &dev->pixaspect, &hresolu, &vresolu); |
194 |
|
pframe.l = pframe.d = 0; |
195 |
|
pframe.r = hresolu; pframe.u = vresolu; |
196 |
|
pdepth = 0; |
369 |
|
if ((err = setview(vp)) != NULL) { |
370 |
|
sprintf(errmsg, "view not set - %s", err); |
371 |
|
error(COMMAND, errmsg); |
372 |
< |
} else if (bcmp(vp, &ourview, sizeof(VIEW))) { |
373 |
< |
copyview(&oldview, &ourview); |
374 |
< |
copyview(&ourview, vp); |
375 |
< |
newimage(); /* newimage() calls with vp=&ourview! */ |
372 |
> |
} else if (bcmp((char *)vp, (char *)&ourview, sizeof(VIEW))) { |
373 |
> |
copystruct(&oldview, &ourview); |
374 |
> |
copystruct(&ourview, vp); |
375 |
> |
newimage(); |
376 |
|
} |
377 |
|
} |
378 |
|
|
412 |
|
} |
413 |
|
|
414 |
|
|
415 |
< |
spinvector(vres, vorig, vnorm, theta) /* rotate vector around normal */ |
416 |
< |
FVECT vres, vorig, vnorm; |
417 |
< |
double theta; |
415 |
> |
zoomview(vp, zf) /* zoom in our out */ |
416 |
> |
register VIEW *vp; |
417 |
> |
double zf; |
418 |
|
{ |
419 |
< |
extern double sin(), cos(); |
420 |
< |
double sint, cost, dotp; |
421 |
< |
FVECT vperp; |
422 |
< |
register int i; |
423 |
< |
|
401 |
< |
if (theta == 0.0) { |
402 |
< |
VCOPY(vres, vorig); |
419 |
> |
switch (vp->type) { |
420 |
> |
case VT_PAR: /* parallel view */ |
421 |
> |
case VT_ANG: /* angular fisheye */ |
422 |
> |
vp->horiz /= zf; |
423 |
> |
vp->vert /= zf; |
424 |
|
return; |
425 |
+ |
case VT_PER: /* perspective view */ |
426 |
+ |
vp->horiz = atan(tan(vp->horiz*(PI/180./2.))/zf) / |
427 |
+ |
(PI/180./2.); |
428 |
+ |
vp->vert = atan(tan(vp->vert*(PI/180./2.))/zf) / |
429 |
+ |
(PI/180./2.); |
430 |
+ |
return; |
431 |
+ |
case VT_HEM: /* hemispherical fisheye */ |
432 |
+ |
vp->horiz = sin(vp->horiz*(PI/180./2.))/zf; |
433 |
+ |
if (vp->horiz >= 1.0-FTINY) |
434 |
+ |
vp->horiz = 180.; |
435 |
+ |
else |
436 |
+ |
vp->horiz = asin(vp->horiz) / (PI/180./2.); |
437 |
+ |
vp->vert = sin(vp->vert*(PI/180./2.))/zf; |
438 |
+ |
if (vp->vert >= 1.0-FTINY) |
439 |
+ |
vp->vert = 180.; |
440 |
+ |
else |
441 |
+ |
vp->vert = asin(vp->vert) / (PI/180./2.); |
442 |
+ |
return; |
443 |
|
} |
405 |
– |
sint = sin(theta); |
406 |
– |
cost = cos(theta); |
407 |
– |
dotp = DOT(vorig, vnorm); |
408 |
– |
fcross(vperp, vnorm, vorig); |
409 |
– |
for (i = 0; i < 3; i++) |
410 |
– |
vres[i] = vnorm[i]*dotp*(1.-cost) + |
411 |
– |
vorig[i]*cost + vperp[i]*sint; |
444 |
|
} |