ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rvmain.c
Revision: 2.23
Committed: Tue Apr 22 17:12:25 2025 UTC (9 days, 20 hours ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.22: +23 -14 lines
Log Message:
feat(rpict,rtrace,rvu,rxpict,rxtrace,rxpiece): Added -e expr and -f file.cal options

File Contents

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