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.4 by greg, Thu Oct 15 21:13:13 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 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;
# Line 49 | Line 43 | char  *argv[];
43                          case 'r':
44                                  reverse = 1;
45                                  break;
46 +                        case 'h':
47 +                                header = 0;
48 +                                break;
49                          default:
50                                  fprintf(stderr, "%s: unknown option '%s'\n",
51                                                  argv[0], argv[i]);
# Line 63 | Line 60 | char  *argv[];
60                  fprintf(stderr, "%s: file not found\n", argv[i]);
61                  return(1);
62          }
63 <        if (reverse)
63 >        if (reverse) {
64 >                if (header) {
65 >                        if (checkheader(fp, "ascii", stdout) < 0)
66 >                                goto formaterr;
67 >                } else
68 >                        printargs(argc, argv, stdout);
69 >                fputformat(AMBFMT, stdout);
70 >                putchar('\n');
71 > #ifdef MSDOS
72 >                setmode(fileno(stdout), O_BINARY);
73 > #endif
74 >                putambmagic(stdout);
75                  writamb(fp);
76 <        else
76 >        } else {
77 > #ifdef MSDOS
78 >                setmode(fileno(fp), O_BINARY);
79 > #endif
80 >                if (checkheader(fp, AMBFMT, header ? stdout : (FILE *)NULL) < 0)
81 >                        goto formaterr;
82 >                if (!hasambmagic(fp))
83 >                        goto formaterr;
84 >                if (header) {
85 >                        fputformat("ascii", stdout);
86 >                        putchar('\n');
87 >                }
88                  lookamb(fp);
89 +        }
90          fclose(fp);
91          return(0);
92 + formaterr:
93 +        fprintf(stderr, "%s: format error on input\n", argv[0]);
94 +        exit(1);
95   }
96  
97  
98   lookamb(fp)                     /* get ambient values from a file */
99   FILE  *fp;
100   {
101 <        while (fread(&av, sizeof(AMBVAL), 1, fp) == 1) {
101 >        while (readambval(&av, fp)) {
102                  if (dataonly) {
103                          printf("%f\t%f\t%f\t", av.pos[0], av.pos[1], av.pos[2]);
104                          printf("%f\t%f\t%f\t", av.dir[0], av.dir[1], av.dir[2]);
105                          printf("%d\t%f\t%f\t", av.lvl, av.weight, av.rad);
106 <                        printf("%e\t%e\t%e\n", colval(av.val,RED),
106 >                        printf("%e\t%e\t%e\t", colval(av.val,RED),
107                                                  colval(av.val,GRN),
108                                                  colval(av.val,BLU));
109 +                        printf("%f\t%f\t%f\t", av.gpos[0],
110 +                                        av.gpos[1], av.gpos[2]);
111 +                        printf("%f\t%f\t%f\n", av.gdir[0],
112 +                                        av.gdir[1], av.gdir[2]);
113                  } else {
114                          printf("\nPosition:\t%f\t%f\t%f\n", av.pos[0],
115                                          av.pos[1], av.pos[2]);
# Line 92 | Line 119 | FILE  *fp;
119                                          av.weight, av.rad);
120                          printf("Value:\t\t%e\t%e\t%e\n", colval(av.val,RED),
121                                          colval(av.val,GRN), colval(av.val,BLU));
122 +                        printf("Pos.Grad:\t%f\t%f\t%f\n", av.gpos[0],
123 +                                        av.gpos[1], av.gpos[2]);
124 +                        printf("Dir.Grad:\t%f\t%f\t%f\n", av.gdir[0],
125 +                                        av.gdir[1], av.gdir[2]);
126                  }
127                  if (ferror(stdout))
128                          exit(1);
# Line 105 | Line 136 | FILE  *fp;
136          for ( ; ; ) {
137                  if (!dataonly)
138                          fscanf(fp, "%*s");
139 <                if (fscanf(fp, "%lf %lf %lf",
139 >                if (fscanf(fp, "%f %f %f",
140                                  &av.pos[0], &av.pos[1], &av.pos[2]) != 3)
141                          return;
142                  if (!dataonly)
143                          fscanf(fp, "%*s");
144 <                if (fscanf(fp, "%lf %lf %lf",
144 >                if (fscanf(fp, "%f %f %f",
145                                  &av.dir[0], &av.dir[1], &av.dir[2]) != 3)
146                          return;
147                  if (!dataonly)
# Line 123 | Line 154 | FILE  *fp;
154                  if (fscanf(fp, "%f %f %f",
155                                  &av.val[RED], &av.val[GRN], &av.val[BLU]) != 3)
156                          return;
157 <                fwrite(&av, sizeof(AMBVAL), 1, stdout);
157 >                if (!dataonly)
158 >                        fscanf(fp, "%*s");
159 >                if (fscanf(fp, "%f %f %f",
160 >                                &av.gpos[0], &av.gpos[1], &av.gpos[2]) != 3)
161 >                        return;
162 >                if (!dataonly)
163 >                        fscanf(fp, "%*s");
164 >                if (fscanf(fp, "%f %f %f",
165 >                                &av.gdir[0], &av.gdir[1], &av.gdir[2]) != 3)
166 >                        return;
167 >                av.next = NULL;
168 >                writambval(&av, stdout);
169                  if (ferror(stdout))
170                          exit(1);
171          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines