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-2022 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 * Updates state via *tsp, pushes member's directory entry on *pathp.
335 * (Caller is responsible for popping it).
336 *
337 * Returns -
338 * -1 failure
339 * 0 success, member pushed on path
340 */
341RT_EXPORT extern int db_apply_state_from_memb(struct db_tree_state *tsp,
342 struct db_full_path *pathp,
343 const union tree *tp);
344
345/**
346 * Returns -
347 * -1 found member, failed to apply state
348 * 0 unable to find member 'cp'
349 * 1 state applied OK
350 */
351RT_EXPORT extern int db_apply_state_from_one_member(struct db_tree_state *tsp,
352 struct db_full_path *pathp,
353 const char *cp,
354 int sofar,
355 const union tree *tp);
356
357/**
358 * The search stops on the first match.
359 *
360 * Returns -
361 * tp if found
362 * TREE_NULL if not found in this tree
363 */
364RT_EXPORT extern union tree *db_find_named_leaf(union tree *tp, const char *cp);
365
366/**
367 * The search stops on the first match.
368 *
369 * Returns -
370 * TREE_NULL if not found in this tree
371 * tp if found
372 * *side == 1 if leaf is on lhs.
373 * *side == 2 if leaf is on rhs.
374 *
375 */
376RT_EXPORT extern union tree *db_find_named_leafs_parent(int *side,
377 union tree *tp,
378 const char *cp);
379RT_EXPORT extern void db_tree_del_lhs(union tree *tp,
380 struct resource *resp);
381RT_EXPORT extern void db_tree_del_rhs(union tree *tp,
382 struct resource *resp);
383
384/**
385 * Given a name presumably referenced in a OP_DB_LEAF node, delete
386 * that node, and the operation node that references it. Not that
387 * this may not produce an equivalent tree, for example when rewriting
388 * (A - subtree) as (subtree), but that will be up to the caller/user
389 * to adjust. This routine gets rid of exactly two nodes in the tree:
390 * leaf, and op. Use some other routine if you wish to kill the
391 * entire rhs below "-" and "intersect" nodes.
392 *
393 * The two nodes deleted will have their memory freed.
394 *
395 * If the tree is a single OP_DB_LEAF node, the leaf is freed and *tp
396 * is set to NULL.
397 *
398 * Returns -
399 * -3 Internal error
400 * -2 Tree is empty
401 * -1 Unable to find OP_DB_LEAF node specified by 'cp'.
402 * 0 OK
403 */
404RT_EXPORT extern int db_tree_del_dbleaf(union tree **tp,
405 const char *cp,
406 struct resource *resp,
407 int nflag);
408
409/**
410 * Multiply on the left every matrix found in a DB_LEAF node in a
411 * tree.
412 */
413RT_EXPORT extern void db_tree_mul_dbleaf(union tree *tp,
414 const mat_t mat);
415
416/**
417 * This routine traverses a combination (union tree) in LNR order and
418 * calls the provided function for each OP_DB_LEAF node. Note that
419 * this routine does not go outside this one combination!!!!
420 *
421 * was previously named comb_functree()
422 */
423RT_EXPORT extern void db_tree_funcleaf(struct db_i *dbip,
424 struct rt_comb_internal *comb,
425 union tree *comb_tree,
426 void (*leaf_func)(struct db_i *, struct rt_comb_internal *, union tree *,
427 void *, void *, void *, void *),
428 void * user_ptr1,
429 void * user_ptr2,
430 void * user_ptr3,
431 void * user_ptr4);
432
433/**
434 * Starting with possible prior partial path and corresponding
435 * accumulated state, follow the path given by "new_path", updating
436 * *tsp and *total_path with full state information along the way. In
437 * a better world, there would have been a "combined_tree_state" arg.
438 *
439 * Parameter 'depth' controls how much of 'new_path' is used:
440 *
441 * 0 use all of new_path
442 * >0 use only this many of the first elements of the path
443 * <0 use all but this many path elements.
444 *
445 * A much more complete version of rt_plookup() and pathHmat(). There
446 * is also a TCL interface.
447 *
448 * Returns -
449 * 0 success (plus *tsp is updated)
450 * -1 error (*tsp values are not useful)
451 */
452RT_EXPORT extern int db_follow_path(struct db_tree_state *tsp,
453 struct db_full_path *total_path,
454 const struct db_full_path *new_path,
455 int noisy,
456 long pdepth);
457
458/**
459 * Follow the slash-separated path given by "cp", and update *tsp and
460 * *total_path with full state information along the way.
461 *
462 * A much more complete version of rt_plookup().
463 *
464 * Returns -
465 * 0 success (plus *tsp is updated)
466 * -1 error (*tsp values are not useful)
467 */
468RT_EXPORT extern int db_follow_path_for_state(struct db_tree_state *tsp,
469 struct db_full_path *pathp,
470 const char *orig_str, int noisy);
471
472/**
473 * Recurse down the tree, finding all the leaves (or finding just all
474 * the regions).
475 *
476 * ts_region_start_func() is called to permit regions to be skipped.
477 * It is not intended to be used for collecting state.
478 */
479RT_EXPORT extern union tree *db_recurse(struct db_tree_state *tsp,
480 struct db_full_path *pathp,
481 struct combined_tree_state **region_start_statepp,
482 void *client_data);
483RT_EXPORT extern union tree *db_dup_subtree(const union tree *tp,
484 struct resource *resp);
485RT_EXPORT extern void db_ck_tree(const union tree *tp);
486
487
488/**
489 * Release all storage associated with node 'tp', including children
490 * nodes.
491 */
492RT_EXPORT extern void db_free_tree(union tree *tp,
493 struct resource *resp);
494
495
496/**
497 * Re-balance this node to make it left heavy. Union operators will
498 * be moved to left side. when finished "tp" MUST still point to top
499 * node of this subtree.
500 */
501RT_EXPORT extern void db_left_hvy_node(union tree *tp);
502
503
504/**
505 * If there are non-union operations in the tree, above the region
506 * nodes, then rewrite the tree so that the entire tree top is nothing
507 * but union operations, and any non-union operations are clustered
508 * down near the region nodes.
509 */
510RT_EXPORT extern void db_non_union_push(union tree *tp,
511 struct resource *resp);
512
513/**
514 * Return a count of the number of "union tree" nodes below "tp",
515 * including tp.
516 */
517RT_EXPORT extern int db_count_tree_nodes(const union tree *tp,
518 int count);
519
520
521/**
522 * Returns -
523 * 1 if this tree contains nothing but union operations.
524 * 0 if at least one subtraction or intersection op exists.
525 */
526RT_EXPORT extern int db_is_tree_all_unions(const union tree *tp);
527RT_EXPORT extern int db_count_subtree_regions(const union tree *tp);
528RT_EXPORT extern int db_tally_subtree_regions(union tree *tp,
529 union tree **reg_trees,
530 int cur,
531 int lim,
532 struct resource *resp);
533
534/**
535 * This is the top interface to the "tree walker."
536 *
537 * Parameters:
538 * rtip rt_i structure to database (open with rt_dirbuild())
539 * argc # of tree-tops named
540 * argv names of tree-tops to process
541 * init_state Input parameter: initial state of the tree.
542 * For example: rt_initial_tree_state,
543 * and mged_initial_tree_state.
544 *
545 * These parameters are pointers to callback routines. If NULL, they
546 * won't be called.
547 *
548 * reg_start_func Called at beginning of each region, before
549 * visiting any nodes within the region. Return
550 * 0 if region should be skipped without
551 * recursing, otherwise non-zero. DO NOT USE FOR
552 * OTHER PURPOSES! For example, can be used to
553 * quickly skip air regions.
554 *
555 * reg_end_func Called after all nodes within a region have been
556 * recursively processed by leaf_func. If it
557 * wants to retain 'curtree' then it may steal
558 * that pointer and return TREE_NULL. If it
559 * wants us to clean up some or all of that tree,
560 * then it returns a non-null (union tree *)
561 * pointer, and that tree is safely freed in a
562 * non-parallel section before we return.
563 *
564 * leaf_func Function to process a leaf node. It is actually
565 * invoked from db_recurse() from
566 * _db_walk_subtree(). Returns (union tree *)
567 * representing the leaf, or TREE_NULL if leaf
568 * does not exist or has an error.
569 *
570 *
571 * This routine will employ multiple CPUs if asked, but is not
572 * multiply-parallel-recursive. Call this routine with ncpu > 1 from
573 * serial code only. When called from within an existing thread, ncpu
574 * must be 1.
575 *
576 * If ncpu > 1, the caller is responsible for making sure that
577 * RTG.rtg_parallel is non-zero.
578 *
579 * Plucks per-cpu resources out of rtip->rti_resources[]. They need
580 * to have been initialized first.
581 *
582 * Returns -
583 * -1 Failure to prepare even a single sub-tree
584 * 0 OK
585 */
586RT_EXPORT extern int db_walk_tree(struct db_i *dbip,
587 int argc,
588 const char **argv,
589 int ncpu,
590 const struct db_tree_state *init_state,
591 int (*reg_start_func) (struct db_tree_state * /*tsp*/,
592 const struct db_full_path * /*pathp*/,
593 const struct rt_comb_internal * /* combp */,
594 void *client_data),
595 union tree *(*reg_end_func) (struct db_tree_state * /*tsp*/,
596 const struct db_full_path * /*pathp*/,
597 union tree * /*curtree*/,
598 void *client_data),
599 union tree *(*leaf_func) (struct db_tree_state * /*tsp*/,
600 const struct db_full_path * /*pathp*/,
601 struct rt_db_internal * /*ip*/,
602 void *client_data),
603 void *client_data);
604
605/**
606 * Fills a bu_vls with a representation of the given tree appropriate
607 * for processing by Tcl scripts.
608 *
609 * A tree 't' is represented in the following manner:
610 *
611 * t := { l dbobjname { mat } }
612 * | { l dbobjname }
613 * | { u t1 t2 }
614 * | { n t1 t2 }
615 * | { - t1 t2 }
616 * | { ^ t1 t2 }
617 * | { ! t1 }
618 * | { G t1 }
619 * | { X t1 }
620 * | { N }
621 * | {}
622 *
623 * where 'dbobjname' is a string containing the name of a database object,
624 * 'mat' is the matrix preceding a leaf,
625 * 't1', 't2' are trees (recursively defined).
626 *
627 * Notice that in most cases, this tree will be grossly unbalanced.
628 */
629RT_EXPORT extern int db_tree_list(struct bu_vls *vls, const union tree *tp);
630
631/**
632 * Take a TCL-style string description of a binary tree, as produced
633 * by db_tree_list(), and reconstruct the in-memory form of that tree.
634 */
635RT_EXPORT extern union tree *db_tree_parse(struct bu_vls *vls, const char *str, struct resource *resp);
636
637/**
638 * This subroutine is called for a no-frills tree-walk, with the
639 * provided subroutines being called at every combination and leaf
640 * (solid) node, respectively.
641 *
642 * This routine is recursive, so no variables may be declared static.
643 */
644RT_EXPORT extern void db_functree(struct db_i *dbip,
645 struct directory *dp,
646 void (*comb_func)(struct db_i *,
647 struct directory *,
648 void *),
649 void (*leaf_func)(struct db_i *,
650 struct directory *,
651 void *),
652 struct resource *resp,
653 void *client_data);
654/**
655 * Ray Tracing library database tree walker.
656 *
657 * Collect and prepare regions and solids for subsequent ray-tracing.
658 *
659 */
660
661
662/**
663 * Calculate the bounding RPP of the region whose boolean tree is
664 * 'tp'. The bounding RPP is returned in tree_min and tree_max, which
665 * need not have been initialized first.
666 *
667 * Returns -
668 * 0 success
669 * -1 failure (tree_min and tree_max may have been altered)
670 */
671RT_EXPORT extern int rt_bound_tree(const union tree *tp,
672 vect_t tree_min,
673 vect_t tree_max);
674
675/**
676 * Eliminate any references to NOP nodes from the tree. It is safe to
677 * use db_free_tree() here, because there will not be any dead solids.
678 * They will all have been converted to OP_NOP nodes by
679 * _rt_tree_kill_dead_solid_refs(), previously, so there is no need to
680 * worry about multiple db_free_tree()'s repeatedly trying to free one
681 * solid that has been instanced multiple times.
682 *
683 * Returns -
684 * 0 this node is OK.
685 * -1 request caller to kill this node
686 */
687RT_EXPORT extern int rt_tree_elim_nops(union tree *,
688 struct resource *resp);
689
690/**
691 * Return count of number of leaf nodes in this tree.
692 */
693RT_EXPORT extern size_t db_tree_nleaves(const union tree *tp);
694
695/**
696 * Take a binary tree in "V4-ready" layout (non-unions pushed below
697 * unions, left-heavy), and flatten it into an array layout, ready for
698 * conversion back to the GIFT-inspired V4 database format.
699 *
700 * This is done using the db_non_union_push() routine.
701 *
702 * If argument 'free' is non-zero, then the non-leaf nodes are freed
703 * along the way, to prevent memory leaks. In this case, the caller's
704 * copy of 'tp' will be invalid upon return.
705 *
706 * When invoked at the very top of the tree, the op argument must be
707 * OP_UNION.
708 */
709RT_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);
710
711
712/**
713 * Produce a GIFT-compatible listing, one "member" per line,
714 * regardless of the structure of the tree we've been given.
715 */
716RT_EXPORT extern void db_tree_flatten_describe(struct bu_vls *vls,
717 const union tree *tp,
718 int indented,
719 int lvl,
720 double mm2local,
721 struct resource *resp);
722
723RT_EXPORT extern void db_tree_describe(struct bu_vls *vls,
724 const union tree *tp,
725 int indented,
726 int lvl,
727 double mm2local);
728
729/**
730 * Support routine for db_ck_v4gift_tree().
731 * Ensure that the tree below 'tp' is left-heavy, i.e. that there are
732 * nothing but solids on the right side of any binary operations.
733 *
734 * Returns -
735 * -1 ERROR
736 * 0 OK
737 */
738RT_EXPORT extern int db_ck_left_heavy_tree(const union tree *tp,
739 int no_unions);
740/**
741 * Look a gift-tree in the mouth.
742 *
743 * Ensure that this boolean tree conforms to the GIFT convention that
744 * union operations must bind the loosest.
745 *
746 * There are two stages to this check:
747 * 1) Ensure that if unions are present they are all at the root of tree,
748 * 2) Ensure non-union children of union nodes are all left-heavy
749 * (nothing but solid nodes permitted on rhs of binary operators).
750 *
751 * Returns -
752 * -1 ERROR
753 * 0 OK
754 */
755RT_EXPORT extern int db_ck_v4gift_tree(const union tree *tp);
756
757/**
758 * Given a rt_tree_array array, build a tree of "union tree" nodes
759 * appropriately connected together. Every element of the
760 * rt_tree_array array used is replaced with a TREE_NULL. Elements
761 * which are already TREE_NULL are ignored. Returns a pointer to the
762 * top of the tree.
763 */
764RT_EXPORT extern union tree *db_mkbool_tree(struct rt_tree_array *rt_tree_array,
765 size_t howfar,
766 struct resource *resp);
767
768RT_EXPORT extern union tree *db_mkgift_tree(struct rt_tree_array *trees,
769 size_t subtreecount,
770 struct resource *resp);
771
772
773RT_EXPORT extern void rt_optim_tree(union tree *tp,
774 struct resource *resp);
775
776
777
778__END_DECLS
779
780#endif /* RT_TREE_H */
781
782/*
783 * Local Variables:
784 * tab-width: 8
785 * mode: C
786 * indent-tabs-mode: t
787 * c-file-style: "stroustrup"
788 * End:
789 * ex: shiftwidth=4 tabstop=8
790 */
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.
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