moab
|
00001 /* 00002 * MOAB, a Mesh-Oriented datABase, is a software component for creating, 00003 * storing and accessing finite element mesh data. 00004 * 00005 * Copyright 2004 Sandia Corporation. Under the terms of Contract 00006 * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government 00007 * retains certain rights in this software. 00008 * 00009 * This library is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU Lesser General Public 00011 * License as published by the Free Software Foundation; either 00012 * version 2.1 of the License, or (at your option) any later version. 00013 * 00014 */ 00015 00021 #ifndef MOAB_ORIENTED_BOX_TREE_TOOL_HPP 00022 #define MOAB_ORIENTED_BOX_TREE_TOOL_HPP 00023 00024 #include "moab/Forward.hpp" 00025 00026 #include <iosfwd> 00027 #include <list> 00028 #include <vector> 00029 00030 namespace moab { 00031 00032 class Range; 00033 class OrientedBox; 00034 class StatData; 00035 class CartVect; 00036 00040 class OrientedBoxTreeTool 00041 { 00042 public: 00043 00075 struct Settings { 00076 public: 00077 Settings(); 00078 int max_leaf_entities; 00079 int max_depth; 00080 00081 00082 00083 double worst_split_ratio; 00088 double best_split_ratio; 00090 unsigned int set_options; 00092 bool valid() const; 00093 }; 00094 00095 OrientedBoxTreeTool( Interface* i, 00096 const char* tag_name = 0, 00097 bool destroy_created_trees = false ) ; 00098 00099 ~OrientedBoxTreeTool(); 00100 00109 ErrorCode build( const Range& entities, 00110 EntityHandle& set_handle_out, 00111 const Settings* settings = 0 ); 00112 00127 ErrorCode join_trees( const Range& tree_roots, 00128 EntityHandle& root_set_out, 00129 const Settings* settings = 0 ); 00130 00131 00144 class TrvStats{ 00145 public: 00146 00149 const std::vector< unsigned >& nodes_visited() const 00150 { return nodes_visited_count; } 00152 const std::vector< unsigned >& leaves_visited() const 00153 { return leaves_visited_count; } 00155 const std::vector< unsigned >& traversals_ended() const 00156 { return traversals_ended_count; } 00159 unsigned int ray_tri_tests() const 00160 { return ray_tri_tests_count; } 00162 void reset(); 00164 void print( std::ostream& str ) const ; 00165 00166 TrvStats() : ray_tri_tests_count(0) {} 00167 00168 private: 00169 00170 std::vector< unsigned > nodes_visited_count; 00171 std::vector< unsigned > leaves_visited_count; 00172 std::vector< unsigned > traversals_ended_count; 00173 unsigned int ray_tri_tests_count; 00174 00175 void increment( unsigned depth ); 00176 void increment_leaf( unsigned depth ); 00177 void end_traversal( unsigned depth ); 00178 00179 friend class OrientedBoxTreeTool; 00180 00181 }; 00182 00183 00196 ErrorCode ray_intersect_triangles( std::vector<double>& distances_out, 00197 std::vector<EntityHandle>& facets_out, 00198 EntityHandle root_set, 00199 double tolerance, 00200 const double ray_point[3], 00201 const double unit_ray_dir[3], 00202 const double* ray_length = 0, 00203 TrvStats* accum = 0 ); 00204 00215 ErrorCode ray_intersect_boxes( Range& boxes_out, 00216 EntityHandle root_set, 00217 double tolerance, 00218 const double ray_point[3], 00219 const double unit_ray_dir[3], 00220 const double* ray_length = 0, 00221 TrvStats* accum = 0 ); 00222 00228 ErrorCode ray_intersect_triangles( 00229 std::vector<double>& intersection_distances_out, 00230 std::vector<EntityHandle>& intersection_facets_out, 00231 const Range& leaf_boxes_containing_tris, 00232 double tolerance, 00233 const double ray_point[3], 00234 const double unit_ray_dir[3], 00235 const double* ray_length = 0, 00236 unsigned int* raytri_test_count = 0); 00237 00238 00279 ErrorCode ray_intersect_sets( std::vector<double>& distances_out, 00280 std::vector<EntityHandle>& sets_out, 00281 std::vector<EntityHandle>& facets_out, 00282 EntityHandle root_set, 00283 double tolerance, 00284 int min_tolerace_intersections, 00285 const double ray_point[3], 00286 const double unit_ray_dir[3], 00287 const double* nonneg_ray_len = 0, 00288 TrvStats* accum = 0, 00289 const double* neg_ray_len = 0, 00290 const EntityHandle* geom_vol = 0, 00291 const Tag* sense_tag = 0, 00292 const int* desired_orient = 0, 00293 const std::vector<EntityHandle>* prev_facets = 0 ); 00294 00304 ErrorCode closest_to_location( const double* point, 00305 EntityHandle tree_root, 00306 double* point_out, 00307 EntityHandle& facet_out, 00308 EntityHandle* set_out = 0, 00309 TrvStats* accum = 0 ); 00310 00318 ErrorCode closest_to_location( const double* point, 00319 EntityHandle tree_root, 00320 double tolerance, 00321 std::vector<EntityHandle>& facets_out, 00322 std::vector<EntityHandle>* sets_out = 0, 00323 TrvStats* accum = 0 ); 00324 00336 ErrorCode sphere_intersect_triangles( const double* center, 00337 double radius, 00338 EntityHandle tree_root, 00339 std::vector<EntityHandle>& facets_out, 00340 std::vector<EntityHandle>* sets_out = 0, 00341 TrvStats* accum = 0 ); 00342 00347 ErrorCode box( EntityHandle node_set, 00348 double center[3], 00349 double axis1[3], 00350 double axis2[3], 00351 double axis3[3] ); 00352 00353 ErrorCode delete_tree( EntityHandle root_set ); 00354 00365 void print( EntityHandle tree_root_set, 00366 std::ostream& stream, 00367 bool list_contents = false, 00368 const char* id_tag_name = 0 ); 00369 00374 ErrorCode stats( EntityHandle tree_root_set, std::ostream& stream ); 00375 00388 ErrorCode stats( EntityHandle set, 00389 unsigned &entities_in_tree, 00390 double &root_volume, 00391 double &tot_node_volume, 00392 double &tot_to_root_volume, 00393 unsigned &tree_height, 00394 unsigned &node_count, 00395 unsigned &num_leaves); 00396 00403 class Op { 00404 public: 00405 00416 virtual ErrorCode visit( EntityHandle node, 00417 int depth, 00418 bool& descend ) = 0; 00419 00421 virtual ErrorCode leaf( EntityHandle node ) = 0; 00422 00423 virtual ~Op(); // probably isn't necessary in this case, and 00424 // does nothing, but lots of compilers warn if 00425 // virtual function but no virtual destructor. 00426 }; 00427 00436 ErrorCode preorder_traverse( EntityHandle root_set, 00437 Op& operation, 00438 TrvStats* accum = 0 ); 00439 00440 Interface* get_moab_instance() const { return instance; } 00441 00442 struct SetData; 00443 00452 ErrorCode box( EntityHandle node_set, 00453 OrientedBox& box ); 00454 private: 00455 00456 ErrorCode build_tree( const Range& entities, 00457 EntityHandle& set, 00458 int depth, 00459 const Settings& settings ); 00460 00461 ErrorCode build_sets( std::list<SetData>& sets, 00462 EntityHandle& node_set, 00463 int depth, 00464 const Settings& settings ); 00465 00466 ErrorCode recursive_stats( OrientedBoxTreeTool* tool, 00467 Interface* instance, 00468 EntityHandle set, 00469 int depth, 00470 StatData& data, 00471 unsigned& count_out, 00472 CartVect& dimensions_out ); 00473 00474 Interface* instance; 00475 Tag tagHandle; 00476 00477 bool cleanUpTrees; 00478 std::vector<EntityHandle> createdTrees; 00479 }; 00480 00481 } // namespace moab 00482 00483 #endif