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

Comparing ray/src/rt/rtrace.c (file contents):
Revision 2.89 by greg, Fri Apr 3 17:06:16 2020 UTC vs.
Revision 2.96 by greg, Mon Jun 15 15:44:04 2020 UTC

# Line 45 | Line 45 | extern int  traincl;                   /* include == 1, exclude == 0 *
45   extern int  hresolu;                    /* horizontal resolution */
46   extern int  vresolu;                    /* vertical resolution */
47  
48 < static int  castonly = 0;
48 > int  castonly = 0;                      /* only doing ray-casting? */
49  
50   #ifndef  MAXTSET
51   #define  MAXTSET        8191            /* maximum number in trace set */
# Line 68 | Line 68 | static oputf_t  oputo, oputd, oputv, oputV, oputl, opu
68                  oputr, oputR, oputx, oputX, oputn, oputN, oputs,
69                  oputw, oputW, oputm, oputM, oputtilde;
70  
71 static void setoutput(char *vs);
71   extern void tranotify(OBJECT obj);
72 + static int is_fifo(FILE *fp);
73   static void bogusray(void);
74   static void raycast(RAY *r);
75   static void rayirrad(RAY *r);
# Line 117 | Line 117 | formstr(                               /* return format identifier */
117   }
118  
119  
120 < extern void
120 > void
121   rtrace(                         /* trace rays from file */
122          char  *fname,
123          int  nproc
# Line 144 | Line 144 | rtrace(                                /* trace rays from file */
144          if (inform != 'a')
145                  SET_FILE_BINARY(inpfp);
146                                          /* set up output */
147 <        setoutput(outvals);
148 <        if (imm_irrad)
149 <                castonly = 0;
150 <        else if (castonly)
147 >        if (castonly || every_out[0] != NULL)
148                  nproc = 1;              /* don't bother multiprocessing */
149          if ((nextflush > 0) & (nproc > nextflush)) {
150                  error(WARNING, "reducing number of processes to match flush interval");
# Line 158 | Line 155 | rtrace(                                /* trace rays from file */
155          case 'f': putreal = putf; break;
156          case 'd': putreal = putd; break;
157          case 'c':
158 <                if (outvals[0] && (outvals[1] || !strchr("vrx", outvals[0])))
158 >                if (outvals[1] || !strchr("vrx", outvals[0]))
159                          error(USER, "color format only with -ov, -or, -ox");
160                  putreal = putrgbe; break;
161          default:
# Line 167 | Line 164 | rtrace(                                /* trace rays from file */
164          if (nproc > 1) {                /* start multiprocessing */
165                  ray_popen(nproc);
166                  ray_fifo_out = printvals;
167 +                ray_pnbatch = 1;        /* optimize for throughput */
168          }
169          if (hresolu > 0) {
170                  if (vresolu > 0)
# Line 228 | Line 226 | trace_sources(void)                    /* trace rays to light sources,
226   }
227  
228  
229 < static void
230 < setoutput(                              /* set up output tables */
233 <        char  *vs
234 < )
229 > int
230 > setrtoutput(void)                       /* set up output tables, return #comp */
231   {
232 +        char  *vs = outvals;
233          oputf_t **table = ray_out;
234 +        int  ncomp = 0;
235  
236 <        castonly = 1;
237 <        while (*vs)
238 <                switch (*vs++) {
236 >        if (!*vs)
237 >                error(USER, "empty output specification");
238 >
239 >        castonly = 1;                   /* sets castonly as side-effect */
240 >        do
241 >                switch (*vs) {
242                  case 'T':                               /* trace sources */
243 <                        if (!*vs) break;
243 >                        if (!vs[1]) break;
244                          trace_sources();
245                          /* fall through */
246                  case 't':                               /* trace */
247 <                        if (!*vs) break;
247 >                        if (!vs[1]) break;
248                          *table = NULL;
249                          table = every_out;
250                          trace = ourtrace;
# Line 251 | Line 252 | setoutput(                             /* set up output tables */
252                          break;
253                  case 'o':                               /* origin */
254                          *table++ = oputo;
255 +                        ncomp += 3;
256                          break;
257                  case 'd':                               /* direction */
258                          *table++ = oputd;
259 +                        ncomp += 3;
260                          break;
261                  case 'r':                               /* reflected contrib. */
262                          *table++ = oputr;
263 +                        ncomp += 3;
264                          castonly = 0;
265                          break;
266                  case 'R':                               /* reflected distance */
267                          *table++ = oputR;
268 +                        ncomp++;
269                          castonly = 0;
270                          break;
271                  case 'x':                               /* xmit contrib. */
272                          *table++ = oputx;
273 +                        ncomp += 3;
274                          castonly = 0;
275                          break;
276                  case 'X':                               /* xmit distance */
277                          *table++ = oputX;
278 +                        ncomp++;
279                          castonly = 0;
280                          break;
281                  case 'v':                               /* value */
282                          *table++ = oputv;
283 +                        ncomp += 3;
284                          castonly = 0;
285                          break;
286                  case 'V':                               /* contribution */
287                          *table++ = oputV;
288 +                        ncomp += 3;
289 +                        castonly = 0;
290                          if (ambounce > 0 && (ambacc > FTINY || ambssamp > 0))
291                                  error(WARNING,
292                                          "-otV accuracy depends on -aa 0 -as 0");
293                          break;
294                  case 'l':                               /* effective distance */
295                          *table++ = oputl;
296 +                        ncomp++;
297                          castonly = 0;
298                          break;
299                  case 'c':                               /* local coordinates */
300                          *table++ = oputc;
301 +                        ncomp += 2;
302                          break;
303                  case 'L':                               /* single ray length */
304                          *table++ = oputL;
305 +                        ncomp++;
306                          break;
307                  case 'p':                               /* point */
308                          *table++ = oputp;
309 +                        ncomp += 3;
310                          break;
311                  case 'n':                               /* perturbed normal */
312                          *table++ = oputn;
313 +                        ncomp += 3;
314                          castonly = 0;
315                          break;
316                  case 'N':                               /* unperturbed normal */
317                          *table++ = oputN;
318 +                        ncomp += 3;
319                          break;
320                  case 's':                               /* surface */
321                          *table++ = oputs;
322 +                        ncomp++;
323                          break;
324                  case 'w':                               /* weight */
325                          *table++ = oputw;
326 +                        ncomp++;
327                          break;
328                  case 'W':                               /* coefficient */
329                          *table++ = oputW;
330 +                        ncomp += 3;
331                          castonly = 0;
332                          if (ambounce > 0 && (ambacc > FTINY) | (ambssamp > 0))
333                                  error(WARNING,
# Line 316 | Line 335 | setoutput(                             /* set up output tables */
335                          break;
336                  case 'm':                               /* modifier */
337                          *table++ = oputm;
338 +                        ncomp++;
339                          break;
340                  case 'M':                               /* material */
341                          *table++ = oputM;
342 +                        ncomp++;
343                          break;
344                  case '~':                               /* tilde */
345                          *table++ = oputtilde;
346                          break;
347 +                default:
348 +                        sprintf(errmsg, "unrecognized output option '%c'", *vs);
349 +                        error(USER, errmsg);
350                  }
351 +        while (*++vs);
352 +
353          *table = NULL;
354 +        if (*every_out != NULL)
355 +                ncomp = 0;
356                                                          /* compatibility */
357 +        if ((do_irrad | imm_irrad) && castonly)
358 +                error(USER, "-I+ and -i+ options require some value output");
359          for (table = ray_out; *table != NULL; table++) {
360                  if ((*table == oputV) | (*table == oputW))
361                          error(WARNING, "-oVW options require trace mode");
# Line 334 | Line 364 | setoutput(                             /* set up output tables */
364                                  (*table == oputx) | (*table == oputX))
365                          error(WARNING, "-orRxX options incompatible with -I+ and -i+");
366          }
367 +        return(ncomp);
368   }
369  
370  
# Line 432 | Line 463 | printvals(                     /* print requested ray values */
463  
464  
465   static int
466 + is_fifo(                /* check if file pointer connected to pipe */
467 +        FILE *fp
468 + )
469 + {
470 + #ifdef S_ISFIFO
471 +        struct stat  sbuf;
472 +
473 +        if (fstat(fileno(fp), &sbuf) < 0)
474 +                error(SYSTEM, "fstat() failed on input stream");
475 +        return(S_ISFIFO(sbuf.st_mode));
476 + #else
477 +        return (fp == stdin);           /* just a guess, really */
478 + #endif
479 + }
480 +
481 +
482 + static int
483   getvec(                 /* get a vector from fp */
484          FVECT  vec,
485          int  fmt,
# Line 495 | Line 543 | nextray(               /* return next ray in work group (-1.0 if EO
543                  int     rsiz = 6*20;    /* conservative ascii ray size */
544                  if (inform == 'f') rsiz = 6*sizeof(float);
545                  else if (inform == 'd') rsiz = 6*sizeof(double);
546 <                if ((inpfp == stdin) & (qlength*rsiz > 512))    /* pipe limit */
546 >                                        /* check against pipe limit */
547 >                if (qlength*rsiz > 512 && is_fifo(inpfp))
548                          inp_queue = (FVECT *)malloc(sizeof(FVECT)*2*qlength);
549                  inp_qend = -(inp_queue == NULL);        /* flag for no queue */
550          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines