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.36 by greg, Wed Apr 6 15:28:18 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 +
70   int
71 < main(argc, argv)
116 < int  argc;
117 < char  *argv[];
71 > main(int  argc, char  *argv[])
72   {
73   #define  check(ol,al)           if (argv[i][ol] || \
74                                  badarg(argc-i-1,argv+i+1,al)) \
75                                  goto badopt
76 < #define  bool(olen,var)         switch (argv[i][olen]) { \
76 > #define  check_bool(olen,var)           switch (argv[i][olen]) { \
77                                  case '\0': var = !var; break; \
78                                  case 'y': case 'Y': case 't': case 'T': \
79                                  case '+': case '1': var = 1; break; \
80                                  case 'n': case 'N': case 'f': case 'F': \
81                                  case '-': case '0': var = 0; break; \
82                                  default: goto badopt; }
83 <        int  loadflags = ~IO_FILES;
83 >        extern char  *octname;
84          int  persist = 0;
85 <        char  **tralp;
86 <        int  duped1;
85 >        char  *octnm = NULL;
86 >        char  **tralp = NULL;
87 >        int  duped1 = -1;
88          int  rval;
89          int  i;
90                                          /* global program name */
91          progname = argv[0] = fixargv0(argv[0]);
92 +                                        /* add trace notify function */
93 +        for (i = 0; addobjnotify[i] != NULL; i++)
94 +                ;
95 +        addobjnotify[i] = tranotify;
96                                          /* option city */
97          for (i = 1; i < argc; i++) {
98                                                  /* expand arguments */
# Line 160 | Line 119 | char  *argv[];
119                          continue;
120                  }
121                  switch (argv[i][1]) {
122 +                case 'n':                               /* number of cores */
123 +                        check(2,"i");
124 +                        nproc = atoi(argv[++i]);
125 +                        if (nproc <= 0)
126 +                                error(USER, "bad number of processes");
127 +                        break;
128                  case 'x':                               /* x resolution */
129                          check(2,"i");
130                          hresolu = atoi(argv[++i]);
# Line 170 | Line 135 | char  *argv[];
135                          break;
136                  case 'w':                               /* warnings */
137                          rval = erract[WARNING].pf != NULL;
138 <                        bool(2,rval);
138 >                        check_bool(2,rval);
139                          if (rval) erract[WARNING].pf = wputs;
140                          else erract[WARNING].pf = NULL;
141                          break;
# Line 181 | Line 146 | char  *argv[];
146                  case 'l':                               /* limit distance */
147                          if (argv[i][2] != 'd')
148                                  goto badopt;
149 <                        bool(3,lim_dist);
149 >                        check_bool(3,lim_dist);
150                          break;
151                  case 'I':                               /* immed. irradiance */
152 <                        bool(2,imm_irrad);
152 >                        check_bool(2,imm_irrad);
153                          break;
154                  case 'f':                               /* format i/o */
155                          switch (argv[i][2]) {
# Line 216 | Line 181 | char  *argv[];
181                          break;
182                  case 'h':                               /* header output */
183                          rval = loadflags & IO_INFO;
184 <                        bool(2,rval);
184 >                        check_bool(2,rval);
185                          loadflags = rval ? loadflags | IO_INFO :
186                                          loadflags & ~IO_INFO;
187                          break;
# Line 230 | Line 195 | char  *argv[];
195                                          tralp = tralist;
196                                  }
197                                  if (argv[i][2] == 'I') {        /* file */
198 <                                        rval = wordfile(tralp,
199 <                                        getpath(argv[++i],getlibpath(),R_OK));
198 >                                        rval = wordfile(tralp, MAXMODLIST-(tralp-tralist),
199 >                                        getpath(argv[++i],getrlibpath(),R_OK));
200                                          if (rval < 0) {
201                                                  sprintf(errmsg,
202                                  "cannot open trace include file \"%s\"",
# Line 252 | Line 217 | char  *argv[];
217                                          tralp = tralist;
218                                  }
219                                  if (argv[i][2] == 'E') {        /* file */
220 <                                        rval = wordfile(tralp,
221 <                                        getpath(argv[++i],getlibpath(),R_OK));
220 >                                        rval = wordfile(tralp, MAXMODLIST-(tralp-tralist),
221 >                                        getpath(argv[++i],getrlibpath(),R_OK));
222                                          if (rval < 0) {
223                                                  sprintf(errmsg,
224                                  "cannot open trace exclude file \"%s\"",
# Line 286 | Line 251 | char  *argv[];
251                          goto badopt;
252                  }
253          }
254 +        if (nproc > 1 && persist)
255 +                error(USER, "multiprocessing incompatible with persist file");
256                                          /* initialize object types */
257          initotypes();
258                                          /* initialize urand */
259 <        initurand(2048);
259 >        if (rand_samp) {
260 >                srandom((long)time(0));
261 >                initurand(0);
262 >        } else {
263 >                srandom(0L);
264 >                initurand(2048);
265 >        }
266                                          /* set up signal handling */
267          sigdie(SIGINT, "Interrupt");
268 + #ifdef SIGHUP
269          sigdie(SIGHUP, "Hangup");
270 + #endif
271          sigdie(SIGTERM, "Terminate");
272 + #ifdef SIGPIPE
273          sigdie(SIGPIPE, "Broken pipe");
274 + #endif
275 + #ifdef SIGALRM
276          sigdie(SIGALRM, "Alarm clock");
277 + #endif
278   #ifdef  SIGXCPU
279          sigdie(SIGXCPU, "CPU limit exceeded");
280          sigdie(SIGXFSZ, "File size exceeded");
# Line 315 | Line 294 | char  *argv[];
294   #endif
295                                          /* get octree */
296          if (i == argc)
297 <                octname = NULL;
297 >                octnm = NULL;
298          else if (i == argc-1)
299 <                octname = argv[i];
299 >                octnm = argv[i];
300          else
301                  goto badopt;
302 <        if (octname == NULL)
302 >        if (octnm == NULL)
303                  error(USER, "missing octree argument");
304                                          /* set up output */
305   #ifdef  PERSIST
# Line 329 | Line 308 | char  *argv[];
308                  openheader();
309          }
310   #endif
332 #ifdef  MSDOS
311          if (outform != 'a')
312 <                setmode(fileno(stdout), O_BINARY);
313 <        if (octname == NULL)
314 <                setmode(fileno(stdin), O_BINARY);
337 < #endif
338 <        readoct(octname, loadflags, &thescene, NULL);
312 >                SET_FILE_BINARY(stdout);
313 >        rval = setrtoutput();
314 >        readoct(octname = octnm, loadflags, &thescene, NULL);
315          nsceneobjs = nobjects;
316  
317          if (loadflags & IO_INFO) {      /* print header */
318                  printargs(i, argv, stdout);
319                  printf("SOFTWARE= %s\n", VersionID);
320                  fputnow(stdout);
321 +                if (rval > 0)           /* saved from setrtoutput() call */
322 +                        printf("NCOMP=%d\n", rval);
323 +                if ((outform == 'f') | (outform == 'd'))
324 +                        fputendian(stdout);
325                  fputformat(formstr(outform), stdout);
326                  putchar('\n');
327          }
328  
329 <        marksources();                  /* find and mark sources */
329 >        if (!castonly) {        /* any actual ray traversal to do? */
330  
331 <        setambient();                   /* initialize ambient calculation */
331 >                ray_init_pmap();        /* PMAP: set up & load photon maps */
332 >                
333 >                marksources();          /* find and mark sources */
334  
335 +                setambient();           /* initialize ambient calculation */
336 +        } else
337 +                distantsources();       /* else mark only distant sources */
338 +
339 +        fflush(stdout);                 /* in case we're duplicating header */
340 +
341   #ifdef  PERSIST
342          if (persist) {
355                fflush(stdout);
343                                                  /* reconnect stdout */
344                  dup2(duped1, fileno(stdout));
345                  close(duped1);
# Line 363 | Line 350 | char  *argv[];
350                          while ((rval=fork()) == 0) {    /* keep on forkin' */
351                                  pflock(1);
352                                  pfhold();
353 +                                ambsync();              /* load new values */
354                          }
355                          if (rval < 0)
356                                  error(SYSTEM, "cannot fork child for persist function");
357 <                        pfdetach();             /* parent exits */
357 >                        pfdetach();             /* parent will run then exit */
358                  }
359          }
360   runagain:
# Line 374 | Line 362 | runagain:
362                  dupheader();                    /* send header to stdout */
363   #endif
364                                          /* trace rays */
365 <        rtrace(NULL);
365 >        rtrace(NULL, nproc);
366                                          /* flush ambient file */
367          ambsync();
368   #ifdef  PERSIST
# Line 389 | Line 377 | runagain:
377                  }
378          }
379          if (persist == PCHILD) {        /* wait for a signal then go again */
392                close(duped1);                  /* release output handle */
380                  pfhold();
381                  raynum = nrays = 0;             /* reinitialize */
382                  goto runagain;
383          }
384   #endif
385 +
386 +        ray_done_pmap();           /* PMAP: free photon maps */
387 +        
388          quit(0);
389  
390   badopt:
391          sprintf(errmsg, "command line error at '%s'", argv[i]);
392          error(USER, errmsg);
393 +        return 1; /* pro forma return */
394  
395   #undef  check
396 < #undef  bool
396 > #undef  check_bool
397   }
398  
399  
400   void
401 < wputs(s)                                /* warning output function */
402 < char    *s;
401 > wputs(                          /* warning output function */
402 >        char    *s
403 > )
404   {
405          int  lasterrno = errno;
406          eputs(s);
# Line 417 | Line 409 | char   *s;
409  
410  
411   void
412 < eputs(s)                                /* put string to stderr */
413 < register char  *s;
412 > eputs(                          /* put string to stderr */
413 >        register char  *s
414 > )
415   {
416          static int  midline = 0;
417  
# Line 436 | Line 429 | register char  *s;
429   }
430  
431  
432 < void
433 < onsig(signo)                            /* fatal signal */
434 < int  signo;
432 > static void
433 > onsig(                          /* fatal signal */
434 >        int  signo
435 > )
436   {
437          static int  gotsig = 0;
438  
439          if (gotsig++)                   /* two signals and we're gone! */
440                  _exit(signo);
441  
442 + #ifdef SIGALRM
443          alarm(15);                      /* allow 15 seconds to clean up */
444          signal(SIGALRM, SIG_DFL);       /* make certain we do die */
445 + #endif
446          eputs("signal - ");
447          eputs(sigerr[signo]);
448          eputs("\n");
# Line 454 | Line 450 | int  signo;
450   }
451  
452  
453 < void
454 < sigdie(signo, msg)                      /* set fatal signal */
455 < int  signo;
456 < char  *msg;
453 > static void
454 > sigdie(                 /* set fatal signal */
455 >        int  signo,
456 >        char  *msg
457 > )
458   {
459          if (signal(signo, onsig) == SIG_IGN)
460                  signal(signo, SIG_IGN);
# Line 465 | Line 462 | char  *msg;
462   }
463  
464  
465 < void
466 < printdefaults()                 /* print default values to stdout */
465 > static void
466 > printdefaults(void)                     /* print default values to stdout */
467   {
468          register char  *cp;
469  
470          if (imm_irrad)
471                  printf("-I+\t\t\t\t# immediate irradiance on\n");
472 <        printf("-x  %-9d\t\t\t# x resolution\n", hresolu);
473 <        printf("-y  %-9d\t\t\t# y resolution\n", vresolu);
472 >        printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc);
473 >        printf("-x %-9d\t\t\t# %s\n", hresolu,
474 >                        vresolu && hresolu ? "x resolution" : "flush interval");
475 >        printf("-y %-9d\t\t\t# y resolution\n", vresolu);
476          printf(lim_dist ? "-ld+\t\t\t\t# limit distance on\n" :
477                          "-ld-\t\t\t\t# limit distance off\n");
478 +        printf("-h%c\t\t\t\t# %s header\n", loadflags & IO_INFO ? '+' : '-',
479 +                        loadflags & IO_INFO ? "output" : "no");
480          printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n",
481                          inform, outform, formstr(inform), formstr(outform));
482 <        printf("-o%s\t\t\t\t# output", outvals);
482 >        printf("-o%-9s\t\t\t# output", outvals);
483          for (cp = outvals; *cp; cp++)
484                  switch (*cp) {
485 <                case 't': printf(" trace"); break;
485 >                case 't': case 'T': printf(" trace"); break;
486                  case 'o': printf(" origin"); break;
487                  case 'd': printf(" direction"); break;
488 +                case 'r': printf(" reflect_contrib"); break;
489 +                case 'R': printf(" reflect_length"); break;
490 +                case 'x': printf(" unreflect_contrib"); break;
491 +                case 'X': printf(" unreflect_length"); break;
492                  case 'v': printf(" value"); break;
493 +                case 'V': printf(" contribution"); break;
494                  case 'l': printf(" length"); break;
495                  case 'L': printf(" first_length"); break;
496                  case 'p': printf(" point"); break;
# Line 492 | Line 498 | printdefaults()                        /* print default values to stdout */
498                  case 'N': printf(" unperturbed_normal"); break;
499                  case 's': printf(" surface"); break;
500                  case 'w': printf(" weight"); break;
501 +                case 'W': printf(" coefficient"); break;
502                  case 'm': printf(" modifier"); break;
503 +                case 'M': printf(" material"); break;
504 +                case '-': printf(" stroke"); break;
505                  }
506          putchar('\n');
507          printf(erract[WARNING].pf != NULL ?

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines