moab
|
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) meshsetFlags = (unsigned) tmp_int; 00030 else if (0 > tmp_int) return MB_FAILURE; 00031 00032 // CLEAN_UP: if false, do not delete tree sets upon tree class destruction; default = true 00033 bool tmp_bool; 00034 rval = options.get_toggle_option("CLEAN_UP", true, tmp_bool); 00035 if (MB_SUCCESS == rval && !tmp_bool) cleanUp = false; 00036 00037 // TAG_NAME: tag name to store tree information on tree nodes; default = "AKDTree" 00038 std::string tmp_str; 00039 rval = options.get_str_option("TAG_NAME", tmp_str); 00040 if (MB_SUCCESS == rval) boxTagName = tmp_str; 00041 00042 return MB_SUCCESS; 00043 } 00044 00045 ErrorCode Tree::find_all_trees( Range& results ) 00046 { 00047 Tag tag = get_box_tag(); 00048 ErrorCode rval = moab()->get_entities_by_type_and_tag( 0, MBENTITYSET, &tag, 0, 1, results ); 00049 if (MB_SUCCESS != rval || results.empty()) return rval; 00050 std::vector<BoundBox> boxes(results.size()); 00051 rval = moab()->tag_get_data(tag, results, &boxes[0]); 00052 if (MB_SUCCESS != rval) return rval; 00053 for (std::vector<BoundBox>::iterator vit = boxes.begin(); vit != boxes.end(); vit++) 00054 boundBox.update(*vit); 00055 00056 if (results.size() == 1) myRoot = *results.begin(); 00057 00058 return MB_SUCCESS; 00059 } 00060 00061 ErrorCode Tree::create_root( const double box_min[3], 00062 const double box_max[3], 00063 EntityHandle& root_handle ) 00064 { 00065 ErrorCode rval = mbImpl->create_meshset( meshsetFlags, root_handle ); 00066 if (MB_SUCCESS != rval) 00067 return rval; 00068 00069 myRoot = root_handle; 00070 00071 double box_tag[6]; 00072 for (int i = 0; i < 3; i++) { 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) 00078 return rval; 00079 00080 boundBox.bMin = box_min; 00081 boundBox.bMax = box_max; 00082 00083 return MB_SUCCESS; 00084 } 00085 00086 ErrorCode Tree::delete_tree_sets() 00087 { 00088 if (!myRoot) return MB_SUCCESS; 00089 00090 ErrorCode rval; 00091 std::vector<EntityHandle> children, dead_sets, current_sets; 00092 current_sets.push_back(myRoot); 00093 while (!current_sets.empty()) { 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) 00099 return rval; 00100 std::copy( children.begin(), children.end(), std::back_inserter(current_sets) ); 00101 children.clear(); 00102 } 00103 00104 rval = mbImpl->tag_delete_data( boxTag, &myRoot, 1 ); 00105 if (MB_SUCCESS != rval) 00106 return rval; 00107 00108 rval = mbImpl->delete_entities( &dead_sets[0], dead_sets.size() ); 00109 if (MB_SUCCESS != rval) return rval; 00110 00111 myRoot = 0; 00112 00113 return MB_SUCCESS; 00114 } 00115 00116 }