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