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-2022 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 *
122 * Given a region, return a matrix which maps model coordinates into
123 * region "shader space". This is a space where points in the model
124 * within the bounding box of the region are mapped into "region"
125 * space (the coordinate system in which the region is defined). The
126 * area occupied by the region's bounding box (in region coordinates)
127 * are then mapped into the unit cube. This unit cube defines "shader
128 * space".
129 *
130 * Returns:
131 * 0 OK
132 * <0 Failure
133 */
134RT_EXPORT extern int rt_shader_mat(mat_t model_to_shader, /* result */
135 const struct rt_i *rtip,
136 const struct region *rp,
137 point_t p_min, /* input/output: shader/region min point */
138 point_t p_max, /* input/output: shader/region max point */
139 struct resource *resp);
140
141/* mirror.c */
142RT_EXPORT extern struct rt_db_internal *rt_mirror(struct db_i *dpip,
143 struct rt_db_internal *ip,
144 point_t mirror_pt,
145 vect_t mirror_dir,
146 struct resource *resp);
147
148
149RT_EXPORT extern void rt_plot_all_bboxes(FILE *fp,
150 struct rt_i *rtip);
151RT_EXPORT extern void rt_plot_all_solids(FILE *fp,
152 struct rt_i *rtip,
153 struct resource *resp);
154
155
156/* pr.c */
157/* TODO - do these belong in libbn? */
158RT_EXPORT extern void rt_pr_fallback_angle(struct bu_vls *str,
159 const char *prefix,
160 const double angles[5]);
161RT_EXPORT extern void rt_find_fallback_angle(double angles[5],
162 const vect_t vec);
163RT_EXPORT extern void rt_pr_tol(const struct bn_tol *tol);
164
165
166/**
167 * Find the roots of a polynomial
168 *
169 * TODO - should this be moved to libbn?
170 *
171 * WARNING: The polynomial given as input is destroyed by this
172 * routine. The caller must save it if it is important!
173 *
174 * NOTE : This routine is written for polynomials with real
175 * coefficients ONLY. To use with complex coefficients, the Complex
176 * Math library should be used throughout. Some changes in the
177 * algorithm will also be required.
178 */
179RT_EXPORT extern int rt_poly_roots(bn_poly_t *eqn,
180 bn_complex_t roots[],
181 const char *name);
182
183/** @} */
184
185
186
187__END_DECLS
188
189#endif /* RT_CALC_H */
190
191/*
192 * Local Variables:
193 * tab-width: 8
194 * mode: C
195 * indent-tabs-mode: t
196 * c-file-style: "stroustrup"
197 * End:
198 * ex: shiftwidth=4 tabstop=8
199 */
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)
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