BRL-CAD
Loading...
Searching...
No Matches
wdb.h
Go to the documentation of this file.
1/* W D B . H
2 * BRL-CAD
3 *
4 * Copyright (c) 1993-2026 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/** @file rt/wdb.h
21 *
22 */
23
24#ifndef RT_WDB_H
25#define RT_WDB_H
26
27#include "common.h"
28
29#include "vmath.h"
30#include "bu/magic.h"
31#include "bu/list.h"
32#include "bu/vls.h"
33#include "bu/observer.h"
34#include "rt/db_instance.h"
35#include "rt/tree.h"
36
38
39/* struct rt_wdb database types (for wdb_type struct entry).
40 * The "default" types will return the wdbp associated with
41 * the dbip - i.e., if the dbip is an inmem it will return
42 * the INMEM types, and if associated with a file it will
43 * return the DISK types. This is for calling code that
44 * just needs a wdbp and isn't concerned with the details
45 * of how objects are being written. */
46#define RT_WDB_TYPE_DB_DEFAULT 0
47#define RT_WDB_TYPE_DB_DEFAULT_APPEND_ONLY 1
48#define RT_WDB_TYPE_DB_DISK 2
49#define RT_WDB_TYPE_DB_DISK_APPEND_ONLY 3
50#define RT_WDB_TYPE_DB_INMEM 4
51#define RT_WDB_TYPE_DB_INMEM_APPEND_ONLY 5
52
53
54/**
55 * This data structure is at the core of the "LIBWDB" support for
56 * allowing application programs to read and write BRL-CAD databases.
57 * Many different access styles are supported.
58 */
59
60struct rt_wdb {
61 struct bu_list l;
62 int type; /** < @brief .g database type (RT_WDB_TYPE - disk or inmem, append-only) */
63 struct db_i * dbip;
65
68
69 /* variables for name prefixing */
73
74 /* default region ident codes for this particular database. */
75 int wdb_item_default;/**< @brief GIFT region ID */
77 int wdb_mat_default;/**< @brief GIFT material code */
78 int wdb_los_default;/**< @brief Line-of-sight estimate */
79
80 /* These members are marked for removal */
81 struct bu_vls wdb_name; /**< @brief database object name */
83 void * wdb_interp; /**< @brief Tcl_Interp */
84};
85
86#define RT_CHECK_WDB(_p) BU_CKMAG(_p, RT_WDB_MAGIC, "rt_wdb")
87#define RT_CK_WDB(_p) RT_CHECK_WDB(_p)
88#define RT_WDB_INIT_ZERO { {RT_WDB_MAGIC, BU_LIST_NULL, BU_LIST_NULL}, 0, NULL, RT_DBTS_INIT_ZERO, BG_TESS_TOL_INIT_ZERO, BN_TOL_INIT_ZERO, NULL, BU_VLS_INIT_ZERO, 0, 0, 0, 0, 0, 0, BU_VLS_INIT_ZERO, BU_OBSERVER_LIST_INIT_ZERO, NULL }
89#define RT_WDB_NULL ((struct rt_wdb *)NULL)
90
91/**
92 *
93 * Routines to allow libwdb to use librt's import/export interface,
94 * rather than having to know about the database formats directly.
95 *
96 */
97RT_EXPORT extern struct rt_wdb *wdb_fopen(const char *filename);
98
99
100/**
101 * Create a libwdb output stream destined for a disk file. This will
102 * destroy any existing file by this name, and start fresh. The file
103 * is then opened in the normal "update" mode and an in-memory
104 * directory is built along the way, allowing retrievals and object
105 * replacements as needed.
106 *
107 * The rt_wdb type returned is RT_WDB_TYPE_DB_DISK.
108 *
109 * Users can change the database title by calling: ???
110 */
111RT_EXPORT extern struct rt_wdb *wdb_fopen_v(const char *filename,
112 int version);
113
114
115/**
116 * Create a libwdb output stream destined for an existing BRL-CAD database,
117 * already opened via a db_open() call.
118 *
119 * Note: there can be only one rt_wdb container of each type per dbip - if an
120 * rt_wdb of the specified type is already associated with the database, the
121 * pre-existing stream will be returned.
122 *
123 * RT_WDB_TYPE_DB_DISK Add to on-disk database
124 * RT_WDB_TYPE_DB_DISK_APPEND_ONLY Add to on-disk database, don't clobber existing names, use prefix
125 * RT_WDB_TYPE_DB_INMEM Add to in-memory database only
126 * RT_WDB_TYPE_DB_INMEM_APPEND_ONLY Ditto, but give errors if name in use.
127 */
128RT_EXPORT extern struct rt_wdb *wdb_dbopen(struct db_i *dbip,
129 int mode);
130
131
132/**
133 * Returns -
134 * 0 and modified *internp;
135 * -1 ft_import failure (from rt_db_get_internal)
136 * -2 db_get_external failure (from rt_db_get_internal)
137 * -3 Attempt to import from write-only (stream) file.
138 * -4 Name not found in database TOC.
139 *
140 * NON-PARALLEL because of rt_uniresource
141 */
142RT_EXPORT extern int wdb_import(struct rt_wdb *wdbp,
143 struct rt_db_internal *internp,
144 const char *name,
145 const mat_t mat);
146
147
148/**
149 * The caller must free "ep".
150 *
151 * Note that the minor_type used here should match both the rt_db_internal
152 * idb_minor_type and struct directory d_minor_type, if either or both of those
153 * containers are associated with the bu_external data being written (typically
154 * either ip->idb_minor_type or dp->d_minor_type are used as the last arguments
155 * to wdb_export_external.)
156 *
157 * Returns -
158 * 0 OK
159 * <0 error
160 */
162 struct bu_external *ep,
163 const char *name,
164 int flags,
165 unsigned char minor_type);
166
167/**
168 * Convert the internal representation of a solid to the external one,
169 * and write it into the database.
170 *
171 * The internal representation is always freed. This is the analog of
172 * rt_db_put_internal() for rt_wdb objects.
173 *
174 * Use this routine in preference to wdb_export() whenever the caller
175 * already has an rt_db_internal structure handy.
176 *
177 * NON-PARALLEL because of rt_uniresource
178 *
179 * Returns -
180 * 0 OK
181 * <0 error
182 */
184 const char *name,
185 struct rt_db_internal *ip,
186 double local2mm);
187
188
189/**
190 * Export an in-memory representation of an object, as described in
191 * the file h/rtgeom.h, into the indicated database.
192 *
193 * The internal representation (gp) is always freed.
194 *
195 * WARNING: The caller must be careful not to double-free gp,
196 * particularly if it's been extracted from an rt_db_internal, e.g. by
197 * passing intern.idb_ptr for gp.
198 *
199 * If the caller has an rt_db_internal structure handy already, they
200 * should call wdb_put_internal() directly -- this is a convenience
201 * routine intended primarily for internal use in LIBWDB.
202 *
203 * Returns -
204 * 0 OK
205 * <0 error
206 */
207RT_EXPORT extern int wdb_export(struct rt_wdb *wdbp,
208 const char *name,
209 void *gp,
210 int id,
211 double local2mm);
212RT_EXPORT extern void wdb_init(struct rt_wdb *wdbp,
213 struct db_i *dbip,
214 int mode);
215
216
217/**
218 * Close a database created with wdb_fopen or wdb_fopen_v.
219 */
220RT_EXPORT extern void wdb_close(struct rt_wdb *wdbp);
221
222/**
223 * Given the name of a database object or a full path to a leaf
224 * object, obtain the internal form of that leaf. Packaged separately
225 * mainly to make available nice Tcl error handling.
226 *
227 * Returns -
228 * BRLCAD_OK
229 * BRLCAD_ERROR
230 */
232 struct rt_db_internal *ip,
233 const char *path,
234 struct rt_wdb *wdb);
235
236
237/**
238 * Given the name of a database object or a full path to a leaf
239 * object, obtain the internal form of that leaf. Packaged separately
240 * mainly to make available nice Tcl error handling. Additionally,
241 * copies ts.ts_mat to matp.
242 *
243 * Returns -
244 * BRLCAD_OK
245 * BRLCAD_ERROR
246 */
248 struct rt_db_internal *ip,
249 const char *path,
250 struct rt_wdb *wdb,
251 matp_t matp);
252
253
255
256#endif /* RT_WDB_H */
257
258/*
259 * Local Variables:
260 * tab-width: 8
261 * mode: C
262 * indent-tabs-mode: t
263 * c-file-style: "stroustrup"
264 * End:
265 * ex: shiftwidth=4 tabstop=8
266 */
Definition dvec.h:74
Header file for the BRL-CAD common definitions.
fastf_t mat_t[ELEMENTS_PER_MAT]
4x4 matrix
Definition vmath.h:369
fastf_t * matp_t
pointer to a 4x4 matrix
Definition vmath.h:372
Global registry of recognized magic numbers.
struct rt_wdb * wdb_fopen_v(const char *filename, int version)
void wdb_init(struct rt_wdb *wdbp, struct db_i *dbip, int mode)
struct rt_wdb * wdb_fopen(const char *filename)
int wdb_import_from_path2(struct bu_vls *logstr, struct rt_db_internal *ip, const char *path, struct rt_wdb *wdb, matp_t matp)
void wdb_close(struct rt_wdb *wdbp)
struct rt_wdb * wdb_dbopen(struct db_i *dbip, int mode)
int wdb_export(struct rt_wdb *wdbp, const char *name, void *gp, int id, double local2mm)
int wdb_import(struct rt_wdb *wdbp, struct rt_db_internal *internp, const char *name, const mat_t mat)
int wdb_import_from_path(struct bu_vls *logstr, struct rt_db_internal *ip, const char *path, struct rt_wdb *wdb)
int wdb_export_external(struct rt_wdb *wdbp, struct bu_external *ep, const char *name, int flags, unsigned char minor_type)
int wdb_put_internal(struct rt_wdb *wdbp, const char *name, struct rt_db_internal *ip, double local2mm)
Definition tol.h:72
Definition vls.h:53
Definition wdb.h:60
int wdb_mat_default
GIFT material code.
Definition wdb.h:77
struct bu_vls wdb_name
database object name
Definition wdb.h:81
int wdb_item_default
GIFT region ID.
Definition wdb.h:75
struct bu_vls wdb_prestr
Definition wdb.h:70
void * wdb_interp
Tcl_Interp.
Definition wdb.h:83
int wdb_los_default
Line-of-sight estimate.
Definition wdb.h:78
struct bn_tol wdb_tol
Definition wdb.h:67
struct bu_observer_list wdb_observers
Definition wdb.h:82
int wdb_num_dups
Definition wdb.h:72
int wdb_air_default
Definition wdb.h:76
struct db_i * dbip
.g database type (RT_WDB_TYPE - disk or inmem, append-only)
Definition wdb.h:63
struct bu_list l
Definition wdb.h:61
struct bg_tess_tol wdb_ttol
Definition wdb.h:66
int type
Definition wdb.h:62
int wdb_ncharadd
Definition wdb.h:71
struct db_tree_state wdb_initial_tree_state
Definition wdb.h:64
fundamental vector, matrix, quaternion math macros