BRL-CAD
hit.h
Go to the documentation of this file.
1/* H I T . H
2 * BRL-CAD
3 *
4 * Copyright (c) 1993-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/** @addtogroup rt_hit
21 * @brief Information about where a ray hits the surface.
22 *
23 * The hit structure contains information about an
24 * individual boundary/ray intersection.
25 *
26 * This is the lowest level of intersection information returned by
27 * LIBRT's intersection logic. Generally, multiple hits are used
28 * by higher level routines to construct segments (per shape)
29 * and partitions (boolean evaluations of multiple segments which
30 * constitute the actual portion of the ray deemed to have passed
31 * through solid geometry.)
32 *
33 */
34/** @{ */
35/** @file rt/hit.h */
36
37#ifndef RT_HIT_H
38#define RT_HIT_H
39
40#include "common.h"
41#include "vmath.h"
42#include "bu/magic.h"
43#include "bu/vls.h"
44#include "rt/defines.h"
45#include "rt/xray.h"
46
47__BEGIN_DECLS
48
49/**
50 * @brief
51 * Information about where a ray hits the surface.
52 *
53 *
54 * Important Note: Surface Normals always point OUT of a solid.
55 *
56 * DEPRECATED: The hit_point and hit_normal elements will be removed
57 * from this structure, so as to separate the concept of the solid's
58 * normal at the hit point from the post-boolean normal at the hit
59 * point.
60 */
61struct hit {
62 uint32_t hit_magic;
63 fastf_t hit_dist; /**< @brief dist from r_pt to hit_point */
64 point_t hit_point; /**< @brief DEPRECATED: Intersection point, use VJOIN1 hit_dist */
65 vect_t hit_normal; /**< @brief DEPRECATED: Surface Normal at hit_point, use RT_HIT_NORMAL */
66 vect_t hit_vpriv; /**< @brief PRIVATE vector for xxx_*() */
67 void * hit_private; /**< @brief PRIVATE handle for xxx_shot() */
68 int hit_surfno; /**< @brief solid-specific surface indicator */
69 struct xray * hit_rayp; /**< @brief pointer to defining ray */
70};
71#define HIT_NULL ((struct hit *)0)
72#define RT_CK_HIT(_p) BU_CKMAG(_p, RT_HIT_MAGIC, "struct hit")
73#define RT_HIT_INIT_ZERO { RT_HIT_MAGIC, 0.0, VINIT_ZERO, VINIT_ZERO, VINIT_ZERO, NULL, 0, NULL }
74
75/**
76 * Compute normal into (_hitp)->hit_normal.
77 *
78 * Set flip-flag accordingly depending on boolean logic, as one hit
79 * may be shared between multiple partitions with different flip
80 * status.
81 *
82 * Example: box.r = box.s - sph.s; sph.r = sph.s
83 *
84 * Return the post-boolean normal into caller-provided _normal vector.
85 */
86#define RT_HIT_NORMAL(_normal, _hitp, _stp, _unused, _flipflag) { \
87 RT_CK_HIT(_hitp); \
88 RT_CK_SOLTAB(_stp); \
89 RT_CK_FUNCTAB((_stp)->st_meth); \
90 { \
91 void *_n = (void *)_normal; \
92 if ((_stp)->st_meth->ft_norm) { \
93 (_stp)->st_meth->ft_norm(_hitp, _stp, (_hitp)->hit_rayp); \
94 } \
95 if (_n != NULL) { \
96 int _f = (int)_flipflag; \
97 if (_f) { \
98 VREVERSE((fastf_t *)_normal, (_hitp)->hit_normal); \
99 } else { \
100 VMOVE((fastf_t *)_normal, (_hitp)->hit_normal); \
101 } \
102 } \
103 } \
104 }
105
106/* A more powerful interface would be: */
107/* RT_GET_NORMAL(_normal, _partition, inhit/outhit flag, ap) */
108
109/**
110 * Information about curvature of the surface at a hit point. The
111 * principal direction pdir has unit length and principal curvature
112 * c1. |c1| <= |c2|, i.e. c1 is the most nearly flat principle
113 * curvature. A POSITIVE curvature indicates that the surface bends
114 * TOWARD the (outward pointing) normal vector at that point. c1 and
115 * c2 are the inverse radii of curvature. The other principle
116 * direction is implied: pdir2 = normal x pdir1.
117 */
118struct curvature {
119 vect_t crv_pdir; /**< @brief Principle direction */
120 fastf_t crv_c1; /**< @brief curvature in principle dir */
121 fastf_t crv_c2; /**< @brief curvature in other direction */
122};
123#define CURVE_NULL ((struct curvature *)0)
124#define RT_CURVATURE_INIT_ZERO { VINIT_ZERO, 0.0, 0.0 }
125
126/**
127 * Use this macro after having computed the normal, to compute the
128 * curvature at a hit point.
129 *
130 * In Release 4.4 and earlier, this was called RT_CURVE(). When the
131 * extra argument was added the name was changed.
132 */
133#define RT_CURVATURE(_curvp, _hitp, _flipflag, _stp) { \
134 RT_CK_HIT(_hitp); \
135 RT_CK_SOLTAB(_stp); \
136 RT_CK_FUNCTAB((_stp)->st_meth); \
137 if ((_stp)->st_meth->ft_curve) { \
138 (_stp)->st_meth->ft_curve(_curvp, _hitp, _stp); \
139 } \
140 if (_flipflag) { \
141 (_curvp)->crv_c1 = - (_curvp)->crv_c1; \
142 (_curvp)->crv_c2 = - (_curvp)->crv_c2; \
143 } \
144 }
145
146/* A more powerful interface would be: */
147/* RT_GET_CURVATURE(_curvp, _partition, inhit/outhit flag, ap) */
148
149/**
150 * Mostly for texture mapping, information about parametric space.
151 */
152struct uvcoord {
153 fastf_t uv_u; /**< @brief Range 0..1 */
154 fastf_t uv_v; /**< @brief Range 0..1 */
155 fastf_t uv_du; /**< @brief delta in u */
156 fastf_t uv_dv; /**< @brief delta in v */
157};
158#define RT_HIT_UVCOORD(ap, _stp, _hitp, uvp) { \
159 RT_CK_HIT(_hitp); \
160 RT_CK_SOLTAB(_stp); \
161 RT_CK_FUNCTAB((_stp)->st_meth); \
162 if ((_stp)->st_meth->ft_uv) { \
163 (_stp)->st_meth->ft_uv(ap, _stp, _hitp, uvp); \
164 } \
165 }
166
167
168/* A more powerful interface would be: */
169/* RT_GET_UVCOORD(_uvp, _partition, inhit/outhit flag, ap) */
170
171/* Print a bit vector */
172RT_EXPORT extern void rt_pr_hit(const char *str,
173 const struct hit *hitp);
174RT_EXPORT extern void rt_pr_hit_vls(struct bu_vls *v,
175 const char *str,
176 const struct hit *hitp);
177RT_EXPORT extern void rt_pr_hitarray_vls(struct bu_vls *v,
178 const char *str,
179 const struct hit *hitp,
180 int count);
181
182__END_DECLS
183
184#endif /* RT_HIT_H */
185/** @} */
186/*
187 * Local Variables:
188 * tab-width: 8
189 * mode: C
190 * indent-tabs-mode: t
191 * c-file-style: "stroustrup"
192 * End:
193 * ex: shiftwidth=4 tabstop=8
194 */
Header file for the BRL-CAD common definitions.
void rt_pr_hit(const char *str, const struct hit *hitp)
void rt_pr_hit_vls(struct bu_vls *v, const char *str, const struct hit *hitp)
void rt_pr_hitarray_vls(struct bu_vls *v, const char *str, const struct hit *hitp, int count)
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
Global registry of recognized magic numbers.
Definition: vls.h:53
Definition: hit.h:118
vect_t crv_pdir
Principle direction.
Definition: hit.h:119
fastf_t crv_c1
curvature in principle dir
Definition: hit.h:120
fastf_t crv_c2
curvature in other direction
Definition: hit.h:121
Information about where a ray hits the surface.
Definition: hit.h:61
vect_t hit_normal
DEPRECATED: Surface Normal at hit_point, use RT_HIT_NORMAL.
Definition: hit.h:65
struct xray * hit_rayp
pointer to defining ray
Definition: hit.h:69
point_t hit_point
DEPRECATED: Intersection point, use VJOIN1 hit_dist.
Definition: hit.h:64
uint32_t hit_magic
Definition: hit.h:62
int hit_surfno
solid-specific surface indicator
Definition: hit.h:68
vect_t hit_vpriv
PRIVATE vector for xxx_*()
Definition: hit.h:66
fastf_t hit_dist
dist from r_pt to hit_point
Definition: hit.h:63
void * hit_private
PRIVATE handle for xxx_shot()
Definition: hit.h:67
Definition: hit.h:152
fastf_t uv_du
delta in u
Definition: hit.h:155
fastf_t uv_v
Range 0..1.
Definition: hit.h:154
fastf_t uv_u
Range 0..1.
Definition: hit.h:153
fastf_t uv_dv
delta in v
Definition: hit.h:156
Primary ray data structure.
Definition: xray.h:41
fundamental vector, matrix, quaternion math macros