ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/ies2rad.c
(Generate patch)

Comparing ray/src/cv/ies2rad.c (file contents):
Revision 2.12 by greg, Tue Apr 25 21:37:14 1995 UTC vs.
Revision 2.17 by gregl, Mon Nov 10 10:13:58 1997 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1992 Regents of the University of California */
1 > /* Copyright (c) 1996 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 12 | Line 12 | static char SCCSid[] = "$SunId$ LBL";
12  
13   #include <stdio.h>
14   #include <math.h>
15 + #include <sys/types.h>
16   #include <ctype.h>
17   #include "color.h"
18   #include "paths.h"
# Line 108 | Line 109 | float  defcolor[3] = {1.,1.,1.};       /* default lamp color
109   float   *lampcolor = defcolor;          /* pointer to current lamp color */
110   double  multiplier = 1.0;               /* multiplier for all light sources */
111   char    units[64] = "meters";           /* output units */
112 + int     out2stdout = 0;                 /* put out to stdout r.t. file */
113   int     instantiate = 0;                /* instantiate geometry */
114   double  illumrad = 0.0;                 /* radius for illum sphere */
115  
# Line 126 | Line 128 | extern char    *strcpy(), *strcat(), *stradd(), *tailtrun
128                  *filename(), *libname(), *fullname(), *malloc(),
129                  *getword(), *atos();
130   extern float    *matchlamp();
131 + extern time_t   fdate();
132  
133   #define scnint(fp,ip)   cvtint(ip,getword(fp))
134   #define scnflt(fp,rp)   cvtflt(rp,getword(fp))
# Line 203 | Line 206 | char   *argv[];
206                  case 'f':               /* lamp data file */
207                          lampdat = argv[++i];
208                          break;
209 <                case 'o':               /* output file name */
209 >                case 'o':               /* output file root name */
210                          outfile = argv[++i];
211                          break;
212 +                case 's':               /* output to stdout */
213 +                        out2stdout = !out2stdout;
214 +                        break;
215                  case 'i':               /* illum */
216                          illumrad = atof(argv[++i]);
217                          break;
# Line 241 | Line 247 | char   *argv[];
247                          exit(ies2rad(NULL, outfile) == 0 ? 0 : 1);
248                  else if (i == argc-1)
249                          exit(ies2rad(argv[i], outfile) == 0 ? 0 : 1);
250 <                else {
251 <                        fprintf(stderr, "%s: single input file required\n",
246 <                                        argv[0]);
247 <                        exit(1);
248 <                }
250 >                else
251 >                        goto needsingle;
252          } else if (i >= argc) {
253                  fprintf(stderr, "%s: missing output file specification\n",
254                                  argv[0]);
255                  exit(1);
256          }
257 +        if (out2stdout && i != argc-1)
258 +                goto needsingle;
259          status = 0;
260          for ( ; i < argc; i++) {
261                  tailtrunc(strcpy(outname,filename(argv[i])));
# Line 258 | Line 263 | char   *argv[];
263                          status = 1;
264          }
265          exit(status);
266 + needsingle:
267 +        fprintf(stderr, "%s: single input file required\n", argv[0]);
268 +        exit(1);
269   }
270  
271  
# Line 464 | Line 472 | char   *inpname, *outname;
472                  perror(inpname);
473                  return(-1);
474          }
475 <        if ((outfp = fopen(fullname(buf,outname,T_RAD), "w")) == NULL) {
475 >        if (out2stdout)
476 >                outfp = stdout;
477 >        else if ((outfp = fopen(fullname(buf,outname,T_RAD), "w")) == NULL) {
478                  perror(buf);
479                  fclose(inpfp);
480                  return(-1);
# Line 667 | Line 677 | char   *mod, *name;
677          else
678                  fprintf(out, "5 ");
679          fprintf(out, "%s %s source.cal ",
680 <                        sinf->type==SPHERE ? "corr" : "flatcorr",
680 >                        sinf->type==SPHERE ? "corr" :
681 >                        sinf->type==DISK ? "cylcorr" : "boxcorr",
682                          libname(buf,name,T_DST));
683          if (pmtype == PM_B) {
684                  if (FEQ(bounds[1][0],0.))
# Line 690 | Line 701 | char   *mod, *name;
701                  } else
702                          fprintf(out, "src_theta ");
703          }
704 <        fprintf(out, "\n0\n1 %g\n", sinf->mult);
704 >        if (sinf->type == SPHERE)
705 >                fprintf(out, "\n0\n1 %g\n", sinf->mult/sinf->area);
706 >        else if (sinf->type == DISK)
707 >                fprintf(out, "\n0\n3 %g %g %g\n", sinf->mult,
708 >                                sinf->l, sinf->h);
709 >        else
710 >                fprintf(out, "\n0\n4 %g %g %g %g\n", sinf->mult,
711 >                                sinf->l, sinf->w, sinf->h);
712          if (putsource(sinf, out, id, filename(name),
713                          bounds[0][0]<90., bounds[0][1]>90.) != 0)
714                  return(-1);
# Line 704 | Line 722 | FILE   *fp;
722   char    *mod, *name;
723   int     dolower, doupper;
724   {
725 <        char    buf[MAXWORD];
725 >        int     dosides = doupper && dolower && shp->h > MINDIM;
726 >        char    lname[MAXWORD];
727          
728 <        fprintf(fp, "\n%s %s %s_light\n", mod,
729 <                        shp->isillum ? "illum" : "light",
730 <                        name);
728 >        strcat(strcpy(lname, name), "_light");
729 >        fprintf(fp, "\n%s %s %s\n", mod,
730 >                        shp->isillum ? "illum" : "light", lname);
731          fprintf(fp, "0\n0\n3 %g %g %g\n",
732 <                        lampcolor[0]/shp->area,
714 <                        lampcolor[1]/shp->area,
715 <                        lampcolor[2]/shp->area);
716 <        if (doupper && dolower && shp->type != SPHERE && shp->h > MINDIM)
717 <                if (shp->isillum) {
718 <                        fprintf(fp, "\nvoid illum %s_glow\n", name);
719 <                        fprintf(fp, "0\n0\n3 0 0 0\n");
720 <                } else {
721 <                        fprintf(fp, "\n%s glow %s_glow\n", mod, name);
722 <                        fprintf(fp, "0\n0\n4 %g %g %g -1\n",
723 <                                        lampcolor[0]/shp->area,
724 <                                        lampcolor[1]/shp->area,
725 <                                        lampcolor[2]/shp->area);
726 <                }
732 >                        lampcolor[0], lampcolor[1], lampcolor[2]);
733          switch (shp->type) {
734          case RECT:
729                strcat(strcpy(buf, name), "_light");
735                  if (dolower)
736 <                        putrectsrc(shp, fp, buf, name, 0);
736 >                        putrectsrc(shp, fp, lname, name, 0);
737                  if (doupper)
738 <                        putrectsrc(shp, fp, buf, name, 1);
739 <                if (doupper && dolower && shp->h > MINDIM) {
740 <                        strcat(strcpy(buf, name), "_glow");
736 <                        putsides(shp, fp, buf, name);
737 <                }
738 >                        putrectsrc(shp, fp, lname, name, 1);
739 >                if (dosides)
740 >                        putsides(shp, fp, lname, name);
741                  break;
742          case DISK:
740                strcat(strcpy(buf, name), "_light");
743                  if (dolower)
744 <                        putdisksrc(shp, fp, buf, name, 0);
744 >                        putdisksrc(shp, fp, lname, name, 0);
745                  if (doupper)
746 <                        putdisksrc(shp, fp, buf, name, 1);
747 <                if (doupper && dolower && shp->h > MINDIM) {
748 <                        strcat(strcpy(buf, name), "_glow");
747 <                        putcyl(shp, fp, buf, name);
748 <                }
746 >                        putdisksrc(shp, fp, lname, name, 1);
747 >                if (dosides)
748 >                        putcyl(shp, fp, lname, name);
749                  break;
750          case SPHERE:
751 <                strcat(strcpy(buf, name), "_light");
752 <                putspheresrc(shp, fp, buf, name);
751 >                putspheresrc(shp, fp, lname, name);
752                  break;
753          }
754          return(0);
# Line 969 | Line 968 | char *
968   getword(fp)                     /* scan a word from fp */
969   register FILE   *fp;
970   {
971 <        static char     word[MAXWORD];
971 >        static char     wrd[MAXWORD];
972          register char   *cp;
973          register int    c;
974  
975          while (isspace(c=getc(fp)))
976                  ;
977 <        for (cp = word; c != EOF && cp < word+MAXWORD-1;
977 >        for (cp = wrd; c != EOF && cp < wrd+MAXWORD-1;
978                          *cp++ = c, c = getc(fp))
979                  if (isspace(c) || c == ',') {
980                          while (isspace(c))
# Line 983 | Line 982 | register FILE  *fp;
982                          if (c != EOF & c != ',')
983                                  ungetc(c, fp);
984                          *cp = '\0';
985 <                        return(word);
985 >                        return(wrd);
986                  }
987          *cp = '\0';
988 <        return(cp > word ? word : NULL);
988 >        return(cp > wrd ? wrd : NULL);
989   }
990  
991  
992 < cvtint(ip, word)                /* convert a word to an integer */
992 > cvtint(ip, wrd)                 /* convert a word to an integer */
993   int     *ip;
994 < char    *word;
994 > char    *wrd;
995   {
996 <        if (word == NULL || !isint(word))
996 >        if (wrd == NULL || !isint(wrd))
997                  return(0);
998 <        *ip = atoi(word);
998 >        *ip = atoi(wrd);
999          return(1);
1000   }
1001  
1002  
1003 < cvtflt(rp, word)                /* convert a word to a double */
1003 > cvtflt(rp, wrd)                 /* convert a word to a double */
1004   double  *rp;
1005 < char    *word;
1005 > char    *wrd;
1006   {
1007 <        if (word == NULL || !isflt(word))
1007 >        if (wrd == NULL || !isflt(wrd))
1008                  return(0);
1009 <        *rp = atof(word);
1009 >        *rp = atof(wrd);
1010          return(1);
1011   }
1012  
# Line 1040 | Line 1039 | FILE   *outfp;                 /* close output file upon return */
1039                  strcpy(cp, "| oconv - > ");
1040                  cp += 12;
1041                  fullname(cp,outname,T_OCT);
1042 <                if (system(buf)) {              /* create octree */
1042 >                if (fdate(inpname) > fdate(outname) &&
1043 >                                system(buf)) {          /* create octree */
1044                          fclose(outfp);
1045                          return(-1);
1046                  }
# Line 1054 | Line 1054 | FILE   *outfp;                 /* close output file upon return */
1054                  fprintf(outfp, "0\n0\n");
1055                  fclose(outfp);
1056          } else {                        /* else append to luminaire file */
1057                fclose(outfp);
1057                  if (!FEQ(meters2out, 1.0)) {    /* apply scalefactor */
1058                          sprintf(cp, "| xform -s %f ", meters2out);
1059                          cp += strlen(cp);
1060                  }
1061 <                strcpy(cp, ">> ");              /* append works for DOS? */
1062 <                cp += 3;
1063 <                fullname(cp,outname,T_RAD);
1061 >                if (!out2stdout) {
1062 >                        fclose(outfp);
1063 >                        strcpy(cp, ">> ");      /* append works for DOS? */
1064 >                        cp += 3;
1065 >                        fullname(cp,outname,T_RAD);
1066 >                }
1067                  if (system(buf))
1068                          return(-1);
1069          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines