--- ray/src/cv/nff2rad.c 1993/03/05 15:16:16 2.3 +++ ray/src/cv/nff2rad.c 2003/11/15 17:54:06 2.7 @@ -1,9 +1,6 @@ -/* Copyright (c) 1992 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: nff2rad.c,v 2.7 2003/11/15 17:54:06 schorsch Exp $"; #endif - /* * Convert Neutral File Format input to Radiance scene description. * @@ -69,16 +66,52 @@ These are explained in depth below: { see conversion r ***********************************************************************/ +#include #include +#include +#include "rtmath.h" + +typedef double Flt ; +typedef Flt Vec[3] ; +typedef Vec Point ; +typedef Vec Color ; + +#define VecCopy(a,b) (b)[0]=(a)[0];(b)[1]=(a)[1];(b)[2]=(a)[2]; +#define NCOLORS (738) + +typedef struct t_color_entry { + char * ce_name ; + Vec ce_color ; +} ColorEntry ; + +#define LESS_THAN -1 +#define GREATER_THAN 1 +#define EQUAL_TO 0 + char *viewfile = NULL; /* view parameters file */ char *progname; +void init(void); +void nff2rad(void); +void comment(void); +void view(void); +void light(void); +void background(void); +void fill(void); +void cone(void); +void sphere(void); +void poly(void); +int LookupColorByName(char * name, Vec color); +int BinarySearch(char * name, int l, int h, ColorEntry array[]); -main(argc, argv) /* convert NFF file to Radiance */ -int argc; -char *argv[]; + +int +main( /* convert NFF file to Radiance */ + int argc, + char *argv[] +) { int i; @@ -105,17 +138,19 @@ userr: } -init() /* spit out initial definitions */ +void +init(void) /* spit out initial definitions */ { printf("# File created by %s\n", progname); printf("\nvoid light light\n"); - printf("0\n0\n3 1 1 1\n"); + printf("0\n0\n3 1e6 1e6 1e6\n"); printf("\nvoid plastic fill\n"); printf("0\n0\n5 .5 .5 .5 0 0\n"); } -nff2rad() /* convert NFF on stdin to Radiance on stdout */ +void +nff2rad(void) /* convert NFF on stdin to Radiance on stdout */ { register int c; @@ -171,7 +206,8 @@ Format: ******************/ -comment() +void +comment(void) { register int c; @@ -228,7 +264,8 @@ The parameters are: ***************/ -view() +void +view(void) { static FILE *fp = NULL; float from[3], at[3], up[3], angle; @@ -277,7 +314,8 @@ Format: **************************/ -light() +void +light(void) { static int nlights = 0; register int c; @@ -290,7 +328,7 @@ light() while ((c = getchar()) != EOF && c != '\n') ; printf("\nlight sphere l%d \n", ++nlights); - printf("0\n0\n4 %g %g %g 1\n", x, y, z); + printf("0\n0\n4 %g %g %g .01\n", x, y, z); } @@ -306,7 +344,8 @@ Format: ********************/ -background() +void +background(void) { float r, g, b; char colname[50]; @@ -353,7 +392,8 @@ Format: *********************/ -fill() +void +fill(void) { float r, g, b, d, s, p, t, n; char colname[50]; @@ -375,18 +415,20 @@ fill() fprintf(stderr, "%s: fill material syntax error\n", progname); exit(1); } - d /= 1.-s-t; - r *= d; - g *= d; - b *= d; if (p > 1.) p = 1./p; if (t > .001) { /* has transmission */ - printf("\nvoid trans fill\n"); - printf("0\n0\n7 %g %g %g %g 0 %g 1\n", r, g, b, s, t); + if (n > 1.1) { /* has index of refraction */ + printf("\nvoid dielectric fill\n"); + printf("0\n0\n5 %g %g %g %g 0\n", r, g, b, n); + } else { /* transmits w/o refraction */ + printf("\nvoid trans fill\n"); + printf("0\n0\n7 %g %g %g %g 0 %g 1\n", + r*d, g*d, b*d, s, t); + } } else { /* no transmission */ printf("\nvoid plastic fill\n"); - printf("0\n0\n5 %g %g %g %g %g\n", r, g, b, s, p); + printf("0\n0\n5 %g %g %g %g %g\n", r*d, g*d, b*d, s, p); } } @@ -416,7 +458,8 @@ Format: ************************/ -cone() +void +cone(void) { static int ncs = 0; int invert; @@ -428,7 +471,7 @@ cone() progname); exit(1); } - if (invert = r0 < 0.) { + if ( (invert = r0 < 0.) ) { r0 = -r0; r1 = -r1; } @@ -461,7 +504,8 @@ Format: ******************/ -sphere() +void +sphere(void) { static int nspheres = 0; float x, y, z, r; @@ -516,7 +560,8 @@ Format: *******************/ -poly() +void +poly(void) { static int npolys = 0; int ispatch; @@ -545,13 +590,21 @@ fmterr: exit(1); } /*********************************************************************** - * $Author: greg $ (Mark VandeWettering, drizzle.cs.uoregon.edu) - * $Revision: 2.3 $ - * $Date: 1993/03/05 15:16:16 $ + * $Author: schorsch $ (Mark VandeWettering, drizzle.cs.uoregon.edu) + * $Revision: 2.7 $ + * $Date: 2003/11/15 17:54:06 $ * $Log: nff2rad.c,v $ - * Revision 2.3 1993/03/05 15:16:16 greg - * portability improvements + * Revision 2.7 2003/11/15 17:54:06 schorsch + * Continued ANSIfication and reduced compile warnings. * + * Revision 2.6 2003/07/27 22:12:01 schorsch + * Added grouping parens to reduce ambiguity warnings. + * + * Revision 2.5 2003/02/22 02:07:23 greg + * Changes and check-in for 3.5 release + * Includes new source files and modifications not recorded for many years + * See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release + * * Revision 1.2 88/09/12 12:53:47 markv * Fixed problem in LookupColorbyName, had return ; and return(0). * [ Thank you lint! ] @@ -565,23 +618,6 @@ fmterr: * ***********************************************************************/ -typedef double Flt ; -typedef Flt Vec[3] ; -typedef Vec Point ; -typedef Vec Color ; - -#define VecCopy(a,b) (b)[0]=(a)[0];(b)[1]=(a)[1];(b)[2]=(a)[2]; -#define NCOLORS (738) - -typedef struct t_color_entry { - char * ce_name ; - Vec ce_color ; -} ColorEntry ; - -#define LESS_THAN -1 -#define GREATER_THAN 1 -#define EQUAL_TO 0 - /* * Note: These colors must be in sorted order, because we binary search * for them. @@ -1331,9 +1367,10 @@ ColorEntry Colors[] = { } ; int -LookupColorByName(name, color) - char * name ; - Vec color ; +LookupColorByName( + char * name, + Vec color +) { int rc ; rc = BinarySearch(name, 0, NCOLORS - 1 , Colors) ; @@ -1347,10 +1384,12 @@ LookupColorByName(name, color) int -BinarySearch(name, l, h, array) - char * name ; - int l, h ; - ColorEntry array[] ; +BinarySearch( + char * name, + int l, + int h, + ColorEntry array[] +) { int m, rc ; if (l > h)