--- ray/src/rt/lookamb.c 1989/02/02 10:41:25 1.1 +++ ray/src/rt/lookamb.c 2003/06/05 19:29:34 2.9 @@ -1,40 +1,26 @@ -/* Copyright (c) 1986 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: lookamb.c,v 2.9 2003/06/05 19:29:34 schorsch Exp $"; #endif - /* * lookamb.c - program to examine ambient components. - * - * 10/8/86 */ -#include +#include "copyright.h" -#include "color.h" +#include "platform.h" +#include "ray.h" +#include "ambient.h" -typedef double FVECT[3]; - -typedef struct ambval { - FVECT pos; /* position in space */ - FVECT dir; /* normal direction */ - int lvl; /* recursion level of parent ray */ - float weight; /* weight of parent ray */ - COLOR val; /* computed ambient value */ - float rad; /* validity radius */ - struct ambval *next; /* next in list */ -} AMBVAL; /* ambient value */ - int dataonly = 0; - +int header = 1; int reverse = 0; AMBVAL av; main(argc, argv) /* load ambient values from a file */ +int argc; char *argv[]; { FILE *fp; @@ -49,6 +35,9 @@ char *argv[]; case 'r': reverse = 1; break; + case 'h': + header = 0; + break; default: fprintf(stderr, "%s: unknown option '%s'\n", argv[0], argv[i]); @@ -63,26 +52,55 @@ char *argv[]; fprintf(stderr, "%s: file not found\n", argv[i]); return(1); } - if (reverse) + if (reverse) { + if (header) { + if (checkheader(fp, "ascii", stdout) < 0) + goto formaterr; + } else { + newheader("RADIANCE", stdout); + printargs(argc, argv, stdout); + } + fputformat(AMBFMT, stdout); + putchar('\n'); + SET_FILE_BINARY(stdout); + putambmagic(stdout); writamb(fp); - else + } else { + SET_FILE_BINARY(fp); + if (checkheader(fp, AMBFMT, header ? stdout : (FILE *)NULL) < 0) + goto formaterr; + if (!hasambmagic(fp)) + goto formaterr; + if (header) { + fputformat("ascii", stdout); + putchar('\n'); + } lookamb(fp); + } fclose(fp); return(0); +formaterr: + fprintf(stderr, "%s: format error on input\n", argv[0]); + exit(1); } +void lookamb(fp) /* get ambient values from a file */ FILE *fp; { - while (fread(&av, sizeof(AMBVAL), 1, fp) == 1) { + while (readambval(&av, fp)) { if (dataonly) { printf("%f\t%f\t%f\t", av.pos[0], av.pos[1], av.pos[2]); printf("%f\t%f\t%f\t", av.dir[0], av.dir[1], av.dir[2]); printf("%d\t%f\t%f\t", av.lvl, av.weight, av.rad); - printf("%e\t%e\t%e\n", colval(av.val,RED), + printf("%e\t%e\t%e\t", colval(av.val,RED), colval(av.val,GRN), colval(av.val,BLU)); + printf("%f\t%f\t%f\t", av.gpos[0], + av.gpos[1], av.gpos[2]); + printf("%f\t%f\t%f\n", av.gdir[0], + av.gdir[1], av.gdir[2]); } else { printf("\nPosition:\t%f\t%f\t%f\n", av.pos[0], av.pos[1], av.pos[2]); @@ -92,6 +110,10 @@ FILE *fp; av.weight, av.rad); printf("Value:\t\t%e\t%e\t%e\n", colval(av.val,RED), colval(av.val,GRN), colval(av.val,BLU)); + printf("Pos.Grad:\t%f\t%f\t%f\n", av.gpos[0], + av.gpos[1], av.gpos[2]); + printf("Dir.Grad:\t%f\t%f\t%f\n", av.gdir[0], + av.gdir[1], av.gdir[2]); } if (ferror(stdout)) exit(1); @@ -99,18 +121,19 @@ FILE *fp; } +void writamb(fp) /* write binary ambient values */ FILE *fp; { for ( ; ; ) { if (!dataonly) fscanf(fp, "%*s"); - if (fscanf(fp, "%lf %lf %lf", + if (fscanf(fp, "%f %f %f", &av.pos[0], &av.pos[1], &av.pos[2]) != 3) return; if (!dataonly) fscanf(fp, "%*s"); - if (fscanf(fp, "%lf %lf %lf", + if (fscanf(fp, "%f %f %f", &av.dir[0], &av.dir[1], &av.dir[2]) != 3) return; if (!dataonly) @@ -123,7 +146,18 @@ FILE *fp; if (fscanf(fp, "%f %f %f", &av.val[RED], &av.val[GRN], &av.val[BLU]) != 3) return; - fwrite(&av, sizeof(AMBVAL), 1, stdout); + if (!dataonly) + fscanf(fp, "%*s"); + if (fscanf(fp, "%f %f %f", + &av.gpos[0], &av.gpos[1], &av.gpos[2]) != 3) + return; + if (!dataonly) + fscanf(fp, "%*s"); + if (fscanf(fp, "%f %f %f", + &av.gdir[0], &av.gdir[1], &av.gdir[2]) != 3) + return; + av.next = NULL; + writambval(&av, stdout); if (ferror(stdout)) exit(1); }