BRL-CAD
Loading...
Searching...
No Matches
util.h
Go to the documentation of this file.
1/* B V I E W _ U T I L . H
2 * BRL-CAD
3 *
4 * Copyright (c) 1993-2025 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 bv_util
21 *
22 */
23/** @{ */
24/** @file bv/util.h */
25
26#ifndef BV_UTIL_H
27#define BV_UTIL_H
28
29#include "common.h"
30#include "bu/hash.h"
31#include "bn/tol.h"
32#include "dm/defines.h"
33#include "bv/defines.h"
34
36
37/* Set default values for a bv. */
38BV_EXPORT extern void bv_init(struct bview *v, struct bview_set *s);
39BV_EXPORT extern void bv_free(struct bview *v);
40
41/**
42 * FIXME: this routine is suspect and needs investigating. if run
43 * during view initialization, the shaders regression test fails.
44 */
45BV_EXPORT void bv_mat_aet(struct bview *v);
47BV_EXPORT extern void bv_settings_init(struct bview_settings *s);
49/* To use default scaling (0.5 model scale == 2.0 view factor) use
50 * this as an argument to bv_autoview's scale parameter */
51#define BV_AUTOVIEW_SCALE_DEFAULT -1
52/**
53 * Automatically set up the view to make the scene objects visible
54 */
55BV_EXPORT extern void bv_autoview(struct bview *v, fastf_t scale, int all_view_objs);
57/* Copy the size and camera info (deliberately not a full copy of all view state) */
58BV_EXPORT extern void bv_sync(struct bview *dest, struct bview *src);
60/* Copy settings (potentially) common to the view and scene objects.
61 * Return 0 if no changes were made to dest. If dest did have one
62 * or more settings updated from src, return 1. */
65/* Sync values within the bv, perform callbacks if any are defined */
66BV_EXPORT extern void bv_update(struct bview *gvp);
68/* Update objects in the selection set (if any) and their children */
69BV_EXPORT extern int bv_update_selected(struct bview *gvp);
71/* Clear or reset the knob states. Specify a category to indicate which
72 * variables should be reset:
73 *
74 * BV_KNOBS_ALL resets both rate and absolute values
75 * BV_KNOBS_RATE resets rate only
76 * BV_KNOBS_ABS resets absolute only
77 */
78#define BV_KNOBS_ALL 0
79#define BV_KNOBS_RATE 1
80#define BV_KNOBS_ABS 2
81BV_EXPORT extern void bv_knobs_reset(struct bview_knobs *k, int category);
83/* Hash the semantic (non-pointer) contents of a bview_knobs struct. This
84 * intentionally excludes any *_udata pointers to avoid pointer address noise
85 * and skips any padding that would be present if hashing the raw struct.
86 *
87 * If 'state' is non-NULL the supplied hash state is updated in-place and the
88 * function returns 0 (the caller is expected to finalize the hash later.)
89 * If 'state' is NULL an internal hash state is created, populated and
90 * finalized and the resulting hash value is returned.
91 *
92 * Returns:
93 * 0 if k is NULL or state supplied (non-owning mode)
94 * hash if state is NULL (owning mode)
95 */
96BV_EXPORT extern unsigned long long
97bv_knobs_hash(struct bview_knobs *k, struct bu_data_hash_state *state);
99/**
100 * @brief
101 * Process an individual libbv knob command.
102 *
103 * Note that the reason rvec, do_rot, tvec and do_tran are set, rather than an
104 * immediate view update being performed, is to allow parent applications to
105 * process multiple commands before finally triggering the bv_knobs_rot or
106 * bv_knobs_tran functions to implement the accumulated instructions.
107 *
108 * @param[out] rvec Pointer to rotation vector
109 * @param[out] do_rot Pointer to flag indicating whether the command implies a rotation op is needed
110 * @param[out] tvec Pointer to translation vector
111 * @param[out] do_tran Pointer to flag indicating whether the command implies a translation op is needed
112 *
113 * @param[in] v bview structure
114 * @param[in] cmd command string - valid entries are x, y, z, X, Y Z, ax, ay, az, aX, aY, aZ, S, aS
115 * @param[in] f numerical parameter to cmd (i.e. aX 0.1 - required for all commands)
116 * @param[in] origin char indicating origin - may be 'e' (eye_pt), 'm' (model origin) or 'v' (view origin - default)
117 * @param[in] model_flag Manipulate view using model coordinates rather than view coordinates
118 * @param[in] incr_flag Treat f parameter as an incremental change rather than an absolute setting
119 *
120 * @return
121 * Returns BRLCAD_OK if command was successfully processed, BRLCAD_ERROR otherwise.
122 * */
125 struct bview *v, const char *cmd, fastf_t f,
126 char origin, int model_flag, int incr_flag
127 );
128
129/**
130 * @brief
131 * Rotate the view based on an Euler angle triplet (degrees) specified
132 * in one of several coordinate frames, about one of several origins.
133 *
134 * coords: Rotation input frame
135 * 'v' - rvec in view coordinates
136 * 'm' - rvec in model coordinates (converted via Rv * Rm * Rv^{-1})
137 * 'o' - rvec in object coordinates (use obj_rot to map object->model->view,
138 * fallback to 'v' semantics if obj_rot is NULL)
139 *
140 * origin: Rotation pivot specifier
141 * 'v' : view center (0,0,0 in view space)
142 * 'm' : model origin
143 * 'e' : eye point (0,0,1 in view space)
144 * 'k' : model-space custom pivot supplied via pvt_pt
145 * Any unrecognized value falls back to 'v'.
146 *
147 * obj_rot:
148 * Accumulated object->model rotation matrix when coords=='o'. NULL otherwise.
149 *
150 * pvt_pt:
151 * Model-space pivot point when origin=='k'. Ignored otherwise.
152 * NULL == model origin.
153 *
154 * BEHAVIOR
155 * 1. rvec is converted into a pure view-space rotation matrix according
156 * to 'coords' (and obj_rot for 'o').
157 * 2. If origin != 'v', the view center (gv_center) is relocated so the
158 * specified pivot is invariant under the applied rotation.
159 * 3. gv_rotation is post-multiplied by the view rotation matrix.
160 * 4. bv_update(v) refreshes derived matrices. Absolute translation bookkeeping
161 * (tra_v_abs / tra_m_abs) is always recomputed
162 *
163 * @param[in,out] v target bview structure
164 * @param[in] rvec rotation vector (Euler angles, degrees) expressed in the coordinate frame indicated by coords.
165 * @param[in] origin char indicating origin - may be 'e' (eye_pt), 'm' (model origin), 'v' (view origin - default) or 'k' (keypoint)
166 * @param[in] coords coordinate frame - may be 'm' (model), 'o' (obj coords via obj_rot), or 'v' (view)
167 * @param[in] obj_rot pointer to accumulated object rotation matrix (may be NULL)
168 * @param[in] pvt_pt model space pivot point
169 */
170BV_EXPORT extern void
171bv_knobs_rot(struct bview *v,
173 char origin,
174 char coords,
175 const matp_t obj_rot,
176 const pointp_t pvt_pt);
177
178/* @brief
179 * Process a knob translation vector.
180 *
181 * @param[in] v bview structure
182 * @param[in] tvec Pointer to translation vector
183 * @param[in] model_flag Manipulate view using model coordinates rather than view coordinates
184 */
185BV_EXPORT extern void
186bv_knobs_tran(struct bview *v,
188 int model_flag);
189
190
191/* Update the bview struct's knob rate flags based on the vector values. */
192BV_EXPORT extern void
193bv_update_rate_flags(struct bview *v);
195
196/* Return 1 if the visible contents differ
197 * Return 2 if visible content is the same but settings differ
198 * Return 3 if content is the same but user data, dmp or callbacks differ
199 * Return -1 if one or more of the views is NULL
200 * Else return 0 */
201BV_EXPORT extern int bv_differ(struct bview *v1, struct bview *v2);
203/* Return a hash of the contents of the bv container. Returns 0 on failure. */
204BV_EXPORT extern unsigned long long bv_hash(struct bview *v);
206/* Return a hash of the contents of a display list. Returns 0 on failure. */
207BV_EXPORT extern unsigned long long bv_dl_hash(struct display_list *dl);
209/* Returns number of objects defined in any object container
210 * known to this view (0 if completely cleared). */
211BV_EXPORT extern size_t bv_clear(struct bview *v, int flags);
213/* Note that some of these are mutually exclusive as far as producing any
214 * changes - a simultaneous constraint in X and Y, for example, results in a
215 * no-op. */
216#define BV_IDLE 0x000
217#define BV_ROT 0x001
218#define BV_TRANS 0x002
219#define BV_SCALE 0x004
220#define BV_CENTER 0x008
221#define BV_CON_X 0x010
222#define BV_CON_Y 0x020
223#define BV_CON_Z 0x040
224#define BV_CON_GRID 0x080
225#define BV_CON_LINES 0x100
227/* Update a view in response to X,Y coordinate changes as generated
228 * by a graphical interface's mouse motion. */
229BV_EXPORT extern int bv_adjust(struct bview *v, int dx, int dy, point_t keypoint, int mode, unsigned long long flags);
231/* Beginning extraction of the core of libtclcad view object manipulation
232 * logic. The following functions will initially be pretty straightforward
233 * mappings from libtclcad, and will likely evolve over time.
234 */
235
236/* Return -1 if width and/or height are unset (and hence a meaningful
237 * calculation is impossible), else 0. */
240/* Return -1 if width and/or height are unset (and hence a meaningful
241 * calculation is impossible), else 0.
242 *
243 * x and y will normally be integers, but the types are float to allow for
244 * the possibility of sub-pixel coordinate specifications.
245 */
246BV_EXPORT extern int bv_screen_pt(point_t *p, fastf_t x, fastf_t y, struct bview *v);
248
249
250/* Compute the min, max, and center points of the scene object.
251 * Return 1 if a bound was computed, else 0 */
252BV_EXPORT extern int bv_scene_obj_bound(struct bv_scene_obj *s, struct bview *v);
254/* Find the nearest (mode == 0) or farthest (mode == 1) data_vZ value from
255 * the vlist points in s in the context of view v */
256BV_EXPORT extern fastf_t bv_vZ_calc(struct bv_scene_obj *s, struct bview *v, int mode);
258/* Copy object attributes (but not geometry) from src to dest */
259BV_EXPORT extern void bv_obj_sync(struct bv_scene_obj *dest, struct bv_scene_obj *src);
261/* Mark object and any child objects as stale for the drawing routines */
262/* There are a few options for this situation - this one, which requires the client code
263 * to explicitly notify the drawing routines they need to do work, an internal options
264 * hash stored in the bv_scene_obj itself which is checked at render time, and setter
265 * wrapper functions that do the bookkeeping for the caller (in lieu of directly setting
266 * values in the bv_scene_obj struct.) The first one isn't ideal because the visual will
267 * be wrong if the caller doesn't supply the notification, the second has unknown
268 * performance implications, and the third would be a major rework of how the bv_scene_obj
269 * data is accessed (effectively, making the internal storage of bv_scene_obj fully hidden
270 * a.l.a the libdm rework.) Not sure what the best option is yet... leaning towards #2
271 * if it is "fast enough"... */
272BV_EXPORT void bv_obj_stale(struct bv_scene_obj *s);
274/* Given a view, create an object of the specified type. Like bv_obj_get, except it
275 * leaves the addition of objects to the client. Lower level. */
276BV_EXPORT struct bv_scene_obj *
277bv_obj_create(struct bview *v, int type);
279/* Given a view, create an object of the specified type and add it to the
280 * appropriate container. Issues such as memory management as a function of
281 * view settings are handled internally, so client codes don't need to manage
282 * it. */
283BV_EXPORT struct bv_scene_obj *
284bv_obj_get(struct bview *v, int type);
286/* Given an object, create an object that is a child of that object. Issues
287 * such as memory management as a function of view settings are handled
288 * internally, so client codes don't need to manage it. */
289BV_EXPORT struct bv_scene_obj *
292/* Clear the contents of an object (including releasing its children), but keep
293 * it active in the view. Generally used when redrawing an object */
294BV_EXPORT void
295bv_obj_reset(struct bv_scene_obj *s);
297/* Release an object to the internal pools. */
298BV_EXPORT void
299bv_obj_put(struct bv_scene_obj *o);
301/* Given a scene object and a name vname, glob match child names and uuids to
302 * attempt to locate a child of s that matches vname */
303BV_EXPORT struct bv_scene_obj *
304bv_find_child(struct bv_scene_obj *s, const char *vname);
306/* Given a view and a name vname, glob match names and uuids to attempt to
307 * locate a scene object in v that matches vname.
308 *
309 * NOTE - currently this is searching the top level objects, but does not walk
310 * down into their children. May want to support that in the future... */
311BV_EXPORT struct bv_scene_obj *
312bv_find_obj(struct bview *v, const char *vname);
314/* Given a seed name, generate a name that does not collide with any existing
315 * object names in the top level. If the seed name does not collide, it is
316 * returned as the result - otherwise, a name based on the seed name will be
317 * generated.
318 */
319BV_EXPORT void
320bv_uniq_obj_name(struct bu_vls *oname, const char *seed, struct bview *v);
322/* For the specified object/view pairing, return the appropriate scene object
323 * to use with that view. Usually this will return s, but if a Level of Detail
324 * scheme or some other view-aware rendering of the object is active, that object
325 * will be returned instead. */
326BV_EXPORT struct bv_scene_obj *
327bv_obj_for_view(struct bv_scene_obj *s, struct bview *v);
329/* Get a view-specific object vobj for view v on object s. */
330BV_EXPORT struct bv_scene_obj *
331bv_obj_get_vo(struct bv_scene_obj *s, struct bview *v);
333/* Check for the presence of view-specific objects */
334BV_EXPORT int
335bv_obj_have_vo(struct bv_scene_obj *s, struct bview *v);
337/* Clear view-specific objects */
338BV_EXPORT int
339bv_clear_view_obj(struct bv_scene_obj *s, struct bview *v);
341/* Set the illumination state on the object and its children to ill_state.
342 * Returns 0 if no states were changed, and 1 if one or more states were
343 * updated. */
344BV_EXPORT int
345bv_illum_obj(struct bv_scene_obj *s, char ill_state);
347/* For the given view, return a pointer to the bu_ptbl holding active scene
348 * objects with the specified type. Note that view-specific db objects are not
349 * part of these sets - they should be retrieved from the scene objects in this
350 * set with bv_obj_for_view. */
351BV_EXPORT struct bu_ptbl *
352bv_view_objs(struct bview *v, int type);
354/* Given a view, construct the view plane */
355BV_EXPORT int
356bv_view_plane(plane_t *p, struct bview *v);
358
359/* Environment variable controlled logging.
360 *
361 * Set BV_LOG to numerical levels to get increasingly
362 * verbose reporting of drawing info */
363#define BV_ENABLE_ENV_LOGGING 1
365bv_log(int level, const char *fmt, ...) _BU_ATTR_PRINTF23;
367
368/* Debugging function for printing contents of views */
369BV_EXPORT void
370bv_view_print(const char *title, struct bview *v, int verbosity);
373
374/** @} */
375
376#endif /* BV_UTIL_H */
377
378/*
379 * Local Variables:
380 * mode: C
381 * tab-width: 8
382 * indent-tabs-mode: t
383 * c-file-style: "stroustrup"
384 * End:
385 * ex: shiftwidth=4 tabstop=8
386 */
Definition dvec.h:74
Header file for the BRL-CAD common definitions.
#define _BU_ATTR_PRINTF23
Definition defines.h:95
void float float * fy
Definition tig.h:283
void int float float float * scale
Definition tig.h:142
void float float * y
Definition tig.h:73
void int char * mode
Definition tig.h:179
void float * fx
Definition tig.h:282
void float * x
Definition tig.h:72
void int char int int double double * dx
Definition tig.h:183
void bv_free(struct bview *v)
unsigned long long bv_hash(struct bview *v)
int bv_update_selected(struct bview *gvp)
struct bu_ptbl * bv_view_objs(struct bview *v, int type)
void bv_update_rate_flags(struct bview *v)
void bv_autoview(struct bview *v, fastf_t scale, int all_view_objs)
fastf_t bv_vZ_calc(struct bv_scene_obj *s, struct bview *v, int mode)
int bv_knobs_cmd_process(vect_t *rvec, int *do_rot, vect_t *tvec, int *do_tran, struct bview *v, const char *cmd, fastf_t f, char origin, int model_flag, int incr_flag)
Process an individual libbv knob command.
void bv_obj_sync(struct bv_scene_obj *dest, struct bv_scene_obj *src)
struct bv_scene_obj * bv_obj_create(struct bview *v, int type)
void bv_init(struct bview *v, struct bview_set *s)
int bv_adjust(struct bview *v, int dx, int dy, point_t keypoint, int mode, unsigned long long flags)
void bv_uniq_obj_name(struct bu_vls *oname, const char *seed, struct bview *v)
struct bv_scene_obj * bv_find_child(struct bv_scene_obj *s, const char *vname)
int bv_illum_obj(struct bv_scene_obj *s, char ill_state)
int bv_scene_obj_bound(struct bv_scene_obj *s, struct bview *v)
size_t bv_clear(struct bview *v, int flags)
void bv_knobs_tran(struct bview *v, const vect_t tvec, int model_flag)
struct bv_scene_obj * bv_obj_get(struct bview *v, int type)
void bv_obj_put(struct bv_scene_obj *o)
int bv_clear_view_obj(struct bv_scene_obj *s, struct bview *v)
int bv_differ(struct bview *v1, struct bview *v2)
void bv_settings_init(struct bview_settings *s)
void bv_log(int level, const char *fmt,...) _BU_ATTR_PRINTF23
int bv_obj_settings_sync(struct bv_obj_settings *dest, struct bv_obj_settings *src)
struct bv_scene_obj * bv_obj_get_child(struct bv_scene_obj *s)
void bv_obj_reset(struct bv_scene_obj *s)
struct bv_scene_obj * bv_obj_get_vo(struct bv_scene_obj *s, struct bview *v)
int bv_screen_to_view(struct bview *v, fastf_t *fx, fastf_t *fy, fastf_t x, fastf_t y)
void bv_sync(struct bview *dest, struct bview *src)
int bv_screen_pt(point_t *p, fastf_t x, fastf_t y, struct bview *v)
unsigned long long bv_knobs_hash(struct bview_knobs *k, struct bu_data_hash_state *state)
void bv_knobs_reset(struct bview_knobs *k, int category)
int bv_view_plane(plane_t *p, struct bview *v)
int bv_obj_have_vo(struct bv_scene_obj *s, struct bview *v)
void bv_obj_stale(struct bv_scene_obj *s)
void bv_mat_aet(struct bview *v)
struct bv_scene_obj * bv_obj_for_view(struct bv_scene_obj *s, struct bview *v)
unsigned long long bv_dl_hash(struct display_list *dl)
struct bv_scene_obj * bv_find_obj(struct bview *v, const char *vname)
void bv_knobs_rot(struct bview *v, const vect_t rvec, char origin, char coords, const matp_t obj_rot, const pointp_t pvt_pt)
Rotate the view based on an Euler angle triplet (degrees) specified in one of several coordinate fram...
void bv_update(struct bview *gvp)
void bv_view_print(const char *title, struct bview *v, int verbosity)
fastf_t vect_t[ELEMENTS_PER_VECT]
3-tuple vector
Definition vmath.h:349
double fastf_t
fastest 64-bit (or larger) floating point type
Definition vmath.h:334
fastf_t plane_t[ELEMENTS_PER_PLANE]
Definition of a plane equation.
Definition vmath.h:397
fastf_t * matp_t
pointer to a 4x4 matrix
Definition vmath.h:373
fastf_t point_t[ELEMENTS_PER_POINT]
3-tuple point
Definition vmath.h:355
Definition ptbl.h:53
Definition vls.h:53