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.57 by greg, Tue Mar 19 10:48:05 2024 UTC vs.
Revision 2.63 by greg, Mon Oct 20 19:01:32 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 506 | Line 508 | finish_receiver(void)
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 {
# Line 517 | 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 903 | 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! */
911 >        if (p->slist == NULL) { /* missing sample surface! */
912                  fputs(progname, stderr);
913                  fputs(": no sender surface!\n", stderr);
914                  return(-1);
915          }
916                                          /* misplaced output file spec. */
917 <        if ((curparams.outfn != NULL) & (verbose >= 0))
917 >        if ((p->outfn != NULL) & !(verbose & NOWARN))
918                  fprintf(stderr, "%s: warning - ignoring output file in sender ('%s')\n",
919 <                                progname, curparams.outfn);
919 >                                progname, p->outfn);
920                                          /* check/set basis hemisphere */
921 <        if (!curparams.hemis[0]) {
921 >        if (!p->hemis[0]) {
922                  fputs(progname, stderr);
923                  fputs(": missing sender sampling type!\n", stderr);
924                  return(-1);
925          }
926 <        if (normalize(curparams.nrm) == 0) {
926 >        if (normalize(p->nrm) == 0) {
927                  fputs(progname, stderr);
928                  fputs(": undefined normal for sender sampling\n", stderr);
929                  return(-1);
930          }
931 <        if (normalize(curparams.vup) == 0) {
932 <                if (fabs(curparams.nrm[2]) < .7)
933 <                        curparams.vup[2] = 1;
931 >        if (normalize(p->vup) == 0) {
932 >                if (fabs(p->nrm[2]) < .7)
933 >                        p->vup[2] = 1;
934                  else
935 <                        curparams.vup[1] = 1;
935 >                        p->vup[1] = 1;
936          }
937 <        fcross(curparams.udir, curparams.vup, curparams.nrm);
938 <        if (normalize(curparams.udir) == 0) {
937 >        fcross(p->udir, p->vup, p->nrm);
938 >        if (normalize(p->udir) == 0) {
939                  fputs(progname, stderr);
940                  fputs(": up vector coincides with sender normal\n", stderr);
941                  return(-1);
942          }
943 <        fcross(curparams.vdir, curparams.nrm, curparams.udir);
944 <        if (curparams.sign == '-') {    /* left-handed coordinate system? */
945 <                curparams.udir[0] *= -1.;
946 <                curparams.udir[1] *= -1.;
947 <                curparams.udir[2] *= -1.;
943 >        fcross(p->vdir, p->nrm, p->udir);
944 >        if (p->sign == '-') {   /* left-handed coordinate system? */
945 >                p->udir[0] *= -1.;
946 >                p->udir[1] *= -1.;
947 >                p->udir[2] *= -1.;
948          }
949 <        if ((tolower(curparams.hemis[0]) == 'u') | (curparams.hemis[0] == '1'))
950 <                curparams.sample_basis = sample_uniform;
951 <        else if (tolower(curparams.hemis[0]) == 's' &&
952 <                                tolower(curparams.hemis[1]) == 'c')
953 <                curparams.sample_basis = sample_shirchiu;
954 <        else if ((tolower(curparams.hemis[0]) == 'r') |
955 <                        (tolower(curparams.hemis[0]) == 't'))
956 <                curparams.sample_basis = sample_reinhart;
957 <        else if (tolower(curparams.hemis[0]) == 'k') {
958 <                switch (curparams.hemis[1]) {
949 >        if ((tolower(p->hemis[0]) == 'u') | (p->hemis[0] == '1'))
950 >                p->sample_basis = sample_uniform;
951 >        else if (tolower(p->hemis[0]) == 's' &&
952 >                                tolower(p->hemis[1]) == 'c')
953 >                p->sample_basis = sample_shirchiu;
954 >        else if ((tolower(p->hemis[0]) == 'r') |
955 >                        (tolower(p->hemis[0]) == 't'))
956 >                p->sample_basis = sample_reinhart;
957 >        else if (tolower(p->hemis[0]) == 'k') {
958 >                switch (p->hemis[1]) {
959                  case '1':
960                  case '2':
961                  case '4':
# Line 960 | Line 963 | prepare_sampler(void)
963                  case 'f':
964                  case 'F':
965                  case '\0':
966 <                        curparams.hemis[1] = '1';
966 >                        p->hemis[1] = '1';
967                          break;
968                  case 'h':
969                  case 'H':
970 <                        curparams.hemis[1] = '2';
970 >                        p->hemis[1] = '2';
971                          break;
972                  case 'q':
973                  case 'Q':
974 <                        curparams.hemis[1] = '4';
974 >                        p->hemis[1] = '4';
975                          break;
976                  default:
977                          goto unrecognized;
978                  }
979 <                curparams.hemis[2] = '\0';
980 <                curparams.sample_basis = sample_klems;
979 >                p->hemis[2] = '\0';
980 >                p->sample_basis = sample_klems;
981          } else
982                  goto unrecognized;
983                                          /* return number of bins */
984 <        return((*curparams.sample_basis)(&curparams,0,NULL));
984 >        return((*p->sample_basis)(p,0,NULL));
985   unrecognized:
986          fprintf(stderr, "%s: unrecognized sender sampling: h=%s\n",
987 <                        progname, curparams.hemis);
987 >                        progname, p->hemis);
988          return(-1);
989   }
990  
# Line 1067 | Line 1070 | add_surface(int st, const char *oname, FILE *fp)
1070                  snew->area *= PI*snew->area;
1071                  break;
1072          }
1073 <        if ((snew->area <= FTINY*FTINY) & (verbose >= 0)) {
1073 >        if ((snew->area <= FTINY*FTINY) & !(verbose & NOWARN)) {
1074                  fprintf(stderr, "%s: warning - zero area for surface '%s'\n",
1075                                  progname, oname);
1076                  free(snew);
# Line 1104 | Line 1107 | add_recv_object(FILE *fp)
1107          }
1108                                          /* is it a new receiver? */
1109          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                }
1110                  if (strcmp(thismod, curmod)) {
1111                          if (curmod[0]) {        /* output last receiver? */
1112                                  finish_receiver();
# Line 1245 | Line 1242 | main(int argc, char *argv[])
1242          FILE    *rcfp;
1243          int     nsbins;
1244          int     a, i;
1245 +                                        /* set global progname */
1246 +        fixargv0(argv[0]);
1247                                          /* screen rcontrib options */
1249        progname = argv[0];
1248          for (a = 1; a < argc-2; a++) {
1249                  int     na;
1250                                          /* check for argument expansion */
# Line 1262 | Line 1260 | main(int argc, char *argv[])
1260                  na = 1;
1261                  switch (argv[a][1]) {   /* !! Keep consistent !! */
1262                  case 'v':               /* verbose mode */
1263 <                        verbose = 1;
1263 >                        verbose ^= VERBO;
1264                          na = 0;
1265                          continue;
1266                  case 'f':               /* special case for -fo, -ff, etc. */
# Line 1314 | Line 1312 | main(int argc, char *argv[])
1312                          na = 0;
1313                          continue;
1314                  case 'w':               /* options without arguments */
1315 <                        if (!argv[a][2] || strchr("+1tTyY", argv[a][2]) == NULL)
1316 <                                verbose = -1;
1315 >                        if (!argv[a][2])
1316 >                                verbose ^= NOWARN;
1317 >                        else if (strchr("+1tTyY", argv[a][2]) != NULL)
1318 >                                verbose &= ~NOWARN;
1319 >                        else
1320 >                                verbose |= NOWARN;
1321                          break;
1322                  case 'V':
1323                  case 'u':
# Line 1420 | Line 1422 | main(int argc, char *argv[])
1422          curmod[0] = '\0';
1423          if (load_scene(sendfn, add_send_object) < 0)
1424                  return(1);
1425 <        if ((nsbins = prepare_sampler()) <= 0)
1425 >        if ((nsbins = prepare_sampler(&curparams)) <= 0)
1426                  return(1);
1427          CHECKARGC(3);                   /* add row count and octree */
1428          rcarg[nrcargs++] = "-y";
# Line 1435 | Line 1437 | main(int argc, char *argv[])
1437   #ifdef getc_unlocked
1438          flockfile(rcfp);
1439   #endif
1440 <        if (verbose > 0) {
1440 >        if (verbose & VERBO) {
1441                  fprintf(stderr, "%s: sampling %d directions", progname, nsbins);
1442                  if (curparams.nsurfs > 1)
1443                          fprintf(stderr, " (%d elements)\n", curparams.nsurfs);

Diff Legend

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