BRL-CAD
ray_partition.h
Go to the documentation of this file.
1 /* R A Y _ P A R T I T I O N . 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_partition
21  * @brief Partitions of a ray.
22  *
23  * The partition structure contains information about intervals of the ray which pass
24  * through geometry. A partition consists of one or more segments, which are
25  * woven together via rt_boolweave to form the final "solid" partitions that describe
26  * solid segments of geometry along a given ray.
27  *
28  */
29 /** @{ */
30 /** @file rt/ray_partition.h */
31 
32 #ifndef RT_RAY_PARTITION_H
33 #define RT_RAY_PARTITION_H
34 
35 #include "common.h"
36 #include "vmath.h"
37 #include "bu/ptbl.h"
38 #include "rt/defines.h"
39 #include "rt/seg.h"
40 
41 __BEGIN_DECLS
42 
43 /**
44  * Partitions of a ray. Passed from rt_shootray() into user's a_hit()
45  * function.
46  *
47  * Not changed to a bu_list for backwards compatibility, but you can
48  * iterate the whole list by writing:
49  *
50  * for (BU_LIST_FOR(pp, partition, (struct bu_list *)PartHeadp))
51  */
52 
53 struct partition {
54  /* This can be thought of and operated on as a struct bu_list */
55  uint32_t pt_magic; /**< @brief sanity check */
56  struct partition * pt_forw; /**< @brief forwards link */
57  struct partition * pt_back; /**< @brief backwards link */
58  struct seg * pt_inseg; /**< @brief IN seg ptr (gives stp) */
59  struct hit * pt_inhit; /**< @brief IN hit pointer */
60  struct seg * pt_outseg; /**< @brief OUT seg pointer */
61  struct hit * pt_outhit; /**< @brief OUT hit ptr */
62  struct region * pt_regionp; /**< @brief ptr to containing region */
63  char pt_inflip; /**< @brief flip inhit->hit_normal */
64  char pt_outflip; /**< @brief flip outhit->hit_normal */
65  struct region ** pt_overlap_reg; /**< @brief NULL-terminated array of overlapping regions. NULL if no overlap. */
66  struct bu_ptbl pt_seglist; /**< @brief all segs in this partition */
67 };
68 #define PT_NULL ((struct partition *)0)
69 
70 #define RT_CHECK_PT(_p) RT_CK_PT(_p) /**< @brief compat */
71 #define RT_CK_PT(_p) BU_CKMAG(_p, PT_MAGIC, "struct partition")
72 #define RT_CK_PARTITION(_p) BU_CKMAG(_p, PT_MAGIC, "struct partition")
73 #define RT_CK_PT_HD(_p) BU_CKMAG(_p, PT_HD_MAGIC, "struct partition list head")
74 
75 /* Macros for copying only the essential "middle" part of a partition struct. */
76 #define RT_PT_MIDDLE_START pt_inseg /**< @brief 1st elem to copy */
77 #define RT_PT_MIDDLE_END pt_seglist.l.magic /**< @brief copy up to this elem (non-inclusive) */
78 #define RT_PT_MIDDLE_LEN(p) \
79  (((char *)&(p)->RT_PT_MIDDLE_END) - ((char *)&(p)->RT_PT_MIDDLE_START))
80 
81 #define RT_DUP_PT(ip, new, old, res) { \
82  GET_PT(ip, new, res); \
83  memcpy((char *)(&(new)->RT_PT_MIDDLE_START), (char *)(&(old)->RT_PT_MIDDLE_START), RT_PT_MIDDLE_LEN(old)); \
84  (new)->pt_overlap_reg = NULL; \
85  bu_ptbl_cat(&(new)->pt_seglist, &(old)->pt_seglist); }
86 
87 /** Clear out the pointers, empty the hit list */
88 #define GET_PT_INIT(ip, p, res) {\
89  GET_PT(ip, p, res); \
90  memset(((char *) &(p)->RT_PT_MIDDLE_START), 0, RT_PT_MIDDLE_LEN(p)); }
91 
92 #define GET_PT(ip, p, res) { \
93  if (BU_LIST_NON_EMPTY_P(p, partition, &res->re_parthead)) { \
94  BU_LIST_DEQUEUE((struct bu_list *)(p)); \
95  bu_ptbl_reset(&(p)->pt_seglist); \
96  } else { \
97  BU_ALLOC((p), struct partition); \
98  (p)->pt_magic = PT_MAGIC; \
99  bu_ptbl_init(&(p)->pt_seglist, 42, "pt_seglist ptbl"); \
100  (res)->re_partlen++; \
101  } \
102  res->re_partget++; }
103 
104 #define FREE_PT(p, res) { \
105  BU_LIST_APPEND(&(res->re_parthead), (struct bu_list *)(p)); \
106  if ((p)->pt_overlap_reg) { \
107  bu_free((void *)((p)->pt_overlap_reg), "pt_overlap_reg");\
108  (p)->pt_overlap_reg = NULL; \
109  } \
110  res->re_partfree++; }
111 
112 #define RT_FREE_PT_LIST(_headp, _res) { \
113  register struct partition *_pp, *_zap; \
114  for (_pp = (_headp)->pt_forw; _pp != (_headp);) { \
115  _zap = _pp; \
116  _pp = _pp->pt_forw; \
117  BU_LIST_DEQUEUE((struct bu_list *)(_zap)); \
118  FREE_PT(_zap, _res); \
119  } \
120  (_headp)->pt_forw = (_headp)->pt_back = (_headp); \
121  }
122 
123 /** Insert "new" partition in front of "old" partition. Note order change */
124 #define INSERT_PT(_new, _old) BU_LIST_INSERT((struct bu_list *)_old, (struct bu_list *)_new)
125 
126 /** Append "new" partition after "old" partition. Note arg order change */
127 #define APPEND_PT(_new, _old) BU_LIST_APPEND((struct bu_list *)_old, (struct bu_list *)_new)
128 
129 /** Dequeue "cur" partition from doubly-linked list */
130 #define DEQUEUE_PT(_cur) BU_LIST_DEQUEUE((struct bu_list *)_cur)
131 
132 /**
133  * The partition_list structure - bu_list based structure for holding
134  * ray bundles.
135  */
137  struct bu_list l;
138  struct application *ap;
139  struct partition PartHeadp;
140  struct seg segHeadp;
141  void * userptr;
142 };
143 
144 
145 /**
146  * Partition bundle. Passed from rt_shootrays() into user's
147  * bundle_hit() function.
148  */
150  int hits;
151  int misses;
153  struct application *ap;
154 };
155 
156 
157 /**
158  * Return the length of a partition linked list.
159  */
160 RT_EXPORT extern int rt_partition_len(const struct partition *partheadp);
161 
162 
163 __END_DECLS
164 
165 #endif /* RT_RAY_PARTITION_H */
166 /** @} */
167 /*
168  * Local Variables:
169  * tab-width: 8
170  * mode: C
171  * indent-tabs-mode: t
172  * c-file-style: "stroustrup"
173  * End:
174  * ex: shiftwidth=4 tabstop=8
175  */
Header file for the BRL-CAD common definitions.
int rt_partition_len(const struct partition *partheadp)
Definition: list.h:132
Definition: ptbl.h:53
Information about where a ray hits the surface.
Definition: hit.h:61
struct partition_list * list
struct application * ap
struct seg segHeadp
struct application * ap
struct partition PartHeadp
struct bu_list l
struct seg * pt_inseg
IN seg ptr (gives stp)
Definition: ray_partition.h:58
struct region * pt_regionp
ptr to containing region
Definition: ray_partition.h:62
struct region ** pt_overlap_reg
NULL-terminated array of overlapping regions. NULL if no overlap.
Definition: ray_partition.h:65
uint32_t pt_magic
sanity check
Definition: ray_partition.h:55
struct partition * pt_back
backwards link
Definition: ray_partition.h:57
struct hit * pt_outhit
OUT hit ptr.
Definition: ray_partition.h:61
char pt_outflip
flip outhit->hit_normal
Definition: ray_partition.h:64
struct seg * pt_outseg
OUT seg pointer.
Definition: ray_partition.h:60
struct bu_ptbl pt_seglist
all segs in this partition
Definition: ray_partition.h:66
struct partition * pt_forw
forwards link
Definition: ray_partition.h:56
struct hit * pt_inhit
IN hit pointer.
Definition: ray_partition.h:59
char pt_inflip
flip inhit->hit_normal
Definition: ray_partition.h:63
Definition: region.h:44
Definition: seg.h:59
fundamental vector, matrix, quaternion math macros