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.9 by schorsch, Tue Mar 30 16:13:01 2004 UTC vs.
Revision 2.39 by greg, Wed Oct 19 23:10:34 2022 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"
# Line 18 | Line 17 | static const char      RCSid[] = "$Id$";
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 26 | Line 30 | static const char      RCSid[] = "$Id$";
30   #define  PCHILD         3               /* child of normal persist */
31   #endif
32  
29 char  *progname;                        /* argv[0] */
30 char  *octname;                         /* octree name */
33   char  *sigerr[NSIG];                    /* signal error messages */
32 char  *shm_boundary = NULL;             /* boundary of shared memory */
34   char  *errfile = NULL;                  /* error output file */
35  
36 < extern char  *formstr();                /* string from format */
36 < extern int  inform;                     /* input format */
37 < extern int  outform;                    /* output format */
38 < extern char  *outvals;                  /* output values */
36 > int  nproc = 1;                         /* number of processes */
37  
38 < extern int  hresolu;                    /* horizontal resolution */
39 < extern int  vresolu;                    /* vertical resolution */
38 > extern char  *formstr(int f);           /* string from format */
39 > extern int  setrtoutput(void);          /* set output values */
40  
41 < extern int  imm_irrad;                  /* compute immediate irradiance? */
42 < extern int  lim_dist;                   /* limit distance? */
41 > int  inform = 'a';                      /* input format */
42 > int  outform = 'a';                     /* output format */
43 > char  *outvals = "v";                   /* output specification */
44  
45 < extern char  *tralist[];                /* list of modifers to trace (or no) */
46 < extern int  traincl;                    /* include == 1, exclude == 0 */
45 > int  hresolu = 0;                       /* horizontal (scan) size */
46 > int  vresolu = 0;                       /* vertical resolution */
47  
48 + extern int  castonly;                   /* only doing ray-casting? */
49 +
50 + int  imm_irrad = 0;                     /* compute immediate irradiance? */
51 + int  lim_dist = 0;                      /* limit distance? */
52 +
53 + #ifndef MAXMODLIST
54 + #define MAXMODLIST      1024            /* maximum modifiers we'll track */
55 + #endif
56 +
57 + extern void  (*addobjnotify[])();       /* object notification calls */
58 + extern void  tranotify(OBJECT obj);
59 +
60 + char  *tralist[MAXMODLIST];             /* list of modifers to trace (or no) */
61 + int  traincl = -1;                      /* include == 1, exclude == 0 */
62 +
63 + static int  loadflags = ~IO_FILES;      /* what to load from octree */
64 +
65   static void onsig(int  signo);
66   static void sigdie(int  signo, char  *msg);
67   static void printdefaults(void);
68  
69 + #ifdef PERSIST
70 + #define RTRACE_FEATURES "Persist\nParallelPersist\nMultiProcessing\n" \
71 +                        "IrradianceCalc\nImmediateIrradiance\nDistanceLimiting\n" \
72 +                        "HessianAmbientCache\nAmbientAveraging\n" \
73 +                        "AmbientValueSharing\nAdaptiveShadowTesting\n"
74 + #else
75 + #define RTRACE_FEATURES "IrradianceCalc\nIrradianceCalc\nDistanceLimiting\n" \
76 +                        "HessianAmbientCache\nAmbientAveraging\n" \
77 +                        "AmbientValueSharing\nAdaptiveShadowTesting\n"
78 + #endif
79  
80 +
81   int
82   main(int  argc, char  *argv[])
83   {
84   #define  check(ol,al)           if (argv[i][ol] || \
85                                  badarg(argc-i-1,argv+i+1,al)) \
86                                  goto badopt
87 < #define  bool(olen,var)         switch (argv[i][olen]) { \
87 > #define  check_bool(olen,var)           switch (argv[i][olen]) { \
88                                  case '\0': var = !var; break; \
89                                  case 'y': case 'Y': case 't': case 'T': \
90                                  case '+': case '1': var = 1; break; \
91                                  case 'n': case 'N': case 'f': case 'F': \
92                                  case '-': case '0': var = 0; break; \
93                                  default: goto badopt; }
94 <        int  loadflags = ~IO_FILES;
94 >        extern char  *octname;
95          int  persist = 0;
96 <        char  **tralp;
97 <        int  duped1;
96 >        char  *octnm = NULL;
97 >        char  **tralp = NULL;
98 >        int  duped1 = -1;
99          int  rval;
100          int  i;
101                                          /* global program name */
102          progname = argv[0] = fixargv0(argv[0]);
103 +                                        /* feature check only? */
104 +        strcat(RFeatureList, RTRACE_FEATURES);
105 +        if (!strcmp(argv[1], "-features"))
106 +                return feature_status(argc-2, argv+2);
107 +                                        /* add trace notify function */
108 +        for (i = 0; addobjnotify[i] != NULL; i++)
109 +                ;
110 +        addobjnotify[i] = tranotify;
111                                          /* option city */
112          for (i = 1; i < argc; i++) {
113                                                  /* expand arguments */
# Line 98 | Line 134 | main(int  argc, char  *argv[])
134                          continue;
135                  }
136                  switch (argv[i][1]) {
137 +                case 'n':                               /* number of cores */
138 +                        check(2,"i");
139 +                        nproc = atoi(argv[++i]);
140 +                        if (nproc <= 0)
141 +                                error(USER, "bad number of processes");
142 +                        break;
143                  case 'x':                               /* x resolution */
144                          check(2,"i");
145                          hresolu = atoi(argv[++i]);
# Line 108 | Line 150 | main(int  argc, char  *argv[])
150                          break;
151                  case 'w':                               /* warnings */
152                          rval = erract[WARNING].pf != NULL;
153 <                        bool(2,rval);
153 >                        check_bool(2,rval);
154                          if (rval) erract[WARNING].pf = wputs;
155                          else erract[WARNING].pf = NULL;
156                          break;
# Line 119 | Line 161 | main(int  argc, char  *argv[])
161                  case 'l':                               /* limit distance */
162                          if (argv[i][2] != 'd')
163                                  goto badopt;
164 <                        bool(3,lim_dist);
164 >                        check_bool(3,lim_dist);
165                          break;
166                  case 'I':                               /* immed. irradiance */
167 <                        bool(2,imm_irrad);
167 >                        check_bool(2,imm_irrad);
168                          break;
169                  case 'f':                               /* format i/o */
170                          switch (argv[i][2]) {
# Line 154 | Line 196 | main(int  argc, char  *argv[])
196                          break;
197                  case 'h':                               /* header output */
198                          rval = loadflags & IO_INFO;
199 <                        bool(2,rval);
199 >                        check_bool(2,rval);
200                          loadflags = rval ? loadflags | IO_INFO :
201                                          loadflags & ~IO_INFO;
202                          break;
# Line 168 | Line 210 | main(int  argc, char  *argv[])
210                                          tralp = tralist;
211                                  }
212                                  if (argv[i][2] == 'I') {        /* file */
213 <                                        rval = wordfile(tralp,
213 >                                        rval = wordfile(tralp, MAXMODLIST-(tralp-tralist),
214                                          getpath(argv[++i],getrlibpath(),R_OK));
215                                          if (rval < 0) {
216                                                  sprintf(errmsg,
# Line 190 | Line 232 | main(int  argc, char  *argv[])
232                                          tralp = tralist;
233                                  }
234                                  if (argv[i][2] == 'E') {        /* file */
235 <                                        rval = wordfile(tralp,
235 >                                        rval = wordfile(tralp, MAXMODLIST-(tralp-tralist),
236                                          getpath(argv[++i],getrlibpath(),R_OK));
237                                          if (rval < 0) {
238                                                  sprintf(errmsg,
# Line 224 | Line 266 | main(int  argc, char  *argv[])
266                          goto badopt;
267                  }
268          }
269 +        if (nproc > 1 && persist)
270 +                error(USER, "multiprocessing incompatible with persist file");
271                                          /* initialize object types */
272          initotypes();
273                                          /* initialize urand */
274 <        initurand(2048);
274 >        if (rand_samp) {
275 >                srandom((long)time(0));
276 >                initurand(0);
277 >        } else {
278 >                srandom(0L);
279 >                initurand(2048);
280 >        }
281                                          /* set up signal handling */
282          sigdie(SIGINT, "Interrupt");
283   #ifdef SIGHUP
# Line 259 | Line 309 | main(int  argc, char  *argv[])
309   #endif
310                                          /* get octree */
311          if (i == argc)
312 <                octname = NULL;
312 >                octnm = NULL;
313          else if (i == argc-1)
314 <                octname = argv[i];
314 >                octnm = argv[i];
315          else
316                  goto badopt;
317 <        if (octname == NULL)
317 >        if (octnm == NULL)
318                  error(USER, "missing octree argument");
319                                          /* set up output */
320   #ifdef  PERSIST
# Line 273 | Line 323 | main(int  argc, char  *argv[])
323                  openheader();
324          }
325   #endif
276 #ifdef  _WIN32
326          if (outform != 'a')
327                  SET_FILE_BINARY(stdout);
328 <        if (octname == NULL)
329 <                SET_FILE_BINARY(stdin);
281 < #endif
282 <        readoct(octname, loadflags, &thescene, NULL);
328 >        rval = setrtoutput();
329 >        readoct(octname = octnm, loadflags, &thescene, NULL);
330          nsceneobjs = nobjects;
331  
332          if (loadflags & IO_INFO) {      /* print header */
333                  printargs(i, argv, stdout);
334                  printf("SOFTWARE= %s\n", VersionID);
335                  fputnow(stdout);
336 +                if (rval > 0)           /* saved from setrtoutput() call */
337 +                        printf("NCOMP=%d\n", rval);
338 +                if ((outform == 'f') | (outform == 'd'))
339 +                        fputendian(stdout);
340                  fputformat(formstr(outform), stdout);
341                  putchar('\n');
342          }
343  
344 <        marksources();                  /* find and mark sources */
344 >        if (!castonly) {        /* any actual ray traversal to do? */
345  
346 <        setambient();                   /* initialize ambient calculation */
346 >                ray_init_pmap();        /* PMAP: set up & load photon maps */
347 >                
348 >                marksources();          /* find and mark sources */
349  
350 +                setambient();           /* initialize ambient calculation */
351 +        } else
352 +                distantsources();       /* else mark only distant sources */
353 +
354 +        fflush(stdout);                 /* in case we're duplicating header */
355 +
356   #ifdef  PERSIST
357          if (persist) {
299                fflush(stdout);
358                                                  /* reconnect stdout */
359                  dup2(duped1, fileno(stdout));
360                  close(duped1);
# Line 307 | Line 365 | main(int  argc, char  *argv[])
365                          while ((rval=fork()) == 0) {    /* keep on forkin' */
366                                  pflock(1);
367                                  pfhold();
368 +                                ambsync();              /* load new values */
369                          }
370                          if (rval < 0)
371                                  error(SYSTEM, "cannot fork child for persist function");
372 <                        pfdetach();             /* parent exits */
372 >                        pfdetach();             /* parent will run then exit */
373                  }
374          }
375   runagain:
# Line 318 | Line 377 | runagain:
377                  dupheader();                    /* send header to stdout */
378   #endif
379                                          /* trace rays */
380 <        rtrace(NULL);
380 >        rtrace(NULL, nproc);
381                                          /* flush ambient file */
382          ambsync();
383   #ifdef  PERSIST
# Line 333 | Line 392 | runagain:
392                  }
393          }
394          if (persist == PCHILD) {        /* wait for a signal then go again */
336                close(duped1);                  /* release output handle */
395                  pfhold();
396                  raynum = nrays = 0;             /* reinitialize */
397                  goto runagain;
398          }
399   #endif
400 +
401 +        ray_done_pmap();           /* PMAP: free photon maps */
402 +        
403          quit(0);
404  
405   badopt:
# Line 347 | Line 408 | badopt:
408          return 1; /* pro forma return */
409  
410   #undef  check
411 < #undef  bool
411 > #undef  check_bool
412   }
413  
414  
# Line 364 | Line 425 | wputs(                         /* warning output function */
425  
426   void
427   eputs(                          /* put string to stderr */
428 <        register char  *s
428 >        char  *s
429   )
430   {
431          static int  midline = 0;
# Line 419 | Line 480 | sigdie(                        /* set fatal signal */
480   static void
481   printdefaults(void)                     /* print default values to stdout */
482   {
483 <        register char  *cp;
483 >        char  *cp;
484  
485          if (imm_irrad)
486                  printf("-I+\t\t\t\t# immediate irradiance on\n");
487 <        printf("-x  %-9d\t\t\t# x resolution\n", hresolu);
488 <        printf("-y  %-9d\t\t\t# y resolution\n", vresolu);
487 >        printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc);
488 >        printf("-x %-9d\t\t\t# %s\n", hresolu,
489 >                        vresolu && hresolu ? "x resolution" : "flush interval");
490 >        printf("-y %-9d\t\t\t# y resolution\n", vresolu);
491          printf(lim_dist ? "-ld+\t\t\t\t# limit distance on\n" :
492                          "-ld-\t\t\t\t# limit distance off\n");
493 +        printf("-h%c\t\t\t\t# %s header\n", loadflags & IO_INFO ? '+' : '-',
494 +                        loadflags & IO_INFO ? "output" : "no");
495          printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n",
496                          inform, outform, formstr(inform), formstr(outform));
497 <        printf("-o%s\t\t\t\t# output", outvals);
497 >        printf("-o%-9s\t\t\t# output", outvals);
498          for (cp = outvals; *cp; cp++)
499                  switch (*cp) {
500 <                case 't': printf(" trace"); break;
500 >                case 't': case 'T': printf(" trace"); break;
501                  case 'o': printf(" origin"); break;
502                  case 'd': printf(" direction"); break;
503 +                case 'r': printf(" reflect_contrib"); break;
504 +                case 'R': printf(" reflect_length"); break;
505 +                case 'x': printf(" unreflect_contrib"); break;
506 +                case 'X': printf(" unreflect_length"); break;
507                  case 'v': printf(" value"); break;
508 +                case 'V': printf(" contribution"); break;
509                  case 'l': printf(" length"); break;
510                  case 'L': printf(" first_length"); break;
511                  case 'p': printf(" point"); break;
# Line 443 | Line 513 | printdefaults(void)                    /* print default values to stdou
513                  case 'N': printf(" unperturbed_normal"); break;
514                  case 's': printf(" surface"); break;
515                  case 'w': printf(" weight"); break;
516 +                case 'W': printf(" coefficient"); break;
517                  case 'm': printf(" modifier"); break;
518 +                case 'M': printf(" material"); break;
519 +                case '~': printf(" tilde"); break;
520                  }
521          putchar('\n');
522          printf(erract[WARNING].pf != NULL ?

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines