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.7 by greg, Sat Feb 22 02:07:28 2003 UTC vs.
Revision 2.19 by greg, Mon Dec 18 20:19:48 2023 UTC

# Line 5 | Line 5 | static const char      RCSid[] = "$Id$";
5   *  lookamb.c - program to examine ambient components.
6   */
7  
8 < /* ====================================================================
9 < * The Radiance Software License, Version 1.0
10 < *
11 < * Copyright (c) 1990 - 2002 The Regents of the University of California,
12 < * through Lawrence Berkeley National Laboratory.   All rights reserved.
13 < *
14 < * Redistribution and use in source and binary forms, with or without
15 < * modification, are permitted provided that the following conditions
16 < * are met:
17 < *
18 < * 1. Redistributions of source code must retain the above copyright
19 < *         notice, this list of conditions and the following disclaimer.
20 < *
21 < * 2. Redistributions in binary form must reproduce the above copyright
22 < *       notice, this list of conditions and the following disclaimer in
23 < *       the documentation and/or other materials provided with the
24 < *       distribution.
25 < *
26 < * 3. The end-user documentation included with the redistribution,
27 < *           if any, must include the following acknowledgment:
28 < *             "This product includes Radiance software
29 < *                 (http://radsite.lbl.gov/)
30 < *                 developed by the Lawrence Berkeley National Laboratory
31 < *               (http://www.lbl.gov/)."
32 < *       Alternately, this acknowledgment may appear in the software itself,
33 < *       if and wherever such third-party acknowledgments normally appear.
34 < *
35 < * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
36 < *       and "The Regents of the University of California" must
37 < *       not be used to endorse or promote products derived from this
38 < *       software without prior written permission. For written
39 < *       permission, please contact [email protected].
40 < *
41 < * 5. Products derived from this software may not be called "Radiance",
42 < *       nor may "Radiance" appear in their name, without prior written
43 < *       permission of Lawrence Berkeley National Laboratory.
44 < *
45 < * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
46 < * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
47 < * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48 < * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
49 < * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50 < * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
51 < * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
52 < * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
53 < * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
54 < * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
55 < * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 < * SUCH DAMAGE.
57 < * ====================================================================
58 < *
59 < * This software consists of voluntary contributions made by many
60 < * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
61 < * information on Lawrence Berkeley National Laboratory, please see
62 < * <http://www.lbl.gov/>.
63 < */
8 > #include "copyright.h"
9  
10 + #include  "platform.h"
11   #include  "ray.h"
66
12   #include  "ambient.h"
13  
14  
# Line 74 | Line 19 | int  reverse = 0;
19   AMBVAL  av;
20  
21  
22 < main(argc, argv)                /* load ambient values from a file */
23 < int  argc;
24 < char  *argv[];
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(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\t", av.gdir[0], av.gdir[1]);
45 +                        printf("%u\n", av.corral);
46 +                } else {
47 +                        printf("Position:\t%f\t%f\t%f\n", av.pos[0],
48 +                                        av.pos[1], av.pos[2]);
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,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(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);
63 +        }
64 + }
65 +
66 +
67 + static void
68 + writamb(                        /* write binary ambient values to stdout */
69 +        FILE  *fp
70 + )
71 + {
72 +        FVECT   norm;
73 +        COLOR   avcol;
74 +
75 +        for ( ; ; ) {
76 +                if (!dataonly)
77 +                        fscanf(fp, "%*s");
78 +                if (fscanf(fp, "%f %f %f",
79 +                                &av.pos[0], &av.pos[1], &av.pos[2]) != 3)
80 +                        return;
81 +                if (!dataonly)
82 +                        fscanf(fp, "%*s");
83 +                if (fscanf(fp, FVFORMAT, &norm[0], &norm[1], &norm[2]) != 3 ||
84 +                                normalize(norm) == 0)
85 +                        return;
86 +                av.ndir = encodedir(norm);
87 +                if (!dataonly)
88 +                        fscanf(fp, "%*s");
89 +                if (fscanf(fp, FVFORMAT, &norm[0], &norm[1], &norm[2]) != 3 ||
90 +                                normalize(norm) == 0)
91 +                        return;
92 +                av.udir = encodedir(norm);
93 +                if (!dataonly)
94 +                        fscanf(fp, "%*s");
95 +                if (fscanf(fp, "%hd %f %f %f", &av.lvl, &av.weight,
96 +                                &av.rad[0], &av.rad[1]) != 4)
97 +                        return;
98 +                if (!dataonly)
99 +                        fscanf(fp, "%*s");
100 +                if (fscanf(fp, "%f %f %f",
101 +                                &avcol[RED], &avcol[GRN], &avcol[BLU]) != 3)
102 +                        return;
103 +                setscolor(av.val, avcol[RED], avcol[GRN], avcol[BLU]);
104 +                if (!dataonly)
105 +                        fscanf(fp, "%*s");
106 +                if (fscanf(fp, "%f %f", &av.gpos[0], &av.gpos[1]) != 2)
107 +                        return;
108 +                if (!dataonly)
109 +                        fscanf(fp, "%*s");
110 +                if (fscanf(fp, "%f %f", &av.gdir[0], &av.gdir[1]) != 2)
111 +                        return;
112 +                if (dataonly) {
113 +                        if (fscanf(fp, "%u", &av.corral) != 1)
114 +                                return;
115 +                } else if (fscanf(fp, "%*s %X", &av.corral) != 1)
116 +                        return;
117 +                av.next = NULL;
118 +                if (writambval(&av, stdout) < 0)
119 +                        exit(1);
120 +        }
121 + }
122 +
123 +
124 + int
125 + main(           /* load ambient values from a file */
126 +        int  argc,
127 +        char  *argv[]
128 + )
129 + {
130          FILE  *fp;
131          int  i;
132  
# Line 108 | Line 157 | char  *argv[];
157                  return(1);
158          }
159          if (reverse) {
160 +                SET_FILE_BINARY(stdout);
161                  if (header) {
162                          if (checkheader(fp, "ascii", stdout) < 0)
163                                  goto formaterr;
# Line 115 | Line 165 | char  *argv[];
165                          newheader("RADIANCE", stdout);
166                          printargs(argc, argv, stdout);
167                  }
168 +                fputncomp(3, stdout);
169                  fputformat(AMBFMT, stdout);
170 <                putchar('\n');
120 < #ifdef MSDOS
121 <                setmode(fileno(stdout), O_BINARY);
122 < #endif
170 >                fputc('\n', stdout);
171                  putambmagic(stdout);
172                  writamb(fp);
173          } else {
174 < #ifdef MSDOS
175 <                setmode(fileno(fp), O_BINARY);
128 < #endif
129 <                if (checkheader(fp, AMBFMT, header ? stdout : (FILE *)NULL) < 0)
174 >                SET_FILE_BINARY(fp);
175 >                if (getheader(fp, amb_headline, header ? stdout : (FILE *)NULL) < 0)
176                          goto formaterr;
177                  if (!hasambmagic(fp))
178                          goto formaterr;
179                  if (header) {
180                          fputformat("ascii", stdout);
181 <                        putchar('\n');
181 >                        fputc('\n', stdout);
182                  }
183                  lookamb(fp);
184          }
# Line 141 | Line 187 | char  *argv[];
187   formaterr:
188          fprintf(stderr, "%s: format error on input\n", argv[0]);
189          exit(1);
144 }
145
146
147 void
148 lookamb(fp)                     /* get ambient values from a file */
149 FILE  *fp;
150 {
151        while (readambval(&av, fp)) {
152                if (dataonly) {
153                        printf("%f\t%f\t%f\t", av.pos[0], av.pos[1], av.pos[2]);
154                        printf("%f\t%f\t%f\t", av.dir[0], av.dir[1], av.dir[2]);
155                        printf("%d\t%f\t%f\t", av.lvl, av.weight, av.rad);
156                        printf("%e\t%e\t%e\t", colval(av.val,RED),
157                                                colval(av.val,GRN),
158                                                colval(av.val,BLU));
159                        printf("%f\t%f\t%f\t", av.gpos[0],
160                                        av.gpos[1], av.gpos[2]);
161                        printf("%f\t%f\t%f\n", av.gdir[0],
162                                        av.gdir[1], av.gdir[2]);
163                } else {
164                        printf("\nPosition:\t%f\t%f\t%f\n", av.pos[0],
165                                        av.pos[1], av.pos[2]);
166                        printf("Direction:\t%f\t%f\t%f\n", av.dir[0],
167                                        av.dir[1], av.dir[2]);
168                        printf("Lvl,Wt,Rad:\t%d\t\t%f\t%f\n", av.lvl,
169                                        av.weight, av.rad);
170                        printf("Value:\t\t%e\t%e\t%e\n", colval(av.val,RED),
171                                        colval(av.val,GRN), colval(av.val,BLU));
172                        printf("Pos.Grad:\t%f\t%f\t%f\n", av.gpos[0],
173                                        av.gpos[1], av.gpos[2]);
174                        printf("Dir.Grad:\t%f\t%f\t%f\n", av.gdir[0],
175                                        av.gdir[1], av.gdir[2]);
176                }
177                if (ferror(stdout))
178                        exit(1);
179        }
180 }
181
182
183 void
184 writamb(fp)                     /* write binary ambient values */
185 FILE  *fp;
186 {
187        for ( ; ; ) {
188                if (!dataonly)
189                        fscanf(fp, "%*s");
190                if (fscanf(fp, "%f %f %f",
191                                &av.pos[0], &av.pos[1], &av.pos[2]) != 3)
192                        return;
193                if (!dataonly)
194                        fscanf(fp, "%*s");
195                if (fscanf(fp, "%f %f %f",
196                                &av.dir[0], &av.dir[1], &av.dir[2]) != 3)
197                        return;
198                if (!dataonly)
199                        fscanf(fp, "%*s");
200                if (fscanf(fp, "%d %f %f",
201                                &av.lvl, &av.weight, &av.rad) != 3)
202                        return;
203                if (!dataonly)
204                        fscanf(fp, "%*s");
205                if (fscanf(fp, "%f %f %f",
206                                &av.val[RED], &av.val[GRN], &av.val[BLU]) != 3)
207                        return;
208                if (!dataonly)
209                        fscanf(fp, "%*s");
210                if (fscanf(fp, "%f %f %f",
211                                &av.gpos[0], &av.gpos[1], &av.gpos[2]) != 3)
212                        return;
213                if (!dataonly)
214                        fscanf(fp, "%*s");
215                if (fscanf(fp, "%f %f %f",
216                                &av.gdir[0], &av.gdir[1], &av.gdir[2]) != 3)
217                        return;
218                av.next = NULL;
219                writambval(&av, stdout);
220                if (ferror(stdout))
221                        exit(1);
222        }
190   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines