| 1 |
– |
/* Copyright (c) 1987 Regents of the University of California */ |
| 2 |
– |
|
| 1 |
|
#ifndef lint |
| 2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
| 2 |
> |
static const char RCSid[] = "$Id$"; |
| 3 |
|
#endif |
| 6 |
– |
|
| 4 |
|
/* |
| 5 |
|
* rv3.c - miscellaneous routines for rview. |
| 6 |
|
* |
| 7 |
< |
* 5/11/87 |
| 7 |
> |
* External symbols declared in rpaint.h |
| 8 |
|
*/ |
| 9 |
|
|
| 10 |
< |
#include "ray.h" |
| 10 |
> |
#include "copyright.h" |
| 11 |
|
|
| 12 |
< |
#include "octree.h" |
| 12 |
> |
#include <string.h> |
| 13 |
|
|
| 14 |
+ |
#include "ray.h" |
| 15 |
|
#include "rpaint.h" |
| 18 |
– |
|
| 16 |
|
#include "random.h" |
| 17 |
|
|
| 18 |
|
#ifndef WFLUSH |
| 19 |
< |
#define WFLUSH 30 /* flush after this many rays */ |
| 19 |
> |
#define WFLUSH 2048 /* flush after this many rays */ |
| 20 |
|
#endif |
| 21 |
|
|
| 22 |
+ |
#ifdef SMLFLT |
| 23 |
+ |
#define sscanvec(s,v) (sscanf(s,"%f %f %f",v,v+1,v+2)==3) |
| 24 |
+ |
#else |
| 25 |
+ |
#define sscanvec(s,v) (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3) |
| 26 |
+ |
#endif |
| 27 |
|
|
| 28 |
+ |
|
| 29 |
+ |
int |
| 30 |
|
getrect(s, r) /* get a box */ |
| 31 |
|
char *s; |
| 32 |
|
register RECT *r; |
| 73 |
|
} |
| 74 |
|
|
| 75 |
|
|
| 76 |
+ |
int |
| 77 |
|
getinterest(s, direc, vec, mp) /* get area of interest */ |
| 78 |
|
char *s; |
| 79 |
|
int direc; |
| 92 |
|
error(COMMAND, "illegal magnification"); |
| 93 |
|
return(-1); |
| 94 |
|
} |
| 95 |
< |
if (sscanf(s, "%*lf %lf %lf %lf", &vec[0], &vec[1], &vec[2]) != 3) { |
| 95 |
> |
if (!sscanvec(sskip(s), vec)) { |
| 96 |
|
if (dev->getcur == NULL) |
| 97 |
|
return(-1); |
| 98 |
|
(*dev->comout)("Pick view center\n"); |
| 99 |
|
if ((*dev->getcur)(&x, &y) == ABORT) |
| 100 |
|
return(-1); |
| 101 |
< |
if (viewray(thisray.rorg, thisray.rdir, &ourview, |
| 102 |
< |
(x+.5)/hresolu, (y+.5)/vresolu) < 0) { |
| 101 |
> |
if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, |
| 102 |
> |
&ourview, (x+.5)/hresolu, (y+.5)/vresolu)) < -FTINY) { |
| 103 |
|
error(COMMAND, "not on image"); |
| 104 |
|
return(-1); |
| 105 |
|
} |
| 106 |
|
if (!direc || ourview.type == VT_PAR) { |
| 107 |
< |
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
| 107 |
> |
rayorigin(&thisray, PRIMARY, NULL, NULL); |
| 108 |
|
if (!localhit(&thisray, &thescene)) { |
| 109 |
|
error(COMMAND, "not a local object"); |
| 110 |
|
return(-1); |
| 118 |
|
VCOPY(vec, thisray.rdir); |
| 119 |
|
else |
| 120 |
|
VCOPY(vec, thisray.rop); |
| 121 |
< |
} else if (direc) |
| 122 |
< |
for (i = 0; i < 3; i++) |
| 123 |
< |
vec[i] -= ourview.vp[i]; |
| 121 |
> |
} else if (direc) { |
| 122 |
> |
for (i = 0; i < 3; i++) |
| 123 |
> |
vec[i] -= ourview.vp[i]; |
| 124 |
> |
if (normalize(vec) == 0.0) { |
| 125 |
> |
error(COMMAND, "point at view origin"); |
| 126 |
> |
return(-1); |
| 127 |
> |
} |
| 128 |
> |
} |
| 129 |
|
return(0); |
| 130 |
|
} |
| 131 |
|
|
| 143 |
|
} |
| 144 |
|
|
| 145 |
|
|
| 146 |
+ |
void |
| 147 |
|
paint(p, xmin, ymin, xmax, ymax) /* compute and paint a rectangle */ |
| 148 |
|
register PNODE *p; |
| 149 |
|
int xmin, ymin, xmax, ymax; |
| 150 |
|
{ |
| 151 |
< |
extern long nrays; |
| 141 |
< |
static long lastflush = 0; |
| 151 |
> |
static unsigned long lastflush = 0; |
| 152 |
|
static RAY thisray; |
| 153 |
|
double h, v; |
| 154 |
|
|
| 162 |
|
h = xmin + (xmax-xmin)*frandom(); |
| 163 |
|
v = ymin + (ymax-ymin)*frandom(); |
| 164 |
|
|
| 165 |
< |
if (viewray(thisray.rorg, thisray.rdir, &ourview, |
| 166 |
< |
h/hresolu, v/vresolu) < 0) { |
| 165 |
> |
if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, &ourview, |
| 166 |
> |
h/hresolu, v/vresolu)) < -FTINY) { |
| 167 |
|
setcolor(thisray.rcol, 0.0, 0.0, 0.0); |
| 168 |
|
} else { |
| 169 |
< |
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
| 169 |
> |
rayorigin(&thisray, PRIMARY, NULL, NULL); |
| 170 |
> |
samplendx++; |
| 171 |
|
rayvalue(&thisray); |
| 172 |
|
} |
| 173 |
|
|
| 185 |
|
} |
| 186 |
|
|
| 187 |
|
|
| 188 |
+ |
void |
| 189 |
|
newimage() /* start a new image */ |
| 190 |
|
{ |
| 191 |
|
/* free old image */ |
| 192 |
|
freepkids(&ptrunk); |
| 193 |
+ |
/* save reserve memory */ |
| 194 |
+ |
fillreserves(); |
| 195 |
|
/* compute resolution */ |
| 196 |
|
hresolu = dev->xsiz; |
| 197 |
|
vresolu = dev->ysiz; |
| 206 |
|
} |
| 207 |
|
|
| 208 |
|
|
| 209 |
+ |
void |
| 210 |
|
redraw() /* redraw the image */ |
| 211 |
|
{ |
| 212 |
|
(*dev->clear)(hresolu, vresolu); |
| 216 |
|
} |
| 217 |
|
|
| 218 |
|
|
| 219 |
+ |
void |
| 220 |
|
repaint(xmin, ymin, xmax, ymax) /* repaint a region */ |
| 221 |
|
int xmin, ymin, xmax, ymax; |
| 222 |
|
{ |
| 229 |
|
} |
| 230 |
|
|
| 231 |
|
|
| 232 |
+ |
void |
| 233 |
|
paintrect(p, xmin, ymin, xmax, ymax, r) /* paint picture rectangle */ |
| 234 |
|
register PNODE *p; |
| 235 |
|
int xmin, ymin, xmax, ymax; |
| 300 |
|
} |
| 301 |
|
|
| 302 |
|
|
| 303 |
+ |
void |
| 304 |
|
scalepict(p, sf) /* scale picture values */ |
| 305 |
|
register PNODE *p; |
| 306 |
|
double sf; |
| 317 |
|
} |
| 318 |
|
|
| 319 |
|
|
| 320 |
+ |
void |
| 321 |
|
getpictcolrs(yoff, scan, p, xsiz, ysiz) /* get scanline from picture */ |
| 322 |
|
int yoff; |
| 323 |
|
register COLR *scan; |
| 348 |
|
} |
| 349 |
|
|
| 350 |
|
|
| 351 |
< |
pcopy(p1, p2) /* copy paint node p1 into p2 */ |
| 333 |
< |
register PNODE *p1, *p2; |
| 334 |
< |
{ |
| 335 |
< |
copycolor(p2->v, p1->v); |
| 336 |
< |
p2->x = p1->x; |
| 337 |
< |
p2->y = p1->y; |
| 338 |
< |
} |
| 339 |
< |
|
| 340 |
< |
|
| 351 |
> |
void |
| 352 |
|
freepkids(p) /* free pnode's children */ |
| 353 |
|
register PNODE *p; |
| 354 |
|
{ |
| 358 |
|
freepkids(p->kid+DR); |
| 359 |
|
freepkids(p->kid+UL); |
| 360 |
|
freepkids(p->kid+UR); |
| 361 |
< |
free((char *)p->kid); |
| 361 |
> |
free((void *)p->kid); |
| 362 |
|
p->kid = NULL; |
| 363 |
|
} |
| 364 |
|
|
| 365 |
|
|
| 366 |
+ |
void |
| 367 |
|
newview(vp) /* change viewing parameters */ |
| 368 |
|
register VIEW *vp; |
| 369 |
|
{ |
| 372 |
|
if ((err = setview(vp)) != NULL) { |
| 373 |
|
sprintf(errmsg, "view not set - %s", err); |
| 374 |
|
error(COMMAND, errmsg); |
| 375 |
< |
} else if (bcmp((char *)vp, (char *)&ourview, sizeof(VIEW))) { |
| 376 |
< |
copystruct(&oldview, &ourview); |
| 377 |
< |
copystruct(&ourview, vp); |
| 375 |
> |
} else if (memcmp((char *)vp, (char *)&ourview, sizeof(VIEW))) { |
| 376 |
> |
oldview = ourview; |
| 377 |
> |
ourview = *vp; |
| 378 |
|
newimage(); |
| 379 |
|
} |
| 380 |
|
} |
| 381 |
|
|
| 382 |
|
|
| 383 |
+ |
void |
| 384 |
|
moveview(angle, elev, mag, vc) /* move viewpoint */ |
| 385 |
|
double angle, elev, mag; |
| 386 |
|
FVECT vc; |
| 387 |
|
{ |
| 375 |
– |
extern double sqrt(), dist2(); |
| 388 |
|
double d; |
| 389 |
|
FVECT v1; |
| 390 |
< |
VIEW nv; |
| 390 |
> |
VIEW nv = ourview; |
| 391 |
|
register int i; |
| 392 |
|
|
| 381 |
– |
VCOPY(nv.vup, ourview.vup); |
| 382 |
– |
nv.hoff = ourview.hoff; nv.voff = ourview.voff; |
| 393 |
|
spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.)); |
| 394 |
|
if (elev != 0.0) { |
| 395 |
|
fcross(v1, ourview.vup, nv.vdir); |
| 396 |
|
normalize(v1); |
| 397 |
|
spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.)); |
| 398 |
|
} |
| 399 |
< |
if ((nv.type = ourview.type) == VT_PAR) { |
| 400 |
< |
nv.horiz = ourview.horiz / mag; |
| 401 |
< |
nv.vert = ourview.vert / mag; |
| 399 |
> |
if (nv.type == VT_PAR) { |
| 400 |
> |
nv.horiz /= mag; |
| 401 |
> |
nv.vert /= mag; |
| 402 |
|
d = 0.0; /* don't move closer */ |
| 403 |
|
for (i = 0; i < 3; i++) |
| 404 |
|
d += (vc[i] - ourview.vp[i])*ourview.vdir[i]; |
| 405 |
|
} else { |
| 396 |
– |
nv.horiz = ourview.horiz; |
| 397 |
– |
nv.vert = ourview.vert; |
| 406 |
|
d = sqrt(dist2(ourview.vp, vc)) / mag; |
| 407 |
+ |
if (nv.vfore > FTINY) { |
| 408 |
+ |
nv.vfore += d - d*mag; |
| 409 |
+ |
if (nv.vfore < 0.0) nv.vfore = 0.0; |
| 410 |
+ |
} |
| 411 |
+ |
if (nv.vaft > FTINY) { |
| 412 |
+ |
nv.vaft += d - d*mag; |
| 413 |
+ |
if (nv.vaft <= nv.vfore) nv.vaft = 0.0; |
| 414 |
+ |
} |
| 415 |
+ |
nv.vdist /= mag; |
| 416 |
|
} |
| 417 |
|
for (i = 0; i < 3; i++) |
| 418 |
|
nv.vp[i] = vc[i] - d*nv.vdir[i]; |
| 420 |
|
} |
| 421 |
|
|
| 422 |
|
|
| 423 |
< |
zoomview(vp, zf) /* zoom in our out */ |
| 423 |
> |
void |
| 424 |
> |
pcopy(p1, p2) /* copy paint node p1 into p2 */ |
| 425 |
> |
register PNODE *p1, *p2; |
| 426 |
> |
{ |
| 427 |
> |
copycolor(p2->v, p1->v); |
| 428 |
> |
p2->x = p1->x; |
| 429 |
> |
p2->y = p1->y; |
| 430 |
> |
} |
| 431 |
> |
|
| 432 |
> |
|
| 433 |
> |
void |
| 434 |
> |
zoomview(vp, zf) /* zoom in or out */ |
| 435 |
|
register VIEW *vp; |
| 436 |
|
double zf; |
| 437 |
|
{ |
| 438 |
|
switch (vp->type) { |
| 439 |
|
case VT_PAR: /* parallel view */ |
| 440 |
+ |
vp->horiz /= zf; |
| 441 |
+ |
vp->vert /= zf; |
| 442 |
+ |
return; |
| 443 |
|
case VT_ANG: /* angular fisheye */ |
| 444 |
|
vp->horiz /= zf; |
| 445 |
+ |
if (vp->horiz > 360.) |
| 446 |
+ |
vp->horiz = 360.; |
| 447 |
|
vp->vert /= zf; |
| 448 |
+ |
if (vp->vert > 360.) |
| 449 |
+ |
vp->vert = 360.; |
| 450 |
+ |
return; |
| 451 |
+ |
case VT_PLS: /* planisphere fisheye */ |
| 452 |
+ |
vp->horiz = sin((PI/180./2.)*vp->horiz) / |
| 453 |
+ |
(1.0 + cos((PI/180./2.)*vp->horiz)) / zf; |
| 454 |
+ |
vp->horiz *= vp->horiz; |
| 455 |
+ |
vp->horiz = (2.*180./PI)*acos((1. - vp->horiz) / |
| 456 |
+ |
(1. + vp->horiz)); |
| 457 |
+ |
vp->vert = sin((PI/180./2.)*vp->vert) / |
| 458 |
+ |
(1.0 + cos((PI/180./2.)*vp->vert)) / zf; |
| 459 |
+ |
vp->vert *= vp->vert; |
| 460 |
+ |
vp->vert = (2.*180./PI)*acos((1. - vp->vert) / |
| 461 |
+ |
(1. + vp->vert)); |
| 462 |
+ |
return; |
| 463 |
+ |
case VT_CYL: /* cylindrical panorama */ |
| 464 |
+ |
vp->horiz /= zf; |
| 465 |
+ |
if (vp->horiz > 360.) |
| 466 |
+ |
vp->horiz = 360.; |
| 467 |
+ |
vp->vert = atan(tan(vp->vert*(PI/180./2.))/zf) / (PI/180./2.); |
| 468 |
|
return; |
| 469 |
|
case VT_PER: /* perspective view */ |
| 470 |
|
vp->horiz = atan(tan(vp->horiz*(PI/180./2.))/zf) / |