BRL-CAD
comb.h
Go to the documentation of this file.
1/* C O M B . 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 rt/comb.h
21 *
22 */
23
24#ifndef RT_COMB_H
25#define RT_COMB_H
26
27#include "common.h"
28
29#ifdef __cplusplus
30# include "opennurbs.h"
31#endif
32
33#include "vmath.h"
34#include "bu/vls.h"
35#include "rt/defines.h"
36
37__BEGIN_DECLS
38
39/* db_comb.c */
40
41/**
42 * Import a combination record from a V4 database into internal form.
43 */
44RT_EXPORT extern int rt_comb_import4(struct rt_db_internal *ip,
45 const struct bu_external *ep,
46 const mat_t matrix, /* NULL if identity */
47 const struct db_i *dbip,
48 struct resource *resp);
49
50RT_EXPORT extern int rt_comb_export4(struct bu_external *ep,
51 const struct rt_db_internal *ip,
52 double local2mm,
53 const struct db_i *dbip,
54 struct resource *resp);
55
56
57RT_EXPORT extern void db_comb_describe(struct bu_vls *str,
58 const struct rt_comb_internal *comb,
59 int verbose,
60 double mm2local);
61
62/**
63 * OBJ[ID_COMBINATION].ft_describe() method
64 */
65RT_EXPORT extern int rt_comb_describe(struct bu_vls *str,
66 const struct rt_db_internal *ip,
67 int verbose,
68 double mm2local);
69
70/**
71 * fills in rgb with the color for a given comb combination
72 *
73 * returns truthfully if a color could be got. note that this routine
74 * will not (and cannot) handle the color inherit/override flag as
75 * that is set on some higher-level parent combination.
76 *
77 */
78RT_EXPORT extern int rt_comb_get_color(unsigned char rgb[3], const struct rt_comb_internal *comb);
79
80
81/**
82 * change all matching object names in the comb tree from old_name to
83 * new_name
84 *
85 * calling function must supply an initialized bu_ptbl, and free it
86 * once done.
87 */
88RT_EXPORT extern int db_comb_mvall(struct directory *dp,
89 struct db_i *dbip,
90 const char *old_name,
91 const char *new_name,
92 struct bu_ptbl *stack);
93
94/* db5_comb.c */
95
96/**
97 * Read a combination object in v5 external (on-disk) format, and
98 * convert it into the internal format described in rtgeom.h
99 *
100 * This is an unusual conversion, because some of the data is taken
101 * from attributes, not just from the object body. By the time this
102 * is called, the attributes will already have been cracked into
103 * ip->idb_avs, we get the attributes from there.
104 *
105 * Returns -
106 * 0 OK
107 * -1 FAIL
108 */
109RT_EXPORT extern int rt_comb_import5(struct rt_db_internal *ip, const struct bu_external *ep, const mat_t mat, const struct db_i *dbip, struct resource *resp);
110
111/**
112 * Return a RT_DIR_NULL terminated array of directory pointers that
113 * holds the set of immediate children associated with comb. The
114 * caller is responsible for freeing the array, but not the directory
115 * structures pointed to by the array.
116 *
117 * Optionally, pointers may also be supplied to collect arrays holding
118 * the boolean operations and matrices associated with the comb entries.
119 * For boolean operations, the caller is responsible for freeing the
120 * array. For matrices, both the array and the matrices themselves
121 * must be freed by the caller. The boolean operations array is zero
122 * terminated, the matrix array is NULL terminated. For example:
123 *
124 * @code
125 * int i = 0;
126 * struct directory *wdp;
127 * struct directory **children = NULL;
128 * int *bool_ops = NULL;
129 * matp_t *matrices = NULL;
130 * matp_t m;
131 * db_comb_children(dbip, comb, &children, &bool_ops, &matrices);
132 * if (db_comb_children(dbip, comb, &bool_ops, &matrices) > 0) {
133 * i = 0;
134 * wdp = children[0];
135 * while (wdp != RT_DIR_NULL) {
136 * char obuf[1024];
137 * bu_log("%s child %d: %d %s\n", dp->d_namep, i, bool_ops[ind], wdp->d_namep);
138 * if (mats[ind]){
139 * bn_mat_print_guts("", mats[i], obuf, 1024);
140 * bu_log("%s %s\n", wdp->d_namep, obuf);
141 * }
142 * i++;
143 * wdp = children[i];
144 * }
145 * }
146 * i = 0;
147 * while (mats[i]) {
148 * bu_free(mats[i], "free matrix");
149 * i++;
150 * }
151 * bu_free(mats, "free mats array");
152 * bu_free(bool_ops, "free ops");
153 * bu_free(children, "free children struct directory ptr array");
154 * @endcode
155 */
156RT_EXPORT extern int db_comb_children(struct db_i *dbip, struct rt_comb_internal *comb, struct directory ***children, int **bool_ops, matp_t **mats);
157
158#ifdef __cplusplus
159RT_EXPORT extern void
160rt_comb_brep(ON_Brep **b, const struct rt_db_internal *ip, const struct bn_tol *tol, const struct db_i *dbip);
161#endif
162
163__END_DECLS
164
165#endif /* RT_COMB_H */
166
167/*
168 * Local Variables:
169 * tab-width: 8
170 * mode: C
171 * indent-tabs-mode: t
172 * c-file-style: "stroustrup"
173 * End:
174 * ex: shiftwidth=4 tabstop=8
175 */
int rt_comb_describe(struct bu_vls *str, const struct rt_db_internal *ip, int verbose, double mm2local)
int rt_comb_export4(struct bu_external *ep, const struct rt_db_internal *ip, double local2mm, const struct db_i *dbip, struct resource *resp)
int rt_comb_get_color(unsigned char rgb[3], const struct rt_comb_internal *comb)
int rt_comb_import4(struct rt_db_internal *ip, const struct bu_external *ep, const mat_t matrix, const struct db_i *dbip, struct resource *resp)
int rt_comb_import5(struct rt_db_internal *ip, const struct bu_external *ep, const mat_t mat, const struct db_i *dbip, struct resource *resp)
void db_comb_describe(struct bu_vls *str, const struct rt_comb_internal *comb, int verbose, double mm2local)
int db_comb_children(struct db_i *dbip, struct rt_comb_internal *comb, struct directory ***children, int **bool_ops, matp_t **mats)
int db_comb_mvall(struct directory *dp, struct db_i *dbip, const char *old_name, const char *new_name, struct bu_ptbl *stack)
void rt_comb_brep(ON_Brep **b, const struct rt_db_internal *ip, const struct bn_tol *tol, const struct db_i *dbip)
Header file for the BRL-CAD common definitions.
fastf_t mat_t[ELEMENTS_PER_MAT]
4x4 matrix
Definition: vmath.h:366
fastf_t * matp_t
pointer to a 4x4 matrix
Definition: vmath.h:369
Definition: tol.h:72
Definition: ptbl.h:53
Definition: vls.h:53
fundamental vector, matrix, quaternion math macros