ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rvmain.c
Revision: 2.25
Committed: Sat Jun 7 05:09:46 2025 UTC (13 hours ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 2.24: +1 -2 lines
Log Message:
refactor: Put some declarations into "paths.h" and included in "platform.h"

File Contents

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