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.5 by schorsch, Thu Jun 26 00:58:10 2003 UTC vs.
Revision 2.23 by greg, Tue Feb 24 19:39:27 2015 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 24 | 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 char  *formstr();                /* string from format */
39 > int  inform = 'a';                      /* input format */
40 > int  outform = 'a';                     /* output format */
41 > char  *outvals = "v";                   /* output specification */
42  
43 < char  *shm_boundary = NULL;             /* boundary of shared memory */
43 > int  hresolu = 0;                       /* horizontal (scan) size */
44 > int  vresolu = 0;                       /* vertical resolution */
45  
46 < char  *errfile = NULL;                  /* error output file */
46 > int  imm_irrad = 0;                     /* compute immediate irradiance? */
47 > int  lim_dist = 0;                      /* limit distance? */
48  
49 < extern char  *formstr();                /* string from format */
50 < extern int  inform;                     /* input format */
51 < extern int  outform;                    /* output format */
40 < extern char  *outvals;                  /* output values */
49 > #ifndef MAXMODLIST
50 > #define MAXMODLIST      1024            /* maximum modifiers we'll track */
51 > #endif
52  
53 < extern int  hresolu;                    /* horizontal resolution */
54 < extern int  vresolu;                    /* vertical resolution */
53 > extern void  (*addobjnotify[])();       /* object notification calls */
54 > extern void  tranotify(OBJECT obj);
55  
56 < extern int  imm_irrad;                  /* compute immediate irradiance? */
57 < extern int  lim_dist;                   /* limit distance? */
56 > char  *tralist[MAXMODLIST];             /* list of modifers to trace (or no) */
57 > int  traincl = -1;                      /* include == 1, exclude == 0 */
58  
59 < extern char  *tralist[];                /* list of modifers to trace (or no) */
49 < extern int  traincl;                    /* include == 1, exclude == 0 */
59 > static int  loadflags = ~IO_FILES;      /* what to load from octree */
60  
61 < void    onsig();
62 < void    sigdie();
63 < void    printdefaults();
61 > static void onsig(int  signo);
62 > static void sigdie(int  signo, char  *msg);
63 > static void printdefaults(void);
64  
65  
66   int
67 < main(argc, argv)
58 < int  argc;
59 < char  *argv[];
67 > main(int  argc, char  *argv[])
68   {
69   #define  check(ol,al)           if (argv[i][ol] || \
70                                  badarg(argc-i-1,argv+i+1,al)) \
# Line 68 | Line 76 | char  *argv[];
76                                  case 'n': case 'N': case 'f': case 'F': \
77                                  case '-': case '0': var = 0; break; \
78                                  default: goto badopt; }
71        int  loadflags = ~IO_FILES;
79          int  persist = 0;
80 <        char  **tralp;
81 <        int  duped1;
80 >        char  *octnm = NULL;
81 >        char  **tralp = NULL;
82 >        int  duped1 = -1;
83          int  rval;
84          int  i;
85                                          /* global program name */
86          progname = argv[0] = fixargv0(argv[0]);
87 +                                        /* add trace notify function */
88 +        for (i = 0; addobjnotify[i] != NULL; i++)
89 +                ;
90 +        addobjnotify[i] = tranotify;
91 +                                        /* set our defaults */
92 +        rand_samp = 1;
93 +        maxdepth = -10;
94 +        minweight = 2e-3;
95                                          /* option city */
96          for (i = 1; i < argc; i++) {
97                                                  /* expand arguments */
# Line 102 | Line 118 | char  *argv[];
118                          continue;
119                  }
120                  switch (argv[i][1]) {
121 +                case 'n':                               /* number of cores */
122 +                        check(2,"i");
123 +                        nproc = atoi(argv[++i]);
124 +                        if (nproc <= 0)
125 +                                error(USER, "bad number of processes");
126 +                        break;
127                  case 'x':                               /* x resolution */
128                          check(2,"i");
129                          hresolu = atoi(argv[++i]);
# Line 228 | Line 250 | char  *argv[];
250                          goto badopt;
251                  }
252          }
253 +        if (nproc > 1) {
254 +                if (persist)
255 +                        error(USER, "multiprocessing incompatible with persist file");
256 +                if (!vresolu && hresolu > 0 && hresolu < nproc)
257 +                        error(WARNING, "number of cores should not exceed horizontal resolution");
258 +                if (trace != NULL)
259 +                        error(WARNING, "multiprocessing does not work properly with trace mode");
260 +        }
261                                          /* initialize object types */
262          initotypes();
263                                          /* initialize urand */
264 <        initurand(2048);
264 >        if (rand_samp) {
265 >                srandom((long)time(0));
266 >                initurand(0);
267 >        } else {
268 >                srandom(0L);
269 >                initurand(2048);
270 >        }
271                                          /* set up signal handling */
272          sigdie(SIGINT, "Interrupt");
273   #ifdef SIGHUP
# Line 263 | Line 299 | char  *argv[];
299   #endif
300                                          /* get octree */
301          if (i == argc)
302 <                octname = NULL;
302 >                octnm = NULL;
303          else if (i == argc-1)
304 <                octname = argv[i];
304 >                octnm = argv[i];
305          else
306                  goto badopt;
307 <        if (octname == NULL)
307 >        if (octnm == NULL)
308                  error(USER, "missing octree argument");
309                                          /* set up output */
310   #ifdef  PERSIST
# Line 277 | Line 313 | char  *argv[];
313                  openheader();
314          }
315   #endif
280 #ifdef  _WIN32
316          if (outform != 'a')
317                  SET_FILE_BINARY(stdout);
318 <        if (octname == NULL)
284 <                SET_FILE_BINARY(stdin);
285 < #endif
286 <        readoct(octname, loadflags, &thescene, NULL);
318 >        readoct(octnm, loadflags, &thescene, NULL);
319          nsceneobjs = nobjects;
320  
321          if (loadflags & IO_INFO) {      /* print header */
# Line 293 | Line 325 | char  *argv[];
325                  fputformat(formstr(outform), stdout);
326                  putchar('\n');
327          }
328 <
328 >        
329 >        ray_init_pmap();     /* PMAP: set up & load photon maps */
330 >        
331          marksources();                  /* find and mark sources */
332  
333          setambient();                   /* initialize ambient calculation */
334 <
334 >        
335   #ifdef  PERSIST
336          if (persist) {
337                  fflush(stdout);
# Line 311 | Line 345 | char  *argv[];
345                          while ((rval=fork()) == 0) {    /* keep on forkin' */
346                                  pflock(1);
347                                  pfhold();
348 +                                ambsync();              /* load new values */
349                          }
350                          if (rval < 0)
351                                  error(SYSTEM, "cannot fork child for persist function");
352 <                        pfdetach();             /* parent exits */
352 >                        pfdetach();             /* parent will run then exit */
353                  }
354          }
355   runagain:
# Line 322 | Line 357 | runagain:
357                  dupheader();                    /* send header to stdout */
358   #endif
359                                          /* trace rays */
360 <        rtrace(NULL);
360 >        rtrace(NULL, nproc);
361                                          /* flush ambient file */
362          ambsync();
363   #ifdef  PERSIST
# Line 337 | Line 372 | runagain:
372                  }
373          }
374          if (persist == PCHILD) {        /* wait for a signal then go again */
340                close(duped1);                  /* release output handle */
375                  pfhold();
376                  raynum = nrays = 0;             /* reinitialize */
377                  goto runagain;
378          }
379   #endif
380 +
381 +        ray_done_pmap();           /* PMAP: free photon maps */
382 +        
383          quit(0);
384  
385   badopt:
386          sprintf(errmsg, "command line error at '%s'", argv[i]);
387          error(USER, errmsg);
388 +        return 1; /* pro forma return */
389  
390   #undef  check
391   #undef  bool
# Line 355 | Line 393 | badopt:
393  
394  
395   void
396 < wputs(s)                                /* warning output function */
397 < char    *s;
396 > wputs(                          /* warning output function */
397 >        char    *s
398 > )
399   {
400          int  lasterrno = errno;
401          eputs(s);
# Line 365 | Line 404 | char   *s;
404  
405  
406   void
407 < eputs(s)                                /* put string to stderr */
408 < register char  *s;
407 > eputs(                          /* put string to stderr */
408 >        register char  *s
409 > )
410   {
411          static int  midline = 0;
412  
# Line 384 | Line 424 | register char  *s;
424   }
425  
426  
427 < void
428 < onsig(signo)                            /* fatal signal */
429 < int  signo;
427 > static void
428 > onsig(                          /* fatal signal */
429 >        int  signo
430 > )
431   {
432          static int  gotsig = 0;
433  
# Line 404 | Line 445 | int  signo;
445   }
446  
447  
448 < void
449 < sigdie(signo, msg)                      /* set fatal signal */
450 < int  signo;
451 < char  *msg;
448 > static void
449 > sigdie(                 /* set fatal signal */
450 >        int  signo,
451 >        char  *msg
452 > )
453   {
454          if (signal(signo, onsig) == SIG_IGN)
455                  signal(signo, SIG_IGN);
# Line 415 | Line 457 | char  *msg;
457   }
458  
459  
460 < void
461 < printdefaults()                 /* print default values to stdout */
460 > static void
461 > printdefaults(void)                     /* print default values to stdout */
462   {
463          register char  *cp;
464  
465          if (imm_irrad)
466                  printf("-I+\t\t\t\t# immediate irradiance on\n");
467 <        printf("-x  %-9d\t\t\t# x resolution\n", hresolu);
468 <        printf("-y  %-9d\t\t\t# y resolution\n", vresolu);
467 >        printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc);
468 >        printf("-x %-9d\t\t\t# %s\n", hresolu,
469 >                        vresolu && hresolu ? "x resolution" : "flush interval");
470 >        printf("-y %-9d\t\t\t# y resolution\n", vresolu);
471          printf(lim_dist ? "-ld+\t\t\t\t# limit distance on\n" :
472                          "-ld-\t\t\t\t# limit distance off\n");
473 +        printf("-h%c\t\t\t\t# %s header\n", loadflags & IO_INFO ? '+' : '-',
474 +                        loadflags & IO_INFO ? "output" : "no");
475          printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n",
476                          inform, outform, formstr(inform), formstr(outform));
477 <        printf("-o%s\t\t\t\t# output", outvals);
477 >        printf("-o%-9s\t\t\t# output", outvals);
478          for (cp = outvals; *cp; cp++)
479                  switch (*cp) {
480 <                case 't': printf(" trace"); break;
480 >                case 't': case 'T': printf(" trace"); break;
481                  case 'o': printf(" origin"); break;
482                  case 'd': printf(" direction"); break;
483                  case 'v': printf(" value"); break;
484 +                case 'V': printf(" contribution"); break;
485                  case 'l': printf(" length"); break;
486                  case 'L': printf(" first_length"); break;
487                  case 'p': printf(" point"); break;
# Line 442 | Line 489 | printdefaults()                        /* print default values to stdout */
489                  case 'N': printf(" unperturbed_normal"); break;
490                  case 's': printf(" surface"); break;
491                  case 'w': printf(" weight"); break;
492 +                case 'W': printf(" coefficient"); break;
493                  case 'm': printf(" modifier"); break;
494 +                case 'M': printf(" material"); break;
495 +                case '-': printf(" stroke"); break;
496                  }
497          putchar('\n');
498          printf(erract[WARNING].pf != NULL ?

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines