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 * NOTE: this computes a LOOSE axis-aligned RPP. Subtracted (OP_SUBTRACT /
113 * negative) members are recursed into but their RPP is discarded, so the
114 * returned box IGNORES carved-away material and never shrinks to reflect it.
115 * For a bound that accounts for subtractions, evaluate the geometry (e.g. the
116 * ray-traced evaluated-geometry path exposed by the "bb -t" command).
117 *
118 * Returns -
119 * 0 success
120 * -1 failure, the model bounds could not be got
121 *
122 */
123RT_EXPORT extern int rt_bound_internal(struct db_i *dbip,
124 struct directory *dp,
127
128/**
129 * Given the info defining a comb tree instance, calculate its
130 * bounding box (using ft_plot methods as a fallback.) This
131 * routine has its origins in the drawing code
132 */
133RT_EXPORT extern int
135 struct directory *dp,
136 struct db_i *dbip,
137 const struct bg_tess_tol *ttol,
138 const struct bn_tol *tol,
139 mat_t *s_mat
140 );
141
142/**
143 * Given an argc/argv list of objects, calculate their collective
144 * bounding box.
145 *
146 * NOTE: this returns a LOOSE axis-aligned RPP (it is built on rt_bound_tree()).
147 * Subtracted (OP_SUBTRACT / negative) members do NOT tighten the result -- the
148 * box reflects only the positive/union geometry and never shrinks to account
149 * for carved-away material. Callers needing a subtraction-aware bound must
150 * evaluate the geometry (e.g. via the "bb -t" command, which bounds the
151 * ray-traced boolean-evaluated geometry). */
152RT_EXPORT extern int
153rt_obj_bounds(struct bu_vls *msgs,
154 struct db_i *dbip,
155 int argc,
156 const char *argv[],
157 int use_air,
160
161/**
162 *
163 * Given a region, return a matrix which maps model coordinates into
164 * region "shader space". This is a space where points in the model
165 * within the bounding box of the region are mapped into "region"
166 * space (the coordinate system in which the region is defined). The
167 * area occupied by the region's bounding box (in region coordinates)
168 * are then mapped into the unit cube. This unit cube defines "shader
169 * space".
170 *
171 * Returns:
172 * 0 OK
173 * <0 Failure
174 */
175RT_EXPORT extern int rt_shader_mat(mat_t model_to_shader, /* result */
176 const struct rt_i *rtip,
177 const struct region *rp,
178 point_t p_min, /* input/output: shader/region min point */
179 point_t p_max); /* input/output: shader/region max point */
180
181/* mirror.c */
182RT_EXPORT extern struct rt_db_internal *rt_mirror(struct db_i *dpip,
186
187
188RT_EXPORT extern void rt_plot_all_bboxes(FILE *fp,
189 struct rt_i *rtip);
190RT_EXPORT extern void rt_plot_all_solids(FILE *fp, struct rt_i *rtip);
192
193/* pr.c */
194/* TODO - do these belong in libbn? */
195RT_EXPORT extern void rt_pr_fallback_angle(struct bu_vls *str,
196 const char *prefix,
197 const double angles[5]);
198RT_EXPORT extern void rt_find_fallback_angle(double angles[5],
199 const vect_t vec);
200RT_EXPORT extern void rt_pr_tol(const struct bn_tol *tol);
201
203/**
204 * Find the roots of a polynomial
205 *
206 * TODO - should this be moved to libbn?
207 *
208 * WARNING: The polynomial given as input is destroyed by this
209 * routine. The caller must save it if it is important!
210 *
211 * NOTE : This routine is written for polynomials with real
212 * coefficients ONLY. To use with complex coefficients, the Complex
213 * Math library should be used throughout. Some changes in the
214 * algorithm will also be required.
215 */
216RT_EXPORT extern int rt_poly_roots(bn_poly_t *eqn,
218 const char *name);
220/** @} */
221
222
223
225
226#endif /* RT_CALC_H */
227
228/*
229 * Local Variables:
230 * tab-width: 8
231 * mode: C
232 * indent-tabs-mode: t
233 * c-file-style: "stroustrup"
234 * End:
235 * ex: shiftwidth=4 tabstop=8
236 */
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:351
double fastf_t
fastest 64-bit (or larger) floating point type
Definition vmath.h:336
fastf_t mat_t[ELEMENTS_PER_MAT]
4x4 matrix
Definition vmath.h:372
fastf_t point_t[ELEMENTS_PER_POINT]
3-tuple point
Definition vmath.h:357
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