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.64 by greg, Sun Sep 26 15:49:39 2010 UTC vs.
Revision 2.78 by greg, Sat May 4 23:10:32 2019 UTC

# Line 28 | Line 28 | static const char      RCSid[] = "$Id$";
28   #include  "ambient.h"
29   #include  "source.h"
30   #include  "otypes.h"
31 + #include  "otspecial.h"
32   #include  "resolu.h"
33   #include  "random.h"
34  
# Line 53 | Line 54 | OBJECT traset[MAXTSET+1]={0};          /* trace include/exclud
54  
55   static RAY  thisray;                    /* for our convenience */
56  
57 < typedef void putf_t(double v);
57 > typedef void putf_t(RREAL *v, int n);
58   static putf_t puta, putd, putf;
59  
60   typedef void oputf_t(RAY *r);
61   static oputf_t  oputo, oputd, oputv, oputV, oputl, oputL, oputc, oputp,
62 <                oputn, oputN, oputs, oputw, oputW, oputm, oputM, oputtilde;
62 >                oputr, oputR, oputx, oputX, oputn, oputN, oputs,
63 >                oputw, oputW, oputm, oputM, oputtilde;
64  
65   static void setoutput(char *vs);
66   extern void tranotify(OBJECT obj);
# Line 71 | Line 73 | static int getvec(FVECT vec, int fmt, FILE *fp);
73   static void tabin(RAY *r);
74   static void ourtrace(RAY *r);
75  
76 < static oputf_t *ray_out[16], *every_out[16];
76 > static oputf_t *ray_out[32], *every_out[32];
77   static putf_t *putreal;
78  
79  
# Line 114 | Line 116 | rtrace(                                /* trace rays from file */
116   )
117   {
118          unsigned long  vcount = (hresolu > 1) ? (unsigned long)hresolu*vresolu
119 <                                              : vresolu;
119 >                                              : (unsigned long)vresolu;
120          long  nextflush = (vresolu > 0) & (hresolu > 1) ? 0 : hresolu;
121 +        int  bogusflushed = 0;
122          FILE  *fp;
123          double  d;
124          FVECT  orig, direc;
# Line 152 | Line 155 | rtrace(                                /* trace rays from file */
155          if (hresolu > 0) {
156                  if (vresolu > 0)
157                          fprtresolu(hresolu, vresolu, stdout);
158 <                fflush(stdout);
158 >                else
159 >                        fflush(stdout);
160          }
161                                          /* process file */
162          while (getvec(orig, inform, fp) == 0 &&
# Line 160 | Line 164 | rtrace(                                /* trace rays from file */
164  
165                  d = normalize(direc);
166                  if (d == 0.0) {                         /* zero ==> flush */
167 <                        if (--nextflush <= 0 || !vcount) {
168 <                                if (nproc > 1 && ray_fifo_flush() < 0)
169 <                                        error(USER, "lost children");
167 >                        if ((--nextflush <= 0) | !vcount && !bogusflushed) {
168 >                                if (ray_pnprocs > 1 && ray_fifo_flush() < 0)
169 >                                        error(USER, "child(ren) died");
170                                  bogusray();
171                                  fflush(stdout);
172 +                                bogusflushed = 1;
173                                  nextflush = (vresolu > 0) & (hresolu > 1) ? 0 :
174                                                                  hresolu;
175                          } else
# Line 173 | Line 178 | rtrace(                                /* trace rays from file */
178                          rtcompute(orig, direc, lim_dist ? d : 0.0);
179                                                          /* flush if time */
180                          if (!--nextflush) {
181 <                                if (nproc > 1 && ray_fifo_flush() < 0)
182 <                                        error(USER, "lost children");
181 >                                if (ray_pnprocs > 1 && ray_fifo_flush() < 0)
182 >                                        error(USER, "child(ren) died");
183                                  fflush(stdout);
184                                  nextflush = hresolu;
185 <                        }
185 >                        } else
186 >                                bogusflushed = 0;
187                  }
188                  if (ferror(stdout))
189                          error(SYSTEM, "write error");
190                  if (vcount && !--vcount)                /* check for end */
191                          break;
192          }
193 <        if (nproc > 1) {                                /* clean up children */
193 >        if (ray_pnprocs > 1) {                          /* clean up children */
194                  if (ray_fifo_flush() < 0)
195                          error(USER, "unable to complete processing");
196                  ray_pclose(0);
# Line 235 | Line 241 | setoutput(                             /* set up output tables */
241                  case 'd':                               /* direction */
242                          *table++ = oputd;
243                          break;
244 +                case 'r':                               /* reflected contrib. */
245 +                        *table++ = oputr;
246 +                        castonly = 0;
247 +                        break;
248 +                case 'R':                               /* reflected distance */
249 +                        *table++ = oputR;
250 +                        castonly = 0;
251 +                        break;
252 +                case 'x':                               /* xmit contrib. */
253 +                        *table++ = oputx;
254 +                        castonly = 0;
255 +                        break;
256 +                case 'X':                               /* xmit distance */
257 +                        *table++ = oputX;
258 +                        castonly = 0;
259 +                        break;
260                  case 'v':                               /* value */
261                          *table++ = oputv;
262                          castonly = 0;
263                          break;
264                  case 'V':                               /* contribution */
265                          *table++ = oputV;
266 +                        castonly = 0;
267                          if (ambounce > 0 && (ambacc > FTINY || ambssamp > 0))
268                                  error(WARNING,
269                                          "-otV accuracy depends on -aa 0 -as 0");
# Line 273 | Line 296 | setoutput(                             /* set up output tables */
296                          break;
297                  case 'W':                               /* coefficient */
298                          *table++ = oputW;
299 +                        castonly = 0;
300                          if (ambounce > 0 && (ambacc > FTINY || ambssamp > 0))
301                                  error(WARNING,
302                                          "-otW accuracy depends on -aa 0 -as 0");
# Line 294 | Line 318 | setoutput(                             /* set up output tables */
318   static void
319   bogusray(void)                  /* print out empty record */
320   {
297        thisray.rorg[0] = thisray.rorg[1] = thisray.rorg[2] =
298        thisray.rdir[0] = thisray.rdir[1] = thisray.rdir[2] = 0.0;
299        thisray.rmax = 0.0;
321          rayorigin(&thisray, PRIMARY, NULL, NULL);
322          printvals(&thisray);
323   }
# Line 323 | Line 344 | rayirrad(                      /* compute irradiance rather than radiance
344   )
345   {
346          void    (*old_revf)(RAY *) = r->revf;
347 <
348 <        r->rot = 1e-5;                  /* pretend we hit surface */
347 >                                        /* pretend we hit surface */
348 >        r->rxt = r->rot = 1e-5;
349          VSUM(r->rop, r->rorg, r->rdir, r->rot);
350          r->ron[0] = -r->rdir[0];
351          r->ron[1] = -r->rdir[1];
# Line 410 | Line 431 | getvec(                /* get a vector from fp */
431                  }
432                  break;
433          case 'f':                                       /* binary float */
434 <                if (fread((char *)vf, sizeof(float), 3, fp) != 3)
434 >                if (getbinary(vf, sizeof(float), 3, fp) != 3)
435                          return(-1);
436                  VCOPY(vec, vf);
437                  break;
438          case 'd':                                       /* binary double */
439 <                if (fread((char *)vd, sizeof(double), 3, fp) != 3)
439 >                if (getbinary(vd, sizeof(double), 3, fp) != 3)
440                          return(-1);
441                  VCOPY(vec, vd);
442                  break;
# Line 494 | Line 515 | oputo(                         /* print origin */
515          RAY  *r
516   )
517   {
518 <        (*putreal)(r->rorg[0]);
498 <        (*putreal)(r->rorg[1]);
499 <        (*putreal)(r->rorg[2]);
518 >        (*putreal)(r->rorg, 3);
519   }
520  
521  
# Line 505 | Line 524 | oputd(                         /* print direction */
524          RAY  *r
525   )
526   {
527 <        (*putreal)(r->rdir[0]);
509 <        (*putreal)(r->rdir[1]);
510 <        (*putreal)(r->rdir[2]);
527 >        (*putreal)(r->rdir, 3);
528   }
529  
530  
531   static void
532 + oputr(                          /* print mirrored contribution */
533 +        RAY  *r
534 + )
535 + {
536 +        RREAL   cval[3];
537 +
538 +        cval[0] = colval(r->mcol,RED);
539 +        cval[1] = colval(r->mcol,GRN);
540 +        cval[2] = colval(r->mcol,BLU);
541 +        (*putreal)(cval, 3);
542 + }
543 +
544 +
545 +
546 + static void
547 + oputR(                          /* print mirrored distance */
548 +        RAY  *r
549 + )
550 + {
551 +        (*putreal)(&r->rmt, 1);
552 + }
553 +
554 +
555 + static void
556 + oputx(                          /* print unmirrored contribution */
557 +        RAY  *r
558 + )
559 + {
560 +        RREAL   cval[3];
561 +
562 +        cval[0] = colval(r->rcol,RED) - colval(r->mcol,RED);
563 +        cval[1] = colval(r->rcol,GRN) - colval(r->mcol,GRN);
564 +        cval[2] = colval(r->rcol,BLU) - colval(r->mcol,BLU);
565 +        (*putreal)(cval, 3);
566 + }
567 +
568 +
569 + static void
570 + oputX(                          /* print unmirrored distance */
571 +        RAY  *r
572 + )
573 + {
574 +        (*putreal)(&r->rxt, 1);
575 + }
576 +
577 +
578 + static void
579   oputv(                          /* print value */
580          RAY  *r
581   )
582   {
583 +        RREAL   cval[3];
584 +
585          if (outform == 'c') {
586                  COLR  cout;
587                  setcolr(cout,   colval(r->rcol,RED),
588                                  colval(r->rcol,GRN),
589                                  colval(r->rcol,BLU));
590 <                fwrite((char *)cout, sizeof(cout), 1, stdout);
590 >                putbinary(cout, sizeof(cout), 1, stdout);
591                  return;
592          }
593 <        (*putreal)(colval(r->rcol,RED));
594 <        (*putreal)(colval(r->rcol,GRN));
595 <        (*putreal)(colval(r->rcol,BLU));
593 >        cval[0] = colval(r->rcol,RED);
594 >        cval[1] = colval(r->rcol,GRN);
595 >        cval[2] = colval(r->rcol,BLU);
596 >        (*putreal)(cval, 3);
597   }
598  
599  
# Line 535 | Line 602 | oputV(                         /* print value contribution */
602          RAY *r
603   )
604   {
605 <        double  contr[3];
605 >        RREAL   contr[3];
606  
607          raycontrib(contr, r, PRIMARY);
608          multcolor(contr, r->rcol);
609 <        (*putreal)(contr[RED]);
543 <        (*putreal)(contr[GRN]);
544 <        (*putreal)(contr[BLU]);
609 >        (*putreal)(contr, 3);
610   }
611  
612  
# Line 550 | Line 615 | oputl(                         /* print effective distance */
615          RAY  *r
616   )
617   {
618 <        (*putreal)(r->rt);
618 >        RREAL   d = raydistance(r);
619 >
620 >        (*putreal)(&d, 1);
621   }
622  
623  
# Line 559 | Line 626 | oputL(                         /* print single ray length */
626          RAY  *r
627   )
628   {
629 <        (*putreal)(r->rot);
629 >        (*putreal)(&r->rot, 1);
630   }
631  
632  
# Line 568 | Line 635 | oputc(                         /* print local coordinates */
635          RAY  *r
636   )
637   {
638 <        (*putreal)(r->uv[0]);
572 <        (*putreal)(r->uv[1]);
638 >        (*putreal)(r->uv, 2);
639   }
640  
641  
642 + static RREAL    vdummy[3] = {0.0, 0.0, 0.0};
643 +
644 +
645   static void
646   oputp(                          /* print point */
647          RAY  *r
648   )
649   {
650 <        if (r->rot < FHUGE) {
651 <                (*putreal)(r->rop[0]);
652 <                (*putreal)(r->rop[1]);
653 <                (*putreal)(r->rop[2]);
585 <        } else {
586 <                (*putreal)(0.0);
587 <                (*putreal)(0.0);
588 <                (*putreal)(0.0);
589 <        }
650 >        if (r->rot < FHUGE)
651 >                (*putreal)(r->rop, 3);
652 >        else
653 >                (*putreal)(vdummy, 3);
654   }
655  
656  
# Line 595 | Line 659 | oputN(                         /* print unperturbed normal */
659          RAY  *r
660   )
661   {
662 <        if (r->rot < FHUGE) {
663 <                (*putreal)(r->ron[0]);
664 <                (*putreal)(r->ron[1]);
665 <                (*putreal)(r->ron[2]);
602 <        } else {
603 <                (*putreal)(0.0);
604 <                (*putreal)(0.0);
605 <                (*putreal)(0.0);
606 <        }
662 >        if (r->rot < FHUGE)
663 >                (*putreal)(r->ron, 3);
664 >        else
665 >                (*putreal)(vdummy, 3);
666   }
667  
668  
# Line 615 | Line 674 | oputn(                         /* print perturbed normal */
674          FVECT  pnorm;
675  
676          if (r->rot >= FHUGE) {
677 <                (*putreal)(0.0);
619 <                (*putreal)(0.0);
620 <                (*putreal)(0.0);
677 >                (*putreal)(vdummy, 3);
678                  return;
679          }
680          raynormal(pnorm, r);
681 <        (*putreal)(pnorm[0]);
625 <        (*putreal)(pnorm[1]);
626 <        (*putreal)(pnorm[2]);
681 >        (*putreal)(pnorm, 3);
682   }
683  
684  
# Line 645 | Line 700 | oputw(                         /* print weight */
700          RAY  *r
701   )
702   {
703 <        (*putreal)(r->rweight);
703 >        RREAL   rwt = r->rweight;
704 >        
705 >        (*putreal)(&rwt, 1);
706   }
707  
708  
# Line 654 | Line 711 | oputW(                         /* print coefficient */
711          RAY  *r
712   )
713   {
714 <        double  contr[3];
714 >        RREAL   contr[3];
715 >                                /* shadow ray not on source? */
716 >        if (r->rsrc >= 0 && source[r->rsrc].so != r->ro)
717 >                setcolor(contr, 0.0, 0.0, 0.0);
718 >        else
719 >                raycontrib(contr, r, PRIMARY);
720  
721 <        raycontrib(contr, r, PRIMARY);
660 <        (*putreal)(contr[RED]);
661 <        (*putreal)(contr[GRN]);
662 <        (*putreal)(contr[BLU]);
721 >        (*putreal)(contr, 3);
722   }
723  
724  
# Line 707 | Line 766 | oputtilde(                     /* output tilde (spacer) */
766  
767  
768   static void
769 < puta(                           /* print ascii value */
770 <        double  v
769 > puta(                           /* print ascii value(s) */
770 >        RREAL *v, int n
771   )
772   {
773 <        printf("%e\t", v);
773 >        if (n == 3) {
774 >                printf("%e\t%e\t%e\t", v[0], v[1], v[2]);
775 >                return;
776 >        }
777 >        while (n--)
778 >                printf("%e\t", *v++);
779   }
780  
781  
782   static void
783 < putd(v)                         /* print binary double */
720 < double  v;
783 > putd(RREAL *v, int n)           /* print binary double(s) */
784   {
785 <        fwrite((char *)&v, sizeof(v), 1, stdout);
785 > #ifdef  SMLFLT
786 >        double  da[3];
787 >        int     i;
788 >
789 >        if (n > 3)
790 >                error(INTERNAL, "code error in putd()");
791 >        for (i = n; i--; )
792 >                da[i] = v[i];
793 >        putbinary(da, sizeof(double), n, stdout);
794 > #else
795 >        putbinary(v, sizeof(RREAL), n, stdout);
796 > #endif
797   }
798  
799  
800   static void
801 < putf(v)                         /* print binary float */
728 < double  v;
801 > putf(RREAL *v, int n)           /* print binary float(s) */
802   {
803 <        float f = v;
803 > #ifndef SMLFLT
804 >        float   fa[3];
805 >        int     i;
806  
807 <        fwrite((char *)&f, sizeof(f), 1, stdout);
807 >        if (n > 3)
808 >                error(INTERNAL, "code error in putf()");
809 >        for (i = n; i--; )
810 >                fa[i] = v[i];
811 >        putbinary(fa, sizeof(float), n, stdout);
812 > #else
813 >        putbinary(v, sizeof(RREAL), n, stdout);
814 > #endif
815   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines