1 |
|
#ifndef lint |
2 |
< |
static const char RCSid[] = "$Id$"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
4 |
|
/* |
5 |
|
* bbox.c - routines for bounding box computation. |
6 |
|
*/ |
7 |
|
|
8 |
< |
/* ==================================================================== |
9 |
< |
* The Radiance Software License, Version 1.0 |
10 |
< |
* |
11 |
< |
* Copyright (c) 1990 - 2002 The Regents of the University of California, |
12 |
< |
* through Lawrence Berkeley National Laboratory. All rights reserved. |
13 |
< |
* |
14 |
< |
* Redistribution and use in source and binary forms, with or without |
15 |
< |
* modification, are permitted provided that the following conditions |
16 |
< |
* are met: |
17 |
< |
* |
18 |
< |
* 1. Redistributions of source code must retain the above copyright |
19 |
< |
* notice, this list of conditions and the following disclaimer. |
20 |
< |
* |
21 |
< |
* 2. Redistributions in binary form must reproduce the above copyright |
22 |
< |
* notice, this list of conditions and the following disclaimer in |
23 |
< |
* the documentation and/or other materials provided with the |
24 |
< |
* distribution. |
25 |
< |
* |
26 |
< |
* 3. The end-user documentation included with the redistribution, |
27 |
< |
* if any, must include the following acknowledgment: |
28 |
< |
* "This product includes Radiance software |
29 |
< |
* (http://radsite.lbl.gov/) |
30 |
< |
* developed by the Lawrence Berkeley National Laboratory |
31 |
< |
* (http://www.lbl.gov/)." |
32 |
< |
* Alternately, this acknowledgment may appear in the software itself, |
33 |
< |
* if and wherever such third-party acknowledgments normally appear. |
34 |
< |
* |
35 |
< |
* 4. The names "Radiance," "Lawrence Berkeley National Laboratory" |
36 |
< |
* and "The Regents of the University of California" must |
37 |
< |
* not be used to endorse or promote products derived from this |
38 |
< |
* software without prior written permission. For written |
39 |
< |
* permission, please contact [email protected]. |
40 |
< |
* |
41 |
< |
* 5. Products derived from this software may not be called "Radiance", |
42 |
< |
* nor may "Radiance" appear in their name, without prior written |
43 |
< |
* permission of Lawrence Berkeley National Laboratory. |
44 |
< |
* |
45 |
< |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED |
46 |
< |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
47 |
< |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
48 |
< |
* DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR |
49 |
< |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
50 |
< |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
51 |
< |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
52 |
< |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
53 |
< |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
54 |
< |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
55 |
< |
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
56 |
< |
* SUCH DAMAGE. |
57 |
< |
* ==================================================================== |
58 |
< |
* |
59 |
< |
* This software consists of voluntary contributions made by many |
60 |
< |
* individuals on behalf of Lawrence Berkeley National Laboratory. For more |
61 |
< |
* information on Lawrence Berkeley National Laboratory, please see |
62 |
< |
* <http://www.lbl.gov/>. |
63 |
< |
*/ |
8 |
> |
#include "copyright.h" |
9 |
|
|
10 |
|
#include "standard.h" |
66 |
– |
|
11 |
|
#include "object.h" |
68 |
– |
|
12 |
|
#include "octree.h" |
70 |
– |
|
13 |
|
#include "otypes.h" |
72 |
– |
|
14 |
|
#include "face.h" |
74 |
– |
|
15 |
|
#include "cone.h" |
76 |
– |
|
16 |
|
#include "instance.h" |
17 |
+ |
#include "mesh.h" |
18 |
+ |
#include "oconv.h" |
19 |
|
|
20 |
|
|
21 |
< |
add2bbox(o, bbmin, bbmax) /* expand bounding box to fit object */ |
22 |
< |
register OBJREC *o; |
23 |
< |
FVECT bbmin, bbmax; |
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 |
|
|
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); |
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 |
< |
point2bbox(p, bbmin, bbmax) /* expand bounding box to fit point */ |
99 |
< |
register FVECT p, bbmin, bbmax; |
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 |
|
|
113 |
|
} |
114 |
|
|
115 |
|
|
116 |
< |
circle2bbox(cent, norm, rad, bbmin, bbmax) /* expand bbox to fit circle */ |
117 |
< |
FVECT cent, norm; |
118 |
< |
double rad; |
119 |
< |
FVECT bbmin, bbmax; |
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 |
< |
FVECT v1, v2; |
126 |
< |
register int i, j; |
125 |
> |
double d, r; |
126 |
> |
register int i; |
127 |
|
|
128 |
|
for (i = 0; i < 3; i++) { |
129 |
< |
v1[0] = v1[1] = v1[2] = 0; |
130 |
< |
v1[i] = 1.0; |
131 |
< |
fcross(v2, norm, v1); |
132 |
< |
if (normalize(v2) == 0.0) |
133 |
< |
continue; |
134 |
< |
for (j = 0; j < 3; j++) |
135 |
< |
v1[j] = cent[j] + rad*v2[j]; |
165 |
< |
point2bbox(v1, bbmin, bbmax); |
166 |
< |
for (j = 0; j < 3; j++) |
167 |
< |
v1[j] = cent[j] - rad*v2[j]; |
168 |
< |
point2bbox(v1, bbmin, bbmax); |
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 |
|
} |