BRL-CAD
Loading...
Searching...
No Matches
db_internal.h
Go to the documentation of this file.
1/* D B _ I N T E R N A 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/** @file db_internal.h
21 *
22 */
23
24#ifndef RT_DB_INTERNAL_H
25#define RT_DB_INTERNAL_H
26
27#include "common.h"
28
29/* system headers */
30#include <stdio.h> /* for FILE */
31
32/* interface headers */
33#include "bu/magic.h"
34#include "bu/avs.h"
35#include "bn/mat.h"
36#include "rt/defines.h"
37#include "rt/resource.h"
38
40
41struct rt_functab; /* forward declaration */
42
43/**
44 * A handle on the internal format of a BRL-CAD database object.
45 *
46 * Note that the d_minor_type of any directory structure associated with a rt_db_internal should
47 * match the value of the rt_db_internal's idb_minor_type.
48 *
49 * TODO - right now, rt_db_internal doesn't encode any notion of data version,
50 * which appears to be a major reason some APIs need to pass a dbip through in
51 * addition to the rt_db_internal. Should we add an idb_version entry here to
52 * indicate idb_ptr data versioning?
53 */
54struct rt_db_internal {
57 int idb_minor_type; /**< @brief ID_xxx */
58 const struct rt_functab *idb_meth; /**< @brief for ft_ifree(), etc. */
59 void * idb_ptr;
61};
62#define idb_type idb_minor_type
63#define RT_DB_INTERNAL_INIT(_p) { \
64 (_p)->idb_magic = RT_DB_INTERNAL_MAGIC; \
65 (_p)->idb_major_type = -1; \
66 (_p)->idb_minor_type = -1; \
67 (_p)->idb_meth = (const struct rt_functab *) ((void *)0); \
68 (_p)->idb_ptr = ((void *)0); \
69 bu_avs_init_empty(&(_p)->idb_avs); \
70 }
71#define RT_DB_INTERNAL_INIT_ZERO {RT_DB_INTERNAL_MAGIC, -1, -1, NULL, NULL, BU_AVS_INIT_ZERO}
72#define RT_CK_DB_INTERNAL(_p) BU_CKMAG(_p, RT_DB_INTERNAL_MAGIC, "rt_db_internal")
74/**
75 * Get an object from the database, and convert it into its internal
76 * (i.e., unserialized in-memory) representation. Applies the
77 * provided matrix transform only to the in-memory internal being
78 * returned.
79 *
80 * Returns -
81 * <0 On error
82 * id On success.
83 */
85 const struct directory *dp,
86 const struct db_i *dbip,
87 const mat_t mat,
88 struct resource *resp);
89
90/**
91 * Convert the internal representation of a solid to the external one,
92 * and write it into the database. On success only, the internal
93 * representation is freed.
94 *
95 * Returns -
96 * <0 error
97 * 0 success
98 */
99RT_EXPORT extern int rt_db_put_internal(struct directory *dp,
100 struct db_i *dbip,
101 struct rt_db_internal *ip,
102 struct resource *resp);
103
104/**
105 * Put an object in internal format out onto a file in external
106 * format. Used by LIBWDB.
107 *
108 * Can't really require a dbip parameter, as many callers won't have
109 * one.
110 *
111 * THIS ROUTINE ONLY SUPPORTS WRITING V4 GEOMETRY.
112 *
113 * Returns -
114 * 0 OK
115 * <0 error
116 */
117RT_EXPORT extern int rt_fwrite_internal(FILE *fp,
118 const char *name,
119 const struct rt_db_internal *ip,
120 double conv2mm);
123/**
124 * Convert an object name to a rt_db_internal pointer
125 *
126 * Looks up the named object in the directory of the specified model,
127 * obtaining a directory pointer. Then gets that object from the
128 * database and constructs its internal representation. Returns
129 * ID_NULL on error, otherwise returns the type of the object.
130 */
131RT_EXPORT extern int rt_db_lookup_internal(struct db_i *dbip,
132 const char *obj_name,
133 struct directory **dpp,
134 struct rt_db_internal *ip,
135 int noisy,
136 struct resource *resp);
137
138
140
141#endif /* RT_DB_INTERNAL_H */
142
143/*
144 * Local Variables:
145 * tab-width: 8
146 * mode: C
147 * indent-tabs-mode: t
148 * c-file-style: "stroustrup"
149 * End:
150 * ex: shiftwidth=4 tabstop=8
151 */
Definition dvec.h:74
Header file for the BRL-CAD common definitions.
int rt_fwrite_internal(FILE *fp, const char *name, const struct rt_db_internal *ip, double conv2mm)
void rt_db_free_internal(struct rt_db_internal *ip)
int rt_db_get_internal(struct rt_db_internal *ip, const struct directory *dp, const struct db_i *dbip, const mat_t mat, struct resource *resp)
int rt_db_lookup_internal(struct db_i *dbip, const char *obj_name, struct directory **dpp, struct rt_db_internal *ip, int noisy, struct resource *resp)
int rt_db_put_internal(struct directory *dp, struct db_i *dbip, struct rt_db_internal *ip, struct resource *resp)
fastf_t mat_t[ELEMENTS_PER_MAT]
4x4 matrix
Definition vmath.h:370
Global registry of recognized magic numbers.
struct bu_attribute_value_set idb_avs
Definition db_internal.h:61
uint32_t idb_magic
Definition db_internal.h:56
const struct rt_functab * idb_meth
for ft_ifree(), etc.
Definition db_internal.h:59
int idb_minor_type
ID_xxx.
Definition db_internal.h:58