BRL-CAD
shoot.h
Go to the documentation of this file.
1/* S H O O 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
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/application.h"
52#include "rt/xray.h"
53
54__BEGIN_DECLS
55
56/**
57 * @brief
58 * Shoot a ray
59 *
60 * Note that the direction vector r_dir must have unit length; this is
61 * mandatory, and is not ordinarily checked, in the name of
62 * efficiency.
63 *
64 * Input: Pointer to an application structure, with these mandatory fields:
65 * a_ray.r_pt ==> Starting point of ray to be fired
66 * a_ray.r_dir => UNIT VECTOR with direction to fire in (dir cosines)
67 * a_hit =======> Routine to call when something is hit
68 * a_miss ======> Routine to call when ray misses everything
69 *
70 * Calls user's a_miss() or a_hit() routine as appropriate passing
71 * a_hit() a list of partitions intersected. Note that only the
72 * hit_dist elements of pt_inhit and pt_outhit are computed. To
73 * compute both hit_point and hit_normal, use:
74 *
75 * RT_HIT_NORMAL(NULL, hitp, stp, rayp, 0);
76 *
77 * To compute just the hit_point, use:
78 *
79 * VJOIN1(hitp->hit_point, rp->r_pt, hitp->hit_dist, rp->r_dir);
80 *
81 * These calculations are deferred to user code to avoid needless
82 * computation in other ray situations.
83 *
84 * Formal Return: whatever the application function returns (an int).
85 *
86 * NOTE: The application functions may call rt_shootray() recursively.
87 * Thus, none of the local variables may be static.
88 *
89 * To prevent having to lock the statistics variables in a PARALLEL
90 * environment, all the statistics variables have been moved into the
91 * 'resource' structure, which is allocated per-CPU.
92 */
93RT_EXPORT extern int rt_shootray(struct application *ap);
94
95
96/**
97 * @brief
98 * Shoot a bundle of rays
99 *
100 * Function for shooting a bundle of rays. Iteratively walks list of
101 * rays contained in the application bundles xrays field 'b_rays'
102 * passing each single ray to r_shootray().
103 *
104 * Input:
105 *
106 * bundle - Pointer to an application_bundle structure.
107 *
108 * b_ap - Members in this single ray application structure should be
109 * set in a similar fashion as when used with rt_shootray() with the
110 * exception of a_hit() and a_miss(). Default implementations of these
111 * routines are provided that simple update hit/miss counters and
112 * attach the hit partitions and segments to the partition_bundle
113 * structure. Users can still override this default functionality but
114 * have to make sure to move the partition and segment list to the new
115 * partition_bundle structure.
116 *
117 * b_hit() Routine to call when something is hit by the ray bundle.
118 *
119 * b_miss() Routine to call when ray bundle misses everything.
120 *
121 */
122RT_EXPORT extern int rt_shootrays(struct application_bundle *bundle);
123
124
125/**
126 * Shoot a single ray and return the partition list. Handles callback
127 * issues.
128 *
129 * Note that it calls malloc(), therefore should NOT be used if
130 * performance matters.
131 */
132RT_EXPORT extern struct partition *rt_shootray_simple(struct application *ap,
133 point_t origin,
134 vect_t direction);
135
136
137/**
138 * PRIVATE: this is new API and should be considered private for the
139 * time being.
140 */
141RT_EXPORT extern int rt_shootray_bundle(struct application *ap, struct xray *rays, int nrays);
142
143/**
144 * To be called only in non-parallel mode, to tally up the statistics
145 * from the resource structure(s) into the rt instance structure.
146 *
147 * Non-parallel programs should call
148 * rt_add_res_stats(rtip, RESOURCE_NULL);
149 * to have the default resource results tallied in.
150 */
151RT_EXPORT extern void rt_add_res_stats(struct rt_i *rtip,
152 struct resource *resp);
153/** Tally stats into struct rt_i */
154RT_EXPORT extern void rt_zero_res_stats(struct resource *resp);
155
156
157RT_EXPORT extern void rt_res_pieces_clean(struct resource *resp,
158 struct rt_i *rtip);
159
160
161/**
162 * Allocate the per-processor state variables needed to support
163 * rt_shootray()'s use of 'solid pieces'.
164 */
165RT_EXPORT extern void rt_res_pieces_init(struct resource *resp,
166 struct rt_i *rtip);
167RT_EXPORT extern void rt_vstub(struct soltab *stp[],
168 struct xray *rp[],
169 struct seg segp[],
170 int n,
171 struct application *ap);
172
173#ifdef USE_OPENCL
174struct cl_hit {
175 cl_double3 hit_point;
176 cl_double3 hit_normal;
177 cl_double3 hit_vpriv;
178 cl_double hit_dist;
179 cl_int hit_surfno;
180};
181
182struct cl_seg {
183 struct cl_hit seg_in;
184 struct cl_hit seg_out;
185 cl_uint seg_sti;
186};
187
188struct cl_partition {
189 struct cl_hit inhit;
190 struct cl_hit outhit;
191 cl_uint inseg;
192 cl_uint outseg;
193 cl_uint forw_pp; /* index to the next partition */
194 cl_uint back_pp; /* index to the previous partition */
195 cl_uint region_id; /* id of the "owning" region */
196 cl_char inflip; /* flip inhit->hit_normal */
197 cl_char outflip; /* flip outhit->hit_normal */
198};
199
200RT_EXPORT extern void
201clt_frame(void *pixels, uint8_t o[2], int cur_pixel, int last_pixel,
202 int width, int ibackground[3], int inonbackground[3],
203 double airdensity, double haze[3], fastf_t gamma,
204 mat_t view2model, fastf_t cell_width, fastf_t cell_height,
205 fastf_t aspect, int lightmodel, int a_no_booleans);
206#endif
207
208
209
210__END_DECLS
211
212#endif /* RT_SHOOT_H */
213/** @} */
214/*
215 * Local Variables:
216 * tab-width: 8
217 * mode: C
218 * indent-tabs-mode: t
219 * c-file-style: "stroustrup"
220 * End:
221 * ex: shiftwidth=4 tabstop=8
222 */
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)
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_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:345
double fastf_t
fastest 64-bit (or larger) floating point type
Definition: vmath.h:330
fastf_t mat_t[ELEMENTS_PER_MAT]
4x4 matrix
Definition: vmath.h:366
fastf_t point_t[ELEMENTS_PER_POINT]
3-tuple point
Definition: vmath.h:351
Definition: seg.h:59
Definition: soltab.h:56
Primary ray data structure.
Definition: xray.h:41
fundamental vector, matrix, quaternion math macros