moab
|
00001 00006 #ifndef MOAB_TREE_HPP 00007 #define MOAB_TREE_HPP 00008 00009 #include "moab/Interface.hpp" 00010 #include "moab/BoundBox.hpp" 00011 #include "moab/CartVect.hpp" 00012 #include "moab/FileOptions.hpp" 00013 #include "moab/TreeStats.hpp" 00014 00015 #include <string> 00016 #include <vector> 00017 #include <math.h> 00018 #include <assert.h> 00019 00020 namespace moab { 00021 00022 class Interface; 00023 class Range; 00024 class ElemEvaluator; 00025 00026 class Tree 00027 { 00028 public: 00032 Tree(Interface* iface); 00033 00036 virtual ~Tree(); 00037 00041 virtual ErrorCode reset_tree() = 0; 00042 00045 ErrorCode delete_tree_sets(); 00046 00064 virtual ErrorCode build_tree(const Range& entities, 00065 EntityHandle *tree_root_set = NULL, 00066 FileOptions *options = NULL) = 0; 00067 00076 virtual ErrorCode get_bounding_box(BoundBox &box, EntityHandle *tree_node = NULL) const; 00077 00085 virtual ErrorCode get_info(EntityHandle root, 00086 double min[3], double max[3], 00087 unsigned int &max_dep); 00088 00091 ErrorCode find_all_trees( Range& results ); 00092 00111 virtual ErrorCode point_search(const double *point, 00112 EntityHandle& leaf_out, 00113 const double iter_tol = 1.0e-10, 00114 const double inside_tol = 1.0e-6, 00115 bool *multiple_leaves = NULL, 00116 EntityHandle *start_node = NULL, 00117 CartVect *params = NULL) = 0; 00118 00134 virtual ErrorCode distance_search(const double *point, 00135 const double distance, 00136 std::vector<EntityHandle>& leaves_out, 00137 const double iter_tol = 1.0e-10, 00138 const double inside_tol = 1.0e-6, 00139 std::vector<double> *dists_out = NULL, 00140 std::vector<CartVect> *params_out = NULL, 00141 EntityHandle *start_node = NULL) = 0; 00142 00145 Interface* moab() { return mbImpl; } 00146 00149 const Interface* moab() const { return mbImpl; } 00150 00152 double get_max_depth() {return maxDepth;} 00153 00155 double get_max_per_leaf() {return maxPerLeaf;} 00156 00158 TreeStats &tree_stats() {return treeStats;} 00159 00161 const TreeStats &tree_stats() const {return treeStats;} 00162 00165 ErrorCode create_root( const double box_min[3], const double box_max[3], 00166 EntityHandle& root_handle); 00167 00169 virtual ErrorCode print() = 0; 00170 00172 inline ElemEvaluator *get_eval() {return myEval;} 00173 00175 inline void set_eval(ElemEvaluator *eval) {myEval = eval;} 00176 00180 virtual ErrorCode parse_options(FileOptions &opts) = 0; 00181 00182 protected: 00183 00190 ErrorCode parse_common_options(FileOptions &options); 00191 00195 Tag get_box_tag(bool create_if_missing = true); 00196 00197 // moab instance 00198 Interface *mbImpl; 00199 00200 // bounding box for entire tree 00201 BoundBox boundBox; 00202 00203 // max entities per leaf 00204 int maxPerLeaf; 00205 00206 // max depth of tree 00207 int maxDepth; 00208 00209 // tree depth, set by build_tree 00210 int treeDepth; 00211 00212 // min width of box, handled like tolerance 00213 double minWidth; 00214 00215 // meshset creation flags 00216 unsigned int meshsetFlags; 00217 00218 // clean up flag 00219 bool cleanUp; 00220 00221 // tree root 00222 EntityHandle myRoot; 00223 00224 // tag used to mark bounding box of nodes 00225 Tag boxTag; 00226 00227 // tag name used for boxTag 00228 std::string boxTagName; 00229 00230 // tree traversal stats 00231 TreeStats treeStats; 00232 00233 // element evaluator 00234 ElemEvaluator *myEval; 00235 }; 00236 00237 inline Tree::Tree(Interface* iface) 00238 : mbImpl(iface), maxPerLeaf(6), maxDepth(30), treeDepth(-1), minWidth(1.0e-10), 00239 meshsetFlags(0), cleanUp(true), myRoot(0), boxTag(0), myEval(0) 00240 {} 00241 00242 inline Tree::~Tree() 00243 { 00244 } 00245 00246 inline ErrorCode Tree::get_bounding_box(BoundBox &box, EntityHandle *tree_node) const 00247 { 00248 if ((tree_node && *tree_node == myRoot) || !tree_node) { 00249 box = boundBox; 00250 return MB_SUCCESS; 00251 } 00252 else return MB_FAILURE; 00253 } 00254 00255 inline ErrorCode Tree::get_info(EntityHandle /* root */, 00256 double * /*min[3]*/, double * /* max[3]*/, 00257 unsigned int &/*dep*/) 00258 { 00259 return MB_NOT_IMPLEMENTED; 00260 } 00261 00262 inline Tag Tree::get_box_tag(bool create_if_missing) 00263 { 00264 if (!boxTag && create_if_missing) { 00265 assert(boxTagName.length() > 0); 00266 ErrorCode rval = moab()->tag_get_handle(boxTagName.c_str(), 6, MB_TYPE_DOUBLE, boxTag, MB_TAG_CREAT | MB_TAG_SPARSE); 00267 if (MB_INVALID_SIZE == rval) { 00268 // delete the tag and get it again, legacy file... 00269 rval = moab()->tag_delete(boxTag); 00270 if (MB_SUCCESS != rval) return 0; 00271 boxTag = 0; 00272 return get_box_tag(true); 00273 } 00274 00275 if (MB_SUCCESS != rval) return 0; 00276 } 00277 00278 return boxTag; 00279 } 00280 00281 } // namespace moab 00282 00283 #endif