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 "bn/tol.h"
31#include "dm/defines.h"
32#include "bv/defines.h"
33
35
36/* Set default values for a bv. */
37BV_EXPORT extern void bv_init(struct bview *v, struct bview_set *s);
38BV_EXPORT extern void bv_free(struct bview *v);
39
40/**
41 * FIXME: this routine is suspect and needs investigating. if run
42 * during view initialization, the shaders regression test fails.
43 */
44BV_EXPORT void bv_mat_aet(struct bview *v);
46BV_EXPORT extern void bv_settings_init(struct bview_settings *s);
48/* To use default scaling (0.5 model scale == 2.0 view factor) use
49 * this as an argument to bv_autoview's scale parameter */
50#define BV_AUTOVIEW_SCALE_DEFAULT -1
51/**
52 * Automatically set up the view to make the scene objects visible
53 */
54BV_EXPORT extern void bv_autoview(struct bview *v, fastf_t scale, int all_view_objs);
56/* Copy the size and camera info (deliberately not a full copy of all view state) */
57BV_EXPORT extern void bv_sync(struct bview *dest, struct bview *src);
59/* Copy settings (potentially) common to the view and scene objects.
60 * Return 0 if no changes were made to dest. If dest did have one
61 * or more settings updated from src, return 1. */
64/* Sync values within the bv, perform callbacks if any are defined */
65BV_EXPORT extern void bv_update(struct bview *gvp);
67/* Update objects in the selection set (if any) and their children */
68BV_EXPORT extern int bv_update_selected(struct bview *gvp);
70/* Clear or reset the knob states. Specify a category to indicate which
71 * variables should be reset:
72 *
73 * BV_KNOBS_ALL resets both rate and absolute values
74 * BV_KNOBS_RATE resets rate only
75 * BV_KNOBS_ABS resets absolute only
76 */
77#define BV_KNOBS_ALL 0
78#define BV_KNOBS_RATE 1
79#define BV_KNOBS_ABS 2
80BV_EXPORT extern void bv_knobs_reset(struct bview_knobs *k, int category);
82/**
83 * @brief
84 * Process an individual libbv knob command.
85 *
86 * Note that the reason rvec, do_rot, tvec and do_tran are set, rather than an
87 * immediate view update being performed, is to allow parent applications to
88 * process multiple commands before finally triggering the bv_knobs_rot or
89 * bv_knobs_tran functions to implement the accumulated instructions.
90 *
91 * @param[out] rvec Pointer to rotation vector
92 * @param[out] do_rot Pointer to flag indicating whether the command implies a rotation op is needed
93 * @param[out] tvec Pointer to translation vector
94 * @param[out] do_tran Pointer to flag indicating whether the command implies a translation op is needed
95 *
96 * @param[in] v bview structure
97 * @param[in] cmd command string - valid entries are x, y, z, X, Y Z, ax, ay, az, aX, aY, aZ, S, aS
98 * @param[in] f numerical parameter to cmd (i.e. aX 0.1 - required for all commands)
99 * @param[in] origin char indicating origin - may be 'e' (eye_pt), 'm' (model origin) or 'v' (view origin - default)
100 * @param[in] model_flag Manipulate view using model coordinates rather than view coordinates
101 * @param[in] incr_flag Treat f parameter as an incremental change rather than an absolute setting
102 *
103 * @return
104 * Returns BRLCAD_OK if command was successfully processed, BRLCAD_ERROR otherwise.
105 * */
108 struct bview *v, const char *cmd, fastf_t f,
109 char origin, int model_flag, int incr_flag
110 );
111
112/* @brief
113 * Process a knob rotation vector.
114 *
115 * @param[in] v bview structure
116 * @param[in] rvec Pointer to rotation vector
117 * @param[in] origin char indicating origin - may be 'e' (eye_pt), 'm' (model origin) or 'v' (view origin - default)
118 * @param[in] model_flag Manipulate view using model coordinates rather than view coordinates
119 */
120BV_EXPORT extern void
121bv_knobs_rot(struct bview *v,
123 char origin,
124 int model_flag);
125
126
127/* @brief
128 * Process a knob translation vector.
129 *
130 * @param[in] v bview structure
131 * @param[in] tvec Pointer to translation vector
132 * @param[in] model_flag Manipulate view using model coordinates rather than view coordinates
133 */
134BV_EXPORT extern void
135bv_knobs_tran(struct bview *v,
137 int model_flag);
138
139
140/* Update the bview struct's knob rate flags based on the vector values. */
141BV_EXPORT extern void
142bv_update_rate_flags(struct bview *v);
144
145/* Return 1 if the visible contents differ
146 * Return 2 if visible content is the same but settings differ
147 * Return 3 if content is the same but user data, dmp or callbacks differ
148 * Return -1 if one or more of the views is NULL
149 * Else return 0 */
150BV_EXPORT extern int bv_differ(struct bview *v1, struct bview *v2);
152/* Return a hash of the contents of the bv container. Returns 0 on failure. */
153BV_EXPORT extern unsigned long long bv_hash(struct bview *v);
155/* Return a hash of the contents of a display list. Returns 0 on failure. */
156BV_EXPORT extern unsigned long long bv_dl_hash(struct display_list *dl);
158/* Returns number of objects defined in any object container
159 * known to this view (0 if completely cleared). */
160BV_EXPORT extern size_t bv_clear(struct bview *v, int flags);
162/* Note that some of these are mutually exclusive as far as producing any
163 * changes - a simultaneous constraint in X and Y, for example, results in a
164 * no-op. */
165#define BV_IDLE 0x000
166#define BV_ROT 0x001
167#define BV_TRANS 0x002
168#define BV_SCALE 0x004
169#define BV_CENTER 0x008
170#define BV_CON_X 0x010
171#define BV_CON_Y 0x020
172#define BV_CON_Z 0x040
173#define BV_CON_GRID 0x080
174#define BV_CON_LINES 0x100
176/* Update a view in response to X,Y coordinate changes as generated
177 * by a graphical interface's mouse motion. */
178BV_EXPORT extern int bv_adjust(struct bview *v, int dx, int dy, point_t keypoint, int mode, unsigned long long flags);
180/* Beginning extraction of the core of libtclcad view object manipulation
181 * logic. The following functions will initially be pretty straightforward
182 * mappings from libtclcad, and will likely evolve over time.
183 */
184
185/* Return -1 if width and/or height are unset (and hence a meaningful
186 * calculation is impossible), else 0. */
189/* Return -1 if width and/or height are unset (and hence a meaningful
190 * calculation is impossible), else 0.
191 *
192 * x and y will normally be integers, but the types are float to allow for
193 * the possibility of sub-pixel coordinate specifications.
194 */
195BV_EXPORT extern int bv_screen_pt(point_t *p, fastf_t x, fastf_t y, struct bview *v);
197
198
199/* Compute the min, max, and center points of the scene object.
200 * Return 1 if a bound was computed, else 0 */
201BV_EXPORT extern int bv_scene_obj_bound(struct bv_scene_obj *s, struct bview *v);
203/* Find the nearest (mode == 0) or farthest (mode == 1) data_vZ value from
204 * the vlist points in s in the context of view v */
205BV_EXPORT extern fastf_t bv_vZ_calc(struct bv_scene_obj *s, struct bview *v, int mode);
207/* Copy object attributes (but not geometry) from src to dest */
208BV_EXPORT extern void bv_obj_sync(struct bv_scene_obj *dest, struct bv_scene_obj *src);
210/* Mark object and any child objects as stale for the drawing routines */
211/* There are a few options for this situation - this one, which requires the client code
212 * to explicitly notify the drawing routines they need to do work, an internal options
213 * hash stored in the bv_scene_obj itself which is checked at render time, and setter
214 * wrapper functions that do the bookkeeping for the caller (in lieu of directly setting
215 * values in the bv_scene_obj struct.) The first one isn't ideal because the visual will
216 * be wrong if the caller doesn't supply the notification, the second has unknown
217 * performance implications, and the third would be a major rework of how the bv_scene_obj
218 * data is accessed (effectively, making the internal storage of bv_scene_obj fully hidden
219 * a.l.a the libdm rework.) Not sure what the best option is yet... leaning towards #2
220 * if it is "fast enough"... */
221BV_EXPORT void bv_obj_stale(struct bv_scene_obj *s);
223/* Given a view, create an object of the specified type. Like bv_obj_get, except it
224 * leaves the addition of objects to the client. Lower level. */
225BV_EXPORT struct bv_scene_obj *
226bv_obj_create(struct bview *v, int type);
228/* Given a view, create an object of the specified type and add it to the
229 * appropriate container. Issues such as memory management as a function of
230 * view settings are handled internally, so client codes don't need to manage
231 * it. */
232BV_EXPORT struct bv_scene_obj *
233bv_obj_get(struct bview *v, int type);
235/* Given an object, create an object that is a child of that object. Issues
236 * such as memory management as a function of view settings are handled
237 * internally, so client codes don't need to manage it. */
238BV_EXPORT struct bv_scene_obj *
241/* Clear the contents of an object (including releasing its children), but keep
242 * it active in the view. Generally used when redrawing an object */
243BV_EXPORT void
244bv_obj_reset(struct bv_scene_obj *s);
246/* Release an object to the internal pools. */
247BV_EXPORT void
248bv_obj_put(struct bv_scene_obj *o);
250/* Given a scene object and a name vname, glob match child names and uuids to
251 * attempt to locate a child of s that matches vname */
252BV_EXPORT struct bv_scene_obj *
253bv_find_child(struct bv_scene_obj *s, const char *vname);
255/* Given a view and a name vname, glob match names and uuids to attempt to
256 * locate a scene object in v that matches vname.
257 *
258 * NOTE - currently this is searching the top level objects, but does not walk
259 * down into their children. May want to support that in the future... */
260BV_EXPORT struct bv_scene_obj *
261bv_find_obj(struct bview *v, const char *vname);
263/* Given a seed name, generate a name that does not collide with any existing
264 * object names in the top level. If the seed name does not collide, it is
265 * returned as the result - otherwise, a name based on the seed name will be
266 * generated.
267 */
268BV_EXPORT void
269bv_uniq_obj_name(struct bu_vls *oname, const char *seed, struct bview *v);
271/* For the specified object/view pairing, return the appropriate scene object
272 * to use with that view. Usually this will return s, but if a Level of Detail
273 * scheme or some other view-aware rendering of the object is active, that object
274 * will be returned instead. */
275BV_EXPORT struct bv_scene_obj *
276bv_obj_for_view(struct bv_scene_obj *s, struct bview *v);
278/* Get a view-specific object vobj for view v on object s. */
279BV_EXPORT struct bv_scene_obj *
280bv_obj_get_vo(struct bv_scene_obj *s, struct bview *v);
282/* Check for the presence of view-specific objects */
283BV_EXPORT int
284bv_obj_have_vo(struct bv_scene_obj *s, struct bview *v);
286/* Clear view-specific objects */
287BV_EXPORT int
288bv_clear_view_obj(struct bv_scene_obj *s, struct bview *v);
290/* Set the illumination state on the object and its children to ill_state.
291 * Returns 0 if no states were changed, and 1 if one or more states were
292 * updated. */
293BV_EXPORT int
294bv_illum_obj(struct bv_scene_obj *s, char ill_state);
296/* For the given view, return a pointer to the bu_ptbl holding active scene
297 * objects with the specified type. Note that view-specific db objects are not
298 * part of these sets - they should be retrieved from the scene objects in this
299 * set with bv_obj_for_view. */
300BV_EXPORT struct bu_ptbl *
301bv_view_objs(struct bview *v, int type);
303/* Given a view, construct the view plane */
304BV_EXPORT int
305bv_view_plane(plane_t *p, struct bview *v);
307
308/* Environment variable controlled logging.
309 *
310 * Set BV_LOG to numerical levels to get increasingly
311 * verbose reporting of drawing info */
312#define BV_ENABLE_ENV_LOGGING 1
314bv_log(int level, const char *fmt, ...) _BU_ATTR_PRINTF23;
316
317/* Debugging function for printing contents of views */
318BV_EXPORT void
319bv_view_print(const char *title, struct bview *v, int verbosity);
322
323/** @} */
324
325#endif /* BV_UTIL_H */
326
327/*
328 * Local Variables:
329 * mode: C
330 * tab-width: 8
331 * indent-tabs-mode: t
332 * c-file-style: "stroustrup"
333 * End:
334 * ex: shiftwidth=4 tabstop=8
335 */
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, vect_t *tvec, int model_flag)
void bv_knobs_rot(struct bview *v, vect_t *rvec, char origin, 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)
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_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 point_t[ELEMENTS_PER_POINT]
3-tuple point
Definition vmath.h:355
Definition ptbl.h:53
Definition vls.h:53