MOAB: Mesh Oriented datABase
(version 5.4.1)
|
00001 #include "moab/Tree.hpp" 00002 #include "moab/Range.hpp" 00003 #include "moab/Interface.hpp" 00004 00005 #include <limits> 00006 00007 namespace moab 00008 { 00009 ErrorCode Tree::parse_common_options( FileOptions& options ) 00010 { 00011 double tmp_dbl; 00012 int tmp_int; 00013 // MAX_PER_LEAF: max entities per leaf; default = 6 00014 ErrorCode rval = options.get_int_option( "MAX_PER_LEAF", tmp_int ); 00015 if( MB_SUCCESS == rval ) maxPerLeaf = std::max( tmp_int, 1 ); 00016 00017 // MAX_DEPTH: max depth of the tree; default = 30 00018 rval = options.get_int_option( "MAX_DEPTH", tmp_int ); 00019 if( MB_SUCCESS == rval ) maxDepth = tmp_int; 00020 if( maxDepth < 1 ) maxDepth = std::numeric_limits< unsigned >::max(); 00021 00022 // MIN_WIDTH: minimum width of box, used like a tolerance; default = 1.0e-10 00023 rval = options.get_real_option( "MIN_WIDTH", tmp_dbl ); 00024 if( MB_SUCCESS == rval ) minWidth = tmp_dbl; 00025 00026 // MESHSET_FLAGS: flags passed into meshset creation for tree nodes; should be a value from 00027 // ENTITY_SET_PROPERTY (see Types.hpp); default = MESHSET_SET 00028 rval = options.get_int_option( "MESHSET_FLAGS", tmp_int ); 00029 if( MB_SUCCESS == rval && 0 <= tmp_int ) 00030 meshsetFlags = (unsigned)tmp_int; 00031 else if( 0 > tmp_int ) 00032 return MB_FAILURE; 00033 00034 // CLEAN_UP: if false, do not delete tree sets upon tree class destruction; default = true 00035 bool tmp_bool; 00036 rval = options.get_toggle_option( "CLEAN_UP", true, tmp_bool ); 00037 if( MB_SUCCESS == rval && !tmp_bool ) cleanUp = false; 00038 00039 // TAG_NAME: tag name to store tree information on tree nodes; default = "AKDTree" 00040 std::string tmp_str; 00041 rval = options.get_str_option( "TAG_NAME", tmp_str ); 00042 if( MB_SUCCESS == rval ) boxTagName = tmp_str; 00043 00044 return MB_SUCCESS; 00045 } 00046 00047 ErrorCode Tree::find_all_trees( Range& results ) 00048 { 00049 Tag tag = get_box_tag(); 00050 ErrorCode rval = moab()->get_entities_by_type_and_tag( 0, MBENTITYSET, &tag, 0, 1, results ); 00051 if( MB_SUCCESS != rval || results.empty() ) return rval; 00052 std::vector< BoundBox > boxes( results.size() ); 00053 rval = moab()->tag_get_data( tag, results, &boxes[0] ); 00054 if( MB_SUCCESS != rval ) return rval; 00055 for( std::vector< BoundBox >::iterator vit = boxes.begin(); vit != boxes.end(); ++vit ) 00056 boundBox.update( *vit ); 00057 00058 if( results.size() == 1 ) myRoot = *results.begin(); 00059 00060 return MB_SUCCESS; 00061 } 00062 00063 ErrorCode Tree::create_root( const double box_min[3], const double box_max[3], EntityHandle& root_handle ) 00064 { 00065 ErrorCode rval = mbImpl->create_meshset( meshsetFlags, root_handle ); 00066 if( MB_SUCCESS != rval ) return rval; 00067 00068 myRoot = root_handle; 00069 00070 double box_tag[6]; 00071 for( int i = 0; i < 3; i++ ) 00072 { 00073 box_tag[i] = box_min[i]; 00074 box_tag[3 + i] = box_max[i]; 00075 } 00076 rval = mbImpl->tag_set_data( get_box_tag(), &root_handle, 1, box_tag ); 00077 if( MB_SUCCESS != rval ) return rval; 00078 00079 boundBox.bMin = box_min; 00080 boundBox.bMax = box_max; 00081 00082 return MB_SUCCESS; 00083 } 00084 00085 ErrorCode Tree::delete_tree_sets() 00086 { 00087 if( !myRoot ) return MB_SUCCESS; 00088 00089 ErrorCode rval; 00090 std::vector< EntityHandle > children, dead_sets, current_sets; 00091 current_sets.push_back( myRoot ); 00092 while( !current_sets.empty() ) 00093 { 00094 EntityHandle set = current_sets.back(); 00095 current_sets.pop_back(); 00096 dead_sets.push_back( set ); 00097 rval = mbImpl->get_child_meshsets( set, children ); 00098 if( MB_SUCCESS != rval ) return rval; 00099 std::copy( children.begin(), children.end(), std::back_inserter( current_sets ) ); 00100 children.clear(); 00101 } 00102 00103 rval = mbImpl->tag_delete_data( boxTag, &myRoot, 1 ); 00104 if( MB_SUCCESS != rval ) return rval; 00105 00106 rval = mbImpl->delete_entities( &dead_sets[0], dead_sets.size() ); 00107 if( MB_SUCCESS != rval ) return rval; 00108 00109 myRoot = 0; 00110 00111 return MB_SUCCESS; 00112 } 00113 00114 } // namespace moab