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.56 by greg, Thu Feb 8 02:26:01 2024 UTC vs.
Revision 2.65 by greg, Wed Oct 22 20:00:17 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 44 | Line 45 | 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 109 | 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 141 | 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 192 | 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 211 | 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 230 | 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 275 | 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 448 | Line 450 | finish_receiver(void)
450          }
451                                          /* determine sample type/bin */
452          if ((tolower(curparams.hemis[0]) == 'u') | (curparams.hemis[0] == '1')) {
453 <                sprintf(sbuf, "if(-Dx*%g-Dy*%g-Dz*%g,0,-1)",
454 <                        curparams.nrm[0], curparams.nrm[1], curparams.nrm[2]);
455 <                binv = savqstr(sbuf);
453 >                if (curparams.slist->styp != ST_SOURCE) {
454 >                        sprintf(sbuf, "if(-Dx*%g-Dy*%g-Dz*%g,0,-1)",
455 >                                curparams.nrm[0], curparams.nrm[1], curparams.nrm[2]);
456 >                        binv = savqstr(sbuf);
457 >                } else
458 >                        binv = "0";
459                  nbins = "1";            /* uniform sampling -- one bin */
460                  uniform = 1;
461          } else if (tolower(curparams.hemis[0]) == 's' &&
# Line 506 | Line 511 | finish_receiver(void)
511                          curparams.nrm[0], curparams.nrm[1], curparams.nrm[2],
512                          curparams.vup[0], curparams.vup[1], curparams.vup[2],
513                          curparams.sign);
514 +                params = savqstr(sbuf);
515                  binv = "cbin";
516                  nbins = "Ncbins";
517          } else {
# Line 517 | Line 523 | finish_receiver(void)
523                  sprintf(sbuf, "RHS=%c1", curparams.sign);
524                  params = savqstr(sbuf);
525          }
526 <        if (!uniform & (curparams.slist->styp == ST_SOURCE)) {
526 >        if (!uniform) {
527                  SURF    *sp;
528                  for (sp = curparams.slist; sp != NULL; sp = sp->next)
529 <                        if (fabs(sp->area - PI) > 1e-3) {
529 >                        if (sp->styp == ST_SOURCE && fabs(sp->area - PI) > 1e-3) {
530                                  fprintf(stderr, "%s: source '%s' must be 180-degrees\n",
531                                                  progname, sp->sname);
532                                  exit(1);
# Line 903 | Line 909 | sample_klems(PARAMS *p, int b, FILE *fp)
909  
910   /* Prepare hemisphere basis sampler that will send rays to rcontrib */
911   static int
912 < prepare_sampler(void)
912 > prepare_sampler(PARAMS *p)
913   {
914 <        if (curparams.slist == NULL) {  /* missing sample surface! */
914 >        if (p->slist == NULL) { /* missing sample surface! */
915                  fputs(progname, stderr);
916                  fputs(": no sender surface!\n", stderr);
917                  return(-1);
918          }
919                                          /* misplaced output file spec. */
920 <        if ((curparams.outfn != NULL) & (verbose >= 0))
920 >        if ((p->outfn != NULL) & !(verbose & NOWARN))
921                  fprintf(stderr, "%s: warning - ignoring output file in sender ('%s')\n",
922 <                                progname, curparams.outfn);
922 >                                progname, p->outfn);
923                                          /* check/set basis hemisphere */
924 <        if (!curparams.hemis[0]) {
924 >        if (!p->hemis[0]) {
925                  fputs(progname, stderr);
926                  fputs(": missing sender sampling type!\n", stderr);
927                  return(-1);
928          }
929 <        if (normalize(curparams.nrm) == 0) {
929 >        if (normalize(p->nrm) == 0) {
930                  fputs(progname, stderr);
931                  fputs(": undefined normal for sender sampling\n", stderr);
932                  return(-1);
933          }
934 <        if (normalize(curparams.vup) == 0) {
935 <                if (fabs(curparams.nrm[2]) < .7)
936 <                        curparams.vup[2] = 1;
934 >        if (normalize(p->vup) == 0) {
935 >                if (fabs(p->nrm[2]) < .7)
936 >                        p->vup[2] = 1;
937                  else
938 <                        curparams.vup[1] = 1;
938 >                        p->vup[1] = 1;
939          }
940 <        fcross(curparams.udir, curparams.vup, curparams.nrm);
941 <        if (normalize(curparams.udir) == 0) {
940 >        fcross(p->udir, p->vup, p->nrm);
941 >        if (normalize(p->udir) == 0) {
942                  fputs(progname, stderr);
943                  fputs(": up vector coincides with sender normal\n", stderr);
944                  return(-1);
945          }
946 <        fcross(curparams.vdir, curparams.nrm, curparams.udir);
947 <        if (curparams.sign == '-') {    /* left-handed coordinate system? */
948 <                curparams.udir[0] *= -1.;
949 <                curparams.udir[1] *= -1.;
950 <                curparams.udir[2] *= -1.;
946 >        fcross(p->vdir, p->nrm, p->udir);
947 >        if (p->sign == '-') {   /* left-handed coordinate system? */
948 >                p->udir[0] *= -1.;
949 >                p->udir[1] *= -1.;
950 >                p->udir[2] *= -1.;
951          }
952 <        if ((tolower(curparams.hemis[0]) == 'u') | (curparams.hemis[0] == '1'))
953 <                curparams.sample_basis = sample_uniform;
954 <        else if (tolower(curparams.hemis[0]) == 's' &&
955 <                                tolower(curparams.hemis[1]) == 'c')
956 <                curparams.sample_basis = sample_shirchiu;
957 <        else if ((tolower(curparams.hemis[0]) == 'r') |
958 <                        (tolower(curparams.hemis[0]) == 't'))
959 <                curparams.sample_basis = sample_reinhart;
960 <        else if (tolower(curparams.hemis[0]) == 'k') {
961 <                switch (curparams.hemis[1]) {
952 >        if ((tolower(p->hemis[0]) == 'u') | (p->hemis[0] == '1'))
953 >                p->sample_basis = sample_uniform;
954 >        else if (tolower(p->hemis[0]) == 's' &&
955 >                                tolower(p->hemis[1]) == 'c')
956 >                p->sample_basis = sample_shirchiu;
957 >        else if ((tolower(p->hemis[0]) == 'r') |
958 >                        (tolower(p->hemis[0]) == 't'))
959 >                p->sample_basis = sample_reinhart;
960 >        else if (tolower(p->hemis[0]) == 'k') {
961 >                switch (p->hemis[1]) {
962                  case '1':
963                  case '2':
964                  case '4':
# Line 960 | Line 966 | prepare_sampler(void)
966                  case 'f':
967                  case 'F':
968                  case '\0':
969 <                        curparams.hemis[1] = '1';
969 >                        p->hemis[1] = '1';
970                          break;
971                  case 'h':
972                  case 'H':
973 <                        curparams.hemis[1] = '2';
973 >                        p->hemis[1] = '2';
974                          break;
975                  case 'q':
976                  case 'Q':
977 <                        curparams.hemis[1] = '4';
977 >                        p->hemis[1] = '4';
978                          break;
979                  default:
980                          goto unrecognized;
981                  }
982 <                curparams.hemis[2] = '\0';
983 <                curparams.sample_basis = sample_klems;
982 >                p->hemis[2] = '\0';
983 >                p->sample_basis = sample_klems;
984          } else
985                  goto unrecognized;
986                                          /* return number of bins */
987 <        return((*curparams.sample_basis)(&curparams,0,NULL));
987 >        return((*p->sample_basis)(p,0,NULL));
988   unrecognized:
989          fprintf(stderr, "%s: unrecognized sender sampling: h=%s\n",
990 <                        progname, curparams.hemis);
990 >                        progname, p->hemis);
991          return(-1);
992   }
993  
# Line 1067 | Line 1073 | add_surface(int st, const char *oname, FILE *fp)
1073                  snew->area *= PI*snew->area;
1074                  break;
1075          }
1076 <        if ((snew->area <= FTINY*FTINY) & (verbose >= 0)) {
1076 >        if ((snew->area <= FTINY*FTINY) & !(verbose & NOWARN)) {
1077                  fprintf(stderr, "%s: warning - zero area for surface '%s'\n",
1078                                  progname, oname);
1079                  free(snew);
# Line 1104 | Line 1110 | add_recv_object(FILE *fp)
1110          }
1111                                          /* is it a new receiver? */
1112          if ((st = surf_type(otype)) != ST_NONE) {
1107                if (curparams.slist != NULL && (st == ST_SOURCE) ^
1108                                (curparams.slist->styp == ST_SOURCE)) {
1109                        fputs(progname, stderr);
1110                        fputs(": cannot mix source/non-source receivers!\n", stderr);
1111                        return(-1);
1112                }
1113                  if (strcmp(thismod, curmod)) {
1114                          if (curmod[0]) {        /* output last receiver? */
1115                                  finish_receiver();
# Line 1245 | Line 1245 | main(int argc, char *argv[])
1245          FILE    *rcfp;
1246          int     nsbins;
1247          int     a, i;
1248 +                                        /* set global progname */
1249 +        fixargv0(argv[0]);
1250                                          /* screen rcontrib options */
1249        progname = argv[0];
1251          for (a = 1; a < argc-2; a++) {
1252                  int     na;
1253                                          /* check for argument expansion */
# Line 1262 | Line 1263 | main(int argc, char *argv[])
1263                  na = 1;
1264                  switch (argv[a][1]) {   /* !! Keep consistent !! */
1265                  case 'v':               /* verbose mode */
1266 <                        verbose = 1;
1266 >                        verbose ^= VERBO;
1267                          na = 0;
1268                          continue;
1269                  case 'f':               /* special case for -fo, -ff, etc. */
# Line 1305 | Line 1306 | main(int argc, char *argv[])
1306                                  if (sampcnt <= 0)
1307                                          goto userr;
1308                                  na = 0;         /* we re-add this later */
1309 <                                break;
1309 >                                continue;
1310                          }
1311 <                        continue;
1311 >                        break;
1312                  case 'I':               /* only for pass-through mode */
1313                  case 'i':
1314                          iropt = argv[a];
1315                          na = 0;
1316                          continue;
1317                  case 'w':               /* options without arguments */
1318 <                        if (!argv[a][2] || strchr("+1tTyY", argv[a][2]) == NULL)
1319 <                                verbose = -1;
1318 >                        if (!argv[a][2])
1319 >                                verbose ^= NOWARN;
1320 >                        else if (strchr("+1tTyY", argv[a][2]) != NULL)
1321 >                                verbose &= ~NOWARN;
1322 >                        else
1323 >                                verbose |= NOWARN;
1324                          break;
1325                  case 'V':
1326                  case 'u':
# Line 1420 | Line 1425 | main(int argc, char *argv[])
1425          curmod[0] = '\0';
1426          if (load_scene(sendfn, add_send_object) < 0)
1427                  return(1);
1428 <        if ((nsbins = prepare_sampler()) <= 0)
1428 >        if ((nsbins = prepare_sampler(&curparams)) <= 0)
1429                  return(1);
1430          CHECKARGC(3);                   /* add row count and octree */
1431          rcarg[nrcargs++] = "-y";
# Line 1435 | Line 1440 | main(int argc, char *argv[])
1440   #ifdef getc_unlocked
1441          flockfile(rcfp);
1442   #endif
1443 <        if (verbose > 0) {
1443 >        if (verbose & VERBO) {
1444                  fprintf(stderr, "%s: sampling %d directions", progname, nsbins);
1445                  if (curparams.nsurfs > 1)
1446                          fprintf(stderr, " (%d elements)\n", curparams.nsurfs);
# Line 1448 | Line 1453 | main(int argc, char *argv[])
1453          return(pclose_al(rcfp) < 0);    /* all finished! */
1454   userr:
1455          if (a < argc-2)
1456 <                fprintf(stderr, "%s: unsupported option '%s'", progname, argv[a]);
1456 >                fprintf(stderr, "%s: unsupported option '%s'\n", progname, argv[a]);
1457          fprintf(stderr, "Usage: %s [-v][rcontrib options] sender.rad receiver.rad [-i system.oct] [system.rad ..]\n",
1458                                  progname);
1459          return(1);

Diff Legend

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