ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rvmain.c
Revision: 2.24
Committed: Wed Apr 23 02:35:26 2025 UTC (9 days, 1 hour ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 2.23: +1 -4 lines
Log Message:
fix: Added missing calls to initfunc()

File Contents

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