BRL-CAD
Loading...
Searching...
No Matches
shoot.h
Go to the documentation of this file.
1/* S H O O T . H
2 * BRL-CAD
3 *
4 * Copyright (c) 1993-2026 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/** @addtogroup rt_shoot
22 *
23 * @brief
24 * Ray Tracing program shot coordinator. This is the heart of LIBRT's ray-tracing capability.
25 *
26 * Given a ray, shoot it at all the relevant parts of the model,
27 * (building the finished_segs chain), and then call rt_boolregions()
28 * to build and evaluate the partition chain. If the ray actually hit
29 * anything, call the application's a_hit() routine with a pointer to
30 * the partition chain, otherwise, call the application's a_miss()
31 * routine.
32 *
33 * It is important to note that rays extend infinitely only in the
34 * positive direction. The ray is composed of all points P, where
35 *
36 * P = r_pt + K * r_dir
37 *
38 * for K ranging from 0 to +infinity. There is no looking backwards.
39 *
40
41 * */
42/** @{ */
43/** @file rt/shoot.h */
44
45#ifndef RT_SHOOT_H
46#define RT_SHOOT_H
47
48#include "common.h"
49#include "vmath.h"
50#include "rt/defines.h"
51#include "rt/db_instance.h"
52#include "rt/application.h"
53#include "rt/geom.h"
54#include "rt/xray.h"
55
57
58/**
59 * @brief
60 * Shoot a ray
61 *
62 * Note that the direction vector r_dir must have unit length; this is
63 * mandatory, and is not ordinarily checked, in the name of
64 * efficiency.
65 *
66 * Input: Pointer to an application structure, with these mandatory fields:
67 * a_ray.r_pt ==> Starting point of ray to be fired
68 * a_ray.r_dir => UNIT VECTOR with direction to fire in (dir cosines)
69 * a_hit =======> Routine to call when something is hit
70 * a_miss ======> Routine to call when ray misses everything
71 *
72 * Calls user's a_miss() or a_hit() routine as appropriate passing
73 * a_hit() a list of partitions intersected. Note that only the
74 * hit_dist elements of pt_inhit and pt_outhit are computed. To
75 * compute both hit_point and hit_normal, use:
76 *
77 * RT_HIT_NORMAL(NULL, hitp, stp, rayp, 0);
78 *
79 * To compute just the hit_point, use:
80 *
81 * VJOIN1(hitp->hit_point, rp->r_pt, hitp->hit_dist, rp->r_dir);
82 *
83 * These calculations are deferred to user code to avoid needless
84 * computation in other ray situations.
85 *
86 * Formal Return: whatever the application function returns (an int).
87 *
88 * NOTE: The application functions may call rt_shootray() recursively.
89 * Thus, none of the local variables may be static.
90 *
91 * To prevent having to lock the statistics variables in a PARALLEL
92 * environment, all the statistics variables have been moved into the
93 * 'resource' structure, which is allocated per-CPU.
94 */
95RT_EXPORT extern int rt_shootray(struct application *ap);
96
97
98/**
99 * @brief
100 * EXPERIMENTAL vectorized single-ray shooter.
101 *
102 * A drop-in alternative to rt_shootray() that, instead of walking the
103 * space partitioning and shooting solids one at a time, shoots the ray
104 * against ALL solids of each type in one batched ft_vshot() call (falling
105 * back to the per-ray stub for types lacking a vshot), then weaves the
106 * resulting segments through the normal rt_boolweave()/rt_boolfinal()
107 * pipeline and invokes a_hit()/a_miss() exactly like rt_shootray().
108 *
109 * Intended for exercising and benchmarking the ft_vshot() callbacks from
110 * userland (e.g. toggled by an environment variable in rt). Because it
111 * forgoes per-solid spatial culling and returns a single (outer-span)
112 * segment per solid, it is best suited to scenes of many convex solids of
113 * the same type; non-convex solids that produce multiple segments are
114 * approximated by their outer span.
115 */
116RT_EXPORT extern int rt_vshootray(struct application *ap);
117
118
119/**
120 * @brief
121 * Shoot a bundle of rays
122 *
123 * Function for shooting a bundle of rays. Iteratively walks list of
124 * rays contained in the application bundles xrays field 'b_rays'
125 * passing each single ray to r_shootray().
126 *
127 * Input:
128 *
129 * bundle - Pointer to an application_bundle structure.
130 *
131 * b_ap - Members in this single ray application structure should be
132 * set in a similar fashion as when used with rt_shootray() with the
133 * exception of a_hit() and a_miss(). Default implementations of these
134 * routines are provided that simple update hit/miss counters and
135 * attach the hit partitions and segments to the partition_bundle
136 * structure. Users can still override this default functionality but
137 * have to make sure to move the partition and segment list to the new
138 * partition_bundle structure.
139 *
140 * b_hit() Routine to call when something is hit by the ray bundle.
141 *
142 * b_miss() Routine to call when ray bundle misses everything.
143 *
144 */
146
147
148/**
149 * Shoot a single ray and return the partition list. Handles callback
150 * issues.
151 *
152 * Note that it calls malloc(), therefore should NOT be used if
153 * performance matters.
154 */
156 point_t origin,
158
159
160/**
161 * PRIVATE: this is new API and should be considered private for the
162 * time being.
163 */
164RT_EXPORT extern int rt_shootray_bundle(struct application *ap, struct xray *rays, int nrays);
165
166/**
167 * To be called only in non-parallel mode, to tally up the statistics
168 * from the resource structure(s) into the rt instance structure.
169 *
170 * Non-parallel programs should call
171 * rt_add_res_stats(rtip, RESOURCE_NULL);
172 * to have the default resource results tallied in.
173 */
174RT_EXPORT extern void rt_add_res_stats(struct rt_i *rtip,
175 struct resource *resp);
176/** Tally stats into struct rt_i */
177RT_EXPORT extern void rt_zero_res_stats(struct resource *resp);
178
179
180/**
181 * Release the per-processor state variables needed to support
182 * rt_shootray()'s use of 'solid pieces'.
183 *
184 * Deprecated as a public facing API - this should be an implementation
185 * detail in librt.
186 */
188 struct rt_i *rtip);
189
190/**
191 * Allocate the per-processor state variables needed to support
192 * rt_shootray()'s use of 'solid pieces'.
193 *
194 * Deprecated as a public facing API - this should be an implementation
195 * detail in librt.
196 */
198 struct rt_i *rtip);
199
200
201
202RT_EXPORT extern void rt_vstub(struct soltab *stp[],
203 struct xray *rp[],
204 struct seg segp[],
205 int n,
206 struct application *ap);
207
208
209// Flags for rt_gen_obj_pnts
210#define RT_GEN_OBJ_PNTS_SURF 0x1 /**< @brief save only the first and last hit point on a ray */
211#define RT_GEN_OBJ_PNTS_GRID 0x2 /**< @brief sample using an XYZ grid based on the bounding box (default if no method flags are specified) */
212#define RT_GEN_OBJ_PNTS_RAND 0x4 /**< @brief sample using Marsaglia sampling on the bounding sphere with pseudo random numbers */
213#define RT_GEN_OBJ_PNTS_SOBOL 0x8 /**< @brief sample using Marsaglia sampling on the bounding sphere with Sobol' low-discrepancy-sequence generation */
214/**
215 * Generate points from a .g object using raytracing. Various sampling options
216 * are controlled via setting flags.
217 *
218 * Returns: 0 = success, -1 error */
219RT_EXPORT extern int
221 const char *obj, struct bn_tol *tol, int flags, int max_pnts, int max_time, int verbosity);
222
223
224// NOTE: For now this is exposed for testing in libged, but eventually
225// it should be hidden behind the functab methods - NOT to be considered
226// as public API.
227RT_EXPORT extern int
229
230#ifdef USE_OPENCL
231struct cl_hit {
232 cl_double3 hit_point;
233 cl_double3 hit_normal;
234 cl_double3 hit_vpriv;
235 cl_double hit_dist;
236 cl_int hit_surfno;
237};
238
239struct cl_seg {
240 struct cl_hit seg_in;
241 struct cl_hit seg_out;
243};
244
245struct cl_partition {
246 struct cl_hit inhit;
247 struct cl_hit outhit;
250 cl_uint forw_pp; /* index to the next partition */
251 cl_uint back_pp; /* index to the previous partition */
252 cl_uint region_id; /* id of the "owning" region */
253 cl_char inflip; /* flip inhit->hit_normal */
254 cl_char outflip; /* flip outhit->hit_normal */
255};
256
257RT_EXPORT extern void
258clt_frame(void *pixels, uint8_t o[2], int cur_pixel, int last_pixel,
259 int width, int ibackground[3], int inonbackground[3],
260 double airdensity, double haze[3], fastf_t gamma,
262 fastf_t aspect, int lightmodel, int a_no_booleans);
263#endif
264
265
266
268
269#endif /* RT_SHOOT_H */
270/** @} */
271/*
272 * Local Variables:
273 * tab-width: 8
274 * mode: C
275 * indent-tabs-mode: t
276 * c-file-style: "stroustrup"
277 * End:
278 * ex: shiftwidth=4 tabstop=8
279 */
Definition dvec.h:74
Header file for the BRL-CAD common definitions.
#define DEPRECATED
Definition common.h:433
int rt_shootray_bundle(struct application *ap, struct xray *rays, int nrays)
DEPRECATED void rt_res_pieces_clean(struct resource *resp, struct rt_i *rtip)
int rt_sample_pnts(struct bv_scene_obj *s, struct rt_db_internal *ip)
void rt_add_res_stats(struct rt_i *rtip, struct resource *resp)
void rt_vstub(struct soltab *stp[], struct xray *rp[], struct seg segp[], int n, struct application *ap)
int rt_gen_obj_pnts(struct rt_pnts_internal *rpnts, fastf_t *avg_thickness, struct db_i *dbip, const char *obj, struct bn_tol *tol, int flags, int max_pnts, int max_time, int verbosity)
DEPRECATED void rt_res_pieces_init(struct resource *resp, struct rt_i *rtip)
int rt_shootray(struct application *ap)
Shoot a ray.
int rt_shootrays(struct application_bundle *bundle)
Shoot a bundle of rays.
int rt_vshootray(struct application *ap)
EXPERIMENTAL vectorized single-ray shooter.
struct partition * rt_shootray_simple(struct application *ap, point_t origin, vect_t direction)
void rt_zero_res_stats(struct resource *resp)
fastf_t vect_t[ELEMENTS_PER_VECT]
3-tuple vector
Definition vmath.h:348
double fastf_t
fastest 64-bit (or larger) floating point type
Definition vmath.h:333
fastf_t mat_t[ELEMENTS_PER_MAT]
4x4 matrix
Definition vmath.h:369
fastf_t point_t[ELEMENTS_PER_POINT]
3-tuple point
Definition vmath.h:354
Definition tol.h:72
Definition seg.h:59
Primary ray data structure.
Definition xray.h:41
fundamental vector, matrix, quaternion math macros