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 2.11 by greg, Fri Apr 11 20:31:37 2014 UTC vs.
Revision 2.18 by greg, Wed Nov 15 18:02:52 2023 UTC

# Line 10 | Line 10 | static const char      RCSid[] = "$Id$";
10   #include  "platform.h"
11   #include  "ray.h"
12   #include  "ambient.h"
13 #include  "resolu.h"
13  
14  
15   int  dataonly = 0;
# Line 19 | Line 18 | int  reverse = 0;
18  
19   AMBVAL  av;
20  
22 #ifdef NEWAMB
21  
24
22   static void
23   lookamb(                        /* load & convert ambient values from a file */
24          FILE  *fp
25   )
26   {
27          FVECT   norm, uvec;
28 +        COLOR   avcol;
29  
30          while (readambval(&av, fp)) {
31                  decodedir(norm, av.ndir);
32                  decodedir(uvec, av.udir);
33 +                scolor2rgb(avcol, av.val, AMB_CNDX[3], AMB_WLPART);
34                  if (dataonly) {
35                          printf("%f\t%f\t%f\t", av.pos[0], av.pos[1], av.pos[2]);
36                          printf("%f\t%f\t%f\t", norm[0], norm[1], norm[2]);
37                          printf("%f\t%f\t%f\t", uvec[0], uvec[1], uvec[2]);
38                          printf("%d\t%f\t%f\t%f\t", av.lvl, av.weight,
39                                          av.rad[0], av.rad[1]);
40 <                        printf("%e\t%e\t%e\t", colval(av.val,RED),
41 <                                                colval(av.val,GRN),
42 <                                                colval(av.val,BLU));
40 >                        printf("%e\t%e\t%e\t", colval(avcol,RED),
41 >                                                colval(avcol,GRN),
42 >                                                colval(avcol,BLU));
43                          printf("%f\t%f\t", av.gpos[0], av.gpos[1]);
44 <                        printf("%f\t%f\n", av.gdir[0], av.gdir[1]);
44 >                        printf("%f\t%f\t", av.gdir[0], av.gdir[1]);
45 >                        printf("%u\n", av.corral);
46                  } else {
47 <                        printf("\nPosition:\t%f\t%f\t%f\n", av.pos[0],
47 >                        printf("Position:\t%f\t%f\t%f\n", av.pos[0],
48                                          av.pos[1], av.pos[2]);
49 <                        printf("Normal:\t%f\t%f\t%f\n",
49 >                        printf("Normal:\t\t%f\t%f\t%f\n",
50                                          norm[0], norm[1], norm[2]);
51                          printf("Uvector:\t%f\t%f\t%f\n",
52                                          uvec[0], uvec[1], uvec[2]);
53 <                        printf("Lvl,Wt,Urad,Vrad:\t%d\t\t%f\t%f\n", av.lvl,
53 >                        printf("Lvl,Wt,UVrad:\t%d\t\t%f\t%f\t%f\n", av.lvl,
54                                          av.weight, av.rad[0], av.rad[1]);
55 <                        printf("Value:\t\t%e\t%e\t%e\n", colval(av.val,RED),
56 <                                        colval(av.val,GRN), colval(av.val,BLU));
55 >                        printf("Value:\t\t%e\t%e\t%e\n", colval(avcol,RED),
56 >                                        colval(avcol,GRN), colval(avcol,BLU));
57                          printf("Pos.Grad:\t%f\t%f\n", av.gpos[0], av.gpos[1]);
58                          printf("Dir.Grad:\t%f\t%f\n", av.gdir[0], av.gdir[1]);
59 +                        printf("Corral:\t\t%8X\n\n", av.corral);
60                  }
61                  if (ferror(stdout))
62                          exit(1);
# Line 69 | Line 70 | writamb(                       /* write binary ambient values to stdout */
70   )
71   {
72          FVECT   norm;
73 +        COLOR   avcol;
74  
75          for ( ; ; ) {
76                  if (!dataonly)
# Line 88 | Line 90 | writamb(                       /* write binary ambient values to stdout */
90                  av.udir = encodedir(norm);
91                  if (!dataonly)
92                          fscanf(fp, "%*s");
93 <                if (fscanf(fp, "%d %f %f %f", &av.lvl, &av.weight,
93 >                if (fscanf(fp, "%hd %f %f %f", &av.lvl, &av.weight,
94                                  &av.rad[0], &av.rad[1]) != 4)
95                          return;
96                  if (!dataonly)
97                          fscanf(fp, "%*s");
98                  if (fscanf(fp, "%f %f %f",
99 <                                &av.val[RED], &av.val[GRN], &av.val[BLU]) != 3)
99 >                                &avcol[RED], &avcol[GRN], &avcol[BLU]) != 3)
100                          return;
101 +                setscolor(av.val, avcol[RED], avcol[GRN], avcol[BLU]);
102                  if (!dataonly)
103                          fscanf(fp, "%*s");
104                  if (fscanf(fp, "%f %f", &av.gpos[0], &av.gpos[1]) != 2)
# Line 104 | Line 107 | writamb(                       /* write binary ambient values to stdout */
107                          fscanf(fp, "%*s");
108                  if (fscanf(fp, "%f %f", &av.gdir[0], &av.gdir[1]) != 2)
109                          return;
107                av.next = NULL;
108                writambval(&av, stdout);
109                if (ferror(stdout))
110                        exit(1);
111        }
112 }
113
114
115 #else /* ! NEWAMB */
116
117
118 static void
119 lookamb(                        /* get ambient values from a file */
120        FILE  *fp
121 )
122 {
123        while (readambval(&av, fp)) {
110                  if (dataonly) {
111 <                        printf("%f\t%f\t%f\t", av.pos[0], av.pos[1], av.pos[2]);
112 <                        printf("%f\t%f\t%f\t", av.dir[0], av.dir[1], av.dir[2]);
113 <                        printf("%d\t%f\t%f\t", av.lvl, av.weight, av.rad);
128 <                        printf("%e\t%e\t%e\t", colval(av.val,RED),
129 <                                                colval(av.val,GRN),
130 <                                                colval(av.val,BLU));
131 <                        printf("%f\t%f\t%f\t", av.gpos[0],
132 <                                        av.gpos[1], av.gpos[2]);
133 <                        printf("%f\t%f\t%f\n", av.gdir[0],
134 <                                        av.gdir[1], av.gdir[2]);
135 <                } else {
136 <                        printf("\nPosition:\t%f\t%f\t%f\n", av.pos[0],
137 <                                        av.pos[1], av.pos[2]);
138 <                        printf("Direction:\t%f\t%f\t%f\n", av.dir[0],
139 <                                        av.dir[1], av.dir[2]);
140 <                        printf("Lvl,Wt,Rad:\t%d\t\t%f\t%f\n", av.lvl,
141 <                                        av.weight, av.rad);
142 <                        printf("Value:\t\t%e\t%e\t%e\n", colval(av.val,RED),
143 <                                        colval(av.val,GRN), colval(av.val,BLU));
144 <                        printf("Pos.Grad:\t%f\t%f\t%f\n", av.gpos[0],
145 <                                        av.gpos[1], av.gpos[2]);
146 <                        printf("Dir.Grad:\t%f\t%f\t%f\n", av.gdir[0],
147 <                                        av.gdir[1], av.gdir[2]);
148 <                }
149 <                if (ferror(stdout))
150 <                        exit(1);
151 <        }
152 < }
153 <
154 <
155 < static void
156 < writamb(                        /* write binary ambient values */
157 <        FILE  *fp
158 < )
159 < {
160 <        for ( ; ; ) {
161 <                if (!dataonly)
162 <                        fscanf(fp, "%*s");
163 <                if (fscanf(fp, "%f %f %f",
164 <                                &av.pos[0], &av.pos[1], &av.pos[2]) != 3)
111 >                        if (fscanf(fp, "%u", &av.corral) != 1)
112 >                                return;
113 >                } else if (fscanf(fp, "%*s %X", &av.corral) != 1)
114                          return;
166                if (!dataonly)
167                        fscanf(fp, "%*s");
168                if (fscanf(fp, "%f %f %f",
169                                &av.dir[0], &av.dir[1], &av.dir[2]) != 3)
170                        return;
171                if (!dataonly)
172                        fscanf(fp, "%*s");
173                if (fscanf(fp, "%d %f %f",
174                                &av.lvl, &av.weight, &av.rad) != 3)
175                        return;
176                if (!dataonly)
177                        fscanf(fp, "%*s");
178                if (fscanf(fp, "%f %f %f",
179                                &av.val[RED], &av.val[GRN], &av.val[BLU]) != 3)
180                        return;
181                if (!dataonly)
182                        fscanf(fp, "%*s");
183                if (fscanf(fp, "%f %f %f",
184                                &av.gpos[0], &av.gpos[1], &av.gpos[2]) != 3)
185                        return;
186                if (!dataonly)
187                        fscanf(fp, "%*s");
188                if (fscanf(fp, "%f %f %f",
189                                &av.gdir[0], &av.gdir[1], &av.gdir[2]) != 3)
190                        return;
115                  av.next = NULL;
116 <                writambval(&av, stdout);
193 <                if (ferror(stdout))
116 >                if (writambval(&av, stdout) < 0)
117                          exit(1);
118          }
119   }
120  
121  
199 #endif  /* ! NEWAMB */
200
201
122   int
123   main(           /* load ambient values from a file */
124          int  argc,
# Line 235 | Line 155 | main(          /* load ambient values from a file */
155                  return(1);
156          }
157          if (reverse) {
158 +                SET_FILE_BINARY(stdout);
159                  if (header) {
160                          if (checkheader(fp, "ascii", stdout) < 0)
161                                  goto formaterr;
# Line 242 | Line 163 | main(          /* load ambient values from a file */
163                          newheader("RADIANCE", stdout);
164                          printargs(argc, argv, stdout);
165                  }
166 +                fputncomp(3, stdout);
167                  fputformat(AMBFMT, stdout);
168 <                putchar('\n');
247 <                SET_FILE_BINARY(stdout);
168 >                fputc('\n', stdout);
169                  putambmagic(stdout);
170                  writamb(fp);
171          } else {
172                  SET_FILE_BINARY(fp);
173 <                if (checkheader(fp, AMBFMT, header ? stdout : (FILE *)NULL) < 0)
173 >                if (getheader(fp, amb_headline, header ? stdout : (FILE *)NULL) < 0)
174                          goto formaterr;
175                  if (!hasambmagic(fp))
176                          goto formaterr;
177                  if (header) {
178                          fputformat("ascii", stdout);
179 <                        putchar('\n');
179 >                        fputc('\n', stdout);
180                  }
181                  lookamb(fp);
182          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines