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