ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/Development/ray/src/util/rfluxmtx.c
(Generate patch)

Comparing ray/src/util/rfluxmtx.c (file contents):
Revision 2.51 by greg, Mon Mar 2 22:00:05 2020 UTC vs.
Revision 2.62 by greg, Mon Oct 20 18:55:19 2025 UTC

# Line 22 | Line 22 | static const char RCSid[] = "$Id$";
22   #define MAXRCARG        10000
23   #endif
24  
25 < char            *progname;              /* global argv[0] */
25 > #define         NOWARN          1
26 > #define         VERBO           2
27  
28 < int             verbose = 0;            /* verbose mode (< 0 no warnings) */
28 > int             verbose = 0;            /* verbose/warning mode */
29  
30   char            *rcarg[MAXRCARG+1] = {"rcontrib", "-fo+"};
31   int             nrcargs = 2;
# Line 41 | Line 42 | char           *shirchiufn = "disk2square.cal";
42   char            *kfullfn = "klems_full.cal";
43   char            *khalffn = "klems_half.cal";
44   char            *kquarterfn = "klems_quarter.cal";
45 + char            *ciefn = "cieskyscan.cal";
46  
47                                          /* string indicating parameters */
48 < const char      PARAMSTART[] = "@rfluxmtx";
48 > #define PARAMSTART      "@rfluxmtx"
49  
50                                  /* surface type IDs */
51   #define ST_NONE         0
# Line 108 | Line 110 | clear_params(PARAMS *p, int reset_only)
110                  free(sdel);
111          }
112          if (reset_only) {
113 +                p->slist = NULL;
114                  p->nsurfs = 0;
115                  memset(p->nrm, 0, sizeof(FVECT));
116                  memset(p->vup, 0, sizeof(FVECT));
# Line 140 | Line 143 | oconv_command(int ac, char *av[])
143          
144          if (ac-- <= 0)
145                  return(NULL);
146 <        if (verbose < 0) {      /* turn off warnings */
146 >        if (verbose & NOWARN) { /* warnings off? */
147                  strcpy(cp, "-w ");
148                  cp += 3;
149          }
# Line 191 | Line 194 | popen_arglist(char *av[], char *mode)
194                  fputs(": command line too long in popen_arglist()\n", stderr);
195                  return(NULL);
196          }
197 <        if (verbose > 0)
197 >        if (verbose & VERBO)
198                  fprintf(stderr, "%s: opening pipe %s: %s\n",
199                                  progname, (*mode=='w') ? "to" : "from", cmd);
200          return(popen(cmd, mode));
# Line 210 | Line 213 | my_exec(char *av[])
213                  fputs(": command line too long in my_exec()\n", stderr);
214                  return(1);
215          }
216 <        if (verbose > 0)
216 >        if (verbose & VERBO)
217                  fprintf(stderr, "%s: running: %s\n", progname, cmd);
218          return(system(cmd));
219   }
# Line 229 | Line 232 | popen_arglist(char *av[], char *mode)
232                  fprintf(stderr, "%s: only one i/o pipe at a time!\n", progname);
233                  return(NULL);
234          }
235 <        if (verbose > 0) {
235 >        if (verbose & VERBO) {
236                  char    cmd[4096];
237                  if (!convert_commandline(cmd, sizeof(cmd), av))
238                          strcpy(cmd, "COMMAND TOO LONG TO SHOW");
# Line 274 | Line 277 | my_exec(char *av[])
277                  fprintf(stderr, "%s: cannot locate %s\n", progname, av[0]);
278                  return(1);
279          }
280 <        if (verbose > 0) {
280 >        if (verbose & VERBO) {
281                  char    cmd[4096];
282                  if (!convert_commandline(cmd, sizeof(cmd), av))
283                          strcpy(cmd, "COMMAND TOO LONG TO SHOW");
# Line 499 | Line 502 | finish_receiver(void)
502                  calfn = kquarterfn; kquarterfn = NULL;
503                  binf = "kqbin";
504                  nbins = "Nkqbins";
505 +        } else if (!strcasecmp(curparams.hemis, "cie")) {
506 +                calfn = ciefn; ciefn = NULL;
507 +                sprintf(sbuf, "rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g,RHS=%c1",
508 +                        curparams.nrm[0], curparams.nrm[1], curparams.nrm[2],
509 +                        curparams.vup[0], curparams.vup[1], curparams.vup[2],
510 +                        curparams.sign);
511 +                params = savqstr(sbuf);
512 +                binv = "cbin";
513 +                nbins = "Ncbins";
514          } else {
515                  fprintf(stderr, "%s: unrecognized hemisphere sampling: h=%s\n",
516                                  progname, curparams.hemis);
# Line 508 | Line 520 | finish_receiver(void)
520                  sprintf(sbuf, "RHS=%c1", curparams.sign);
521                  params = savqstr(sbuf);
522          }
523 <        if (!uniform & (curparams.slist->styp == ST_SOURCE)) {
523 >        if (!uniform) {
524                  SURF    *sp;
525                  for (sp = curparams.slist; sp != NULL; sp = sp->next)
526 <                        if (fabs(sp->area - PI) > 1e-3) {
526 >                        if (sp->styp == ST_SOURCE && fabs(sp->area - PI) > 1e-3) {
527                                  fprintf(stderr, "%s: source '%s' must be 180-degrees\n",
528                                                  progname, sp->sname);
529                                  exit(1);
# Line 720 | Line 732 | sample_origin(PARAMS *p, FVECT orig, const FVECT rdir,
732                                          /* compute projected areas */
733          for (i = 0, sp = p->slist; sp != NULL; i++, sp = sp->next) {
734                  projsa[i] = -DOT(sp->snrm, rdir) * sp->area;
735 <                tarea += projsa[i] *= (double)(projsa[i] > FTINY);
735 >                tarea += projsa[i] *= (double)(projsa[i] > 0);
736          }
737 <        if (tarea < 0) {                /* wrong side of sender? */
737 >        if (tarea < FTINY*FTINY) {      /* wrong side of sender? */
738                  fputs(progname, stderr);
739                  fputs(": internal - sample behind all sender elements!\n",
740                                  stderr);
# Line 740 | Line 752 | sample_uniform(PARAMS *p, int b, FILE *fp)
752   {
753          int     n = sampcnt;
754          double  samp3[3];
755 <        double  duvw[3];
744 <        FVECT   orig_dir[2];
755 >        FVECT   duvw, orig_dir[2];
756          int     i;
757  
758          if (fp == NULL)                 /* just requesting number of bins? */
# Line 749 | Line 760 | sample_uniform(PARAMS *p, int b, FILE *fp)
760  
761          while (n--) {                   /* stratified hemisphere sampling */
762                  SDmultiSamp(samp3, 3, (n+frandom())/sampcnt);
763 <                SDsquare2disk(duvw, samp3[1], samp3[2]);
763 >                square2disk(duvw, samp3[1], samp3[2]);
764                  duvw[2] = -sqrt(1. - duvw[0]*duvw[0] - duvw[1]*duvw[1]);
765                  for (i = 3; i--; )
766                          orig_dir[1][i] = duvw[0]*p->udir[i] +
# Line 769 | Line 780 | sample_shirchiu(PARAMS *p, int b, FILE *fp)
780   {
781          int     n = sampcnt;
782          double  samp3[3];
783 <        double  duvw[3];
773 <        FVECT   orig_dir[2];
783 >        FVECT   duvw, orig_dir[2];
784          int     i;
785  
786          if (fp == NULL)                 /* just requesting number of bins? */
# Line 778 | Line 788 | sample_shirchiu(PARAMS *p, int b, FILE *fp)
788  
789          while (n--) {                   /* stratified sampling */
790                  SDmultiSamp(samp3, 3, (n+frandom())/sampcnt);
791 <                SDsquare2disk(duvw, (b/p->hsiz + samp3[1])/curparams.hsiz,
791 >                square2disk(duvw, (b/p->hsiz + samp3[1])/curparams.hsiz,
792                                  (b%p->hsiz + samp3[2])/curparams.hsiz);
793                  duvw[2] = sqrt(1. - duvw[0]*duvw[0] - duvw[1]*duvw[1]);
794                  for (i = 3; i--; )
# Line 896 | Line 906 | sample_klems(PARAMS *p, int b, FILE *fp)
906  
907   /* Prepare hemisphere basis sampler that will send rays to rcontrib */
908   static int
909 < prepare_sampler(void)
909 > prepare_sampler(PARAMS *p)
910   {
911 <        if (curparams.slist == NULL) {  /* missing sample surface! */
912 <                fputs(progname, stderr);
903 <                fputs(": no sender surface!\n", stderr);
911 >        if (p->slist == NULL) {         /* missing sample surface! */
912 >                error(USER, "no sender surface");
913                  return(-1);
914          }
915                                          /* misplaced output file spec. */
916 <        if ((curparams.outfn != NULL) & (verbose >= 0))
917 <                fprintf(stderr, "%s: warning - ignoring output file in sender ('%s')\n",
918 <                                progname, curparams.outfn);
916 >        if (p->outfn[0]) {
917 >                sprintf(errmsg, "ignoring output file in sender ('%s')",
918 >                                p->outfn);
919 >                error(WARNING, errmsg);
920 >        }
921                                          /* check/set basis hemisphere */
922 <        if (!curparams.hemis[0]) {
923 <                fputs(progname, stderr);
913 <                fputs(": missing sender sampling type!\n", stderr);
922 >        if (!p->hemis[0]) {
923 >                error(USER, "missing sender sampling type");
924                  return(-1);
925          }
926 <        if (normalize(curparams.nrm) == 0) {
927 <                fputs(progname, stderr);
918 <                fputs(": undefined normal for sender sampling\n", stderr);
926 >        if (normalize(p->nrm) == 0) {
927 >                error(USER, "undefined normal for sender sampling");
928                  return(-1);
929          }
930 <        if (normalize(curparams.vup) == 0) {
931 <                if (fabs(curparams.nrm[2]) < .7)
932 <                        curparams.vup[2] = 1;
930 >        if (normalize(p->vup) == 0) {
931 >                if (fabs(p->nrm[2]) < .7)
932 >                        p->vup[2] = 1;
933                  else
934 <                        curparams.vup[1] = 1;
934 >                        p->vup[1] = 1;
935          }
936 <        fcross(curparams.udir, curparams.vup, curparams.nrm);
937 <        if (normalize(curparams.udir) == 0) {
938 <                fputs(progname, stderr);
930 <                fputs(": up vector coincides with sender normal\n", stderr);
936 >        fcross(p->udir, p->vup, p->nrm);
937 >        if (normalize(p->udir) == 0) {
938 >                error(USER, "up vector coincides with sender normal");
939                  return(-1);
940          }
941 <        fcross(curparams.vdir, curparams.nrm, curparams.udir);
942 <        if (curparams.sign == '-') {    /* left-handed coordinate system? */
943 <                curparams.udir[0] *= -1.;
944 <                curparams.udir[1] *= -1.;
945 <                curparams.udir[2] *= -1.;
941 >        fcross(p->vdir, p->nrm, p->udir);
942 >        if (p->sign == '-') {           /* left-handed coordinate system? */
943 >                p->udir[0] *= -1.;
944 >                p->udir[1] *= -1.;
945 >                p->udir[2] *= -1.;
946          }
947 <        if ((tolower(curparams.hemis[0]) == 'u') | (curparams.hemis[0] == '1'))
948 <                curparams.sample_basis = sample_uniform;
949 <        else if (tolower(curparams.hemis[0]) == 's' &&
950 <                                tolower(curparams.hemis[1]) == 'c')
951 <                curparams.sample_basis = sample_shirchiu;
952 <        else if ((tolower(curparams.hemis[0]) == 'r') |
953 <                        (tolower(curparams.hemis[0]) == 't'))
954 <                curparams.sample_basis = sample_reinhart;
955 <        else if (tolower(curparams.hemis[0]) == 'k') {
956 <                switch (curparams.hemis[1]) {
947 >        if ((tolower(p->hemis[0]) == 'u') | (p->hemis[0] == '1'))
948 >                p->sample_basis = sample_uniform;
949 >        else if (tolower(p->hemis[0]) == 's' &&
950 >                                tolower(p->hemis[1]) == 'c')
951 >                p->sample_basis = sample_shirchiu;
952 >        else if ((tolower(p->hemis[0]) == 'r') |
953 >                        (tolower(p->hemis[0]) == 't'))
954 >                p->sample_basis = sample_reinhart;
955 >        else if (tolower(p->hemis[0]) == 'k') {
956 >                switch (p->hemis[1]) {
957                  case '1':
958                  case '2':
959                  case '4':
# Line 953 | Line 961 | prepare_sampler(void)
961                  case 'f':
962                  case 'F':
963                  case '\0':
964 <                        curparams.hemis[1] = '1';
964 >                        p->hemis[1] = '1';
965                          break;
966                  case 'h':
967                  case 'H':
968 <                        curparams.hemis[1] = '2';
968 >                        p->hemis[1] = '2';
969                          break;
970                  case 'q':
971                  case 'Q':
972 <                        curparams.hemis[1] = '4';
972 >                        p->hemis[1] = '4';
973                          break;
974                  default:
975                          goto unrecognized;
976                  }
977 <                curparams.hemis[2] = '\0';
978 <                curparams.sample_basis = sample_klems;
977 >                p->hemis[2] = '\0';
978 >                p->sample_basis = sample_klems;
979          } else
980                  goto unrecognized;
981                                          /* return number of bins */
982 <        return((*curparams.sample_basis)(&curparams,0,NULL));
982 >        return((*p->sample_basis)(p,0,NULL));
983   unrecognized:
984          fprintf(stderr, "%s: unrecognized sender sampling: h=%s\n",
985 <                        progname, curparams.hemis);
985 >                        progname, p->hemis);
986          return(-1);
987   }
988  
# Line 997 | Line 1005 | finish_polygon(SURF *p)
1005                  VCOPY(e1, e2);
1006          }
1007          p->area = normalize(p->snrm)*0.5;
1008 <        return(p->area > FTINY);
1008 >        return(p->area > FTINY*FTINY);
1009   }
1010  
1011   /* Add a surface to our current parameters */
# Line 1060 | Line 1068 | add_surface(int st, const char *oname, FILE *fp)
1068                  snew->area *= PI*snew->area;
1069                  break;
1070          }
1071 <        if ((snew->area <= FTINY) & (verbose >= 0)) {
1071 >        if ((snew->area <= FTINY*FTINY) & !(verbose & NOWARN)) {
1072                  fprintf(stderr, "%s: warning - zero area for surface '%s'\n",
1073                                  progname, oname);
1074                  free(snew);
# Line 1097 | Line 1105 | add_recv_object(FILE *fp)
1105          }
1106                                          /* is it a new receiver? */
1107          if ((st = surf_type(otype)) != ST_NONE) {
1100                if (curparams.slist != NULL && (st == ST_SOURCE) ^
1101                                (curparams.slist->styp == ST_SOURCE)) {
1102                        fputs(progname, stderr);
1103                        fputs(": cannot mix source/non-source receivers!\n", stderr);
1104                        return(-1);
1105                }
1108                  if (strcmp(thismod, curmod)) {
1109                          if (curmod[0]) {        /* output last receiver? */
1110                                  finish_receiver();
# Line 1238 | Line 1240 | main(int argc, char *argv[])
1240          FILE    *rcfp;
1241          int     nsbins;
1242          int     a, i;
1243 +                                        /* set global progname */
1244 +        fixargv0(argv[0]);
1245                                          /* screen rcontrib options */
1242        progname = argv[0];
1246          for (a = 1; a < argc-2; a++) {
1247                  int     na;
1248                                          /* check for argument expansion */
# Line 1255 | Line 1258 | main(int argc, char *argv[])
1258                  na = 1;
1259                  switch (argv[a][1]) {   /* !! Keep consistent !! */
1260                  case 'v':               /* verbose mode */
1261 <                        verbose = 1;
1261 >                        verbose ^= VERBO;
1262                          na = 0;
1263                          continue;
1264                  case 'f':               /* special case for -fo, -ff, etc. */
# Line 1285 | Line 1288 | main(int argc, char *argv[])
1288                          yrs = argv[++a];
1289                          na = 0;
1290                          continue;
1291 <                case 'c':               /* number of samples */
1292 <                        sampcnt = atoi(argv[++a]);
1293 <                        if (sampcnt <= 0)
1294 <                                goto userr;
1295 <                        na = 0;         /* we re-add this later */
1296 <                        continue;
1291 >                case 'c':               /* spectral sampling or count */
1292 >                        switch (argv[a][2]) {
1293 >                        case 's':
1294 >                                na = 2;
1295 >                                break;
1296 >                        case 'w':
1297 >                                na = 3;
1298 >                                break;
1299 >                        case '\0':
1300 >                                sampcnt = atoi(argv[++a]);
1301 >                                if (sampcnt <= 0)
1302 >                                        goto userr;
1303 >                                na = 0;         /* we re-add this later */
1304 >                                continue;
1305 >                        }
1306 >                        break;
1307                  case 'I':               /* only for pass-through mode */
1308                  case 'i':
1309                          iropt = argv[a];
1310                          na = 0;
1311                          continue;
1312                  case 'w':               /* options without arguments */
1313 <                        if (!argv[a][2] || strchr("+1tTyY", argv[a][2]) == NULL)
1314 <                                verbose = -1;
1313 >                        if (!argv[a][2])
1314 >                                verbose ^= NOWARN;
1315 >                        else if (strchr("+1tTyY", argv[a][2]) != NULL)
1316 >                                verbose &= ~NOWARN;
1317 >                        else
1318 >                                verbose |= NOWARN;
1319                          break;
1320                  case 'V':
1321                  case 'u':
# Line 1308 | Line 1325 | main(int argc, char *argv[])
1325                  case 'n':               /* options with 1 argument */
1326                  case 's':
1327                  case 'o':
1328 +                case 't':
1329                          na = 2;
1330                          break;
1331                  case 'b':               /* special case */
# Line 1402 | Line 1420 | main(int argc, char *argv[])
1420          curmod[0] = '\0';
1421          if (load_scene(sendfn, add_send_object) < 0)
1422                  return(1);
1423 <        if ((nsbins = prepare_sampler()) <= 0)
1423 >        if ((nsbins = prepare_sampler(&curparams)) <= 0)
1424                  return(1);
1425          CHECKARGC(3);                   /* add row count and octree */
1426          rcarg[nrcargs++] = "-y";
# Line 1417 | Line 1435 | main(int argc, char *argv[])
1435   #ifdef getc_unlocked
1436          flockfile(rcfp);
1437   #endif
1438 <        if (verbose > 0) {
1438 >        if (verbose & VERBO) {
1439                  fprintf(stderr, "%s: sampling %d directions", progname, nsbins);
1440                  if (curparams.nsurfs > 1)
1441                          fprintf(stderr, " (%d elements)\n", curparams.nsurfs);

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)