BRL-CAD
tree.h
Go to the documentation of this file.
1/* T R E E . 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/tree.h
21 *
22 */
23
24#ifndef RT_TREE_H
25#define RT_TREE_H
26
27#include "common.h"
28#include "vmath.h"
29#include "bu/avs.h"
30#include "bu/magic.h"
31#include "bu/malloc.h"
32#include "bn/tol.h"
33#include "rt/geom.h"
34#include "rt/defines.h"
35#include "rt/db_instance.h"
36#include "rt/directory.h"
37#include "rt/mater.h"
38#include "rt/op.h"
39#include "rt/region.h"
40#include "rt/soltab.h"
41#include "rt/tol.h"
42#include "nmg.h"
43
44__BEGIN_DECLS
45
46union tree; /* forward declaration */
47struct resource; /* forward declaration */
48struct rt_i; /* forward declaration */
49struct rt_comb_internal; /* forward declaration */
50struct rt_db_internal; /* forward declaration */
51
52/**
53 * State for database tree walker db_walk_tree() and related
54 * user-provided handler routines.
55 */
57 uint32_t magic;
58 struct db_i * ts_dbip;
59 int ts_sofar; /**< @brief Flag bits */
60
61 int ts_regionid; /**< @brief GIFT compat region ID code*/
62 int ts_aircode; /**< @brief GIFT compat air code */
63 int ts_gmater; /**< @brief GIFT compat material code */
64 int ts_los; /**< @brief equivalent LOS estimate */
65 struct mater_info ts_mater; /**< @brief material properties */
66
67 /* FIXME: ts_mat should be a matrix pointer, not a matrix */
68 mat_t ts_mat; /**< @brief transform matrix */
69 int ts_is_fastgen; /**< @brief REGION_NON_FASTGEN/_PLATE/_VOLUME */
70 struct bu_attribute_value_set ts_attrs; /**< @brief attribute/value structure */
71
72 int ts_stop_at_regions; /**< @brief else stop at solids */
74 const struct db_full_path *pathp,
75 const struct rt_comb_internal *comb,
76 void *client_data
77 ); /**< @brief callback during DAG downward traversal called on region nodes */
78 union tree * (*ts_region_end_func)(struct db_tree_state *tsp,
79 const struct db_full_path *pathp,
80 union tree *curtree,
81 void *client_data
82 ); /**< @brief callback during DAG upward traversal called on region nodes */
83 union tree * (*ts_leaf_func)(struct db_tree_state *tsp,
84 const struct db_full_path *pathp,
85 struct rt_db_internal *ip,
86 void *client_data
87 ); /**< @brief callback during DAG traversal called on leaf primitive nodes */
88 const struct bg_tess_tol * ts_ttol; /**< @brief Tessellation tolerance */
89 const struct bn_tol * ts_tol; /**< @brief Math tolerance */
90 struct model ** ts_m; /**< @brief ptr to ptr to NMG "model" */
91 struct rt_i * ts_rtip; /**< @brief Helper for rt_gettrees() */
92 struct resource * ts_resp; /**< @brief Per-CPU data */
93};
94#define RT_DBTS_INIT_ZERO { RT_DBTS_MAGIC, NULL, 0, 0, 0, 0, 0, RT_MATER_INFO_INIT_ZERO, MAT_INIT_ZERO, 0, BU_AVS_INIT_ZERO, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
95/* from mged_initial_tree_state */
96#define RT_DBTS_INIT_IDN { RT_DBTS_MAGIC, NULL, 0, 0, 0, 0, 100, RT_MATER_INFO_INIT_IDN, MAT_INIT_IDN, 0, BU_AVS_INIT_ZERO, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
97
98#define TS_SOFAR_MINUS 1 /**< @brief Subtraction encountered above */
99#define TS_SOFAR_INTER 2 /**< @brief Intersection encountered above */
100#define TS_SOFAR_REGION 4 /**< @brief Region encountered above */
101
102#define RT_CK_DBTS(_p) BU_CKMAG(_p, RT_DBTS_MAGIC, "db_tree_state")
103
104/**
105 * initial tree start for db tree walkers.
106 *
107 * Also used by converters in conv/ directory. Don't forget to
108 * initialize ts_dbip before use.
109 */
110RT_EXPORT extern const struct db_tree_state rt_initial_tree_state;
111
112/**
113 * State for database traversal functions.
114 */
116{
117 uint32_t magic;
118 struct db_i *dbip;
120 struct db_i *,
121 struct directory *,
122 void *);
124 struct db_i *,
125 struct directory *,
126 void *);
127 void (*leaf_func) (
128 struct db_i *,
129 struct directory *,
130 void *);
131 struct resource *resp;
133};
134#define RT_DB_TRAVERSE_INIT(_p) {(_p)->magic = RT_DB_TRAVERSE_MAGIC; \
135 (_p)->dbip = ((void *)0); (_p)->comb_enter_func = ((void *)0); \
136 (_p)->comb_exit_func = ((void *)0); (_p)->leaf_func = ((void *)0); \
137 (_p)->resp = ((void *)0); (_p)->client_data = ((void *)0);}
138#define RT_CK_DB_TRAVERSE(_p) BU_CKMAG(_p, RT_DB_TRAVERSE_MAGIC, "db_traverse")
139
141 uint32_t magic;
144};
145#define RT_CK_CTS(_p) BU_CKMAG(_p, RT_CTS_MAGIC, "combined_tree_state")
146
147union tree {
148 uint32_t magic; /**< @brief First word: magic number */
149 /* Second word is always OP code */
150 struct tree_node {
151 uint32_t magic;
152 int tb_op; /**< @brief non-leaf */
153 struct region *tb_regionp; /**< @brief ptr to containing region */
154 union tree *tb_left;
157 struct tree_leaf {
158 uint32_t magic;
159 int tu_op; /**< @brief leaf, OP_SOLID */
160 struct region *tu_regionp; /**< @brief ptr to containing region */
161 struct soltab *tu_stp;
163 struct tree_cts {
164 uint32_t magic;
165 int tc_op; /**< @brief leaf, OP_REGION */
166 struct region *tc_pad; /**< @brief unused */
170 uint32_t magic;
171 int td_op; /**< @brief leaf, OP_NMG_TESS */
172 const char *td_name; /**< @brief If non-null, dynamic string describing heritage of this region */
173 struct nmgregion *td_r; /**< @brief ptr to NMG region */
176 uint32_t magic;
177 int tl_op; /**< @brief leaf, OP_DB_LEAF */
178 matp_t tl_mat; /**< @brief xform matp, NULL ==> identity */
179 char *tl_name; /**< @brief Name of this leaf (bu_strdup'ed) */
181};
182/* Things which are in the same place in both A & B structures */
183#define tr_op tr_a.tu_op
184#define tr_regionp tr_a.tu_regionp
185
186#define TREE_NULL ((union tree *)0)
187#define RT_CK_TREE(_p) BU_CKMAG(_p, RT_TREE_MAGIC, "union tree")
188
189/**
190 * initialize a union tree to zero without a node operation set. Use
191 * the largest union so all values are effectively zero except for the
192 * magic number.
193 */
194#define RT_TREE_INIT(_p) { \
195 (_p)->magic = RT_TREE_MAGIC; \
196 (_p)->tr_b.tb_op = 0; \
197 (_p)->tr_b.tb_regionp = NULL; \
198 (_p)->tr_b.tb_left = NULL; \
199 (_p)->tr_b.tb_right = NULL; \
200 }
201
202/**
203 * RT_GET_TREE returns a union tree pointer with the magic number is
204 * set to RT_TREE_MAGIC.
205 *
206 * DEPRECATED, use BU_GET()+RT_TREE_INIT()
207 */
208#define RT_GET_TREE(_tp, _res) { \
209 BU_GET((_tp), union tree); \
210 RT_TREE_INIT((_tp)); \
211 }
212
213
214/**
215 * RT_FREE_TREE deinitializes a tree union pointer.
216 *
217 * DEPRECATED, use BU_PUT()
218 */
219#define RT_FREE_TREE(_tp, _res) { \
220 BU_PUT((_tp), union tree); \
221 }
222
223
224/**
225 * flattened version of the union tree
226 */
228{
229 union tree *tl_tree;
230 int tl_op;
231};
232
233#define TREE_LIST_NULL ((struct tree_list *)0)
234
235#ifdef USE_OPENCL
236/**
237 * Flattened version of the infix union tree.
238 */
239#define UOP_UNION 1 /**< @brief Binary: L union R */
240#define UOP_INTERSECT 2 /**< @brief Binary: L intersect R */
241#define UOP_SUBTRACT 3 /**< @brief Binary: L subtract R */
242#define UOP_XOR 4 /**< @brief Binary: L xor R, not both*/
243#define UOP_NOT 5 /**< @brief Unary: not L */
244#define UOP_GUARD 6 /**< @brief Unary: not L, or else! */
245#define UOP_XNOP 7 /**< @brief Unary: L, mark region */
246
247#define UOP_SOLID 0 /**< @brief Leaf: tr_stp -> solid */
248
249/**
250 * bit expr tree representation
251 *
252 * node:
253 * uint uop : 3
254 * uint right_child : 29
255 *
256 * leaf:
257 * uint uop : 3
258 * uint st_bit : 29
259 */
260struct bit_tree {
261 unsigned val;
262};
263
264struct cl_tree_bit {
265 cl_uint val;
266};
267
268/* Print a bit expr tree */
269RT_EXPORT extern void rt_pr_bit_tree(const struct bit_tree *btp,
270 int idx,
271 int lvl);
272
273RT_EXPORT extern void rt_bit_tree(struct bit_tree *btp,
274 const union tree *tp,
275 size_t *len);
276#endif
277
278/* Print an expr tree */
279RT_EXPORT extern void rt_pr_tree(const union tree *tp,
280 int lvl);
281RT_EXPORT extern void rt_pr_tree_vls(struct bu_vls *vls,
282 const union tree *tp);
283RT_EXPORT extern char *rt_pr_tree_str(const union tree *tree);
284
285struct partition; /* forward declaration */
286RT_EXPORT extern void rt_pr_tree_val(const union tree *tp,
287 const struct partition *partp,
288 int pr_name,
289 int lvl);
290
291/**
292 * Duplicate the contents of a db_tree_state structure, including a
293 * private copy of the ts_mater field(s) and the attribute/value set.
294 */
295RT_EXPORT extern void db_dup_db_tree_state(struct db_tree_state *otsp,
296 const struct db_tree_state *itsp);
297
298/**
299 * Release dynamic fields inside the structure, but not the structure
300 * itself.
301 */
302RT_EXPORT extern void db_free_db_tree_state(struct db_tree_state *tsp);
303
304/**
305 * In most cases, you don't want to use this routine, you want to
306 * struct copy mged_initial_tree_state or rt_initial_tree_state, and
307 * then set ts_dbip in your copy.
308 */
309RT_EXPORT extern void db_init_db_tree_state(struct db_tree_state *tsp,
310 struct db_i *dbip,
311 struct resource *resp);
312RT_EXPORT extern struct combined_tree_state *db_new_combined_tree_state(const struct db_tree_state *tsp,
313 const struct db_full_path *pathp);
314RT_EXPORT extern struct combined_tree_state *db_dup_combined_tree_state(const struct combined_tree_state *old);
315RT_EXPORT extern void db_free_combined_tree_state(struct combined_tree_state *ctsp);
316RT_EXPORT extern void db_pr_tree_state(const struct db_tree_state *tsp);
317RT_EXPORT extern void db_pr_combined_tree_state(const struct combined_tree_state *ctsp);
318
319/**
320 * Handle inheritance of material property found in combination
321 * record. Color and the material property have separate inheritance
322 * interlocks.
323 *
324 * Returns -
325 * -1 failure
326 * 0 success
327 * 1 success, this is the top of a new region.
328 */
329RT_EXPORT extern int db_apply_state_from_comb(struct db_tree_state *tsp,
330 const struct db_full_path *pathp,
331 const struct rt_comb_internal *comb);
332
333/**
334 * The search stops on the first match.
335 *
336 * Returns -
337 * tp if found
338 * TREE_NULL if not found in this tree
339 */
340RT_EXPORT extern union tree *db_find_named_leaf(union tree *tp, const char *cp);
341
342/**
343 * The search stops on the first match.
344 *
345 * Returns -
346 * TREE_NULL if not found in this tree
347 * tp if found
348 * *side == 1 if leaf is on lhs.
349 * *side == 2 if leaf is on rhs.
350 *
351 */
352RT_EXPORT extern union tree *db_find_named_leafs_parent(int *side,
353 union tree *tp,
354 const char *cp);
355RT_EXPORT extern void db_tree_del_lhs(union tree *tp,
356 struct resource *resp);
357RT_EXPORT extern void db_tree_del_rhs(union tree *tp,
358 struct resource *resp);
359
360/**
361 * Given a name presumably referenced in a OP_DB_LEAF node, delete
362 * that node, and the operation node that references it. Not that
363 * this may not produce an equivalent tree, for example when rewriting
364 * (A - subtree) as (subtree), but that will be up to the caller/user
365 * to adjust. This routine gets rid of exactly two nodes in the tree:
366 * leaf, and op. Use some other routine if you wish to kill the
367 * entire rhs below "-" and "intersect" nodes.
368 *
369 * The two nodes deleted will have their memory freed.
370 *
371 * If the tree is a single OP_DB_LEAF node, the leaf is freed and *tp
372 * is set to NULL.
373 *
374 * Returns -
375 * -3 Internal error
376 * -2 Tree is empty
377 * -1 Unable to find OP_DB_LEAF node specified by 'cp'.
378 * 0 OK
379 */
380RT_EXPORT extern int db_tree_del_dbleaf(union tree **tp,
381 const char *cp,
382 struct resource *resp,
383 int nflag);
384
385/**
386 * Multiply on the left every matrix found in a DB_LEAF node in a
387 * tree.
388 */
389RT_EXPORT extern void db_tree_mul_dbleaf(union tree *tp,
390 const mat_t mat);
391
392/**
393 * This routine traverses a combination (union tree) in LNR order and
394 * calls the provided function for each OP_DB_LEAF node. Note that
395 * this routine does not go outside this one combination!!!!
396 *
397 * was previously named comb_functree()
398 */
399RT_EXPORT extern void db_tree_funcleaf(struct db_i *dbip,
400 struct rt_comb_internal *comb,
401 union tree *comb_tree,
402 void (*leaf_func)(struct db_i *, struct rt_comb_internal *, union tree *,
403 void *, void *, void *, void *),
404 void * user_ptr1,
405 void * user_ptr2,
406 void * user_ptr3,
407 void * user_ptr4);
408
409/**
410 * Starting with possible prior partial path and corresponding
411 * accumulated state, follow the path given by "new_path", updating
412 * *tsp and *total_path with full state information along the way. In
413 * a better world, there would have been a "combined_tree_state" arg.
414 *
415 * Parameter 'depth' controls how much of 'new_path' is used:
416 *
417 * 0 use all of new_path
418 * >0 use only this many of the first elements of the path
419 * <0 use all but this many path elements.
420 *
421 * A much more complete version of rt_plookup() and pathHmat(). There
422 * is also a TCL interface.
423 *
424 * Returns -
425 * 0 success (plus *tsp is updated)
426 * -1 error (*tsp values are not useful)
427 */
428RT_EXPORT extern int db_follow_path(struct db_tree_state *tsp,
429 struct db_full_path *total_path,
430 const struct db_full_path *new_path,
431 int noisy,
432 long pdepth);
433
434/**
435 * Follow the slash-separated path given by "cp", and update *tsp and
436 * *total_path with full state information along the way.
437 *
438 * A much more complete version of rt_plookup().
439 *
440 * TODO - need to extend this to support specifiers orig_str to
441 * call out particular instances of combs in a tree...
442 *
443 * Returns -
444 * 0 success (plus *tsp is updated)
445 * -1 error (*tsp values are not useful)
446 */
447RT_EXPORT extern int db_follow_path_for_state(struct db_tree_state *tsp,
448 struct db_full_path *pathp,
449 const char *orig_str, int noisy);
450
451RT_EXPORT extern union tree *db_dup_subtree(const union tree *tp,
452 struct resource *resp);
453RT_EXPORT extern void db_ck_tree(const union tree *tp);
454
455
456/**
457 * Release all storage associated with node 'tp', including children
458 * nodes.
459 */
460RT_EXPORT extern void db_free_tree(union tree *tp,
461 struct resource *resp);
462
463
464/**
465 * Re-balance this node to make it left heavy. Union operators will
466 * be moved to left side. when finished "tp" MUST still point to top
467 * node of this subtree.
468 */
469RT_EXPORT extern void db_left_hvy_node(union tree *tp);
470
471
472/**
473 * If there are non-union operations in the tree, above the region
474 * nodes, then rewrite the tree so that the entire tree top is nothing
475 * but union operations, and any non-union operations are clustered
476 * down near the region nodes.
477 */
478RT_EXPORT extern void db_non_union_push(union tree *tp,
479 struct resource *resp);
480
481/**
482 * Return a count of the number of "union tree" nodes below "tp",
483 * including tp.
484 */
485RT_EXPORT extern int db_count_tree_nodes(const union tree *tp,
486 int count);
487
488
489/**
490 * Returns -
491 * 1 if this tree contains nothing but union operations.
492 * 0 if at least one subtraction or intersection op exists.
493 */
494RT_EXPORT extern int db_is_tree_all_unions(const union tree *tp);
495RT_EXPORT extern int db_count_subtree_regions(const union tree *tp);
496RT_EXPORT extern int db_tally_subtree_regions(union tree *tp,
497 union tree **reg_trees,
498 int cur,
499 int lim,
500 struct resource *resp);
501
502/**
503 * This is the top interface to the "tree walker."
504 *
505 * Parameters:
506 * rtip rt_i structure to database (open with rt_dirbuild())
507 * argc # of tree-tops named
508 * argv names of tree-tops to process
509 * init_state Input parameter: initial state of the tree.
510 * For example: rt_initial_tree_state,
511 * and mged_initial_tree_state.
512 *
513 * These parameters are pointers to callback routines. If NULL, they
514 * won't be called.
515 *
516 * reg_start_func Called at beginning of each region, before
517 * visiting any nodes within the region. Return
518 * 0 if region should be skipped without
519 * recursing, otherwise non-zero. DO NOT USE FOR
520 * OTHER PURPOSES! For example, can be used to
521 * quickly skip air regions.
522 *
523 * reg_end_func Called after all nodes within a region have been
524 * recursively processed by leaf_func. If it
525 * wants to retain 'curtree' then it may steal
526 * that pointer and return TREE_NULL. If it
527 * wants us to clean up some or all of that tree,
528 * then it returns a non-null (union tree *)
529 * pointer, and that tree is safely freed in a
530 * non-parallel section before we return.
531 *
532 * leaf_func Function to process a leaf node. It is actually
533 * invoked from db_recurse() from
534 * _db_walk_subtree(). Returns (union tree *)
535 * representing the leaf, or TREE_NULL if leaf
536 * does not exist or has an error.
537 *
538 *
539 * This routine will employ multiple CPUs if asked, but is not
540 * multiply-parallel-recursive. Call this routine with ncpu > 1 from
541 * serial code only. When called from within an existing thread, ncpu
542 * must be 1.
543 *
544 * If ncpu > 1, the caller is responsible for making sure that
545 * RTG.rtg_parallel is non-zero.
546 *
547 * Plucks per-cpu resources out of rtip->rti_resources[]. They need
548 * to have been initialized first.
549 *
550 * Returns -
551 * -1 Failure to prepare even a single sub-tree
552 * 0 OK
553 */
554RT_EXPORT extern int db_walk_tree(struct db_i *dbip,
555 int argc,
556 const char **argv,
557 int ncpu,
558 const struct db_tree_state *init_state,
559 int (*reg_start_func) (struct db_tree_state * /*tsp*/,
560 const struct db_full_path * /*pathp*/,
561 const struct rt_comb_internal * /* combp */,
562 void *client_data),
563 union tree *(*reg_end_func) (struct db_tree_state * /*tsp*/,
564 const struct db_full_path * /*pathp*/,
565 union tree * /*curtree*/,
566 void *client_data),
567 union tree *(*leaf_func) (struct db_tree_state * /*tsp*/,
568 const struct db_full_path * /*pathp*/,
569 struct rt_db_internal * /*ip*/,
570 void *client_data),
571 void *client_data);
572
573/**
574 * Fills a bu_vls with a representation of the given tree appropriate
575 * for processing by Tcl scripts.
576 *
577 * A tree 't' is represented in the following manner:
578 *
579 * t := { l dbobjname { mat } }
580 * | { l dbobjname }
581 * | { u t1 t2 }
582 * | { n t1 t2 }
583 * | { - t1 t2 }
584 * | { ^ t1 t2 }
585 * | { ! t1 }
586 * | { G t1 }
587 * | { X t1 }
588 * | { N }
589 * | {}
590 *
591 * where 'dbobjname' is a string containing the name of a database object,
592 * 'mat' is the matrix preceding a leaf,
593 * 't1', 't2' are trees (recursively defined).
594 *
595 * Notice that in most cases, this tree will be grossly unbalanced.
596 */
597RT_EXPORT extern int db_tree_list(struct bu_vls *vls, const union tree *tp);
598
599/**
600 * Take a TCL-style string description of a binary tree, as produced
601 * by db_tree_list(), and reconstruct the in-memory form of that tree.
602 */
603RT_EXPORT extern union tree *db_tree_parse(struct bu_vls *vls, const char *str, struct resource *resp);
604
605/**
606 * This subroutine is called for a no-frills tree-walk, with the
607 * provided subroutines being called at every combination and leaf
608 * (solid) node, respectively.
609 *
610 * This routine is recursive, so no variables may be declared static.
611 */
612RT_EXPORT extern void db_functree(struct db_i *dbip,
613 struct directory *dp,
614 void (*comb_func)(struct db_i *,
615 struct directory *,
616 void *),
617 void (*leaf_func)(struct db_i *,
618 struct directory *,
619 void *),
620 struct resource *resp,
621 void *client_data);
622/**
623 * Ray Tracing library database tree walker.
624 *
625 * Collect and prepare regions and solids for subsequent ray-tracing.
626 *
627 */
628
629
630/**
631 * Calculate the bounding RPP of the region whose boolean tree is
632 * 'tp'. The bounding RPP is returned in tree_min and tree_max, which
633 * need not have been initialized first.
634 *
635 * Returns -
636 * 0 success
637 * -1 failure (tree_min and tree_max may have been altered)
638 */
639RT_EXPORT extern int rt_bound_tree(const union tree *tp,
640 vect_t tree_min,
641 vect_t tree_max);
642
643/**
644 * Eliminate any references to NOP nodes from the tree. It is safe to
645 * use db_free_tree() here, because there will not be any dead solids.
646 * They will all have been converted to OP_NOP nodes by
647 * _rt_tree_kill_dead_solid_refs(), previously, so there is no need to
648 * worry about multiple db_free_tree()'s repeatedly trying to free one
649 * solid that has been instanced multiple times.
650 *
651 * Returns -
652 * 0 this node is OK.
653 * -1 request caller to kill this node
654 */
655RT_EXPORT extern int rt_tree_elim_nops(union tree *,
656 struct resource *resp);
657
658/**
659 * Return count of number of leaf nodes in this tree.
660 */
661RT_EXPORT extern size_t db_tree_nleaves(const union tree *tp);
662
663/**
664 * Take a binary tree in "V4-ready" layout (non-unions pushed below
665 * unions, left-heavy), and flatten it into an array layout, ready for
666 * conversion back to the GIFT-inspired V4 database format.
667 *
668 * This is done using the db_non_union_push() routine.
669 *
670 * If argument 'free' is non-zero, then the non-leaf nodes are freed
671 * along the way, to prevent memory leaks. In this case, the caller's
672 * copy of 'tp' will be invalid upon return.
673 *
674 * When invoked at the very top of the tree, the op argument must be
675 * OP_UNION.
676 */
677RT_EXPORT extern struct rt_tree_array *db_flatten_tree(struct rt_tree_array *rt_tree_array, union tree *tp, int op, int avail, struct resource *resp);
678
679
680/**
681 * Produce a GIFT-compatible listing, one "member" per line,
682 * regardless of the structure of the tree we've been given.
683 */
684RT_EXPORT extern void db_tree_flatten_describe(struct bu_vls *vls,
685 const union tree *tp,
686 int indented,
687 int lvl,
688 double mm2local,
689 struct resource *resp);
690
691RT_EXPORT extern void db_tree_describe(struct bu_vls *vls,
692 const union tree *tp,
693 int indented,
694 int lvl,
695 double mm2local);
696
697/**
698 * Support routine for db_ck_v4gift_tree().
699 * Ensure that the tree below 'tp' is left-heavy, i.e. that there are
700 * nothing but solids on the right side of any binary operations.
701 *
702 * Returns -
703 * -1 ERROR
704 * 0 OK
705 */
706RT_EXPORT extern int db_ck_left_heavy_tree(const union tree *tp,
707 int no_unions);
708/**
709 * Look a gift-tree in the mouth.
710 *
711 * Ensure that this boolean tree conforms to the GIFT convention that
712 * union operations must bind the loosest.
713 *
714 * There are two stages to this check:
715 * 1) Ensure that if unions are present they are all at the root of tree,
716 * 2) Ensure non-union children of union nodes are all left-heavy
717 * (nothing but solid nodes permitted on rhs of binary operators).
718 *
719 * Returns -
720 * -1 ERROR
721 * 0 OK
722 */
723RT_EXPORT extern int db_ck_v4gift_tree(const union tree *tp);
724
725/**
726 * Given a rt_tree_array array, build a tree of "union tree" nodes
727 * appropriately connected together. Every element of the
728 * rt_tree_array array used is replaced with a TREE_NULL. Elements
729 * which are already TREE_NULL are ignored. Returns a pointer to the
730 * top of the tree.
731 */
732RT_EXPORT extern union tree *db_mkbool_tree(struct rt_tree_array *rt_tree_array,
733 size_t howfar,
734 struct resource *resp);
735
736RT_EXPORT extern union tree *db_mkgift_tree(struct rt_tree_array *trees,
737 size_t subtreecount,
738 struct resource *resp);
739
740
741RT_EXPORT extern void rt_optim_tree(union tree *tp,
742 struct resource *resp);
743
744
745
746
747
748/*************************************************************************
749 * Deprecated
750 *************************************************************************/
751
752
753/**
754 * Updates state via *tsp, pushes member's directory entry on *pathp.
755 * (Caller is responsible for popping it).
756 *
757 * Returns -
758 * -1 failure
759 * 0 success, member pushed on path
760 *
761 * DEPRECATED, internal implementation function
762 */
763RT_EXPORT extern int db_apply_state_from_memb(struct db_tree_state *tsp,
764 struct db_full_path *pathp,
765 const union tree *tp);
766
767/**
768 * Returns -
769 * -1 found member, failed to apply state
770 * 0 unable to find member 'cp'
771 * 1 state applied OK
772 *
773 * DEPRECATED, internal implementation function
774 */
775RT_EXPORT extern int db_apply_state_from_one_member(struct db_tree_state *tsp,
776 struct db_full_path *pathp,
777 const char *cp,
778 int sofar,
779 const union tree *tp);
780
781/**
782 * Recurse down the tree, finding all the leaves (or finding just all
783 * the regions).
784 *
785 * ts_region_start_func() is called to permit regions to be skipped.
786 * It is not intended to be used for collecting state.
787 *
788 * DEPRECATED, internal implementation function
789 */
790RT_EXPORT extern union tree *db_recurse(struct db_tree_state *tsp,
791 struct db_full_path *pathp,
792 struct combined_tree_state **region_start_statepp,
793 void *client_data);
794
795
796
797__END_DECLS
798
799#endif /* RT_TREE_H */
800
801/*
802 * Local Variables:
803 * tab-width: 8
804 * mode: C
805 * indent-tabs-mode: t
806 * c-file-style: "stroustrup"
807 * End:
808 * ex: shiftwidth=4 tabstop=8
809 */
Header file for the BRL-CAD common definitions.
fastf_t vect_t[ELEMENTS_PER_VECT]
3-tuple vector
Definition: vmath.h:345
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
Global registry of recognized magic numbers.
Main header file for the BRL-CAD Non-Manifold Geometry Library, LIBNMG.
Definition: tol.h:72
Definition: vls.h:53
struct db_full_path cts_p
Definition: tree.h:143
struct db_tree_state cts_s
Definition: tree.h:142
uint32_t magic
Definition: tree.h:141
void(* comb_exit_func)(struct db_i *, struct directory *, void *)
Definition: tree.h:123
void * client_data
Definition: tree.h:132
void(* leaf_func)(struct db_i *, struct directory *, void *)
Definition: tree.h:127
uint32_t magic
Definition: tree.h:117
struct db_i * dbip
Definition: tree.h:118
struct resource * resp
Definition: tree.h:131
void(* comb_enter_func)(struct db_i *, struct directory *, void *)
Definition: tree.h:119
int ts_los
equivalent LOS estimate
Definition: tree.h:64
struct mater_info ts_mater
material properties
Definition: tree.h:65
const struct bg_tess_tol * ts_ttol
Tessellation tolerance.
Definition: tree.h:88
int ts_is_fastgen
REGION_NON_FASTGEN/_PLATE/_VOLUME.
Definition: tree.h:69
struct resource * ts_resp
Per-CPU data.
Definition: tree.h:92
struct rt_i * ts_rtip
Helper for rt_gettrees()
Definition: tree.h:91
int ts_sofar
Flag bits.
Definition: tree.h:59
uint32_t magic
Definition: tree.h:57
int ts_regionid
GIFT compat region ID code.
Definition: tree.h:61
struct bu_attribute_value_set ts_attrs
attribute/value structure
Definition: tree.h:70
const struct bn_tol * ts_tol
Math tolerance.
Definition: tree.h:89
struct db_i * ts_dbip
Definition: tree.h:58
struct model ** ts_m
ptr to ptr to NMG "model"
Definition: tree.h:90
int(* ts_region_start_func)(struct db_tree_state *tsp, const struct db_full_path *pathp, const struct rt_comb_internal *comb, void *client_data)
callback during DAG downward traversal called on region nodes
Definition: tree.h:73
int ts_aircode
GIFT compat air code.
Definition: tree.h:62
mat_t ts_mat
transform matrix
Definition: tree.h:68
int ts_stop_at_regions
else stop at solids
Definition: tree.h:72
int ts_gmater
GIFT compat material code.
Definition: tree.h:63
NMG topological model.
Definition: topology.h:289
NMG topological region.
Definition: topology.h:277
Definition: region.h:44
int tl_op
Definition: tree.h:230
union tree * tl_tree
Definition: tree.h:229
Definition: soltab.h:56
int tc_op
leaf, OP_REGION
Definition: tree.h:165
struct region * tc_pad
unused
Definition: tree.h:166
uint32_t magic
Definition: tree.h:164
struct combined_tree_state * tc_ctsp
Definition: tree.h:167
int tl_op
leaf, OP_DB_LEAF
Definition: tree.h:177
uint32_t magic
Definition: tree.h:176
char * tl_name
Name of this leaf (bu_strdup'ed)
Definition: tree.h:179
matp_t tl_mat
xform matp, NULL ==> identity
Definition: tree.h:178
uint32_t magic
Definition: tree.h:158
struct soltab * tu_stp
Definition: tree.h:161
int tu_op
leaf, OP_SOLID
Definition: tree.h:159
struct region * tu_regionp
ptr to containing region
Definition: tree.h:160
const char * td_name
If non-null, dynamic string describing heritage of this region.
Definition: tree.h:172
uint32_t magic
Definition: tree.h:170
struct nmgregion * td_r
ptr to NMG region
Definition: tree.h:173
int td_op
leaf, OP_NMG_TESS
Definition: tree.h:171
union tree * tb_left
Definition: tree.h:154
uint32_t magic
Definition: tree.h:151
int tb_op
non-leaf
Definition: tree.h:152
union tree * tb_right
Definition: tree.h:155
struct region * tb_regionp
ptr to containing region
Definition: tree.h:153
void db_tree_del_lhs(union tree *tp, struct resource *resp)
union tree * db_find_named_leaf(union tree *tp, const char *cp)
int db_follow_path_for_state(struct db_tree_state *tsp, struct db_full_path *pathp, const char *orig_str, int noisy)
int db_walk_tree(struct db_i *dbip, int argc, const char **argv, int ncpu, const struct db_tree_state *init_state, int(*reg_start_func)(struct db_tree_state *, const struct db_full_path *, const struct rt_comb_internal *, void *client_data), union tree *(*reg_end_func)(struct db_tree_state *, const struct db_full_path *, union tree *, void *client_data), union tree *(*leaf_func)(struct db_tree_state *, const struct db_full_path *, struct rt_db_internal *, void *client_data), void *client_data)
void db_pr_tree_state(const struct db_tree_state *tsp)
int db_apply_state_from_memb(struct db_tree_state *tsp, struct db_full_path *pathp, const union tree *tp)
struct combined_tree_state * db_dup_combined_tree_state(const struct combined_tree_state *old)
int db_follow_path(struct db_tree_state *tsp, struct db_full_path *total_path, const struct db_full_path *new_path, int noisy, long pdepth)
void rt_pr_tree_val(const union tree *tp, const struct partition *partp, int pr_name, int lvl)
int db_tally_subtree_regions(union tree *tp, union tree **reg_trees, int cur, int lim, struct resource *resp)
void db_pr_combined_tree_state(const struct combined_tree_state *ctsp)
int db_apply_state_from_one_member(struct db_tree_state *tsp, struct db_full_path *pathp, const char *cp, int sofar, const union tree *tp)
union tree * db_mkbool_tree(struct rt_tree_array *rt_tree_array, size_t howfar, struct resource *resp)
void db_free_combined_tree_state(struct combined_tree_state *ctsp)
union tree * db_dup_subtree(const union tree *tp, struct resource *resp)
int db_ck_v4gift_tree(const union tree *tp)
struct combined_tree_state * db_new_combined_tree_state(const struct db_tree_state *tsp, const struct db_full_path *pathp)
struct rt_tree_array * db_flatten_tree(struct rt_tree_array *rt_tree_array, union tree *tp, int op, int avail, struct resource *resp)
union tree * db_recurse(struct db_tree_state *tsp, struct db_full_path *pathp, struct combined_tree_state **region_start_statepp, void *client_data)
void db_non_union_push(union tree *tp, struct resource *resp)
int db_is_tree_all_unions(const union tree *tp)
void db_tree_flatten_describe(struct bu_vls *vls, const union tree *tp, int indented, int lvl, double mm2local, struct resource *resp)
void db_init_db_tree_state(struct db_tree_state *tsp, struct db_i *dbip, struct resource *resp)
void db_ck_tree(const union tree *tp)
void rt_pr_tree_vls(struct bu_vls *vls, const union tree *tp)
void db_tree_del_rhs(union tree *tp, struct resource *resp)
int rt_tree_elim_nops(union tree *, struct resource *resp)
void db_functree(struct db_i *dbip, struct directory *dp, void(*comb_func)(struct db_i *, struct directory *, void *), void(*leaf_func)(struct db_i *, struct directory *, void *), struct resource *resp, void *client_data)
void rt_optim_tree(union tree *tp, struct resource *resp)
void db_free_db_tree_state(struct db_tree_state *tsp)
char * rt_pr_tree_str(const union tree *tree)
void db_left_hvy_node(union tree *tp)
int db_tree_del_dbleaf(union tree **tp, const char *cp, struct resource *resp, int nflag)
void db_dup_db_tree_state(struct db_tree_state *otsp, const struct db_tree_state *itsp)
union tree * db_tree_parse(struct bu_vls *vls, const char *str, struct resource *resp)
int db_count_tree_nodes(const union tree *tp, int count)
const struct db_tree_state rt_initial_tree_state
int db_apply_state_from_comb(struct db_tree_state *tsp, const struct db_full_path *pathp, const struct rt_comb_internal *comb)
void db_tree_mul_dbleaf(union tree *tp, const mat_t mat)
int rt_bound_tree(const union tree *tp, vect_t tree_min, vect_t tree_max)
union tree * db_find_named_leafs_parent(int *side, union tree *tp, const char *cp)
size_t db_tree_nleaves(const union tree *tp)
void rt_pr_tree(const union tree *tp, int lvl)
union tree * db_mkgift_tree(struct rt_tree_array *trees, size_t subtreecount, struct resource *resp)
int db_tree_list(struct bu_vls *vls, const union tree *tp)
int db_ck_left_heavy_tree(const union tree *tp, int no_unions)
void db_tree_funcleaf(struct db_i *dbip, struct rt_comb_internal *comb, union tree *comb_tree, void(*leaf_func)(struct db_i *, struct rt_comb_internal *, union tree *, void *, void *, void *, void *), void *user_ptr1, void *user_ptr2, void *user_ptr3, void *user_ptr4)
void db_free_tree(union tree *tp, struct resource *resp)
int db_count_subtree_regions(const union tree *tp)
void db_tree_describe(struct bu_vls *vls, const union tree *tp, int indented, int lvl, double mm2local)
Definition: tree.h:147
struct tree::tree_cts tr_c
struct tree::tree_node tr_b
uint32_t magic
First word: magic number.
Definition: tree.h:148
struct tree::tree_leaf tr_a
struct tree::tree_nmgregion tr_d
struct tree::tree_db_leaf tr_l
fundamental vector, matrix, quaternion math macros