BRL-CAD
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-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/** @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
39__BEGIN_DECLS
40
41struct rt_functab; /* forward declaration */
42
43/**
44 * A handle on the internal format of a BRL-CAD database object.
45 */
47 uint32_t idb_magic;
49 int idb_minor_type; /**< @brief ID_xxx */
50 const struct rt_functab *idb_meth; /**< @brief for ft_ifree(), etc. */
51 void * idb_ptr;
53};
54#define idb_type idb_minor_type
55#define RT_DB_INTERNAL_INIT(_p) { \
56 (_p)->idb_magic = RT_DB_INTERNAL_MAGIC; \
57 (_p)->idb_major_type = -1; \
58 (_p)->idb_minor_type = -1; \
59 (_p)->idb_meth = (const struct rt_functab *) ((void *)0); \
60 (_p)->idb_ptr = ((void *)0); \
61 bu_avs_init_empty(&(_p)->idb_avs); \
62 }
63#define RT_DB_INTERNAL_INIT_ZERO {RT_DB_INTERNAL_MAGIC, -1, -1, NULL, NULL, BU_AVS_INIT_ZERO}
64#define RT_CK_DB_INTERNAL(_p) BU_CKMAG(_p, RT_DB_INTERNAL_MAGIC, "rt_db_internal")
65
66/**
67 * Get an object from the database, and convert it into its internal
68 * (i.e., unserialized in-memory) representation. Applies the
69 * provided matrix transform only to the in-memory internal being
70 * returned.
71 *
72 * Returns -
73 * <0 On error
74 * id On success.
75 */
76RT_EXPORT extern int rt_db_get_internal(struct rt_db_internal *ip,
77 const struct directory *dp,
78 const struct db_i *dbip,
79 const mat_t mat,
80 struct resource *resp);
81
82/**
83 * Convert the internal representation of a solid to the external one,
84 * and write it into the database. On success only, the internal
85 * representation is freed.
86 *
87 * Returns -
88 * <0 error
89 * 0 success
90 */
91RT_EXPORT extern int rt_db_put_internal(struct directory *dp,
92 struct db_i *dbip,
93 struct rt_db_internal *ip,
94 struct resource *resp);
95
96/**
97 * Put an object in internal format out onto a file in external
98 * format. Used by LIBWDB.
99 *
100 * Can't really require a dbip parameter, as many callers won't have
101 * one.
102 *
103 * THIS ROUTINE ONLY SUPPORTS WRITING V4 GEOMETRY.
104 *
105 * Returns -
106 * 0 OK
107 * <0 error
108 */
109RT_EXPORT extern int rt_fwrite_internal(FILE *fp,
110 const char *name,
111 const struct rt_db_internal *ip,
112 double conv2mm);
113RT_EXPORT extern void rt_db_free_internal(struct rt_db_internal *ip);
114
115/**
116 * Convert an object name to a rt_db_internal pointer
117 *
118 * Looks up the named object in the directory of the specified model,
119 * obtaining a directory pointer. Then gets that object from the
120 * database and constructs its internal representation. Returns
121 * ID_NULL on error, otherwise returns the type of the object.
122 */
123RT_EXPORT extern int rt_db_lookup_internal(struct db_i *dbip,
124 const char *obj_name,
125 struct directory **dpp,
126 struct rt_db_internal *ip,
127 int noisy,
128 struct resource *resp);
129
130
131__END_DECLS
132
133#endif /* RT_DB_INTERNAL_H */
134
135/*
136 * Local Variables:
137 * tab-width: 8
138 * mode: C
139 * indent-tabs-mode: t
140 * c-file-style: "stroustrup"
141 * End:
142 * ex: shiftwidth=4 tabstop=8
143 */
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:366
Global registry of recognized magic numbers.
struct bu_attribute_value_set idb_avs
Definition: db_internal.h:52
uint32_t idb_magic
Definition: db_internal.h:47
const struct rt_functab * idb_meth
for ft_ifree(), etc.
Definition: db_internal.h:50
int idb_minor_type
ID_xxx.
Definition: db_internal.h:49
void * idb_ptr
Definition: db_internal.h:51