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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines