BRL-CAD
seg.h
Go to the documentation of this file.
1 /* S E G . H
2  * BRL-CAD
3  *
4  * Copyright (c) 1993-2024 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 /** @addtogroup rt_seg
21  * @brief Intersection segment.
22  *
23  * A "seg" or segment is a low level in/out ray/shape intersection solution,
24  * derived by performing intersection calculations between a ray and a single
25  * object. Depending on the type of shape, a single ray may produce
26  * multiple segments when intersected with that shape. Unless the object
27  * happens to also be a top-level unioned object in the database, individual
28  * segments must be "woven" together using boolean hierarchies to obtain the
29  * final partitions which describe solid geometry along a ray. An individual
30  * segment may have either a positive or negative contribution to the "final"
31  * partition, depending on whether parent combs designate their children
32  * as unioned, intersected, or subtracted.
33  */
34 /** @{ */
35 /** @file seg.h */
36 
37 #ifndef RT_SEG_H
38 #define RT_SEG_H
39 
40 #include "common.h"
41 #include "vmath.h"
42 #include "bu/list.h"
43 #include "bu/vls.h"
44 #include "rt/defines.h"
45 #include "rt/hit.h"
46 
47 __BEGIN_DECLS
48 
49 struct soltab; /* forward declaration */
50 
51 /**
52  * Intersection segment.
53  *
54  * Includes information about both endpoints of intersection.
55  * Contains forward link to additional intersection segments if the
56  * intersection spans multiple segments (e.g., shooting a ray through
57  * a torus).
58  */
59 struct seg {
60  struct bu_list l;
61  struct hit seg_in; /**< @brief IN information */
62  struct hit seg_out; /**< @brief OUT information */
63  struct soltab * seg_stp; /**< @brief pointer back to soltab */
64 };
65 #define RT_SEG_NULL ((struct seg *)0)
66 
67 #define RT_CHECK_SEG(_p) BU_CKMAG(_p, RT_SEG_MAGIC, "struct seg")
68 #define RT_CK_SEG(_p) BU_CKMAG(_p, RT_SEG_MAGIC, "struct seg")
69 
70 #define RT_GET_SEG(p, res) { \
71  while (!BU_LIST_WHILE((p), seg, &((res)->re_seg)) || !(p)) \
72  rt_alloc_seg_block(res); \
73  BU_LIST_DEQUEUE(&((p)->l)); \
74  (p)->l.forw = (p)->l.back = BU_LIST_NULL; \
75  (p)->seg_in.hit_magic = (p)->seg_out.hit_magic = RT_HIT_MAGIC; \
76  res->re_segget++; \
77  }
78 
79 
80 #define RT_FREE_SEG(p, res) { \
81  RT_CHECK_SEG(p); \
82  BU_LIST_INSERT(&((res)->re_seg), &((p)->l)); \
83  res->re_segfree++; \
84  }
85 
86 
87 /**
88  * This could be
89  * BU_LIST_INSERT_LIST(&((_res)->re_seg), &((_segheadp)->l))
90  * except for security of checking & counting each element this way.
91  */
92 #define RT_FREE_SEG_LIST(_segheadp, _res) { \
93  register struct seg *_a; \
94  while (BU_LIST_WHILE(_a, seg, &((_segheadp)->l))) { \
95  BU_LIST_DEQUEUE(&(_a->l)); \
96  RT_FREE_SEG(_a, _res); \
97  } \
98  }
99 
100 /* Print seg struct */
101 RT_EXPORT extern void rt_pr_seg(const struct seg *segp);
102 RT_EXPORT extern void rt_pr_seg_vls(struct bu_vls *, const struct seg *);
103 
104 
105 __END_DECLS
106 
107 #endif /* RT_SEG_H */
108 /** @} */
109 /*
110  * Local Variables:
111  * tab-width: 8
112  * mode: C
113  * indent-tabs-mode: t
114  * c-file-style: "stroustrup"
115  * End:
116  * ex: shiftwidth=4 tabstop=8
117  */
Header file for the BRL-CAD common definitions.
void rt_pr_seg_vls(struct bu_vls *, const struct seg *)
void rt_pr_seg(const struct seg *segp)
Definition: list.h:132
Definition: vls.h:53
Information about where a ray hits the surface.
Definition: hit.h:61
Definition: seg.h:59
struct hit seg_in
IN information.
Definition: seg.h:61
struct hit seg_out
OUT information.
Definition: seg.h:62
struct soltab * seg_stp
pointer back to soltab
Definition: seg.h:63
struct bu_list l
Definition: seg.h:60
Definition: soltab.h:57
fundamental vector, matrix, quaternion math macros