BRL-CAD
calc.h
Go to the documentation of this file.
1/* C A L C . 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 raytrace */
21/** @{ */
22/** @file rt/calc.h
23 * @brief
24 * In memory format for non-geometry objects in BRL-CAD databases.
25 */
26
27#ifndef RT_CALC_H
28#define RT_CALC_H
29
30#include "common.h"
31
32/* system headers */
33#include <stdio.h> /* for FILE */
34
35/* interface headers */
36#include "vmath.h"
37#include "bu/vls.h"
38#include "bn/poly.h"
39#include "rt/defines.h"
40
41__BEGIN_DECLS
42
43/* apply a matrix transformation */
44/**
45 * apply a matrix transformation to a given input object, setting the
46 * resultant transformed object as the output solid. if freeflag is
47 * set, the input object will be released.
48 *
49 * returns zero if matrix transform was applied, non-zero on failure.
50 */
51RT_EXPORT extern int rt_matrix_transform(struct rt_db_internal *output, const mat_t matrix, struct rt_db_internal *input, int free_input, struct db_i *dbip, struct resource *resource);
52
53/* find RPP of one region */
54
55/**
56 * Calculate the bounding RPP for a region given the name of the
57 * region node in the database. See remarks in _rt_getregion() above
58 * for name conventions. Returns 0 for failure (and prints a
59 * diagnostic), or 1 for success.
60 */
61RT_EXPORT extern int rt_rpp_region(struct rt_i *rtip,
62 const char *reg_name,
63 fastf_t *min_rpp,
64 fastf_t *max_rpp);
65
66/**
67 * Compute the intersections of a ray with a rectangular
68 * parallelepiped (RPP) that has faces parallel to the coordinate
69 * planes
70 *
71 * The algorithm here was developed by Gary Kuehl for GIFT. A good
72 * description of the approach used can be found in "??" by XYZZY and
73 * Barsky, ACM Transactions on Graphics, Vol 3 No 1, January 1984.
74 *
75 * Note: The computation of entry and exit distance is mandatory, as
76 * the final test catches the majority of misses.
77 *
78 * Note: A hit is returned if the intersect is behind the start point.
79 *
80 * Returns -
81 * 0 if ray does not hit RPP,
82 * !0 if ray hits RPP.
83 *
84 * Implicit return -
85 * rp->r_min = dist from start of ray to point at which ray ENTERS solid
86 * rp->r_max = dist from start of ray to point at which ray LEAVES solid
87 */
88RT_EXPORT extern int rt_in_rpp(struct xray *rp,
89 const fastf_t *invdir,
90 const fastf_t *min,
91 const fastf_t *max);
92
93/* Find the bounding box given a struct rt_db_internal : bbox.c */
94
95/**
96 *
97 * Calculate the bounding RPP of the internal format passed in 'ip'.
98 * The bounding RPP is returned in rpp_min and rpp_max in mm FIXME:
99 * This function needs to be modified to eliminate the rt_gettree()
100 * call and the related parameters. In that case calling code needs to
101 * call another function before calling this function That function
102 * must create a union tree with tr_a.tu_op=OP_SOLID. It can look as
103 * follows : union tree * rt_comb_tree(const struct db_i *dbip, const
104 * struct rt_db_internal *ip). The tree is set in the struct
105 * rt_db_internal * ip argument. Once a suitable tree is set in the
106 * ip, then this function can be called with the struct rt_db_internal
107 * * to return the BB properly without getting stuck during tree
108 * traversal in rt_bound_tree()
109 *
110 * Returns -
111 * 0 success
112 * -1 failure, the model bounds could not be got
113 *
114 */
115RT_EXPORT extern int rt_bound_internal(struct db_i *dbip,
116 struct directory *dp,
117 point_t rpp_min,
118 point_t rpp_max);
119
120/**
121 * Given the info defining a comb tree instance, calculate its
122 * bounding box (using ft_plot methods as a fallback.) This
123 * routine has its origins in the drawing code
124 */
125RT_EXPORT extern int
127 struct directory *dp,
128 struct db_i *dbip,
129 const struct bg_tess_tol *ttol,
130 const struct bn_tol *tol,
131 mat_t *s_mat,
132 struct resource *res
133 );
134
135/**
136 * Given an argc/argv list of objects, calculate their collective
137 * bounding box */
138RT_EXPORT extern int
140 struct db_i *dbip,
141 int argc,
142 const char *argv[],
143 int use_air,
144 point_t rpp_min,
145 point_t rpp_max);
146
147/**
148 *
149 * Given a region, return a matrix which maps model coordinates into
150 * region "shader space". This is a space where points in the model
151 * within the bounding box of the region are mapped into "region"
152 * space (the coordinate system in which the region is defined). The
153 * area occupied by the region's bounding box (in region coordinates)
154 * are then mapped into the unit cube. This unit cube defines "shader
155 * space".
156 *
157 * Returns:
158 * 0 OK
159 * <0 Failure
160 */
161RT_EXPORT extern int rt_shader_mat(mat_t model_to_shader, /* result */
162 const struct rt_i *rtip,
163 const struct region *rp,
164 point_t p_min, /* input/output: shader/region min point */
165 point_t p_max, /* input/output: shader/region max point */
166 struct resource *resp);
167
168/* mirror.c */
169RT_EXPORT extern struct rt_db_internal *rt_mirror(struct db_i *dpip,
170 struct rt_db_internal *ip,
171 point_t mirror_pt,
172 vect_t mirror_dir,
173 struct resource *resp);
174
175
176RT_EXPORT extern void rt_plot_all_bboxes(FILE *fp,
177 struct rt_i *rtip);
178RT_EXPORT extern void rt_plot_all_solids(FILE *fp,
179 struct rt_i *rtip,
180 struct resource *resp);
181
182
183/* pr.c */
184/* TODO - do these belong in libbn? */
185RT_EXPORT extern void rt_pr_fallback_angle(struct bu_vls *str,
186 const char *prefix,
187 const double angles[5]);
188RT_EXPORT extern void rt_find_fallback_angle(double angles[5],
189 const vect_t vec);
190RT_EXPORT extern void rt_pr_tol(const struct bn_tol *tol);
191
192
193/**
194 * Find the roots of a polynomial
195 *
196 * TODO - should this be moved to libbn?
197 *
198 * WARNING: The polynomial given as input is destroyed by this
199 * routine. The caller must save it if it is important!
200 *
201 * NOTE : This routine is written for polynomials with real
202 * coefficients ONLY. To use with complex coefficients, the Complex
203 * Math library should be used throughout. Some changes in the
204 * algorithm will also be required.
205 */
206RT_EXPORT extern int rt_poly_roots(bn_poly_t *eqn,
207 bn_complex_t roots[],
208 const char *name);
209
210/** @} */
211
212
213
214__END_DECLS
215
216#endif /* RT_CALC_H */
217
218/*
219 * Local Variables:
220 * tab-width: 8
221 * mode: C
222 * indent-tabs-mode: t
223 * c-file-style: "stroustrup"
224 * End:
225 * ex: shiftwidth=4 tabstop=8
226 */
Header file for the BRL-CAD common definitions.
void int char int int double * min
Definition: tig.h:182
void float * input
Definition: tig.h:163
void rt_pr_fallback_angle(struct bu_vls *str, const char *prefix, const double angles[5])
int rt_shader_mat(mat_t model_to_shader, const struct rt_i *rtip, const struct region *rp, point_t p_min, point_t p_max, struct resource *resp)
int rt_poly_roots(bn_poly_t *eqn, bn_complex_t roots[], const char *name)
int rt_rpp_region(struct rt_i *rtip, const char *reg_name, fastf_t *min_rpp, fastf_t *max_rpp)
struct rt_db_internal * rt_mirror(struct db_i *dpip, struct rt_db_internal *ip, point_t mirror_pt, vect_t mirror_dir, struct resource *resp)
void rt_pr_tol(const struct bn_tol *tol)
void rt_plot_all_bboxes(FILE *fp, struct rt_i *rtip)
int rt_matrix_transform(struct rt_db_internal *output, const mat_t matrix, struct rt_db_internal *input, int free_input, struct db_i *dbip, struct resource *resource)
int rt_bound_internal(struct db_i *dbip, struct directory *dp, point_t rpp_min, point_t rpp_max)
void rt_plot_all_solids(FILE *fp, struct rt_i *rtip, struct resource *resp)
int rt_in_rpp(struct xray *rp, const fastf_t *invdir, const fastf_t *min, const fastf_t *max)
int rt_bound_instance(point_t *bmin, point_t *bmax, struct directory *dp, struct db_i *dbip, const struct bg_tess_tol *ttol, const struct bn_tol *tol, mat_t *s_mat, struct resource *res)
int rt_obj_bounds(struct bu_vls *msgs, struct db_i *dbip, int argc, const char *argv[], int use_air, point_t rpp_min, point_t rpp_max)
void rt_find_fallback_angle(double angles[5], const vect_t vec)
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: poly.h:50
Definition: tol.h:72
Definition: vls.h:53
Definition: region.h:44
Primary ray data structure.
Definition: xray.h:41
fundamental vector, matrix, quaternion math macros