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.63 by greg, Wed Dec 16 03:30:50 2009 UTC vs.
Revision 2.74 by greg, Tue Jan 8 00:16:31 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 161 | Line 163 | rtrace(                                /* trace rays from file */
163                  d = normalize(direc);
164                  if (d == 0.0) {                         /* zero ==> flush */
165                          if (--nextflush <= 0 || !vcount) {
166 <                                if (nproc > 1 && ray_fifo_flush() < 0)
167 <                                        error(USER, "lost children");
166 >                                if (ray_pnprocs > 1 && ray_fifo_flush() < 0)
167 >                                        error(USER, "child(ren) died");
168                                  bogusray();
169                                  fflush(stdout);
170 <                                nextflush = hresolu;
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 183 | 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 234 | 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 272 | 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 409 | Line 430 | getvec(                /* get a vector from fp */
430                  }
431                  break;
432          case 'f':                                       /* binary float */
433 <                if (fread((char *)vf, sizeof(float), 3, fp) != 3)
433 >                if (getbinary(vf, sizeof(float), 3, fp) != 3)
434                          return(-1);
435                  VCOPY(vec, vf);
436                  break;
437          case 'd':                                       /* binary double */
438 <                if (fread((char *)vd, sizeof(double), 3, fp) != 3)
438 >                if (getbinary(vd, sizeof(double), 3, fp) != 3)
439                          return(-1);
440                  VCOPY(vec, vd);
441                  break;
# Line 493 | Line 514 | oputo(                         /* print origin */
514          RAY  *r
515   )
516   {
517 <        (*putreal)(r->rorg[0]);
497 <        (*putreal)(r->rorg[1]);
498 <        (*putreal)(r->rorg[2]);
517 >        (*putreal)(r->rorg, 3);
518   }
519  
520  
# Line 504 | Line 523 | oputd(                         /* print direction */
523          RAY  *r
524   )
525   {
526 <        (*putreal)(r->rdir[0]);
508 <        (*putreal)(r->rdir[1]);
509 <        (*putreal)(r->rdir[2]);
526 >        (*putreal)(r->rdir, 3);
527   }
528  
529  
530   static void
531 + oputr(                          /* print mirrored contribution */
532 +        RAY  *r
533 + )
534 + {
535 +        RREAL   cval[3];
536 +
537 +        cval[0] = colval(r->mcol,RED);
538 +        cval[1] = colval(r->mcol,GRN);
539 +        cval[2] = colval(r->mcol,BLU);
540 +        (*putreal)(cval, 3);
541 + }
542 +
543 +
544 +
545 + static void
546 + oputR(                          /* print mirrored distance */
547 +        RAY  *r
548 + )
549 + {
550 +        (*putreal)(&r->rmt, 1);
551 + }
552 +
553 +
554 + static void
555 + oputx(                          /* print unmirrored contribution */
556 +        RAY  *r
557 + )
558 + {
559 +        RREAL   cval[3];
560 +
561 +        cval[0] = colval(r->rcol,RED) - colval(r->mcol,RED);
562 +        cval[1] = colval(r->rcol,GRN) - colval(r->mcol,GRN);
563 +        cval[2] = colval(r->rcol,BLU) - colval(r->mcol,BLU);
564 +        (*putreal)(cval, 3);
565 + }
566 +
567 +
568 + static void
569 + oputX(                          /* print unmirrored distance */
570 +        RAY  *r
571 + )
572 + {
573 +        (*putreal)(&r->rxt, 1);
574 + }
575 +
576 +
577 + static void
578   oputv(                          /* print value */
579          RAY  *r
580   )
581   {
582 +        RREAL   cval[3];
583 +
584          if (outform == 'c') {
585                  COLR  cout;
586                  setcolr(cout,   colval(r->rcol,RED),
587                                  colval(r->rcol,GRN),
588                                  colval(r->rcol,BLU));
589 <                fwrite((char *)cout, sizeof(cout), 1, stdout);
589 >                putbinary(cout, sizeof(cout), 1, stdout);
590                  return;
591          }
592 <        (*putreal)(colval(r->rcol,RED));
593 <        (*putreal)(colval(r->rcol,GRN));
594 <        (*putreal)(colval(r->rcol,BLU));
592 >        cval[0] = colval(r->rcol,RED);
593 >        cval[1] = colval(r->rcol,GRN);
594 >        cval[2] = colval(r->rcol,BLU);
595 >        (*putreal)(cval, 3);
596   }
597  
598  
# Line 534 | Line 601 | oputV(                         /* print value contribution */
601          RAY *r
602   )
603   {
604 <        double  contr[3];
604 >        RREAL   contr[3];
605  
606          raycontrib(contr, r, PRIMARY);
607          multcolor(contr, r->rcol);
608 <        (*putreal)(contr[RED]);
542 <        (*putreal)(contr[GRN]);
543 <        (*putreal)(contr[BLU]);
608 >        (*putreal)(contr, 3);
609   }
610  
611  
# Line 549 | Line 614 | oputl(                         /* print effective distance */
614          RAY  *r
615   )
616   {
617 <        (*putreal)(r->rt);
617 >        RREAL   d = raydistance(r);
618 >
619 >        (*putreal)(&d, 1);
620   }
621  
622  
# Line 558 | Line 625 | oputL(                         /* print single ray length */
625          RAY  *r
626   )
627   {
628 <        (*putreal)(r->rot);
628 >        (*putreal)(&r->rot, 1);
629   }
630  
631  
# Line 567 | Line 634 | oputc(                         /* print local coordinates */
634          RAY  *r
635   )
636   {
637 <        (*putreal)(r->uv[0]);
571 <        (*putreal)(r->uv[1]);
637 >        (*putreal)(r->uv, 2);
638   }
639  
640  
641 + static RREAL    vdummy[3] = {0.0, 0.0, 0.0};
642 +
643 +
644   static void
645   oputp(                          /* print point */
646          RAY  *r
647   )
648   {
649 <        if (r->rot < FHUGE) {
650 <                (*putreal)(r->rop[0]);
651 <                (*putreal)(r->rop[1]);
652 <                (*putreal)(r->rop[2]);
584 <        } else {
585 <                (*putreal)(0.0);
586 <                (*putreal)(0.0);
587 <                (*putreal)(0.0);
588 <        }
649 >        if (r->rot < FHUGE)
650 >                (*putreal)(r->rop, 3);
651 >        else
652 >                (*putreal)(vdummy, 3);
653   }
654  
655  
# Line 594 | Line 658 | oputN(                         /* print unperturbed normal */
658          RAY  *r
659   )
660   {
661 <        if (r->rot < FHUGE) {
662 <                (*putreal)(r->ron[0]);
663 <                (*putreal)(r->ron[1]);
664 <                (*putreal)(r->ron[2]);
601 <        } else {
602 <                (*putreal)(0.0);
603 <                (*putreal)(0.0);
604 <                (*putreal)(0.0);
605 <        }
661 >        if (r->rot < FHUGE)
662 >                (*putreal)(r->ron, 3);
663 >        else
664 >                (*putreal)(vdummy, 3);
665   }
666  
667  
# Line 614 | Line 673 | oputn(                         /* print perturbed normal */
673          FVECT  pnorm;
674  
675          if (r->rot >= FHUGE) {
676 <                (*putreal)(0.0);
618 <                (*putreal)(0.0);
619 <                (*putreal)(0.0);
676 >                (*putreal)(vdummy, 3);
677                  return;
678          }
679          raynormal(pnorm, r);
680 <        (*putreal)(pnorm[0]);
624 <        (*putreal)(pnorm[1]);
625 <        (*putreal)(pnorm[2]);
680 >        (*putreal)(pnorm, 3);
681   }
682  
683  
# Line 644 | Line 699 | oputw(                         /* print weight */
699          RAY  *r
700   )
701   {
702 <        (*putreal)(r->rweight);
702 >        RREAL   rwt = r->rweight;
703 >        
704 >        (*putreal)(&rwt, 1);
705   }
706  
707  
# Line 653 | Line 710 | oputW(                         /* print coefficient */
710          RAY  *r
711   )
712   {
713 <        double  contr[3];
713 >        RREAL   contr[3];
714 >                                /* shadow ray not on source? */
715 >        if (r->rsrc >= 0 && source[r->rsrc].so != r->ro)
716 >                setcolor(contr, 0.0, 0.0, 0.0);
717 >        else
718 >                raycontrib(contr, r, PRIMARY);
719  
720 <        raycontrib(contr, r, PRIMARY);
659 <        (*putreal)(contr[RED]);
660 <        (*putreal)(contr[GRN]);
661 <        (*putreal)(contr[BLU]);
720 >        (*putreal)(contr, 3);
721   }
722  
723  
# Line 706 | Line 765 | oputtilde(                     /* output tilde (spacer) */
765  
766  
767   static void
768 < puta(                           /* print ascii value */
769 <        double  v
768 > puta(                           /* print ascii value(s) */
769 >        RREAL *v, int n
770   )
771   {
772 <        printf("%e\t", v);
772 >        if (n == 3) {
773 >                printf("%e\t%e\t%e\t", v[0], v[1], v[2]);
774 >                return;
775 >        }
776 >        while (n--)
777 >                printf("%e\t", *v++);
778   }
779  
780  
781   static void
782 < putd(v)                         /* print binary double */
719 < double  v;
782 > putd(RREAL *v, int n)           /* print binary double(s) */
783   {
784 <        fwrite((char *)&v, sizeof(v), 1, stdout);
784 > #ifdef  SMLFLT
785 >        double  da[3];
786 >        int     i;
787 >
788 >        if (n > 3)
789 >                error(INTERNAL, "code error in putd()");
790 >        for (i = n; i--; )
791 >                da[i] = v[i];
792 >        putbinary(da, sizeof(double), n, stdout);
793 > #else
794 >        putbinary(v, sizeof(RREAL), n, stdout);
795 > #endif
796   }
797  
798  
799   static void
800 < putf(v)                         /* print binary float */
727 < double  v;
800 > putf(RREAL *v, int n)           /* print binary float(s) */
801   {
802 <        float f = v;
802 > #ifndef SMLFLT
803 >        float   fa[3];
804 >        int     i;
805  
806 <        fwrite((char *)&f, sizeof(f), 1, stdout);
806 >        if (n > 3)
807 >                error(INTERNAL, "code error in putf()");
808 >        for (i = n; i--; )
809 >                fa[i] = v[i];
810 >        putbinary(fa, sizeof(float), n, stdout);
811 > #else
812 >        putbinary(v, sizeof(RREAL), n, stdout);
813 > #endif
814   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines