BRL-CAD
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-2024 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 
34 __BEGIN_DECLS
35 
36 /* Set default values for a bv. */
37 BV_EXPORT extern void bv_init(struct bview *v, struct bview_set *s);
38 BV_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  */
44 BV_EXPORT void bv_mat_aet(struct bview *v);
45 
46 BV_EXPORT extern void bv_settings_init(struct bview_settings *s);
47 
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  */
54 BV_EXPORT extern void bv_autoview(struct bview *v, fastf_t scale, int all_view_objs);
55 
56 /* Copy the size and camera info (deliberately not a full copy of all view state) */
57 BV_EXPORT extern void bv_sync(struct bview *dest, struct bview *src);
58 
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. */
62 BV_EXPORT extern int bv_obj_settings_sync(struct bv_obj_settings *dest, struct bv_obj_settings *src);
63 
64 /* Sync values within the bv, perform callbacks if any are defined */
65 BV_EXPORT extern void bv_update(struct bview *gvp);
66 
67 /* Update objects in the selection set (if any) and their children */
68 BV_EXPORT extern int bv_update_selected(struct bview *gvp);
69 
70 /* Return 1 if the visible contents differ
71  * Return 2 if visible content is the same but settings differ
72  * Return 3 if content is the same but user data, dmp or callbacks differ
73  * Return -1 if one or more of the views is NULL
74  * Else return 0 */
75 BV_EXPORT extern int bv_differ(struct bview *v1, struct bview *v2);
76 
77 /* Return a hash of the contents of the bv container. Returns 0 on failure. */
78 BV_EXPORT extern unsigned long long bv_hash(struct bview *v);
79 
80 /* Return a hash of the contents of a display list. Returns 0 on failure. */
81 BV_EXPORT extern unsigned long long bv_dl_hash(struct display_list *dl);
82 
83 /* Returns number of objects defined in any object container
84  * known to this view (0 if completely cleared). */
85 BV_EXPORT extern size_t bv_clear(struct bview *v, int flags);
86 
87 /* Note that some of these are mutually exclusive as far as producing any
88  * changes - a simultaneous constraint in X and Y, for example, results in a
89  * no-op. */
90 #define BV_IDLE 0x000
91 #define BV_ROT 0x001
92 #define BV_TRANS 0x002
93 #define BV_SCALE 0x004
94 #define BV_CENTER 0x008
95 #define BV_CON_X 0x010
96 #define BV_CON_Y 0x020
97 #define BV_CON_Z 0x040
98 #define BV_CON_GRID 0x080
99 #define BV_CON_LINES 0x100
100 
101 /* Update a view in response to X,Y coordinate changes as generated
102  * by a graphical interface's mouse motion. */
103 BV_EXPORT extern int bv_adjust(struct bview *v, int dx, int dy, point_t keypoint, int mode, unsigned long long flags);
104 
105 /* Beginning extraction of the core of libtclcad view object manipulation
106  * logic. The following functions will initially be pretty straightforward
107  * mappings from libtclcad, and will likely evolve over time.
108  */
109 
110 /* Return -1 if width and/or height are unset (and hence a meaningful
111  * calculation is impossible), else 0. */
112 BV_EXPORT extern int bv_screen_to_view(struct bview *v, fastf_t *fx, fastf_t *fy, fastf_t x, fastf_t y);
113 
114 /* Return -1 if width and/or height are unset (and hence a meaningful
115  * calculation is impossible), else 0.
116  *
117  * x and y will normally be integers, but the types are float to allow for
118  * the possibility of sub-pixel coordinate specifications.
119  */
120 BV_EXPORT extern int bv_screen_pt(point_t *p, fastf_t x, fastf_t y, struct bview *v);
121 
122 
123 
124 /* Compute the min, max, and center points of the scene object.
125  * Return 1 if a bound was computed, else 0 */
126 BV_EXPORT extern int bv_scene_obj_bound(struct bv_scene_obj *s, struct bview *v);
127 
128 /* Find the nearest (mode == 0) or farthest (mode == 1) data_vZ value from
129  * the vlist points in s in the context of view v */
130 BV_EXPORT extern fastf_t bv_vZ_calc(struct bv_scene_obj *s, struct bview *v, int mode);
131 
132 /* Copy object attributes (but not geometry) from src to dest */
133 BV_EXPORT extern void bv_obj_sync(struct bv_scene_obj *dest, struct bv_scene_obj *src);
134 
135 /* Mark object and any child objects as stale for the drawing routines */
136 /* There are a few options for this situation - this one, which requires the client code
137  * to explicitly notify the drawing routines they need to do work, an internal options
138  * hash stored in the bv_scene_obj itself which is checked at render time, and setter
139  * wrapper functions that do the bookkeeping for the caller (in lieu of directly setting
140  * values in the bv_scene_obj struct.) The first one isn't ideal because the visual will
141  * be wrong if the caller doesn't supply the notification, the second has unknown
142  * performance implications, and the third would be a major rework of how the bv_scene_obj
143  * data is accessed (effectively, making the internal storage of bv_scene_obj fully hidden
144  * a.l.a the libdm rework.) Not sure what the best option is yet... leaning towards #2
145  * if it is "fast enough"... */
146 BV_EXPORT void bv_obj_stale(struct bv_scene_obj *s);
147 
148 /* Given a view, create an object of the specified type. Like bv_obj_get, except it
149  * leaves the addition of objects to the client. Lower level. */
150 BV_EXPORT struct bv_scene_obj *
151 bv_obj_create(struct bview *v, int type);
152 
153 /* Given a view, create an object of the specified type and add it to the
154  * appropriate container. Issues such as memory management as a function of
155  * view settings are handled internally, so client codes don't need to manage
156  * it. */
157 BV_EXPORT struct bv_scene_obj *
158 bv_obj_get(struct bview *v, int type);
159 
160 /* Given an object, create an object that is a child of that object. Issues
161  * such as memory management as a function of view settings are handled
162  * internally, so client codes don't need to manage it. */
163 BV_EXPORT struct bv_scene_obj *
164 bv_obj_get_child(struct bv_scene_obj *s);
165 
166 /* Clear the contents of an object (including releasing its children), but keep
167  * it active in the view. Generally used when redrawing an object */
168 BV_EXPORT void
169 bv_obj_reset(struct bv_scene_obj *s);
170 
171 /* Release an object to the internal pools. */
172 BV_EXPORT void
173 bv_obj_put(struct bv_scene_obj *o);
174 
175 /* Given a scene object and a name vname, glob match child names and uuids to
176  * attempt to locate a child of s that matches vname */
177 BV_EXPORT struct bv_scene_obj *
178 bv_find_child(struct bv_scene_obj *s, const char *vname);
179 
180 /* Given a view and a name vname, glob match names and uuids to attempt to
181  * locate a scene object in v that matches vname.
182  *
183  * NOTE - currently this is searching the top level objects, but does not walk
184  * down into their children. May want to support that in the future... */
185 BV_EXPORT struct bv_scene_obj *
186 bv_find_obj(struct bview *v, const char *vname);
187 
188 /* Given a seed name, generate a name that does not collide with any existing
189  * object names in the top level. If the seed name does not collide, it is
190  * returned as the result - otherwise, a name based on the seed name will be
191  * generated.
192  */
193 BV_EXPORT void
194 bv_uniq_obj_name(struct bu_vls *oname, const char *seed, struct bview *v);
195 
196 /* For the specified object/view pairing, return the appropriate scene object
197  * to use with that view. Usually this will return s, but if a Level of Detail
198  * scheme or some other view-aware rendering of the object is active, that object
199  * will be returned instead. */
200 BV_EXPORT struct bv_scene_obj *
201 bv_obj_for_view(struct bv_scene_obj *s, struct bview *v);
202 
203 /* Get a view-specific object vobj for view v on object s. */
204 BV_EXPORT struct bv_scene_obj *
205 bv_obj_get_vo(struct bv_scene_obj *s, struct bview *v);
206 
207 /* Check for the presence of view-specific objects */
208 BV_EXPORT int
209 bv_obj_have_vo(struct bv_scene_obj *s, struct bview *v);
210 
211 /* Clear view-specific objects */
212 BV_EXPORT int
213 bv_clear_view_obj(struct bv_scene_obj *s, struct bview *v);
214 
215 /* Set the illumination state on the object and its children to ill_state.
216  * Returns 0 if no states were changed, and 1 if one or more states were
217  * updated. */
218 BV_EXPORT int
219 bv_illum_obj(struct bv_scene_obj *s, char ill_state);
220 
221 /* For the given view, return a pointer to the bu_ptbl holding active scene
222  * objects with the specified type. Note that view-specific db objects are not
223  * part of these sets - they should be retrieved from the scene objects in this
224  * set with bv_obj_for_view. */
225 BV_EXPORT struct bu_ptbl *
226 bv_view_objs(struct bview *v, int type);
227 
228 /* Given a view, construct the view plane */
229 BV_EXPORT int
230 bv_view_plane(plane_t *p, struct bview *v);
231 
232 
233 /* Environment variable controlled logging.
234  *
235  * Set BV_LOG to numerical levels to get increasingly
236  * verbose reporting of drawing info */
237 #define BV_ENABLE_ENV_LOGGING 1
238 BV_EXPORT void
239 bv_log(int level, const char *fmt, ...) _BU_ATTR_PRINTF23;
240 
241 
242 /* Debugging function for printing contents of views */
243 BV_EXPORT void
244 bv_view_print(const char *title, struct bview *v, int verbosity);
245 
246 __END_DECLS
247 
248 /** @} */
249 
250 #endif /* BV_UTIL_H */
251 
252 /*
253  * Local Variables:
254  * mode: C
255  * tab-width: 8
256  * indent-tabs-mode: t
257  * c-file-style: "stroustrup"
258  * End:
259  * ex: shiftwidth=4 tabstop=8
260  */
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)
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)
void bv_obj_sync(struct bv_scene_obj *dest, struct bv_scene_obj *src)
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)
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)
struct bv_scene_obj * bv_find_child(struct bv_scene_obj *s, const char *vname)
void bv_obj_put(struct bv_scene_obj *o)
int bv_clear_view_obj(struct bv_scene_obj *s, struct bview *v)
struct bv_scene_obj * bv_obj_get(struct bview *v, int type)
int bv_differ(struct bview *v1, struct bview *v2)
struct bv_scene_obj * bv_obj_get_child(struct bv_scene_obj *s)
struct bu_ptbl * bv_view_objs(struct bview *v, int type)
struct bv_scene_obj * bv_obj_get_vo(struct bv_scene_obj *s, struct bview *v)
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_for_view(struct bv_scene_obj *s, struct bview *v)
void bv_obj_reset(struct bv_scene_obj *s)
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)
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)
struct bv_scene_obj * bv_find_obj(struct bview *v, const char *vname)
void bv_mat_aet(struct bview *v)
unsigned long long bv_dl_hash(struct display_list *dl)
void bv_update(struct bview *gvp)
struct bv_scene_obj * bv_obj_create(struct bview *v, int type)
void bv_view_print(const char *title, struct bview *v, int verbosity)
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
Definition: defines.h:489