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.1 by greg, Sat Feb 22 02:07:29 2003 UTC vs.
Revision 2.39 by greg, Wed Oct 19 23:10:34 2022 UTC

# Line 5 | Line 5 | static const char      RCSid[] = "$Id$";
5   *  rtmain.c - main for rtrace per-ray calculation program
6   */
7  
8 < /* ====================================================================
9 < * The Radiance Software License, Version 1.0
10 < *
11 < * Copyright (c) 1990 - 2002 The Regents of the University of California,
12 < * through Lawrence Berkeley National Laboratory.   All rights reserved.
13 < *
14 < * Redistribution and use in source and binary forms, with or without
15 < * modification, are permitted provided that the following conditions
16 < * are met:
17 < *
18 < * 1. Redistributions of source code must retain the above copyright
19 < *         notice, this list of conditions and the following disclaimer.
20 < *
21 < * 2. Redistributions in binary form must reproduce the above copyright
22 < *       notice, this list of conditions and the following disclaimer in
23 < *       the documentation and/or other materials provided with the
24 < *       distribution.
25 < *
26 < * 3. The end-user documentation included with the redistribution,
27 < *           if any, must include the following acknowledgment:
28 < *             "This product includes Radiance software
29 < *                 (http://radsite.lbl.gov/)
30 < *                 developed by the Lawrence Berkeley National Laboratory
31 < *               (http://www.lbl.gov/)."
32 < *       Alternately, this acknowledgment may appear in the software itself,
33 < *       if and wherever such third-party acknowledgments normally appear.
34 < *
35 < * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
36 < *       and "The Regents of the University of California" must
37 < *       not be used to endorse or promote products derived from this
38 < *       software without prior written permission. For written
39 < *       permission, please contact [email protected].
40 < *
41 < * 5. Products derived from this software may not be called "Radiance",
42 < *       nor may "Radiance" appear in their name, without prior written
43 < *       permission of Lawrence Berkeley National Laboratory.
44 < *
45 < * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
46 < * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
47 < * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48 < * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
49 < * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50 < * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
51 < * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
52 < * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
53 < * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
54 < * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
55 < * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 < * SUCH DAMAGE.
57 < * ====================================================================
58 < *
59 < * This software consists of voluntary contributions made by many
60 < * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
61 < * information on Lawrence Berkeley National Laboratory, please see
62 < * <http://www.lbl.gov/>.
63 < */
8 > #include "copyright.h"
9  
10 < #include  "ray.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"
68
17   #include  "ambient.h"
70
18   #include  "random.h"
72
19   #include  "paths.h"
20 + #include  "pmapray.h"
21  
22 < #include  <sys/types.h>
22 > extern char     *progname;              /* global argv[0] */
23  
24 < #include  <signal.h>
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 82 | 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(int f);           /* string from format */
39 > extern int  setrtoutput(void);          /* set output values */
40  
41 < char  *shm_boundary = NULL;             /* boundary of shared memory */
41 > int  inform = 'a';                      /* input format */
42 > int  outform = 'a';                     /* output format */
43 > char  *outvals = "v";                   /* output specification */
44  
45 < char  *errfile = NULL;                  /* error output file */
45 > int  hresolu = 0;                       /* horizontal (scan) size */
46 > int  vresolu = 0;                       /* vertical resolution */
47  
48 < extern char  *formstr();                /* string from format */
96 < extern int  inform;                     /* input format */
97 < extern int  outform;                    /* output format */
98 < extern char  *outvals;                  /* output values */
48 > extern int  castonly;                   /* only doing ray-casting? */
49  
50 < extern int  hresolu;                    /* horizontal resolution */
51 < extern int  vresolu;                    /* vertical resolution */
50 > int  imm_irrad = 0;                     /* compute immediate irradiance? */
51 > int  lim_dist = 0;                      /* limit distance? */
52  
53 < extern int  imm_irrad;                  /* compute immediate irradiance? */
54 < extern int  lim_dist;                   /* limit distance? */
53 > #ifndef MAXMODLIST
54 > #define MAXMODLIST      1024            /* maximum modifiers we'll track */
55 > #endif
56  
57 < extern char  *tralist[];                /* list of modifers to trace (or no) */
58 < extern int  traincl;                    /* include == 1, exclude == 0 */
57 > extern void  (*addobjnotify[])();       /* object notification calls */
58 > extern void  tranotify(OBJECT obj);
59  
60 < void    onsig();
61 < void    sigdie();
111 < void    printdefaults();
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(argc, argv)
116 < int  argc;
117 < char  *argv[];
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 160 | Line 134 | 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 170 | Line 150 | 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 181 | Line 161 | 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 216 | Line 196 | 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 230 | Line 210 | char  *argv[];
210                                          tralp = tralist;
211                                  }
212                                  if (argv[i][2] == 'I') {        /* file */
213 <                                        rval = wordfile(tralp,
214 <                                        getpath(argv[++i],getlibpath(),R_OK));
213 >                                        rval = wordfile(tralp, MAXMODLIST-(tralp-tralist),
214 >                                        getpath(argv[++i],getrlibpath(),R_OK));
215                                          if (rval < 0) {
216                                                  sprintf(errmsg,
217                                  "cannot open trace include file \"%s\"",
# Line 252 | Line 232 | char  *argv[];
232                                          tralp = tralist;
233                                  }
234                                  if (argv[i][2] == 'E') {        /* file */
235 <                                        rval = wordfile(tralp,
236 <                                        getpath(argv[++i],getlibpath(),R_OK));
235 >                                        rval = wordfile(tralp, MAXMODLIST-(tralp-tralist),
236 >                                        getpath(argv[++i],getrlibpath(),R_OK));
237                                          if (rval < 0) {
238                                                  sprintf(errmsg,
239                                  "cannot open trace exclude file \"%s\"",
# Line 286 | Line 266 | 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
284          sigdie(SIGHUP, "Hangup");
285 + #endif
286          sigdie(SIGTERM, "Terminate");
287 + #ifdef SIGPIPE
288          sigdie(SIGPIPE, "Broken pipe");
289 + #endif
290 + #ifdef SIGALRM
291          sigdie(SIGALRM, "Alarm clock");
292 + #endif
293   #ifdef  SIGXCPU
294          sigdie(SIGXCPU, "CPU limit exceeded");
295          sigdie(SIGXFSZ, "File size exceeded");
# Line 315 | Line 309 | 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 329 | Line 323 | char  *argv[];
323                  openheader();
324          }
325   #endif
332 #ifdef  MSDOS
326          if (outform != 'a')
327 <                setmode(fileno(stdout), O_BINARY);
328 <        if (octname == NULL)
329 <                setmode(fileno(stdin), O_BINARY);
337 < #endif
338 <        readoct(octname, loadflags, &thescene, NULL);
327 >                SET_FILE_BINARY(stdout);
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) {
355                fflush(stdout);
358                                                  /* reconnect stdout */
359                  dup2(duped1, fileno(stdout));
360                  close(duped1);
# Line 363 | Line 365 | 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 374 | 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 389 | Line 392 | runagain:
392                  }
393          }
394          if (persist == PCHILD) {        /* wait for a signal then go again */
392                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:
406          sprintf(errmsg, "command line error at '%s'", argv[i]);
407          error(USER, errmsg);
408 +        return 1; /* pro forma return */
409  
410   #undef  check
411 < #undef  bool
411 > #undef  check_bool
412   }
413  
414  
415   void
416 < wputs(s)                                /* warning output function */
417 < char    *s;
416 > wputs(                          /* warning output function */
417 >        char    *s
418 > )
419   {
420          int  lasterrno = errno;
421          eputs(s);
# Line 417 | Line 424 | char   *s;
424  
425  
426   void
427 < eputs(s)                                /* put string to stderr */
428 < register char  *s;
427 > eputs(                          /* put string to stderr */
428 >        char  *s
429 > )
430   {
431          static int  midline = 0;
432  
# Line 436 | Line 444 | register char  *s;
444   }
445  
446  
447 < void
448 < onsig(signo)                            /* fatal signal */
449 < int  signo;
447 > static void
448 > onsig(                          /* fatal signal */
449 >        int  signo
450 > )
451   {
452          static int  gotsig = 0;
453  
454          if (gotsig++)                   /* two signals and we're gone! */
455                  _exit(signo);
456  
457 + #ifdef SIGALRM
458          alarm(15);                      /* allow 15 seconds to clean up */
459          signal(SIGALRM, SIG_DFL);       /* make certain we do die */
460 + #endif
461          eputs("signal - ");
462          eputs(sigerr[signo]);
463          eputs("\n");
# Line 454 | Line 465 | int  signo;
465   }
466  
467  
468 < void
469 < sigdie(signo, msg)                      /* set fatal signal */
470 < int  signo;
471 < char  *msg;
468 > static void
469 > sigdie(                 /* set fatal signal */
470 >        int  signo,
471 >        char  *msg
472 > )
473   {
474          if (signal(signo, onsig) == SIG_IGN)
475                  signal(signo, SIG_IGN);
# Line 465 | Line 477 | char  *msg;
477   }
478  
479  
480 < void
481 < printdefaults()                 /* print default values to stdout */
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 492 | Line 513 | printdefaults()                        /* print default values to stdout */
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