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

Comparing ray/src/rt/rvmain.c (file contents):
Revision 2.1 by greg, Sat Feb 22 02:07:29 2003 UTC vs.
Revision 2.23 by greg, Tue Apr 22 17:12:25 2025 UTC

# Line 5 | Line 5 | static const char      RCSid[] = "$Id$";
5   *  rvmain.c - main for rview interactive viewer
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 > #include  <time.h>
12  
13 + #include  "platform.h"
14 + #include  "ray.h"
15 + #include  "func.h"
16   #include  "source.h"
68
17   #include  "ambient.h"
18 <
18 > #include  "rpaint.h"
19   #include  "random.h"
72
20   #include  "paths.h"
21 + #include  "view.h"
22 + #include  "pmapray.h"
23  
24 < #include  <signal.h>
24 > extern char  *progname;                 /* global argv[0] */
25  
26 < #include  "view.h"
26 > VIEW  ourview = STDVIEW;                /* viewing parameters */
27 > int  hresolu, vresolu;                  /* image resolution */
28  
29 < char  *progname;                        /* argv[0] */
29 > int  psample = 8;                       /* pixel sample size */
30 > double  maxdiff = .15;                  /* max. sample difference */
31  
32 < char  *octname;                         /* octree name */
32 > int  greyscale = 0;                     /* map colors to brightness? */
33 > char  *dvcname = dev_default;           /* output device name */
34  
35 < char  *sigerr[NSIG];                    /* signal error messages */
35 > double  exposure = 1.0;                 /* exposure for scene */
36  
37 < char  *shm_boundary = NULL;             /* boundary of shared memory */
37 > int  newparam = 1;                      /* parameter setting changed */
38 >
39 > struct driver  *dev = NULL;             /* driver functions */
40  
41 < char  *errfile = NULL;                  /* error output file */
41 > char  rifname[128];                     /* rad input file name */
42  
43 < extern int  greyscale;                  /* map colors to brightness? */
90 < extern char  *dvcname;                  /* output device name */
91 < extern double  exposure;                /* exposure compensation */
43 > VIEW  oldview;                          /* previous view parameters */
44  
45 < extern VIEW  ourview;                   /* viewing parameters */
45 > PNODE  ptrunk;                          /* the base of our image */
46 > RECT  pframe;                           /* current frame boundaries */
47 > int  pdepth;                            /* image depth in current frame */
48  
49 < extern char  rifname[];                 /* rad input file name */
49 > char  *errfile = NULL;                  /* error output file */
50  
51 < extern int  hresolu;                    /* horizontal resolution */
98 < extern int  vresolu;                    /* vertical resolution */
51 > int  nproc = 1;                         /* number of processes */
52  
53 < extern int  psample;                    /* pixel sample size */
101 < extern double  maxdiff;                 /* max. sample difference */
53 > char  *sigerr[NSIG];                    /* signal error messages */
54  
55 < void    onsig();
56 < void    sigdie();
57 < void    printdefaults();
55 > static void onsig(int  signo);
56 > static void sigdie(int  signo, char  *msg);
57 > static void printdefaults(void);
58  
59 + static void
60 + set_defaults(void)
61 + {
62 +        shadthresh = .1;
63 +        shadcert = .25;
64 +        directrelay = 0;
65 +        vspretest = 128;
66 +        srcsizerat = 0.;
67 +        specthresh = .3;
68 +        specjitter = 1.;
69 +        maxdepth = 6;
70 +        minweight = 1e-3;
71 +        ambacc = 0.3;
72 +        ambres = 32;
73 +        ambdiv = 256;
74 +        ambssamp = 64;
75 + }
76  
77   int
78 < main(argc, argv)
110 < int  argc;
111 < char  *argv[];
78 > main(int argc, char *argv[])
79   {
80   #define  check(ol,al)           if (argv[i][ol] || \
81                                  badarg(argc-i-1,argv+i+1,al)) \
82                                  goto badopt
83 < #define  bool(olen,var)         switch (argv[i][olen]) { \
83 > #define  check_bool(olen,var)           switch (argv[i][olen]) { \
84                                  case '\0': var = !var; break; \
85                                  case 'y': case 'Y': case 't': case 'T': \
86                                  case '+': case '1': var = 1; break; \
87                                  case 'n': case 'N': case 'f': case 'F': \
88                                  case '-': case '0': var = 0; break; \
89                                  default: goto badopt; }
90 +        char  *octnm = NULL;
91          char  *err;
92          int  rval;
93          int  i;
94                                          /* global program name */
95          progname = argv[0] = fixargv0(argv[0]);
96 +                                        /* set our defaults */
97 +        set_defaults();
98 +                                        /* initialize calcomp routines */
99 +        initfunc();
100                                          /* option city */
101          for (i = 1; i < argc; i++) {
102                                                  /* expand arguments */
# Line 160 | Line 132 | char  *argv[];
132                          continue;
133                  }
134                  switch (argv[i][1]) {
135 +                case 'n':                               /* # processes */
136 +                        check(2,"i");
137 +                        nproc = atoi(argv[++i]);
138 +                        if (nproc <= 0)
139 +                                error(USER, "bad number of processes");
140 +                        break;
141                  case 'v':                               /* view file */
142                          if (argv[i][2] != 'f')
143                                  goto badopt;
# Line 178 | Line 156 | char  *argv[];
156                          }
157                          break;
158                  case 'b':                               /* grayscale */
159 <                        bool(2,greyscale);
159 >                        check_bool(2,greyscale);
160                          break;
161                  case 'p':                               /* pixel */
162                          switch (argv[i][2]) {
# Line 202 | Line 180 | char  *argv[];
180                          break;
181                  case 'w':                               /* warnings */
182                          rval = erract[WARNING].pf != NULL;
183 <                        bool(2,rval);
183 >                        check_bool(2,rval);
184                          if (rval) erract[WARNING].pf = wputs;
185                          else erract[WARNING].pf = NULL;
186                          break;
# Line 222 | Line 200 | char  *argv[];
200                          goto badopt;
201                  }
202          }
203 +                                        /* set/check spectral sampling */
204 +        if (setspectrsamp(CNDX, WLPART) <= 0)
205 +                error(USER, "unsupported spectral sampling");
206 +
207          err = setview(&ourview);        /* set viewing parameters */
208          if (err != NULL)
209                  error(USER, err);
210 <                                        /* initialize object types */
229 <        initotypes();
230 <                                        /* initialize urand */
231 <        initurand(2048);
232 <                                        /* set up signal handling */
210 >                                                /* set up signal handling */
211          sigdie(SIGINT, "Interrupt");
234        sigdie(SIGHUP, "Hangup");
212          sigdie(SIGTERM, "Terminate");
213 + #if !defined(_WIN32) && !defined(_WIN64)
214 +        sigdie(SIGHUP, "Hangup");
215          sigdie(SIGPIPE, "Broken pipe");
216          sigdie(SIGALRM, "Alarm clock");
238 #ifdef  SIGXCPU
239        sigdie(SIGXCPU, "CPU limit exceeded");
240        sigdie(SIGXFSZ, "File size exceeded");
217   #endif
218                                          /* open error file */
219          if (errfile != NULL) {
# Line 254 | Line 230 | char  *argv[];
230   #endif
231                                          /* get octree */
232          if (i == argc)
233 <                octname = NULL;
233 >                octnm = NULL;
234          else if (i == argc-1)
235 <                octname = argv[i];
235 >                octnm = argv[i];
236          else
237                  goto badopt;
238 <        if (octname == NULL)
238 >        if (octnm == NULL)
239                  error(USER, "missing octree argument");
240 <                                        /* set up output */
241 < #ifdef  MSDOS
242 <        setmode(fileno(stdout), O_BINARY);
243 < #endif
244 <        readoct(octname, ~(IO_FILES|IO_INFO), &thescene, NULL);
245 <        nsceneobjs = nobjects;
246 <
271 <        marksources();                  /* find and mark sources */
272 <
273 <        setambient();                   /* initialize ambient calculation */
274 <
240 >                                        /* set up output & start process(es) */
241 >        SET_FILE_BINARY(stdout);
242 >        
243 >        ray_init(octnm);                /* also calls ray_init_pmap() */
244 >        
245 > /* temporary shortcut, until winrview is refactored into a "device" */
246 > #ifndef WIN_RVIEW
247          rview();                        /* run interactive viewer */
248  
277        ambsync();                      /* flush ambient file */
249  
250 +        devclose();                     /* close output device */
251 + #endif
252 +
253 +        /* PMAP: free photon maps */
254 +        ray_done_pmap();
255 +        
256 + #ifdef WIN_RVIEW
257 +        return 1;
258 + #endif
259          quit(0);
260  
261   badopt:
262          sprintf(errmsg, "command line error at '%s'", argv[i]);
263          error(USER, errmsg);
264 +        return 1; /* pro forma return */
265  
266   #undef  check
267 < #undef  bool
267 > #undef  check_bool
268   }
269  
270  
271   void
272 < wputs(s)                                /* warning output function */
273 < char    *s;
272 > wputs(                          /* warning output function */
273 >        const char      *s
274 > )
275   {
276          int  lasterrno = errno;
277 +        if (erract[WARNING].pf == NULL)
278 +                return;         /* called by calcomp or someone */
279          eputs(s);
280          errno = lasterrno;
281   }
282  
283  
284   void
285 < eputs(s)                                /* put string to stderr */
286 < register char  *s;
285 > eputs(                          /* put string to stderr */
286 >        const char  *s
287 > )
288   {
289          static int  midline = 0;
290  
# Line 317 | Line 302 | register char  *s;
302   }
303  
304  
305 < void
306 < onsig(signo)                            /* fatal signal */
307 < int  signo;
305 > static void
306 > onsig(                          /* fatal signal */
307 >        int  signo
308 > )
309   {
310          static int  gotsig = 0;
311  
312          if (gotsig++)                   /* two signals and we're gone! */
313                  _exit(signo);
314  
315 + #if !defined(_WIN32) && !defined(_WIN64)
316          alarm(15);                      /* allow 15 seconds to clean up */
317          signal(SIGALRM, SIG_DFL);       /* make certain we do die */
318 + #endif
319          eputs("signal - ");
320          eputs(sigerr[signo]);
321          eputs("\n");
322 +        devclose();
323          quit(3);
324   }
325  
326  
327 < void
328 < sigdie(signo, msg)                      /* set fatal signal */
329 < int  signo;
330 < char  *msg;
327 > static void
328 > sigdie(                 /* set fatal signal */
329 >        int  signo,
330 >        char  *msg
331 > )
332   {
333          if (signal(signo, onsig) == SIG_IGN)
334                  signal(signo, SIG_IGN);
# Line 346 | Line 336 | char  *msg;
336   }
337  
338  
339 < void
340 < printdefaults()                 /* print default values to stdout */
339 > static void
340 > printdefaults(void)                     /* print default values to stdout */
341   {
342 <        register char  *cp;
353 <
342 >        printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc);
343          printf(greyscale ? "-b+\t\t\t\t# greyscale on\n" :
344                          "-b-\t\t\t\t# greyscale off\n");
345          printf("-vt%c\t\t\t\t# view type %s\n", ourview.type,
# Line 359 | Line 348 | printdefaults()                        /* print default values to stdout */
348                          ourview.type==VT_HEM ? "hemispherical" :
349                          ourview.type==VT_ANG ? "angular" :
350                          ourview.type==VT_CYL ? "cylindrical" :
351 +                        ourview.type==VT_PLS ? "planisphere" :
352                          "unknown");
353          printf("-vp %f %f %f\t# view point\n",
354                          ourview.vp[0], ourview.vp[1], ourview.vp[2]);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines