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 |
+ |
#include "copyright.h" |
9 |
+ |
|
10 |
|
#include "ray.h" |
11 |
|
|
12 |
|
#include <sys/types.h> |
21 |
|
#endif |
22 |
|
#endif |
23 |
|
|
24 |
< |
extern time_t time(); |
26 |
< |
|
24 |
> |
#include <time.h> |
25 |
|
#include <signal.h> |
26 |
|
|
27 |
+ |
#include "platform.h" |
28 |
|
#include "view.h" |
30 |
– |
|
31 |
– |
#include "resolu.h" |
32 |
– |
|
29 |
|
#include "random.h" |
34 |
– |
|
30 |
|
#include "paths.h" |
31 |
|
|
32 |
+ |
|
33 |
|
#define RFTEMPLATE "rfXXXXXX" |
34 |
|
|
35 |
|
#ifndef SIGCONT |
36 |
|
#define SIGCONT SIGIO |
37 |
|
#endif |
38 |
|
|
39 |
+ |
CUBE thescene; /* our scene */ |
40 |
+ |
OBJECT nsceneobjs; /* number of objects in our scene */ |
41 |
+ |
|
42 |
|
int dimlist[MAXDIM]; /* sampling dimensions */ |
43 |
|
int ndims = 0; /* number of sampling dimensions */ |
44 |
|
int samplendx; /* sample index number */ |
45 |
|
|
46 |
+ |
extern void ambnotify(); |
47 |
+ |
void (*addobjnotify[])() = {ambnotify, NULL}; |
48 |
+ |
|
49 |
|
VIEW ourview = STDVIEW; /* view parameters */ |
50 |
|
int hresolu = 512; /* horizontal resolution */ |
51 |
|
int vresolu = 512; /* vertical resolution */ |
57 |
|
|
58 |
|
double mblur = 0.; /* motion blur parameter */ |
59 |
|
|
60 |
+ |
void (*trace)() = NULL; /* trace call */ |
61 |
+ |
|
62 |
+ |
int do_irrad = 0; /* compute irradiance? */ |
63 |
+ |
|
64 |
|
double dstrsrc = 0.0; /* square source distribution */ |
65 |
|
double shadthresh = .05; /* shadow threshold */ |
66 |
|
double shadcert = .5; /* shadow certainty */ |
82 |
|
int maxdepth = 6; /* maximum recursion depth */ |
83 |
|
double minweight = 5e-3; /* minimum ray weight */ |
84 |
|
|
85 |
+ |
char *ambfile = NULL; /* ambient file name */ |
86 |
|
COLOR ambval = BLKCOLOR; /* ambient value */ |
87 |
|
int ambvwt = 0; /* initial weight for ambient value */ |
88 |
|
double ambacc = 0.2; /* ambient accuracy */ |
93 |
|
char *amblist[128]; /* ambient include/exclude list */ |
94 |
|
int ambincl = -1; /* include == 1, exclude == 0 */ |
95 |
|
|
89 |
– |
#ifdef MSDOS |
90 |
– |
int ralrm = 60; /* seconds between reports */ |
91 |
– |
#else |
96 |
|
int ralrm = 0; /* seconds between reports */ |
93 |
– |
#endif |
97 |
|
|
98 |
|
double pctdone = 0.0; /* percentage done */ |
96 |
– |
|
99 |
|
time_t tlastrept = 0L; /* time at last report */ |
100 |
+ |
time_t tstart; /* starting time */ |
101 |
|
|
99 |
– |
extern time_t tstart; /* starting time */ |
100 |
– |
|
101 |
– |
extern unsigned long nrays; /* number of rays traced */ |
102 |
– |
|
102 |
|
#define MAXDIV 16 /* maximum sample size */ |
103 |
|
|
104 |
|
#define pixjitter() (.5+dstrpix*(.5-frandom())) |
107 |
|
|
108 |
|
static VIEW lastview; /* the previous view input */ |
109 |
|
|
110 |
< |
extern char *mktemp(); |
110 |
> |
extern char *mktemp(); /* XXX should be in stdlib.h or unistd.h */ |
111 |
|
|
112 |
+ |
void report(); |
113 |
+ |
|
114 |
|
double pixvalue(); |
115 |
|
|
116 |
|
#ifdef NIX |
129 |
|
#endif |
130 |
|
|
131 |
|
|
132 |
+ |
void |
133 |
|
quit(code) /* quit program */ |
134 |
|
int code; |
135 |
|
{ |
136 |
|
if (code) /* report status */ |
137 |
|
report(); |
138 |
+ |
#ifndef NIX |
139 |
|
headclean(); /* delete header file */ |
140 |
|
pfclean(); /* clean up persist files */ |
141 |
+ |
#endif |
142 |
|
exit(code); |
143 |
|
} |
144 |
|
|
145 |
|
|
146 |
|
#ifndef NIX |
147 |
+ |
void |
148 |
|
report() /* report progress */ |
149 |
|
{ |
150 |
|
extern char *myhostname(); |
185 |
|
#endif |
186 |
|
} |
187 |
|
#else |
188 |
+ |
void |
189 |
|
report() /* report progress */ |
190 |
|
{ |
191 |
|
tlastrept = time((time_t *)NULL); |
196 |
|
#endif |
197 |
|
|
198 |
|
|
199 |
+ |
void |
200 |
|
rpict(seq, pout, zout, prvr) /* generate image(s) */ |
201 |
|
int seq; |
202 |
|
char *pout, *zout, *prvr; |
212 |
|
* sequenced file naming. |
213 |
|
*/ |
214 |
|
{ |
208 |
– |
extern char *rindex(), *strncpy(), *strcat(), *strcpy(); |
215 |
|
char fbuf[128], fbuf2[128]; |
216 |
|
int npicts; |
217 |
|
register char *cp; |
288 |
|
"cannot open output file \"%s\"", fbuf); |
289 |
|
error(SYSTEM, errmsg); |
290 |
|
} |
291 |
< |
#ifdef MSDOS |
286 |
< |
setmode(fileno(stdout), O_BINARY); |
287 |
< |
#endif |
291 |
> |
SET_FILE_BINARY(stdout); |
292 |
|
dupheader(); |
293 |
|
} |
294 |
|
hres = hresolu; vres = vresolu; pa = pixaspect; |
295 |
|
if (prvr != NULL) |
296 |
|
if (viewfile(prvr, &ourview, &rs) <= 0 |
297 |
< |
|| rs.or != PIXSTANDARD) { |
297 |
> |
|| rs.rt != PIXSTANDARD) { |
298 |
|
sprintf(errmsg, |
299 |
|
"cannot recover view parameters from \"%s\"", prvr); |
300 |
|
error(WARNING, errmsg); |
352 |
|
render(zfile, oldfile) /* render the scene */ |
353 |
|
char *zfile, *oldfile; |
354 |
|
{ |
351 |
– |
extern long lseek(); |
355 |
|
COLOR *scanbar[MAXDIV+1]; /* scanline arrays of pixel values */ |
356 |
|
float *zbar[MAXDIV+1]; /* z values */ |
357 |
|
char *sampdens; /* previous sample density */ |
362 |
|
COLOR *colptr; |
363 |
|
float *zptr; |
364 |
|
register int i; |
365 |
+ |
/* check for empty image */ |
366 |
+ |
if (hres <= 0 || vres <= 0) { |
367 |
+ |
error(WARNING, "empty output picture"); |
368 |
+ |
fprtresolu(0, 0, stdout); |
369 |
+ |
return; |
370 |
+ |
} |
371 |
|
/* allocate scanlines */ |
372 |
|
for (i = 0; i <= psample; i++) { |
373 |
|
scanbar[i] = (COLOR *)malloc(hres*sizeof(COLOR)); |
378 |
|
ystep = (psample*99+70)/140; |
379 |
|
if (hstep > 2) { |
380 |
|
i = hres/hstep + 2; |
381 |
< |
if ((sampdens = malloc(i)) == NULL) |
381 |
> |
if ((sampdens = (char *)malloc(i)) == NULL) |
382 |
|
goto memerr; |
383 |
|
while (i--) |
384 |
|
sampdens[i] = hstep; |
390 |
|
sprintf(errmsg, "cannot open z-file \"%s\"", zfile); |
391 |
|
error(SYSTEM, errmsg); |
392 |
|
} |
393 |
< |
#ifdef MSDOS |
385 |
< |
setmode(zfd, O_BINARY); |
386 |
< |
#endif |
393 |
> |
SET_FD_BINARY(zfd); |
394 |
|
for (i = 0; i <= psample; i++) { |
395 |
|
zbar[i] = (float *)malloc(hres*sizeof(float)); |
396 |
|
if (zbar[i] == NULL) |
408 |
|
if (i >= vres) |
409 |
|
goto alldone; |
410 |
|
if (zfd != -1 && i > 0 && |
411 |
< |
lseek(zfd, (long)i*hres*sizeof(float), 0) == -1) |
411 |
> |
lseek(zfd, (off_t)i*hres*sizeof(float), 0) < 0) |
412 |
|
error(SYSTEM, "z-file seek error in render"); |
413 |
|
pctdone = 100.0*i/vres; |
414 |
|
if (ralrm > 0) /* report init stats */ |
477 |
|
if (close(zfd) == -1) |
478 |
|
goto writerr; |
479 |
|
for (i = 0; i <= psample; i++) |
480 |
< |
free((char *)zbar[i]); |
480 |
> |
free((void *)zbar[i]); |
481 |
|
} |
482 |
|
for (i = 0; i <= psample; i++) |
483 |
< |
free((char *)scanbar[i]); |
483 |
> |
free((void *)scanbar[i]); |
484 |
|
if (sampdens != NULL) |
485 |
|
free(sampdens); |
486 |
|
pctdone = 100.0; |
672 |
|
error(WARNING, errmsg); |
673 |
|
goto gotzip; |
674 |
|
} |
675 |
< |
#ifdef MSDOS |
669 |
< |
setmode(fileno(fp), O_BINARY); |
670 |
< |
#endif |
675 |
> |
SET_FILE_BINARY(fp); |
676 |
|
/* discard header */ |
677 |
|
getheader(fp, NULL, NULL); |
678 |
|
/* get picture size */ |
701 |
|
} |
702 |
|
if (fflush(stdout) == EOF) |
703 |
|
goto writerr; |
704 |
< |
free((char *)scanline); |
704 |
> |
free((void *)scanline); |
705 |
|
fclose(fp); |
706 |
|
unlink(oldfile); |
707 |
|
return(y); |