ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/ot/bbox.c
Revision: 2.7
Committed: Fri Sep 16 15:09:21 2016 UTC (8 years, 1 month ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R4, rad5R2, rad5R1, rad5R3, HEAD
Changes since 2.6: +3 -1 lines
Log Message:
Added checks for illegal cones/rings/cylinders

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: bbox.c,v 2.6 2005/06/14 17:10:06 greg Exp $";
3 #endif
4 /*
5 * bbox.c - routines for bounding box computation.
6 */
7
8 #include "copyright.h"
9
10 #include "standard.h"
11 #include "object.h"
12 #include "octree.h"
13 #include "otypes.h"
14 #include "face.h"
15 #include "cone.h"
16 #include "instance.h"
17 #include "mesh.h"
18 #include "oconv.h"
19
20
21 static void point2bbox(FVECT p, FVECT bbmin, FVECT bbmax);
22 static void circle2bbox(FVECT cent, FVECT norm, double rad, FVECT bbmin, FVECT bbmax);
23
24
25 void
26 add2bbox( /* expand bounding box to fit object */
27 register OBJREC *o,
28 FVECT bbmin,
29 FVECT bbmax
30 )
31 {
32 CONE *co;
33 FACE *fo;
34 INSTANCE *io;
35 MESHINST *mi;
36 FVECT v;
37 register int i, j;
38
39 switch (o->otype) {
40 case OBJ_SPHERE:
41 case OBJ_BUBBLE:
42 if (o->oargs.nfargs != 4)
43 objerror(o, USER, "bad arguments");
44 for (i = 0; i < 3; i++) {
45 VCOPY(v, o->oargs.farg);
46 v[i] -= o->oargs.farg[3];
47 point2bbox(v, bbmin, bbmax);
48 v[i] += 2.0 * o->oargs.farg[3];
49 point2bbox(v, bbmin, bbmax);
50 }
51 break;
52 case OBJ_FACE:
53 fo = getface(o);
54 j = fo->nv;
55 while (j--)
56 point2bbox(VERTEX(fo,j), bbmin, bbmax);
57 break;
58 case OBJ_CONE:
59 case OBJ_CUP:
60 case OBJ_CYLINDER:
61 case OBJ_TUBE:
62 case OBJ_RING:
63 co = getcone(o, 0);
64 if (co == NULL)
65 break;
66 if (o->otype != OBJ_RING)
67 circle2bbox(CO_P0(co), co->ad, CO_R0(co), bbmin, bbmax);
68 circle2bbox(CO_P1(co), co->ad, CO_R1(co), bbmin, bbmax);
69 break;
70 case OBJ_INSTANCE:
71 io = getinstance(o, IO_BOUNDS);
72 for (j = 0; j < 8; j++) {
73 for (i = 0; i < 3; i++) {
74 v[i] = io->obj->scube.cuorg[i];
75 if (j & 1<<i)
76 v[i] += io->obj->scube.cusize;
77 }
78 multp3(v, v, io->x.f.xfm);
79 point2bbox(v, bbmin, bbmax);
80 }
81 break;
82 case OBJ_MESH:
83 mi = getmeshinst(o, IO_BOUNDS);
84 for (j = 0; j < 8; j++) {
85 for (i = 0; i < 3; i++) {
86 v[i] = mi->msh->mcube.cuorg[i];
87 if (j & 1<<i)
88 v[i] += mi->msh->mcube.cusize;
89 }
90 multp3(v, v, mi->x.f.xfm);
91 point2bbox(v, bbmin, bbmax);
92 }
93 break;
94 }
95 }
96
97
98 static void
99 point2bbox( /* expand bounding box to fit point */
100 register FVECT p,
101 register FVECT bbmin,
102 register FVECT bbmax
103 )
104 {
105 register int i;
106
107 for (i = 0; i < 3; i++) {
108 if (p[i] < bbmin[i])
109 bbmin[i] = p[i];
110 if (p[i] > bbmax[i])
111 bbmax[i] = p[i];
112 }
113 }
114
115
116 static void
117 circle2bbox( /* expand bbox to fit circle */
118 FVECT cent,
119 FVECT norm,
120 double rad,
121 FVECT bbmin,
122 FVECT bbmax
123 )
124 {
125 double d, r;
126 register int i;
127
128 for (i = 0; i < 3; i++) {
129 r = sqrt(1. - norm[i]*norm[i]);
130 d = cent[i] + r*rad;
131 if (d > bbmax[i])
132 bbmax[i] = d;
133 d = cent[i] - r*rad;
134 if (d < bbmin[i])
135 bbmin[i] = d;
136 }
137 }