ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/m_clip.c
Revision: 2.7
Committed: Mon Jul 21 22:30:19 2003 UTC (20 years, 9 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 2.6: +3 -2 lines
Log Message:
Eliminated copystruct() macro, which is unnecessary in ANSI.
Reduced ambiguity warnings for nested if/if/else clauses.

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: m_clip.c,v 2.6 2003/02/25 02:47:22 greg Exp $";
3 #endif
4 /*
5 * m_clip.c - routine for clipped (cut) objects.
6 */
7
8 #include "copyright.h"
9
10 #include "ray.h"
11
12 /*
13 * Clipping objects permit holes and sections to be taken out
14 * of other objects. The method is simple:
15 *
16 * The argument is the clipped materials;
17 * the first is used to shade upon exit.
18 */
19
20
21 int
22 m_clip(m, r) /* clip objects from ray */
23 register OBJREC *m;
24 register RAY *r;
25 {
26 OBJECT cset[MAXSET+1], *modset;
27 OBJECT obj, mod;
28 int entering;
29 register int i;
30
31 obj = objndx(m);
32 if ((modset = (OBJECT *)m->os) == NULL) {
33 if (m->oargs.nsargs < 1 || m->oargs.nsargs > MAXSET)
34 objerror(m, USER, "bad # arguments");
35 modset = (OBJECT *)malloc((m->oargs.nsargs+1)*sizeof(OBJECT));
36 if (modset == NULL)
37 error(SYSTEM, "out of memory in m_clip");
38 modset[0] = 0;
39 for (i = 0; i < m->oargs.nsargs; i++) {
40 if (!strcmp(m->oargs.sarg[i], VOIDID))
41 continue;
42 if ((mod = lastmod(obj, m->oargs.sarg[i])) == OVOID) {
43 sprintf(errmsg, "unknown modifier \"%s\"",
44 m->oargs.sarg[i]);
45 objerror(m, WARNING, errmsg);
46 continue;
47 }
48 if (inset(modset, mod)) {
49 objerror(m, WARNING, "duplicate modifier");
50 continue;
51 }
52 insertelem(modset, mod);
53 }
54 m->os = (char *)modset;
55 }
56 if (r->clipset != NULL)
57 setcopy(cset, r->clipset);
58 else
59 cset[0] = 0;
60
61 entering = r->rod > 0.0; /* entering clipped region? */
62
63 for (i = modset[0]; i > 0; i--) {
64 if (entering) {
65 if (!inset(cset, modset[i])) {
66 if (cset[0] >= MAXSET)
67 error(INTERNAL, "set overflow in m_clip");
68 insertelem(cset, modset[i]);
69 }
70 } else {
71 if (inset(cset, modset[i]))
72 deletelem(cset, modset[i]);
73 }
74 }
75 /* compute ray value */
76 r->newcset = cset;
77 if (strcmp(m->oargs.sarg[0], VOIDID)) {
78 int inside = 0;
79 register RAY *rp;
80 /* check for penetration */
81 for (rp = r; rp->parent != NULL; rp = rp->parent)
82 if (!(rp->rtype & RAYREFL) && rp->parent->ro != NULL
83 && inset(modset, rp->parent->ro->omod)) {
84 if (rp->parent->rod > 0.0)
85 inside++;
86 else
87 inside--;
88 }
89 if (inside > 0) { /* we just hit the object */
90 flipsurface(r);
91 return(rayshade(r, lastmod(obj, m->oargs.sarg[0])));
92 }
93 }
94 raytrans(r); /* else transfer ray */
95 return(1);
96 }