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