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

Comparing ray/src/rt/lookamb.c (file contents):
Revision 1.1 by greg, Thu Feb 2 10:41:25 1989 UTC vs.
Revision 2.3 by greg, Thu Jul 16 12:08:44 1992 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 Regents of the University of California */
1 > /* Copyright (c) 1991 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 14 | Line 14 | static char SCCSid[] = "$SunId$ LBL";
14  
15   #include  "color.h"
16  
17 + #include  "ambient.h"
18  
18 typedef double  FVECT[3];
19  
20 typedef struct ambval {
21        FVECT  pos;             /* position in space */
22        FVECT  dir;             /* normal direction */
23        int  lvl;               /* recursion level of parent ray */
24        float  weight;          /* weight of parent ray */
25        COLOR  val;             /* computed ambient value */
26        float  rad;             /* validity radius */
27        struct ambval  *next;   /* next in list */
28 }  AMBVAL;                      /* ambient value */
29
20   int  dataonly = 0;
21 <
21 > int  header = 1;
22   int  reverse = 0;
23  
24   AMBVAL  av;
# Line 49 | Line 39 | char  *argv[];
39                          case 'r':
40                                  reverse = 1;
41                                  break;
42 +                        case 'h':
43 +                                header = 0;
44 +                                break;
45                          default:
46                                  fprintf(stderr, "%s: unknown option '%s'\n",
47                                                  argv[0], argv[i]);
# Line 63 | Line 56 | char  *argv[];
56                  fprintf(stderr, "%s: file not found\n", argv[i]);
57                  return(1);
58          }
59 <        if (reverse)
59 >        if (reverse) {
60 >                if (header) {
61 >                        if (checkheader(fp, "ascii", stdout) < 0)
62 >                                goto formaterr;
63 >                } else
64 >                        printargs(argc, argv, stdout);
65 >                fputformat(AMBFMT, stdout);
66 >                putchar('\n');
67 >                putambmagic(stdout);
68                  writamb(fp);
69 <        else
69 >        } else {
70 >                if (checkheader(fp, AMBFMT, header ? stdout : (FILE *)NULL) < 0)
71 >                        goto formaterr;
72 >                if (!hasambmagic(fp))
73 >                        goto formaterr;
74 >                if (header) {
75 >                        fputformat("ascii", stdout);
76 >                        putchar('\n');
77 >                }
78                  lookamb(fp);
79 +        }
80          fclose(fp);
81          return(0);
82 + formaterr:
83 +        fprintf(stderr, "%s: format error on input\n", argv[0]);
84 +        exit(1);
85   }
86  
87  
88   lookamb(fp)                     /* get ambient values from a file */
89   FILE  *fp;
90   {
91 <        while (fread(&av, sizeof(AMBVAL), 1, fp) == 1) {
91 >        while (readambval(&av, fp)) {
92                  if (dataonly) {
93                          printf("%f\t%f\t%f\t", av.pos[0], av.pos[1], av.pos[2]);
94                          printf("%f\t%f\t%f\t", av.dir[0], av.dir[1], av.dir[2]);
95                          printf("%d\t%f\t%f\t", av.lvl, av.weight, av.rad);
96 <                        printf("%e\t%e\t%e\n", colval(av.val,RED),
96 >                        printf("%e\t%e\t%e\t", colval(av.val,RED),
97                                                  colval(av.val,GRN),
98                                                  colval(av.val,BLU));
99 +                        printf("%f\t%f\t%f\t", av.gpos[0],
100 +                                        av.gpos[1], av.gpos[2]);
101 +                        printf("%f\t%f\t%f\n", av.gdir[0],
102 +                                        av.gdir[1], av.gdir[2]);
103                  } else {
104                          printf("\nPosition:\t%f\t%f\t%f\n", av.pos[0],
105                                          av.pos[1], av.pos[2]);
# Line 92 | Line 109 | FILE  *fp;
109                                          av.weight, av.rad);
110                          printf("Value:\t\t%e\t%e\t%e\n", colval(av.val,RED),
111                                          colval(av.val,GRN), colval(av.val,BLU));
112 +                        printf("Pos.Grad:\t%f\t%f\t%f\n", av.gpos[0],
113 +                                        av.gpos[1], av.gpos[2]);
114 +                        printf("Dir.Grad:\t%f\t%f\t%f\n", av.gdir[0],
115 +                                        av.gdir[1], av.gdir[2]);
116                  }
117                  if (ferror(stdout))
118                          exit(1);
# Line 105 | Line 126 | FILE  *fp;
126          for ( ; ; ) {
127                  if (!dataonly)
128                          fscanf(fp, "%*s");
129 <                if (fscanf(fp, "%lf %lf %lf",
129 >                if (fscanf(fp, "%f %f %f",
130                                  &av.pos[0], &av.pos[1], &av.pos[2]) != 3)
131                          return;
132                  if (!dataonly)
133                          fscanf(fp, "%*s");
134 <                if (fscanf(fp, "%lf %lf %lf",
134 >                if (fscanf(fp, "%f %f %f",
135                                  &av.dir[0], &av.dir[1], &av.dir[2]) != 3)
136                          return;
137                  if (!dataonly)
# Line 123 | Line 144 | FILE  *fp;
144                  if (fscanf(fp, "%f %f %f",
145                                  &av.val[RED], &av.val[GRN], &av.val[BLU]) != 3)
146                          return;
147 <                fwrite(&av, sizeof(AMBVAL), 1, stdout);
147 >                if (!dataonly)
148 >                        fscanf(fp, "%*s");
149 >                if (fscanf(fp, "%f %f %f",
150 >                                &av.gpos[0], &av.gpos[1], &av.gpos[2]) != 3)
151 >                        return;
152 >                if (!dataonly)
153 >                        fscanf(fp, "%*s");
154 >                if (fscanf(fp, "%f %f %f",
155 >                                &av.gdir[0], &av.gdir[1], &av.gdir[2]) != 3)
156 >                        return;
157 >                av.next = NULL;
158 >                writambval(&av, stdout);
159                  if (ferror(stdout))
160                          exit(1);
161          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines