ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rvmain.c
Revision: 2.20
Committed: Wed Jan 17 01:31:08 2024 UTC (4 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.19: +6 -1 lines
Log Message:
fix(rpict,rvu,rcontrib): Fixed luminance estimate during spectral rendering

File Contents

# User Rev Content
1 greg 2.1 #ifndef lint
2 greg 2.20 static const char RCSid[] = "$Id: rvmain.c,v 2.19 2023/02/06 22:40:21 greg Exp $";
3 greg 2.1 #endif
4     /*
5     * rvmain.c - main for rview interactive viewer
6     */
7    
8 greg 2.2 #include "copyright.h"
9 greg 2.1
10 schorsch 2.3 #include <signal.h>
11 greg 2.5 #include <time.h>
12 schorsch 2.3
13     #include "platform.h"
14 greg 2.1 #include "ray.h"
15     #include "source.h"
16     #include "ambient.h"
17 schorsch 2.4 #include "rpaint.h"
18 greg 2.1 #include "random.h"
19     #include "paths.h"
20     #include "view.h"
21 greg 2.12 #include "pmapray.h"
22 greg 2.1
23 greg 2.9 extern char *progname; /* global argv[0] */
24 greg 2.1
25 greg 2.9 VIEW ourview = STDVIEW; /* viewing parameters */
26     int hresolu, vresolu; /* image resolution */
27 greg 2.1
28 greg 2.9 int psample = 8; /* pixel sample size */
29     double maxdiff = .15; /* max. sample difference */
30    
31     int greyscale = 0; /* map colors to brightness? */
32     char *dvcname = dev_default; /* output device name */
33    
34     double exposure = 1.0; /* exposure for scene */
35 greg 2.1
36 greg 2.9 int newparam = 1; /* parameter setting changed */
37    
38     struct driver *dev = NULL; /* driver functions */
39 greg 2.1
40 greg 2.9 char rifname[128]; /* rad input file name */
41 greg 2.1
42 greg 2.9 VIEW oldview; /* previous view parameters */
43 greg 2.1
44 greg 2.9 PNODE ptrunk; /* the base of our image */
45     RECT pframe; /* current frame boundaries */
46     int pdepth; /* image depth in current frame */
47 greg 2.1
48 greg 2.9 char *errfile = NULL; /* error output file */
49 greg 2.1
50 greg 2.9 int nproc = 1; /* number of processes */
51 greg 2.1
52 greg 2.9 char *sigerr[NSIG]; /* signal error messages */
53 greg 2.1
54 schorsch 2.4 static void onsig(int signo);
55     static void sigdie(int signo, char *msg);
56     static void printdefaults(void);
57 greg 2.1
58 greg 2.17 int
59 greg 2.9 main(int argc, char *argv[])
60 greg 2.1 {
61     #define check(ol,al) if (argv[i][ol] || \
62     badarg(argc-i-1,argv+i+1,al)) \
63     goto badopt
64 schorsch 2.15 #define check_bool(olen,var) switch (argv[i][olen]) { \
65 greg 2.1 case '\0': var = !var; break; \
66     case 'y': case 'Y': case 't': case 'T': \
67     case '+': case '1': var = 1; break; \
68     case 'n': case 'N': case 'f': case 'F': \
69     case '-': case '0': var = 0; break; \
70     default: goto badopt; }
71 greg 2.9 char *octnm = NULL;
72 greg 2.1 char *err;
73     int rval;
74     int i;
75     /* global program name */
76     progname = argv[0] = fixargv0(argv[0]);
77 greg 2.9 /* set our defaults */
78     shadthresh = .1;
79     shadcert = .25;
80     directrelay = 0;
81     vspretest = 128;
82     srcsizerat = 0.;
83     specthresh = .3;
84     specjitter = 1.;
85     maxdepth = 6;
86 greg 2.18 minweight = 1e-3;
87 greg 2.9 ambacc = 0.3;
88     ambres = 32;
89     ambdiv = 256;
90     ambssamp = 64;
91 greg 2.1 /* option city */
92     for (i = 1; i < argc; i++) {
93     /* expand arguments */
94     while ((rval = expandarg(&argc, &argv, i)) > 0)
95     ;
96     if (rval < 0) {
97     sprintf(errmsg, "cannot expand '%s'", argv[i]);
98     error(SYSTEM, errmsg);
99     }
100     if (argv[i] == NULL || argv[i][0] != '-')
101     break; /* break from options */
102     if (!strcmp(argv[i], "-version")) {
103     puts(VersionID);
104     quit(0);
105     }
106     if (!strcmp(argv[i], "-defaults") ||
107     !strcmp(argv[i], "-help")) {
108     printdefaults();
109     quit(0);
110     }
111     if (!strcmp(argv[i], "-devices")) {
112     printdevices();
113     quit(0);
114     }
115     rval = getrenderopt(argc-i, argv+i);
116     if (rval >= 0) {
117     i += rval;
118     continue;
119     }
120     rval = getviewopt(&ourview, argc-i, argv+i);
121     if (rval >= 0) {
122     i += rval;
123     continue;
124     }
125     switch (argv[i][1]) {
126 greg 2.9 case 'n': /* # processes */
127     check(2,"i");
128     nproc = atoi(argv[++i]);
129     if (nproc <= 0)
130     error(USER, "bad number of processes");
131     break;
132 greg 2.1 case 'v': /* view file */
133     if (argv[i][2] != 'f')
134     goto badopt;
135     check(3,"s");
136     rval = viewfile(argv[++i], &ourview, NULL);
137     if (rval < 0) {
138     sprintf(errmsg,
139     "cannot open view file \"%s\"",
140     argv[i]);
141     error(SYSTEM, errmsg);
142     } else if (rval == 0) {
143     sprintf(errmsg,
144     "bad view file \"%s\"",
145     argv[i]);
146     error(USER, errmsg);
147     }
148     break;
149     case 'b': /* grayscale */
150 schorsch 2.15 check_bool(2,greyscale);
151 greg 2.1 break;
152     case 'p': /* pixel */
153     switch (argv[i][2]) {
154     case 's': /* sample */
155     check(3,"i");
156     psample = atoi(argv[++i]);
157     break;
158     case 't': /* threshold */
159     check(3,"f");
160     maxdiff = atof(argv[++i]);
161     break;
162     case 'e': /* exposure */
163     check(3,"f");
164     exposure = atof(argv[++i]);
165     if (argv[i][0] == '+' || argv[i][0] == '-')
166     exposure = pow(2.0, exposure);
167     break;
168     default:
169     goto badopt;
170     }
171     break;
172     case 'w': /* warnings */
173     rval = erract[WARNING].pf != NULL;
174 schorsch 2.15 check_bool(2,rval);
175 greg 2.1 if (rval) erract[WARNING].pf = wputs;
176     else erract[WARNING].pf = NULL;
177     break;
178     case 'e': /* error file */
179     check(2,"s");
180     errfile = argv[++i];
181     break;
182     case 'o': /* output device */
183     check(2,"s");
184     dvcname = argv[++i];
185     break;
186     case 'R': /* render input file */
187     check(2,"s");
188     strcpy(rifname, argv[++i]);
189     break;
190     default:
191     goto badopt;
192     }
193     }
194 greg 2.20 /* set/check spectral sampling */
195     rval = setspectrsamp(CNDX, WLPART);
196     if (rval < 0)
197     error(USER, "unsupported spectral sampling");
198    
199 greg 2.1 err = setview(&ourview); /* set viewing parameters */
200     if (err != NULL)
201     error(USER, err);
202 greg 2.9 /* set up signal handling */
203 greg 2.1 sigdie(SIGINT, "Interrupt");
204 greg 2.11 sigdie(SIGTERM, "Terminate");
205 schorsch 2.14 #if !defined(_WIN32) && !defined(_WIN64)
206 greg 2.1 sigdie(SIGHUP, "Hangup");
207     sigdie(SIGPIPE, "Broken pipe");
208     sigdie(SIGALRM, "Alarm clock");
209 greg 2.11 #endif
210 greg 2.1 /* open error file */
211     if (errfile != NULL) {
212     if (freopen(errfile, "a", stderr) == NULL)
213     quit(2);
214     fprintf(stderr, "**************\n*** PID %5d: ",
215     getpid());
216     printargs(argc, argv, stderr);
217     putc('\n', stderr);
218     fflush(stderr);
219     }
220     #ifdef NICE
221     nice(NICE); /* lower priority */
222     #endif
223     /* get octree */
224     if (i == argc)
225 greg 2.9 octnm = NULL;
226 greg 2.1 else if (i == argc-1)
227 greg 2.9 octnm = argv[i];
228 greg 2.1 else
229     goto badopt;
230 greg 2.9 if (octnm == NULL)
231 greg 2.1 error(USER, "missing octree argument");
232 greg 2.9 /* set up output & start process(es) */
233 schorsch 2.3 SET_FILE_BINARY(stdout);
234 greg 2.9
235 greg 2.13 ray_init(octnm); /* also calls ray_init_pmap() */
236 greg 2.12
237 schorsch 2.16 /* temporary shortcut, until winrview is refactored into a "device" */
238     #ifndef WIN_RVIEW
239 greg 2.1 rview(); /* run interactive viewer */
240    
241 schorsch 2.16
242 greg 2.9 devclose(); /* close output device */
243 schorsch 2.16 #endif
244 greg 2.1
245 greg 2.12 /* PMAP: free photon maps */
246     ray_done_pmap();
247    
248 schorsch 2.16 #ifdef WIN_RVIEW
249     return 1;
250     #endif
251 greg 2.1 quit(0);
252    
253     badopt:
254     sprintf(errmsg, "command line error at '%s'", argv[i]);
255     error(USER, errmsg);
256 schorsch 2.4 return 1; /* pro forma return */
257 greg 2.1
258     #undef check
259 schorsch 2.15 #undef check_bool
260 greg 2.1 }
261    
262    
263     void
264 schorsch 2.4 wputs( /* warning output function */
265 greg 2.19 const char *s
266 schorsch 2.4 )
267 greg 2.1 {
268     int lasterrno = errno;
269     eputs(s);
270     errno = lasterrno;
271     }
272    
273    
274     void
275 schorsch 2.4 eputs( /* put string to stderr */
276 greg 2.19 const char *s
277 schorsch 2.4 )
278 greg 2.1 {
279     static int midline = 0;
280    
281     if (!*s)
282     return;
283     if (!midline++) {
284     fputs(progname, stderr);
285     fputs(": ", stderr);
286     }
287     fputs(s, stderr);
288     if (s[strlen(s)-1] == '\n') {
289     fflush(stderr);
290     midline = 0;
291     }
292     }
293    
294    
295 schorsch 2.4 static void
296     onsig( /* fatal signal */
297     int signo
298     )
299 greg 2.1 {
300     static int gotsig = 0;
301    
302     if (gotsig++) /* two signals and we're gone! */
303     _exit(signo);
304    
305 schorsch 2.14 #if !defined(_WIN32) && !defined(_WIN64)
306 greg 2.1 alarm(15); /* allow 15 seconds to clean up */
307     signal(SIGALRM, SIG_DFL); /* make certain we do die */
308 greg 2.11 #endif
309 greg 2.1 eputs("signal - ");
310     eputs(sigerr[signo]);
311     eputs("\n");
312 greg 2.9 devclose();
313 greg 2.1 quit(3);
314     }
315    
316    
317 schorsch 2.4 static void
318     sigdie( /* set fatal signal */
319     int signo,
320     char *msg
321     )
322 greg 2.1 {
323     if (signal(signo, onsig) == SIG_IGN)
324     signal(signo, SIG_IGN);
325     sigerr[signo] = msg;
326     }
327    
328    
329 schorsch 2.4 static void
330     printdefaults(void) /* print default values to stdout */
331 greg 2.1 {
332 greg 2.9 printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc);
333 greg 2.1 printf(greyscale ? "-b+\t\t\t\t# greyscale on\n" :
334     "-b-\t\t\t\t# greyscale off\n");
335     printf("-vt%c\t\t\t\t# view type %s\n", ourview.type,
336     ourview.type==VT_PER ? "perspective" :
337     ourview.type==VT_PAR ? "parallel" :
338     ourview.type==VT_HEM ? "hemispherical" :
339     ourview.type==VT_ANG ? "angular" :
340     ourview.type==VT_CYL ? "cylindrical" :
341 greg 2.8 ourview.type==VT_PLS ? "planisphere" :
342 greg 2.1 "unknown");
343     printf("-vp %f %f %f\t# view point\n",
344     ourview.vp[0], ourview.vp[1], ourview.vp[2]);
345     printf("-vd %f %f %f\t# view direction\n",
346     ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]);
347     printf("-vu %f %f %f\t# view up\n",
348     ourview.vup[0], ourview.vup[1], ourview.vup[2]);
349     printf("-vh %f\t\t\t# view horizontal size\n", ourview.horiz);
350     printf("-vv %f\t\t\t# view vertical size\n", ourview.vert);
351     printf("-vo %f\t\t\t# view fore clipping plane\n", ourview.vfore);
352     printf("-va %f\t\t\t# view aft clipping plane\n", ourview.vaft);
353     printf("-vs %f\t\t\t# view shift\n", ourview.hoff);
354     printf("-vl %f\t\t\t# view lift\n", ourview.voff);
355     printf("-pe %f\t\t\t# pixel exposure\n", exposure);
356     printf("-ps %-9d\t\t\t# pixel sample\n", psample);
357     printf("-pt %f\t\t\t# pixel threshold\n", maxdiff);
358     printf("-o %s\t\t\t\t# output device\n", dvcname);
359     printf(erract[WARNING].pf != NULL ?
360     "-w+\t\t\t\t# warning messages on\n" :
361     "-w-\t\t\t\t# warning messages off\n");
362     print_rdefaults();
363     }