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, 11 hours 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

# User Rev Content
1 greg 2.1 #ifndef lint
2 greg 2.24 static const char RCSid[] = "$Id: rvmain.c,v 2.23 2025/04/22 17:12:25 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.23 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 greg 2.17 int
77 greg 2.9 main(int argc, char *argv[])
78 greg 2.1 {
79     #define check(ol,al) if (argv[i][ol] || \
80     badarg(argc-i-1,argv+i+1,al)) \
81     goto badopt
82 schorsch 2.15 #define check_bool(olen,var) switch (argv[i][olen]) { \
83 greg 2.1 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 greg 2.9 char *octnm = NULL;
90 greg 2.1 char *err;
91     int rval;
92     int i;
93     /* global program name */
94     progname = argv[0] = fixargv0(argv[0]);
95 greg 2.9 /* set our defaults */
96 greg 2.23 set_defaults();
97 greg 2.1 /* 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 greg 2.9 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 greg 2.1 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 schorsch 2.15 check_bool(2,greyscale);
157 greg 2.1 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 schorsch 2.15 check_bool(2,rval);
181 greg 2.1 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 greg 2.20 /* set/check spectral sampling */
201 greg 2.21 if (setspectrsamp(CNDX, WLPART) <= 0)
202 greg 2.20 error(USER, "unsupported spectral sampling");
203    
204 greg 2.1 err = setview(&ourview); /* set viewing parameters */
205     if (err != NULL)
206     error(USER, err);
207 greg 2.9 /* set up signal handling */
208 greg 2.1 sigdie(SIGINT, "Interrupt");
209 greg 2.11 sigdie(SIGTERM, "Terminate");
210 schorsch 2.14 #if !defined(_WIN32) && !defined(_WIN64)
211 greg 2.1 sigdie(SIGHUP, "Hangup");
212     sigdie(SIGPIPE, "Broken pipe");
213     sigdie(SIGALRM, "Alarm clock");
214 greg 2.11 #endif
215 greg 2.1 /* 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 greg 2.9 octnm = NULL;
231 greg 2.1 else if (i == argc-1)
232 greg 2.9 octnm = argv[i];
233 greg 2.1 else
234     goto badopt;
235 greg 2.9 if (octnm == NULL)
236 greg 2.1 error(USER, "missing octree argument");
237 greg 2.9 /* set up output & start process(es) */
238 schorsch 2.3 SET_FILE_BINARY(stdout);
239 greg 2.9
240 greg 2.13 ray_init(octnm); /* also calls ray_init_pmap() */
241 greg 2.12
242 schorsch 2.16 /* temporary shortcut, until winrview is refactored into a "device" */
243     #ifndef WIN_RVIEW
244 greg 2.1 rview(); /* run interactive viewer */
245    
246 schorsch 2.16
247 greg 2.9 devclose(); /* close output device */
248 schorsch 2.16 #endif
249 greg 2.1
250 greg 2.12 /* PMAP: free photon maps */
251     ray_done_pmap();
252    
253 schorsch 2.16 #ifdef WIN_RVIEW
254     return 1;
255     #endif
256 greg 2.1 quit(0);
257    
258     badopt:
259     sprintf(errmsg, "command line error at '%s'", argv[i]);
260     error(USER, errmsg);
261 schorsch 2.4 return 1; /* pro forma return */
262 greg 2.1
263     #undef check
264 schorsch 2.15 #undef check_bool
265 greg 2.1 }
266    
267    
268     void
269 schorsch 2.4 wputs( /* warning output function */
270 greg 2.19 const char *s
271 schorsch 2.4 )
272 greg 2.1 {
273     int lasterrno = errno;
274 greg 2.22 if (erract[WARNING].pf == NULL)
275     return; /* called by calcomp or someone */
276 greg 2.1 eputs(s);
277     errno = lasterrno;
278     }
279    
280    
281     void
282 schorsch 2.4 eputs( /* put string to stderr */
283 greg 2.19 const char *s
284 schorsch 2.4 )
285 greg 2.1 {
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 schorsch 2.4 static void
303     onsig( /* fatal signal */
304     int signo
305     )
306 greg 2.1 {
307     static int gotsig = 0;
308    
309     if (gotsig++) /* two signals and we're gone! */
310     _exit(signo);
311    
312 schorsch 2.14 #if !defined(_WIN32) && !defined(_WIN64)
313 greg 2.1 alarm(15); /* allow 15 seconds to clean up */
314     signal(SIGALRM, SIG_DFL); /* make certain we do die */
315 greg 2.11 #endif
316 greg 2.1 eputs("signal - ");
317     eputs(sigerr[signo]);
318     eputs("\n");
319 greg 2.9 devclose();
320 greg 2.1 quit(3);
321     }
322    
323    
324 schorsch 2.4 static void
325     sigdie( /* set fatal signal */
326     int signo,
327     char *msg
328     )
329 greg 2.1 {
330     if (signal(signo, onsig) == SIG_IGN)
331     signal(signo, SIG_IGN);
332     sigerr[signo] = msg;
333     }
334    
335    
336 schorsch 2.4 static void
337     printdefaults(void) /* print default values to stdout */
338 greg 2.1 {
339 greg 2.9 printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc);
340 greg 2.1 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 greg 2.8 ourview.type==VT_PLS ? "planisphere" :
349 greg 2.1 "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     }