ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/ambio.c
Revision: 2.13
Committed: Tue May 14 17:39:10 2019 UTC (4 years, 11 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R3
Changes since 2.12: +1 -82 lines
Log Message:
Stripped out code related to old (pre-Hessian) ambient calculation

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: ambio.c,v 2.12 2017/01/27 22:00:49 greg Exp $";
3 #endif
4 /*
5 * Read and write portable ambient values
6 *
7 * Declarations of external symbols in ambient.h
8 */
9
10 #include "copyright.h"
11
12 #include "ray.h"
13 #include "ambient.h"
14
15
16 #define badflt(x) (((x) < -FHUGE) | ((x) > FHUGE))
17
18 #define badvec(v) (badflt((v)[0]) | badflt((v)[1]) | badflt((v)[2]))
19
20
21 void
22 putambmagic(fp) /* write out ambient value magic number */
23 FILE *fp;
24 {
25 putint(AMBMAGIC, 2, fp);
26 }
27
28
29 int
30 hasambmagic(fp) /* read in and check validity of magic # */
31 FILE *fp;
32 {
33 int magic;
34
35 magic = getint(2, fp);
36 if (feof(fp))
37 return(0);
38 return(magic == AMBMAGIC);
39 }
40
41
42 #define putpos(v,fp) putflt((v)[0],fp);putflt((v)[1],fp);putflt((v)[2],fp)
43
44 #define getpos(v,fp) (v)[0]=getflt(fp);(v)[1]=getflt(fp);(v)[2]=getflt(fp)
45
46 #define putv2(v2,fp) putflt((v2)[0],fp);putflt((v2)[1],fp)
47
48 #define getv2(v2,fp) (v2)[0]=getflt(fp);(v2)[1]=getflt(fp)
49
50 int
51 writambval( /* write ambient value to stream */
52 AMBVAL *av,
53 FILE *fp
54 )
55 {
56 COLR clr;
57
58 putint(av->lvl, 1, fp);
59 putflt(av->weight, fp);
60 putpos(av->pos, fp);
61 putint(av->ndir, sizeof(av->ndir), fp);
62 putint(av->udir, sizeof(av->udir), fp);
63 setcolr(clr, colval(av->val,RED),
64 colval(av->val,GRN), colval(av->val,BLU));
65 putbinary((char *)clr, sizeof(clr), 1, fp);
66 putv2(av->rad, fp);
67 putv2(av->gpos, fp);
68 putv2(av->gdir, fp);
69 putint(av->corral, sizeof(av->corral), fp);
70 return(ferror(fp) ? -1 : 0);
71 }
72
73
74 int
75 ambvalOK( /* check consistency of ambient value */
76 AMBVAL *av
77 )
78 {
79 double d;
80
81 if (badvec(av->pos)) return(0);
82 if (!av->ndir | !av->udir) return(0);
83 if ((av->weight <= 0.) | (av->weight > 1.)) return(0);
84 if ((av->rad[0] <= 0.) | (av->rad[0] >= FHUGE)) return(0);
85 if ((av->rad[1] <= 0.) | (av->rad[1] >= FHUGE)) return(0);
86 if ((colval(av->val,RED) < 0.) |
87 (colval(av->val,RED) >= FHUGE) |
88 (colval(av->val,GRN) < 0.) |
89 (colval(av->val,GRN) >= FHUGE) |
90 (colval(av->val,BLU) < 0.) |
91 (colval(av->val,BLU) >= FHUGE)) return(0);
92 if (badflt(av->gpos[0]) || badflt(av->gpos[1])) return(0);
93 if (badflt(av->gdir[0]) || badflt(av->gdir[1])) return(0);
94 return(1);
95 }
96
97
98 int
99 readambval( /* read ambient value from stream */
100 AMBVAL *av,
101 FILE *fp
102 )
103 {
104 COLR clr;
105
106 av->lvl = getint(1, fp) & 0xff;
107 if (feof(fp))
108 return(0);
109 av->weight = getflt(fp);
110 getpos(av->pos, fp);
111 av->ndir = getint(sizeof(av->ndir), fp);
112 av->udir = getint(sizeof(av->udir), fp);
113 if (getbinary((char *)clr, sizeof(clr), 1, fp) != 1)
114 return(0);
115 colr_color(av->val, clr);
116 getv2(av->rad, fp);
117 getv2(av->gpos, fp);
118 getv2(av->gdir, fp);
119 av->corral = (uint32)getint(sizeof(av->corral), fp);
120 return(feof(fp) ? 0 : ambvalOK(av));
121 }