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.2 by greg, Fri Jan 19 00:00:13 1990 UTC vs.
Revision 2.6 by greg, Sun Feb 27 10:17:33 1994 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 12 | Line 12 | static char SCCSid[] = "$SunId$ LBL";
12  
13   #include  <stdio.h>
14  
15 + #ifdef MSDOS
16 + #include  <fcntl.h>
17 + #endif
18 +
19   #include  "color.h"
20  
21 + #include  "ambient.h"
22  
18 typedef double  FVECT[3];
23  
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
24   int  dataonly = 0;
25 <
25 > int  header = 1;
26   int  reverse = 0;
27  
28   AMBVAL  av;
29  
30  
31   main(argc, argv)                /* load ambient values from a file */
32 + int  argc;
33   char  *argv[];
34   {
35          FILE  *fp;
# Line 49 | Line 44 | char  *argv[];
44                          case 'r':
45                                  reverse = 1;
46                                  break;
47 +                        case 'h':
48 +                                header = 0;
49 +                                break;
50                          default:
51                                  fprintf(stderr, "%s: unknown option '%s'\n",
52                                                  argv[0], argv[i]);
# Line 63 | Line 61 | char  *argv[];
61                  fprintf(stderr, "%s: file not found\n", argv[i]);
62                  return(1);
63          }
64 <        if (reverse)
64 >        if (reverse) {
65 >                if (header) {
66 >                        if (checkheader(fp, "ascii", stdout) < 0)
67 >                                goto formaterr;
68 >                } else {
69 >                        newheader("RADIANCE", stdout);
70 >                        printargs(argc, argv, stdout);
71 >                }
72 >                fputformat(AMBFMT, stdout);
73 >                putchar('\n');
74 > #ifdef MSDOS
75 >                setmode(fileno(stdout), O_BINARY);
76 > #endif
77 >                putambmagic(stdout);
78                  writamb(fp);
79 <        else
79 >        } else {
80 > #ifdef MSDOS
81 >                setmode(fileno(fp), O_BINARY);
82 > #endif
83 >                if (checkheader(fp, AMBFMT, header ? stdout : (FILE *)NULL) < 0)
84 >                        goto formaterr;
85 >                if (!hasambmagic(fp))
86 >                        goto formaterr;
87 >                if (header) {
88 >                        fputformat("ascii", stdout);
89 >                        putchar('\n');
90 >                }
91                  lookamb(fp);
92 +        }
93          fclose(fp);
94          return(0);
95 + formaterr:
96 +        fprintf(stderr, "%s: format error on input\n", argv[0]);
97 +        exit(1);
98   }
99  
100  
101   lookamb(fp)                     /* get ambient values from a file */
102   FILE  *fp;
103   {
104 <        while (fread((char *)&av, sizeof(AMBVAL), 1, fp) == 1) {
104 >        while (readambval(&av, fp)) {
105                  if (dataonly) {
106                          printf("%f\t%f\t%f\t", av.pos[0], av.pos[1], av.pos[2]);
107                          printf("%f\t%f\t%f\t", av.dir[0], av.dir[1], av.dir[2]);
108                          printf("%d\t%f\t%f\t", av.lvl, av.weight, av.rad);
109 <                        printf("%e\t%e\t%e\n", colval(av.val,RED),
109 >                        printf("%e\t%e\t%e\t", colval(av.val,RED),
110                                                  colval(av.val,GRN),
111                                                  colval(av.val,BLU));
112 +                        printf("%f\t%f\t%f\t", av.gpos[0],
113 +                                        av.gpos[1], av.gpos[2]);
114 +                        printf("%f\t%f\t%f\n", av.gdir[0],
115 +                                        av.gdir[1], av.gdir[2]);
116                  } else {
117                          printf("\nPosition:\t%f\t%f\t%f\n", av.pos[0],
118                                          av.pos[1], av.pos[2]);
# Line 92 | Line 122 | FILE  *fp;
122                                          av.weight, av.rad);
123                          printf("Value:\t\t%e\t%e\t%e\n", colval(av.val,RED),
124                                          colval(av.val,GRN), colval(av.val,BLU));
125 +                        printf("Pos.Grad:\t%f\t%f\t%f\n", av.gpos[0],
126 +                                        av.gpos[1], av.gpos[2]);
127 +                        printf("Dir.Grad:\t%f\t%f\t%f\n", av.gdir[0],
128 +                                        av.gdir[1], av.gdir[2]);
129                  }
130                  if (ferror(stdout))
131                          exit(1);
# Line 105 | Line 139 | FILE  *fp;
139          for ( ; ; ) {
140                  if (!dataonly)
141                          fscanf(fp, "%*s");
142 <                if (fscanf(fp, "%lf %lf %lf",
142 >                if (fscanf(fp, "%f %f %f",
143                                  &av.pos[0], &av.pos[1], &av.pos[2]) != 3)
144                          return;
145                  if (!dataonly)
146                          fscanf(fp, "%*s");
147 <                if (fscanf(fp, "%lf %lf %lf",
147 >                if (fscanf(fp, "%f %f %f",
148                                  &av.dir[0], &av.dir[1], &av.dir[2]) != 3)
149                          return;
150                  if (!dataonly)
# Line 123 | Line 157 | FILE  *fp;
157                  if (fscanf(fp, "%f %f %f",
158                                  &av.val[RED], &av.val[GRN], &av.val[BLU]) != 3)
159                          return;
160 <                fwrite((char *)&av, sizeof(AMBVAL), 1, stdout);
160 >                if (!dataonly)
161 >                        fscanf(fp, "%*s");
162 >                if (fscanf(fp, "%f %f %f",
163 >                                &av.gpos[0], &av.gpos[1], &av.gpos[2]) != 3)
164 >                        return;
165 >                if (!dataonly)
166 >                        fscanf(fp, "%*s");
167 >                if (fscanf(fp, "%f %f %f",
168 >                                &av.gdir[0], &av.gdir[1], &av.gdir[2]) != 3)
169 >                        return;
170 >                av.next = NULL;
171 >                writambval(&av, stdout);
172                  if (ferror(stdout))
173                          exit(1);
174          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines