BRL-CAD
pattern.h
Go to the documentation of this file.
1/* R T _ P A T T E R N . 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_pattern
21 * @brief Functionality for generating patterns of rays.
22 */
23/** @{ */
24/** @file rt/pattern.h */
25
26#ifndef RT_PATTERN_H
27#define RT_PATTERN_H
28
29#include "common.h"
30
31#include "rt/defines.h"
32#include "rt/xray.h"
33
34__BEGIN_DECLS
35
36/**
37 * Initial set of 'xrays' pattern generators that can
38 * used to feed a bundle set of rays to rt_shootrays()
39 */
40
41/**
42 * PRIVATE: this is new API and should be considered private for the
43 * time being.
44 */
45RT_EXPORT extern int rt_raybundle_maker(struct xray *rp, double radius, const fastf_t *avec, const fastf_t *bvec, int rays_per_ring, int nring);
46
47
48/** Available ray generation patterns */
49typedef enum {
50 RT_PATTERN_RECT_ORTHOGRID, /*!< grid of rays with parallel normals */
51 RT_PATTERN_RECT_PERSPGRID, /*!< rays from a point with diverging normals to a grid */
52 RT_PATTERN_CIRC_ORTHOGRID, /*!< circular subset of RECT_ORTHOGRID rays */
53 RT_PATTERN_CIRC_PERSPGRID, /*!< circular subset of RECT_PERSPGRID rays */
54 RT_PATTERN_CIRC_SPIRAL, /*!< rays in a circular spiral pattern */
55 RT_PATTERN_ELLIPSE_ORTHOGRID, /*!< elliptical subset of RECT_ORTHOGRID rays */
56 RT_PATTERN_ELLIPSE_PERSPGRID, /*!< elliptical subset of RECT_PERSPGRID rays */
57 RT_PATTERN_CIRC_LAYERS, /*!< cylindrical layers of circular arrays */
58 RT_PATTERN_SPH_LAYERS, /*!< layers of circular rays with the circle radius of each layer described by slices of a sphere */
59 RT_PATTERN_SPH_QRAND, /*!< quasi-random unbiased spherical volume sampling pattern */
60 RT_PATTERN_UNKNOWN /*!< unknown pattern */
62
63
64/**
65 * Data container used to supply options to and receive data from
66 * the rt_pattern generator function
67 */
69 /* output - MUST DO this should really be an array of fastf_t numbers... */
70 fastf_t *rays; /*!< An array of px,py,pz,nx,ny,nz ray/normal results */
71 size_t ray_cnt;
72 /* inputs */
73 point_t center_pt; /*!< "Seed" ray point */
74 vect_t center_dir; /*!< "Seed" ray normal */
75 size_t vn; /*!< Number of additional vect_t input parameters */
76 vect_t *n_vec; /*!< Array of vect_t input parameters */
77 size_t pn; /*!< Number of additional floating point number parameters */
78 fastf_t *n_p; /*!< Array of fastf_t input parameters */
79};
80#define RT_PATTERN_DATA_INIT_ZERO {NULL, 0, {0, 0, 0}, {0, 0, 0}, 0, NULL, 0, NULL}
81
82/**
83 * Make a bundle of rays around a main ray using a generator
84 *
85 * If data is NULL, return -1
86 *
87 * If the data in the rt_pattern_data struct does not meet the requirements
88 * of the specified pattern, return -2
89 *
90 * If data->rays is NULL, return the number of rays that would have
91 * been generated.
92 *
93 * If data->rays is not NULL and ray_cnt does not match the number of rays
94 * that will be generated, return -3.
95 *
96 * If data->rays is not NULL and ray_cnt matches the number of rays
97 * that will be generated, assign rays to the rays output.
98 *
99 *
100 * Pattern data for each pattern type:
101 * ===================================
102 *
103 * * all lengths are in mm;
104 * * center_ray.r_dir must have unit length, if
105 * * parameter data arrays are necessary they are the responsibility of
106 * the calling function
107 *
108 * RT_PATTERN_RECT_ORTHOGRID:
109 * --------------------------
110 * Make a bundle of orthogonal rays around a center ray as a uniform
111 * rectangular grid. Grid extents are from -a_vec to a_vec and -b_vec
112 * to b_vec.
113 *
114 * Param | Description
115 * --------------------- | -----------
116 * center_pt, center_dir | Initializing ray at center of pattern
117 * n_vec[0] | Direction for up
118 * n_vec[1] | Direction for right
119 * n_p[0] | Offset between rays in the a direction
120 * n_p[1] | Offset between rays in the b direction
121 *
122 * RT_PATTERN_RECT_PERSPGRID:
123 * --------------------------
124 * Make a bundle of rays around a main ray in the shape of a frustum
125 * as a uniform rectangular grid.
126 *
127 * Param | Description
128 * --------------------- | -----------
129 * center_pt, center_dir | Initializing ray at center of pattern
130 * n_vec[0] | Direction for up
131 * n_vec[1] | Direction for right
132 * n_p[0] | angle of divergence in the direction of n_vec[0]
133 * n_p[1] | angle of divergence in the direction of n_vec[1]
134 * n_p[2] |
135 * n_p[3] |
136 *
137 * RT_PATTERN_CIRC_ORTHOGRID:
138 * --------------------------
139 * Make a bundle of rays around a main ray using a uniform rectangular
140 * grid pattern with a circular extent.
141 *
142 * Param | Description
143 * --------------------- | -----------
144 * center_pt, center_dir | Initializing ray at center of pattern
145 * n_vec[0] | Direction for up
146 * n_p[0] | grid size
147 * n_p[1] | Radius
148 *
149 * RT_PATTERN_CIRC_PERSPGRID:
150 * --------------------------
151 * Make a bundle of rays around a main ray in the shape of a cone,
152 * using a uniform rectangular grid.
153 *
154 * Param | Description
155 * --------------------- | -----------
156 * center_pt, center_dir | Initializing ray at center of pattern
157 * n_vec[0] | Direction for up
158 * n_p[0] | Angle of divergence of the cone
159 * n_p[1] | Number of rays that line on each radial ring of the cone
160 *
161 * RT_PATTERN_CIRC_SPIRAL:
162 * --------------------------
163 * Make a concentric set of circles of rays (rings) around a main ray.
164 *
165 * Param | Description
166 * --------------------- | -----------
167 * center_pt, center_dir | Initializing ray at center of pattern
168 * n_p[0] | Pattern maximum radius
169 * n_p[1] | Number of rays per ring
170 * n_p[2] | Number of rings
171 * n_p[3] | Spiral skew
172 *
173 * RT_PATTERN_ELLIPSE_ORTHOGRID:
174 * -------------------
175 * Make a bundle of rays around a main ray using a uniform rectangular
176 * grid pattern with an elliptical extent.
177 *
178 * Param | Description
179 * --------------------- | -----------
180 * center_pt, center_dir | Initializing ray at center of pattern
181 * n_vec[0] | Direction for up
182 * n_vec[1] | Direction for right
183 * n_p[0] | grid size
184 *
185 * RT_PATTERN_ELLIPSE_PERSPGRID:
186 * -----------------------------
187 * TODO
188 *
189 * RT_PATTERN_CIRC_LAYERS:
190 * -----------------------------
191 * TODO
192 *
193 * RT_PATTERN_SPH_LAYERS:
194 * -----------------------------
195 * TODO
196 *
197 * RT_PATTERN_SPH_QRAND:
198 * -----------------------------
199 * TODO - maybe start here? http://mathworld.wolfram.com/SpherePointPicking.html
200 *
201 * return negative on error (data will be unmodified in error condition)
202 * ray count on success (>=0)
203 *
204 *
205 * If ray count greater than zero, data->rays array will hold rays generated by pattern
206 *
207 *
208 * The following is an example:
209 * @code
210 * int ray_cnt = 0;
211 * struct rt_pattern_data data = RT_PATTERN_DATA_INIT;
212 * VSET(data.a_vec, 0, 0, 1);
213 * data.p1 = 0.1
214 * data.p2 = 10
215 * ray_cnt = rt_pattern(&data, RT_CIRCULAR_GRID);
216 * if (ray_cnt < 0) {
217 * bu_log("error");
218 * } else {
219 * do_something_with_rays(data.rays);
220 * bu_free(data.rays);
221 * }
222 * @endcode
223 */
224RT_EXPORT extern int rt_pattern(struct rt_pattern_data *data, rt_pattern_t type);
225
226/**
227 * Make a bundle of rays around a main ray using a uniform rectangular
228 * grid pattern with an elliptical extent.
229 *
230 * avec and bvec a. The gridsize is
231 * given in mm.
232 *
233 * rp[0].r_dir must have unit length.
234 */
235RT_EXPORT extern int rt_gen_elliptical_grid(struct xrays *rays,
236 const struct xray *center_ray,
237 const fastf_t *avec,
238 const fastf_t *bvec,
239 fastf_t gridsize);
240
241/**
242 * Make a bundle of rays around a main ray using a uniform rectangular
243 * grid pattern with a circular extent. The radius, gridsize is given
244 * in mm.
245 *
246 * rp[0].r_dir must have unit length.
247 */
248RT_EXPORT extern int rt_gen_circular_grid(struct xrays *ray_bundle,
249 const struct xray *center_ray,
250 fastf_t radius,
251 const fastf_t *up_vector,
252 fastf_t gridsize);
253
254/**
255 * Make a bundle of rays around a main ray in the shape of a cone,
256 * using a uniform rectangular grid; theta is the angle of divergence
257 * of the cone, and rays_per_radius is the number of rays that lie on
258 * any given radius of the cone.
259 *
260 * center_ray.r_dir must have unit length.
261 */
262RT_EXPORT extern int rt_gen_conic(struct xrays *rays,
263 const struct xray *center_ray,
265 vect_t up_vector,
266 int rays_per_radius);
267
268/**
269 * Make a bundle of rays around a main ray in the shape of a frustum
270 * as a uniform rectangular grid. a_vec and b_vec are the directions
271 * for up and right, respectively; a_theta and b_theta are the angles
272 * of divergence in the directions of a_vec and b_vec respectively.
273 * This is useful for creating a grid of rays for perspective
274 * rendering.
275 */
276RT_EXPORT extern int rt_gen_frustum(struct xrays *rays,
277 const struct xray *center_ray,
278 const vect_t a_vec,
279 const vect_t b_vec,
280 const fastf_t a_theta,
281 const fastf_t b_theta,
282 const fastf_t a_num,
283 const fastf_t b_num);
284
285/**
286 * Make a bundle of orthogonal rays around a center ray as a uniform
287 * rectangular grid. a_vec and b_vec are the directions for up and
288 * right, respectively; their magnitudes determine the extent of the
289 * grid (the grid extends from -a_vec to a_vec in the up-direction and
290 * from -b_vec to b_vec in the right direction). da and db are the
291 * offset between rays in the a and b directions respectively.
292 */
293RT_EXPORT extern int rt_gen_rect(struct xrays *rays,
294 const struct xray *center_ray,
295 const vect_t a_vec,
296 const vect_t b_vec,
297 const fastf_t da,
298 const fastf_t db);
299
300__END_DECLS
301
302#endif /* RT_PATTERN_H */
303/** @} */
304/*
305 * Local Variables:
306 * mode: C
307 * tab-width: 8
308 * indent-tabs-mode: t
309 * c-file-style: "stroustrup"
310 * End:
311 * ex: shiftwidth=4 tabstop=8
312 */
Header file for the BRL-CAD common definitions.
void float int int float float * theta
Definition: tig.h:167
int rt_pattern(struct rt_pattern_data *data, rt_pattern_t type)
int rt_gen_circular_grid(struct xrays *ray_bundle, const struct xray *center_ray, fastf_t radius, const fastf_t *up_vector, fastf_t gridsize)
int rt_gen_frustum(struct xrays *rays, const struct xray *center_ray, const vect_t a_vec, const vect_t b_vec, const fastf_t a_theta, const fastf_t b_theta, const fastf_t a_num, const fastf_t b_num)
int rt_gen_rect(struct xrays *rays, const struct xray *center_ray, const vect_t a_vec, const vect_t b_vec, const fastf_t da, const fastf_t db)
int rt_gen_conic(struct xrays *rays, const struct xray *center_ray, fastf_t theta, vect_t up_vector, int rays_per_radius)
int rt_gen_elliptical_grid(struct xrays *rays, const struct xray *center_ray, const fastf_t *avec, const fastf_t *bvec, fastf_t gridsize)
rt_pattern_t
Definition: pattern.h:49
int rt_raybundle_maker(struct xray *rp, double radius, const fastf_t *avec, const fastf_t *bvec, int rays_per_ring, int nring)
@ RT_PATTERN_UNKNOWN
Definition: pattern.h:60
@ RT_PATTERN_CIRC_LAYERS
Definition: pattern.h:57
@ RT_PATTERN_SPH_LAYERS
Definition: pattern.h:58
@ RT_PATTERN_SPH_QRAND
Definition: pattern.h:59
@ RT_PATTERN_RECT_PERSPGRID
Definition: pattern.h:51
@ RT_PATTERN_RECT_ORTHOGRID
Definition: pattern.h:50
@ RT_PATTERN_CIRC_PERSPGRID
Definition: pattern.h:53
@ RT_PATTERN_ELLIPSE_ORTHOGRID
Definition: pattern.h:55
@ RT_PATTERN_CIRC_ORTHOGRID
Definition: pattern.h:52
@ RT_PATTERN_ELLIPSE_PERSPGRID
Definition: pattern.h:56
@ RT_PATTERN_CIRC_SPIRAL
Definition: pattern.h:54
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
size_t ray_cnt
Definition: pattern.h:71
size_t vn
Definition: pattern.h:75
vect_t center_dir
Definition: pattern.h:74
fastf_t * n_p
Definition: pattern.h:78
size_t pn
Definition: pattern.h:77
fastf_t * rays
Definition: pattern.h:70
point_t center_pt
Definition: pattern.h:73
vect_t * n_vec
Definition: pattern.h:76
Primary ray data structure.
Definition: xray.h:41
Definition: xray.h:58