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 |
+ |
/* ==================================================================== |
11 |
+ |
* The Radiance Software License, Version 1.0 |
12 |
+ |
* |
13 |
+ |
* Copyright (c) 1990 - 2002 The Regents of the University of California, |
14 |
+ |
* through Lawrence Berkeley National Laboratory. All rights reserved. |
15 |
+ |
* |
16 |
+ |
* Redistribution and use in source and binary forms, with or without |
17 |
+ |
* modification, are permitted provided that the following conditions |
18 |
+ |
* are met: |
19 |
+ |
* |
20 |
+ |
* 1. Redistributions of source code must retain the above copyright |
21 |
+ |
* notice, this list of conditions and the following disclaimer. |
22 |
+ |
* |
23 |
+ |
* 2. Redistributions in binary form must reproduce the above copyright |
24 |
+ |
* notice, this list of conditions and the following disclaimer in |
25 |
+ |
* the documentation and/or other materials provided with the |
26 |
+ |
* distribution. |
27 |
+ |
* |
28 |
+ |
* 3. The end-user documentation included with the redistribution, |
29 |
+ |
* if any, must include the following acknowledgment: |
30 |
+ |
* "This product includes Radiance software |
31 |
+ |
* (http://radsite.lbl.gov/) |
32 |
+ |
* developed by the Lawrence Berkeley National Laboratory |
33 |
+ |
* (http://www.lbl.gov/)." |
34 |
+ |
* Alternately, this acknowledgment may appear in the software itself, |
35 |
+ |
* if and wherever such third-party acknowledgments normally appear. |
36 |
+ |
* |
37 |
+ |
* 4. The names "Radiance," "Lawrence Berkeley National Laboratory" |
38 |
+ |
* and "The Regents of the University of California" must |
39 |
+ |
* not be used to endorse or promote products derived from this |
40 |
+ |
* software without prior written permission. For written |
41 |
+ |
* permission, please contact [email protected]. |
42 |
+ |
* |
43 |
+ |
* 5. Products derived from this software may not be called "Radiance", |
44 |
+ |
* nor may "Radiance" appear in their name, without prior written |
45 |
+ |
* permission of Lawrence Berkeley National Laboratory. |
46 |
+ |
* |
47 |
+ |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED |
48 |
+ |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
49 |
+ |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
50 |
+ |
* DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR |
51 |
+ |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
52 |
+ |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
53 |
+ |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
54 |
+ |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
55 |
+ |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
56 |
+ |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
57 |
+ |
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
58 |
+ |
* SUCH DAMAGE. |
59 |
+ |
* ==================================================================== |
60 |
+ |
* |
61 |
+ |
* This software consists of voluntary contributions made by many |
62 |
+ |
* individuals on behalf of Lawrence Berkeley National Laboratory. For more |
63 |
+ |
* information on Lawrence Berkeley National Laboratory, please see |
64 |
+ |
* <http://www.lbl.gov/>. |
65 |
+ |
*/ |
66 |
+ |
|
67 |
|
#include "ray.h" |
68 |
|
|
15 |
– |
#include "octree.h" |
16 |
– |
|
69 |
|
#include "rpaint.h" |
70 |
|
|
71 |
|
#include "random.h" |
72 |
|
|
73 |
|
#ifndef WFLUSH |
74 |
< |
#define WFLUSH 30 /* flush after this many rays */ |
74 |
> |
#ifdef SPEED |
75 |
> |
#define WFLUSH (5*SPEED) |
76 |
> |
#else |
77 |
> |
#define WFLUSH 100 /* flush after this many rays */ |
78 |
|
#endif |
79 |
+ |
#endif |
80 |
|
|
81 |
+ |
#ifdef SMLFLT |
82 |
+ |
#define sscanvec(s,v) (sscanf(s,"%f %f %f",v,v+1,v+2)==3) |
83 |
+ |
#else |
84 |
+ |
#define sscanvec(s,v) (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3) |
85 |
+ |
#endif |
86 |
|
|
87 |
+ |
|
88 |
+ |
int |
89 |
|
getrect(s, r) /* get a box */ |
90 |
|
char *s; |
91 |
|
register RECT *r; |
132 |
|
} |
133 |
|
|
134 |
|
|
135 |
+ |
int |
136 |
|
getinterest(s, direc, vec, mp) /* get area of interest */ |
137 |
|
char *s; |
138 |
|
int direc; |
151 |
|
error(COMMAND, "illegal magnification"); |
152 |
|
return(-1); |
153 |
|
} |
154 |
< |
if (sscanf(s, "%*lf %lf %lf %lf", &vec[0], &vec[1], &vec[2]) != 3) { |
154 |
> |
if (!sscanvec(sskip(s), vec)) { |
155 |
|
if (dev->getcur == NULL) |
156 |
|
return(-1); |
157 |
|
(*dev->comout)("Pick view center\n"); |
158 |
|
if ((*dev->getcur)(&x, &y) == ABORT) |
159 |
|
return(-1); |
160 |
< |
if (viewray(thisray.rorg, thisray.rdir, &ourview, |
161 |
< |
(x+.5)/hresolu, (y+.5)/vresolu) < 0) { |
160 |
> |
if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, |
161 |
> |
&ourview, (x+.5)/hresolu, (y+.5)/vresolu)) < -FTINY) { |
162 |
|
error(COMMAND, "not on image"); |
163 |
|
return(-1); |
164 |
|
} |
197 |
|
} |
198 |
|
|
199 |
|
|
200 |
+ |
void |
201 |
|
paint(p, xmin, ymin, xmax, ymax) /* compute and paint a rectangle */ |
202 |
|
register PNODE *p; |
203 |
|
int xmin, ymin, xmax, ymax; |
204 |
|
{ |
205 |
< |
extern long nrays; |
141 |
< |
static long lastflush = 0; |
205 |
> |
static unsigned long lastflush = 0; |
206 |
|
static RAY thisray; |
207 |
|
double h, v; |
208 |
|
|
216 |
|
h = xmin + (xmax-xmin)*frandom(); |
217 |
|
v = ymin + (ymax-ymin)*frandom(); |
218 |
|
|
219 |
< |
if (viewray(thisray.rorg, thisray.rdir, &ourview, |
220 |
< |
h/hresolu, v/vresolu) < 0) { |
219 |
> |
if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, &ourview, |
220 |
> |
h/hresolu, v/vresolu)) < -FTINY) { |
221 |
|
setcolor(thisray.rcol, 0.0, 0.0, 0.0); |
222 |
|
} else { |
223 |
|
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
224 |
+ |
samplendx++; |
225 |
|
rayvalue(&thisray); |
226 |
|
} |
227 |
|
|
239 |
|
} |
240 |
|
|
241 |
|
|
242 |
+ |
void |
243 |
|
newimage() /* start a new image */ |
244 |
|
{ |
245 |
|
/* free old image */ |
260 |
|
} |
261 |
|
|
262 |
|
|
263 |
+ |
void |
264 |
|
redraw() /* redraw the image */ |
265 |
|
{ |
266 |
|
(*dev->clear)(hresolu, vresolu); |
270 |
|
} |
271 |
|
|
272 |
|
|
273 |
+ |
void |
274 |
|
repaint(xmin, ymin, xmax, ymax) /* repaint a region */ |
275 |
|
int xmin, ymin, xmax, ymax; |
276 |
|
{ |
283 |
|
} |
284 |
|
|
285 |
|
|
286 |
+ |
void |
287 |
|
paintrect(p, xmin, ymin, xmax, ymax, r) /* paint picture rectangle */ |
288 |
|
register PNODE *p; |
289 |
|
int xmin, ymin, xmax, ymax; |
354 |
|
} |
355 |
|
|
356 |
|
|
357 |
+ |
void |
358 |
|
scalepict(p, sf) /* scale picture values */ |
359 |
|
register PNODE *p; |
360 |
|
double sf; |
371 |
|
} |
372 |
|
|
373 |
|
|
374 |
+ |
void |
375 |
|
getpictcolrs(yoff, scan, p, xsiz, ysiz) /* get scanline from picture */ |
376 |
|
int yoff; |
377 |
|
register COLR *scan; |
402 |
|
} |
403 |
|
|
404 |
|
|
405 |
< |
pcopy(p1, p2) /* copy paint node p1 into p2 */ |
335 |
< |
register PNODE *p1, *p2; |
336 |
< |
{ |
337 |
< |
copycolor(p2->v, p1->v); |
338 |
< |
p2->x = p1->x; |
339 |
< |
p2->y = p1->y; |
340 |
< |
} |
341 |
< |
|
342 |
< |
|
405 |
> |
void |
406 |
|
freepkids(p) /* free pnode's children */ |
407 |
|
register PNODE *p; |
408 |
|
{ |
412 |
|
freepkids(p->kid+DR); |
413 |
|
freepkids(p->kid+UL); |
414 |
|
freepkids(p->kid+UR); |
415 |
< |
free((char *)p->kid); |
415 |
> |
free((void *)p->kid); |
416 |
|
p->kid = NULL; |
417 |
|
} |
418 |
|
|
419 |
|
|
420 |
+ |
void |
421 |
|
newview(vp) /* change viewing parameters */ |
422 |
|
register VIEW *vp; |
423 |
|
{ |
434 |
|
} |
435 |
|
|
436 |
|
|
437 |
+ |
void |
438 |
|
moveview(angle, elev, mag, vc) /* move viewpoint */ |
439 |
|
double angle, elev, mag; |
440 |
|
FVECT vc; |
441 |
|
{ |
377 |
– |
extern double sqrt(), dist2(); |
442 |
|
double d; |
443 |
|
FVECT v1; |
444 |
|
VIEW nv; |
458 |
|
d = 0.0; /* don't move closer */ |
459 |
|
for (i = 0; i < 3; i++) |
460 |
|
d += (vc[i] - ourview.vp[i])*ourview.vdir[i]; |
461 |
+ |
nv.vfore = ourview.vfore; |
462 |
+ |
nv.vaft = ourview.vaft; |
463 |
|
} else { |
464 |
|
nv.horiz = ourview.horiz; |
465 |
|
nv.vert = ourview.vert; |
466 |
|
d = sqrt(dist2(ourview.vp, vc)) / mag; |
467 |
+ |
if ((nv.vfore = ourview.vfore) > FTINY) { |
468 |
+ |
nv.vfore += d - d*mag; |
469 |
+ |
if (nv.vfore < 0.0) nv.vfore = 0.0; |
470 |
+ |
} |
471 |
+ |
if ((nv.vaft = ourview.vaft) > FTINY) { |
472 |
+ |
nv.vaft += d - d*mag; |
473 |
+ |
if (nv.vaft <= nv.vfore) nv.vaft = 0.0; |
474 |
+ |
} |
475 |
|
} |
476 |
|
for (i = 0; i < 3; i++) |
477 |
|
nv.vp[i] = vc[i] - d*nv.vdir[i]; |
479 |
|
} |
480 |
|
|
481 |
|
|
482 |
< |
zoomview(vp, zf) /* zoom in our out */ |
482 |
> |
void |
483 |
> |
pcopy(p1, p2) /* copy paint node p1 into p2 */ |
484 |
> |
register PNODE *p1, *p2; |
485 |
> |
{ |
486 |
> |
copycolor(p2->v, p1->v); |
487 |
> |
p2->x = p1->x; |
488 |
> |
p2->y = p1->y; |
489 |
> |
} |
490 |
> |
|
491 |
> |
|
492 |
> |
void |
493 |
> |
zoomview(vp, zf) /* zoom in or out */ |
494 |
|
register VIEW *vp; |
495 |
|
double zf; |
496 |
|
{ |
497 |
|
switch (vp->type) { |
498 |
|
case VT_PAR: /* parallel view */ |
499 |
+ |
vp->horiz /= zf; |
500 |
+ |
vp->vert /= zf; |
501 |
+ |
return; |
502 |
|
case VT_ANG: /* angular fisheye */ |
503 |
|
vp->horiz /= zf; |
504 |
+ |
if (vp->horiz > 360.) |
505 |
+ |
vp->horiz = 360.; |
506 |
|
vp->vert /= zf; |
507 |
+ |
if (vp->vert > 360.) |
508 |
+ |
vp->vert = 360.; |
509 |
+ |
return; |
510 |
+ |
case VT_CYL: /* cylindrical panorama */ |
511 |
+ |
vp->horiz /= zf; |
512 |
+ |
if (vp->horiz > 360.) |
513 |
+ |
vp->horiz = 360.; |
514 |
+ |
vp->vert = atan(tan(vp->vert*(PI/180./2.))/zf) / (PI/180./2.); |
515 |
|
return; |
516 |
|
case VT_PER: /* perspective view */ |
517 |
|
vp->horiz = atan(tan(vp->horiz*(PI/180./2.))/zf) / |