BRL-CAD
ray.h
Go to the documentation of this file.
1/* R A Y . H
2 * BRL-CAD
3 *
4 * Copyright (c) 2004-2023 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
21/*----------------------------------------------------------------------*/
22/** @addtogroup nmg_ray
23 *
24 * TODO - these structs and ray_in_rpp are versions of librt functionality,
25 * and we need to think about how/where to merge them into a common function
26 * and struct that are available to both libraries without introducing a
27 * coupling dependency.
28 */
29/** @{ */
30/** @file nmg/ray.h */
31
32#ifndef NMG_RAY_H
33#define NMG_RAY_H
34
35#include "common.h"
36
37#include "vmath.h"
38#include "bu/list.h"
39#include "nmg/defines.h"
40//#include "nmg/model.h"
41
42__BEGIN_DECLS
43
44struct model;
45
46NMG_EXPORT extern struct bu_list re_nmgfree; /**< @brief head of NMG hitmiss freelist */
47
48#define NMG_HIT_LIST 0
49#define NMG_MISS_LIST 1
50
51/* These values are for the hitmiss "in_out" variable and indicate the
52 * nature of the hit when known
53 */
54#define HMG_INBOUND_STATE(_hm) (((_hm)->in_out & 0x0f0) >> 4)
55#define HMG_OUTBOUND_STATE(_hm) ((_hm)->in_out & 0x0f)
56
57
58#define NMG_RAY_STATE_INSIDE 1
59#define NMG_RAY_STATE_ON 2
60#define NMG_RAY_STATE_OUTSIDE 4
61#define NMG_RAY_STATE_ANY 8
62
63#define HMG_HIT_IN_IN 0x11 /**< @brief hit internal structure */
64#define HMG_HIT_IN_OUT 0x14 /**< @brief breaking out */
65#define HMG_HIT_OUT_IN 0x41 /**< @brief breaking in */
66#define HMG_HIT_OUT_OUT 0x44 /**< @brief edge/vertex graze */
67#define HMG_HIT_IN_ON 0x12
68#define HMG_HIT_ON_IN 0x21
69#define HMG_HIT_ON_ON 0x22
70#define HMG_HIT_OUT_ON 0x42
71#define HMG_HIT_ON_OUT 0x24
72#define HMG_HIT_ANY_ANY 0x88 /**< @brief hit on non-3-manifold */
73
74#define NMG_VERT_ENTER 1
75#define NMG_VERT_ENTER_LEAVE 0
76#define NMG_VERT_LEAVE -1
77#define NMG_VERT_UNKNOWN -2
78
79#define NMG_HITMISS_SEG_IN 0x696e00 /**< @brief "in" */
80#define NMG_HITMISS_SEG_OUT 0x6f757400 /**< @brief "out" */
81
82#define NMG_CK_RD(_rd) NMG_CKMAG(_rd, NMG_RAY_DATA_MAGIC, "ray data");
83
84#ifdef NO_BOMBING_MACROS
85# define NMG_CK_HITMISS(hm) (void)(hm)
86#else
87# define NMG_CK_HITMISS(hm) \
88 {\
89 switch (hm->l.magic) { \
90 case NMG_RT_HIT_MAGIC: \
91 case NMG_RT_HIT_SUB_MAGIC: \
92 case NMG_RT_MISS_MAGIC: \
93 break; \
94 case NMG_MISS_LIST: \
95 bu_log(CPP_FILELINE ": struct hitmiss has NMG_MISS_LIST magic #\n"); \
96 bu_bomb("NMG_CK_HITMISS: going down in flames\n"); \
97 break; \
98 case NMG_HIT_LIST: \
99 bu_log(CPP_FILELINE ": struct hitmiss has NMG_MISS_LIST magic #\n"); \
100 bu_bomb("NMG_CK_HITMISS: going down in flames\n"); \
101 break; \
102 default: \
103 bu_log(CPP_FILELINE ": bad struct hitmiss magic: %u:(0x%08x)\n", \
104 hm->l.magic, hm->l.magic); \
105 bu_bomb("NMG_CK_HITMISS: going down in flames\n"); \
106 }\
107 if (!hm->hit.hit_private) { \
108 bu_log(CPP_FILELINE ": NULL hit_private in hitmiss struct\n"); \
109 bu_bomb("NMG_CK_HITMISS: going down in flames\n"); \
110 } \
111 }
112#endif
113
114#ifdef NO_BOMBING_MACROS
115# define NMG_CK_HITMISS_LISTS(rd) (void)(rd)
116#else
117# define NMG_CK_HITMISS_LISTS(rd) \
118 { \
119 struct nmg_hitmiss *_a_hit; \
120 for (BU_LIST_FOR(_a_hit, nmg_hitmiss, &rd->rd_hit)) {NMG_CK_HITMISS(_a_hit);} \
121 for (BU_LIST_FOR(_a_hit, nmg_hitmiss, &rd->rd_miss)) {NMG_CK_HITMISS(_a_hit);} \
122 }
123#endif
124
125#define NMG_GET_HITMISS(_p) { \
126 (_p) = BU_LIST_FIRST(nmg_hitmiss, &(re_nmgfree)); \
127 if (BU_LIST_IS_HEAD((_p), &(re_nmgfree))) \
128 BU_ALLOC((_p), struct nmg_hitmiss); \
129 else \
130 BU_LIST_DEQUEUE(&((_p)->l)); \
131 }
132
133
134#define NMG_FREE_HITLIST(_p) { \
135 BU_CK_LIST_HEAD((_p)); \
136 BU_LIST_APPEND_LIST(&(re_nmgfree), (_p)); \
137 }
138
139#ifdef NO_BOMBING_MACROS
140# define nmg_bu_bomb(rd, vlfree, str) (void)(rd)
141#else
142# define nmg_bu_bomb(rd, vlfree, str) { \
143 bu_log("%s", str); \
144 if (nmg_debug & NMG_DEBUG_NMGRT) bu_bomb("End of diagnostics"); \
145 BU_LIST_INIT(&rd->rd_hit); \
146 BU_LIST_INIT(&rd->rd_miss); \
147 nmg_debug |= NMG_DEBUG_NMGRT; \
148 nmg_isect_ray_model(rd,vlfree); \
149 bu_bomb("Should have bombed before this\n"); \
150 }
151#endif
152
153
154#define HIT 1 /**< @brief a hit on a face */
155#define MISS 0 /**< @brief a miss on the face */
156
157struct nmg_ray {
158 uint32_t magic;
159 point_t r_pt; /**< @brief Point at which ray starts */
160 vect_t r_dir; /**< @brief Direction of ray (UNIT Length) */
161 fastf_t r_min; /**< @brief entry dist to bounding sphere */
162 fastf_t r_max; /**< @brief exit dist from bounding sphere */
163};
164
165struct nmg_hit {
166 uint32_t hit_magic;
167 fastf_t hit_dist; /**< @brief dist from r_pt to hit_point */
168 point_t hit_point; /**< @brief DEPRECATED: Intersection point, use VJOIN1 hit_dist */
169 vect_t hit_normal; /**< @brief DEPRECATED: Surface Normal at hit_point, use RT_HIT_NORMAL */
170 vect_t hit_vpriv; /**< @brief PRIVATE vector for xxx_*() */
171 void * hit_private; /**< @brief PRIVATE handle for xxx_shot() */
172 int hit_surfno; /**< @brief solid-specific surface indicator */
173 struct nmg_ray * hit_rayp; /**< @brief pointer to defining ray */
174};
175
176struct nmg_seg {
177 struct bu_list l;
178 struct nmg_hit seg_in; /**< @brief IN information */
179 struct nmg_hit seg_out; /**< @brief OUT information */
180 void * seg_stp; /**< @brief pointer back to soltab */
181};
182
184 struct bu_list l;
185 struct nmg_hit hit;
186 fastf_t dist_in_plane; /**< @brief distance from plane intersect */
187 int in_out; /**< @brief status of ray as it transitions
188 * this hit point.
189 */
194 int start_stop; /**< @brief is this a seg_in or seg_out */
195 struct nmg_hitmiss *other; /**< @brief for keeping track of the other
196 * end of the segment when we know
197 * it
198 */
199};
200
201/**
202 * Ray Data structure
203 *
204 * A) the hitmiss table has one element for each nmg structure in the
205 * nmgmodel. The table keeps track of which elements have been
206 * processed before and which haven't. Elements in this table will
207 * either be: (NULL) item not previously processed hitmiss ptr item
208 * previously processed
209 *
210 * the 0th item in the array is a pointer to the head of the "hit"
211 * list. The 1th item in the array is a pointer to the head of the
212 * "miss" list.
213 *
214 * B) If plane_pt is non-null then we are currently processing a face
215 * intersection. The plane_dist and ray_dist_to_plane are valid. The
216 * ray/edge intersector should check the distance from the plane
217 * intercept to the edge and update "plane_closest" if the current
218 * edge is closer to the intercept than the previous closest object.
219 */
221 uint32_t magic;
222 struct model *rd_m;
223 char *manifolds; /**< @brief structure 1-3manifold table */
225 struct nmg_ray *rp;
226 void * *ap;
228 void * *stp;
229 const struct bn_tol *tol;
230 struct nmg_hitmiss **hitmiss; /**< @brief 1 struct hitmiss ptr per elem. */
231 struct bu_list rd_hit; /**< @brief list of hit elements */
232 struct bu_list rd_miss; /**< @brief list of missed/sub-hit elements */
233
234/* The following are to support isect_ray_face() */
235
236 /**
237 * plane_pt is the intercept point of the ray with the plane of
238 * the face.
239 */
240 point_t plane_pt; /**< @brief ray/plane(face) intercept point */
241
242 /**
243 * ray_dist_to_plane is the parametric distance along the ray from
244 * the ray origin (rd->rp->r_pt) to the ray/plane intercept point
245 */
246 fastf_t ray_dist_to_plane; /**< @brief ray parametric dist to plane */
247
248 /**
249 * the "face_subhit" element is a boolean used by isect_ray_face
250 * and [e|v]u_touch_func to record the fact that the
251 * ray/(plane/face) intercept point was within tolerance of an
252 * edge/vertex of the face. In such instances, isect_ray_face
253 * does NOT need to generate a hit point for the face, as the hit
254 * point for the edge/vertex will suffice.
255 */
257
258 /**
259 * the "classifying_ray" flag indicates that this ray is being
260 * used to classify a point, so that the "eu_touch" and "vu_touch"
261 * functions should not be called.
262 */
264};
265
266int
268 const fastf_t *invdir, /* inverses of rp->r_dir[] */
269 const fastf_t *min,
270 const fastf_t *max);
271
272NMG_EXPORT extern int nmg_class_ray_vs_shell(struct nmg_ray *rp,
273 const struct shell *s,
274 const int in_or_out_only,
275 struct bu_list *vlfree,
276 const struct bn_tol *tol);
277
278NMG_EXPORT extern void nmg_isect_ray_model(struct nmg_ray_data *rd, struct bu_list *vlfree);
279
280__END_DECLS
281
282#endif /* NMG_RAY_H */
283/** @} */
284/*
285 * Local Variables:
286 * mode: C
287 * tab-width: 8
288 * indent-tabs-mode: t
289 * c-file-style: "stroustrup"
290 * End:
291 * ex: shiftwidth=4 tabstop=8
292 */
Header file for the BRL-CAD common definitions.
void int char int int double * min
Definition: tig.h:182
int nmg_class_ray_vs_shell(struct nmg_ray *rp, const struct shell *s, const int in_or_out_only, struct bu_list *vlfree, const struct bn_tol *tol)
void nmg_isect_ray_model(struct nmg_ray_data *rd, struct bu_list *vlfree)
struct bu_list re_nmgfree
head of NMG hitmiss freelist
int ray_in_rpp(struct nmg_ray *rp, const fastf_t *invdir, const fastf_t *min, const fastf_t *max)
fastf_t vect_t[ELEMENTS_PER_VECT]
3-tuple vector
Definition: vmath.h:345
double fastf_t
fastest 64-bit (or larger) floating point type
Definition: vmath.h:330
fastf_t point_t[ELEMENTS_PER_POINT]
3-tuple point
Definition: vmath.h:351
Definition: tol.h:72
Definition: list.h:131
Information about where a ray hits the surface.
Definition: hit.h:61
NMG topological model.
Definition: topology.h:289
Definition: ray.h:165
vect_t hit_normal
DEPRECATED: Surface Normal at hit_point, use RT_HIT_NORMAL.
Definition: ray.h:169
struct nmg_ray * hit_rayp
pointer to defining ray
Definition: ray.h:173
point_t hit_point
DEPRECATED: Intersection point, use VJOIN1 hit_dist.
Definition: ray.h:168
uint32_t hit_magic
Definition: ray.h:166
int hit_surfno
solid-specific surface indicator
Definition: ray.h:172
vect_t hit_vpriv
PRIVATE vector for xxx_*()
Definition: ray.h:170
fastf_t hit_dist
dist from r_pt to hit_point
Definition: ray.h:167
void * hit_private
PRIVATE handle for xxx_shot()
Definition: ray.h:171
long * inbound_use
Definition: ray.h:190
vect_t inbound_norm
Definition: ray.h:191
struct nmg_hitmiss * other
for keeping track of the other end of the segment when we know it
Definition: ray.h:195
fastf_t dist_in_plane
distance from plane intersect
Definition: ray.h:186
long * outbound_use
Definition: ray.h:192
vect_t outbound_norm
Definition: ray.h:193
int start_stop
is this a seg_in or seg_out
Definition: ray.h:194
struct bu_list l
Definition: ray.h:184
int in_out
status of ray as it transitions this hit point.
Definition: ray.h:187
int face_subhit
Definition: ray.h:256
struct model * rd_m
Definition: ray.h:222
struct bu_list rd_hit
list of hit elements
Definition: ray.h:231
void ** stp
Definition: ray.h:228
struct nmg_hitmiss ** hitmiss
1 struct hitmiss ptr per elem.
Definition: ray.h:230
uint32_t magic
Definition: ray.h:221
struct nmg_ray * rp
Definition: ray.h:225
char * manifolds
structure 1-3manifold table
Definition: ray.h:223
const struct bn_tol * tol
Definition: ray.h:229
struct bu_list rd_miss
list of missed/sub-hit elements
Definition: ray.h:232
void ** ap
Definition: ray.h:226
fastf_t ray_dist_to_plane
ray parametric dist to plane
Definition: ray.h:246
vect_t rd_invdir
Definition: ray.h:224
int classifying_ray
Definition: ray.h:263
struct nmg_seg * seghead
Definition: ray.h:227
point_t plane_pt
ray/plane(face) intercept point
Definition: ray.h:240
Definition: ray.h:157
point_t r_pt
Point at which ray starts.
Definition: ray.h:159
fastf_t r_max
exit dist from bounding sphere
Definition: ray.h:162
uint32_t magic
Definition: ray.h:158
vect_t r_dir
Direction of ray (UNIT Length)
Definition: ray.h:160
fastf_t r_min
entry dist to bounding sphere
Definition: ray.h:161
Definition: ray.h:176
struct nmg_hit seg_out
OUT information.
Definition: ray.h:179
struct nmg_hit seg_in
IN information.
Definition: ray.h:178
void * seg_stp
pointer back to soltab
Definition: ray.h:180
struct bu_list l
Definition: ray.h:177
NMG topological shell.
Definition: topology.h:261
fundamental vector, matrix, quaternion math macros