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.62 by greg, Mon Dec 14 07:31:37 2009 UTC vs.
Revision 2.77 by greg, Sat May 4 13:48:06 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;
120 <        long  nextflush = hresolu;
119 >                                              : (unsigned long)vresolu;
120 >        long  nextflush = (vresolu > 0) & (hresolu > 1) ? 0 : hresolu;
121          FILE  *fp;
122          double  d;
123          FVECT  orig, direc;
# Line 160 | Line 162 | rtrace(                                /* trace rays from file */
162  
163                  d = normalize(direc);
164                  if (d == 0.0) {                         /* zero ==> flush */
165 <                        if (nproc > 1 && ray_fifo_flush() < 0)
166 <                                error(USER, "lost children");
167 <                        bogusray();
168 <                        if (--nextflush <= 0 || !vcount) {
165 >                        if ((--nextflush <= 0) | !vcount) {
166 >                                if (ray_pnprocs > 1 && ray_fifo_flush() < 0)
167 >                                        error(USER, "child(ren) died");
168 >                                bogusray();
169                                  fflush(stdout);
170 <                                nextflush = hresolu;
171 <                        }
170 >                                nextflush = (vresolu > 0) & (hresolu > 1) ? 0 :
171 >                                                                hresolu;
172 >                        } else
173 >                                bogusray();
174                  } else {                                /* compute and print */
175                          rtcompute(orig, direc, lim_dist ? d : 0.0);
176                                                          /* flush if time */
177                          if (!--nextflush) {
178 <                                if (nproc > 1 && ray_fifo_flush() < 0)
179 <                                        error(USER, "lost children");
178 >                                if (ray_pnprocs > 1 && ray_fifo_flush() < 0)
179 >                                        error(USER, "child(ren) died");
180                                  fflush(stdout);
181                                  nextflush = hresolu;
182                          }
# Line 182 | Line 186 | rtrace(                                /* trace rays from file */
186                  if (vcount && !--vcount)                /* check for end */
187                          break;
188          }
189 <        if (nproc > 1) {                                /* clean up children */
189 >        if (ray_pnprocs > 1) {                          /* clean up children */
190                  if (ray_fifo_flush() < 0)
191                          error(USER, "unable to complete processing");
192                  ray_pclose(0);
# Line 233 | Line 237 | setoutput(                             /* set up output tables */
237                  case 'd':                               /* direction */
238                          *table++ = oputd;
239                          break;
240 +                case 'r':                               /* reflected contrib. */
241 +                        *table++ = oputr;
242 +                        castonly = 0;
243 +                        break;
244 +                case 'R':                               /* reflected distance */
245 +                        *table++ = oputR;
246 +                        castonly = 0;
247 +                        break;
248 +                case 'x':                               /* xmit contrib. */
249 +                        *table++ = oputx;
250 +                        castonly = 0;
251 +                        break;
252 +                case 'X':                               /* xmit distance */
253 +                        *table++ = oputX;
254 +                        castonly = 0;
255 +                        break;
256                  case 'v':                               /* value */
257                          *table++ = oputv;
258                          castonly = 0;
259                          break;
260                  case 'V':                               /* contribution */
261                          *table++ = oputV;
262 +                        castonly = 0;
263                          if (ambounce > 0 && (ambacc > FTINY || ambssamp > 0))
264                                  error(WARNING,
265                                          "-otV accuracy depends on -aa 0 -as 0");
# Line 271 | Line 292 | setoutput(                             /* set up output tables */
292                          break;
293                  case 'W':                               /* coefficient */
294                          *table++ = oputW;
295 +                        castonly = 0;
296                          if (ambounce > 0 && (ambacc > FTINY || ambssamp > 0))
297                                  error(WARNING,
298                                          "-otW accuracy depends on -aa 0 -as 0");
# Line 292 | Line 314 | setoutput(                             /* set up output tables */
314   static void
315   bogusray(void)                  /* print out empty record */
316   {
317 <        thisray.rorg[0] = thisray.rorg[1] = thisray.rorg[2] =
296 <        thisray.rdir[0] = thisray.rdir[1] = thisray.rdir[2] = 0.0;
297 <        thisray.rmax = 0.0;
317 >        memset(&thisray, 0, sizeof(thisray));
318          rayorigin(&thisray, PRIMARY, NULL, NULL);
319          printvals(&thisray);
320   }
# Line 321 | Line 341 | rayirrad(                      /* compute irradiance rather than radiance
341   )
342   {
343          void    (*old_revf)(RAY *) = r->revf;
344 <
345 <        r->rot = 1e-5;                  /* pretend we hit surface */
344 >                                        /* pretend we hit surface */
345 >        r->rxt = r->rot = 1e-5;
346          VSUM(r->rop, r->rorg, r->rdir, r->rot);
347          r->ron[0] = -r->rdir[0];
348          r->ron[1] = -r->rdir[1];
# Line 408 | Line 428 | getvec(                /* get a vector from fp */
428                  }
429                  break;
430          case 'f':                                       /* binary float */
431 <                if (fread((char *)vf, sizeof(float), 3, fp) != 3)
431 >                if (getbinary(vf, sizeof(float), 3, fp) != 3)
432                          return(-1);
433                  VCOPY(vec, vf);
434                  break;
435          case 'd':                                       /* binary double */
436 <                if (fread((char *)vd, sizeof(double), 3, fp) != 3)
436 >                if (getbinary(vd, sizeof(double), 3, fp) != 3)
437                          return(-1);
438                  VCOPY(vec, vd);
439                  break;
# Line 492 | Line 512 | oputo(                         /* print origin */
512          RAY  *r
513   )
514   {
515 <        (*putreal)(r->rorg[0]);
496 <        (*putreal)(r->rorg[1]);
497 <        (*putreal)(r->rorg[2]);
515 >        (*putreal)(r->rorg, 3);
516   }
517  
518  
# Line 503 | Line 521 | oputd(                         /* print direction */
521          RAY  *r
522   )
523   {
524 <        (*putreal)(r->rdir[0]);
507 <        (*putreal)(r->rdir[1]);
508 <        (*putreal)(r->rdir[2]);
524 >        (*putreal)(r->rdir, 3);
525   }
526  
527  
528   static void
529 + oputr(                          /* print mirrored contribution */
530 +        RAY  *r
531 + )
532 + {
533 +        RREAL   cval[3];
534 +
535 +        cval[0] = colval(r->mcol,RED);
536 +        cval[1] = colval(r->mcol,GRN);
537 +        cval[2] = colval(r->mcol,BLU);
538 +        (*putreal)(cval, 3);
539 + }
540 +
541 +
542 +
543 + static void
544 + oputR(                          /* print mirrored distance */
545 +        RAY  *r
546 + )
547 + {
548 +        (*putreal)(&r->rmt, 1);
549 + }
550 +
551 +
552 + static void
553 + oputx(                          /* print unmirrored contribution */
554 +        RAY  *r
555 + )
556 + {
557 +        RREAL   cval[3];
558 +
559 +        cval[0] = colval(r->rcol,RED) - colval(r->mcol,RED);
560 +        cval[1] = colval(r->rcol,GRN) - colval(r->mcol,GRN);
561 +        cval[2] = colval(r->rcol,BLU) - colval(r->mcol,BLU);
562 +        (*putreal)(cval, 3);
563 + }
564 +
565 +
566 + static void
567 + oputX(                          /* print unmirrored distance */
568 +        RAY  *r
569 + )
570 + {
571 +        (*putreal)(&r->rxt, 1);
572 + }
573 +
574 +
575 + static void
576   oputv(                          /* print value */
577          RAY  *r
578   )
579   {
580 +        RREAL   cval[3];
581 +
582          if (outform == 'c') {
583                  COLR  cout;
584                  setcolr(cout,   colval(r->rcol,RED),
585                                  colval(r->rcol,GRN),
586                                  colval(r->rcol,BLU));
587 <                fwrite((char *)cout, sizeof(cout), 1, stdout);
587 >                putbinary(cout, sizeof(cout), 1, stdout);
588                  return;
589          }
590 <        (*putreal)(colval(r->rcol,RED));
591 <        (*putreal)(colval(r->rcol,GRN));
592 <        (*putreal)(colval(r->rcol,BLU));
590 >        cval[0] = colval(r->rcol,RED);
591 >        cval[1] = colval(r->rcol,GRN);
592 >        cval[2] = colval(r->rcol,BLU);
593 >        (*putreal)(cval, 3);
594   }
595  
596  
# Line 533 | Line 599 | oputV(                         /* print value contribution */
599          RAY *r
600   )
601   {
602 <        double  contr[3];
602 >        RREAL   contr[3];
603  
604          raycontrib(contr, r, PRIMARY);
605          multcolor(contr, r->rcol);
606 <        (*putreal)(contr[RED]);
541 <        (*putreal)(contr[GRN]);
542 <        (*putreal)(contr[BLU]);
606 >        (*putreal)(contr, 3);
607   }
608  
609  
# Line 548 | Line 612 | oputl(                         /* print effective distance */
612          RAY  *r
613   )
614   {
615 <        (*putreal)(r->rt);
615 >        RREAL   d = raydistance(r);
616 >
617 >        (*putreal)(&d, 1);
618   }
619  
620  
# Line 557 | Line 623 | oputL(                         /* print single ray length */
623          RAY  *r
624   )
625   {
626 <        (*putreal)(r->rot);
626 >        (*putreal)(&r->rot, 1);
627   }
628  
629  
# Line 566 | Line 632 | oputc(                         /* print local coordinates */
632          RAY  *r
633   )
634   {
635 <        (*putreal)(r->uv[0]);
570 <        (*putreal)(r->uv[1]);
635 >        (*putreal)(r->uv, 2);
636   }
637  
638  
639 + static RREAL    vdummy[3] = {0.0, 0.0, 0.0};
640 +
641 +
642   static void
643   oputp(                          /* print point */
644          RAY  *r
645   )
646   {
647 <        if (r->rot < FHUGE) {
648 <                (*putreal)(r->rop[0]);
649 <                (*putreal)(r->rop[1]);
650 <                (*putreal)(r->rop[2]);
583 <        } else {
584 <                (*putreal)(0.0);
585 <                (*putreal)(0.0);
586 <                (*putreal)(0.0);
587 <        }
647 >        if (r->rot < FHUGE)
648 >                (*putreal)(r->rop, 3);
649 >        else
650 >                (*putreal)(vdummy, 3);
651   }
652  
653  
# Line 593 | Line 656 | oputN(                         /* print unperturbed normal */
656          RAY  *r
657   )
658   {
659 <        if (r->rot < FHUGE) {
660 <                (*putreal)(r->ron[0]);
661 <                (*putreal)(r->ron[1]);
662 <                (*putreal)(r->ron[2]);
600 <        } else {
601 <                (*putreal)(0.0);
602 <                (*putreal)(0.0);
603 <                (*putreal)(0.0);
604 <        }
659 >        if (r->rot < FHUGE)
660 >                (*putreal)(r->ron, 3);
661 >        else
662 >                (*putreal)(vdummy, 3);
663   }
664  
665  
# Line 613 | Line 671 | oputn(                         /* print perturbed normal */
671          FVECT  pnorm;
672  
673          if (r->rot >= FHUGE) {
674 <                (*putreal)(0.0);
617 <                (*putreal)(0.0);
618 <                (*putreal)(0.0);
674 >                (*putreal)(vdummy, 3);
675                  return;
676          }
677          raynormal(pnorm, r);
678 <        (*putreal)(pnorm[0]);
623 <        (*putreal)(pnorm[1]);
624 <        (*putreal)(pnorm[2]);
678 >        (*putreal)(pnorm, 3);
679   }
680  
681  
# Line 643 | Line 697 | oputw(                         /* print weight */
697          RAY  *r
698   )
699   {
700 <        (*putreal)(r->rweight);
700 >        RREAL   rwt = r->rweight;
701 >        
702 >        (*putreal)(&rwt, 1);
703   }
704  
705  
# Line 652 | Line 708 | oputW(                         /* print coefficient */
708          RAY  *r
709   )
710   {
711 <        double  contr[3];
711 >        RREAL   contr[3];
712 >                                /* shadow ray not on source? */
713 >        if (r->rsrc >= 0 && source[r->rsrc].so != r->ro)
714 >                setcolor(contr, 0.0, 0.0, 0.0);
715 >        else
716 >                raycontrib(contr, r, PRIMARY);
717  
718 <        raycontrib(contr, r, PRIMARY);
658 <        (*putreal)(contr[RED]);
659 <        (*putreal)(contr[GRN]);
660 <        (*putreal)(contr[BLU]);
718 >        (*putreal)(contr, 3);
719   }
720  
721  
# Line 705 | Line 763 | oputtilde(                     /* output tilde (spacer) */
763  
764  
765   static void
766 < puta(                           /* print ascii value */
767 <        double  v
766 > puta(                           /* print ascii value(s) */
767 >        RREAL *v, int n
768   )
769   {
770 <        printf("%e\t", v);
770 >        if (n == 3) {
771 >                printf("%e\t%e\t%e\t", v[0], v[1], v[2]);
772 >                return;
773 >        }
774 >        while (n--)
775 >                printf("%e\t", *v++);
776   }
777  
778  
779   static void
780 < putd(v)                         /* print binary double */
718 < double  v;
780 > putd(RREAL *v, int n)           /* print binary double(s) */
781   {
782 <        fwrite((char *)&v, sizeof(v), 1, stdout);
782 > #ifdef  SMLFLT
783 >        double  da[3];
784 >        int     i;
785 >
786 >        if (n > 3)
787 >                error(INTERNAL, "code error in putd()");
788 >        for (i = n; i--; )
789 >                da[i] = v[i];
790 >        putbinary(da, sizeof(double), n, stdout);
791 > #else
792 >        putbinary(v, sizeof(RREAL), n, stdout);
793 > #endif
794   }
795  
796  
797   static void
798 < putf(v)                         /* print binary float */
726 < double  v;
798 > putf(RREAL *v, int n)           /* print binary float(s) */
799   {
800 <        float f = v;
800 > #ifndef SMLFLT
801 >        float   fa[3];
802 >        int     i;
803  
804 <        fwrite((char *)&f, sizeof(f), 1, stdout);
804 >        if (n > 3)
805 >                error(INTERNAL, "code error in putf()");
806 >        for (i = n; i--; )
807 >                fa[i] = v[i];
808 >        putbinary(fa, sizeof(float), n, stdout);
809 > #else
810 >        putbinary(v, sizeof(RREAL), n, stdout);
811 > #endif
812   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines