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 * Shoot a bundle of rays
101 *
102 * Function for shooting a bundle of rays. Iteratively walks list of
103 * rays contained in the application bundles xrays field 'b_rays'
104 * passing each single ray to r_shootray().
105 *
106 * Input:
107 *
108 * bundle - Pointer to an application_bundle structure.
109 *
110 * b_ap - Members in this single ray application structure should be
111 * set in a similar fashion as when used with rt_shootray() with the
112 * exception of a_hit() and a_miss(). Default implementations of these
113 * routines are provided that simple update hit/miss counters and
114 * attach the hit partitions and segments to the partition_bundle
115 * structure. Users can still override this default functionality but
116 * have to make sure to move the partition and segment list to the new
117 * partition_bundle structure.
118 *
119 * b_hit() Routine to call when something is hit by the ray bundle.
120 *
121 * b_miss() Routine to call when ray bundle misses everything.
122 *
123 */
125
126
127/**
128 * Shoot a single ray and return the partition list. Handles callback
129 * issues.
130 *
131 * Note that it calls malloc(), therefore should NOT be used if
132 * performance matters.
133 */
135 point_t origin,
137
138
139/**
140 * PRIVATE: this is new API and should be considered private for the
141 * time being.
142 */
143RT_EXPORT extern int rt_shootray_bundle(struct application *ap, struct xray *rays, int nrays);
144
145/**
146 * To be called only in non-parallel mode, to tally up the statistics
147 * from the resource structure(s) into the rt instance structure.
148 *
149 * Non-parallel programs should call
150 * rt_add_res_stats(rtip, RESOURCE_NULL);
151 * to have the default resource results tallied in.
152 */
153RT_EXPORT extern void rt_add_res_stats(struct rt_i *rtip,
154 struct resource *resp);
155/** Tally stats into struct rt_i */
156RT_EXPORT extern void rt_zero_res_stats(struct resource *resp);
157
158
159/**
160 * Release the per-processor state variables needed to support
161 * rt_shootray()'s use of 'solid pieces'.
162 *
163 * Deprecated as a public facing API - this should be an implementation
164 * detail in librt.
165 */
167 struct rt_i *rtip);
168
169/**
170 * Allocate the per-processor state variables needed to support
171 * rt_shootray()'s use of 'solid pieces'.
172 *
173 * Deprecated as a public facing API - this should be an implementation
174 * detail in librt.
175 */
177 struct rt_i *rtip);
178
179
180
181RT_EXPORT extern void rt_vstub(struct soltab *stp[],
182 struct xray *rp[],
183 struct seg segp[],
184 int n,
185 struct application *ap);
186
187
188// Flags for rt_gen_obj_pnts
189#define RT_GEN_OBJ_PNTS_SURF 0x1 /**< @brief save only the first and last hit point on a ray */
190#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) */
191#define RT_GEN_OBJ_PNTS_RAND 0x4 /**< @brief sample using Marsaglia sampling on the bounding sphere with pseudo random numbers */
192#define RT_GEN_OBJ_PNTS_SOBOL 0x8 /**< @brief sample using Marsaglia sampling on the bounding sphere with Sobol' low-discrepancy-sequence generation */
193/**
194 * Generate points from a .g object using raytracing. Various sampling options
195 * are controlled via setting flags.
196 *
197 * Returns: 0 = success, -1 error */
198RT_EXPORT extern int
200 const char *obj, struct bn_tol *tol, int flags, int max_pnts, int max_time, int verbosity);
201
202
203// NOTE: For now this is exposed for testing in libged, but eventually
204// it should be hidden behind the functab methods - NOT to be considered
205// as public API.
206RT_EXPORT extern int
208
209#ifdef USE_OPENCL
210struct cl_hit {
211 cl_double3 hit_point;
212 cl_double3 hit_normal;
213 cl_double3 hit_vpriv;
214 cl_double hit_dist;
215 cl_int hit_surfno;
216};
217
218struct cl_seg {
219 struct cl_hit seg_in;
220 struct cl_hit seg_out;
222};
223
224struct cl_partition {
225 struct cl_hit inhit;
226 struct cl_hit outhit;
229 cl_uint forw_pp; /* index to the next partition */
230 cl_uint back_pp; /* index to the previous partition */
231 cl_uint region_id; /* id of the "owning" region */
232 cl_char inflip; /* flip inhit->hit_normal */
233 cl_char outflip; /* flip outhit->hit_normal */
234};
235
236RT_EXPORT extern void
237clt_frame(void *pixels, uint8_t o[2], int cur_pixel, int last_pixel,
238 int width, int ibackground[3], int inonbackground[3],
239 double airdensity, double haze[3], fastf_t gamma,
241 fastf_t aspect, int lightmodel, int a_no_booleans);
242#endif
243
244
245
247
248#endif /* RT_SHOOT_H */
249/** @} */
250/*
251 * Local Variables:
252 * tab-width: 8
253 * mode: C
254 * indent-tabs-mode: t
255 * c-file-style: "stroustrup"
256 * End:
257 * ex: shiftwidth=4 tabstop=8
258 */
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.
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