| 1 |
– |
/* Copyright (c) 1986 Regents of the University of California */ |
| 2 |
– |
|
| 1 |
|
#ifndef lint |
| 2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
| 2 |
> |
static const char RCSid[] = "$Id$"; |
| 3 |
|
#endif |
| 6 |
– |
|
| 4 |
|
/* |
| 5 |
|
* lookamb.c - program to examine ambient components. |
| 9 |
– |
* |
| 10 |
– |
* 10/8/86 |
| 6 |
|
*/ |
| 7 |
|
|
| 8 |
< |
#include <stdio.h> |
| 8 |
> |
#include "copyright.h" |
| 9 |
|
|
| 10 |
< |
#include "color.h" |
| 10 |
> |
#include "platform.h" |
| 11 |
> |
#include "ray.h" |
| 12 |
> |
#include "ambient.h" |
| 13 |
> |
#include "resolu.h" |
| 14 |
|
|
| 15 |
|
|
| 18 |
– |
typedef double FVECT[3]; |
| 19 |
– |
|
| 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 |
– |
|
| 16 |
|
int dataonly = 0; |
| 17 |
< |
|
| 17 |
> |
int header = 1; |
| 18 |
|
int reverse = 0; |
| 19 |
|
|
| 20 |
|
AMBVAL av; |
| 21 |
|
|
| 22 |
|
|
| 23 |
< |
main(argc, argv) /* load ambient values from a file */ |
| 24 |
< |
char *argv[]; |
| 23 |
> |
int |
| 24 |
> |
main( /* load ambient values from a file */ |
| 25 |
> |
int argc, |
| 26 |
> |
char *argv[] |
| 27 |
> |
) |
| 28 |
|
{ |
| 29 |
|
FILE *fp; |
| 30 |
|
int i; |
| 38 |
|
case 'r': |
| 39 |
|
reverse = 1; |
| 40 |
|
break; |
| 41 |
+ |
case 'h': |
| 42 |
+ |
header = 0; |
| 43 |
+ |
break; |
| 44 |
|
default: |
| 45 |
|
fprintf(stderr, "%s: unknown option '%s'\n", |
| 46 |
|
argv[0], argv[i]); |
| 55 |
|
fprintf(stderr, "%s: file not found\n", argv[i]); |
| 56 |
|
return(1); |
| 57 |
|
} |
| 58 |
< |
if (reverse) |
| 58 |
> |
if (reverse) { |
| 59 |
> |
if (header) { |
| 60 |
> |
if (checkheader(fp, "ascii", stdout) < 0) |
| 61 |
> |
goto formaterr; |
| 62 |
> |
} else { |
| 63 |
> |
newheader("RADIANCE", stdout); |
| 64 |
> |
printargs(argc, argv, stdout); |
| 65 |
> |
} |
| 66 |
> |
fputformat(AMBFMT, stdout); |
| 67 |
> |
putchar('\n'); |
| 68 |
> |
SET_FILE_BINARY(stdout); |
| 69 |
> |
putambmagic(stdout); |
| 70 |
|
writamb(fp); |
| 71 |
< |
else |
| 71 |
> |
} else { |
| 72 |
> |
SET_FILE_BINARY(fp); |
| 73 |
> |
if (checkheader(fp, AMBFMT, header ? stdout : (FILE *)NULL) < 0) |
| 74 |
> |
goto formaterr; |
| 75 |
> |
if (!hasambmagic(fp)) |
| 76 |
> |
goto formaterr; |
| 77 |
> |
if (header) { |
| 78 |
> |
fputformat("ascii", stdout); |
| 79 |
> |
putchar('\n'); |
| 80 |
> |
} |
| 81 |
|
lookamb(fp); |
| 82 |
+ |
} |
| 83 |
|
fclose(fp); |
| 84 |
|
return(0); |
| 85 |
+ |
formaterr: |
| 86 |
+ |
fprintf(stderr, "%s: format error on input\n", argv[0]); |
| 87 |
+ |
exit(1); |
| 88 |
|
} |
| 89 |
|
|
| 90 |
|
|
| 91 |
< |
lookamb(fp) /* get ambient values from a file */ |
| 92 |
< |
FILE *fp; |
| 91 |
> |
extern void |
| 92 |
> |
lookamb( /* get ambient values from a file */ |
| 93 |
> |
FILE *fp |
| 94 |
> |
) |
| 95 |
|
{ |
| 96 |
< |
while (fread((char *)&av, sizeof(AMBVAL), 1, fp) == 1) { |
| 96 |
> |
while (readambval(&av, fp)) { |
| 97 |
|
if (dataonly) { |
| 98 |
|
printf("%f\t%f\t%f\t", av.pos[0], av.pos[1], av.pos[2]); |
| 99 |
|
printf("%f\t%f\t%f\t", av.dir[0], av.dir[1], av.dir[2]); |
| 100 |
|
printf("%d\t%f\t%f\t", av.lvl, av.weight, av.rad); |
| 101 |
< |
printf("%e\t%e\t%e\n", colval(av.val,RED), |
| 101 |
> |
printf("%e\t%e\t%e\t", colval(av.val,RED), |
| 102 |
|
colval(av.val,GRN), |
| 103 |
|
colval(av.val,BLU)); |
| 104 |
+ |
printf("%f\t%f\t%f\t", av.gpos[0], |
| 105 |
+ |
av.gpos[1], av.gpos[2]); |
| 106 |
+ |
printf("%f\t%f\t%f\n", av.gdir[0], |
| 107 |
+ |
av.gdir[1], av.gdir[2]); |
| 108 |
|
} else { |
| 109 |
|
printf("\nPosition:\t%f\t%f\t%f\n", av.pos[0], |
| 110 |
|
av.pos[1], av.pos[2]); |
| 114 |
|
av.weight, av.rad); |
| 115 |
|
printf("Value:\t\t%e\t%e\t%e\n", colval(av.val,RED), |
| 116 |
|
colval(av.val,GRN), colval(av.val,BLU)); |
| 117 |
+ |
printf("Pos.Grad:\t%f\t%f\t%f\n", av.gpos[0], |
| 118 |
+ |
av.gpos[1], av.gpos[2]); |
| 119 |
+ |
printf("Dir.Grad:\t%f\t%f\t%f\n", av.gdir[0], |
| 120 |
+ |
av.gdir[1], av.gdir[2]); |
| 121 |
|
} |
| 122 |
|
if (ferror(stdout)) |
| 123 |
|
exit(1); |
| 125 |
|
} |
| 126 |
|
|
| 127 |
|
|
| 128 |
< |
writamb(fp) /* write binary ambient values */ |
| 129 |
< |
FILE *fp; |
| 128 |
> |
extern void |
| 129 |
> |
writamb( /* write binary ambient values */ |
| 130 |
> |
FILE *fp |
| 131 |
> |
) |
| 132 |
|
{ |
| 133 |
|
for ( ; ; ) { |
| 134 |
|
if (!dataonly) |
| 135 |
|
fscanf(fp, "%*s"); |
| 136 |
< |
if (fscanf(fp, "%lf %lf %lf", |
| 136 |
> |
if (fscanf(fp, "%f %f %f", |
| 137 |
|
&av.pos[0], &av.pos[1], &av.pos[2]) != 3) |
| 138 |
|
return; |
| 139 |
|
if (!dataonly) |
| 140 |
|
fscanf(fp, "%*s"); |
| 141 |
< |
if (fscanf(fp, "%lf %lf %lf", |
| 141 |
> |
if (fscanf(fp, "%f %f %f", |
| 142 |
|
&av.dir[0], &av.dir[1], &av.dir[2]) != 3) |
| 143 |
|
return; |
| 144 |
|
if (!dataonly) |
| 151 |
|
if (fscanf(fp, "%f %f %f", |
| 152 |
|
&av.val[RED], &av.val[GRN], &av.val[BLU]) != 3) |
| 153 |
|
return; |
| 154 |
< |
fwrite((char *)&av, sizeof(AMBVAL), 1, stdout); |
| 154 |
> |
if (!dataonly) |
| 155 |
> |
fscanf(fp, "%*s"); |
| 156 |
> |
if (fscanf(fp, "%f %f %f", |
| 157 |
> |
&av.gpos[0], &av.gpos[1], &av.gpos[2]) != 3) |
| 158 |
> |
return; |
| 159 |
> |
if (!dataonly) |
| 160 |
> |
fscanf(fp, "%*s"); |
| 161 |
> |
if (fscanf(fp, "%f %f %f", |
| 162 |
> |
&av.gdir[0], &av.gdir[1], &av.gdir[2]) != 3) |
| 163 |
> |
return; |
| 164 |
> |
av.next = NULL; |
| 165 |
> |
writambval(&av, stdout); |
| 166 |
|
if (ferror(stdout)) |
| 167 |
|
exit(1); |
| 168 |
|
} |