ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rtmain.c
(Generate patch)

Comparing ray/src/rt/rtmain.c (file contents):
Revision 2.8 by schorsch, Tue Oct 21 19:19:28 2003 UTC vs.
Revision 2.46 by greg, Tue Aug 15 01:19:37 2023 UTC

# Line 7 | Line 7 | static const char      RCSid[] = "$Id$";
7  
8   #include "copyright.h"
9  
10 #include  <sys/types.h>
10   #include  <signal.h>
11  
12   #include  "platform.h"
13   #include  "rtprocess.h" /* getpid() */
14 + #include  "resolu.h"
15   #include  "ray.h"
16   #include  "source.h"
17   #include  "ambient.h"
18   #include  "random.h"
19   #include  "paths.h"
20 + #include  "pmapray.h"
21  
22 + extern char     *progname;              /* global argv[0] */
23 +
24 + extern char     *shm_boundary;          /* boundary of shared memory */
25 +
26                                          /* persistent processes define */
27   #ifdef  F_SETLKW
28   #define  PERSIST        1               /* normal persist */
# Line 25 | Line 30 | static const char      RCSid[] = "$Id$";
30   #define  PCHILD         3               /* child of normal persist */
31   #endif
32  
33 < char  *progname;                        /* argv[0] */
33 > char  *sigerr[NSIG];                    /* signal error messages */
34 > char  *errfile = NULL;                  /* error output file */
35  
36 < char  *octname;                         /* octree name */
36 > int  nproc = 1;                         /* number of processes */
37  
38 < char  *sigerr[NSIG];                    /* signal error messages */
38 > extern int  setrtoutput(void);          /* set output values */
39  
40 < char  *shm_boundary = NULL;             /* boundary of shared memory */
40 > int  inform = 'a';                      /* input format */
41 > int  outform = 'a';                     /* output format */
42 > char  *outvals = "v";                   /* output specification */
43  
44 < char  *errfile = NULL;                  /* error output file */
44 > int  hresolu = 0;                       /* horizontal (scan) size */
45 > int  vresolu = 0;                       /* vertical resolution */
46  
47 < extern char  *formstr();                /* string from format */
39 < extern int  inform;                     /* input format */
40 < extern int  outform;                    /* output format */
41 < extern char  *outvals;                  /* output values */
47 > extern int  castonly;                   /* only doing ray-casting? */
48  
49 < extern int  hresolu;                    /* horizontal resolution */
50 < extern int  vresolu;                    /* vertical resolution */
49 > int  imm_irrad = 0;                     /* compute immediate irradiance? */
50 > int  lim_dist = 0;                      /* limit distance? */
51  
52 < extern int  imm_irrad;                  /* compute immediate irradiance? */
53 < extern int  lim_dist;                   /* limit distance? */
52 > #ifndef MAXMODLIST
53 > #define MAXMODLIST      1024            /* maximum modifiers we'll track */
54 > #endif
55  
56 < extern char  *tralist[];                /* list of modifers to trace (or no) */
57 < extern int  traincl;                    /* include == 1, exclude == 0 */
56 > extern void  (*addobjnotify[])();       /* object notification calls */
57 > extern void  tranotify(OBJECT obj);
58  
59 < void    onsig(int);
60 < void    sigdie(int, char*);
54 < void    printdefaults(void);
59 > char  *tralist[MAXMODLIST];             /* list of modifers to trace (or no) */
60 > int  traincl = -1;                      /* include == 1, exclude == 0 */
61  
62 + static int  loadflags = ~IO_FILES;      /* what to load from octree */
63  
64 + static void onsig(int  signo);
65 + static void sigdie(int  signo, char  *msg);
66 + static void printdefaults(void);
67 +
68 + #ifdef PERSIST
69 + #define RTRACE_FEATURES "Persist\nParallelPersist\nMultiprocessing\n" \
70 +                        "IrradianceCalc\nImmediateIrradiance\nDistanceLimiting\n" \
71 +                        "ParticipatingMedia=Mist\n" \
72 +                        "HessianAmbientCache\nAmbientAveraging\n" \
73 +                        "AmbientValueSharing\nAdaptiveShadowTesting\n" \
74 +                        "InputFormats=a,f,d\nOutputFormats=a,f,d,c\n" \
75 +                        "Outputs=o,d,v,V,w,W,l,L,c,p,n,N,s,m,M,r,x,R,X,~\n"
76 + #else
77 + #define RTRACE_FEATURES "IrradianceCalc\nIrradianceCalc\nDistanceLimiting\n" \
78 +                        "ParticipatingMedia=Mist\n" \
79 +                        "HessianAmbientCache\nAmbientAveraging\n" \
80 +                        "AmbientValueSharing\nAdaptiveShadowTesting\n" \
81 +                        "InputFormats=a,f,d\nOutputFormats=a,f,d,c\n" \
82 +                        "Outputs=o,d,v,V,w,W,l,L,c,p,n,N,s,m,M,r,x,R,X,~\n"
83 + #endif
84 +
85 +
86   int
87 < main(argc, argv)
59 < int  argc;
60 < char  *argv[];
87 > main(int  argc, char  *argv[])
88   {
89   #define  check(ol,al)           if (argv[i][ol] || \
90                                  badarg(argc-i-1,argv+i+1,al)) \
91                                  goto badopt
92 < #define  bool(olen,var)         switch (argv[i][olen]) { \
92 > #define  check_bool(olen,var)           switch (argv[i][olen]) { \
93                                  case '\0': var = !var; break; \
94                                  case 'y': case 'Y': case 't': case 'T': \
95                                  case '+': case '1': var = 1; break; \
96                                  case 'n': case 'N': case 'f': case 'F': \
97                                  case '-': case '0': var = 0; break; \
98                                  default: goto badopt; }
99 <        int  loadflags = ~IO_FILES;
99 >        extern char  *octname;
100          int  persist = 0;
101 <        char  **tralp;
102 <        int  duped1;
101 >        char  *octnm = NULL;
102 >        char  **tralp = NULL;
103 >        int  duped1 = -1;
104          int  rval;
105          int  i;
106                                          /* global program name */
107          progname = argv[0] = fixargv0(argv[0]);
108 +                                        /* feature check only? */
109 +        strcat(RFeatureList, RTRACE_FEATURES);
110 +        if (argc > 1 && !strcmp(argv[1], "-features"))
111 +                return feature_status(argc-2, argv+2);
112 +                                        /* add trace notify function */
113 +        for (i = 0; addobjnotify[i] != NULL; i++)
114 +                ;
115 +        addobjnotify[i] = tranotify;
116                                          /* option city */
117          for (i = 1; i < argc; i++) {
118                                                  /* expand arguments */
# Line 103 | Line 139 | char  *argv[];
139                          continue;
140                  }
141                  switch (argv[i][1]) {
142 +                case 'n':                               /* number of cores */
143 +                        check(2,"i");
144 +                        nproc = atoi(argv[++i]);
145 +                        if (nproc <= 0)
146 +                                error(USER, "bad number of processes");
147 +                        break;
148                  case 'x':                               /* x resolution */
149                          check(2,"i");
150                          hresolu = atoi(argv[++i]);
# Line 113 | Line 155 | char  *argv[];
155                          break;
156                  case 'w':                               /* warnings */
157                          rval = erract[WARNING].pf != NULL;
158 <                        bool(2,rval);
158 >                        check_bool(2,rval);
159                          if (rval) erract[WARNING].pf = wputs;
160                          else erract[WARNING].pf = NULL;
161                          break;
# Line 124 | Line 166 | char  *argv[];
166                  case 'l':                               /* limit distance */
167                          if (argv[i][2] != 'd')
168                                  goto badopt;
169 <                        bool(3,lim_dist);
169 >                        check_bool(3,lim_dist);
170                          break;
171                  case 'I':                               /* immed. irradiance */
172 <                        bool(2,imm_irrad);
172 >                        check_bool(2,imm_irrad);
173                          break;
174                  case 'f':                               /* format i/o */
175                          switch (argv[i][2]) {
# Line 159 | Line 201 | char  *argv[];
201                          break;
202                  case 'h':                               /* header output */
203                          rval = loadflags & IO_INFO;
204 <                        bool(2,rval);
204 >                        check_bool(2,rval);
205                          loadflags = rval ? loadflags | IO_INFO :
206                                          loadflags & ~IO_INFO;
207                          break;
# Line 173 | Line 215 | char  *argv[];
215                                          tralp = tralist;
216                                  }
217                                  if (argv[i][2] == 'I') {        /* file */
218 <                                        rval = wordfile(tralp,
218 >                                        rval = wordfile(tralp, MAXMODLIST-(tralp-tralist),
219                                          getpath(argv[++i],getrlibpath(),R_OK));
220                                          if (rval < 0) {
221                                                  sprintf(errmsg,
# Line 195 | Line 237 | char  *argv[];
237                                          tralp = tralist;
238                                  }
239                                  if (argv[i][2] == 'E') {        /* file */
240 <                                        rval = wordfile(tralp,
240 >                                        rval = wordfile(tralp, MAXMODLIST-(tralp-tralist),
241                                          getpath(argv[++i],getrlibpath(),R_OK));
242                                          if (rval < 0) {
243                                                  sprintf(errmsg,
# Line 229 | Line 271 | char  *argv[];
271                          goto badopt;
272                  }
273          }
274 +        if (nproc > 1 && persist)
275 +                error(USER, "multiprocessing incompatible with persist file");
276                                          /* initialize object types */
277          initotypes();
278                                          /* initialize urand */
279 <        initurand(2048);
279 >        if (rand_samp) {
280 >                srandom((long)time(0));
281 >                initurand(0);
282 >        } else {
283 >                srandom(0L);
284 >                initurand(2048);
285 >        }
286                                          /* set up signal handling */
287          sigdie(SIGINT, "Interrupt");
288   #ifdef SIGHUP
# Line 264 | Line 314 | char  *argv[];
314   #endif
315                                          /* get octree */
316          if (i == argc)
317 <                octname = NULL;
317 >                octnm = NULL;
318          else if (i == argc-1)
319 <                octname = argv[i];
319 >                octnm = argv[i];
320          else
321                  goto badopt;
322 <        if (octname == NULL)
322 >        if (octnm == NULL)
323                  error(USER, "missing octree argument");
324                                          /* set up output */
325   #ifdef  PERSIST
# Line 278 | Line 328 | char  *argv[];
328                  openheader();
329          }
330   #endif
281 #ifdef  _WIN32
331          if (outform != 'a')
332                  SET_FILE_BINARY(stdout);
333 <        if (octname == NULL)
334 <                SET_FILE_BINARY(stdin);
286 < #endif
333 >        rval = setrtoutput();
334 >        octname = savqstr(octnm);
335          readoct(octname, loadflags, &thescene, NULL);
336          nsceneobjs = nobjects;
337  
# Line 291 | Line 339 | char  *argv[];
339                  printargs(i, argv, stdout);
340                  printf("SOFTWARE= %s\n", VersionID);
341                  fputnow(stdout);
342 +                if (rval > 0)           /* saved from setrtoutput() call */
343 +                        printf("NCOMP=%d\n", rval);
344 +                if ((outform == 'f') | (outform == 'd'))
345 +                        fputendian(stdout);
346                  fputformat(formstr(outform), stdout);
347                  putchar('\n');
348          }
349  
350 <        marksources();                  /* find and mark sources */
350 >        if (!castonly) {        /* any actual ray traversal to do? */
351  
352 <        setambient();                   /* initialize ambient calculation */
352 >                ray_init_pmap();        /* PMAP: set up & load photon maps */
353 >                
354 >                marksources();          /* find and mark sources */
355  
356 +                setambient();           /* initialize ambient calculation */
357 +        } else
358 +                distantsources();       /* else mark only distant sources */
359 +
360 +        fflush(stdout);                 /* in case we're duplicating header */
361 +
362   #ifdef  PERSIST
363          if (persist) {
304                fflush(stdout);
364                                                  /* reconnect stdout */
365                  dup2(duped1, fileno(stdout));
366                  close(duped1);
# Line 312 | Line 371 | char  *argv[];
371                          while ((rval=fork()) == 0) {    /* keep on forkin' */
372                                  pflock(1);
373                                  pfhold();
374 +                                ambsync();              /* load new values */
375                          }
376                          if (rval < 0)
377                                  error(SYSTEM, "cannot fork child for persist function");
378 <                        pfdetach();             /* parent exits */
378 >                        pfdetach();             /* parent will run then exit */
379                  }
380          }
381   runagain:
# Line 323 | Line 383 | runagain:
383                  dupheader();                    /* send header to stdout */
384   #endif
385                                          /* trace rays */
386 <        rtrace(NULL);
386 >        rtrace(NULL, nproc);
387                                          /* flush ambient file */
388          ambsync();
389   #ifdef  PERSIST
# Line 338 | Line 398 | runagain:
398                  }
399          }
400          if (persist == PCHILD) {        /* wait for a signal then go again */
341                close(duped1);                  /* release output handle */
401                  pfhold();
402                  raynum = nrays = 0;             /* reinitialize */
403                  goto runagain;
404          }
405   #endif
406 +
407 +        ray_done_pmap();           /* PMAP: free photon maps */
408 +        
409          quit(0);
410  
411   badopt:
412          sprintf(errmsg, "command line error at '%s'", argv[i]);
413          error(USER, errmsg);
414 +        return 1; /* pro forma return */
415  
416   #undef  check
417 < #undef  bool
417 > #undef  check_bool
418   }
419  
420  
421   void
422 < wputs(s)                                /* warning output function */
423 < char    *s;
422 > wputs(                          /* warning output function */
423 >        const char      *s
424 > )
425   {
426          int  lasterrno = errno;
427          eputs(s);
# Line 366 | Line 430 | char   *s;
430  
431  
432   void
433 < eputs(s)                                /* put string to stderr */
434 < register char  *s;
433 > eputs(                          /* put string to stderr */
434 >        const char  *s
435 > )
436   {
437          static int  midline = 0;
438  
# Line 385 | Line 450 | register char  *s;
450   }
451  
452  
453 < void
454 < onsig(signo)                            /* fatal signal */
455 < int  signo;
453 > static void
454 > onsig(                          /* fatal signal */
455 >        int  signo
456 > )
457   {
458          static int  gotsig = 0;
459  
# Line 405 | Line 471 | int  signo;
471   }
472  
473  
474 < void
475 < sigdie(signo, msg)                      /* set fatal signal */
476 < int  signo;
477 < char  *msg;
474 > static void
475 > sigdie(                 /* set fatal signal */
476 >        int  signo,
477 >        char  *msg
478 > )
479   {
480          if (signal(signo, onsig) == SIG_IGN)
481                  signal(signo, SIG_IGN);
# Line 416 | Line 483 | char  *msg;
483   }
484  
485  
486 < void
486 > static void
487   printdefaults(void)                     /* print default values to stdout */
488   {
489 <        register char  *cp;
489 >        char  *cp;
490  
491          if (imm_irrad)
492                  printf("-I+\t\t\t\t# immediate irradiance on\n");
493 <        printf("-x  %-9d\t\t\t# x resolution\n", hresolu);
494 <        printf("-y  %-9d\t\t\t# y resolution\n", vresolu);
493 >        printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc);
494 >        printf("-x %-9d\t\t\t# %s\n", hresolu,
495 >                        vresolu && hresolu ? "x resolution" : "flush interval");
496 >        printf("-y %-9d\t\t\t# y resolution\n", vresolu);
497          printf(lim_dist ? "-ld+\t\t\t\t# limit distance on\n" :
498                          "-ld-\t\t\t\t# limit distance off\n");
499 +        printf("-h%c\t\t\t\t# %s header\n", loadflags & IO_INFO ? '+' : '-',
500 +                        loadflags & IO_INFO ? "output" : "no");
501          printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n",
502                          inform, outform, formstr(inform), formstr(outform));
503 <        printf("-o%s\t\t\t\t# output", outvals);
503 >        printf("-o%-9s\t\t\t# output", outvals);
504          for (cp = outvals; *cp; cp++)
505                  switch (*cp) {
506 <                case 't': printf(" trace"); break;
506 >                case 't': case 'T': printf(" trace"); break;
507                  case 'o': printf(" origin"); break;
508                  case 'd': printf(" direction"); break;
509 +                case 'r': printf(" reflect_contrib"); break;
510 +                case 'R': printf(" reflect_length"); break;
511 +                case 'x': printf(" unreflect_contrib"); break;
512 +                case 'X': printf(" unreflect_length"); break;
513                  case 'v': printf(" value"); break;
514 +                case 'V': printf(" contribution"); break;
515                  case 'l': printf(" length"); break;
516                  case 'L': printf(" first_length"); break;
517                  case 'p': printf(" point"); break;
# Line 443 | Line 519 | printdefaults(void)                    /* print default values to stdou
519                  case 'N': printf(" unperturbed_normal"); break;
520                  case 's': printf(" surface"); break;
521                  case 'w': printf(" weight"); break;
522 +                case 'W': printf(" coefficient"); break;
523                  case 'm': printf(" modifier"); break;
524 +                case 'M': printf(" material"); break;
525 +                case '~': printf(" tilde"); break;
526                  }
527          putchar('\n');
528          printf(erract[WARNING].pf != NULL ?

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines