1 |
– |
/* Copyright (c) 1996 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 |
|
* rpict.c - routines and variables for picture generation. |
6 |
|
*/ |
7 |
|
|
8 |
+ |
/* ==================================================================== |
9 |
+ |
* The Radiance Software License, Version 1.0 |
10 |
+ |
* |
11 |
+ |
* Copyright (c) 1990 - 2002 The Regents of the University of California, |
12 |
+ |
* through Lawrence Berkeley National Laboratory. All rights reserved. |
13 |
+ |
* |
14 |
+ |
* Redistribution and use in source and binary forms, with or without |
15 |
+ |
* modification, are permitted provided that the following conditions |
16 |
+ |
* are met: |
17 |
+ |
* |
18 |
+ |
* 1. Redistributions of source code must retain the above copyright |
19 |
+ |
* notice, this list of conditions and the following disclaimer. |
20 |
+ |
* |
21 |
+ |
* 2. Redistributions in binary form must reproduce the above copyright |
22 |
+ |
* notice, this list of conditions and the following disclaimer in |
23 |
+ |
* the documentation and/or other materials provided with the |
24 |
+ |
* distribution. |
25 |
+ |
* |
26 |
+ |
* 3. The end-user documentation included with the redistribution, |
27 |
+ |
* if any, must include the following acknowledgment: |
28 |
+ |
* "This product includes Radiance software |
29 |
+ |
* (http://radsite.lbl.gov/) |
30 |
+ |
* developed by the Lawrence Berkeley National Laboratory |
31 |
+ |
* (http://www.lbl.gov/)." |
32 |
+ |
* Alternately, this acknowledgment may appear in the software itself, |
33 |
+ |
* if and wherever such third-party acknowledgments normally appear. |
34 |
+ |
* |
35 |
+ |
* 4. The names "Radiance," "Lawrence Berkeley National Laboratory" |
36 |
+ |
* and "The Regents of the University of California" must |
37 |
+ |
* not be used to endorse or promote products derived from this |
38 |
+ |
* software without prior written permission. For written |
39 |
+ |
* permission, please contact [email protected]. |
40 |
+ |
* |
41 |
+ |
* 5. Products derived from this software may not be called "Radiance", |
42 |
+ |
* nor may "Radiance" appear in their name, without prior written |
43 |
+ |
* permission of Lawrence Berkeley National Laboratory. |
44 |
+ |
* |
45 |
+ |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED |
46 |
+ |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
47 |
+ |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
48 |
+ |
* DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR |
49 |
+ |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
50 |
+ |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
51 |
+ |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
52 |
+ |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
53 |
+ |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
54 |
+ |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
55 |
+ |
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
56 |
+ |
* SUCH DAMAGE. |
57 |
+ |
* ==================================================================== |
58 |
+ |
* |
59 |
+ |
* This software consists of voluntary contributions made by many |
60 |
+ |
* individuals on behalf of Lawrence Berkeley National Laboratory. For more |
61 |
+ |
* information on Lawrence Berkeley National Laboratory, please see |
62 |
+ |
* <http://www.lbl.gov/>. |
63 |
+ |
*/ |
64 |
+ |
|
65 |
|
#include "ray.h" |
66 |
|
|
67 |
|
#include <sys/types.h> |
82 |
|
|
83 |
|
#include "view.h" |
84 |
|
|
31 |
– |
#include "resolu.h" |
32 |
– |
|
85 |
|
#include "random.h" |
86 |
|
|
87 |
|
#include "paths.h" |
92 |
|
#define SIGCONT SIGIO |
93 |
|
#endif |
94 |
|
|
95 |
+ |
CUBE thescene; /* our scene */ |
96 |
+ |
OBJECT nsceneobjs; /* number of objects in our scene */ |
97 |
+ |
|
98 |
|
int dimlist[MAXDIM]; /* sampling dimensions */ |
99 |
|
int ndims = 0; /* number of sampling dimensions */ |
100 |
|
int samplendx; /* sample index number */ |
101 |
|
|
102 |
+ |
extern void ambnotify(); |
103 |
+ |
void (*addobjnotify[])() = {ambnotify, NULL}; |
104 |
+ |
|
105 |
|
VIEW ourview = STDVIEW; /* view parameters */ |
106 |
|
int hresolu = 512; /* horizontal resolution */ |
107 |
|
int vresolu = 512; /* vertical resolution */ |
113 |
|
|
114 |
|
double mblur = 0.; /* motion blur parameter */ |
115 |
|
|
116 |
+ |
void (*trace)() = NULL; /* trace call */ |
117 |
+ |
|
118 |
+ |
int do_irrad = 0; /* compute irradiance? */ |
119 |
+ |
|
120 |
|
double dstrsrc = 0.0; /* square source distribution */ |
121 |
|
double shadthresh = .05; /* shadow threshold */ |
122 |
|
double shadcert = .5; /* shadow certainty */ |
138 |
|
int maxdepth = 6; /* maximum recursion depth */ |
139 |
|
double minweight = 5e-3; /* minimum ray weight */ |
140 |
|
|
141 |
+ |
char *ambfile = NULL; /* ambient file name */ |
142 |
|
COLOR ambval = BLKCOLOR; /* ambient value */ |
143 |
|
int ambvwt = 0; /* initial weight for ambient value */ |
144 |
|
double ambacc = 0.2; /* ambient accuracy */ |
149 |
|
char *amblist[128]; /* ambient include/exclude list */ |
150 |
|
int ambincl = -1; /* include == 1, exclude == 0 */ |
151 |
|
|
89 |
– |
#ifdef MSDOS |
90 |
– |
int ralrm = 60; /* seconds between reports */ |
91 |
– |
#else |
152 |
|
int ralrm = 0; /* seconds between reports */ |
93 |
– |
#endif |
153 |
|
|
154 |
|
double pctdone = 0.0; /* percentage done */ |
96 |
– |
|
155 |
|
time_t tlastrept = 0L; /* time at last report */ |
156 |
+ |
time_t tstart; /* starting time */ |
157 |
|
|
99 |
– |
extern time_t tstart; /* starting time */ |
100 |
– |
|
101 |
– |
extern unsigned long nrays; /* number of rays traced */ |
102 |
– |
|
158 |
|
#define MAXDIV 16 /* maximum sample size */ |
159 |
|
|
160 |
|
#define pixjitter() (.5+dstrpix*(.5-frandom())) |
165 |
|
|
166 |
|
extern char *mktemp(); |
167 |
|
|
168 |
+ |
void report(); |
169 |
+ |
|
170 |
|
double pixvalue(); |
171 |
|
|
172 |
|
#ifdef NIX |
185 |
|
#endif |
186 |
|
|
187 |
|
|
188 |
+ |
void |
189 |
|
quit(code) /* quit program */ |
190 |
|
int code; |
191 |
|
{ |
192 |
|
if (code) /* report status */ |
193 |
|
report(); |
194 |
+ |
#ifndef NIX |
195 |
|
headclean(); /* delete header file */ |
196 |
|
pfclean(); /* clean up persist files */ |
197 |
+ |
#endif |
198 |
|
exit(code); |
199 |
|
} |
200 |
|
|
201 |
|
|
202 |
|
#ifndef NIX |
203 |
+ |
void |
204 |
|
report() /* report progress */ |
205 |
|
{ |
206 |
|
extern char *myhostname(); |
241 |
|
#endif |
242 |
|
} |
243 |
|
#else |
244 |
+ |
void |
245 |
|
report() /* report progress */ |
246 |
|
{ |
247 |
|
tlastrept = time((time_t *)NULL); |
252 |
|
#endif |
253 |
|
|
254 |
|
|
255 |
+ |
void |
256 |
|
rpict(seq, pout, zout, prvr) /* generate image(s) */ |
257 |
|
int seq; |
258 |
|
char *pout, *zout, *prvr; |
353 |
|
hres = hresolu; vres = vresolu; pa = pixaspect; |
354 |
|
if (prvr != NULL) |
355 |
|
if (viewfile(prvr, &ourview, &rs) <= 0 |
356 |
< |
|| rs.or != PIXSTANDARD) { |
356 |
> |
|| rs.rt != PIXSTANDARD) { |
357 |
|
sprintf(errmsg, |
358 |
|
"cannot recover view parameters from \"%s\"", prvr); |
359 |
|
error(WARNING, errmsg); |
421 |
|
COLOR *colptr; |
422 |
|
float *zptr; |
423 |
|
register int i; |
424 |
+ |
/* check for empty image */ |
425 |
+ |
if (hres <= 0 || vres <= 0) { |
426 |
+ |
error(WARNING, "empty output picture"); |
427 |
+ |
fprtresolu(0, 0, stdout); |
428 |
+ |
return; |
429 |
+ |
} |
430 |
|
/* allocate scanlines */ |
431 |
|
for (i = 0; i <= psample; i++) { |
432 |
|
scanbar[i] = (COLOR *)malloc(hres*sizeof(COLOR)); |
437 |
|
ystep = (psample*99+70)/140; |
438 |
|
if (hstep > 2) { |
439 |
|
i = hres/hstep + 2; |
440 |
< |
if ((sampdens = malloc(i)) == NULL) |
440 |
> |
if ((sampdens = (char *)malloc(i)) == NULL) |
441 |
|
goto memerr; |
442 |
|
while (i--) |
443 |
|
sampdens[i] = hstep; |
469 |
|
if (i >= vres) |
470 |
|
goto alldone; |
471 |
|
if (zfd != -1 && i > 0 && |
472 |
< |
lseek(zfd, (long)i*hres*sizeof(float), 0) < 0) |
472 |
> |
lseek(zfd, (off_t)i*hres*sizeof(float), 0) < 0) |
473 |
|
error(SYSTEM, "z-file seek error in render"); |
474 |
|
pctdone = 100.0*i/vres; |
475 |
|
if (ralrm > 0) /* report init stats */ |
538 |
|
if (close(zfd) == -1) |
539 |
|
goto writerr; |
540 |
|
for (i = 0; i <= psample; i++) |
541 |
< |
free((char *)zbar[i]); |
541 |
> |
free((void *)zbar[i]); |
542 |
|
} |
543 |
|
for (i = 0; i <= psample; i++) |
544 |
< |
free((char *)scanbar[i]); |
544 |
> |
free((void *)scanbar[i]); |
545 |
|
if (sampdens != NULL) |
546 |
|
free(sampdens); |
547 |
|
pctdone = 100.0; |
764 |
|
} |
765 |
|
if (fflush(stdout) == EOF) |
766 |
|
goto writerr; |
767 |
< |
free((char *)scanline); |
767 |
> |
free((void *)scanline); |
768 |
|
fclose(fp); |
769 |
|
unlink(oldfile); |
770 |
|
return(y); |