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-2023 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. */
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);
45
46BV_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 */
54BV_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) */
57BV_EXPORT extern void bv_sync(struct bview *dest, struct bview *src);
58
59/* Copy settings (potentially) common to the view and scene objects */
60BV_EXPORT extern void bv_obj_settings_sync(struct bv_obj_settings *dest, struct bv_obj_settings *src);
61
62/* Sync values within the bv, perform callbacks if any are defined */
63BV_EXPORT extern void bv_update(struct bview *gvp);
64
65/* Update objects in the selection set (if any) and their children */
66BV_EXPORT extern int bv_update_selected(struct bview *gvp);
67
68/* Return 1 if the visible contents differ
69 * Return 2 if visible content is the same but settings differ
70 * Return 3 if content is the same but user data, dmp or callbacks differ
71 * Return -1 if one or more of the views is NULL
72 * Else return 0 */
73BV_EXPORT extern int bv_differ(struct bview *v1, struct bview *v2);
74
75/* Return a hash of the contents of the bv container. Returns 0 on failure. */
76BV_EXPORT extern unsigned long long bv_hash(struct bview *v);
77
78/* Return a hash of the contents of a display list. Returns 0 on failure. */
79BV_EXPORT extern unsigned long long bv_dl_hash(struct display_list *dl);
80
81/* Returns number of objects defined in any object container
82 * known to this view (0 if completely cleared). */
83BV_EXPORT extern size_t bv_clear(struct bview *v, int flags);
84
85/* Note that some of these are mutually exclusive as far as producing any
86 * changes - a simultaneous constraint in X and Y, for example, results in a
87 * no-op. */
88#define BV_IDLE 0x000
89#define BV_ROT 0x001
90#define BV_TRANS 0x002
91#define BV_SCALE 0x004
92#define BV_CENTER 0x008
93#define BV_CON_X 0x010
94#define BV_CON_Y 0x020
95#define BV_CON_Z 0x040
96#define BV_CON_GRID 0x080
97#define BV_CON_LINES 0x100
98
99/* Update a view in response to X,Y coordinate changes as generated
100 * by a graphical interface's mouse motion. */
101BV_EXPORT extern int bv_adjust(struct bview *v, int dx, int dy, point_t keypoint, int mode, unsigned long long flags);
102
103/* Beginning extraction of the core of libtclcad view object manipulation
104 * logic. The following functions will initially be pretty straightforward
105 * mappings from libtclcad, and will likely evolve over time.
106 */
107
108/* Return -1 if width and/or height are unset (and hence a meaningful
109 * calculation is impossible), else 0. */
110BV_EXPORT extern int bv_screen_to_view(struct bview *v, fastf_t *fx, fastf_t *fy, fastf_t x, fastf_t y);
111
112/* Compute the min, max, and center points of the scene object.
113 * Return 1 if a bound was computed, else 0 */
114BV_EXPORT extern int bv_scene_obj_bound(struct bv_scene_obj *s, struct bview *v);
115
116/* Find the nearest (mode == 0) or farthest (mode == 1) data_vZ value from
117 * the vlist points in s in the context of view v */
118BV_EXPORT extern fastf_t bv_vZ_calc(struct bv_scene_obj *s, struct bview *v, int mode);
119
120/* Copy object attributes (but not geometry) from src to dest */
121BV_EXPORT extern void bv_obj_sync(struct bv_scene_obj *dest, struct bv_scene_obj *src);
122
123/* Mark object and any child objects as stale for the drawing routines */
124/* There are a few options for this situation - this one, which requires the client code
125 * to explicitly notify the drawing routines they need to do work, an internal options
126 * hash stored in the bv_scene_obj itself which is checked at render time, and setter
127 * wrapper functions that do the bookkeeping for the caller (in lieu of directly setting
128 * values in the bv_scene_obj struct.) The first one isn't ideal because the visual will
129 * be wrong if the caller doesn't supply the notification, the second has unknown
130 * performance implications, and the third would be a major rework of how the bv_scene_obj
131 * data is accessed (effectively, making the internal storage of bv_scene_obj fully hidden
132 * a.l.a the libdm rework.) Not sure what the best option is yet... leaning towards #2
133 * if it is "fast enough"... */
134BV_EXPORT void bv_obj_stale(struct bv_scene_obj *s);
135
136/* Given a view, create an object of the specified type. Like bv_obj_get, except it
137 * leaves the addition of objects to the client. Lower level. */
138BV_EXPORT struct bv_scene_obj *
139bv_obj_create(struct bview *v, int type);
140
141/* Given a view, create an object of the specified type and add it to the
142 * appropriate container. Issues such as memory management as a function of
143 * view settings are handled internally, so client codes don't need to manage
144 * it. */
145BV_EXPORT struct bv_scene_obj *
146bv_obj_get(struct bview *v, int type);
147
148/* Given an object, create an object that is a child of that object. Issues
149 * such as memory management as a function of view settings are handled
150 * internally, so client codes don't need to manage it. */
151BV_EXPORT struct bv_scene_obj *
153
154/* Clear the contents of an object (including releasing its children), but keep
155 * it active in the view. Generally used when redrawing an object */
156BV_EXPORT void
158
159/* Release an object to the internal pools. */
160BV_EXPORT void
162
163/* Given a scene object and a name vname, glob match child names and uuids to
164 * attempt to locate a child of s that matches vname */
165BV_EXPORT struct bv_scene_obj *
166bv_find_child(struct bv_scene_obj *s, const char *vname);
167
168/* Given a view and a name vname, glob match names and uuids to attempt to
169 * locate a scene object in v that matches vname.
170 *
171 * NOTE - currently this is searching the top level objects, but does not walk
172 * down into their children. May want to support that in the future... */
173BV_EXPORT struct bv_scene_obj *
174bv_find_obj(struct bview *v, const char *vname);
175
176/* For the specified object/view pairing, return the appropriate scene object
177 * to use with that view. Usually this will return s, but if a Level of Detail
178 * scheme or some other view-aware rendering of the object is active, that object
179 * will be returned instead. */
180BV_EXPORT struct bv_scene_obj *
181bv_obj_for_view(struct bv_scene_obj *s, struct bview *v);
182
183/* Stash a view-specific object vobj for view v on object s. If vobj is NULL,
184 * this will clear the object for that particular view. */
185BV_EXPORT void
186bv_set_view_obj(struct bv_scene_obj *s, struct bview *v, struct bv_scene_obj *vobj);
187
188/* For the given view, return a pointer to the bu_ptbl holding active scene
189 * objects with the specified type. Note that view-specific db objects are not
190 * part of these sets - they should be retrieved from the scene objects in this
191 * set with bv_obj_for_view. */
192BV_EXPORT struct bu_ptbl *
193bv_view_objs(struct bview *v, int type);
194
195__END_DECLS
196
197/** @} */
198
199#endif /* BV_UTIL_H */
200
201/*
202 * Local Variables:
203 * mode: C
204 * tab-width: 8
205 * indent-tabs-mode: t
206 * c-file-style: "stroustrup"
207 * End:
208 * ex: shiftwidth=4 tabstop=8
209 */
Header file for the BRL-CAD common definitions.
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_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)
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)
struct bv_scene_obj * bv_find_child(struct bv_scene_obj *s, const char *vname)
int bv_scene_obj_bound(struct bv_scene_obj *s, struct bview *v)
size_t bv_clear(struct bview *v, int flags)
void bv_obj_settings_sync(struct bv_obj_settings *dest, struct bv_obj_settings *src)
struct bv_scene_obj * bv_obj_get(struct bview *v, int type)
void bv_obj_put(struct bv_scene_obj *o)
int bv_differ(struct bview *v1, struct bview *v2)
void bv_settings_init(struct bview_settings *s)
void bv_set_view_obj(struct bv_scene_obj *s, struct bview *v, struct bv_scene_obj *vobj)
struct bv_scene_obj * bv_obj_get_child(struct bv_scene_obj *s)
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)
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)
double fastf_t
fastest 64-bit (or larger) floating point type
Definition: vmath.h:330
fastf_t point_t[ELEMENTS_PER_POINT]
3-tuple point
Definition: vmath.h:351
Definition: ptbl.h:53
Definition: defines.h:476