Mesh Oriented datABase  (version 5.5.0)
An array-based unstructured mesh library
moab::Tree Class Referenceabstract

Parent class of various tree types in MOAB. More...

#include <Tree.hpp>

+ Inheritance diagram for moab::Tree:
+ Collaboration diagram for moab::Tree:

Public Member Functions

 Tree (Interface *iface)
 Constructor (bare) More...
 
virtual ~Tree ()
 Destructor. More...
 
virtual ErrorCode reset_tree ()=0
 Destroy the tree maintained by this object, optionally checking we have the right root. More...
 
ErrorCode delete_tree_sets ()
 Delete the entity sets associated with the tree, starting with the root and traversing children. More...
 
virtual ErrorCode build_tree (const Range &entities, EntityHandle *tree_root_set=NULL, FileOptions *options=NULL)=0
 
virtual ErrorCode get_bounding_box (BoundBox &box, EntityHandle *tree_node=NULL) const
 Get bounding box for tree below tree_node, or entire tree If no tree has been built yet, returns +/- DBL_MAX for all dimensions. Note for some tree types, boxes are not available for non-root nodes, and this function will return failure if non-root is passed in. More...
 
virtual ErrorCode get_info (EntityHandle root, double min[3], double max[3], unsigned int &max_dep)
 Return some basic information about the tree Stats are returned for tree starting from input node or tree root (root = 0) More...
 
ErrorCode find_all_trees (Range &results)
 Find all trees, by bounding box tag. More...
 
virtual ErrorCode point_search (const double *point, EntityHandle &leaf_out, const double iter_tol=1.0e-10, const double inside_tol=1.0e-6, bool *multiple_leaves=NULL, EntityHandle *start_node=NULL, CartVect *params=NULL)=0
 Get leaf containing input position. More...
 
virtual ErrorCode distance_search (const double *point, const double distance, std::vector< EntityHandle > &leaves_out, const double iter_tol=1.0e-10, const double inside_tol=1.0e-6, std::vector< double > *dists_out=NULL, std::vector< CartVect > *params_out=NULL, EntityHandle *start_node=NULL)=0
 Find all leaves within a given distance from point If dists_out input non-NULL, also returns distances from each leaf; if point i is inside leaf, 0 is given as dists_out[i]. If params_out is non-NULL and myEval is non-NULL, will evaluate individual entities in tree nodes and return containing entities in leaves_out. In those cases, if params_out is also non-NULL, will return parameters in those elements in that vector. More...
 
Interfacemoab ()
 Return the MOAB interface associated with this tree. More...
 
const Interfacemoab () const
 Return the MOAB interface associated with this tree. More...
 
double get_max_depth ()
 Get max depth set on tree. More...
 
double get_max_per_leaf ()
 Get max entities per leaf set on tree. More...
 
TreeStatstree_stats ()
 Get tree traversal stats object. More...
 
const TreeStatstree_stats () const
 Get tree traversal stats object. More...
 
ErrorCode create_root (const double box_min[3], const double box_max[3], EntityHandle &root_handle)
 Create tree root and tag with bounding box. More...
 
virtual ErrorCode print ()=0
 print various things about this tree More...
 
ElemEvaluatorget_eval ()
 get/set the ElemEvaluator More...
 
void set_eval (ElemEvaluator *eval)
 get/set the ElemEvaluator More...
 
virtual ErrorCode parse_options (FileOptions &opts)=0
 Parse options for this tree, including common options for all trees. More...
 

Protected Member Functions

ErrorCode parse_common_options (FileOptions &options)
 Parse options common to all trees. More...
 
Tag get_box_tag (bool create_if_missing=true)
 Get the box tag, possibly constructing it first. More...
 

Protected Attributes

InterfacembImpl
 
BoundBox boundBox
 
int maxPerLeaf
 
int maxDepth
 
int treeDepth
 
double minWidth
 
unsigned int meshsetFlags
 
bool cleanUp
 
EntityHandle myRoot
 
Tag boxTag
 
std::string boxTagName
 
TreeStats treeStats
 
ElemEvaluatormyEval
 

Detailed Description

Parent class of various tree types in MOAB.

Definition at line 27 of file Tree.hpp.

Constructor & Destructor Documentation

◆ Tree()

moab::Tree::Tree ( Interface iface)
inline

Constructor (bare)

Parameters
ifaceMOAB instance

Definition at line 257 of file Tree.hpp.

258  : mbImpl( iface ), maxPerLeaf( 6 ), maxDepth( 30 ), treeDepth( -1 ), minWidth( 1.0e-10 ), meshsetFlags( 0 ),
259  cleanUp( true ), myRoot( 0 ), boxTag( 0 ), myEval( 0 )
260 {
261 }

◆ ~Tree()

moab::Tree::~Tree ( )
inlinevirtual

Destructor.

Definition at line 263 of file Tree.hpp.

263 {}

Member Function Documentation

◆ build_tree()

virtual ErrorCode moab::Tree::build_tree ( const Range entities,
EntityHandle tree_root_set = NULL,
FileOptions options = NULL 
)
pure virtual

Build the tree Build a tree with the entities input. If a non-NULL tree_root_set pointer is input, use the pointed-to set as the root of this tree (*tree_root_set!=0) otherwise construct a new root set and pass its handle back in *tree_root_set. Options vary by tree type, with a few common to all types of trees. Common options: MAX_PER_LEAF: max entities per leaf; default = 6 MAX_DEPTH: max depth of the tree; default = 30 MIN_WIDTH: minimum width of box, used like a tolerance; default = 1.0e-10 MESHSET_FLAGS: flags passed into meshset creation for tree nodes; should be a value from ENTITY_SET_PROPERTY (see Types.hpp); default = MESHSET_SET CLEAN_UP: if false, do not delete tree sets upon tree class destruction; default = true TAG_NAME: tag name to store tree information on tree nodes; default determined by tree type

Parameters
entitiesEntities with which to build the tree
tree_rootRoot set for tree (see function description)
optsOptions for tree (see function description)
Returns
Error is returned only on build failure

Implemented in moab::BVHTree, and moab::AdaptiveKDTree.

Referenced by moab::SpatialLocator::add_elems(), and moab::SpatialLocator::SpatialLocator().

◆ create_root()

ErrorCode moab::Tree::create_root ( const double  box_min[3],
const double  box_max[3],
EntityHandle root_handle 
)

Create tree root and tag with bounding box.

Definition at line 63 of file Tree.cpp.

64 {
65  ErrorCode rval = mbImpl->create_meshset( meshsetFlags, root_handle );
66  if( MB_SUCCESS != rval ) return rval;
67 
68  myRoot = root_handle;
69 
70  double box_tag[6];
71  for( int i = 0; i < 3; i++ )
72  {
73  box_tag[i] = box_min[i];
74  box_tag[3 + i] = box_max[i];
75  }
76  rval = mbImpl->tag_set_data( get_box_tag(), &root_handle, 1, box_tag );
77  if( MB_SUCCESS != rval ) return rval;
78 
81 
82  return MB_SUCCESS;
83 }

References moab::BoundBox::bMax, moab::BoundBox::bMin, boundBox, box_max(), box_min(), moab::Interface::create_meshset(), ErrorCode, get_box_tag(), MB_SUCCESS, mbImpl, meshsetFlags, myRoot, and moab::Interface::tag_set_data().

Referenced by moab::AdaptiveKDTree::build_tree(), and moab::BVHTree::build_tree().

◆ delete_tree_sets()

ErrorCode moab::Tree::delete_tree_sets ( )

Delete the entity sets associated with the tree, starting with the root and traversing children.

Definition at line 85 of file Tree.cpp.

86 {
87  if( !myRoot ) return MB_SUCCESS;
88 
89  ErrorCode rval;
90  std::vector< EntityHandle > children, dead_sets, current_sets;
91  current_sets.push_back( myRoot );
92  while( !current_sets.empty() )
93  {
94  EntityHandle set = current_sets.back();
95  current_sets.pop_back();
96  dead_sets.push_back( set );
97  rval = mbImpl->get_child_meshsets( set, children );
98  if( MB_SUCCESS != rval ) return rval;
99  std::copy( children.begin(), children.end(), std::back_inserter( current_sets ) );
100  children.clear();
101  }
102 
103  rval = mbImpl->tag_delete_data( boxTag, &myRoot, 1 );
104  if( MB_SUCCESS != rval ) return rval;
105 
106  rval = mbImpl->delete_entities( &dead_sets[0], dead_sets.size() );
107  if( MB_SUCCESS != rval ) return rval;
108 
109  myRoot = 0;
110 
111  return MB_SUCCESS;
112 }

References boxTag, children, moab::Interface::delete_entities(), ErrorCode, moab::Interface::get_child_meshsets(), MB_SUCCESS, mbImpl, myRoot, and moab::Interface::tag_delete_data().

Referenced by moab::AdaptiveKDTree::reset_tree(), and moab::BVHTree::reset_tree().

◆ distance_search()

virtual ErrorCode moab::Tree::distance_search ( const double *  point,
const double  distance,
std::vector< EntityHandle > &  leaves_out,
const double  iter_tol = 1.0e-10,
const double  inside_tol = 1.0e-6,
std::vector< double > *  dists_out = NULL,
std::vector< CartVect > *  params_out = NULL,
EntityHandle start_node = NULL 
)
pure virtual

Find all leaves within a given distance from point If dists_out input non-NULL, also returns distances from each leaf; if point i is inside leaf, 0 is given as dists_out[i]. If params_out is non-NULL and myEval is non-NULL, will evaluate individual entities in tree nodes and return containing entities in leaves_out. In those cases, if params_out is also non-NULL, will return parameters in those elements in that vector.

Parameters
pointPoint to be located in tree
distanceDistance within which to query
leaves_outLeaves within distance or containing point
iter_tolTolerance for convergence of point search
inside_tolTolerance for inside element calculation
dists_outIf non-NULL, will contain distsances to leaves
params_outIf non-NULL, will contain parameters of the point in the ents in leaves_out
start_nodeStart from this tree node (non-NULL) instead of tree root (NULL)

Implemented in moab::AdaptiveKDTree.

◆ find_all_trees()

ErrorCode moab::Tree::find_all_trees ( Range results)

Find all trees, by bounding box tag.

Definition at line 47 of file Tree.cpp.

48 {
49  Tag tag = get_box_tag();
50  ErrorCode rval = moab()->get_entities_by_type_and_tag( 0, MBENTITYSET, &tag, 0, 1, results );
51  if( MB_SUCCESS != rval || results.empty() ) return rval;
52  std::vector< BoundBox > boxes( results.size() );
53  rval = moab()->tag_get_data( tag, results, &boxes[0] );
54  if( MB_SUCCESS != rval ) return rval;
55  for( std::vector< BoundBox >::iterator vit = boxes.begin(); vit != boxes.end(); ++vit )
56  boundBox.update( *vit );
57 
58  if( results.size() == 1 ) myRoot = *results.begin();
59 
60  return MB_SUCCESS;
61 }

References moab::Range::begin(), boundBox, moab::Range::empty(), ErrorCode, get_box_tag(), moab::Interface::get_entities_by_type_and_tag(), MB_SUCCESS, MBENTITYSET, moab(), myRoot, moab::Range::size(), moab::Interface::tag_get_data(), and moab::BoundBox::update().

Referenced by main().

◆ get_bounding_box()

ErrorCode moab::Tree::get_bounding_box ( BoundBox box,
EntityHandle tree_node = NULL 
) const
inlinevirtual

Get bounding box for tree below tree_node, or entire tree If no tree has been built yet, returns +/- DBL_MAX for all dimensions. Note for some tree types, boxes are not available for non-root nodes, and this function will return failure if non-root is passed in.

Parameters
boxThe box for this tree
tree_nodeIf non-NULL, node for which box is requested, tree root if NULL
Returns
Only returns error on fatal condition

Reimplemented in moab::BVHTree.

Definition at line 265 of file Tree.hpp.

266 {
267  if( ( tree_node && *tree_node == myRoot ) || !tree_node )
268  {
269  box = boundBox;
270  return MB_SUCCESS;
271  }
272  else
273  return MB_FAILURE;
274 }

References boundBox, MB_SUCCESS, and myRoot.

Referenced by moab::AdaptiveKDTree::distance_search(), moab::AdaptiveKDTree::get_info(), moab::Coupler::initialize_tree(), moab::AdaptiveKDTree::point_search(), moab::AdaptiveKDTree::print(), moab::AdaptiveKDTree::ray_intersect_triangles(), moab::SpatialLocator::SpatialLocator(), and moab::Coupler::test_local_box().

◆ get_box_tag()

Tag moab::Tree::get_box_tag ( bool  create_if_missing = true)
inlineprotected

Get the box tag, possibly constructing it first.

Parameters
create_if_missingIf true and it has not been made yet, make it

Definition at line 284 of file Tree.hpp.

285 {
286  if( !boxTag && create_if_missing )
287  {
288  assert( boxTagName.length() > 0 );
289  ErrorCode rval =
291  if( MB_INVALID_SIZE == rval )
292  {
293  // delete the tag and get it again, legacy file...
294  rval = moab()->tag_delete( boxTag );
295  if( MB_SUCCESS != rval ) return 0;
296  boxTag = 0;
297  return get_box_tag( true );
298  }
299 
300  if( MB_SUCCESS != rval ) return 0;
301  }
302 
303  return boxTag;
304 }

References boxTag, boxTagName, ErrorCode, MB_INVALID_SIZE, MB_SUCCESS, MB_TAG_CREAT, MB_TAG_SPARSE, MB_TYPE_DOUBLE, moab(), moab::Interface::tag_delete(), and moab::Interface::tag_get_handle().

Referenced by create_root(), and find_all_trees().

◆ get_eval()

ElemEvaluator* moab::Tree::get_eval ( )
inline

get/set the ElemEvaluator

Definition at line 187 of file Tree.hpp.

188  {
189  return myEval;
190  }

References myEval.

Referenced by moab::SpatialLocator::locate_points().

◆ get_info()

ErrorCode moab::Tree::get_info ( EntityHandle  root,
double  min[3],
double  max[3],
unsigned int &  max_dep 
)
inlinevirtual

Return some basic information about the tree Stats are returned for tree starting from input node or tree root (root = 0)

Parameters
rootIf non-0, give stats below and including root
minMinimum corner of bounding box
maxMaximum corner of bounding box
max_depMaximum depth of tree below root

Reimplemented in moab::AdaptiveKDTree.

Definition at line 276 of file Tree.hpp.

280 {
281  return MB_NOT_IMPLEMENTED;
282 }

References MB_NOT_IMPLEMENTED.

◆ get_max_depth()

double moab::Tree::get_max_depth ( )
inline

Get max depth set on tree.

Definition at line 156 of file Tree.hpp.

157  {
158  return maxDepth;
159  }

References maxDepth.

◆ get_max_per_leaf()

double moab::Tree::get_max_per_leaf ( )
inline

Get max entities per leaf set on tree.

Definition at line 162 of file Tree.hpp.

163  {
164  return maxPerLeaf;
165  }

References maxPerLeaf.

◆ moab() [1/2]

◆ moab() [2/2]

const Interface* moab::Tree::moab ( ) const
inline

Return the MOAB interface associated with this tree.

Definition at line 150 of file Tree.hpp.

151  {
152  return mbImpl;
153  }

References mbImpl.

◆ parse_common_options()

ErrorCode moab::Tree::parse_common_options ( FileOptions options)
protected

Parse options common to all trees.

Parameters
optionsOptions for representing tree; see Tree::build_tree() and subclass build_tree() functions for allowed options
Returns
Non-success returned from base class function only under catastrophic circumstances; derived classes also can recognize subclass-specific options

Definition at line 9 of file Tree.cpp.

10 {
11  double tmp_dbl;
12  int tmp_int;
13  // MAX_PER_LEAF: max entities per leaf; default = 6
14  ErrorCode rval = options.get_int_option( "MAX_PER_LEAF", tmp_int );
15  if( MB_SUCCESS == rval ) maxPerLeaf = std::max( tmp_int, 1 );
16 
17  // MAX_DEPTH: max depth of the tree; default = 30
18  rval = options.get_int_option( "MAX_DEPTH", tmp_int );
19  if( MB_SUCCESS == rval ) maxDepth = tmp_int;
20  if( maxDepth < 1 ) maxDepth = std::numeric_limits< unsigned >::max();
21 
22  // MIN_WIDTH: minimum width of box, used like a tolerance; default = 1.0e-10
23  rval = options.get_real_option( "MIN_WIDTH", tmp_dbl );
24  if( MB_SUCCESS == rval ) minWidth = tmp_dbl;
25 
26  // MESHSET_FLAGS: flags passed into meshset creation for tree nodes; should be a value from
27  // ENTITY_SET_PROPERTY (see Types.hpp); default = MESHSET_SET
28  rval = options.get_int_option( "MESHSET_FLAGS", tmp_int );
29  if( MB_SUCCESS == rval && 0 <= tmp_int )
30  meshsetFlags = (unsigned)tmp_int;
31  else if( 0 > tmp_int )
32  return MB_FAILURE;
33 
34  // CLEAN_UP: if false, do not delete tree sets upon tree class destruction; default = true
35  bool tmp_bool;
36  rval = options.get_toggle_option( "CLEAN_UP", true, tmp_bool );
37  if( MB_SUCCESS == rval && !tmp_bool ) cleanUp = false;
38 
39  // TAG_NAME: tag name to store tree information on tree nodes; default = "AKDTree"
40  std::string tmp_str;
41  rval = options.get_str_option( "TAG_NAME", tmp_str );
42  if( MB_SUCCESS == rval ) boxTagName = tmp_str;
43 
44  return MB_SUCCESS;
45 }

References boxTagName, cleanUp, ErrorCode, moab::FileOptions::get_int_option(), moab::FileOptions::get_real_option(), moab::FileOptions::get_str_option(), moab::FileOptions::get_toggle_option(), maxDepth, maxPerLeaf, MB_SUCCESS, meshsetFlags, and minWidth.

Referenced by moab::AdaptiveKDTree::parse_options(), and moab::BVHTree::parse_options().

◆ parse_options()

virtual ErrorCode moab::Tree::parse_options ( FileOptions opts)
pure virtual

Parse options for this tree, including common options for all trees.

Parameters
optsOptions

Implemented in moab::BVHTree, and moab::AdaptiveKDTree.

◆ point_search()

virtual ErrorCode moab::Tree::point_search ( const double *  point,
EntityHandle leaf_out,
const double  iter_tol = 1.0e-10,
const double  inside_tol = 1.0e-6,
bool *  multiple_leaves = NULL,
EntityHandle start_node = NULL,
CartVect params = NULL 
)
pure virtual

Get leaf containing input position.

Does not take into account global bounding box of tree.

  • Therefore there is always one leaf containing the point.
  • If caller wants to account for global bounding box, then caller can test against that box and not call this method at all if the point is outside the box, as there is no leaf containing the point in that case.
    Parameters
    pointPoint to be located in tree
    leaf_outLeaf containing point
    iter_tolTolerance for convergence of point search
    inside_tolTolerance for inside element calculation
    multiple_leavesSome tree types can have multiple leaves containing a point; if non-NULL, this parameter is returned true if multiple leaves contain the input point
    start_nodeStart from this tree node (non-NULL) instead of tree root (NULL)
    Returns
    Non-success returned only in case of failure; not-found indicated by leaf_out=0

Implemented in moab::BVHTree, and moab::AdaptiveKDTree.

Referenced by moab::SpatialLocator::locate_points().

◆ print()

virtual ErrorCode moab::Tree::print ( )
pure virtual

print various things about this tree

Implemented in moab::BVHTree, and moab::AdaptiveKDTree.

◆ reset_tree()

virtual ErrorCode moab::Tree::reset_tree ( )
pure virtual

Destroy the tree maintained by this object, optionally checking we have the right root.

Parameters
rootIf non-NULL, check that this is the root, return failure if not

Implemented in moab::BVHTree, and moab::AdaptiveKDTree.

◆ set_eval()

void moab::Tree::set_eval ( ElemEvaluator eval)
inline

get/set the ElemEvaluator

Definition at line 193 of file Tree.hpp.

194  {
195  myEval = eval;
196  }

References myEval.

Referenced by moab::SpatialLocator::elem_eval(), and moab::SpatialLocator::locate_points().

◆ tree_stats() [1/2]

TreeStats& moab::Tree::tree_stats ( )
inline

Get tree traversal stats object.

Definition at line 168 of file Tree.hpp.

169  {
170  return treeStats;
171  }

References treeStats.

Referenced by DeformMeshRemap::execute(), and moab::AdaptiveKDTree::intersect_children_with_elems().

◆ tree_stats() [2/2]

const TreeStats& moab::Tree::tree_stats ( ) const
inline

Get tree traversal stats object.

Definition at line 174 of file Tree.hpp.

175  {
176  return treeStats;
177  }

References treeStats.

Member Data Documentation

◆ boundBox

◆ boxTag

Tag moab::Tree::boxTag
protected

◆ boxTagName

std::string moab::Tree::boxTagName
protected

◆ cleanUp

bool moab::Tree::cleanUp
protected

Definition at line 239 of file Tree.hpp.

Referenced by parse_common_options(), and moab::AdaptiveKDTree::~AdaptiveKDTree().

◆ maxDepth

◆ maxPerLeaf

◆ mbImpl

◆ meshsetFlags

unsigned int moab::Tree::meshsetFlags
protected

◆ minWidth

double moab::Tree::minWidth
protected

Definition at line 233 of file Tree.hpp.

Referenced by moab::AdaptiveKDTree::build_tree(), and parse_common_options().

◆ myEval

◆ myRoot

◆ treeDepth

int moab::Tree::treeDepth
protected

Definition at line 230 of file Tree.hpp.

Referenced by moab::BVHTree::build_tree().

◆ treeStats


The documentation for this class was generated from the following files: