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-2025 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
159RT_EXPORT extern void rt_res_pieces_clean(struct resource *resp,
160 struct rt_i *rtip);
161
162
163/**
164 * Allocate the per-processor state variables needed to support
165 * rt_shootray()'s use of 'solid pieces'.
166 */
167RT_EXPORT extern void rt_res_pieces_init(struct resource *resp,
168 struct rt_i *rtip);
169RT_EXPORT extern void rt_vstub(struct soltab *stp[],
170 struct xray *rp[],
171 struct seg segp[],
172 int n,
173 struct application *ap);
174
175
176// Flags for rt_gen_obj_pnts
177#define RT_GEN_OBJ_PNTS_SURF 0x1 /**< @brief save only the first and last hit point on a ray */
178#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) */
179#define RT_GEN_OBJ_PNTS_RAND 0x4 /**< @brief sample using Marsaglia sampling on the bounding sphere with pseudo random numbers */
180#define RT_GEN_OBJ_PNTS_SOBOL 0x8 /**< @brief sample using Marsaglia sampling on the bounding sphere with Sobol' low-discrepancy-sequence generation */
181/**
182 * Generate points from a .g object using raytracing. Various sampling options
183 * are controlled via setting flags.
184 *
185 * Returns: 0 = success, -1 error */
186RT_EXPORT extern int
188 const char *obj, struct bn_tol *tol, int flags, int max_pnts, int max_time, int verbosity);
189
190
191// NOTE: For now this is exposed for testing in libged, but eventually
192// it should be hidden behind the functab methods - NOT to be considered
193// as public API.
194RT_EXPORT extern int
196
197#ifdef USE_OPENCL
198struct cl_hit {
199 cl_double3 hit_point;
200 cl_double3 hit_normal;
201 cl_double3 hit_vpriv;
202 cl_double hit_dist;
203 cl_int hit_surfno;
204};
205
206struct cl_seg {
207 struct cl_hit seg_in;
208 struct cl_hit seg_out;
210};
211
212struct cl_partition {
213 struct cl_hit inhit;
214 struct cl_hit outhit;
217 cl_uint forw_pp; /* index to the next partition */
218 cl_uint back_pp; /* index to the previous partition */
219 cl_uint region_id; /* id of the "owning" region */
220 cl_char inflip; /* flip inhit->hit_normal */
221 cl_char outflip; /* flip outhit->hit_normal */
222};
223
224RT_EXPORT extern void
225clt_frame(void *pixels, uint8_t o[2], int cur_pixel, int last_pixel,
226 int width, int ibackground[3], int inonbackground[3],
227 double airdensity, double haze[3], fastf_t gamma,
229 fastf_t aspect, int lightmodel, int a_no_booleans);
230#endif
231
232
233
235
236#endif /* RT_SHOOT_H */
237/** @} */
238/*
239 * Local Variables:
240 * tab-width: 8
241 * mode: C
242 * indent-tabs-mode: t
243 * c-file-style: "stroustrup"
244 * End:
245 * ex: shiftwidth=4 tabstop=8
246 */
Definition dvec.h:74
Header file for the BRL-CAD common definitions.
void float float int * n
Definition tig.h:74
int rt_shootray_bundle(struct application *ap, struct xray *rays, int nrays)
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)
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)
void rt_res_pieces_init(struct resource *resp, struct rt_i *rtip)
fastf_t vect_t[ELEMENTS_PER_VECT]
3-tuple vector
Definition vmath.h:349
double fastf_t
fastest 64-bit (or larger) floating point type
Definition vmath.h:334
fastf_t mat_t[ELEMENTS_PER_MAT]
4x4 matrix
Definition vmath.h:370
fastf_t point_t[ELEMENTS_PER_POINT]
3-tuple point
Definition vmath.h:355
Definition tol.h:72
Definition seg.h:59
Primary ray data structure.
Definition xray.h:41
fundamental vector, matrix, quaternion math macros