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